Commit 56d86012 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[JPEG Thumbnailer] Read thumbnail from EXIF metadata, if available

It's a lot more efficient to read the thumbnail stored within the image
than loading the full image and scaling it down, even though Qt's JPEG
handler and libjpeg do some optimizations and fast downscaling already.
parent 711ea263
Pipeline #198430 passed with stage
in 5 minutes and 26 seconds
......@@ -35,6 +35,14 @@ set_package_properties(Taglib PROPERTIES
PURPOSE "Provides support for audio thumbnails"
)
find_package(KF5KExiv2)
set_package_properties(KF5KExiv2 PROPERTIES
TYPE OPTIONAL
PURPOSE "Provides support for extracting JPEG thumbnails")
if (KF5KExiv2_FOUND)
set(HAVE_KEXIV2 TRUE)
endif()
include_directories(${CMAKE_BINARY_DIR})
include(ECMSetupQtPluginMacroNames)
......@@ -45,6 +53,8 @@ ecm_setup_qtplugin_macro_names(
PACKAGE_SETUP_AUTOMOC_VARIABLES
)
configure_file(config-thumbnail.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-thumbnail.h)
########### next target ###############
add_library(kio_thumbnail MODULE)
......@@ -107,6 +117,9 @@ target_link_libraries(jpegthumbnail
KF5::ConfigCore
KF5::ConfigGui
)
if (TARGET KF5::KExiv2)
target_link_libraries(jpegthumbnail KF5::KExiv2)
endif()
install(FILES jpegcreatorsettings5.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(TARGETS jpegthumbnail DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf${QT_MAJOR_VERSION}/thumbcreator)
......
/*
SPDX-FileCopyrightText: 2022 Kai Uwe Broulik <kde@broulik.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#cmakedefine01 HAVE_KEXIV2
/* This file is part of the KDE libraries
SPDX-FileCopyrightText: 2008 Andre Gemünd <scroogie@gmail.com>
SPDX-FileCopyrightText: 2016 Alexander Volkov <a.volkov@rusbitech.ru>
SPDX-FileCopyrightText: 2022 Kai Uwe Broulik <kde@broulik.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "config-thumbnail.h"
#include "jpegcreator.h"
#include "jpegcreatorsettings5.h"
......@@ -14,16 +17,32 @@
#include <QImageReader>
#include <klocalizedstring.h>
#if HAVE_KEXIV2
#include <KExiv2/KExiv2>
#endif
EXPORT_THUMBNAILER_WITH_JSON(JpegCreator, "jpegthumbnail.json")
JpegCreator::JpegCreator()
{
}
bool JpegCreator::create(const QString &path, int width, int height, QImage &image)
bool JpegCreator::exifThumbnail(const QString &path, QImage &image) const
{
QImageReader imageReader(path, "jpeg");
#if HAVE_KEXIV2
KExiv2Iface::KExiv2 exiv2Image(path);
image = exiv2Image.getExifThumbnail(JpegCreatorSettings::self()->rotate());
return !image.isNull();
#else
Q_UNUSED(path)
Q_UNUSED(image)
return false;
#endif // HAVE_KEXIV2
}
bool JpegCreator::imageReaderThumbnail(const QString &path, int width, int height, QImage &image) const
{
QImageReader imageReader(path, "jpeg");
const QSize imageSize = imageReader.size();
if (imageSize.isValid() && (imageSize.width() > width || imageSize.height() > height)) {
const QSize thumbnailSize = imageSize.scaled(width, height, Qt::KeepAspectRatio);
......@@ -31,11 +50,24 @@ bool JpegCreator::create(const QString &path, int width, int height, QImage &ima
}
imageReader.setQuality(75); // set quality so that the jpeg handler will use a high quality downscaler
JpegCreatorSettings* settings = JpegCreatorSettings::self();
settings->load();
imageReader.setAutoTransform(settings->rotate());
imageReader.setAutoTransform(JpegCreatorSettings::self()->rotate());
return imageReader.read(&image);
}
bool JpegCreator::create(const QString &path, int width, int height, QImage &image)
{
JpegCreatorSettings::self()->load();
if (exifThumbnail(path, image)) {
return true;
}
if (imageReaderThumbnail(path, width, height, image)) {
return true;
}
return false;
}
#include "jpegcreator.moc"
/* This file is part of the KDE libraries
SPDX-FileCopyrightText: 2008 Andre Gemünd <scroogie@gmail.com>
SPDX-FileCopyrightText: 2022 Kai Uwe Broulik <kde@broulik.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
......@@ -16,6 +17,9 @@ class JpegCreator : public ThumbCreator
public:
JpegCreator();
bool create(const QString &path, int, int, QImage &img) override;
private:
bool exifThumbnail(const QString &path, QImage &image) const;
bool imageReaderThumbnail(const QString &path, int width, int height, QImage &image) const;
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment