Greetings,
I've been pulling my hair trying to figure how to either enable QT to load exr/hdr images or simply to convert exr/hdr data to fit into a QImage. I'd definitely prefer the former but manual conversion would do just fine.
thank you,
Greetings,
I've been pulling my hair trying to figure how to either enable QT to load exr/hdr images or simply to convert exr/hdr data to fit into a QImage. I'd definitely prefer the former but manual conversion would do just fine.
thank you,
Last edited by neosettler; 10th April 2019 at 05:31.
You need to find a library that provides a Qt Image Plugin for the format.
A quick Google search got me these two
https://github.com/AardmanCGI/qt4-exr-plugin
https://api.kde.org/frameworks/kimag...tml/index.html
Cheers,
_
Tank you for your suggestion Anda, I should have mentioned that I'm using QT 5.12 on Windows 10.
I've came across those two as well. The exr-plugin is for Qt4 and I doubt KDE could be compiled on Windows without pulling teeth. Plus, their documentation is clearly outdated so I'm a little hesitant to say the least.
Here is what I got so far:
GetPixels() is from an EXR image loaded with FreeImage library (96-bit : 3 x 32-bit IEEE floating point). While the top third of the image is correct, the bottom 2/3 is black. I must be missing something very obvious!?Qt Code:
uint l_h = m_ZImage->GetHeight(); uint l_w = m_ZImage->GetWidth(); float *l_data = (float*)m_ZImage->GetPixels(); /// From uchar. uchar *l_pixels = m_QImage.bits(); for (uint i = 0; i < l_h; ++i) { for (uint j = 0; j < l_w; ++j) { uint l_id = (i * l_w) + j; l_pixels[l_id] = uchar(l_data[l_id] * 255); l_id++; l_pixels[l_id] = uchar(l_data[l_id] * 255); l_id++; l_pixels[l_id] = uchar(l_data[l_id] * 255); } }To copy to clipboard, switch view to plain text mode
Ah, I see.
Still could be very similar code for Qt5, not sure if the image plugin API has changed at all.
I don't see a reason why a library of Qt image plugins would be problematic on Windows.
It is unlikely that libraries used by these plugins are not also available for Windows and cmake is usually quite capable of finding libs even on Windows.
Strange.
Maybe try a single loop? Both arrays should have the same number of elements.
Cheers,
_
I was able to compile a similiar code, i think it was the qt4 code, with qt5 and the image is shown. But reading the file is very slow (2 seconds) in comparison to a png file (100ms).
I think this part is their it is very slow. Does anybody have an idea to optimize it here?
Qt Code:
int width, height; Imf::RgbaInputFile file(istr); Imath::Box2i dw = file.dataWindow(); width = dw.max.x - dw.min.x + 1; height = dw.max.y - dw.min.y + 1; Imf::Array2D<Imf::Rgba> pixels; pixels.resizeErase(height, width); file.setFrameBuffer(&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width); file.readPixels(dw.min.y, dw.max.y); if (image.isNull()) { return false; } // somehow copy pixels into image for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // copy pixels(x,y) into image(x,y) image.setPixel(x, y, RgbaToQrgba(pixels[y][x])); } } *outImage = image;To copy to clipboard, switch view to plain text mode
Are you sure this line is correct? It looks like you are passing a pointer to an address -before- the start of the pixels array...file.setFrameBuffer(&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);
You can use one of the QImage constructors that takes a pointer to a data buffer, width, height, and format to create the QImage directly from the data, without having to assign pixel-by-pixel. However, as the documentation says, the data buffer must be valid for the lifetime of the QImage - the QImage does not make a deep copy of the data buffer.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Thanks for the fast answer.
I tried the code from here: https://cgit.kde.org/kimageformats.g...ormats/exr.cpp (bool EXRHandler::read(QImage *outImage))
So, it seemed valid for me because it is used in kde. But I will try your suggestion to directly create the QImage.
Well I assume that code works if it is part of KDE. But if your image is large, then setting pixel-by-pixel will be slow, as you have seen.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks