QXpmHandler: clean up write_xpm_image: use conventional pointer arithmetic

... instead of *(array + index).

Also fix a pointless cast from QRgb to int which the next line
implicitly undoes (because colorMap has QRgb as key, not int) and get
rid of the local variables that facilitated said fallacy in the first
place.

Change-Id: I71a92822ee2404646f6fb5533e40252f38e6b21f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2021-08-04 16:42:07 +02:00
parent 2658f95d3c
commit 726119c431

View File

@ -1133,8 +1133,7 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
for (int y = 0; y < h; ++y) {
const QRgb *yp = reinterpret_cast<const QRgb *>(image.constScanLine(y));
for (int x = 0; x < w; ++x) {
QRgb color = *(yp + x);
const auto [it, inserted] = colorMap.try_emplace(color, ncolors);
const auto [it, inserted] = colorMap.try_emplace(yp[x], ncolors);
if (inserted)
++ncolors;
}
@ -1170,10 +1169,8 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const
for (int y = 0; y < h; ++y) {
line.clear();
const QRgb *yp = reinterpret_cast<const QRgb *>(image.constScanLine(y));
for (int x = 0; x < w; ++x) {
int color = (int)(*(yp + x));
line.append(xpm_color_name(cpp, colorMap[color]));
}
for (int x = 0; x < w; ++x)
line.append(xpm_color_name(cpp, colorMap[yp[x]]));
s << ',' << Qt::endl << '\"' << line << '\"';
}
s << "};" << Qt::endl;