diff --git a/README.md b/README.md index 6de786d..3c2df74 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,12 @@ image formats. The following image formats have read-only support: - Animated Windows cursors (ani) +- Camera RAW images (arw, cr2, cr3, dcs, dng, ...) - Gimp (xcf) - OpenEXR (exr) - Photoshop documents (psd, psb, pdd, psdt) +- Radiance HDR (hdr) - Sun Raster (ras) -- Camera RAW images (arw, cr2, cr3, dcs, dng, ...) - Quite OK Image format (qoi) The following image formats have read and write support: diff --git a/autotests/read/hdr/rgb-landscape.png b/autotests/read/hdr/rgb-landscape.png index 1da6ff1..4a96be1 100755 Binary files a/autotests/read/hdr/rgb-landscape.png and b/autotests/read/hdr/rgb-landscape.png differ diff --git a/autotests/read/hdr/rgb-portrait.png b/autotests/read/hdr/rgb-portrait.png index 129cb98..1acc495 100644 Binary files a/autotests/read/hdr/rgb-portrait.png and b/autotests/read/hdr/rgb-portrait.png differ diff --git a/autotests/read/hdr/rgb.png b/autotests/read/hdr/rgb.png index 503abd9..7948b9e 100644 Binary files a/autotests/read/hdr/rgb.png and b/autotests/read/hdr/rgb.png differ diff --git a/src/imageformats/hdr.cpp b/src/imageformats/hdr.cpp index 136784a..1303fc3 100644 --- a/src/imageformats/hdr.cpp +++ b/src/imageformats/hdr.cpp @@ -9,11 +9,11 @@ #include "hdr_p.h" #include "util_p.h" +#include #include #include #include #include -#include #include @@ -27,15 +27,6 @@ namespace // Private. #define MINELEN 8 // minimum scanline length for encoding #define MAXELEN 0x7fff // maximum scanline length for encoding -static inline uchar ClipToByte(float value) -{ - if (value > 255.0f) { - return 255; - } - // else if (value < 0.0f) return 0; // we know value is positive. - return uchar(value); -} - // read an old style line from the hdr image file // if 'first' is true the first byte is already read static bool Read_Old_Line(uchar *image, int width, QDataStream &s) @@ -70,7 +61,7 @@ static bool Read_Old_Line(uchar *image, int width, QDataStream &s) return true; } -static void RGBE_To_QRgbLine(uchar *image, QRgb *scanline, int width) +static void RGBE_To_QRgbLine(uchar *image, float *scanline, int width) { for (int j = 0; j < width; j++) { // v = ldexp(1.0, int(image[3]) - 128); @@ -82,8 +73,12 @@ static void RGBE_To_QRgbLine(uchar *image, QRgb *scanline, int width) v = 1.0f / float(1 << -e); } - scanline[j] = qRgb(ClipToByte(float(image[0]) * v), ClipToByte(float(image[1]) * v), ClipToByte(float(image[2]) * v)); - + auto j4 = j * 4; + auto vn = v / 255.0f; + scanline[j4] = std::min(float(image[0]) * vn, 1.0f); + scanline[j4 + 1] = std::min(float(image[1]) * vn, 1.0f); + scanline[j4 + 2] = std::min(float(image[2]) * vn, 1.0f); + scanline[j4 + 3] = 1.0f; image += 4; } } @@ -95,7 +90,7 @@ static bool LoadHDR(QDataStream &s, const int width, const int height, QImage &i uchar code; // Create dst image. - img = imageAlloc(width, height, QImage::Format_RGB32); + img = imageAlloc(width, height, QImage::Format_RGBX32FPx4); if (img.isNull()) { qCDebug(HDRPLUGIN) << "Couldn't create image with size" << width << height << "and format RGB32"; return false; @@ -106,7 +101,7 @@ static bool LoadHDR(QDataStream &s, const int width, const int height, QImage &i uchar *image = (uchar *)lineArray.data(); for (int cline = 0; cline < height; cline++) { - QRgb *scanline = (QRgb *)img.scanLine(cline); + auto scanline = (float *)img.scanLine(cline); // determine scanline type if ((width < MINELEN) || (MAXELEN < width)) {