diff --git a/autotests/read/exr/gray.exr b/autotests/read/exr/gray.exr new file mode 100644 index 0000000..9ea4cce Binary files /dev/null and b/autotests/read/exr/gray.exr differ diff --git a/autotests/read/exr/gray.png b/autotests/read/exr/gray.png new file mode 100644 index 0000000..f442a21 Binary files /dev/null and b/autotests/read/exr/gray.png differ diff --git a/src/imageformats/scanlineconverter.cpp b/src/imageformats/scanlineconverter.cpp index a797818..f949900 100644 --- a/src/imageformats/scanlineconverter.cpp +++ b/src/imageformats/scanlineconverter.cpp @@ -60,20 +60,25 @@ const uchar *ScanLineConverter::convertedScanLine(const QImage &image, qint32 y) } if (image.width() != _tmpBuffer.width() || image.format() != _tmpBuffer.format()) { _tmpBuffer = QImage(image.width(), 1, image.format()); + _tmpBuffer.setColorTable(image.colorTable()); } if (_tmpBuffer.isNull()) { return nullptr; } std::memcpy(_tmpBuffer.bits(), image.constScanLine(y), std::min(_tmpBuffer.bytesPerLine(), image.bytesPerLine())); + auto tmp = _tmpBuffer; if (colorSpaceConversion) { auto cs = image.colorSpace(); if (!cs.isValid()) { cs = _defaultColorSpace; } - _tmpBuffer.setColorSpace(cs); - _tmpBuffer.convertToColorSpace(_colorSpace); + if (tmp.depth() < 24) { + tmp = tmp.convertToFormat(tmp.hasAlphaChannel() ? QImage::Format_ARGB32 : QImage::Format_RGB32); + } + tmp.setColorSpace(cs); + tmp.convertToColorSpace(_colorSpace); } - _convBuffer = _tmpBuffer.convertToFormat(_targetFormat); + _convBuffer = tmp.convertToFormat(_targetFormat); if (_convBuffer.isNull()) { return nullptr; } @@ -90,9 +95,6 @@ qsizetype ScanLineConverter::bytesPerLine() const bool ScanLineConverter::isColorSpaceConversionNeeded(const QImage &image, const QColorSpace &targetColorSpace, const QColorSpace &defaultColorSpace) { - if (image.depth() < 24) { // RGB 8 bit or grater only - return false; - } auto sourceColorSpace = image.colorSpace(); if (!sourceColorSpace.isValid()) { sourceColorSpace = defaultColorSpace;