Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qsharedimageprovider.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <private/qquickpixmapcache_p.h>
6#include <private/qimage_p.h>
7#include <QImageReader>
8#include <QFileInfo>
9#include <QDir>
10
12
14
16
18{
19 QImageReader imgio(path);
20 QSize realSize = imgio.size();
21 QSize requestSize;
23 if (params) {
24 requestSize = params->value(RequestedSize).toSize();
25 options = params->value(ProviderOptions).value<QQuickImageProviderOptions>();
26 }
27
28 QSize scSize = QQuickImageProviderWithOptions::loadSize(imgio.size(), requestSize, imgio.format(), options);
29
30 if (scSize.isValid())
31 imgio.setScaledSize(scSize);
32
34 if (imgio.read(&image)) {
35 if (realSize.isEmpty())
36 realSize = image.size();
37 // Make sure we have acceptable format for texture uploader, or it will convert & lose sharing
38 // This mimics the testing & conversion normally done by the quick pixmapcache & texturefactory
41 if (image.hasAlphaChannel() && image.data_ptr()->checkForAlphaPixels())
43 qCDebug(lcSharedImage) << "Convert on load from format" << image.format() << "to" << newFmt;
44 image = image.convertToFormat(newFmt);
45 }
46 }
47
48 if (params && params->size() > OriginalSize)
49 params->replace(OriginalSize, realSize);
50
51 return image;
52}
53
55{
56 QSize reqSz;
58 if (params) {
59 reqSz = params->value(RequestedSize).toSize();
61 }
62 if (!reqSz.isValid())
63 return path;
64 int aspect = opts.preserveAspectRatioCrop() || opts.preserveAspectRatioFit() ? 1 : 0;
65
66 QString key = path + QStringLiteral("_%1x%2_%3").arg(reqSz.width()).arg(reqSz.height()).arg(aspect);
67 qCDebug(lcSharedImage) << "KEY:" << key;
68 return key;
69}
70
73{
74}
75
77{
78 QFileInfo fi(QDir::root(), id);
80 if (path.isEmpty())
81 return QImage();
82
84 params[QuickSharedImageLoader::RequestedSize].setValue(requestedSize);
86
88 if (img.isNull()) {
89 // May be sharing problem, fall back to normal local load
91 if (!img.isNull())
92 qCWarning(lcSharedImage) << "Sharing problem; loading" << id << "unshared";
93 }
94
95 //... QSize realSize = params.value(QSharedImageLoader::OriginalSize).toSize();
96 // quickpixmapcache's readImage() reports back the original size, prior to requestedSize scaling, in the *size
97 // parameter. That value is currently ignored by quick however, which only cares about the present size of the
98 // returned image. So handling and sharing of info on pre-scaled size is currently not implemented.
99 if (size) {
100 *size = img.size();
101 }
102
103 return img;
104}
105
107
108#include "moc_qsharedimageprovider_p.cpp"
static QDir root()
Returns the root directory.
Definition qdir.h:221
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
The QImageReader class provides a format independent interface for reading images from files or other...
void setScaledSize(const QSize &size)
Sets the scaled size of the image to size.
QByteArray format() const
Returns the format QImageReader uses for reading images.
QSize size() const
Returns the size of the image, without actually reading the image contents.
QImage read()
Reads an image from the device.
\inmodule QtGui
Definition qimage.h:37
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_RGB32
Definition qimage.h:46
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
Definition qlist.h:74
\inmodule QtCore
Definition qobject.h:90
The QQuickImageProviderOptions class provides options for QQuickImageProviderWithOptions image reques...
bool preserveAspectRatioFit() const
Returns whether the image request is for a PreserveAspectFit Image.
bool preserveAspectRatioCrop() const
Returns whether the image request is for a PreserveAspectCrop Image.
static QSize loadSize(const QSize &originalSize, const QSize &requestedSize, const QByteArray &format, const QQuickImageProviderOptions &options, qreal devicePixelRatio=1.0)
Returns the recommended scaled image size for loading and storage.
The QQuickImageProvider class provides an interface for supporting pixmaps and threaded image request...
QImage load(const QString &path, ImageParameters *params=nullptr)
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
Definition qsize.h:123
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:126
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QuickSharedImageLoader(QObject *parent=nullptr)
QString key(const QString &path, ImageParameters *params) override
QImage loadFile(const QString &path, ImageParameters *params) override
QScopedPointer< QuickSharedImageLoader > loader
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options) override
Combined button and popup list for selecting options.
Definition image.cpp:4
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1504
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
void ** params
GLint void * img
Definition qopenglext.h:233
GLsizei const GLchar *const * path
#define QStringLiteral(str)
QFileInfo fi("c:/temp/foo")
[newstuff]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
ProviderOptions
Definition uiatypes_p.h:36