mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-05-28 00:30:23 -04:00
ScanlineConverter: fix indexed conversion and support for source depth less than 24 bits
This commit is contained in:
parent
f065104b72
commit
9f7b1b8dee
BIN
autotests/read/exr/gray.exr
Normal file
BIN
autotests/read/exr/gray.exr
Normal file
Binary file not shown.
BIN
autotests/read/exr/gray.png
Normal file
BIN
autotests/read/exr/gray.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
@ -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);
|
||||
}
|
||||
_convBuffer = _tmpBuffer.convertToFormat(_targetFormat);
|
||||
tmp.setColorSpace(cs);
|
||||
tmp.convertToColorSpace(_colorSpace);
|
||||
}
|
||||
_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;
|
||||
|
Loading…
Reference in New Issue
Block a user