summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qimage_conversions.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-02-04 12:41:17 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-02-13 18:27:17 +0000
commit9bf8cc1f185d3d39446a6911f4a694f274bb94c3 (patch)
tree5d05278dde15055624b37c7b51b37dd5d9a42f8a /src/gui/image/qimage_conversions.cpp
parent1b46872cde7fb50652f55bfe1e286e6af5124200 (diff)
qimage_conversions.cpp: keep shared copies of gray and alpha color tables
Since QVector is implicitly shared, don't re-generate the same two color tables all over again, but create them once and keep them around in a Q_GLOBAL_STATIC. Change-Id: I9a8d32021d8cc327264f2818a23beaae67fe3ee8 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/gui/image/qimage_conversions.cpp')
-rw-r--r--src/gui/image/qimage_conversions.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp
index 2a0bdeb7c1..50fad1566c 100644
--- a/src/gui/image/qimage_conversions.cpp
+++ b/src/gui/image/qimage_conversions.cpp
@@ -46,6 +46,22 @@
QT_BEGIN_NAMESPACE
+struct QDefaultColorTables
+{
+ QDefaultColorTables()
+ : gray(256), alpha(256)
+ {
+ for (int i = 0; i < 256; ++i) {
+ gray[i] = qRgb(i, i, i);
+ alpha[i] = qRgba(0, 0, 0, i);
+ }
+ }
+
+ QVector<QRgb> gray, alpha;
+};
+
+Q_GLOBAL_STATIC(QDefaultColorTables, defaultColorTables);
+
// table to flip bits
static const uchar bitflip[256] = {
/*
@@ -1952,11 +1968,7 @@ static void convert_Alpha8_to_Indexed8(QImageData *dest, const QImageData *src,
memcpy(dest->data, src->data, src->bytes_per_line * src->height);
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgba(0, 0, 0, i);
-
- dest->colortable = colors;
+ dest->colortable = defaultColorTables->alpha;
}
static void convert_Grayscale8_to_Indexed8(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
@@ -1966,22 +1978,15 @@ static void convert_Grayscale8_to_Indexed8(QImageData *dest, const QImageData *s
memcpy(dest->data, src->data, src->bytes_per_line * src->height);
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgb(i, i, i);
- dest->colortable = colors;
+ dest->colortable = defaultColorTables->gray;
}
static bool convert_Alpha8_to_Indexed8_inplace(QImageData *data, Qt::ImageConversionFlags)
{
Q_ASSERT(data->format == QImage::Format_Alpha8);
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgba(0, 0, 0, i);
-
- data->colortable = colors;
+ data->colortable = defaultColorTables->alpha;
data->format = QImage::Format_Indexed8;
return true;
@@ -1991,11 +1996,7 @@ static bool convert_Grayscale8_to_Indexed8_inplace(QImageData *data, Qt::ImageCo
{
Q_ASSERT(data->format == QImage::Format_Grayscale8);
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgb(i, i, i);
-
- data->colortable = colors;
+ data->colortable = defaultColorTables->gray;
data->format = QImage::Format_Indexed8;
return true;