From ab6fd84c62ff4a72696798dcf6598dd6a44389f6 Mon Sep 17 00:00:00 2001 From: Elvis Lee Date: Wed, 26 Apr 2017 12:29:24 +0900 Subject: [PATCH] Make it possible to avoid loading comments from JPEG and PNG files Skip reading JPEG and PNG comments information from the header to save the memory. This can now be configured through the feature system. Change-Id: I3744312f69aa3201d5188776cbd99fe690b75d32 Task-number: QTBUG-83123 Pick-to: 5.15 Reviewed-by: Eirik Aavitsland --- src/gui/configure.cmake | 4 ++++ src/gui/configure.json | 7 +++++++ src/gui/image/qpnghandler.cpp | 4 ++++ src/plugins/imageformats/jpeg/qjpeghandler.cpp | 2 ++ 4 files changed, 17 insertions(+) diff --git a/src/gui/configure.cmake b/src/gui/configure.cmake index 9ee5089f49..51acfaf6f3 100644 --- a/src/gui/configure.cmake +++ b/src/gui/configure.cmake @@ -812,6 +812,10 @@ qt_feature("system-png" PRIVATE ENABLE INPUT_libpng STREQUAL 'system' DISABLE INPUT_libpng STREQUAL 'qt' ) +qt_feature("imageio-text-loading" PRIVATE + LABEL "Image Text section loading" +) +qt_feature_definition("imageio-text-loading" "QT_NO_IMAGEIO_TEXT_LOADING" NEGATE) qt_feature("sessionmanager" PUBLIC SECTION "Kernel" LABEL "Session Management" diff --git a/src/gui/configure.json b/src/gui/configure.json index 377865679d..af513346a2 100644 --- a/src/gui/configure.json +++ b/src/gui/configure.json @@ -1366,6 +1366,13 @@ "condition": "features.png && libs.libpng", "output": [ "privateFeature" ] }, + "imageio-text-loading": { + "label": "Image Text section loading", + "output": [ + "privateFeature", + { "type": "define", "negative": true, "name": "QT_NO_IMAGEIO_TEXT_LOADING" } + ] + }, "qpa_default_platform": { "label": "QPA default platform", "condition": "features.gui", diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index f66ab2778a..e49c795792 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -530,6 +530,7 @@ static void qt_png_warning(png_structp /*png_ptr*/, png_const_charp message) void QPngHandlerPrivate::readPngTexts(png_info *info) { +#ifndef QT_NO_IMAGEIO_TEXT_LOADING png_textp text_ptr; int num_text=0; png_get_text(png_ptr, info, &text_ptr, &num_text); @@ -552,6 +553,9 @@ void QPngHandlerPrivate::readPngTexts(png_info *info) readTexts.append(value); text_ptr++; } +#else + Q_UNUSED(info) +#endif } diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp index fed585a82e..25b0c625fd 100644 --- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp +++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp @@ -956,6 +956,7 @@ bool QJpegHandlerPrivate::readJpegHeader(QIODevice *device) for (jpeg_saved_marker_ptr marker = info.marker_list; marker != nullptr; marker = marker->next) { if (marker->marker == JPEG_COM) { +#ifndef QT_NO_IMAGEIO_TEXT_LOADING QString key, value; QString s = QString::fromUtf8((const char *)marker->data, marker->data_length); int index = s.indexOf(QLatin1String(": ")); @@ -971,6 +972,7 @@ bool QJpegHandlerPrivate::readJpegHeader(QIODevice *device) description += key + QLatin1String(": ") + value.simplified(); readTexts.append(key); readTexts.append(value); +#endif } else if (marker->marker == JPEG_APP0 + 1) { exifData.append((const char*)marker->data, marker->data_length); } else if (marker->marker == JPEG_APP0 + 2) {