Page 1 of 1

Process modules and palettes

Posted: 2014-09-11T12:01:56-07:00
by snibgo
(I think this is a bug, but maybe it's a development issue.)

I have written a number of "-process" modules. See my page http://im.snibgo.com/customim.htm .

Fred has discovered, and I confirm, that they don't work correctly when the input (and hence the output) is a palette image.

I have built these with IM 6.8.9-6 Q32 HDRI. I don't know what Fred has used.

For example, replacelast.c (at http://im.snibgo.com/customim.htm#replacelast.c ) is a trivial module that replaces the image with one of the same size, but green.

Code: Select all

%IMDEV%convert rose: -process replacelast roseRL1.png
This result is correct:

Image

Code: Select all

%IMDEV%convert rose: roseRL.gif
Image

Code: Select all

%IMDEV%convert roseRL.gif -process replacelast roseRL2.png
This result is incorrect. Every pixel is nearly black, (43,47,30) out of 255:

Image

The problem also occurs in other modules, where I use SetPixelRed() etc, with QuantumRange values. The common factor in the problem is a palette input file. A workaround is "-type truecolor" to prevent the output from being palette.

If I should be doing something else in my code to prevent the problem, I'm happy to do it. But I hope my code doesn't need to worry about whether the image is palette.

Re: Process modules and palettes

Posted: 2014-09-11T13:25:36-07:00
by magick
Not a bug, you either need to operate directly on the image colormap or promote your image from PseudoClass to DirectClass. For example,
  • if (SetImageStorageClass(my_image,DirectClass) == MagickFalse)
    perror("rut row");
    /* modify your rgba pixels here. */

Re: Process modules and palettes

Posted: 2014-09-11T13:57:01-07:00
by snibgo
Ah yes, I had seen "SetImageStorageClass(my_image,DirectClass)" in various places, and couldn't see what it was doing. Thanks, that cures the problem. It makes a palette output with the correct colour. I'll amend my code on that page.

[Mod note: the bug was in my understanding, so I'm moving this to the Developers forum.]