Effect of MagickSetImageColormapColor?
Posted: 2006-10-14T15:14:29-07:00
I'm using windows binary installation of 6.2.9-8.
I've written a C program which uses MagickWand to extract part of a GIF image. It reads in the GIF (which has 64 colours), changes it to a grayscale image and then quantizes it to 16 colours. I then use MagickSetImageColormapColor to force the first colour in the map to pure black and the last colour in the map to pure white. The program then crops the image and writes it out.
If I do a histogram of the image before setting the map colours, the first colour index is rgb(2,2,2). If I do a histogram of the image after setting colour index zero to black, the histogram still reports that the colour is rgb(2,2,2).
The file when written to disk has the first colour set to pure black.
This is the sequence of events:
So it would seem that the colours in the image in memory are directly affected by MagickSetImageType and MagickQuantizeImage but that MagickSetImageColormapColor only takes effect when the image is written to disk.
Why doesn't MagickSetImageColormapColor take immediate effect like the others and how do I make it do that?
Thanks
Pete
I've written a C program which uses MagickWand to extract part of a GIF image. It reads in the GIF (which has 64 colours), changes it to a grayscale image and then quantizes it to 16 colours. I then use MagickSetImageColormapColor to force the first colour in the map to pure black and the last colour in the map to pure white. The program then crops the image and writes it out.
If I do a histogram of the image before setting the map colours, the first colour index is rgb(2,2,2). If I do a histogram of the image after setting colour index zero to black, the histogram still reports that the colour is rgb(2,2,2).
The file when written to disk has the first colour set to pure black.
This is the sequence of events:
Code: Select all
identify of the original image reports:
293.gif GIF 300x918 300x918+0+0 PseudoClass 64c 8-bit 46.0059kb
in the program:
status=MagickReadImage(m_wand,file_name);
// Histogram shows 64 colours. Index 0 is rgb(0,0,0)
MagickSetImageType(m_wand, GrayscaleType);
// Histogram shows 60 colours. Index 0 is rgb(0,0,0)
MagickQuantizeImage(m_wand, 16, GRAYColorspace, 0 , 0, 0);
// Histogram shows 16 colours. Index 0 is rgb(2,2,2)
// Now force index 0 to black and last index to white
// nc is the number of colours returned by MagickGetImageHistogram
p_wand = NewPixelWand();
PixelSetColor(p_wand,"rgb(255,255,255)");
MagickSetImageColormapColor(m_wand,nc-1,p_wand);
PixelSetColor(p_wand,"rgb(0,0,0)");
MagickSetImageColormapColor(m_wand,0,p_wand);
p_wand = DestroyPixelWand(p_wand);
// Histogram shows 16 colours. Index 0 is still rgb(2,2,2)
// Crop the image, fix up virtual page in the GIF and write to a file
MagickCropImage(m_wand,cw,ch,cx,cy);
MagickSetImagePage(m_wand,cw,ch,0,0);
MagickWriteImage(m_wand,"atest.gif");
// Histogram shows 16 colours. Index 0 is still rgb(2,2,2) in memory
// Looking at the output image (atest.gif) with PSP 9 shows that colour 0 is rgb(0,0,0)
Why doesn't MagickSetImageColormapColor take immediate effect like the others and how do I make it do that?
Thanks
Pete