Process modules and palettes

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Process modules and palettes

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Process modules and palettes

Post 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. */
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Process modules and palettes

Post 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.]
snibgo's IM pages: im.snibgo.com
Post Reply