Question about using GetImagePixels

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
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Question about using GetImagePixels

Post by rmagick »

In RMagick, before I call GetImagePixels and SyncImagePixels I call SetImageType to set the type to TrueColorType. I can't remember why I did this and now I'm wondering if it's necessary. So, should my code ensure that the image is TrueColorType before calling GetImagePixels? What if the image has an alpha channel?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Question about using GetImagePixels

Post by magick »

If you are going to introduce new colors into an image it is best to ensure the image is DirectClass before you update the pixels. Call
  • SetImageStorageClass(image,DirectClass);
Instead of SetImageType() because SetImageType() with a TrueColorType parameter converts the image to the RGB colorspace and turns off the alpha channel which is probably not what you want (in particular if the image happens to be alpha or if it is in the CMYK colorspace).
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: Question about using GetImagePixels

Post by rmagick »

Thanks for your advice! I thought that call looked fishy. I'll make the fix in RMagick asap.
Post Reply