diff options
Diffstat (limited to 'src/gui/image/qppmhandler.cpp')
-rw-r--r-- | src/gui/image/qppmhandler.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/gui/image/qppmhandler.cpp b/src/gui/image/qppmhandler.cpp index c809b341f8..3a4af46195 100644 --- a/src/gui/image/qppmhandler.cpp +++ b/src/gui/image/qppmhandler.cpp @@ -11,8 +11,8 @@ #include <qloggingcategory.h> #include <qrgba64.h> #include <qvariant.h> - -#include <ctype.h> +#include <private/qlocale_p.h> +#include <private/qtools_p.h> QT_BEGIN_NAMESPACE @@ -32,7 +32,7 @@ static void discard_pbm_line(QIODevice *d) } while (res > 0 && buf[res-1] != '\n'); } -static int read_pbm_int(QIODevice *d, bool *ok) +static int read_pbm_int(QIODevice *d, bool *ok, int maxDigits = -1) { char c; int val = -1; @@ -41,7 +41,7 @@ static int read_pbm_int(QIODevice *d, bool *ok) for (;;) { if (!d->getChar(&c)) // end of file break; - digit = isdigit((uchar) c); + digit = QtMiscUtils::isAsciiDigit(c); if (val != -1) { if (digit) { const int cValue = c - '0'; @@ -50,6 +50,8 @@ static int read_pbm_int(QIODevice *d, bool *ok) } else { hasOverflow = true; } + if (maxDigits > 0 && --maxDigits == 0) + break; continue; } else { if (c == '#') // comment @@ -59,12 +61,14 @@ static int read_pbm_int(QIODevice *d, bool *ok) } if (digit) // first digit val = c - '0'; - else if (isspace((uchar) c)) + else if (ascii_isspace(c)) continue; else if (c == '#') discard_pbm_line(d); else break; + if (maxDigits > 0 && --maxDigits == 0) + break; } if (val < 0) *ok = false; @@ -77,7 +81,7 @@ static bool read_pbm_header(QIODevice *device, char& type, int& w, int& h, int& if (device->read(buf, 3) != 3) // read P[1-6]<white-space> return false; - if (!(buf[0] == 'P' && isdigit((uchar) buf[1]) && isspace((uchar) buf[2]))) + if (!(buf[0] == 'P' && QtMiscUtils::isAsciiDigit(buf[1]) && ascii_isspace(buf[2]))) return false; type = buf[1]; @@ -213,7 +217,7 @@ static bool read_pbm_body(QIODevice *device, char type, int w, int h, int mcc, Q b = 0; for (int i=0; i<8; i++) { if (i < bitsLeft) - b = (b << 1) | (read_pbm_int(device, &ok) & 1); + b = (b << 1) | (read_pbm_int(device, &ok, 1) & 1); else b = (b << 1) | (0 & 1); // pad it our self if we need to } @@ -265,13 +269,12 @@ static bool read_pbm_body(QIODevice *device, char type, int w, int h, int mcc, Q return true; } -static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QByteArray &sourceFormat) +static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, QByteArrayView sourceFormat) { QByteArray str; QImage image = sourceImage; - QByteArray format = sourceFormat; + const QByteArrayView format = sourceFormat.left(3); // ignore RAW part - format = format.left(3); // ignore RAW part bool gray = format == "pgm"; if (format == "pbm") { @@ -322,7 +325,7 @@ static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QBy switch (image.depth()) { case 1: { str.insert(1, '4'); - if (out->write(str, str.length()) != str.length()) + if (out->write(str, str.size()) != str.size()) return false; w = (w+7)/8; for (uint y=0; y<h; y++) { @@ -336,12 +339,12 @@ static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QBy case 8: { str.insert(1, gray ? '5' : '6'); str.append("255\n"); - if (out->write(str, str.length()) != str.length()) + if (out->write(str, str.size()) != str.size()) return false; qsizetype bpl = qsizetype(w) * (gray ? 1 : 3); uchar *buf = new uchar[bpl]; if (image.format() == QImage::Format_Indexed8) { - QList<QRgb> color = image.colorTable(); + const QList<QRgb> color = image.colorTable(); for (uint y=0; y<h; y++) { const uchar *b = image.constScanLine(y); uchar *p = buf; @@ -389,7 +392,7 @@ static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QBy case 32: { str.insert(1, '6'); str.append("255\n"); - if (out->write(str, str.length()) != str.length()) + if (out->write(str, str.size()) != str.size()) return false; qsizetype bpl = qsizetype(w) * 3; uchar *buf = new uchar[bpl]; |