Generating P6 (raw) PPM output images using "convert"

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
kslavin

Generating P6 (raw) PPM output images using "convert"

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Generating P6 (raw) PPM output images using "convert"

Post 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.
kslavin

Re: Generating P6 (raw) PPM output images using "convert"

Post by kslavin »

This message was originally a retraction. However, I now find that this bug is real -see the following post.
Last edited by kslavin on 2007-10-04T14:54:44-07:00, edited 2 times in total.
kslavin

Re: Generating P6 (raw) PPM output images using "convert"

Post 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.
Post Reply