2
* Copyright (C) 2011 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Lucas Beeler <lucas@yorba.org>
18
* Jim Nelson <jim@yorba.org>
21
#ifndef GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_
22
#define GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_
25
#include "orientation.h"
32
#include <QQuickImageProvider>
40
* Gallery uses a custom image provider for three reasons:
42
* 1. QML's image loader does not respect EXIF orientation. This provider will
43
* rotate and mirror the image as necessary.
45
* 2. QML's image caching appears to be directly related to image size (scaling)
46
* which leads to thrashing when animating a thumbnail or loading images at
47
* various sizes (such as in the album viewer versus the photo viewer).
48
* The strategy here is to cache the largest requested size of the image
49
* and allow QML to downscale it as necessary. This minimizes expensive
50
* JPEG load-and-decodes.
52
* 3. Logging (enabled with --log-image-loading) allows for monitoring of
53
* all image I/O, useful when debugging and optimizing.
55
class GalleryStandardImageProvider : public QObject, public QQuickImageProvider
60
static const char* PROVIDER_ID;
61
static const char* PROVIDER_ID_SCHEME;
63
static const char* REVISION_PARAM_NAME;
64
static const char* ORIENTATION_PARAM_NAME;
66
static const char* SIZE_KEY;
68
GalleryStandardImageProvider();
69
virtual ~GalleryStandardImageProvider();
71
static QUrl toURL(const QFileInfo& file);
73
virtual QImage requestImage(const QString& id, QSize* size,
74
const QSize& requestedSize);
76
void setPreviewManager(PreviewManager* previewManager);
77
void setLogging(bool enableLogging);
78
void setMaxLoadResolution(int resolution);
88
// these fields should only be accessed when imageMutex_ is locked
92
Orientation orientation;
94
// the following should only be accessed when cacheMutex_ is locked; the
95
// counter controls removing a CachedImage entry from the cache table
99
CachedImage(const QString& fileId, const QString& filename);
101
void storeImage(const QImage& newImage, const QSize& newFullSize,
102
Orientation newOrientation);
103
bool isFullSized() const;
104
bool isReady() const;
105
bool isCacheHit(const QSize& requestedSize) const;
108
QMap<QString, CachedImage*> m_cache;
109
QList<QString> m_fifo;
112
PreviewManager* m_previewManager;
113
bool m_logImageLoading;
114
int m_maxLoadResolution;
116
static QSize orientSize(const QSize& size, Orientation orientation);
118
CachedImage* claimCachedImageEntry(const QString& id, QString& loggingStr);
120
QImage fetchCachedImage(CachedImage* cachedImage, const QSize& requestedSize,
121
uint* bytesLoaded, QString& loggingStr);
123
void releaseCachedImageEntry(CachedImage* cachedImage, uint bytesLoaded,
124
long* currentCachedBytes, int* currentCacheEntries);
126
QString idToFile(const QString& id) const;
128
//Allow our test access to private variables.
129
friend class tst_GalleryStandardImageProvider;
132
#endif // GALLERY_GALLERY_STANDARD_IMAGE_PROVIDER_H_