Fix drawCachedGlyphs on RGBA8888

drawCachedGlyphs draws with the wrong color on RGBA8888. The issue
is that the draw routines bitmapblit_quint32 and alphamapblit_quint32
while safe to use on rgba formats, needs to have the input color
converted.

This patch adds small wrapper functions for bitmapblit and alphamapblit
that converts the formats. Two tests are extended to ensure we have
test coverage.

Change-Id: I5f99f3795eba46a69d4df5b167e6099024e9a060
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
This commit is contained in:
Allan Sandfeld Jensen 2014-02-07 16:52:00 +01:00 committed by The Qt Project
parent 08cbbde617
commit b1a882f178
5 changed files with 87 additions and 44 deletions

View File

@ -5605,7 +5605,7 @@ static void qt_gradient_quint16(int count, const QSpan *spans, void *userData)
}
}
inline static void qt_bitmapblit_quint32(QRasterBuffer *rasterBuffer,
inline static void qt_bitmapblit_argb32(QRasterBuffer *rasterBuffer,
int x, int y, quint32 color,
const uchar *map,
int mapWidth, int mapHeight, int mapStride)
@ -5614,6 +5614,15 @@ inline static void qt_bitmapblit_quint32(QRasterBuffer *rasterBuffer,
map, mapWidth, mapHeight, mapStride);
}
inline static void qt_bitmapblit_rgba8888(QRasterBuffer *rasterBuffer,
int x, int y, quint32 color,
const uchar *map,
int mapWidth, int mapHeight, int mapStride)
{
qt_bitmapblit_template<quint32>(rasterBuffer, x, y, ARGB2RGBA(color),
map, mapWidth, mapHeight, mapStride);
}
inline static void qt_bitmapblit_quint16(QRasterBuffer *rasterBuffer,
int x, int y, quint32 color,
const uchar *map,
@ -5725,11 +5734,11 @@ static inline void grayBlendPixel(quint32 *dst, int coverage, int sr, int sg, in
}
#endif
static void qt_alphamapblit_quint32(QRasterBuffer *rasterBuffer,
int x, int y, quint32 color,
const uchar *map,
int mapWidth, int mapHeight, int mapStride,
const QClipData *clip)
static void qt_alphamapblit_argb32(QRasterBuffer *rasterBuffer,
int x, int y, quint32 color,
const uchar *map,
int mapWidth, int mapHeight, int mapStride,
const QClipData *clip)
{
const quint32 c = color;
const int destStride = rasterBuffer->bytesPerLine() / sizeof(quint32);
@ -5820,10 +5829,19 @@ static void qt_alphamapblit_quint32(QRasterBuffer *rasterBuffer,
}
}
static void qt_alphargbblit_quint32(QRasterBuffer *rasterBuffer,
int x, int y, quint32 color,
const uint *src, int mapWidth, int mapHeight, int srcStride,
const QClipData *clip)
static void qt_alphamapblit_rgba8888(QRasterBuffer *rasterBuffer,
int x, int y, quint32 color,
const uchar *map,
int mapWidth, int mapHeight, int mapStride,
const QClipData *clip)
{
qt_alphamapblit_argb32(rasterBuffer, x, y, ARGB2RGBA(color), map, mapWidth, mapHeight, mapStride, clip);
}
static void qt_alphargbblit_argb32(QRasterBuffer *rasterBuffer,
int x, int y, quint32 color,
const uint *src, int mapWidth, int mapHeight, int srcStride,
const QClipData *clip)
{
const quint32 c = color;
@ -5965,27 +5983,27 @@ DrawHelper qDrawHelper[QImage::NImageFormats] =
{
blend_color_argb,
qt_gradient_argb32,
qt_bitmapblit_quint32,
qt_alphamapblit_quint32,
qt_alphargbblit_quint32,
qt_bitmapblit_argb32,
qt_alphamapblit_argb32,
qt_alphargbblit_argb32,
qt_rectfill_argb32
},
// Format_ARGB32,
{
blend_color_generic,
qt_gradient_argb32,
qt_bitmapblit_quint32,
qt_alphamapblit_quint32,
qt_alphargbblit_quint32,
qt_bitmapblit_argb32,
qt_alphamapblit_argb32,
qt_alphargbblit_argb32,
qt_rectfill_nonpremul_argb32
},
// Format_ARGB32_Premultiplied
{
blend_color_argb,
qt_gradient_argb32,
qt_bitmapblit_quint32,
qt_alphamapblit_quint32,
qt_alphargbblit_quint32,
qt_bitmapblit_argb32,
qt_alphamapblit_argb32,
qt_alphargbblit_argb32,
qt_rectfill_argb32
},
// Format_RGB16
@ -6049,42 +6067,39 @@ DrawHelper qDrawHelper[QImage::NImageFormats] =
{
blend_color_generic,
blend_src_generic,
qt_bitmapblit_quint32,
qt_bitmapblit_rgba8888,
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
qt_alphamapblit_quint32,
qt_alphargbblit_quint32,
qt_alphamapblit_rgba8888,
#else
0,
0,
#endif
0,
qt_rectfill_rgba
},
// Format_RGBA8888
{
blend_color_generic,
blend_src_generic,
qt_bitmapblit_quint32,
qt_bitmapblit_rgba8888,
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
qt_alphamapblit_quint32,
qt_alphargbblit_quint32,
qt_alphamapblit_rgba8888,
#else
0,
0,
#endif
0,
qt_rectfill_nonpremul_rgba
},
// Format_RGB8888_Premultiplied
{
blend_color_generic,
blend_src_generic,
qt_bitmapblit_quint32,
qt_bitmapblit_rgba8888,
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
qt_alphamapblit_quint32,
qt_alphargbblit_quint32,
qt_alphamapblit_rgba8888,
#else
0,
0,
#endif
0,
qt_rectfill_rgba
}
};
@ -6173,9 +6188,9 @@ void qInitDrawhelperAsm()
qDrawHelper[QImage::Format_ARGB32].bitmapBlit = qt_bitmapblit32_avx;
qDrawHelper[QImage::Format_ARGB32_Premultiplied].bitmapBlit = qt_bitmapblit32_avx;
qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_avx;
qDrawHelper[QImage::Format_RGBX8888].bitmapBlit = qt_bitmapblit32_avx;
qDrawHelper[QImage::Format_RGBA8888].bitmapBlit = qt_bitmapblit32_avx;
qDrawHelper[QImage::Format_RGBA8888_Premultiplied].bitmapBlit = qt_bitmapblit32_avx;
qDrawHelper[QImage::Format_RGBX8888].bitmapBlit = qt_bitmapblit8888_avx;
qDrawHelper[QImage::Format_RGBA8888].bitmapBlit = qt_bitmapblit8888_avx;
qDrawHelper[QImage::Format_RGBA8888_Premultiplied].bitmapBlit = qt_bitmapblit8888_avx;
extern void qt_scale_image_argb32_on_argb32_avx(uchar *destPixels, int dbpl,
const uchar *srcPixels, int sbpl,
@ -6198,9 +6213,9 @@ void qInitDrawhelperAsm()
qDrawHelper[QImage::Format_ARGB32].bitmapBlit = qt_bitmapblit32_sse2;
qDrawHelper[QImage::Format_ARGB32_Premultiplied].bitmapBlit = qt_bitmapblit32_sse2;
qDrawHelper[QImage::Format_RGB16].bitmapBlit = qt_bitmapblit16_sse2;
qDrawHelper[QImage::Format_RGBX8888].bitmapBlit = qt_bitmapblit32_sse2;
qDrawHelper[QImage::Format_RGBA8888].bitmapBlit = qt_bitmapblit32_sse2;
qDrawHelper[QImage::Format_RGBA8888_Premultiplied].bitmapBlit = qt_bitmapblit32_sse2;
qDrawHelper[QImage::Format_RGBX8888].bitmapBlit = qt_bitmapblit8888_sse2;
qDrawHelper[QImage::Format_RGBA8888].bitmapBlit = qt_bitmapblit8888_sse2;
qDrawHelper[QImage::Format_RGBA8888_Premultiplied].bitmapBlit = qt_bitmapblit8888_sse2;
extern void qt_scale_image_argb32_on_argb32_sse2(uchar *destPixels, int dbpl,
const uchar *srcPixels, int sbpl,

View File

@ -60,6 +60,7 @@
#define qt_memfill32_sse2 qt_memfill32_avx
#define qt_memfill16_sse2 qt_memfill16_avx
#define qt_bitmapblit32_sse2 qt_bitmapblit32_avx
#define qt_bitmapblit8888_sse2 qt_bitmapblit8888_avx
#define qt_bitmapblit16_sse2 qt_bitmapblit16_avx
#define QSimdSse2 QSimdAvx
#define qt_fetch_radial_gradient_sse2 qt_fetch_radial_gradient_avx

View File

@ -470,6 +470,13 @@ void qt_bitmapblit32_sse2(QRasterBuffer *rasterBuffer, int x, int y,
}
}
void qt_bitmapblit8888_sse2(QRasterBuffer *rasterBuffer, int x, int y,
quint32 color,
const uchar *src, int width, int height, int stride)
{
qt_bitmapblit32_sse2(rasterBuffer, x, y, ARGB2RGBA(color), src, width, height, stride);
}
void qt_bitmapblit16_sse2(QRasterBuffer *rasterBuffer, int x, int y,
quint32 color,
const uchar *src, int width, int height, int stride)

View File

@ -63,6 +63,9 @@ void qt_memfill16_sse2(quint16 *dest, quint16 value, int count);
void qt_bitmapblit32_sse2(QRasterBuffer *rasterBuffer, int x, int y,
quint32 color,
const uchar *src, int width, int height, int stride);
void qt_bitmapblit8888_sse2(QRasterBuffer *rasterBuffer, int x, int y,
quint32 color,
const uchar *src, int width, int height, int stride);
void qt_bitmapblit16_sse2(QRasterBuffer *rasterBuffer, int x, int y,
quint32 color,
const uchar *src, int width, int height, int stride);
@ -85,6 +88,9 @@ void qt_memfill16_avx(quint16 *dest, quint16 value, int count);
void qt_bitmapblit32_avx(QRasterBuffer *rasterBuffer, int x, int y,
quint32 color,
const uchar *src, int width, int height, int stride);
void qt_bitmapblit8888_avx(QRasterBuffer *rasterBuffer, int x, int y,
quint32 color,
const uchar *src, int width, int height, int stride);
void qt_bitmapblit16_avx(QRasterBuffer *rasterBuffer, int x, int y,
quint32 color,
const uchar *src, int width, int height, int stride);

View File

@ -87,6 +87,7 @@ private slots:
void plainTextVsRichText();
void setPenPlainText_data();
void setPenPlainText();
void setPenRichText();
void richTextOverridesPen();
@ -106,6 +107,8 @@ private:
QImage const m_whiteSquare;
};
Q_DECLARE_METATYPE(QImage::Format);
void tst_QStaticText::initTestCase()
{
// a "blank" square; we compare against in our testfunctions to verify
@ -615,30 +618,41 @@ void tst_QStaticText::plainTextVsRichText()
QCOMPARE(imagePlainText, imageRichText);
}
void tst_QStaticText::setPenPlainText_data()
{
QTest::addColumn<QImage::Format>("format");
QTest::newRow("argb32pm") << QImage::Format_ARGB32_Premultiplied;
QTest::newRow("rgb32") << QImage::Format_RGB32;
QTest::newRow("rgba8888pm") << QImage::Format_RGBA8888_Premultiplied;
QTest::newRow("rgbx8888") << QImage::Format_RGBX8888;
}
void tst_QStaticText::setPenPlainText()
{
QFETCH(QImage::Format, format);
QFont font = QGuiApplication::font();
font.setStyleStrategy(QFont::NoAntialias);
QFontMetricsF fm(font);
QPixmap image(qCeil(fm.width("XXXXX")), qCeil(fm.height()));
QImage image(qCeil(fm.width("XXXXX")), qCeil(fm.height()), format);
image.fill(Qt::white);
{
QPainter p(&image);
p.setFont(font);
p.setPen(Qt::green);
p.setPen(Qt::yellow);
QStaticText staticText("XXXXX");
staticText.setTextFormat(Qt::PlainText);
p.drawStaticText(0, 0, staticText);
}
QImage img = image.toImage();
for (int x=0; x<img.width(); ++x) {
for (int y=0; y<img.height(); ++y) {
QRgb pixel = img.pixel(x, y);
for (int x=0; x<image.width(); ++x) {
for (int y=0; y<image.height(); ++y) {
QRgb pixel = image.pixel(x, y);
QVERIFY(pixel == QColor(Qt::white).rgba()
|| pixel == QColor(Qt::green).rgba());
|| pixel == QColor(Qt::yellow).rgba());
}
}
}