Loading image with Magick++, displaying with Qt
Hi, I have some problems using Magick++ with Qt. It's almost working, but almost in this case is not acceptable.
Code:
Magick::Image image;
try {
image.read(qPrintable(fileName));
}
catch (Magick::Exception &error_) {
}
Magick::Blob blob;
image.write(&blob, "XPM");
pixmap.loadFromData((char*)blob.data(), "XPM");
return pixmap;
This code does it's thing, but...
Code:
image.write(&blob, "XPM");
takes 4 seconds, and the displayed image looks like lost some of it's quality.
Code:
Magick::Image image;
try {
image.read(qPrintable(fileName));
}
catch (Magick::Exception &error_) {
}
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());
}
}
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?
Re: Loading image with Magick++, displaying with Qt
why are you using redQuantum() instead of red()?
Re: Loading image with Magick++, displaying with Qt
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.
Re: Loading image with Magick++, displaying with Qt
probably due to format mis-match.
Re: Loading image with Magick++, displaying with Qt
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.
Re: Loading image with Magick++, displaying with Qt
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.