Coverage Report

Created: 2026-05-16 07:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/prefix/include/QtGui/qpixmap.h
Line
Count
Source
1
// Copyright (C) 2016 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
// Qt-Security score:significant reason:default
4
5
#ifndef QPIXMAP_H
6
#define QPIXMAP_H
7
8
#include <QtGui/qtguiglobal.h>
9
#include <QtGui/qpaintdevice.h>
10
#include <QtGui/qcolor.h>
11
#include <QtCore/qnamespace.h>
12
#include <QtCore/qshareddata.h>
13
#include <QtCore/qstring.h> // char*->QString conversion
14
#include <QtGui/qimage.h>
15
#include <QtGui/qtransform.h>
16
17
QT_BEGIN_NAMESPACE
18
19
20
class QImageWriter;
21
class QImageReader;
22
class QColor;
23
class QVariant;
24
class QPlatformPixmap;
25
QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QPlatformPixmap, Q_GUI_EXPORT)
26
27
class Q_GUI_EXPORT QPixmap : public QPaintDevice
28
{
29
public:
30
    QPixmap();
31
    explicit QPixmap(QPlatformPixmap *data);
32
    QPixmap(int w, int h);
33
    explicit QPixmap(const QSize &);
34
    QPixmap(const QString& fileName, const char *format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
35
#ifndef QT_NO_IMAGEFORMAT_XPM
36
    explicit QPixmap(const char * const xpm[]);
37
#endif
38
    QPixmap(const QPixmap &);
39
0
    QPixmap(QPixmap &&other) noexcept : QPaintDevice(), data(std::move(other.data)) {}
40
    ~QPixmap();
41
42
    QPixmap &operator=(const QPixmap &);
43
    QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QPixmap)
44
    inline void swap(QPixmap &other) noexcept
45
0
    { data.swap(other.data); }
46
    bool operator==(const QPixmap &) const = delete;
47
    bool operator!=(const QPixmap &) const = delete;
48
49
    operator QVariant() const;
50
51
    bool isNull() const;
52
    int devType() const override;
53
54
    int width() const;
55
    int height() const;
56
    QSize size() const;
57
    QRect rect() const;
58
    int depth() const;
59
60
    static int defaultDepth();
61
62
    void fill(const QColor &fillColor = Qt::white);
63
64
    QBitmap mask() const;
65
    void setMask(const QBitmap &);
66
67
    qreal devicePixelRatio() const;
68
    void setDevicePixelRatio(qreal scaleFactor);
69
    QSizeF deviceIndependentSize() const;
70
71
    bool hasAlpha() const;
72
    bool hasAlphaChannel() const;
73
74
#ifndef QT_NO_IMAGE_HEURISTIC_MASK
75
    QBitmap createHeuristicMask(bool clipTight = true) const;
76
#endif
77
    QBitmap createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode = Qt::MaskInColor) const;
78
79
    inline QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
80
                          Qt::TransformationMode mode = Qt::FastTransformation) const
81
0
        { return scaled(QSize(w, h), aspectMode, mode); }
82
    QPixmap scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
83
                   Qt::TransformationMode mode = Qt::FastTransformation) const;
84
    QPixmap scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
85
    QPixmap scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const;
86
    QPixmap transformed(const QTransform &, Qt::TransformationMode mode = Qt::FastTransformation) const;
87
    static QTransform trueMatrix(const QTransform &m, int w, int h);
88
89
    QImage toImage() const;
90
    static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
91
    static QPixmap fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags = Qt::AutoColor);
92
    static QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags = Qt::AutoColor)
93
0
    {
94
0
        return fromImageInPlace(image, flags);
95
0
    }
96
97
    bool load(const QString& fileName, const char *format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
98
    bool loadFromData(const uchar *buf, uint len, const char* format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
99
    inline bool loadFromData(const QByteArray &data, const char* format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
100
    bool save(const QString& fileName, const char* format = nullptr, int quality = -1) const;
101
    bool save(QIODevice* device, const char* format = nullptr, int quality = -1) const;
102
103
    bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor);
104
105
    inline QPixmap copy(int x, int y, int width, int height) const;
106
    QPixmap copy(const QRect &rect = QRect()) const;
107
108
    inline void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed = nullptr);
109
    void scroll(int dx, int dy, const QRect &rect, QRegion *exposed = nullptr);
110
111
    qint64 cacheKey() const;
112
113
    bool isDetached() const;
114
    void detach();
115
116
    bool isQBitmap() const;
117
118
    QPaintEngine *paintEngine() const override;
119
120
0
    inline bool operator!() const { return isNull(); }
121
122
protected:
123
    int metric(PaintDeviceMetric) const override;
124
    static QPixmap fromImageInPlace(QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
125
126
private:
127
    QExplicitlySharedDataPointer<QPlatformPixmap> data;
128
129
    bool doImageIO(QImageWriter *io, int quality) const;
130
131
    QPixmap(const QSize &s, int type);
132
    void doInit(int, int, int);
133
    friend class QPlatformPixmap;
134
    friend class QBitmap;
135
    friend class QPaintDevice;
136
    friend class QPainter;
137
    friend class QOpenGLWidget;
138
    friend class QWidgetPrivate;
139
    friend class QRasterBuffer;
140
#if !defined(QT_NO_DATASTREAM)
141
    friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
142
#endif
143
144
public:
145
    QPlatformPixmap* handle() const;
146
147
public:
148
    typedef QExplicitlySharedDataPointer<QPlatformPixmap> DataPtr;
149
0
    inline DataPtr &data_ptr() { return data; }
150
};
151
152
Q_DECLARE_SHARED(QPixmap)
153
154
inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const
155
0
{
156
0
    return copy(QRect(ax, ay, awidth, aheight));
157
0
}
158
159
inline void QPixmap::scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion *exposed)
160
0
{
161
0
    scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed);
162
0
}
163
164
inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format,
165
                                  Qt::ImageConversionFlags flags)
166
0
{
167
0
    return loadFromData(reinterpret_cast<const uchar *>(buf.constData()), uint(buf.size()), format, flags);
168
0
}
169
170
171
/*****************************************************************************
172
 QPixmap stream functions
173
*****************************************************************************/
174
175
#if !defined(QT_NO_DATASTREAM)
176
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &);
177
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
178
#endif
179
180
#ifndef QT_NO_DEBUG_STREAM
181
Q_GUI_EXPORT QDebug operator<<(QDebug, const QPixmap &);
182
#endif
183
184
QT_END_NAMESPACE
185
186
#endif // QPIXMAP_H