summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-02-09 09:14:12 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-02-13 08:17:00 +0000
commitac8a3b948da1980bc59bae3fc76d20b5b45662a0 (patch)
treef08eed7df003491d742190f9eeb5a2fb06518ae5 /src/gui/image
parent9915630d0886434e8984904b1cadedc81dc78ca0 (diff)
QtGui: Use QImage::constBits()/constScanLine() in non-const contexts.
Prevent potential detaching by using constBits()/constScanLine() instead of bits()/scanLine(). Change-Id: If03f8d4d3b8ed4c07aed5eff7f580e57ca771919 Reviewed-by: Gunnar Sletta <gunnar@sletta.org> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qgifhandler.cpp4
-rw-r--r--src/gui/image/qpixmap_blitter.cpp2
-rw-r--r--src/gui/image/qpixmap_win.cpp2
-rw-r--r--src/gui/image/qppmhandler.cpp6
-rw-r--r--src/gui/image/qxbmhandler.cpp2
-rw-r--r--src/gui/image/qxpmhandler.cpp4
6 files changed, 10 insertions, 10 deletions
diff --git a/src/gui/image/qgifhandler.cpp b/src/gui/image/qgifhandler.cpp
index 7ba6b123e8..9c748c0373 100644
--- a/src/gui/image/qgifhandler.cpp
+++ b/src/gui/image/qgifhandler.cpp
@@ -199,7 +199,7 @@ void QGIFFormat::disposePrevious(QImage *image)
fillRect(image, l, t, r-l+1, b-t+1, color(bgcol));
} else {
// Impossible: We don't know of a bgcol - use pixel 0
- QRgb *bits = (QRgb*)image->bits();
+ const QRgb *bits = reinterpret_cast<const QRgb *>(image->constBits());
fillRect(image, l, t, r-l+1, b-t+1, bits[0]);
}
// ### Changed: QRect(l, t, r-l+1, b-t+1)
@@ -208,7 +208,7 @@ void QGIFFormat::disposePrevious(QImage *image)
if (frame >= 0) {
for (int ln=t; ln<=b; ln++) {
memcpy(image->scanLine(ln)+l,
- backingstore.scanLine(ln-t),
+ backingstore.constScanLine(ln-t),
(r-l+1)*sizeof(QRgb));
}
// ### Changed: QRect(l, t, r-l+1, b-t+1)
diff --git a/src/gui/image/qpixmap_blitter.cpp b/src/gui/image/qpixmap_blitter.cpp
index b254c5a2af..a68425e100 100644
--- a/src/gui/image/qpixmap_blitter.cpp
+++ b/src/gui/image/qpixmap_blitter.cpp
@@ -183,7 +183,7 @@ void QBlittablePlatformPixmap::fromImage(const QImage &image,
correctFormatPic = correctFormatPic.convertToFormat(thisImg->format(), flags);
uchar *mem = thisImg->bits();
- const uchar *bits = correctFormatPic.bits();
+ const uchar *bits = correctFormatPic.constBits();
int bytesCopied = 0;
while (bytesCopied < correctFormatPic.byteCount()) {
memcpy(mem,bits,correctFormatPic.bytesPerLine());
diff --git a/src/gui/image/qpixmap_win.cpp b/src/gui/image/qpixmap_win.cpp
index a7a9b375ff..8db3bdbc7f 100644
--- a/src/gui/image/qpixmap_win.cpp
+++ b/src/gui/image/qpixmap_win.cpp
@@ -198,7 +198,7 @@ Q_GUI_EXPORT HBITMAP qt_createIconMask(const QBitmap &bitmap)
QScopedArrayPointer<uchar> bits(new uchar[bpl * h]);
bm.invertPixels();
for (int y = 0; y < h; ++y)
- memcpy(bits.data() + y * bpl, bm.scanLine(y), bpl);
+ memcpy(bits.data() + y * bpl, bm.constScanLine(y), bpl);
HBITMAP hbm = CreateBitmap(w, h, 1, 1, bits.data());
return hbm;
}
diff --git a/src/gui/image/qppmhandler.cpp b/src/gui/image/qppmhandler.cpp
index 7f23656c02..6eb35e1558 100644
--- a/src/gui/image/qppmhandler.cpp
+++ b/src/gui/image/qppmhandler.cpp
@@ -329,7 +329,7 @@ static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QBy
if (image.format() == QImage::Format_Indexed8) {
QVector<QRgb> color = image.colorTable();
for (uint y=0; y<h; y++) {
- uchar *b = image.scanLine(y);
+ const uchar *b = image.constScanLine(y);
uchar *p = buf;
uchar *end = buf+bpl;
if (gray) {
@@ -350,7 +350,7 @@ static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QBy
}
} else {
for (uint y=0; y<h; y++) {
- uchar *b = image.scanLine(y);
+ const uchar *b = image.constScanLine(y);
uchar *p = buf;
uchar *end = buf + bpl;
if (gray) {
@@ -380,7 +380,7 @@ static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QBy
uint bpl = w * 3;
uchar *buf = new uchar[bpl];
for (uint y=0; y<h; y++) {
- QRgb *b = (QRgb*)image.scanLine(y);
+ const QRgb *b = reinterpret_cast<const QRgb *>(image.constScanLine(y));
uchar *p = buf;
uchar *end = buf+bpl;
while (p < end) {
diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp
index 81525d9dd6..44d07f1624 100644
--- a/src/gui/image/qxbmhandler.cpp
+++ b/src/gui/image/qxbmhandler.cpp
@@ -210,7 +210,7 @@ static bool write_xbm_image(const QImage &sourceImage, QIODevice *device, const
char *p = buf;
int bpl = (w+7)/8;
for (int y = 0; y < h; ++y) {
- uchar *b = image.scanLine(y);
+ const uchar *b = image.constScanLine(y);
for (i = 0; i < bpl; ++i) {
*p++ = '0'; *p++ = 'x';
*p++ = hexrep[*b >> 4];
diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp
index e9ac4a9cc2..fbce78eb74 100644
--- a/src/gui/image/qxpmhandler.cpp
+++ b/src/gui/image/qxpmhandler.cpp
@@ -1098,7 +1098,7 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
// build color table
for(y=0; y<h; y++) {
- QRgb * yp = (QRgb *)image.scanLine(y);
+ const QRgb *yp = reinterpret_cast<const QRgb *>(image.constScanLine(y));
for(x=0; x<w; x++) {
QRgb color = *(yp + x);
if (!colorMap.contains(color))
@@ -1144,7 +1144,7 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
// write pixels, limit to 4 characters per pixel
line.truncate(cpp*w);
for(y=0; y<h; y++) {
- QRgb * yp = (QRgb *) image.scanLine(y);
+ const QRgb *yp = reinterpret_cast<const QRgb *>(image.constScanLine(y));
int cc = 0;
for(x=0; x<w; x++) {
int color = (int)(*(yp + x));