Coverage Report

Created: 2026-02-10 07:39

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