Results 1 to 10 of 10

Thread: OpenEXR to QImage

  1. #1
    Join Date
    Feb 2014
    Posts
    24
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default OpenEXR to QImage

    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 06:31.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenEXR to QImage

    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,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    24
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: OpenEXR to QImage

    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.

  4. #4
    Join Date
    Feb 2014
    Posts
    24
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: OpenEXR to QImage

    Here is what I got so far:

    Qt Code:
    1. uint l_h = m_ZImage->GetHeight();
    2. uint l_w = m_ZImage->GetWidth();
    3. float *l_data = (float*)m_ZImage->GetPixels(); /// From uchar.
    4. m_QImage = QImage(l_w, l_h, QImage::Format_RGB888);
    5. uchar *l_pixels = m_QImage.bits();
    6.  
    7. for (uint i = 0; i < l_h; ++i)
    8. {
    9. for (uint j = 0; j < l_w; ++j)
    10. {
    11. uint l_id = (i * l_w) + j;
    12. l_pixels[l_id] = uchar(l_data[l_id] * 255); l_id++;
    13. l_pixels[l_id] = uchar(l_data[l_id] * 255); l_id++;
    14. l_pixels[l_id] = uchar(l_data[l_id] * 255);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    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!?

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenEXR to QImage

    Quote Originally Posted by neosettler View Post
    The exr-plugin is for Qt4
    Ah, I see.

    Still could be very similar code for Qt5, not sure if the image plugin API has changed at all.

    Quote Originally Posted by neosettler View Post
    I doubt KDE could be compiled on Windows without pulling teeth
    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.

    Quote Originally Posted by neosettler View Post
    While the top third of the image is correct, the bottom 2/3 is black. I must be missing something very obvious!?
    Strange.

    Maybe try a single loop? Both arrays should have the same number of elements.

    Cheers,
    _

  6. #6
    Join Date
    Jul 2014
    Posts
    32
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: OpenEXR to QImage

    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:
    1. int width, height;
    2.  
    3. K_IStream istr(device(), QByteArray());
    4. Imf::RgbaInputFile file(istr);
    5. Imath::Box2i dw = file.dataWindow();
    6.  
    7. width = dw.max.x - dw.min.x + 1;
    8. height = dw.max.y - dw.min.y + 1;
    9.  
    10. Imf::Array2D<Imf::Rgba> pixels;
    11. pixels.resizeErase(height, width);
    12.  
    13. file.setFrameBuffer(&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);
    14. file.readPixels(dw.min.y, dw.max.y);
    15.  
    16. QImage image(width, height, QImage::Format_RGB32);
    17. if (image.isNull()) {
    18. return false;
    19. }
    20.  
    21. // somehow copy pixels into image
    22. for (int y = 0; y < height; y++) {
    23. for (int x = 0; x < width; x++) {
    24. // copy pixels(x,y) into image(x,y)
    25. image.setPixel(x, y, RgbaToQrgba(pixels[y][x]));
    26. }
    27. }
    28.  
    29. *outImage = image;
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: OpenEXR to QImage

    file.setFrameBuffer(&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);
    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...

    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.

  8. #8
    Join Date
    Jul 2014
    Posts
    32
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: OpenEXR to QImage

    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.

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: OpenEXR to 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.

  10. #10
    Join Date
    Jul 2014
    Posts
    32
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: OpenEXR to QImage

    Quote Originally Posted by d_stranz View Post
    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.
    Yes, loading the file works but it is very slow. I have loaded a 4K image. Loading the same image as png (similar file size as well) takes only 50-100ms.

Similar Threads

  1. QImage contains smaller QImage
    By Ini in forum General Programming
    Replies: 5
    Last Post: 31st May 2016, 18:11
  2. How to add new QImage to the left side of old QImage??
    By ganapathi in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2016, 09:54
  3. How to enable OpenEXR support in QT on windows
    By jho in forum Installation and Deployment
    Replies: 2
    Last Post: 9th March 2015, 12:18
  4. Replies: 5
    Last Post: 16th May 2011, 22:15
  5. Replies: 3
    Last Post: 15th March 2006, 12:44

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.