summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2016-07-22 11:13:41 +0200
committerEirik Aavitsland <eirik.aavitsland@qt.io>2016-07-27 11:46:11 +0000
commit7bf002c3b3f8009138fca217c7fa0c234aed21bd (patch)
tree1fa917d4c8bf0b5851d86d6397aa3dc9577e5781 /src
parent5b64b64717caca231d399a138e747bdded9c116c (diff)
Backwards compatibility fix: No default colormap for Mono QImages
This is a partial revert of a4e2f2e687ca7aec88ecf82f72d42ac61e17a5b9. That fix tried to avoid the risk of a crash in pixel() by ensuring Mono QImages created with external data also got a default color table. However, that broke usable behavior in existing code that was painting in Mono QImages using color0/color1. This commit reverts to the old behavior, and instead expands on the checking in pixel() so that lacking color table is handled gracefully for all indexed formats. Task-number: QTBUG-54827 Change-Id: I9164198bed9d20c4b12cdba40a31c141bef3128d Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/gui/image/qimage.cpp42
1 files changed, 20 insertions, 22 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 60d402289d..ee77a32b86 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -828,17 +828,6 @@ QImageData *QImageData::create(uchar *data, int width, int height, int bpl, QIm
d->cleanupFunction = cleanupFunction;
d->cleanupInfo = cleanupInfo;
- switch (format) {
- case QImage::Format_Mono:
- case QImage::Format_MonoLSB:
- d->colortable.resize(2);
- d->colortable[0] = QColor(Qt::black).rgba();
- d->colortable[1] = QColor(Qt::white).rgba();
- break;
- default:
- break;
- }
-
return d;
}
@@ -2237,21 +2226,30 @@ QRgb QImage::pixel(int x, int y) const
}
const uchar *s = d->data + y * d->bytes_per_line;
- switch(d->format) {
+
+ int index = -1;
+ switch (d->format) {
case Format_Mono:
- return d->colortable.at((*(s + (x >> 3)) >> (~x & 7)) & 1);
+ index = (*(s + (x >> 3)) >> (~x & 7)) & 1;
+ break;
case Format_MonoLSB:
- return d->colortable.at((*(s + (x >> 3)) >> (x & 7)) & 1);
+ index = (*(s + (x >> 3)) >> (x & 7)) & 1;
+ break;
case Format_Indexed8:
- {
- int index = (int)s[x];
- if (index < d->colortable.size()) {
- return d->colortable.at(index);
- } else {
- qWarning("QImage::pixel: color table index %d out of range.", index);
- return 0;
- }
+ index = s[x];
+ break;
+ default:
+ break;
+ }
+ if (index >= 0) { // Indexed format
+ if (index >= d->colortable.size()) {
+ qWarning("QImage::pixel: color table index %d out of range.", index);
+ return 0;
}
+ return d->colortable.at(index);
+ }
+
+ switch (d->format) {
case Format_RGB32:
return 0xff000000 | reinterpret_cast<const QRgb *>(s)[x];
case Format_ARGB32: // Keep old behaviour.