diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-01-06 22:57:54 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-01-06 22:57:54 (GMT) |
commit | 58112b1e251c03b0a72511508712f9a67ce84d25 (patch) | |
tree | 510325d673e65ee5a1e34065f059e0491fb2534d /src/gui/image/qimage.cpp | |
parent | 0647ea310c3880a0b1457f750dd6d092666c14de (diff) | |
download | Qt-58112b1e251c03b0a72511508712f9a67ce84d25.zip Qt-58112b1e251c03b0a72511508712f9a67ce84d25.tar.gz Qt-58112b1e251c03b0a72511508712f9a67ce84d25.tar.bz2 |
Add QImage::constBits() and QImage::constScanLine()
QImage::bits() and QImage::scanLine() can create deep copies
if the QImage is not const. The constBits() and constScanLine()
functions make things more explicit and less error-prone.
Reviewed-by: Daniel Pope
Diffstat (limited to 'src/gui/image/qimage.cpp')
-rw-r--r-- | src/gui/image/qimage.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index ec8dd88..fc1107d 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1832,7 +1832,7 @@ void QImage::setColor(int i, QRgb c) qAlpha() to access the pixels. \sa bytesPerLine(), bits(), {QImage#Pixel Manipulation}{Pixel - Manipulation} + Manipulation}, constScanLine() */ uchar *QImage::scanLine(int i) { @@ -1862,6 +1862,28 @@ const uchar *QImage::scanLine(int i) const /*! + Returns a pointer to the pixel data at the scanline with index \a + i. The first scanline is at index 0. + + The scanline data is aligned on a 32-bit boundary. + + Note that QImage uses \l{Implicit Data Sharing} {implicit data + sharing}, but this function does \e not perform a deep copy of the + shared pixel data, because the returned data is const. + + \sa scanLine(), constBits() + \since 4.7 +*/ +const uchar *QImage::constScanLine(int i) const +{ + if (!d) + return 0; + + Q_ASSERT(i >= 0 && i < height()); + return d->data + i * d->bytes_per_line; +} + +/*! Returns a pointer to the first pixel data. This is equivalent to scanLine(0). @@ -1870,7 +1892,7 @@ const uchar *QImage::scanLine(int i) const data, thus ensuring that this QImage is the only one using the current return value. - \sa scanLine(), byteCount() + \sa scanLine(), byteCount(), constBits() */ uchar *QImage::bits() { @@ -1898,6 +1920,20 @@ const uchar *QImage::bits() const } +/*! + Returns a pointer to the first pixel data. + + Note that QImage uses \l{Implicit Data Sharing} {implicit data + sharing}, but this function does \e not perform a deep copy of the + shared pixel data, because the returned data is const. + + \sa bits(), constScanLine() + \since 4.7 +*/ +const uchar *QImage::constBits() const +{ + return d ? d->data : 0; +} /*! \fn void QImage::reset() |