Page 1 of 1
Generating P6 (raw) PPM output images using "convert"
Posted: 2007-10-03T16:24:15-07:00
by kslavin
Hi all,
When using "convert", I noticed that if I specify a .ppm output image, it always generates a P3 magic number header (ASCII RGB). After looking at the code, the only way I could generate files with P6 (raw RGB) was to use the convert
-compress Undefined
option. This seems a little counter-intuitive, and is also undocumented on the
www/command-line-options.html
page. Is there a better way?
Thanks,
Keith
Re: Generating P6 (raw) PPM output images using "convert"
Posted: 2007-10-03T16:47:51-07:00
by magick
ImageMagick should only create ASCII PPM Images when a compression of None is specified as in
convert logo: -compress none logo.ppm
otherwise raw PPM images are created. We tested this with the latest release and it seems to work as we described.
Re: Generating P6 (raw) PPM output images using "convert"
Posted: 2007-10-04T07:54:02-07:00
by kslavin
This message was originally a retraction. However, I now find that this bug is real -see the following post.
Re: Generating P6 (raw) PPM output images using "convert"
Posted: 2007-10-04T14:32:29-07:00
by kslavin
I retract the retraction! If the input file is compressed, then the PPM output file is correctly compressed. However if the input file is an uncompressed image (e.g. tiff), then the output is an ASCII P3 PPM file! It turns out there is a path through ReadImage() (in magick/constitute.c) onto the ImageStack in ConvertImageCommand() (in wand/convert.c), which calls WriteImages() (in magick/constitute.c) with the input image as the second argument. This in turn calls WriteImage(), with the input image again as the second argument. This in turn calls SyncImageInfo(). In that routine, if image_info->compression is Undefined (which it is if the compress flag is not used) then image->compression is left unchanged (=1=NoCompression in magick/compress.h) . When WriteImage() calls (via a function pointer) WritePNMImage() (in coders/pnm.c), the image->compression flag is then used to select P3 instead of P6.
Sorry about the long-winded explanation.