From f15c0b695aa851086fac04387ed336401e7a562f Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 13 May 2016 13:33:52 +0200 Subject: [PATCH] Optimize QImage checkForAlphaPixels This routine is often called to down-convert pixmaps and backing stores to RGB32. This patch replaces a comparison in each pixel, with a single AND in each pixel and a comparison at each line. The new form is also auto- vectorized by at least GCC. Change-Id: I3e07585a3ec12f888321d35da57ac99b561dbec4 Reviewed-by: Gunnar Sletta --- src/gui/image/qimage.cpp | 49 +++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 2911477d28..82ad9b1738 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -193,74 +193,81 @@ bool QImageData::checkForAlphaPixels() const break; case QImage::Format_ARGB32: case QImage::Format_ARGB32_Premultiplied: { - uchar *bits = data; + const uchar *bits = data; for (int y=0; y(bits)[x]; + has_alpha_pixels = (alphaAnd != 0xff000000); bits += bytes_per_line; } } break; case QImage::Format_RGBA8888: case QImage::Format_RGBA8888_Premultiplied: { - uchar *bits = data; + const uchar *bits = data; for (int y=0; y(bits)[x]; + has_alpha_pixels = (alphaAnd != 0xc0000000); bits += bytes_per_line; } } break; case QImage::Format_ARGB8555_Premultiplied: case QImage::Format_ARGB8565_Premultiplied: { - uchar *bits = data; - uchar *end_bits = data + bytes_per_line; + const uchar *bits = data; + const uchar *end_bits = data + bytes_per_line; for (int y=0; y(bits)[x]; + has_alpha_pixels = (alphaAnd != 0xf000); + bits += bytes_per_line; } } break;