From 426308a93bc4ab52faa40fe53d3c0e52fce4072c Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 28 Sep 2020 10:49:28 +0200 Subject: Add logging categories to image handlers Change-Id: Ia0c47826d08b3f641c17d8a585f62d008a8b095b Reviewed-by: Eirik Aavitsland --- src/gui/image/qimageiohandler.cpp | 7 +++++-- src/gui/image/qpnghandler.cpp | 11 +++++++---- src/gui/image/qppmhandler.cpp | 9 +++++++-- src/gui/image/qxbmhandler.cpp | 9 ++++++++- src/gui/image/qxpmhandler.cpp | 21 +++++++++++++-------- 5 files changed, 40 insertions(+), 17 deletions(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qimageiohandler.cpp b/src/gui/image/qimageiohandler.cpp index 96dfa8d670..75a2f2ac65 100644 --- a/src/gui/image/qimageiohandler.cpp +++ b/src/gui/image/qimageiohandler.cpp @@ -270,10 +270,13 @@ #include #include +#include #include QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(lcImageIo, "qt.gui.imageio") + class QIODevice; class QImageIOHandlerPrivate @@ -584,8 +587,8 @@ bool QImageIOHandler::allocateImage(QSize size, QImage::Format format, QImage *i return false; const qsizetype mb = szp.totalSize >> 20; if (mb > mbLimit || (mb == mbLimit && szp.totalSize % (1 << 20))) { - qWarning("QImageIOHandler: Rejecting image as it exceeds the current " - "allocation limit of %i megabytes", mbLimit); + qCWarning(lcImageIo, "QImageIOHandler: Rejecting image as it exceeds the current " + "allocation limit of %i megabytes", mbLimit); return false; } } diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index 4b12ea6479..897055f7ae 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include // for qt_getImageText @@ -80,6 +81,8 @@ QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(lcImageIo) + // avoid going through QImage::scanLine() which calls detach #define FAST_SCAN_LINE(data, bpl, y) (data + (y) * bpl) @@ -497,7 +500,7 @@ static void read_image_scaled(QImage *outImage, png_structp png_ptr, png_infop i extern "C" { static void qt_png_warning(png_structp /*png_ptr*/, png_const_charp message) { - qWarning("libpng warning: %s", message); + qCWarning(lcImageIo, "libpng warning: %s", message); } } @@ -587,7 +590,7 @@ bool QPngHandlerPrivate::readPngHeader() png_get_iCCP(png_ptr, info_ptr, &name, &compressionType, &profileData, &profLen); colorSpace = QColorSpace::fromIccProfile(QByteArray((const char *)profileData, profLen)); if (!colorSpace.isValid()) { - qWarning() << "QPngHandler: Failed to parse ICC profile"; + qCWarning(lcImageIo) << "QPngHandler: Failed to parse ICC profile"; } else { QColorSpacePrivate *csD = QColorSpacePrivate::getWritable(colorSpace); if (csD->description.isEmpty()) @@ -911,7 +914,7 @@ bool QPNGImageWriter::writeImage(const QImage& image, int compression_in, const int compression = compression_in; if (compression >= 0) { if (compression > 9) { - qWarning("PNG: Compression %d out of range", compression); + qCWarning(lcImageIo, "PNG: Compression %d out of range", compression); compression = 9; } png_set_compression_level(png_ptr, compression); @@ -1204,7 +1207,7 @@ bool QPngHandler::canRead() const bool QPngHandler::canRead(QIODevice *device) { if (!device) { - qWarning("QPngHandler::canRead() called with no device"); + qCWarning(lcImageIo, "QPngHandler::canRead() called with no device"); return false; } diff --git a/src/gui/image/qppmhandler.cpp b/src/gui/image/qppmhandler.cpp index eccd750f1d..71dbefe354 100644 --- a/src/gui/image/qppmhandler.cpp +++ b/src/gui/image/qppmhandler.cpp @@ -41,14 +41,19 @@ #ifndef QT_NO_IMAGEFORMAT_PPM +#include #include #include +#include +#include #include + #include -#include QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(lcImageIo) + /***************************************************************************** PBM/PGM/PPM (ASCII and RAW) image read/write functions *****************************************************************************/ @@ -473,7 +478,7 @@ bool QPpmHandler::canRead() const bool QPpmHandler::canRead(QIODevice *device, QByteArray *subType) { if (!device) { - qWarning("QPpmHandler::canRead() called with no device"); + qCWarning(lcImageIo, "QPpmHandler::canRead() called with no device"); return false; } diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp index 39f379520e..9c324aeeb9 100644 --- a/src/gui/image/qxbmhandler.cpp +++ b/src/gui/image/qxbmhandler.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -51,6 +52,8 @@ QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(lcImageIo) + /***************************************************************************** X bitmap image read/write functions *****************************************************************************/ @@ -293,7 +296,10 @@ bool QXbmHandler::canRead() const bool QXbmHandler::canRead(QIODevice *device) { - QImage image; + if (!device) { + qCWarning(lcImageIo, "QXbmHandler::canRead() called with no device"); + return false; + } // it's impossible to tell whether we can load an XBM or not when // it's from a sequential device, as the only way to do it is to @@ -301,6 +307,7 @@ bool QXbmHandler::canRead(QIODevice *device) if (device->isSequential()) return false; + QImage image; qint64 oldPos = device->pos(); bool success = read_xbm_image(device, &image); device->seek(oldPos); diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index 258ff318f5..7b545614a7 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -41,17 +41,22 @@ #ifndef QT_NO_IMAGEFORMAT_XPM -#include #include +#include #include +#include #include #include #include +#include + #include QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(lcImageIo) + static quint64 xpmHash(const QString &str) { unsigned int hashValue = 0; @@ -892,7 +897,7 @@ static bool read_xpm_body( for(currentColor=0; currentColor < ncols; ++currentColor) { if (!read_xpm_string(buf, device, source, index, state)) { - qWarning("QImage: XPM color specification missing"); + qCWarning(lcImageIo, "XPM color specification missing"); return false; } QByteArray index; @@ -907,7 +912,7 @@ static bool read_xpm_body( if (i < 0) i = tokens.indexOf("m"); if (i < 0) { - qWarning("QImage: XPM color specification is missing: %s", buf.constData()); + qCWarning(lcImageIo, "XPM color specification is missing: %s", buf.constData()); return false; // no c/g/g4/m specification at all } QByteArray color; @@ -915,7 +920,7 @@ static bool read_xpm_body( color.append(tokens.at(i)); } if (color.isEmpty()) { - qWarning("QImage: XPM color value is missing from specification: %s", buf.constData()); + qCWarning(lcImageIo, "XPM color value is missing from specification: %s", buf.constData()); return false; // no color value } buf = color; @@ -958,7 +963,7 @@ static bool read_xpm_body( // Read pixels for(int y=0; y