Fix text drawing onto transparent ARGB32

We can not use the same blend routines for ARGB32 as we use for
ARGB32PM. It needs to blend transparent colors differently.

Pick-to: 6.5
Fixes: QTBUG-91262
Change-Id: I6b75fa8096b92452655dcad94478ae2a74415939
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
(cherry picked from commit bb854606ec8f95787dfd2a4d1b6bcaddbcf4d042)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Allan Sandfeld Jensen 2024-09-30 14:53:29 +02:00 committed by Qt Cherry-pick Bot
parent 25686af631
commit 1896424554
2 changed files with 28 additions and 2 deletions

View File

@ -6051,8 +6051,8 @@ DrawHelper qDrawHelper[] =
{
blend_color_generic,
qt_bitmapblit_argb32,
qt_alphamapblit_argb32,
qt_alphargbblit_argb32,
qt_alphamapblit_generic,
qt_alphargbblit_generic,
qt_rectfill_nonpremul_argb32
},
// Format_ARGB32_Premultiplied

View File

@ -280,6 +280,7 @@ private slots:
void fillPolygon();
void textOnArgb32();
void drawImageAtPointF();
void scaledDashes();
#if QT_CONFIG(raster_fp)
@ -5460,6 +5461,31 @@ void tst_QPainter::fillPolygon()
}
}
void tst_QPainter::textOnArgb32()
{
QImage backing(100, 20, QImage::Format_RGB32);
backing.fill(Qt::white);
QImage img(100, 20, QImage::Format_ARGB32);
img.fill(Qt::transparent); // Filled with transparent black
QPainter imagePainter(&img);
imagePainter.setPen(Qt::red);
imagePainter.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
imagePainter.setRenderHints(QPainter::TextAntialiasing);
imagePainter.drawText(img.rect(), Qt::AlignCenter,"Text example");
imagePainter.end();
imagePainter.begin(&backing);
imagePainter.drawImage(backing.rect(), img);
imagePainter.end();
for (int y = 0; y < backing.height(); ++y) {
for (int x = 0; x < backing.width(); ++x) {
const uint32_t px = backing.pixel(x, y);
// Red over white, should always be full red.
QCOMPARE(qRed(px), 255);
}
}
}
void tst_QPainter::drawImageAtPointF()
{
// Just test we do not crash