0

I try porting code with using ImageMagick-7.0.0-Q16-HDRI.

This code work with ImageMagick-6.9.1-Q16:

QString ImageMagick::fromQImage(const QImage &qimage){
    if (!qimage.size().isValid()) return "ImageMagick::fromQImage - Empty Qimage";
    image = Magick::Image(Magick::Geometry(qimage.width(), qimage.height()), Magick::ColorRGB(0.5, 0.2, 0.3));
    double scale = 1 / 255.0;
    image.modifyImage();
    Magick::PixelPacket *pixels;
    Magick::ColorRGB mgc;
    for (int y = 0; y < qimage.height(); y++) {
        pixels = image.setPixels(0, y, image.columns(), 1);
        for (int x = 0; x < qimage.width(); x++) {
            QColor pix = qimage.pixel(x, y);
            // *pixels++ = Magick::ColorRGB(256 * pix.red(), 256 * pix.green(), 256 * pix.blue());
            mgc.red(scale *pix.red());
            mgc.green(scale *pix.green());
            mgc.blue(scale *pix.blue());
            // *pixels++ = Magick::ColorRGB(scale *pix.red(), scale * pix.green(), scale * pix.blue());
            pixels[x] = mgc;
        }
        image.syncPixels();
    }
    return "";
}

Now I must use by http://www.imagemagick.org/script/porting.php instead PixelPacket:

MagickCore::Quantum *pixels;

Where in some case:

  • pixels[0]- red channel of pixel
  • pixels[1]- green channel of pixel
  • pixels[2]- blue channel of pixel

How will work with SetPixelRed()... instead of pixels[x] = mgc;

MagickCore::SetPixelRed((MagickCore::Image*)&image,scale*pix.red(),pixels+x*3);
MagickCore::SetPixelGreen((MagickCore::Image*)&image,scale*pix.green(),pixels+x*3);
MagickCore::SetPixelBlue((MagickCore::Image*)&image,scale*pix.blue(),pixels+x*3);

But it right now is?

Found next solution:

size_t imageQuantum = MAGICKCORE_QUANTUM_DEPTH;
size_t toFloatQuantum=(pow(2,imageQuantum)-1);
size_t imageChanells=image.channels();

...

pixels[x*imageChanells]=mgc.red()*toFloatQuantum;
pixels[x*imageChanells+1]=mgc.green()*toFloatQuantum;
pixels[x*imageChanells+2]=mgc.blue()*toFloatQuantum;
0

1 Answer 1

0

This is a really good question, but I think you're attacking this problem from the wrong angle.

If Quantum is returned from Magick::Pixels.get then just apply QColor directly to the value, and sync

Magick::Image img(Magick::Geometry(2,2), Magick::Color("white"));
img.modifyImage();
Magick::Pixels view(img);
Magick::Quantum * pixels = view.get(0, 0, 2, 2);
int x,y;
for (y= 0; y < 2 ; y++ ) {
    for (x = 0 ; x < 2 ; x++ ) {
        // As we starting the pixels as white, we can
        // leverage multiplication assignment (*=) operator.
        *pixels++ *= pix.red()  / 255.0; // Red
        *pixels++ *= pix.green()/ 255.0; // Green
        *pixels++ *= pix.blue() / 255.0; // Blue
    }
}
view.sync()

No need to invoke any additional class(es) from MagickCore

4
  • Magick::PixelPacket *pixels; // error C2038 PixelPacket : is not member of 'Magick' view.get(... - return array of Quantums Magick::Pixels Quantum *get(const ::ssize_t x_,const ::ssize_t y_, const size_t columns_,const size_t rows_);
    – lexxai
    Sep 11, 2015 at 18:26
  • Argh, I'm an idiot for not running my own code. I'll updated the answer. Sep 11, 2015 at 19:34
  • Thanks. Can be Quantum value more Q16 65535 ? I have pixel values after filter AdaptiveSharp (Radius 4, sigma 1) : RGBpixel 68556.8 75715.5 69944.4
    – lexxai
    Sep 11, 2015 at 20:53
  • @lexxai Can't say. Better jump over to official forums. This might be handled in application, or undefined behavior. Sep 14, 2015 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.