diff options
Diffstat (limited to 'src/gui/image/qimage.cpp')
-rw-r--r-- | src/gui/image/qimage.cpp | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index f902f1b715..64a53b4c0e 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -104,35 +104,22 @@ QImageData::QImageData() { } -/*! \fn QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors) +/*! \fn QImageData * QImageData::create(const QSize &size, QImage::Format format) \internal Creates a new image data. Returns 0 if invalid parameters are give or anything else failed. */ -QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors) +QImageData * QImageData::create(const QSize &size, QImage::Format format) { - if (!size.isValid() || numColors < 0 || format == QImage::Format_Invalid) + if (!size.isValid() || format == QImage::Format_Invalid) return 0; // invalid parameter(s) uint width = size.width(); uint height = size.height(); uint depth = qt_depthForFormat(format); - switch (format) { - case QImage::Format_Mono: - case QImage::Format_MonoLSB: - numColors = 2; - break; - case QImage::Format_Indexed8: - numColors = qBound(0, numColors, 256); - break; - default: - numColors = 0; - break; - } - const int bytes_per_line = ((width * depth + 31) >> 5) << 2; // bytes per scanline (must be multiple of 4) // sanity check for potential overflows @@ -144,13 +131,16 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format, int nu return 0; QScopedPointer<QImageData> d(new QImageData); - d->colortable.resize(numColors); - if (depth == 1) { + + 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(); - } else { - for (int i = 0; i < numColors; ++i) - d->colortable[i] = 0; + break; + default: + break; } d->width = width; @@ -779,7 +769,7 @@ QImage::QImage() Q_DECL_NOEXCEPT QImage::QImage(int width, int height, Format format) : QPaintDevice() { - d = QImageData::create(QSize(width, height), format, 0); + d = QImageData::create(QSize(width, height), format); } /*! @@ -794,7 +784,7 @@ QImage::QImage(int width, int height, Format format) QImage::QImage(const QSize &size, Format format) : QPaintDevice() { - d = QImageData::create(size, format, 0); + d = QImageData::create(size, format); } @@ -838,6 +828,17 @@ 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; } @@ -2242,7 +2243,15 @@ QRgb QImage::pixel(int x, int y) const case Format_MonoLSB: return d->colortable.at((*(s + (x >> 3)) >> (x & 7)) & 1); case Format_Indexed8: - return d->colortable.at((int)s[x]); + { + 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; + } + } case Format_RGB32: return 0xff000000 | reinterpret_cast<const QRgb *>(s)[x]; case Format_ARGB32: // Keep old behaviour. |