summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qxpmhandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/image/qxpmhandler.cpp')
-rw-r--r--src/gui/image/qxpmhandler.cpp30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp
index deff56aa58..cf105b250a 100644
--- a/src/gui/image/qxpmhandler.cpp
+++ b/src/gui/image/qxpmhandler.cpp
@@ -1125,8 +1125,6 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
break;
}
- QString line;
-
// write header
QTextStream s(device);
s << "/* XPM */" << Qt::endl
@@ -1137,35 +1135,29 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
QMap<QRgb, int>::Iterator c = colorMap.begin();
while (c != colorMap.end()) {
QRgb color = c.key();
- if (image.format() != QImage::Format_RGB32 && !qAlpha(color))
- line = QString::asprintf("\"%s c None\"",
- xpm_color_name(cpp, *c));
- else
- line = QString::asprintf("\"%s c #%02x%02x%02x\"",
- xpm_color_name(cpp, *c),
- qRed(color),
- qGreen(color),
- qBlue(color));
+ const QString line = image.format() != QImage::Format_RGB32 && !qAlpha(color)
+ ? QString::asprintf("\"%s c None\"", xpm_color_name(cpp, *c))
+ : QString::asprintf("\"%s c #%02x%02x%02x\"", xpm_color_name(cpp, *c),
+ qRed(color), qGreen(color), qBlue(color));
++c;
s << ',' << Qt::endl << line;
}
// write pixels, limit to 4 characters per pixel
- line.truncate(cpp*w);
+ QByteArray line;
for(y=0; y<h; y++) {
+ line.clear();
const QRgb *yp = reinterpret_cast<const QRgb *>(image.constScanLine(y));
- int cc = 0;
for(x=0; x<w; x++) {
int color = (int)(*(yp + x));
const QByteArray chars(xpm_color_name(cpp, colorMap[color]));
- line[cc++] = QLatin1Char(chars[0]);
+ line.append(chars[0]);
if (cpp > 1) {
- line[cc++] = QLatin1Char(chars[1]);
+ line.append(chars[1]);
if (cpp > 2) {
- line[cc++] = QLatin1Char(chars[2]);
- if (cpp > 3) {
- line[cc++] = QLatin1Char(chars[3]);
- }
+ line.append(chars[2]);
+ if (cpp > 3)
+ line.append(chars[3]);
}
}
}