Changeset View
Changeset View
Standalone View
Standalone View
lib/thumbnailprovider/thumbnailgenerator.cpp
Context not available. | |||||
22 | #include "thumbnailgenerator.h" | 22 | #include "thumbnailgenerator.h" | ||
---|---|---|---|---|---|
23 | 23 | | |||
24 | // Local | 24 | // Local | ||
25 | #include "jpegcontent.h" | | |||
26 | #include "gwenviewconfig.h" | 25 | #include "gwenviewconfig.h" | ||
27 | #include "exiv2imageloader.h" | 26 | #include "exiv2imageloader.h" | ||
28 | 27 | | |||
Context not available. | |||||
58 | { | 57 | { | ||
59 | mImage = QImage(); | 58 | mImage = QImage(); | ||
60 | mNeedCaching = true; | 59 | mNeedCaching = true; | ||
61 | QImage originalImage; | 60 | | ||
62 | QSize originalSize; | 61 | Exiv2ImageLoader content; | ||
62 | bool exivContentAvailable = content.load(pixPath); | ||||
63 | int previewRatio = 1; | ||||
64 | | ||||
65 | // If there's jpeg content (from jpg or raw files), try to load an embedded thumbnail, if available. | ||||
66 | if (exivContentAvailable) { | ||||
67 | QImage thumbnail = content.thumbnail(); | ||||
68 | | ||||
69 | // If the user does not care about the generated thumbnails (by deleting them on exit), use ANY | ||||
70 | // embedded thumnail, even if it's too small. | ||||
71 | if (!thumbnail.isNull() && | ||||
72 | (GwenviewConfig::lowResourceUsageMode() || qMax(thumbnail.width(), thumbnail.height()) >= pixelSize) | ||||
73 | ) { | ||||
74 | mImage = std::move(thumbnail); | ||||
75 | mOriginalWidth = content.size().width(); | ||||
76 | mOriginalHeight = content.size().height(); | ||||
77 | return true; | ||||
78 | } | ||||
79 | } | ||||
63 | 80 | | |||
64 | QByteArray formatHint = pixPath.section(QLatin1Char('.'), -1).toLocal8Bit().toLower(); | 81 | QByteArray formatHint = pixPath.section(QLatin1Char('.'), -1).toLocal8Bit().toLower(); | ||
65 | QImageReader reader(pixPath); | 82 | QImageReader reader(pixPath); | ||
66 | 83 | | |||
67 | JpegContent content; | 84 | #ifdef KDCRAW_FOUND | ||
68 | QByteArray format; | | |||
69 | QByteArray data; | 85 | QByteArray data; | ||
70 | QBuffer buffer; | 86 | QBuffer buffer; | ||
71 | int previewRatio = 1; | | |||
72 | | ||||
73 | #ifdef KDCRAW_FOUND | | |||
74 | // raw images deserve special treatment | 87 | // raw images deserve special treatment | ||
75 | if (KDcrawIface::KDcraw::rawFilesList().contains(QString::fromLatin1(formatHint))) { | 88 | if (KDcrawIface::KDcraw::rawFilesList().contains(QString::fromLatin1(formatHint))) { | ||
76 | // use KDCraw to extract the preview | 89 | // use KDCraw to extract the preview | ||
77 | bool ret = KDcrawIface::KDcraw::loadEmbeddedPreview(data, pixPath); | 90 | bool ret = KDcrawIface::KDcraw::loadEmbeddedPreview(data, pixPath); | ||
78 | 91 | | |||
79 | // We need QImage. Loading JpegContent from QImage - exif lost | | |||
80 | // Loading QImage from JpegContent - unimplemented, would go with loadFromData | | |||
81 | if (!ret) { | 92 | if (!ret) { | ||
82 | // if the embedded preview loading failed, load half preview instead. That's slower... | 93 | // if the embedded preview loading failed, load half preview instead. That's slower... | ||
83 | if (!KDcrawIface::KDcraw::loadHalfPreview(data, pixPath)) { | 94 | if (!KDcrawIface::KDcraw::loadHalfPreview(data, pixPath)) { | ||
Context not available. | |||||
87 | previewRatio = 2; | 98 | previewRatio = 2; | ||
88 | } | 99 | } | ||
89 | 100 | | |||
90 | // And we need JpegContent too because of EXIF (orientation!). | | |||
91 | if (!content.loadFromData(data)) { | | |||
92 | qWarning() << "unable to load preview for " << pixPath.toUtf8().constData(); | | |||
93 | return false; | | |||
94 | } | | |||
95 | | ||||
96 | buffer.setBuffer(&data); | 101 | buffer.setBuffer(&data); | ||
97 | buffer.open(QIODevice::ReadOnly); | 102 | buffer.open(QIODevice::ReadOnly); | ||
98 | reader.setDevice(&buffer); | 103 | reader.setDevice(&buffer); | ||
Context not available. | |||||
106 | // Set filename again, otherwise QImageReader won't restart from scratch | 111 | // Set filename again, otherwise QImageReader won't restart from scratch | ||
107 | reader.setFileName(pixPath); | 112 | reader.setFileName(pixPath); | ||
108 | } | 113 | } | ||
109 | | ||||
110 | if (reader.format() == "jpeg" && GwenviewConfig::applyExifOrientation()) { | | |||
111 | content.load(pixPath); | | |||
112 | } | | |||
113 | } | | |||
114 | | ||||
115 | // If there's jpeg content (from jpg or raw files), try to load an embedded thumbnail, if available. | | |||
116 | if (!content.rawData().isEmpty()) { | | |||
117 | QImage thumbnail = content.thumbnail(); | | |||
118 | | ||||
119 | // If the user does not care about the generated thumbnails (by deleting them on exit), use ANY | | |||
120 | // embedded thumnail, even if it's too small. | | |||
121 | if (!thumbnail.isNull() && | | |||
122 | (GwenviewConfig::lowResourceUsageMode() || qMax(thumbnail.width(), thumbnail.height()) >= pixelSize) | | |||
123 | ) { | | |||
124 | mImage = std::move(thumbnail); | | |||
125 | mOriginalWidth = content.size().width(); | | |||
126 | mOriginalHeight = content.size().height(); | | |||
127 | return true; | | |||
128 | } | | |||
129 | } | 114 | } | ||
130 | 115 | | |||
131 | // Generate thumbnail from full image | 116 | // Generate thumbnail from full image | ||
132 | originalSize = reader.size(); | 117 | QSize originalSize = reader.size(); | ||
133 | if (originalSize.isValid() && reader.supportsOption(QImageIOHandler::ScaledSize) | 118 | if (originalSize.isValid() && reader.supportsOption(QImageIOHandler::ScaledSize) | ||
134 | && qMax(originalSize.width(), originalSize.height()) >= pixelSize) | 119 | && qMax(originalSize.width(), originalSize.height()) >= pixelSize) | ||
135 | { | 120 | { | ||
Context not available. | |||||
146 | } | 131 | } | ||
147 | 132 | | |||
148 | // format() is empty after QImageReader::read() is called | 133 | // format() is empty after QImageReader::read() is called | ||
149 | format = reader.format(); | 134 | QByteArray format = reader.format(); | ||
135 | QImage originalImage; | ||||
150 | if (!reader.read(&originalImage)) { | 136 | if (!reader.read(&originalImage)) { | ||
151 | return false; | 137 | return false; | ||
152 | } | 138 | } | ||
Context not available. |