handle RGB16 in replaceColors()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-01-01 03:00:47 +02:00
parent e166aa922a
commit 46102ae26f

View file

@ -52,11 +52,32 @@ inline static QImage replaceColors(const QImage &source, const QMap<QRgb, QRgb>
QImage result(source);
const int bpl = result.bytesPerLine();
uchar* imagebits = result.bits();
for (int h = 0; h < source.height(); h++) {
uchar* scan = QFAST_SCAN_LINE(imagebits, bpl, h);
for (int w = 0; w < source.width(); w++) {
const QRgb pixel = source.pixel(w, h);
((uint *)scan)[w] = colormap.value(pixel, pixel);
switch (result.format()) {
case QImage::Format_RGB32:
case QImage::Format_ARGB32:
case QImage::Format_ARGB32_Premultiplied: {
for (int h = 0; h < source.height(); h++) {
uchar* scan = QFAST_SCAN_LINE(imagebits, bpl, h);
for (int w = 0; w < source.width(); w++) {
const QRgb pixel = source.pixel(w, h);
((uint *)scan)[w] = colormap.value(pixel, pixel);
}
}
break;
}
case QImage::Format_RGB16: {
for (int h = 0; h < source.height(); h++) {
uchar* scan = QFAST_SCAN_LINE(imagebits, bpl, h);
for (int w = 0; w < source.width(); w++) {
const QRgb pixel = source.pixel(w, h);
((quint16 *)scan)[w] = qt_colorConvert<quint16, quint32>(colormap.value(pixel, pixel), 0);
}
}
break;
}
default: {
Q_ASSERT_X(false, "replaceColors", "internal error");
break;
}
}
return result;