first.cpp:726:38: error: member reference base type 'const MagickCore::Quantum' (aka 'const float') is not a structure or union
unsigned char r = pixelsArr[ i ].red * 255 / QuantumRange;
~~~~~~~~~~~~~~^~~~
first.cpp:727:38: error: member reference base type 'const MagickCore::Quantum' (aka 'const float') is not a structure or union
unsigned char g = pixelsArr[ i ].redQuantum * 255 / QuantumRange;
How to convert this float (which called Quantum) to R/G/B components?
IM: is up to date, OS X 10.12.3.
Is the RGB order just goes like this in my pixelsArr?
const MagickCore::Quantum *pixelsArr = image->getConstPixels( 0, 0, _imgWidth, _imgHeight );
for ( unsigned int i = 0; i < _imgWidth * _imgHeight * 3; i += 3 ) {
for ( unsigned int i1 = 0; i1 < 2; i1++ ) {
unsigned char r = pixelsArr[ i + 0 ] * 255 / QuantumRange;
unsigned char g = pixelsArr[ i + 1 ] * 255 / QuantumRange;
unsigned char b = pixelsArr[ i + 2 ] * 255 / QuantumRange;
Am I right or not?
snibgo
wrote:
↑
2017-03-31T19:15:26-07:00
getConstPixels() is declared in Image.h. It returns "PixelPacket *", which is not the same thing as "Quantum *".
It doesn't look that it's the same thing:
Ah, you are using v7? getConstPixels() changed from v6. In v6, it returns PixelPacket*. In v7, it returns Quantum*.
When asking questions, please always state the version of IM you are using.
Sorry, I don't use Magick++ or MacickWand in v7. But you can see how getConstPixels is used, by an example in Image.cpp. You can call GetPixelInfoPixel to convert the returned Quantum* to an object of type PixelInfo.
The type PixelInfo is defined in MagickCore\pixel.h. This has element red, green, blue and many others.
for ( unsigned int j = 0; j < _height; j++ ) {
for ( unsigned int i = 0; i < _width; i++ ) {
Magick::Color c = image->pixelColor( i, j );
unsigned char r = c.quantumRed() * 255 / QuantumRange;
unsigned char g = c.quantumGreen() * 255 / QuantumRange;
unsigned char b = c.quantumBlue() * 255 / QuantumRange;
it's very usable way of getting a pixel color for me!