PDA

View Full Version : Loading image with Magick++, displaying with Qt



RSX
28th April 2013, 15:33
Hi, I have some problems using Magick++ with Qt. It's almost working, but almost in this case is not acceptable.


Magick::Image image;
try {
image.read(qPrintable(fileName));
}
catch (Magick::Exception &error_) {
QMessageBox::warning(this, "Error!", QString("%1").arg(error_.what()));
return QPixmap();
}

Magick::Blob blob;
image.write(&blob, "XPM");

QPixmap pixmap;
pixmap.loadFromData((char*)blob.data(), "XPM");
return pixmap;
This code does it's thing, but...

image.write(&blob, "XPM");
takes 4 seconds, and the displayed image looks like lost some of it's quality.


Magick::Image image;
try {
image.read(qPrintable(fileName));
}
catch (Magick::Exception &error_) {
QMessageBox::warning(this, "Error!", QString("%1").arg(error_.what()));
return QPixmap();
}

QImage img(image.columns(), image.rows(), QImage::Format_RGB32);
Magick::ColorRGB rgb;
for (int x = 0; x < img.width(); x++) {
for (int y = 0; y < img.height(); y++) {
rgb = *image.getPixels(x, y, 1, 1);
QColor color(rgb.redQuantum(), rgb.greenQuantum(), rgb.blueQuantum());
img.setPixel(x, y, color.rgb());
}
}
return QPixmap::fromImage(img);

There's no noticeable delay now when loading image, but displayed image has wrong colors (gets blue-ish kinda).
I tested this code also with image 1x1 which had color (R: 183, G: 113, B: 51), but Magick++ returns it as (R: 113, G: 51, B: 51).

The problems might be more Magick++ related, but perhaps someone knows what's wrong or has managed to load image in other way without problems?

amleto
28th April 2013, 18:46
why are you using redQuantum() instead of red()?

RSX
28th April 2013, 20:29
It doesn't matter, red() returns 0.0 - 1.0 values, redQuantum() 0 - 255.

The second code actually works now, but had to recompile library with MAGICKCORE_QUANTUM_DEPTH 8. The first one now crashes program.

amleto
29th April 2013, 00:27
probably due to format mis-match.

ChrisW67
29th April 2013, 02:07
We have no idea what the original image is or what the output looks like. A bluish hue could come from the original, input colorspace conversion, dithering or an indexed palette. All happening in the Magick code.

RSX
29th April 2013, 13:42
In first code, the image doesn't matter, it just takes very very long to write image to BLOB. The displayed image slightly lost quality but wasn't bad afterall. In the second code I gave you original image and the output, it was image of 1 pixel: input (R: 183, G: 113, B: 51), output (R: 113, G: 51, B: 51). The second code works fine now, as I said in previous post.