mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 10:22:49 +00:00
kioslave: implement rotation of thumbnail for any kind of image
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
92ebbae660
commit
fce69c3dc4
11 changed files with 121 additions and 457 deletions
|
@ -23,7 +23,7 @@ build_script:
|
|||
libxcb-record0-dev libglu1-mesa-dev mesa-common-dev libmtp-dev python \
|
||||
libgps-dev libusb-1.0-0-dev libssh-dev libsmbclient-dev perl-base \
|
||||
libdrm-dev libraw1394-dev libsensors4-dev libgles2-mesa-dev libpam0g-dev \
|
||||
libpci-dev libopenexr-dev liblzma-dev libexiv2-dev libbz2-dev libjpeg-dev \
|
||||
libpci-dev libopenexr-dev liblzma-dev libbz2-dev libjpeg-dev \
|
||||
libdbusmenu-katie ccache
|
||||
|
||||
export PATH="/usr/lib/ccache/:$PATH"
|
||||
|
|
|
@ -6,24 +6,12 @@ set_package_properties(OpenEXR PROPERTIES
|
|||
TYPE OPTIONAL
|
||||
)
|
||||
|
||||
macro_optional_find_package(Exiv2)
|
||||
set_package_properties(Exiv2 PROPERTIES
|
||||
DESCRIPTION "A library to access image metadata"
|
||||
URL "http://www.exiv2.org"
|
||||
PURPOSE "Provides support for automatic rotation of JPEGs in the thumbnail kioslave"
|
||||
TYPE OPTIONAL
|
||||
)
|
||||
|
||||
find_program(WRESTOOL_EXECUTABLE wrestool)
|
||||
add_feature_info(wrestool
|
||||
WRESTOOL_EXECUTABLE
|
||||
"ICO thumbnails support in KIO slave"
|
||||
)
|
||||
|
||||
macro_bool_to_01(EXIV2_FOUND HAVE_EXIV2)
|
||||
|
||||
include_directories(${JPEG_INCLUDE_DIR})
|
||||
|
||||
########### next target ###############
|
||||
|
||||
set(kio_thumbnail_PART_SRCS thumbnail.cpp imagefilter.cpp)
|
||||
|
@ -38,10 +26,17 @@ install(TARGETS kio_thumbnail DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
|
|||
|
||||
set(imagethumbnail_PART_SRCS imagecreator.cpp)
|
||||
|
||||
set_source_files_properties(${imagethumbnail_PART_SRCS} PROPERTIES
|
||||
COMPILE_FLAGS "-DHAVE_KEXIV2 ${KDE4_ENABLE_EXCEPTIONS}"
|
||||
)
|
||||
|
||||
kde4_add_kcfg_files(imagethumbnail_PART_SRCS imagecreatorsettings.kcfgc)
|
||||
kde4_add_plugin(imagethumbnail ${imagethumbnail_PART_SRCS})
|
||||
|
||||
target_link_libraries(imagethumbnail ${KDE4_KIO_LIBS})
|
||||
target_link_libraries(imagethumbnail ${KDE4_KIO_LIBS} ${KDE4_KEXIV2_LIBS})
|
||||
|
||||
install(TARGETS imagethumbnail DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
|
||||
install(FILES imagecreatorsettings.kcfg DESTINATION ${KDE4_KCFG_INSTALL_DIR})
|
||||
install(TARGETS imagethumbnail DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
|
||||
|
||||
########### next target ###############
|
||||
|
@ -50,24 +45,6 @@ install( FILES directorythumbnail.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DI
|
|||
|
||||
########### next target ###############
|
||||
|
||||
set(jpegthumbnail_PART_SRCS jpegcreator.cpp)
|
||||
kde4_add_kcfg_files(jpegthumbnail_PART_SRCS jpegcreatorsettings.kcfgc)
|
||||
kde4_add_plugin(jpegthumbnail ${jpegthumbnail_PART_SRCS})
|
||||
|
||||
target_link_libraries(jpegthumbnail ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${JPEG_LIBRARIES} ${KDE4_KIO_LIBS})
|
||||
|
||||
if(HAVE_EXIV2)
|
||||
set_source_files_properties(jpegcreator.cpp PROPERTIES
|
||||
COMPILE_FLAGS "-DHAVE_EXIV2 ${KDE4_ENABLE_EXCEPTIONS}")
|
||||
include_directories(${EXIV2_INCLUDE_DIR})
|
||||
target_link_libraries(jpegthumbnail ${EXIV2_LIBRARIES})
|
||||
endif()
|
||||
|
||||
install(FILES jpegcreatorsettings.kcfg DESTINATION ${KDE4_KCFG_INSTALL_DIR})
|
||||
install(TARGETS jpegthumbnail DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
|
||||
|
||||
########### next target ###############
|
||||
|
||||
set(svgthumbnail_PART_SRCS svgcreator.cpp)
|
||||
|
||||
kde4_add_plugin(svgthumbnail ${svgthumbnail_PART_SRCS})
|
||||
|
@ -167,7 +144,6 @@ install(
|
|||
thumbnail.protocol
|
||||
svgthumbnail.desktop
|
||||
imagethumbnail.desktop
|
||||
jpegthumbnail.desktop
|
||||
textthumbnail.desktop
|
||||
djvuthumbnail.desktop
|
||||
desktopthumbnail.desktop
|
||||
|
|
|
@ -19,12 +19,16 @@
|
|||
*/
|
||||
|
||||
#include "imagecreator.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include "imagecreatorsettings.h"
|
||||
|
||||
#include <QImage>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <kdemacros.h>
|
||||
#include <klocale.h>
|
||||
|
||||
#ifdef HAVE_KEXIV2
|
||||
#include <libkexiv2/kexiv2.h>
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
@ -41,6 +45,16 @@ bool ImageCreator::create(const QString &path, int, int, QImage &img)
|
|||
return false;
|
||||
if (img.depth() != 32)
|
||||
img = img.convertToFormat(img.hasAlphaChannel() ? QImage::Format_ARGB32 : QImage::Format_RGB32);
|
||||
|
||||
#ifdef HAVE_KEXIV2
|
||||
ImageCreatorSettings* settings = ImageCreatorSettings::self();
|
||||
settings->readConfig();
|
||||
if (settings->rotate()) {
|
||||
KExiv2Iface::KExiv2 exiv(path);
|
||||
exiv.rotateExifQImage(img, exiv.getImageOrientation());
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -48,3 +62,21 @@ ThumbCreator::Flags ImageCreator::flags() const
|
|||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
QWidget *ImageCreator::createConfigurationWidget()
|
||||
{
|
||||
QCheckBox *rotateCheckBox = new QCheckBox(i18nc("@option:check", "Rotate the image automatically"));
|
||||
rotateCheckBox->setChecked(ImageCreatorSettings::rotate());
|
||||
return rotateCheckBox;
|
||||
}
|
||||
|
||||
void ImageCreator::writeConfiguration(const QWidget *configurationWidget)
|
||||
{
|
||||
const QCheckBox *rotateCheckBox = qobject_cast<const QCheckBox*>(configurationWidget);
|
||||
if (rotateCheckBox) {
|
||||
ImageCreatorSettings* settings = ImageCreatorSettings::self();
|
||||
settings->setRotate(rotateCheckBox->isChecked());
|
||||
settings->writeConfig();
|
||||
}
|
||||
}
|
|
@ -28,6 +28,8 @@ public:
|
|||
ImageCreator() {}
|
||||
virtual bool create(const QString &path, int, int, QImage &img);
|
||||
virtual Flags flags() const;
|
||||
virtual QWidget *createConfigurationWidget();
|
||||
virtual void writeConfiguration(const QWidget *configurationWidget);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE kcfg SYSTEM "http://www.kde.org/standards/kcfg/1.0/kcfg.dtd">
|
||||
<kcfg>
|
||||
<kcfgfile name="jpegcreatorrc"/>
|
||||
<kcfgfile name="imagecreatorrc"/>
|
||||
<group name="General">
|
||||
<entry name="rotate" type="bool">
|
||||
<label>Rotate JPEG automatically</label>
|
||||
<label>Rotate the image automatically</label>
|
||||
<default>true</default>
|
||||
</entry>
|
||||
</group>
|
4
kioslave/thumbnail/imagecreatorsettings.kcfgc
Normal file
4
kioslave/thumbnail/imagecreatorsettings.kcfgc
Normal file
|
@ -0,0 +1,4 @@
|
|||
File=imagecreatorsettings.kcfg
|
||||
ClassName=ImageCreatorSettings
|
||||
Singleton=true
|
||||
Mutators=true
|
|
@ -1,76 +1,77 @@
|
|||
[Desktop Entry]
|
||||
Type=Service
|
||||
Name=Images (GIF, PNG, BMP, ...)
|
||||
Name[ar]=صور (GIF, PNG, BMP, ...)
|
||||
Name[ast]=Imáxenes (GIF, PNG, BMP...)
|
||||
Name[bg]=Изображения (GIF, PNG, BMP, ...)
|
||||
Name[bn]=ছবি (GIF, PNG, BMP, ...)
|
||||
Name[bs]=Slike (GIF, PNG, BMP...)
|
||||
Name[ca]=Imatges (GIF, PNG, BMP...)
|
||||
Name[ca@valencia]=Imatges (GIF, PNG, BMP...)
|
||||
Name[cs]=Obrázky (GIF, PNG, BMP, ...)
|
||||
Name[da]=Billeder (GIF, PNG, BMP, ...)
|
||||
Name[de]=Bilder (GIF, PNG, BMP ...)
|
||||
Name[el]=Εικόνες (GIF, PNG, BMP, ...)
|
||||
Name[en_GB]=Images (GIF, PNG, BMP, ...)
|
||||
Name[eo]=Bildoj (GIF, PNG, BMP, ...)
|
||||
Name[es]=Imágenes (GIF, PNG, BMP...)
|
||||
Name[et]=Pildid (GIF, PNG, BMP...)
|
||||
Name[eu]=Irudiak (GIF, PNG, BMP, ...)
|
||||
Name[fa]=تصاویر (GIF, PNG, BMP, ...)
|
||||
Name[fi]=Kuvat (GIF, PNG, BMP, …)
|
||||
Name[fr]=Images (GIF, PNG, BMP, etc.)
|
||||
Name[ga]=Íomhánna (GIF, PNG, BMP, ...)
|
||||
Name[gl]=Imaxes (GIF, PNG, BMP, ...)
|
||||
Name[gu]=ચિત્રો (GIF, PNG, BMP, ...)
|
||||
Name[he]=תמונות (GIF, PNG, BMP, ...)
|
||||
Name[hi]=छवियाँ (GIF, PNG, BMP, ...)
|
||||
Name[hr]=Slike (GIF, PNG, BMP, …)
|
||||
Name[hu]=Képek (GIF, PNG, BMP, …)
|
||||
Name[ia]=Imagines (GIF, PNG, BMP, ...)
|
||||
Name[id]=Gambar (GIF, PNG, BMP, ...)
|
||||
Name[is]=Myndir (GIF, PNG, BMP, ...)
|
||||
Name[it]=Immagini (GIF, PNG, BMP, ...)
|
||||
Name[ja]=画像 (GIF、PNG、BMP など)
|
||||
Name[ka]=გამოსახულებები (GIF, PNG, BMP, ...)
|
||||
Name[kk]=Кескіндер (GIF, PNG, BMP, ...)
|
||||
Name[km]=រូបភាព (GIF, PNG, BMP, ...)
|
||||
Name[kn]=ಚಿತ್ರಗಳು,(GIF, PNG, BMP, ...)
|
||||
Name[ko]=그림 (GIF, PNG, BMP, ...)
|
||||
Name[lt]=Vaizdai (GIF, PNG, BMP, ...)
|
||||
Name[lv]=Attēli (GIF, PNG, BMP, ...)
|
||||
Name[mai]=चित्र (GIF, PNG, BMP, ...)
|
||||
Name[mr]=प्रतिमा (GIF, PNG, BMP, ...)
|
||||
Name[nb]=Bilder (GIF, PNG, BMP, …)
|
||||
Name[nds]=Biller (GIF, PNG, BMP, ...)
|
||||
Name[nl]=Afbeeldingen (GIF, PNG, BMP, ...)
|
||||
Name[nn]=Bilete (GIF, PNG, BMP osb.)
|
||||
Name[pa]=ਚਿੱਤਰ (GIF, PNG, BMP, ...)
|
||||
Name[pl]=Obrazy (GIF, PNG, BMP, ...)
|
||||
Name[pt]=Imagens (GIF, PNG, BMP, ...)
|
||||
Name[pt_BR]=Imagens (GIF, PNG, BMP, ...)
|
||||
Name[ro]=Imagini (GIF, PNG, BMP, ...)
|
||||
Name[ru]=Изображения (GIF, PNG, BMP, ...)
|
||||
Name[si]=පින්තූර (GIF, PNG, BMP, ...)
|
||||
Name[sk]=Obrázky (GIF, PNG, BMP, ...)
|
||||
Name[sl]=Slike (GIF, PNG, BMP, ...)
|
||||
Name=Images (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[ar]=صور (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[ast]=Imáxenes (GIF, PNG, BMP, JPEG...)
|
||||
Name[bg]=Изображения (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[bn]=ছবি (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[bs]=Slike (GIF, PNG, BMP, JPEG...)
|
||||
Name[ca]=Imatges (GIF, PNG, BMP, JPEG...)
|
||||
Name[ca@valencia]=Imatges (GIF, PNG, BMP, JPEG...)
|
||||
Name[cs]=Obrázky (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[da]=Billeder (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[de]=Bilder (GIF, PNG, BMP, JPEG ...)
|
||||
Name[el]=Εικόνες (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[en_GB]=Images (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[eo]=Bildoj (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[es]=Imágenes (GIF, PNG, BMP, JPEG...)
|
||||
Name[et]=Pildid (GIF, PNG, BMP, JPEG...)
|
||||
Name[eu]=Irudiak (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[fa]=تصاویر (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[fi]=Kuvat (GIF, PNG, BMP, JPEG, …)
|
||||
Name[fr]=Images (GIF, PNG, BMP, JPEG, etc.)
|
||||
Name[ga]=Íomhánna (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[gl]=Imaxes (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[gu]=ચિત્રો (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[he]=תמונות (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[hi]=छवियाँ (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[hr]=Slike (GIF, PNG, BMP, JPEG, …)
|
||||
Name[hu]=Képek (GIF, PNG, BMP, JPEG, …)
|
||||
Name[ia]=Imagines (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[id]=Gambar (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[is]=Myndir (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[it]=Immagini (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[ja]=画像 (GIF、PNG、BMP、JPEG など)
|
||||
Name[ka]=გამოსახულებები (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[kk]=Кескіндер (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[km]=រូបភាព (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[kn]=ಚಿತ್ರಗಳು,(GIF, PNG, BMP, JPEG, ...)
|
||||
Name[ko]=그림 (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[lt]=Vaizdai (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[lv]=Attēli (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[mai]=चित्र (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[mr]=प्रतिमा (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[nb]=Bilder (GIF, PNG, BMP, JPEG, …)
|
||||
Name[nds]=Biller (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[nl]=Afbeeldingen (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[nn]=Bilete (GIF, PNG, BMP, JPEG osb.)
|
||||
Name[pa]=ਚਿੱਤਰ (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[pl]=Obrazy (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[pt]=Imagens (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[pt_BR]=Imagens (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[ro]=Imagini (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[ru]=Изображения (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[si]=පින්තූර (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[sk]=Obrázky (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[sl]=Slike (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[sr]=Слике (ГИФ, ПНГ, БМП...)
|
||||
Name[sr@ijekavian]=Слике (ГИФ, ПНГ, БМП...)
|
||||
Name[sr@ijekavianlatin]=Slike (GIF, PNG, BMP...)
|
||||
Name[sr@latin]=Slike (GIF, PNG, BMP...)
|
||||
Name[sv]=Bilder (GIF, PNG, BMP, ...)
|
||||
Name[tg]=Тасвирҳо (GIF, PNG, BMP, ...)
|
||||
Name[th]=แฟ้มภาพต่าง ๆ (GIF, PNG, BMP, ...)
|
||||
Name[tr]=Resimler (GIF, PNG, BMP, ...)
|
||||
Name[ug]=سۈرەتلەر (GIF, PNG, BMP, ...)
|
||||
Name[uk]=Зображення (GIF, PNG, BMP…)
|
||||
Name[vi]=Ảnh (GIF, PNG, BMP,... )
|
||||
Name[wa]=Imådjes (GIF, PNG, BMP...)
|
||||
Name[x-test]=xxImages (GIF, PNG, BMP, ...)xx
|
||||
Name[zh_CN]=图像 (GIF、PNG、BMP ...)
|
||||
Name[zh_TW]=影像(GIF、PNG、BMP...)
|
||||
Name[sr@ijekavianlatin]=Slike (GIF, PNG, BMP, JPEG...)
|
||||
Name[sr@latin]=Slike (GIF, PNG, BMP, JPEG...)
|
||||
Name[sv]=Bilder (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[tg]=Тасвирҳо (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[th]=แฟ้มภาพต่าง ๆ (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[tr]=Resimler (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[ug]=سۈرەتلەر (GIF, PNG, BMP, JPEG, ...)
|
||||
Name[uk]=Зображення (GIF, PNG, BMP, JPEG…)
|
||||
Name[vi]=Ảnh (GIF, PNG, BMP, JPEG,... )
|
||||
Name[wa]=Imådjes (GIF, PNG, BMP, JPEG...)
|
||||
Name[x-test]=xxImages (GIF, PNG, BMP, JPEG, ...)xx
|
||||
Name[zh_CN]=图像 (GIF、PNG、BMP、JPEG ...)
|
||||
Name[zh_TW]=影像(GIF、PNG、BMP、JPEG...)
|
||||
X-KDE-ServiceTypes=ThumbCreator
|
||||
MimeType=image/cgm;image/fax-g3;image/gif;image/jp2;image/png;image/x-png;image/tiff;image/bmp;image/x-dds;image/x-ico;image/x-pcx;image/x-photo-cd;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-rgb;image/x-tga;image/x-xbitmap;image/x-xcf;image/x-xpixmap;image/x-sun-raster;image/vnd.adobe.photoshop;image/x-psd;image/x-hdr;image/x-pic;image/vnd.microsoft.icon;image/x-icon;image/x-webp;image/webp;
|
||||
MimeType=image/cgm;image/fax-g3;image/gif;image/jp2;image/jpeg;image/png;image/x-png;image/tiff;image/bmp;image/x-dds;image/x-ico;image/x-pcx;image/x-photo-cd;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-rgb;image/x-tga;image/x-xbitmap;image/x-xcf;image/x-xpixmap;image/x-sun-raster;image/vnd.adobe.photoshop;image/x-psd;image/x-hdr;image/x-pic;image/vnd.microsoft.icon;image/x-icon;image/x-webp;image/webp;
|
||||
X-KDE-Library=imagethumbnail
|
||||
X-KDE-PluginInfo-EnabledByDefault=true
|
||||
CacheThumbnail=true
|
||||
Configurable=true
|
||||
|
|
|
@ -1,227 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2008 Andre Gemünd <scroogie@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "jpegcreator.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <csetjmp>
|
||||
#include "jpegcreatorsettings.h"
|
||||
#include <QCheckBox>
|
||||
#include <QFile>
|
||||
#include <QImage>
|
||||
#include <kdemacros.h>
|
||||
#include <klocale.h>
|
||||
|
||||
#ifdef HAVE_EXIV2
|
||||
#include <exiv2/image.hpp>
|
||||
#include <exiv2/exif.hpp>
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <jpeglib.h>
|
||||
|
||||
KDE_EXPORT ThumbCreator *new_creator()
|
||||
{
|
||||
return new JpegCreator;
|
||||
}
|
||||
}
|
||||
|
||||
struct jpeg_custom_error_mgr
|
||||
{
|
||||
struct jpeg_error_mgr builtin;
|
||||
jmp_buf setjmp_buffer;
|
||||
};
|
||||
|
||||
void jpeg_custom_error_callback(j_common_ptr jpegDecompress)
|
||||
{
|
||||
jpeg_custom_error_mgr *custom_err = (jpeg_custom_error_mgr *)jpegDecompress->err;
|
||||
|
||||
// jump to error recovery (fallback to old method)
|
||||
longjmp(custom_err->setjmp_buffer, 1);
|
||||
}
|
||||
|
||||
JpegCreator::JpegCreator()
|
||||
{
|
||||
}
|
||||
|
||||
QTransform JpegCreator::orientationMatrix(int exivOrientation) const
|
||||
{
|
||||
//Check (e.g.) man jpegexiforient for an explanation
|
||||
switch (exivOrientation) {
|
||||
case 2:
|
||||
return QTransform(-1, 0, 0, 1, 0, 0);
|
||||
case 3:
|
||||
return QTransform(-1, 0, 0, -1, 0, 0);
|
||||
case 4:
|
||||
return QTransform(1, 0, 0, -1, 0, 0);
|
||||
case 5:
|
||||
return QTransform(0, 1, 1, 0, 0, 0);
|
||||
case 6:
|
||||
return QTransform(0, 1, -1, 0, 0, 0);
|
||||
case 7:
|
||||
return QTransform(0, -1, -1, 0, 0, 0);
|
||||
case 8:
|
||||
return QTransform(0, -1, 1, 0, 0, 0);
|
||||
case 1:
|
||||
default:
|
||||
return QTransform(1, 0, 0, 1, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a faster thumbnail creation specifically for JPEG images, as it uses the libjpeg feature of
|
||||
* calculating the inverse dct for a part of coefficients for lower resolutions.
|
||||
* Interesting parameters are the quality settings of libjpeg
|
||||
* jpegDecompress.do_fancy_upsampling (TRUE, FALSE)
|
||||
* jpegDecompress.do_block_smoothing (TRUE, FALSE)
|
||||
* jpegDecompress.dct_method (JDCT_IFAST, JDCT_ISLOW, JDCT_IFLOAT)
|
||||
* and the resampling parameter of QImage.
|
||||
*
|
||||
* Important: We do not need to scaled to exact dimesions, as thumbnail.cpp will check dimensions and
|
||||
* rescale anyway.
|
||||
*/
|
||||
bool JpegCreator::create(const QString &path, int width, int height, QImage &image)
|
||||
{
|
||||
QImage img;
|
||||
const QByteArray name = QFile::encodeName(path);
|
||||
FILE *jpegFile = fopen(name.constData(), "rb");
|
||||
if (jpegFile == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// create jpeglib data structures and calculate scale denominator
|
||||
struct jpeg_decompress_struct jpegDecompress;
|
||||
struct jpeg_custom_error_mgr jpegError;
|
||||
jpegDecompress.err = jpeg_std_error(&jpegError.builtin);
|
||||
jpeg_create_decompress(&jpegDecompress);
|
||||
jpeg_stdio_src(&jpegDecompress, jpegFile);
|
||||
jpeg_read_header(&jpegDecompress, TRUE);
|
||||
|
||||
const double ratioWidth = jpegDecompress.image_width / (double)width;
|
||||
const double ratioHeight = jpegDecompress.image_height / (double)height;
|
||||
int scale = 1;
|
||||
if (ratioWidth > 7 || ratioHeight > 7) {
|
||||
scale = 8;
|
||||
} else if (ratioWidth > 3.5 || ratioHeight > 3.5) {
|
||||
scale = 4;
|
||||
} else if (ratioWidth > 1.75 || ratioHeight > 1.75) {
|
||||
scale = 2;
|
||||
}
|
||||
|
||||
// set jpeglib decompression parameters
|
||||
jpegDecompress.scale_num = 1;
|
||||
jpegDecompress.scale_denom = scale;
|
||||
jpegDecompress.do_fancy_upsampling = FALSE;
|
||||
jpegDecompress.do_block_smoothing = FALSE;
|
||||
jpegDecompress.dct_method = JDCT_IFAST;
|
||||
jpegDecompress.err->error_exit = jpeg_custom_error_callback;
|
||||
jpegDecompress.out_color_space = JCS_RGB;
|
||||
|
||||
jpeg_calc_output_dimensions(&jpegDecompress);
|
||||
|
||||
if (setjmp(jpegError.setjmp_buffer)) {
|
||||
jpeg_abort_decompress(&jpegDecompress);
|
||||
fclose(jpegFile);
|
||||
// libjpeg version failed, fall back to direct loading of QImage
|
||||
if (!img.load(path)) {
|
||||
return false;
|
||||
}
|
||||
if (img.depth() != 32) {
|
||||
img = img.convertToFormat(QImage::Format_RGB32);
|
||||
}
|
||||
} else {
|
||||
jpeg_start_decompress(&jpegDecompress);
|
||||
img = QImage(jpegDecompress.output_width, jpegDecompress.output_height, QImage::Format_RGB32);
|
||||
uchar *buffer = img.bits();
|
||||
const int bpl = img.bytesPerLine();
|
||||
while (jpegDecompress.output_scanline < jpegDecompress.output_height) {
|
||||
// advance line-pointer to next line
|
||||
uchar *line = buffer + jpegDecompress.output_scanline * bpl;
|
||||
jpeg_read_scanlines(&jpegDecompress, &line, 1);
|
||||
}
|
||||
jpeg_finish_decompress(&jpegDecompress);
|
||||
|
||||
// align correctly for QImage
|
||||
// code copied from Gwenview and digiKam
|
||||
for (int i = 0; i < int(jpegDecompress.output_height); ++i) {
|
||||
uchar *in = img.scanLine(i) + jpegDecompress.output_width * 3;
|
||||
QRgb *out = (QRgb*)img.scanLine(i);
|
||||
for (int j = jpegDecompress.output_width - 1; j >= 0; --j) {
|
||||
in -= 3;
|
||||
out[j] = qRgb(in[0], in[1], in[2]);
|
||||
}
|
||||
}
|
||||
fclose(jpegFile);
|
||||
jpeg_destroy_decompress(&jpegDecompress);
|
||||
}
|
||||
|
||||
#ifdef HAVE_EXIV2
|
||||
JpegCreatorSettings* settings = JpegCreatorSettings::self();
|
||||
settings->readConfig();
|
||||
if (settings->rotate()) {
|
||||
//Handle exif rotation
|
||||
try {
|
||||
Exiv2::Image::AutoPtr exivImg = Exiv2::ImageFactory::open(name.constData());
|
||||
if (exivImg.get()) {
|
||||
exivImg->readMetadata();
|
||||
Exiv2::ExifData exifData = exivImg->exifData();
|
||||
if (!exifData.empty()) {
|
||||
Exiv2::ExifKey key("Exif.Image.Orientation");
|
||||
Exiv2::ExifData::iterator it = exifData.findKey(key);
|
||||
if (it != exifData.end()) {
|
||||
int orient = it->toLong();
|
||||
image = img.transformed(orientationMatrix(orient));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
// Apparently libexiv changed its API at some point, a different exception is thrown
|
||||
// depending on the version. an ifdef could make it work, but since we just ignore the exception
|
||||
// there is no point in doing that
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
image = img;
|
||||
return true;
|
||||
}
|
||||
|
||||
ThumbCreator::Flags JpegCreator::flags() const
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
QWidget *JpegCreator::createConfigurationWidget()
|
||||
{
|
||||
QCheckBox *rotateCheckBox = new QCheckBox(i18nc("@option:check", "Rotate the image automatically"));
|
||||
rotateCheckBox->setChecked(JpegCreatorSettings::rotate());
|
||||
return rotateCheckBox;
|
||||
}
|
||||
|
||||
void JpegCreator::writeConfiguration(const QWidget *configurationWidget)
|
||||
{
|
||||
const QCheckBox *rotateCheckBox = qobject_cast<const QCheckBox*>(configurationWidget);
|
||||
if (rotateCheckBox) {
|
||||
JpegCreatorSettings* settings = JpegCreatorSettings::self();
|
||||
settings->setRotate(rotateCheckBox->isChecked());
|
||||
settings->writeConfig();
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2008 Andre Gemünd <scroogie@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _JPEGCREATOR_H_
|
||||
#define _JPEGCREATOR_H_
|
||||
|
||||
#include <kio/thumbcreator.h>
|
||||
|
||||
#include <QTransform>
|
||||
|
||||
class JpegCreator : public ThumbCreator
|
||||
{
|
||||
public:
|
||||
JpegCreator();
|
||||
virtual bool create(const QString &path, int, int, QImage &img);
|
||||
virtual Flags flags() const;
|
||||
virtual QWidget *createConfigurationWidget();
|
||||
virtual void writeConfiguration(const QWidget *configurationWidget);
|
||||
private:
|
||||
QTransform orientationMatrix(int exivOrientation) const;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,4 +0,0 @@
|
|||
File=jpegcreatorsettings.kcfg
|
||||
ClassName=JpegCreatorSettings
|
||||
Singleton=true
|
||||
Mutators=true
|
|
@ -1,81 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Type=Service
|
||||
Name=JPEG Images
|
||||
Name[ar]=صور JPEG
|
||||
Name[ast]=Imáxenes JPEG
|
||||
Name[bg]=Изображения JPEG
|
||||
Name[bn]=JPEG ছবি
|
||||
Name[bs]=JPEG slike
|
||||
Name[ca]=Imatges JPEG
|
||||
Name[ca@valencia]=Imatges JPEG
|
||||
Name[cs]=JPEG obrázky
|
||||
Name[csb]=Òbrôzczi JPEG
|
||||
Name[da]=JPEG-billeder
|
||||
Name[de]=JPEG-Bilder
|
||||
Name[el]=Εικόνες JPEG
|
||||
Name[en_GB]=JPEG Images
|
||||
Name[eo]=JPEG-bildoj
|
||||
Name[es]=Imágenes JPEG
|
||||
Name[et]=JPEG pildid
|
||||
Name[eu]=JPEG irudiak
|
||||
Name[fa]=تصاویر JPEG
|
||||
Name[fi]=JPEG-kuvat
|
||||
Name[fr]=Images JPEG
|
||||
Name[fy]=JPEG-ôfbyldings
|
||||
Name[ga]=Íomhánna JPEG
|
||||
Name[gl]=Imaxes JPEG
|
||||
Name[gu]=JPEG ચિત્રો
|
||||
Name[he]=תמונות JPEG
|
||||
Name[hi]=जेपीजी छवियाँ
|
||||
Name[hr]=JPEG slike
|
||||
Name[hu]=JPEG-képek
|
||||
Name[ia]=Imagines JPEG
|
||||
Name[id]=Gambar JPEG
|
||||
Name[is]=JPEG myndir
|
||||
Name[it]=Immagini JPEG
|
||||
Name[ja]=JPEG 画像
|
||||
Name[kk]=JPEG кескіндері
|
||||
Name[km]=រូបភាព JPEG
|
||||
Name[kn]=JPEG ಚಿತ್ರಗಳು
|
||||
Name[ko]=JPEG 그림
|
||||
Name[lt]=JPEG nuotraukos
|
||||
Name[lv]=JPEG attēli
|
||||
Name[mai]=JPEG चित्र
|
||||
Name[mk]=JPEG-слики
|
||||
Name[ml]=ജെപെഗ് ചിത്രങ്ങള്
|
||||
Name[mr]=JPEG प्रतिमा
|
||||
Name[nb]=JPEG-bilder
|
||||
Name[nds]=JPEG-Biller
|
||||
Name[nl]=JPEG-afbeeldingen
|
||||
Name[nn]=JPEG-bilete
|
||||
Name[pa]=JPEG ਚਿੱਤਰ
|
||||
Name[pl]=Obrazy JPEG
|
||||
Name[pt]=Imagens JPEG
|
||||
Name[pt_BR]=Imagens JPEG
|
||||
Name[ro]=Imagini JPEG
|
||||
Name[ru]=Изображения JPEG
|
||||
Name[si]=JPEG පින්තූර
|
||||
Name[sk]=Obrázky JPEG
|
||||
Name[sl]=Slike JPEG
|
||||
Name[sr]=ЈПЕГ слике
|
||||
Name[sr@ijekavian]=ЈПЕГ слике
|
||||
Name[sr@ijekavianlatin]=JPEG slike
|
||||
Name[sr@latin]=JPEG slike
|
||||
Name[sv]=JPEG-bilder
|
||||
Name[tg]=Тасвирҳои JPEG
|
||||
Name[th]=แฟ้มภาพประเภท JPEG
|
||||
Name[tr]=JPEG Resimleri
|
||||
Name[ug]=JPEG سۈرەتلەر
|
||||
Name[uk]=Зображення JPEG
|
||||
Name[vi]=Ảnh JPEG
|
||||
Name[wa]=Imådjes JPEG
|
||||
Name[x-test]=xxJPEG Imagesxx
|
||||
Name[zh_CN]=JPEG 图像
|
||||
Name[zh_TW]=JPEG 影像
|
||||
X-KDE-ServiceTypes=ThumbCreator
|
||||
MimeType=image/jpeg;
|
||||
X-KDE-Library=jpegthumbnail
|
||||
X-KDE-PluginInfo-EnabledByDefault=true
|
||||
CacheThumbnail=true
|
||||
Configurable=true
|
||||
ThumbnailerVersion=2
|
Loading…
Add table
Reference in a new issue