diff -r 56cd8111b7f7 -r 41300fa6a67c src/gui/image/qimage.cpp --- a/src/gui/image/qimage.cpp Tue Jan 26 12:42:25 2010 +0200 +++ b/src/gui/image/qimage.cpp Tue Feb 02 00:43:10 2010 +0200 @@ -449,7 +449,7 @@ to the pixel() function. The pixel() function returns the color as a QRgb value indepedent of the image's format. - In case of monochrome and 8-bit images, the numColors() and + In case of monochrome and 8-bit images, the colorCount() and colorTable() functions provide information about the color components used to store the image data: The colorTable() function returns the image's entire color table. To obtain a single entry, @@ -484,7 +484,7 @@ depths are 1 (monochrome), 8 and 32 (for more information see the \l {QImage#Image Formats}{Image Formats} section). - The format(), bytesPerLine(), and numBytes() functions provide + The format(), bytesPerLine(), and byteCount() functions provide low-level information about the data stored in the image. The cacheKey() function returns a number that uniquely @@ -623,7 +623,7 @@ \o Sets the color table used to translate color indexes. Only monochrome and 8-bit formats. \row - \o setNumColors() + \o setColorCount() \o Resizes the color table. Only monochrome and 8-bit formats. \endtable @@ -906,7 +906,7 @@ If \a format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with - setNumColors() or setColorTable() before the image is used. + setColorCount() or setColorTable() before the image is used. */ QImage::QImage(uchar* data, int width, int height, Format format) : QPaintDevice() @@ -928,7 +928,7 @@ If \a format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with - setNumColors() or setColorTable() before the image is used. + setColorCount() or setColorTable() before the image is used. Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, @@ -954,7 +954,7 @@ If \a format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with - setNumColors() or setColorTable() before the image is used. + setColorCount() or setColorTable() before the image is used. */ QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format format) :QPaintDevice() @@ -974,7 +974,7 @@ If \a format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with - setNumColors() or setColorTable() before the image is used. + setColorCount() or setColorTable() before the image is used. Unlike the similar QImage constructor that takes a non-const data buffer, this version will never alter the contents of the buffer. For example, @@ -1126,7 +1126,7 @@ Use the constructor that accepts a width, a height and a format (i.e. specifying the depth and bit order), in combination with the - setNumColors() function, instead. + setColorCount() function, instead. \oldcode QImage image(width, height, depth, numColors); @@ -1135,15 +1135,15 @@ // For 8 bit images the default number of colors is 256. If // another number of colors is required it can be specified - // using the setNumColors() function. - image.setNumColors(numColors); + // using the setColorCount() function. + image.setColorCount(numColors); \endcode */ -QImage::QImage(int w, int h, int depth, int numColors, Endian bitOrder) +QImage::QImage(int w, int h, int depth, int colorCount, Endian bitOrder) : QPaintDevice() { - d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), numColors); + d = QImageData::create(QSize(w, h), formatFor(depth, bitOrder), colorCount); } /*! @@ -1152,7 +1152,7 @@ Use the constructor that accepts a size and a format (i.e. specifying the depth and bit order), in combination with the - setNumColors() function, instead. + setColorCount() function, instead. \oldcode QSize mySize(width, height); @@ -1163,8 +1163,8 @@ // For 8 bit images the default number of colors is 256. If // another number of colors is required it can be specified - // using the setNumColors() function. - image.setNumColors(numColors); + // using the setColorCount() function. + image.setColorCount(numColors); \endcode */ QImage::QImage(const QSize& size, int depth, int numColors, Endian bitOrder) @@ -1232,7 +1232,7 @@ for (int i = 0; i < numColors; ++i) d->colortable[i] = colortable[i]; } else if (numColors) { - setNumColors(numColors); + setColorCount(numColors); } } @@ -1283,7 +1283,7 @@ for (int i = 0; i < numColors; ++i) d->colortable[i] = colortable[i]; } else if (numColors) { - setNumColors(numColors); + setColorCount(numColors); } } #endif // Q_WS_QWS @@ -1592,17 +1592,31 @@ } /*! + \obsolete \fn int QImage::numColors() const Returns the size of the color table for the image. - Notice that numColors() returns 0 for 32-bpp images because these + \sa setColorCount() +*/ +int QImage::numColors() const +{ + return d ? d->colortable.size() : 0; +} + +/*! + \since 4.6 + \fn int QImage::colorCount() const + + Returns the size of the color table for the image. + + Notice that colorCount() returns 0 for 32-bpp images because these images do not use color tables, but instead encode pixel values as ARGB quadruplets. - \sa setNumColors(), {QImage#Image Information}{Image Information} + \sa setColorCount(), {QImage#Image Information}{Image Information} */ -int QImage::numColors() const +int QImage::colorCount() const { return d ? d->colortable.size() : 0; } @@ -1711,7 +1725,7 @@ Returns a list of the colors contained in the image's color table, or an empty list if the image does not have a color table - \sa setColorTable(), numColors(), color() + \sa setColorTable(), colorCount(), color() */ QVector QImage::colorTable() const { @@ -1720,10 +1734,10 @@ /*! + \obsolete Returns the number of bytes occupied by the image data. - \sa bytesPerLine(), bits(), {QImage#Image Information}{Image - Information} + \sa byteCount() */ int QImage::numBytes() const { @@ -1731,9 +1745,21 @@ } /*! + \since 4.6 + Returns the number of bytes occupied by the image data. + + \sa bytesPerLine(), bits(), {QImage#Image Information}{Image + Information} +*/ +int QImage::byteCount() const +{ + return d ? d->nbytes : 0; +} + +/*! Returns the number of bytes per image scanline. - This is equivalent to numBytes()/ height(). + This is equivalent to byteCount() / height(). \sa scanLine() */ @@ -1756,7 +1782,7 @@ */ QRgb QImage::color(int i) const { - Q_ASSERT(i < numColors()); + Q_ASSERT(i < colorCount()); return d ? d->colortable.at(i) : QRgb(uint(-1)); } @@ -1767,9 +1793,9 @@ given to \a colorValue. The color value is an ARGB quadruplet. If \a index is outside the current size of the color table, it is - expanded with setNumColors(). - - \sa color(), numColors(), setColorTable(), {QImage#Pixel Manipulation}{Pixel + expanded with setColorCount(). + + \sa color(), colorCount(), setColorTable(), {QImage#Pixel Manipulation}{Pixel Manipulation} */ void QImage::setColor(int i, QRgb c) @@ -1787,7 +1813,7 @@ return; if (i >= d->colortable.size()) - setNumColors(i+1); + setColorCount(i+1); d->colortable[i] = c; d->has_alpha_clut |= (qAlpha(c) != 255); } @@ -1844,7 +1870,7 @@ data, thus ensuring that this QImage is the only one using the current return value. - \sa scanLine(), numBytes() + \sa scanLine(), byteCount() */ uchar *QImage::bits() { @@ -2025,8 +2051,21 @@ #endif /*! + \obsolete Resizes the color table to contain \a numColors entries. + \sa setColorCount() +*/ + +void QImage::setNumColors(int numColors) +{ + setColorCount(numColors); +} + +/*! + \since 4.6 + Resizes the color table to contain \a colorCount entries. + If the color table is expanded, all the extra colors will be set to transparent (i.e qRgba(0, 0, 0, 0)). @@ -2034,14 +2073,14 @@ have entries for all the pixel/index values present in the image, otherwise the results are undefined. - \sa numColors(), colorTable(), setColor(), {QImage#Image + \sa colorCount(), colorTable(), setColor(), {QImage#Image Transformations}{Image Transformations} */ -void QImage::setNumColors(int numColors) +void QImage::setColorCount(int colorCount) { if (!d) { - qWarning("QImage::setNumColors: null image"); + qWarning("QImage::setColorCount: null image"); return; } @@ -2051,17 +2090,16 @@ if (!d) return; - if (numColors == d->colortable.size()) + if (colorCount == d->colortable.size()) return; - if (numColors <= 0) { // use no color table + if (colorCount <= 0) { // use no color table d->colortable = QVector(); return; } int nc = d->colortable.size(); - d->colortable.resize(numColors); - for (int i = nc; i < numColors; ++i) + d->colortable.resize(colorCount); + for (int i = nc; i < colorCount; ++i) d->colortable[i] = 0; - } /*! @@ -3674,7 +3712,7 @@ otherwise the parameter must be a QRgb value. If \a position is not a valid coordinate pair in the image, or if - \a index_or_rgb >= numColors() in the case of monochrome and + \a index_or_rgb >= colorCount() in the case of monochrome and 8-bit images, the result is undefined. \warning This function is expensive due to the call of the internal @@ -3835,7 +3873,7 @@ } else { if (d->colortable.isEmpty()) return true; - for (int i = 0; i < numColors(); i++) + for (int i = 0; i < colorCount(); i++) if (!qIsGray(d->colortable.at(i))) return false; } @@ -3862,7 +3900,7 @@ case 16: return allGray(); case 8: { - for (int i = 0; i < numColors(); i++) + for (int i = 0; i < colorCount(); i++) if (d->colortable.at(i) != qRgb(i,i,i)) return false; return true; @@ -4083,7 +4121,8 @@ } QImage mask(d->width, d->height, Format_MonoLSB); - dither_to_Mono(mask.d, d, flags, true); + if (!mask.isNull()) + dither_to_Mono(mask.d, d, flags, true); return mask; } @@ -4127,7 +4166,7 @@ int w = width(); int h = height(); QImage m(w, h, Format_MonoLSB); - m.setNumColors(2); + m.setColorCount(2); m.setColor(0, QColor(Qt::color0).rgba()); m.setColor(1, QColor(Qt::color1).rgba()); m.fill(0xff); @@ -5702,7 +5741,7 @@ int h = d->height; QImage image(w, h, Format_Indexed8); - image.setNumColors(256); + image.setColorCount(256); // set up gray scale table. for (int i=0; i<256; ++i) @@ -5832,7 +5871,7 @@ static QImage rotated90(const QImage &image) { QImage out(image.height(), image.width(), image.format()); - if (image.numColors() > 0) + if (image.colorCount() > 0) out.setColorTable(image.colorTable()); int w = image.width(); int h = image.height(); @@ -5871,7 +5910,7 @@ break; default: for (int y=0; y 0) + if (image.colorCount() > 0) out.setColorTable(image.colorTable()); int w = image.width(); int h = image.height(); @@ -5930,7 +5969,7 @@ break; default: for (int y=0; ycolortable.size() < 256) { // colors are left in the color table, so pick that one as transparent dImage.d->colortable.append(0x0); - memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.numBytes()); + memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.byteCount()); } else { - memset(dImage.bits(), 0, dImage.numBytes()); + memset(dImage.bits(), 0, dImage.byteCount()); } break; case 1: case 16: case 24: case 32: - memset(dImage.bits(), 0x00, dImage.numBytes()); + memset(dImage.bits(), 0x00, dImage.byteCount()); break; }