summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qimage.cpp
diff options
context:
space:
mode:
authorHarald Fernengel <harald@trolltech.com>2009-08-13 13:31:02 (GMT)
committerHarald Fernengel <harald@trolltech.com>2009-08-13 13:31:41 (GMT)
commit6d2a1051970a417c4e60375cb43f06751da57728 (patch)
treea9a4b3a0d7bf5ad8be8074ca8c4d9b932946db37 /src/gui/image/qimage.cpp
parent7bce80068d1e8cc54ac129abb53545d6fad69bc1 (diff)
downloadQt-6d2a1051970a417c4e60375cb43f06751da57728.zip
Qt-6d2a1051970a417c4e60375cb43f06751da57728.tar.gz
Qt-6d2a1051970a417c4e60375cb43f06751da57728.tar.bz2
Use QScopedPointer wherever possible
Ensures that we don't leak when creating a new Pixmap while running out of memory
Diffstat (limited to 'src/gui/image/qimage.cpp')
-rw-r--r--src/gui/image/qimage.cpp54
1 files changed, 21 insertions, 33 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index c19c450..5e635d6 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -2374,8 +2374,9 @@ static void dither_to_Mono(QImageData *dst, const QImageData *src,
switch (dithermode) {
case Diffuse: {
- int *line1 = new int[w];
- int *line2 = new int[w];
+ QScopedArrayPointer<int> lineBuffer(new int[w * 2]);
+ int *line1 = lineBuffer.data();
+ int *line2 = lineBuffer.data() + w;
int bmwidth = (w+7)/8;
int *b1, *b2;
@@ -2455,8 +2456,6 @@ static void dither_to_Mono(QImageData *dst, const QImageData *src,
b2++;
}
}
- delete [] line1;
- delete [] line2;
} break;
case Ordered: {
@@ -2597,10 +2596,9 @@ static void convert_X_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageC
static void convert_ARGB_PM_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
{
- QImageData *tmp = QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32);
- convert_ARGB_PM_to_ARGB(tmp, src, flags);
- dither_to_Mono(dst, tmp, flags, false);
- delete tmp;
+ QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32));
+ convert_ARGB_PM_to_ARGB(tmp.data(), src, flags);
+ dither_to_Mono(dst, tmp.data(), flags, false);
}
//
@@ -2749,15 +2747,16 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
int* line1[3];
int* line2[3];
int* pv[3];
- line1[0] = new int[src->width];
- line2[0] = new int[src->width];
- line1[1] = new int[src->width];
- line2[1] = new int[src->width];
- line1[2] = new int[src->width];
- line2[2] = new int[src->width];
- pv[0] = new int[src->width];
- pv[1] = new int[src->width];
- pv[2] = new int[src->width];
+ QScopedArrayPointer<int> lineBuffer(new int[src->width * 9]);
+ line1[0] = lineBuffer.data();
+ line2[0] = lineBuffer.data() + src->width;
+ line1[1] = lineBuffer.data() + src->width * 2;
+ line2[1] = lineBuffer.data() + src->width * 3;
+ line1[2] = lineBuffer.data() + src->width * 4;
+ line2[2] = lineBuffer.data() + src->width * 5;
+ pv[0] = lineBuffer.data() + src->width * 6;
+ pv[1] = lineBuffer.data() + src->width * 7;
+ pv[2] = lineBuffer.data() + src->width * 8;
int endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian);
for (int y = 0; y < src->height; y++) {
@@ -2820,15 +2819,6 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
src_data += src->bytes_per_line;
dest_data += dst->bytes_per_line;
}
- delete [] line1[0];
- delete [] line2[0];
- delete [] line1[1];
- delete [] line2[1];
- delete [] line1[2];
- delete [] line2[2];
- delete [] pv[0];
- delete [] pv[1];
- delete [] pv[2];
} else { // OrderedDither
for (int y = 0; y < src->height; y++) {
const QRgb *p = (const QRgb *)src_data;
@@ -2861,8 +2851,8 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
const int trans = 216;
Q_ASSERT(dst->colortable.size() > trans);
dst->colortable[trans] = 0;
- QImageData *mask = QImageData::create(QSize(src->width, src->height), QImage::Format_Mono);
- dither_to_Mono(mask, src, flags, true);
+ QScopedPointer<QImageData> mask(QImageData::create(QSize(src->width, src->height), QImage::Format_Mono));
+ dither_to_Mono(mask.data(), src, flags, true);
uchar *dst_data = dst->data;
const uchar *mask_data = mask->data;
for (int y = 0; y < src->height; y++) {
@@ -2874,7 +2864,6 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
dst_data += dst->bytes_per_line;
}
dst->has_alpha_clut = true;
- delete mask;
}
#undef MAX_R
@@ -2887,10 +2876,9 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::
static void convert_ARGB_PM_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
{
- QImageData *tmp = QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32);
- convert_ARGB_PM_to_ARGB(tmp, src, flags);
- convert_RGB_to_Indexed8(dst, tmp, flags);
- delete tmp;
+ QScopedPointer<QImageData> tmp(QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32));
+ convert_ARGB_PM_to_ARGB(tmp.data(), src, flags);
+ convert_RGB_to_Indexed8(dst, tmp.data(), flags);
}
static void convert_ARGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)