/src/kdegraphics-thumbnailers/raw/rawcreator.cpp
Line | Count | Source |
1 | | /** |
2 | | SPDX-FileCopyrightText: 2008 Unai Garro <ugarro@gmail.com> |
3 | | |
4 | | SPDX-License-Identifier: GPL-2.0-or-later |
5 | | **/ |
6 | | |
7 | | #include "rawcreator.h" |
8 | | |
9 | | #include <QImage> |
10 | | |
11 | | #include <kdcraw/kdcraw.h> |
12 | | #include <kexiv2/kexiv2.h> |
13 | | |
14 | | #include <KPluginFactory> |
15 | | |
16 | 0 | K_PLUGIN_CLASS_WITH_JSON(RAWCreator, "rawthumbnail.json") Unexecuted instantiation: rawthumbnail_factory::tr(char const*, char const*, int) Unexecuted instantiation: rawthumbnail_factory::~rawthumbnail_factory() |
17 | 0 |
|
18 | 0 | RAWCreator::RAWCreator(QObject *parent, const QVariantList &args) |
19 | 719 | : KIO::ThumbnailCreator(parent, args) |
20 | 719 | { |
21 | 719 | } |
22 | | |
23 | | RAWCreator::~RAWCreator() |
24 | 719 | { |
25 | 719 | } |
26 | | |
27 | | KIO::ThumbnailResult RAWCreator::create(const KIO::ThumbnailRequest &request) |
28 | 719 | { |
29 | | //load the image into the QByteArray |
30 | 719 | QByteArray data; |
31 | 719 | bool loaded=KDcrawIface::KDcraw::loadEmbeddedPreview(data,request.url().toLocalFile()); |
32 | | |
33 | 719 | if (!loaded) { |
34 | 719 | return KIO::ThumbnailResult::fail(); |
35 | 719 | } |
36 | | //Load the image into a QImage |
37 | 0 | QImage preview; |
38 | 0 | if (!preview.loadFromData(data) || preview.isNull()) |
39 | 0 | return KIO::ThumbnailResult::fail(); |
40 | | |
41 | | //And its EXIF info |
42 | 0 | KExiv2Iface::KExiv2 exiv; |
43 | 0 | if (exiv.loadFromData(data)) |
44 | 0 | { |
45 | | //We managed reading the EXIF info, rotate the image |
46 | | //according to the EXIF orientation flag |
47 | 0 | KExiv2Iface::KExiv2::ImageOrientation orient=exiv.getImageOrientation(); |
48 | | |
49 | | //Rotate according to the EXIF orientation flag |
50 | 0 | switch(orient) |
51 | 0 | { |
52 | 0 | case KExiv2Iface::KExiv2::ORIENTATION_UNSPECIFIED: |
53 | 0 | case KExiv2Iface::KExiv2::ORIENTATION_NORMAL: |
54 | 0 | break; //we do nothing |
55 | 0 | case KExiv2Iface::KExiv2::ORIENTATION_HFLIP: |
56 | 0 | preview = preview.mirrored(true,false); |
57 | 0 | break; |
58 | 0 | case KExiv2Iface::KExiv2::ORIENTATION_ROT_180: |
59 | 0 | preview = preview.transformed(QTransform().rotate(180)); |
60 | 0 | break; |
61 | 0 | case KExiv2Iface::KExiv2::ORIENTATION_VFLIP: |
62 | 0 | preview = preview.mirrored(false,true); |
63 | 0 | break; |
64 | 0 | case KExiv2Iface::KExiv2::ORIENTATION_ROT_90_HFLIP: |
65 | 0 | preview = preview.mirrored(true,false); |
66 | 0 | preview = preview.transformed(QTransform().rotate(90)); |
67 | 0 | break; |
68 | 0 | case KExiv2Iface::KExiv2::ORIENTATION_ROT_90: |
69 | 0 | preview = preview.transformed(QTransform().rotate(90)); |
70 | 0 | break; |
71 | 0 | case KExiv2Iface::KExiv2::ORIENTATION_ROT_90_VFLIP: |
72 | 0 | preview = preview.mirrored(false,true); |
73 | 0 | preview = preview.transformed(QTransform().rotate(90)); |
74 | 0 | break; |
75 | 0 | case KExiv2Iface::KExiv2::ORIENTATION_ROT_270: |
76 | 0 | preview = preview.transformed(QTransform().rotate(270)); |
77 | 0 | break; |
78 | 0 | default: |
79 | 0 | break; |
80 | 0 | } |
81 | 0 | } |
82 | | |
83 | | //Scale the image as requested by the thumbnailer |
84 | 0 | QImage img=preview.scaled(request.targetSize(),Qt::KeepAspectRatio); |
85 | |
|
86 | 0 | return KIO::ThumbnailResult::pass(img); |
87 | 0 | } |
88 | | |
89 | | #include "rawcreator.moc" |