RGB Triplets

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
steveq

RGB Triplets

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: RGB Triplets

Post 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.
steveq

Re: RGB Triplets

Post by steveq »

Ahhh... makes sense... thanks again magick.

:-)

Steve Q
Post Reply