Page 1 of 1

RGB Triplets

Posted: 2010-02-25T01:17:22-07:00
by steveq
Hey All,

I have an image in memory and I want to create a RGB triplet (RGBRGBRGBRGB etc) buffer in memory.

I have the following code:

Code: Select all

			Color clr;

			img.depth( 8 );

			clr = img.pixelColor( 100, 100 );

			unsigned short red = clr.redQuantum();
			unsigned short green = clr.greenQuantum();
			unsigned short blue = clr.blueQuantum();
The values I am being returned are >255 which I thought that given the image is 8bpp, 255 would be the maximum value I could receive?

I have 2 questions:

1) Is there an easy way to get a RGB triplet buffer that represents the image?
2) If not, why are the values I am getting so large? Am I geting the data correctly?

Thanks heaps for your help,

Steve Q.

Re: RGB Triplets

Posted: 2010-02-25T05:45:20-07:00
by magick
Internally the pixel intensities are stored at the depth of your instance of ImageMagick. If its Q16, pixel values range from 0-65535 even if the image depth is 8. Simply divide by 257 to get the equivalent 8-bit depth. You can force a range from 0-255 by building ImageMagick at a quantum depth of 8.

Re: RGB Triplets

Posted: 2010-02-25T20:49:10-07:00
by steveq
Ahhh... makes sense... thanks again magick.

:-)

Steve Q