summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authoraavit <qt-info@nokia.com>2010-03-04 12:34:27 (GMT)
committeraavit <qt-info@nokia.com>2010-03-04 13:03:09 (GMT)
commit7b923d14c0e8d8f84c71e8d636a0632f4566f00a (patch)
treeaf0244b1d039526749c39b4dcf565bbebbfa4e41 /src/gui/image
parente53480370409b96d24d3f53513e8b2019a398e70 (diff)
downloadQt-7b923d14c0e8d8f84c71e8d636a0632f4566f00a.zip
Qt-7b923d14c0e8d8f84c71e8d636a0632f4566f00a.tar.gz
Qt-7b923d14c0e8d8f84c71e8d636a0632f4566f00a.tar.bz2
Added QImage::bitPlaneCount().
When the image format contains unused bits (e.g. Format_RGB32), depth() does not give the true number of bits of color information per pixel. This new function does. Task-number: QTBUG-7982 Reviewed-by: Trond
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qimage.cpp55
-rw-r--r--src/gui/image/qimage.h1
2 files changed, 51 insertions, 5 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 6bcf72b..94307de 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -480,9 +480,12 @@ bool QImageData::checkForAlphaPixels() const
\row
\o Low-level information
\o
+
The depth() function returns the depth of the image. The supported
- depths are 1 (monochrome), 8 and 32 (for more information see the
- \l {QImage#Image Formats}{Image Formats} section).
+ depths are 1 (monochrome), 8, 16, 24 and 32 bits. The
+ bitPlaneCount() function tells how many of those bits that are
+ used. For more information see the
+ \l {QImage#Image Formats}{Image Formats} section.
The format(), bytesPerLine(), and byteCount() functions provide
low-level information about the data stored in the image.
@@ -707,7 +710,7 @@ bool QImageData::checkForAlphaPixels() const
packed with the less significant bit (LSB) first.
\value Format_Indexed8 The image is stored using 8-bit indexes
- into a colormap.
+ into a colormap.
\value Format_RGB32 The image is stored using a 32-bit RGB format (0xffRRGGBB).
@@ -1580,12 +1583,12 @@ QRect QImage::rect() const
/*!
Returns the depth of the image.
- The image depth is the number of bits used to encode a single
+ The image depth is the number of bits used to store a single
pixel, also called bits per pixel (bpp).
The supported depths are 1, 8, 16, 24 and 32.
- \sa convertToFormat(), {QImage#Image Formats}{Image Formats},
+ \sa bitPlaneCount(), convertToFormat(), {QImage#Image Formats}{Image Formats},
{QImage#Image Information}{Image Information}
*/
@@ -5848,6 +5851,48 @@ bool QImage::hasAlphaChannel() const
}
+/*!
+ \since 4.7
+ Returns the number of bit planes in the image.
+
+ The number of bit planes is the number of bits of color and
+ transparency information for each pixel. This is different from
+ (i.e. smaller than) the depth when the image format contains
+ unused bits.
+
+ \sa depth(), format(), {QImage#Image Formats}{Image Formats}
+*/
+int QImage::bitPlaneCount() const
+{
+ if (!d)
+ return 0;
+ int bpc = 0;
+ switch (d->format) {
+ case QImage::Format_Invalid:
+ break;
+ case QImage::Format_RGB32:
+ bpc = 24;
+ break;
+ case QImage::Format_RGB666:
+ bpc = 18;
+ break;
+ case QImage::Format_RGB555:
+ bpc = 15;
+ break;
+ case QImage::Format_ARGB8555_Premultiplied:
+ bpc = 23;
+ break;
+ case QImage::Format_RGB444:
+ bpc = 12;
+ break;
+ default:
+ bpc = depthForFormat(d->format);
+ break;
+ }
+ return bpc;
+}
+
+
#ifdef QT3_SUPPORT
#if defined(Q_WS_X11)
QT_BEGIN_INCLUDE_NAMESPACE
diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h
index dd13782..896061f 100644
--- a/src/gui/image/qimage.h
+++ b/src/gui/image/qimage.h
@@ -169,6 +169,7 @@ public:
QT_DEPRECATED int numColors() const;
#endif
int colorCount() const;
+ int bitPlaneCount() const;
QRgb color(int i) const;
void setColor(int i, QRgb c);