qplatformpixmap.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qplatformpixmap.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qplatformpixmap.h"-
41#include <qpa/qplatformintegration.h>-
42#include <QtCore/qbuffer.h>-
43#include <QtGui/qbitmap.h>-
44#include <QtGui/qimagereader.h>-
45#include <private/qguiapplication_p.h>-
46#include <private/qimagepixmapcleanuphooks_p.h>-
47-
48QT_BEGIN_NAMESPACE-
49-
50/*!-
51 \class QPlatformPixmap-
52 \since 5.0-
53 \internal-
54 \preliminary-
55 \ingroup qpa-
56-
57 \brief The QPlatformPixmap class provides an abstraction for native pixmaps.-
58 */-
59QPlatformPixmap *QPlatformPixmap::create(int w, int h, PixelType type)-
60{-
61 QPlatformPixmap *data = QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(static_cast<QPlatformPixmap::PixelType>(type));-
62 data->resize(w, h);-
63 return data;
never executed: return data;
0
64}-
65-
66-
67QPlatformPixmap::QPlatformPixmap(PixelType pixelType, int objectId)-
68 : w(0),-
69 h(0),-
70 d(0),-
71 is_null(true),-
72 ref(0),-
73 detach_no(0),-
74 type(pixelType),-
75 id(objectId),-
76 ser_no(0),-
77 is_cached(false)-
78{-
79}
never executed: end of block
0
80-
81QPlatformPixmap::~QPlatformPixmap()-
82{-
83 // Sometimes the pixmap cleanup hooks will be called from derrived classes, which will-
84 // then set is_cached to false. For example, on X11 Qt GUI needs to delete the GLXPixmap-
85 // or EGL Pixmap Surface for a given pixmap _before_ the native X11 pixmap is deleted,-
86 // otherwise some drivers will leak the GL surface. In this case, QX11PlatformPixmap will-
87 // call the cleanup hooks itself before deleting the native pixmap and set is_cached to-
88 // false.-
89 if (is_cached) {
is_cachedDescription
TRUEnever evaluated
FALSEnever evaluated
0
90 QImagePixmapCleanupHooks::executePlatformPixmapDestructionHooks(this);-
91 is_cached = false;-
92 }
never executed: end of block
0
93}
never executed: end of block
0
94-
95QPlatformPixmap *QPlatformPixmap::createCompatiblePlatformPixmap() const-
96{-
97 QPlatformPixmap *d = QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(pixelType());-
98 return d;
never executed: return d;
0
99}-
100-
101static QImage makeBitmapCompliantIfNeeded(QPlatformPixmap *d, const QImage &image, Qt::ImageConversionFlags flags)-
102{-
103 if (d->pixelType() == QPlatformPixmap::BitmapType) {
d->pixelType()...ap::BitmapTypeDescription
TRUEnever evaluated
FALSEnever evaluated
0
104 QImage img = image.convertToFormat(QImage::Format_MonoLSB, flags);-
105-
106 // make sure image.color(0) == Qt::color0 (white)-
107 // and image.color(1) == Qt::color1 (black)-
108 const QRgb c0 = QColor(Qt::black).rgb();-
109 const QRgb c1 = QColor(Qt::white).rgb();-
110 if (img.color(0) == c0 && img.color(1) == c1) {
img.color(0) == c0Description
TRUEnever evaluated
FALSEnever evaluated
img.color(1) == c1Description
TRUEnever evaluated
FALSEnever evaluated
0
111 img.invertPixels();-
112 img.setColor(0, c1);-
113 img.setColor(1, c0);-
114 }
never executed: end of block
0
115 return img;
never executed: return img;
0
116 }-
117-
118 return image;
never executed: return image;
0
119}-
120-
121void QPlatformPixmap::fromImageReader(QImageReader *imageReader,-
122 Qt::ImageConversionFlags flags)-
123{-
124 const QImage image = imageReader->read();-
125 fromImage(image, flags);-
126}
never executed: end of block
0
127-
128bool QPlatformPixmap::fromFile(const QString &fileName, const char *format,-
129 Qt::ImageConversionFlags flags)-
130{-
131 QImage image = QImageReader(fileName, format).read();-
132 if (image.isNull())
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
133 return false;
never executed: return false;
0
134 fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags);-
135 return !isNull();
never executed: return !isNull();
0
136}-
137-
138bool QPlatformPixmap::fromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags)-
139{-
140 QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len);-
141 QBuffer b(&a);-
142 b.open(QIODevice::ReadOnly);-
143 QImage image = QImageReader(&b, format).read();-
144 if (image.isNull())
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
145 return false;
never executed: return false;
0
146 fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags);-
147 return !isNull();
never executed: return !isNull();
0
148}-
149-
150void QPlatformPixmap::copy(const QPlatformPixmap *data, const QRect &rect)-
151{-
152 fromImage(data->toImage(rect), Qt::NoOpaqueDetection);-
153}
never executed: end of block
0
154-
155bool QPlatformPixmap::scroll(int dx, int dy, const QRect &rect)-
156{-
157 Q_UNUSED(dx);-
158 Q_UNUSED(dy);-
159 Q_UNUSED(rect);-
160 return false;
never executed: return false;
0
161}-
162-
163QPixmap QPlatformPixmap::transformed(const QTransform &matrix,-
164 Qt::TransformationMode mode) const-
165{-
166 return QPixmap::fromImage(toImage().transformed(matrix, mode));
never executed: return QPixmap::fromImage(toImage().transformed(matrix, mode));
0
167}-
168-
169void QPlatformPixmap::setSerialNumber(int serNo)-
170{-
171 ser_no = serNo;-
172}
never executed: end of block
0
173-
174void QPlatformPixmap::setDetachNumber(int detNo)-
175{-
176 detach_no = detNo;-
177}
never executed: end of block
0
178-
179QImage QPlatformPixmap::toImage(const QRect &rect) const-
180{-
181 if (rect.contains(QRect(0, 0, w, h)))
rect.contains(...t(0, 0, w, h))Description
TRUEnever evaluated
FALSEnever evaluated
0
182 return toImage();
never executed: return toImage();
0
183 else-
184 return toImage().copy(rect);
never executed: return toImage().copy(rect);
0
185}-
186-
187QImage* QPlatformPixmap::buffer()-
188{-
189 return 0;
never executed: return 0;
0
190}-
191-
192-
193QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9