Fix unneeded use of QImage invertPixels and createAlphaMask

The result of createAlphaMask was mostly overwritten and then inverted,
we can write the right values directly instead.

Change-Id: I3cdddcc74218a4058bddd20178733688607c8a01
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
bb10
Allan Sandfeld Jensen 2019-12-18 13:16:20 +01:00
parent 322e5b7f5e
commit 09f19e48ac
1 changed files with 2 additions and 9 deletions

View File

@ -615,13 +615,7 @@ bool ICOReader::write(QIODevice *device, const QVector<QImage> &images)
}
QImage maskImage(image.width(), image.height(), QImage::Format_Mono);
image = image.convertToFormat(QImage::Format_ARGB32);
if (image.hasAlphaChannel()) {
maskImage = image.createAlphaMask();
} else {
maskImage.fill(0xff);
}
maskImage = maskImage.convertToFormat(QImage::Format_Mono);
maskImage.fill(Qt::color1);
int nbits = 32;
int bpl_bmp = ((image.width()*nbits+31)/32)*4;
@ -671,7 +665,7 @@ bool ICOReader::write(QIODevice *device, const QVector<QImage> &images)
*b++ = qRed(*p);
*b++ = qAlpha(*p);
if (qAlpha(*p) > 0) // Even mostly transparent pixels must not be masked away
maskImage.setPixel(x, y, Qt::color1); // (i.e. createAlphaMask() takes away too much)
maskImage.setPixel(x, y, 0);
p++;
x++;
}
@ -679,7 +673,6 @@ bool ICOReader::write(QIODevice *device, const QVector<QImage> &images)
}
delete[] buf;
maskImage.invertPixels(); // seems as though it needs this
// NOTE! !! The mask is only flipped vertically - not horizontally !!
for (y = maskImage.height() - 1; y >= 0; y--)
buffer.write((char*)maskImage.scanLine(y), maskImage.bytesPerLine());