This was a quite easy task in ImageMagick 6, just getConstPixels(), ColorRGB and you are done.
But I'm unable to do the same task with ImageMagick 7, I got an ugly mostly pink something.
What am I doing wrong?
QImage
convert( const Magick::Image & img )
{
QImage qimg( static_cast< int > ( img.columns() ),
static_cast< int > ( img.rows() ), QImage::Format_RGB888 );
using Quantum = MagickCore::Quantum;
const Quantum * pixels;
for( int y = 0; y < qimg.height(); ++y)
{
pixels = img.getConstPixels( 0, y, static_cast< std::size_t > ( qimg.width() ), 1 );
for( int x = 0; x < qimg.width(); ++x )
{
int red = 0;
int green = 0;
int blue = 0;
if( MagickCore::GetPixelRedTraits( img.constImage() ) )
red = ( (double) GetPixelRed( img.constImage(), pixels ) /
(double) QuantumRange ) * 255;
if( MagickCore::GetPixelGreenTraits( img.constImage() ) )
green = ( (double) GetPixelGreen( img.constImage(), pixels ) /
(double) QuantumRange ) * 255;
if( MagickCore::GetPixelBlueTraits( img.constImage() ) )
blue = ( (double) GetPixelBlue( img.constImage(), pixels ) /
(double) QuantumRange ) * 255;
qimg.setPixel( x, y, QColor( red, green, blue ).rgb() );
pixels += MagickCore::GetPixelChannels( img.constImage() );
}
}
return qimg;
}
Thank you.
As I can guess, in ImageMagick 7 something wrong with touching pixel by X, Y. Am I right?


I have no clue why the above code doesn't work, but I found a following solution: