image/qpixmap.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include <qglobal.h> -
43 -
44#include "qpixmap.h" -
45#include <qpa/qplatformpixmap.h> -
46#include "qimagepixmapcleanuphooks_p.h" -
47 -
48#include "qbitmap.h" -
49#include "qimage.h" -
50#include "qpainter.h" -
51#include "qdatastream.h" -
52#include "qbuffer.h" -
53#include <private/qguiapplication_p.h> -
54#include "qevent.h" -
55#include "qfile.h" -
56#include "qfileinfo.h" -
57#include "qpixmapcache.h" -
58#include "qdatetime.h" -
59#include "qimagereader.h" -
60#include "qimagewriter.h" -
61#include "qpaintengine.h" -
62#include "qscreen.h" -
63#include "qthread.h" -
64#include "qdebug.h" -
65 -
66#include <qpa/qplatformintegration.h> -
67 -
68#include "qpixmap_raster_p.h" -
69#include "private/qhexstring_p.h" -
70 -
71QT_BEGIN_NAMESPACE -
72 -
73static bool qt_pixmap_thread_test() -
74{ -
75 if (!QCoreApplication::instance()) {
partially evaluated: !QCoreApplication::instance()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:107063
0-107063
76 qFatal("QPixmap: Must construct a QApplication before a QPaintDevice");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 76, __PRETTY_FUNCTION__).fatal("QPixmap: Must construct a QApplication before a QPaintDevice");
-
77 return false;
never executed: return false;
0
78 } -
79 -
80 if (qApp->thread() != QThread::currentThread()) {
partially evaluated: (static_cast<QGuiApplication *>(QCoreApplication::instance()))->thread() != QThread::currentThread()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:107063
0-107063
81 bool fail = false;
never executed (the execution status of this line is deduced): bool fail = false;
-
82 if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)) {
never evaluated: !QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ThreadedPixmaps)
0
83 printf("Lighthouse plugin does not support threaded pixmaps!\n");
never executed (the execution status of this line is deduced): printf("Lighthouse plugin does not support threaded pixmaps!\n");
-
84 fail = true;
never executed (the execution status of this line is deduced): fail = true;
-
85 }
never executed: }
0
86 if (fail) {
never evaluated: fail
0
87 qWarning("QPixmap: It is not safe to use pixmaps outside the GUI thread");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 87, __PRETTY_FUNCTION__).warning("QPixmap: It is not safe to use pixmaps outside the GUI thread");
-
88 return false;
never executed: return false;
0
89 } -
90 }
never executed: }
0
91 return true;
executed: return true;
Execution Count:107063
107063
92} -
93 -
94void QPixmap::doInit(int w, int h, int type) -
95{ -
96 if ((w > 0 && h > 0) || type == QPlatformPixmap::BitmapType)
evaluated: w > 0
TRUEFALSE
yes
Evaluation Count:648
yes
Evaluation Count:81535
evaluated: h > 0
TRUEFALSE
yes
Evaluation Count:647
yes
Evaluation Count:1
evaluated: type == QPlatformPixmap::BitmapType
TRUEFALSE
yes
Evaluation Count:113
yes
Evaluation Count:81423
1-81535
97 data = QPlatformPixmap::create(w, h, (QPlatformPixmap::PixelType) type);
executed: data = QPlatformPixmap::create(w, h, (QPlatformPixmap::PixelType) type);
Execution Count:760
760
98 else -
99 data = 0;
executed: data = 0;
Execution Count:81423
81423
100} -
101 -
102/*! -
103 Constructs a null pixmap. -
104 -
105 \sa isNull() -
106*/ -
107 -
108QPixmap::QPixmap() -
109 : QPaintDevice() -
110{ -
111 (void) qt_pixmap_thread_test();
executed (the execution status of this line is deduced): (void) qt_pixmap_thread_test();
-
112 doInit(0, 0, QPlatformPixmap::PixmapType);
executed (the execution status of this line is deduced): doInit(0, 0, QPlatformPixmap::PixmapType);
-
113}
executed: }
Execution Count:77987
77987
114 -
115/*! -
116 \fn QPixmap::QPixmap(int width, int height) -
117 -
118 Constructs a pixmap with the given \a width and \a height. If -
119 either \a width or \a height is zero, a null pixmap is -
120 constructed. -
121 -
122 \warning This will create a QPixmap with uninitialized data. Call -
123 fill() to fill the pixmap with an appropriate color before drawing -
124 onto it with QPainter. -
125 -
126 \sa isNull() -
127*/ -
128 -
129QPixmap::QPixmap(int w, int h) -
130 : QPaintDevice() -
131{ -
132 if (!qt_pixmap_thread_test())
partially evaluated: !qt_pixmap_thread_test()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:345
0-345
133 doInit(0, 0, QPlatformPixmap::PixmapType);
never executed: doInit(0, 0, QPlatformPixmap::PixmapType);
0
134 else -
135 doInit(w, h, QPlatformPixmap::PixmapType);
executed: doInit(w, h, QPlatformPixmap::PixmapType);
Execution Count:345
345
136} -
137 -
138/*! -
139 \overload -
140 -
141 Constructs a pixmap of the given \a size. -
142 -
143 \warning This will create a QPixmap with uninitialized data. Call -
144 fill() to fill the pixmap with an appropriate color before drawing -
145 onto it with QPainter. -
146*/ -
147 -
148QPixmap::QPixmap(const QSize &size) -
149 : QPaintDevice() -
150{ -
151 if (!qt_pixmap_thread_test())
partially evaluated: !qt_pixmap_thread_test()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:290
0-290
152 doInit(0, 0, QPlatformPixmap::PixmapType);
never executed: doInit(0, 0, QPlatformPixmap::PixmapType);
0
153 else -
154 doInit(size.width(), size.height(), QPlatformPixmap::PixmapType);
executed: doInit(size.width(), size.height(), QPlatformPixmap::PixmapType);
Execution Count:290
290
155} -
156 -
157/*! -
158 \internal -
159*/ -
160QPixmap::QPixmap(const QSize &s, int type) -
161{ -
162 if (!qt_pixmap_thread_test())
partially evaluated: !qt_pixmap_thread_test()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:130
0-130
163 doInit(0, 0, static_cast<QPlatformPixmap::PixelType>(type));
never executed: doInit(0, 0, static_cast<QPlatformPixmap::PixelType>(type));
0
164 else -
165 doInit(s.width(), s.height(), static_cast<QPlatformPixmap::PixelType>(type));
executed: doInit(s.width(), s.height(), static_cast<QPlatformPixmap::PixelType>(type));
Execution Count:130
130
166} -
167 -
168/*! -
169 \internal -
170*/ -
171QPixmap::QPixmap(QPlatformPixmap *d) -
172 : QPaintDevice(), data(d) -
173{ -
174}
executed: }
Execution Count:4042
4042
175 -
176/*! -
177 Constructs a pixmap from the file with the given \a fileName. If the -
178 file does not exist or is of an unknown format, the pixmap becomes a -
179 null pixmap. -
180 -
181 The loader attempts to read the pixmap using the specified \a -
182 format. If the \a format is not specified (which is the default), -
183 the loader probes the file for a header to guess the file format. -
184 -
185 The file name can either refer to an actual file on disk or to -
186 one of the application's embedded resources. See the -
187 \l{resources.html}{Resource System} overview for details on how -
188 to embed images and other resource files in the application's -
189 executable. -
190 -
191 If the image needs to be modified to fit in a lower-resolution -
192 result (e.g. converting from 32-bit to 8-bit), use the \a -
193 flags to control the conversion. -
194 -
195 The \a fileName, \a format and \a flags parameters are -
196 passed on to load(). This means that the data in \a fileName is -
197 not compiled into the binary. If \a fileName contains a relative -
198 path (e.g. the filename only) the relevant file must be found -
199 relative to the runtime working directory. -
200 -
201 \sa {QPixmap#Reading and Writing Image Files}{Reading and Writing -
202 Image Files} -
203*/ -
204 -
205QPixmap::QPixmap(const QString& fileName, const char *format, Qt::ImageConversionFlags flags) -
206 : QPaintDevice() -
207{ -
208 doInit(0, 0, QPlatformPixmap::PixmapType);
executed (the execution status of this line is deduced): doInit(0, 0, QPlatformPixmap::PixmapType);
-
209 if (!qt_pixmap_thread_test())
partially evaluated: !qt_pixmap_thread_test()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1229
0-1229
210 return;
never executed: return;
0
211 -
212 load(fileName, format, flags);
executed (the execution status of this line is deduced): load(fileName, format, flags);
-
213}
executed: }
Execution Count:1229
1229
214 -
215/*! -
216 Constructs a pixmap that is a copy of the given \a pixmap. -
217 -
218 \sa copy() -
219*/ -
220 -
221QPixmap::QPixmap(const QPixmap &pixmap) -
222 : QPaintDevice() -
223{ -
224 if (!qt_pixmap_thread_test()) {
partially evaluated: !qt_pixmap_thread_test()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:27082
0-27082
225 doInit(0, 0, QPlatformPixmap::PixmapType);
never executed (the execution status of this line is deduced): doInit(0, 0, QPlatformPixmap::PixmapType);
-
226 return;
never executed: return;
0
227 } -
228 if (pixmap.paintingActive()) { // make a deep copy
partially evaluated: pixmap.paintingActive()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:27082
0-27082
229 pixmap.copy().swap(*this);
never executed (the execution status of this line is deduced): pixmap.copy().swap(*this);
-
230 } else {
never executed: }
0
231 data = pixmap.data;
executed (the execution status of this line is deduced): data = pixmap.data;
-
232 }
executed: }
Execution Count:27082
27082
233} -
234 -
235/*! -
236 Constructs a pixmap from the given \a xpm data, which must be a -
237 valid XPM image. -
238 -
239 Errors are silently ignored. -
240 -
241 Note that it's possible to squeeze the XPM variable a little bit -
242 by using an unusual declaration: -
243 -
244 \snippet code/src_gui_image_qpixmap.cpp 0 -
245 -
246 The extra \c const makes the entire definition read-only, which is -
247 slightly more efficient (for example, when the code is in a shared -
248 library) and ROMable when the application is to be stored in ROM. -
249*/ -
250#ifndef QT_NO_IMAGEFORMAT_XPM -
251QPixmap::QPixmap(const char * const xpm[]) -
252 : QPaintDevice() -
253{ -
254 doInit(0, 0, QPlatformPixmap::PixmapType);
executed (the execution status of this line is deduced): doInit(0, 0, QPlatformPixmap::PixmapType);
-
255 if (!xpm)
partially evaluated: !xpm
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2202
0-2202
256 return;
never executed: return;
0
257 -
258 QImage image(xpm);
executed (the execution status of this line is deduced): QImage image(xpm);
-
259 if (!image.isNull()) {
partially evaluated: !image.isNull()
TRUEFALSE
yes
Evaluation Count:2202
no
Evaluation Count:0
0-2202
260 if (data && data->pixelType() == QPlatformPixmap::BitmapType)
partially evaluated: data
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2202
never evaluated: data->pixelType() == QPlatformPixmap::BitmapType
0-2202
261 *this = QBitmap::fromImage(image);
never executed: *this = QBitmap::fromImage(image);
0
262 else -
263 *this = fromImage(image);
executed: *this = fromImage(image);
Execution Count:2202
2202
264 } -
265}
executed: }
Execution Count:2202
2202
266#endif -
267 -
268 -
269/*! -
270 Destroys the pixmap. -
271*/ -
272 -
273QPixmap::~QPixmap() -
274{ -
275 Q_ASSERT(!data || data->ref.load() >= 1); // Catch if ref-counting changes again
executed (the execution status of this line is deduced): qt_noop();
-
276}
executed: }
Execution Count:112604
112604
277 -
278/*! -
279 \internal -
280*/ -
281int QPixmap::devType() const -
282{ -
283 return QInternal::Pixmap;
executed: return QInternal::Pixmap;
Execution Count:3879
3879
284} -
285 -
286/*! -
287 \fn QPixmap QPixmap::copy(int x, int y, int width, int height) const -
288 \overload -
289 -
290 Returns a deep copy of the subset of the pixmap that is specified -
291 by the rectangle QRect( \a x, \a y, \a width, \a height). -
292*/ -
293 -
294/*! -
295 \fn QPixmap QPixmap::copy(const QRect &rectangle) const -
296 -
297 Returns a deep copy of the subset of the pixmap that is specified -
298 by the given \a rectangle. For more information on deep copies, -
299 see the \l {Implicit Data Sharing} documentation. -
300 -
301 If the given \a rectangle is empty, the whole image is copied. -
302 -
303 \sa operator=(), QPixmap(), {QPixmap#Pixmap -
304 Transformations}{Pixmap Transformations} -
305*/ -
306QPixmap QPixmap::copy(const QRect &rect) const -
307{ -
308 if (isNull())
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:9
1-9
309 return QPixmap();
executed: return QPixmap();
Execution Count:1
1
310 -
311 QRect r(0, 0, width(), height());
executed (the execution status of this line is deduced): QRect r(0, 0, width(), height());
-
312 if (!rect.isEmpty())
evaluated: !rect.isEmpty()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:6
3-6
313 r = r.intersected(rect);
executed: r = r.intersected(rect);
Execution Count:3
3
314 -
315 QPlatformPixmap *d = data->createCompatiblePlatformPixmap();
executed (the execution status of this line is deduced): QPlatformPixmap *d = data->createCompatiblePlatformPixmap();
-
316 d->copy(data.data(), r);
executed (the execution status of this line is deduced): d->copy(data.data(), r);
-
317 return QPixmap(d);
executed: return QPixmap(d);
Execution Count:9
9
318} -
319 -
320/*! -
321 \fn QPixmap::scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed) -
322 \since 4.6 -
323 -
324 This convenience function is equivalent to calling QPixmap::scroll(\a dx, -
325 \a dy, QRect(\a x, \a y, \a width, \a height), \a exposed). -
326 -
327 \sa QWidget::scroll(), QGraphicsItem::scroll() -
328*/ -
329 -
330/*! -
331 \since 4.6 -
332 -
333 Scrolls the area \a rect of this pixmap by (\a dx, \a dy). The exposed -
334 region is left unchanged. You can optionally pass a pointer to an empty -
335 QRegion to get the region that is \a exposed by the scroll operation. -
336 -
337 \snippet code/src_gui_image_qpixmap.cpp 2 -
338 -
339 You cannot scroll while there is an active painter on the pixmap. -
340 -
341 \sa QWidget::scroll(), QGraphicsItem::scroll() -
342*/ -
343void QPixmap::scroll(int dx, int dy, const QRect &rect, QRegion *exposed) -
344{ -
345 if (isNull() || (dx == 0 && dy == 0))
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:24
evaluated: dx == 0
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:14
evaluated: dy == 0
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:7
1-24
346 return;
executed: return;
Execution Count:4
4
347 QRect dest = rect & this->rect();
executed (the execution status of this line is deduced): QRect dest = rect & this->rect();
-
348 QRect src = dest.translated(-dx, -dy) & dest;
executed (the execution status of this line is deduced): QRect src = dest.translated(-dx, -dy) & dest;
-
349 if (src.isEmpty()) {
evaluated: src.isEmpty()
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:12
9-12
350 if (exposed)
partially evaluated: exposed
TRUEFALSE
yes
Evaluation Count:9
no
Evaluation Count:0
0-9
351 *exposed += dest;
executed: *exposed += dest;
Execution Count:9
9
352 return;
executed: return;
Execution Count:9
9
353 } -
354 -
355 detach();
executed (the execution status of this line is deduced): detach();
-
356 -
357 if (!data->scroll(dx, dy, src)) {
partially evaluated: !data->scroll(dx, dy, src)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
358 // Fallback -
359 QPixmap pix = *this;
never executed (the execution status of this line is deduced): QPixmap pix = *this;
-
360 QPainter painter(&pix);
never executed (the execution status of this line is deduced): QPainter painter(&pix);
-
361 painter.setCompositionMode(QPainter::CompositionMode_Source);
never executed (the execution status of this line is deduced): painter.setCompositionMode(QPainter::CompositionMode_Source);
-
362 painter.drawPixmap(src.translated(dx, dy), *this, src);
never executed (the execution status of this line is deduced): painter.drawPixmap(src.translated(dx, dy), *this, src);
-
363 painter.end();
never executed (the execution status of this line is deduced): painter.end();
-
364 *this = pix;
never executed (the execution status of this line is deduced): *this = pix;
-
365 }
never executed: }
0
366 -
367 if (exposed) {
partially evaluated: exposed
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
0-12
368 *exposed += dest;
executed (the execution status of this line is deduced): *exposed += dest;
-
369 *exposed -= src.translated(dx, dy);
executed (the execution status of this line is deduced): *exposed -= src.translated(dx, dy);
-
370 }
executed: }
Execution Count:12
12
371}
executed: }
Execution Count:12
12
372 -
373/*! -
374 Assigns the given \a pixmap to this pixmap and returns a reference -
375 to this pixmap. -
376 -
377 \sa copy(), QPixmap() -
378*/ -
379 -
380QPixmap &QPixmap::operator=(const QPixmap &pixmap) -
381{ -
382 if (paintingActive()) {
partially evaluated: paintingActive()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13605
0-13605
383 qWarning("QPixmap::operator=: Cannot assign to pixmap during painting");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 383, __PRETTY_FUNCTION__).warning("QPixmap::operator=: Cannot assign to pixmap during painting");
-
384 return *this;
never executed: return *this;
0
385 } -
386 if (pixmap.paintingActive()) { // make a deep copy
partially evaluated: pixmap.paintingActive()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13605
0-13605
387 pixmap.copy().swap(*this);
never executed (the execution status of this line is deduced): pixmap.copy().swap(*this);
-
388 } else {
never executed: }
0
389 data = pixmap.data;
executed (the execution status of this line is deduced): data = pixmap.data;
-
390 }
executed: }
Execution Count:13605
13605
391 return *this;
executed: return *this;
Execution Count:13605
13605
392} -
393 -
394/*! -
395 \fn void QPixmap::swap(QPixmap &other) -
396 \since 4.8 -
397 -
398 Swaps pixmap \a other with this pixmap. This operation is very -
399 fast and never fails. -
400*/ -
401 -
402/*! -
403 Returns the pixmap as a QVariant. -
404*/ -
405QPixmap::operator QVariant() const -
406{ -
407 return QVariant(QVariant::Pixmap, this);
executed: return QVariant(QVariant::Pixmap, this);
Execution Count:14
14
408} -
409 -
410/*! -
411 \fn bool QPixmap::operator!() const -
412 -
413 Returns true if this is a null pixmap; otherwise returns false. -
414 -
415 \sa isNull() -
416*/ -
417 -
418/*! -
419 Converts the pixmap to a QImage. Returns a null image if the -
420 conversion fails. -
421 -
422 If the pixmap has 1-bit depth, the returned image will also be 1 -
423 bit deep. Images with more bits will be returned in a format -
424 closely represents the underlying system. Usually this will be -
425 QImage::Format_ARGB32_Premultiplied for pixmaps with an alpha and -
426 QImage::Format_RGB32 or QImage::Format_RGB16 for pixmaps without -
427 alpha. -
428 -
429 Note that for the moment, alpha masks on monochrome images are -
430 ignored. -
431 -
432 \sa fromImage(), {QImage#Image Formats}{Image Formats} -
433*/ -
434QImage QPixmap::toImage() const -
435{ -
436 if (isNull())
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:1850
12-1850
437 return QImage();
executed: return QImage();
Execution Count:12
12
438 -
439 return data->toImage();
executed: return data->toImage();
Execution Count:1850
1850
440} -
441 -
442/*! -
443 \fn QMatrix QPixmap::trueMatrix(const QTransform &matrix, int width, int height) -
444 -
445 Returns the actual matrix used for transforming a pixmap with the -
446 given \a width, \a height and \a matrix. -
447 -
448 When transforming a pixmap using the transformed() function, the -
449 transformation matrix is internally adjusted to compensate for -
450 unwanted translation, i.e. transformed() returns the smallest -
451 pixmap containing all transformed points of the original -
452 pixmap. This function returns the modified matrix, which maps -
453 points correctly from the original pixmap into the new pixmap. -
454 -
455 \sa transformed(), {QPixmap#Pixmap Transformations}{Pixmap -
456 Transformations} -
457*/ -
458QTransform QPixmap::trueMatrix(const QTransform &m, int w, int h) -
459{ -
460 return QImage::trueMatrix(m, w, h);
never executed: return QImage::trueMatrix(m, w, h);
0
461} -
462 -
463/*! -
464 \overload -
465 -
466 This convenience function loads the matrix \a m into a -
467 QTransform and calls the overloaded function with the -
468 QTransform and the width \a w and the height \a h. -
469 */ -
470QMatrix QPixmap::trueMatrix(const QMatrix &m, int w, int h) -
471{ -
472 return trueMatrix(QTransform(m), w, h).toAffine();
never executed: return trueMatrix(QTransform(m), w, h).toAffine();
0
473} -
474 -
475 -
476/*! -
477 \fn bool QPixmap::isQBitmap() const -
478 -
479 Returns true if this is a QBitmap; otherwise returns false. -
480*/ -
481 -
482bool QPixmap::isQBitmap() const -
483{ -
484 return data->type == QPlatformPixmap::BitmapType;
executed: return data->type == QPlatformPixmap::BitmapType;
Execution Count:7
7
485} -
486 -
487/*! -
488 \fn bool QPixmap::isNull() const -
489 -
490 Returns true if this is a null pixmap; otherwise returns false. -
491 -
492 A null pixmap has zero width, zero height and no contents. You -
493 cannot draw in a null pixmap. -
494*/ -
495bool QPixmap::isNull() const -
496{ -
497 return !data || data->isNull();
executed: return !data || data->isNull();
Execution Count:57918
57918
498} -
499 -
500/*! -
501 \fn int QPixmap::width() const -
502 -
503 Returns the width of the pixmap. -
504 -
505 \sa size(), {QPixmap#Pixmap Information}{Pixmap Information} -
506*/ -
507int QPixmap::width() const -
508{ -
509 return data ? data->width() : 0;
executed: return data ? data->width() : 0;
Execution Count:7438
7438
510} -
511 -
512/*! -
513 \fn int QPixmap::height() const -
514 -
515 Returns the height of the pixmap. -
516 -
517 \sa size(), {QPixmap#Pixmap Information}{Pixmap Information} -
518*/ -
519int QPixmap::height() const -
520{ -
521 return data ? data->height() : 0;
executed: return data ? data->height() : 0;
Execution Count:7542
7542
522} -
523 -
524/*! -
525 \fn QSize QPixmap::size() const -
526 -
527 Returns the size of the pixmap. -
528 -
529 \sa width(), height(), {QPixmap#Pixmap Information}{Pixmap -
530 Information} -
531*/ -
532QSize QPixmap::size() const -
533{ -
534 return data ? QSize(data->width(), data->height()) : QSize(0, 0);
executed: return data ? QSize(data->width(), data->height()) : QSize(0, 0);
Execution Count:13246
13246
535} -
536 -
537/*! -
538 \fn QRect QPixmap::rect() const -
539 -
540 Returns the pixmap's enclosing rectangle. -
541 -
542 \sa {QPixmap#Pixmap Information}{Pixmap Information} -
543*/ -
544QRect QPixmap::rect() const -
545{ -
546 return data ? QRect(0, 0, data->width(), data->height()) : QRect();
executed: return data ? QRect(0, 0, data->width(), data->height()) : QRect();
Execution Count:274
274
547} -
548 -
549/*! -
550 \fn int QPixmap::depth() const -
551 -
552 Returns the depth of the pixmap. -
553 -
554 The pixmap depth is also called bits per pixel (bpp) or bit planes -
555 of a pixmap. A null pixmap has depth 0. -
556 -
557 \sa defaultDepth(), {QPixmap#Pixmap Information}{Pixmap -
558 Information} -
559*/ -
560int QPixmap::depth() const -
561{ -
562 return data ? data->depth() : 0;
executed: return data ? data->depth() : 0;
Execution Count:2787
2787
563} -
564 -
565/*! -
566 Sets a mask bitmap. -
567 -
568 This function merges the \a mask with the pixmap's alpha channel. A pixel -
569 value of 1 on the mask means the pixmap's pixel is unchanged; a value of 0 -
570 means the pixel is transparent. The mask must have the same size as this -
571 pixmap. -
572 -
573 Setting a null mask resets the mask, leaving the previously transparent -
574 pixels black. The effect of this function is undefined when the pixmap is -
575 being painted on. -
576 -
577 \warning This is potentially an expensive operation. -
578 -
579 \sa mask(), {QPixmap#Pixmap Transformations}{Pixmap Transformations}, -
580 QBitmap -
581*/ -
582void QPixmap::setMask(const QBitmap &mask) -
583{ -
584 if (paintingActive()) {
partially evaluated: paintingActive()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:64
0-64
585 qWarning("QPixmap::setMask: Cannot set mask while pixmap is being painted on");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 585, __PRETTY_FUNCTION__).warning("QPixmap::setMask: Cannot set mask while pixmap is being painted on");
-
586 return;
never executed: return;
0
587 } -
588 -
589 if (!mask.isNull() && mask.size() != size()) {
evaluated: !mask.isNull()
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:59
partially evaluated: mask.size() != size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-59
590 qWarning("QPixmap::setMask() mask size differs from pixmap size");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 590, __PRETTY_FUNCTION__).warning("QPixmap::setMask() mask size differs from pixmap size");
-
591 return;
never executed: return;
0
592 } -
593 -
594 if (isNull())
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:62
2-62
595 return;
executed: return;
Execution Count:2
2
596 -
597 if (static_cast<const QPixmap &>(mask).data == data) // trying to selfmask
partially evaluated: static_cast<const QPixmap &>(mask).data == data
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:62
0-62
598 return;
never executed: return;
0
599 -
600 detach();
executed (the execution status of this line is deduced): detach();
-
601 -
602 QImage image = data->toImage();
executed (the execution status of this line is deduced): QImage image = data->toImage();
-
603 if (mask.size().isEmpty()) {
evaluated: mask.size().isEmpty()
TRUEFALSE
yes
Evaluation Count:57
yes
Evaluation Count:5
5-57
604 if (image.depth() != 1) { // hw: ????
evaluated: image.depth() != 1
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:54
3-54
605 image = image.convertToFormat(QImage::Format_RGB32);
executed (the execution status of this line is deduced): image = image.convertToFormat(QImage::Format_RGB32);
-
606 }
executed: }
Execution Count:3
3
607 } else {
executed: }
Execution Count:57
57
608 const int w = image.width();
executed (the execution status of this line is deduced): const int w = image.width();
-
609 const int h = image.height();
executed (the execution status of this line is deduced): const int h = image.height();
-
610 -
611 switch (image.depth()) { -
612 case 1: { -
613 const QImage imageMask = mask.toImage().convertToFormat(image.format());
executed (the execution status of this line is deduced): const QImage imageMask = mask.toImage().convertToFormat(image.format());
-
614 for (int y = 0; y < h; ++y) {
evaluated: y < h
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-3
615 const uchar *mscan = imageMask.scanLine(y);
executed (the execution status of this line is deduced): const uchar *mscan = imageMask.scanLine(y);
-
616 uchar *tscan = image.scanLine(y);
executed (the execution status of this line is deduced): uchar *tscan = image.scanLine(y);
-
617 int bytesPerLine = image.bytesPerLine();
executed (the execution status of this line is deduced): int bytesPerLine = image.bytesPerLine();
-
618 for (int i = 0; i < bytesPerLine; ++i)
evaluated: i < bytesPerLine
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:3
3-12
619 tscan[i] &= mscan[i];
executed: tscan[i] &= mscan[i];
Execution Count:12
12
620 }
executed: }
Execution Count:3
3
621 break;
executed: break;
Execution Count:1
1
622 } -
623 default: { -
624 const QImage imageMask = mask.toImage().convertToFormat(QImage::Format_MonoLSB);
executed (the execution status of this line is deduced): const QImage imageMask = mask.toImage().convertToFormat(QImage::Format_MonoLSB);
-
625 image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
executed (the execution status of this line is deduced): image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
-
626 for (int y = 0; y < h; ++y) {
evaluated: y < h
TRUEFALSE
yes
Evaluation Count:220
yes
Evaluation Count:4
4-220
627 const uchar *mscan = imageMask.scanLine(y);
executed (the execution status of this line is deduced): const uchar *mscan = imageMask.scanLine(y);
-
628 QRgb *tscan = (QRgb *)image.scanLine(y);
executed (the execution status of this line is deduced): QRgb *tscan = (QRgb *)image.scanLine(y);
-
629 for (int x = 0; x < w; ++x) {
evaluated: x < w
TRUEFALSE
yes
Evaluation Count:20200
yes
Evaluation Count:220
220-20200
630 if (!(mscan[x>>3] & (1 << (x&7))))
evaluated: !(mscan[x>>3] & (1 << (x&7)))
TRUEFALSE
yes
Evaluation Count:20175
yes
Evaluation Count:25
25-20175
631 tscan[x] = 0;
executed: tscan[x] = 0;
Execution Count:20175
20175
632 }
executed: }
Execution Count:20200
20200
633 }
executed: }
Execution Count:220
220
634 break;
executed: break;
Execution Count:4
4
635 } -
636 } -
637 }
executed: }
Execution Count:5
5
638 data->fromImage(image, Qt::AutoColor);
executed (the execution status of this line is deduced): data->fromImage(image, Qt::AutoColor);
-
639}
executed: }
Execution Count:62
62
640 -
641/*! -
642 Returns the device pixel ratio for the pixmap. This is the -
643 ratio between pixmap pixels and device-independent pixels. -
644 -
645 Use this function when calculating layout geometry based on -
646 the pixmap size: QSize layoutSize = image.size() / image.devicePixelRatio() -
647 -
648 The default value is 1.0. -
649 -
650 \sa setDevicePixelRatio() -
651*/ -
652qreal QPixmap::devicePixelRatio() const -
653{ -
654 if (!data)
evaluated: !data
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:4370
10-4370
655 return qreal(1.0);
executed: return qreal(1.0);
Execution Count:10
10
656 return data->devicePixelRatio();
executed: return data->devicePixelRatio();
Execution Count:4370
4370
657} -
658 -
659/*! -
660 Sets the the device pixel ratio for the pixmap. This is the -
661 ratio between image pixels and device-independent pixels. -
662 -
663 The default value is 1.0. Setting it to something else has -
664 two effects: -
665 -
666 QPainters that are opened on the pixmap will be scaled. For -
667 example, painting on a 200x200 image if with a ratio of 2.0 -
668 will result in effective (device-independent) painting bounds -
669 of 100x100. -
670 -
671 Code paths in Qt that calculate layout geometry based on the -
672 pixmap size will take the ratio into account: -
673 QSize layoutSize = pixmap.size() / pixmap.devicePixelRatio() -
674 The net effect of this is that the pixmap is displayed as -
675 high-dpi pixmap rather than a large pixmap. -
676 -
677 \sa devicePixelRatio() -
678*/ -
679void QPixmap::setDevicePixelRatio(qreal scaleFactor) -
680{ -
681 detach();
executed (the execution status of this line is deduced): detach();
-
682 data->setDevicePixelRatio(scaleFactor);
executed (the execution status of this line is deduced): data->setDevicePixelRatio(scaleFactor);
-
683}
executed: }
Execution Count:8
8
684 -
685#ifndef QT_NO_IMAGE_HEURISTIC_MASK -
686/*! -
687 Creates and returns a heuristic mask for this pixmap. -
688 -
689 The function works by selecting a color from one of the corners -
690 and then chipping away pixels of that color, starting at all the -
691 edges. If \a clipTight is true (the default) the mask is just -
692 large enough to cover the pixels; otherwise, the mask is larger -
693 than the data pixels. -
694 -
695 The mask may not be perfect but it should be reasonable, so you -
696 can do things such as the following: -
697 -
698 \snippet code/src_gui_image_qpixmap.cpp 1 -
699 -
700 This function is slow because it involves converting to/from a -
701 QImage, and non-trivial computations. -
702 -
703 \sa QImage::createHeuristicMask(), createMaskFromColor() -
704*/ -
705QBitmap QPixmap::createHeuristicMask(bool clipTight) const -
706{ -
707 QBitmap m = QBitmap::fromImage(toImage().createHeuristicMask(clipTight));
never executed (the execution status of this line is deduced): QBitmap m = QBitmap::fromImage(toImage().createHeuristicMask(clipTight));
-
708 return m;
never executed: return m;
0
709} -
710#endif -
711 -
712/*! -
713 Creates and returns a mask for this pixmap based on the given \a -
714 maskColor. If the \a mode is Qt::MaskInColor, all pixels matching the -
715 maskColor will be transparent. If \a mode is Qt::MaskOutColor, all pixels -
716 matching the maskColor will be opaque. -
717 -
718 This function is slow because it involves converting to/from a -
719 QImage. -
720 -
721 \sa createHeuristicMask(), QImage::createMaskFromColor() -
722*/ -
723QBitmap QPixmap::createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) const -
724{ -
725 QImage image = toImage().convertToFormat(QImage::Format_ARGB32);
executed (the execution status of this line is deduced): QImage image = toImage().convertToFormat(QImage::Format_ARGB32);
-
726 return QBitmap::fromImage(image.createMaskFromColor(maskColor.rgba(), mode));
executed: return QBitmap::fromImage(image.createMaskFromColor(maskColor.rgba(), mode));
Execution Count:2
2
727} -
728 -
729/*! -
730 Loads a pixmap from the file with the given \a fileName. Returns -
731 true if the pixmap was successfully loaded; otherwise invalidates -
732 the pixmap and returns false. -
733 -
734 The loader attempts to read the pixmap using the specified \a -
735 format. If the \a format is not specified (which is the default), -
736 the loader probes the file for a header to guess the file format. -
737 -
738 The file name can either refer to an actual file on disk or to one -
739 of the application's embedded resources. See the -
740 \l{resources.html}{Resource System} overview for details on how to -
741 embed pixmaps and other resource files in the application's -
742 executable. -
743 -
744 If the data needs to be modified to fit in a lower-resolution -
745 result (e.g. converting from 32-bit to 8-bit), use the \a flags to -
746 control the conversion. -
747 -
748 Note that QPixmaps are automatically added to the QPixmapCache -
749 when loaded from a file; the key used is internal and can not -
750 be acquired. -
751 -
752 \sa loadFromData(), {QPixmap#Reading and Writing Image -
753 Files}{Reading and Writing Image Files} -
754*/ -
755 -
756bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConversionFlags flags) -
757{ -
758 if (fileName.isEmpty()) {
evaluated: fileName.isEmpty()
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:1202
36-1202
759 data.reset();
executed (the execution status of this line is deduced): data.reset();
-
760 return false;
executed: return false;
Execution Count:36
36
761 } -
762 -
763 QFileInfo info(fileName);
executed (the execution status of this line is deduced): QFileInfo info(fileName);
-
764 QString key = QLatin1String("qt_pixmap")
executed (the execution status of this line is deduced): QString key = QLatin1String("qt_pixmap")
-
765 % info.absoluteFilePath()
executed (the execution status of this line is deduced): % info.absoluteFilePath()
-
766 % HexString<uint>(info.lastModified().toTime_t())
executed (the execution status of this line is deduced): % HexString<uint>(info.lastModified().toTime_t())
-
767 % HexString<quint64>(info.size())
executed (the execution status of this line is deduced): % HexString<quint64>(info.size())
-
768 % HexString<uint>(data ? data->pixelType() : QPlatformPixmap::PixmapType);
executed (the execution status of this line is deduced): % HexString<uint>(data ? data->pixelType() : QPlatformPixmap::PixmapType);
-
769 -
770 // Note: If no extension is provided, we try to match the -
771 // file against known plugin extensions -
772 if (!info.completeSuffix().isEmpty() && !info.exists()) {
evaluated: !info.completeSuffix().isEmpty()
TRUEFALSE
yes
Evaluation Count:1197
yes
Evaluation Count:5
evaluated: !info.exists()
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:1189
5-1197
773 data.reset();
executed (the execution status of this line is deduced): data.reset();
-
774 return false;
executed: return false;
Execution Count:8
8
775 } -
776 -
777 if (QPixmapCache::find(key, this))
evaluated: QPixmapCache::find(key, this)
TRUEFALSE
yes
Evaluation Count:1087
yes
Evaluation Count:107
107-1087
778 return true;
executed: return true;
Execution Count:1087
1087
779 -
780 if (!data)
evaluated: !data
TRUEFALSE
yes
Evaluation Count:106
yes
Evaluation Count:1
1-106
781 data = QPlatformPixmap::create(0, 0, QPlatformPixmap::PixmapType);
executed: data = QPlatformPixmap::create(0, 0, QPlatformPixmap::PixmapType);
Execution Count:106
106
782 -
783 if (data->fromFile(fileName, format, flags)) {
evaluated: data->fromFile(fileName, format, flags)
TRUEFALSE
yes
Evaluation Count:102
yes
Evaluation Count:5
5-102
784 QPixmapCache::insert(key, *this);
executed (the execution status of this line is deduced): QPixmapCache::insert(key, *this);
-
785 return true;
executed: return true;
Execution Count:102
102
786 } -
787 -
788 data.reset();
executed (the execution status of this line is deduced): data.reset();
-
789 return false;
executed: return false;
Execution Count:5
5
790} -
791 -
792/*! -
793 \fn bool QPixmap::loadFromData(const uchar *data, uint len, const char *format, Qt::ImageConversionFlags flags) -
794 -
795 Loads a pixmap from the \a len first bytes of the given binary \a -
796 data. Returns true if the pixmap was loaded successfully; -
797 otherwise invalidates the pixmap and returns false. -
798 -
799 The loader attempts to read the pixmap using the specified \a -
800 format. If the \a format is not specified (which is the default), -
801 the loader probes the file for a header to guess the file format. -
802 -
803 If the data needs to be modified to fit in a lower-resolution -
804 result (e.g. converting from 32-bit to 8-bit), use the \a flags to -
805 control the conversion. -
806 -
807 \sa load(), {QPixmap#Reading and Writing Image Files}{Reading and -
808 Writing Image Files} -
809*/ -
810 -
811bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags) -
812{ -
813 if (len == 0 || buf == 0) {
evaluated: len == 0
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:19
evaluated: buf == 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:18
1-19
814 data.reset();
executed (the execution status of this line is deduced): data.reset();
-
815 return false;
executed: return false;
Execution Count:4
4
816 } -
817 -
818 if (!data)
partially evaluated: !data
TRUEFALSE
yes
Evaluation Count:18
no
Evaluation Count:0
0-18
819 data = QPlatformPixmap::create(0, 0, QPlatformPixmap::PixmapType);
executed: data = QPlatformPixmap::create(0, 0, QPlatformPixmap::PixmapType);
Execution Count:18
18
820 -
821 if (data->fromData(buf, len, format, flags))
partially evaluated: data->fromData(buf, len, format, flags)
TRUEFALSE
yes
Evaluation Count:18
no
Evaluation Count:0
0-18
822 return true;
executed: return true;
Execution Count:18
18
823 -
824 data.reset();
never executed (the execution status of this line is deduced): data.reset();
-
825 return false;
never executed: return false;
0
826} -
827 -
828/*! -
829 \fn bool QPixmap::loadFromData(const QByteArray &data, const char *format, Qt::ImageConversionFlags flags) -
830 -
831 \overload -
832 -
833 Loads a pixmap from the binary \a data using the specified \a -
834 format and conversion \a flags. -
835*/ -
836 -
837 -
838/*! -
839 Saves the pixmap to the file with the given \a fileName using the -
840 specified image file \a format and \a quality factor. Returns true -
841 if successful; otherwise returns false. -
842 -
843 The \a quality factor must be in the range [0,100] or -1. Specify -
844 0 to obtain small compressed files, 100 for large uncompressed -
845 files, and -1 to use the default settings. -
846 -
847 If \a format is 0, an image format will be chosen from \a fileName's -
848 suffix. -
849 -
850 \sa {QPixmap#Reading and Writing Image Files}{Reading and Writing -
851 Image Files} -
852*/ -
853 -
854bool QPixmap::save(const QString &fileName, const char *format, int quality) const -
855{ -
856 if (isNull())
never evaluated: isNull()
0
857 return false; // nothing to save
never executed: return false;
0
858 QImageWriter writer(fileName, format);
never executed (the execution status of this line is deduced): QImageWriter writer(fileName, format);
-
859 return doImageIO(&writer, quality);
never executed: return doImageIO(&writer, quality);
0
860} -
861 -
862/*! -
863 \overload -
864 -
865 This function writes a QPixmap to the given \a device using the -
866 specified image file \a format and \a quality factor. This can be -
867 used, for example, to save a pixmap directly into a QByteArray: -
868 -
869 \snippet image/image.cpp 1 -
870*/ -
871 -
872bool QPixmap::save(QIODevice* device, const char* format, int quality) const -
873{ -
874 if (isNull())
partially evaluated: isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
875 return false; // nothing to save
never executed: return false;
0
876 QImageWriter writer(device, format);
executed (the execution status of this line is deduced): QImageWriter writer(device, format);
-
877 return doImageIO(&writer, quality);
executed: return doImageIO(&writer, quality);
Execution Count:1
1
878} -
879 -
880/*! \internal -
881*/ -
882bool QPixmap::doImageIO(QImageWriter *writer, int quality) const -
883{ -
884 if (quality > 100 || quality < -1)
partially evaluated: quality > 100
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
partially evaluated: quality < -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
885 qWarning("QPixmap::save: quality out of range [-1,100]");
never executed: QMessageLogger("image/qpixmap.cpp", 885, __PRETTY_FUNCTION__).warning("QPixmap::save: quality out of range [-1,100]");
0
886 if (quality >= 0)
partially evaluated: quality >= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
887 writer->setQuality(qMin(quality,100));
never executed: writer->setQuality(qMin(quality,100));
0
888 return writer->write(toImage());
executed: return writer->write(toImage());
Execution Count:1
1
889} -
890 -
891 -
892/*! -
893 \obsolete -
894 -
895 Use QPainter or the fill(QColor) overload instead. -
896*/ -
897 -
898void QPixmap::fill(const QPaintDevice *device, const QPoint &p) -
899{ -
900 Q_UNUSED(device)
never executed (the execution status of this line is deduced): (void)device;
-
901 Q_UNUSED(p)
never executed (the execution status of this line is deduced): (void)p;
-
902 qWarning("%s is deprecated, ignored", Q_FUNC_INFO);
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 902, __PRETTY_FUNCTION__).warning("%s is deprecated, ignored", __PRETTY_FUNCTION__);
-
903}
never executed: }
0
904 -
905 -
906/*! -
907 \fn void QPixmap::fill(const QPaintDevice *device, int x, int y) -
908 \obsolete -
909 -
910 Use QPainter or the fill(QColor) overload instead. -
911*/ -
912 -
913 -
914/*! -
915 Fills the pixmap with the given \a color. -
916 -
917 The effect of this function is undefined when the pixmap is -
918 being painted on. -
919 -
920 \sa {QPixmap#Pixmap Transformations}{Pixmap Transformations} -
921*/ -
922 -
923void QPixmap::fill(const QColor &color) -
924{ -
925 if (isNull())
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:363
4-363
926 return;
executed: return;
Execution Count:4
4
927 -
928 // Some people are probably already calling fill while a painter is active, so to not break -
929 // their programs, only print a warning and return when the fill operation could cause a crash. -
930 if (paintingActive() && (color.alpha() != 255) && !hasAlphaChannel()) {
partially evaluated: paintingActive()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:363
never evaluated: (color.alpha() != 255)
never evaluated: !hasAlphaChannel()
0-363
931 qWarning("QPixmap::fill: Cannot fill while pixmap is being painted on");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 931, __PRETTY_FUNCTION__).warning("QPixmap::fill: Cannot fill while pixmap is being painted on");
-
932 return;
never executed: return;
0
933 } -
934 -
935 if (data->ref.load() == 1) {
evaluated: data->ref.load() == 1
TRUEFALSE
yes
Evaluation Count:353
yes
Evaluation Count:10
10-353
936 // detach() will also remove this pixmap from caches, so -
937 // it has to be called even when ref == 1. -
938 detach();
executed (the execution status of this line is deduced): detach();
-
939 } else {
executed: }
Execution Count:353
353
940 // Don't bother to make a copy of the data object, since -
941 // it will be filled with new pixel data anyway. -
942 QPlatformPixmap *d = data->createCompatiblePlatformPixmap();
executed (the execution status of this line is deduced): QPlatformPixmap *d = data->createCompatiblePlatformPixmap();
-
943 d->resize(data->width(), data->height());
executed (the execution status of this line is deduced): d->resize(data->width(), data->height());
-
944 data = d;
executed (the execution status of this line is deduced): data = d;
-
945 }
executed: }
Execution Count:10
10
946 data->fill(color);
executed (the execution status of this line is deduced): data->fill(color);
-
947}
executed: }
Execution Count:363
363
948 -
949/*! \fn int QPixmap::serialNumber() const -
950 \obsolete -
951 Returns a number that identifies the contents of this QPixmap -
952 object. Distinct QPixmap objects can only have the same serial -
953 number if they refer to the same contents (but they don't have -
954 to). -
955 -
956 Use cacheKey() instead. -
957 -
958 \warning The serial number doesn't necessarily change when -
959 the pixmap is altered. This means that it may be dangerous to use -
960 it as a cache key. For caching pixmaps, we recommend using the -
961 QPixmapCache class whenever possible. -
962*/ -
963 -
964/*! -
965 Returns a number that identifies this QPixmap. Distinct QPixmap -
966 objects can only have the same cache key if they refer to the same -
967 contents. -
968 -
969 The cacheKey() will change when the pixmap is altered. -
970*/ -
971qint64 QPixmap::cacheKey() const -
972{ -
973 if (isNull())
evaluated: isNull()
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:3726
23-3726
974 return 0;
executed: return 0;
Execution Count:23
23
975 -
976 Q_ASSERT(data);
executed (the execution status of this line is deduced): qt_noop();
-
977 return data->cacheKey();
executed: return data->cacheKey();
Execution Count:3726
3726
978} -
979 -
980#if 0 -
981static void sendResizeEvents(QWidget *target) -
982{ -
983 QResizeEvent e(target->size(), QSize()); -
984 QApplication::sendEvent(target, &e); -
985 -
986 const QObjectList children = target->children(); -
987 for (int i = 0; i < children.size(); ++i) { -
988 QWidget *child = static_cast<QWidget*>(children.at(i)); -
989 if (child->isWidgetType() && !child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent)) -
990 sendResizeEvents(child); -
991 } -
992} -
993#endif -
994 -
995/*! -
996 \obsolete -
997 -
998 Use QWidget::grab() instead. -
999*/ -
1000QPixmap QPixmap::grabWidget(QObject *widget, const QRect &rectangle) -
1001{ -
1002 QPixmap pixmap;
never executed (the execution status of this line is deduced): QPixmap pixmap;
-
1003 qWarning("QPixmap::grabWidget is deprecated, use QWidget::grab() instead");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 1003, __PRETTY_FUNCTION__).warning("QPixmap::grabWidget is deprecated, use QWidget::grab() instead");
-
1004 if (!widget)
never evaluated: !widget
0
1005 return pixmap;
never executed: return pixmap;
0
1006 QMetaObject::invokeMethod(widget, "grab", Qt::DirectConnection,
never executed (the execution status of this line is deduced): QMetaObject::invokeMethod(widget, "grab", Qt::DirectConnection,
-
1007 Q_RETURN_ARG(QPixmap, pixmap),
never executed (the execution status of this line is deduced): QReturnArgument<QPixmap >("QPixmap", pixmap),
-
1008 Q_ARG(QRect, rectangle));
never executed (the execution status of this line is deduced): QArgument<QRect >("QRect", rectangle));
-
1009 return pixmap;
never executed: return pixmap;
0
1010} -
1011 -
1012/*! -
1013 \fn QPixmap QPixmap::grabWidget(QObject *widget, int x, int y, int w, int h) -
1014 \obsolete -
1015 -
1016 Use QWidget::grab() instead. -
1017*/ -
1018 -
1019/***************************************************************************** -
1020 QPixmap stream functions -
1021 *****************************************************************************/ -
1022#if !defined(QT_NO_DATASTREAM) -
1023/*! -
1024 \relates QPixmap -
1025 -
1026 Writes the given \a pixmap to the given \a stream as a PNG -
1027 image. Note that writing the stream to a file will not produce a -
1028 valid image file. -
1029 -
1030 \sa QPixmap::save(), {Serializing Qt Data Types} -
1031*/ -
1032 -
1033QDataStream &operator<<(QDataStream &stream, const QPixmap &pixmap) -
1034{ -
1035 return stream << pixmap.toImage();
executed: return stream << pixmap.toImage();
Execution Count:59
59
1036} -
1037 -
1038/*! -
1039 \relates QPixmap -
1040 -
1041 Reads an image from the given \a stream into the given \a pixmap. -
1042 -
1043 \sa QPixmap::load(), {Serializing Qt Data Types} -
1044*/ -
1045 -
1046QDataStream &operator>>(QDataStream &stream, QPixmap &pixmap) -
1047{ -
1048 QImage image;
executed (the execution status of this line is deduced): QImage image;
-
1049 stream >> image;
executed (the execution status of this line is deduced): stream >> image;
-
1050 -
1051 if (image.isNull()) {
evaluated: image.isNull()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:55
3-55
1052 pixmap = QPixmap();
executed (the execution status of this line is deduced): pixmap = QPixmap();
-
1053 } else if (image.depth() == 1) {
executed: }
Execution Count:3
evaluated: image.depth() == 1
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:42
3-42
1054 pixmap = QBitmap::fromImage(image);
executed (the execution status of this line is deduced): pixmap = QBitmap::fromImage(image);
-
1055 } else {
executed: }
Execution Count:13
13
1056 pixmap = QPixmap::fromImage(image);
executed (the execution status of this line is deduced): pixmap = QPixmap::fromImage(image);
-
1057 }
executed: }
Execution Count:42
42
1058 return stream;
executed: return stream;
Execution Count:58
58
1059} -
1060 -
1061#endif // QT_NO_DATASTREAM -
1062 -
1063/*! -
1064 \internal -
1065*/ -
1066 -
1067bool QPixmap::isDetached() const -
1068{ -
1069 return data && data->ref.load() == 1;
executed: return data && data->ref.load() == 1;
Execution Count:4
4
1070} -
1071 -
1072/*! -
1073 Replaces this pixmap's data with the given \a image using the -
1074 specified \a flags to control the conversion. The \a flags -
1075 argument is a bitwise-OR of the \l{Qt::ImageConversionFlags}. -
1076 Passing 0 for \a flags sets all the default options. Returns true -
1077 if the result is that this pixmap is not null. -
1078 -
1079 Note: this function was part of Qt 3 support in Qt 4.6 and earlier. -
1080 It has been promoted to official API status in 4.7 to support updating -
1081 the pixmap's image without creating a new QPixmap as fromImage() would. -
1082 -
1083 \sa fromImage() -
1084 \since 4.7 -
1085*/ -
1086bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags flags) -
1087{ -
1088 if (image.isNull() || !data)
never evaluated: image.isNull()
never evaluated: !data
0
1089 *this = QPixmap::fromImage(image, flags);
never executed: *this = QPixmap::fromImage(image, flags);
0
1090 else -
1091 data->fromImage(image, flags);
never executed: data->fromImage(image, flags);
0
1092 return !isNull();
never executed: return !isNull();
0
1093} -
1094 -
1095/*! -
1096 \fn QPixmap QPixmap::scaled(int width, int height, -
1097 Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode -
1098 transformMode) const -
1099 -
1100 \overload -
1101 -
1102 Returns a copy of the pixmap scaled to a rectangle with the given -
1103 \a width and \a height according to the given \a aspectRatioMode and -
1104 \a transformMode. -
1105 -
1106 If either the \a width or the \a height is zero or negative, this -
1107 function returns a null pixmap. -
1108*/ -
1109 -
1110/*! -
1111 \fn QPixmap QPixmap::scaled(const QSize &size, Qt::AspectRatioMode -
1112 aspectRatioMode, Qt::TransformationMode transformMode) const -
1113 -
1114 Scales the pixmap to the given \a size, using the aspect ratio and -
1115 transformation modes specified by \a aspectRatioMode and \a -
1116 transformMode. -
1117 -
1118 \image qimage-scaling.png -
1119 -
1120 \list -
1121 \li If \a aspectRatioMode is Qt::IgnoreAspectRatio, the pixmap -
1122 is scaled to \a size. -
1123 \li If \a aspectRatioMode is Qt::KeepAspectRatio, the pixmap is -
1124 scaled to a rectangle as large as possible inside \a size, preserving the aspect ratio. -
1125 \li If \a aspectRatioMode is Qt::KeepAspectRatioByExpanding, -
1126 the pixmap is scaled to a rectangle as small as possible -
1127 outside \a size, preserving the aspect ratio. -
1128 \endlist -
1129 -
1130 If the given \a size is empty, this function returns a null -
1131 pixmap. -
1132 -
1133 -
1134 In some cases it can be more beneficial to draw the pixmap to a -
1135 painter with a scale set rather than scaling the pixmap. This is -
1136 the case when the painter is for instance based on OpenGL or when -
1137 the scale factor changes rapidly. -
1138 -
1139 \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap -
1140 Transformations} -
1141 -
1142*/ -
1143QPixmap QPixmap::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode) const -
1144{ -
1145 if (isNull()) {
partially evaluated: isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:109
0-109
1146 qWarning("QPixmap::scaled: Pixmap is a null pixmap");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 1146, __PRETTY_FUNCTION__).warning("QPixmap::scaled: Pixmap is a null pixmap");
-
1147 return QPixmap();
never executed: return QPixmap();
0
1148 } -
1149 if (s.isEmpty())
partially evaluated: s.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:109
0-109
1150 return QPixmap();
never executed: return QPixmap();
0
1151 -
1152 QSize newSize = size();
executed (the execution status of this line is deduced): QSize newSize = size();
-
1153 newSize.scale(s, aspectMode);
executed (the execution status of this line is deduced): newSize.scale(s, aspectMode);
-
1154 newSize.rwidth() = qMax(newSize.width(), 1);
executed (the execution status of this line is deduced): newSize.rwidth() = qMax(newSize.width(), 1);
-
1155 newSize.rheight() = qMax(newSize.height(), 1);
executed (the execution status of this line is deduced): newSize.rheight() = qMax(newSize.height(), 1);
-
1156 if (newSize == size())
partially evaluated: newSize == size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:109
0-109
1157 return *this;
never executed: return *this;
0
1158 -
1159 QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(),
executed (the execution status of this line is deduced): QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(),
-
1160 (qreal)newSize.height() / height());
executed (the execution status of this line is deduced): (qreal)newSize.height() / height());
-
1161 QPixmap pix = transformed(wm, mode);
executed (the execution status of this line is deduced): QPixmap pix = transformed(wm, mode);
-
1162 return pix;
executed: return pix;
Execution Count:109
109
1163} -
1164 -
1165/*! -
1166 \fn QPixmap QPixmap::scaledToWidth(int width, Qt::TransformationMode -
1167 mode) const -
1168 -
1169 Returns a scaled copy of the image. The returned image is scaled -
1170 to the given \a width using the specified transformation \a mode. -
1171 The height of the pixmap is automatically calculated so that the -
1172 aspect ratio of the pixmap is preserved. -
1173 -
1174 If \a width is 0 or negative, a null pixmap is returned. -
1175 -
1176 \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap -
1177 Transformations} -
1178*/ -
1179QPixmap QPixmap::scaledToWidth(int w, Qt::TransformationMode mode) const -
1180{ -
1181 if (isNull()) {
never evaluated: isNull()
0
1182 qWarning("QPixmap::scaleWidth: Pixmap is a null pixmap");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 1182, __PRETTY_FUNCTION__).warning("QPixmap::scaleWidth: Pixmap is a null pixmap");
-
1183 return copy();
never executed: return copy();
0
1184 } -
1185 if (w <= 0)
never evaluated: w <= 0
0
1186 return QPixmap();
never executed: return QPixmap();
0
1187 -
1188 qreal factor = (qreal) w / width();
never executed (the execution status of this line is deduced): qreal factor = (qreal) w / width();
-
1189 QTransform wm = QTransform::fromScale(factor, factor);
never executed (the execution status of this line is deduced): QTransform wm = QTransform::fromScale(factor, factor);
-
1190 return transformed(wm, mode);
never executed: return transformed(wm, mode);
0
1191} -
1192 -
1193/*! -
1194 \fn QPixmap QPixmap::scaledToHeight(int height, -
1195 Qt::TransformationMode mode) const -
1196 -
1197 Returns a scaled copy of the image. The returned image is scaled -
1198 to the given \a height using the specified transformation \a mode. -
1199 The width of the pixmap is automatically calculated so that the -
1200 aspect ratio of the pixmap is preserved. -
1201 -
1202 If \a height is 0 or negative, a null pixmap is returned. -
1203 -
1204 \sa isNull(), {QPixmap#Pixmap Transformations}{Pixmap -
1205 Transformations} -
1206*/ -
1207QPixmap QPixmap::scaledToHeight(int h, Qt::TransformationMode mode) const -
1208{ -
1209 if (isNull()) {
never evaluated: isNull()
0
1210 qWarning("QPixmap::scaleHeight: Pixmap is a null pixmap");
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 1210, __PRETTY_FUNCTION__).warning("QPixmap::scaleHeight: Pixmap is a null pixmap");
-
1211 return copy();
never executed: return copy();
0
1212 } -
1213 if (h <= 0)
never evaluated: h <= 0
0
1214 return QPixmap();
never executed: return QPixmap();
0
1215 -
1216 qreal factor = (qreal) h / height();
never executed (the execution status of this line is deduced): qreal factor = (qreal) h / height();
-
1217 QTransform wm = QTransform::fromScale(factor, factor);
never executed (the execution status of this line is deduced): QTransform wm = QTransform::fromScale(factor, factor);
-
1218 return transformed(wm, mode);
never executed: return transformed(wm, mode);
0
1219} -
1220 -
1221/*! -
1222 Returns a copy of the pixmap that is transformed using the given -
1223 transformation \a transform and transformation \a mode. The original -
1224 pixmap is not changed. -
1225 -
1226 The transformation \a transform is internally adjusted to compensate -
1227 for unwanted translation; i.e. the pixmap produced is the smallest -
1228 pixmap that contains all the transformed points of the original -
1229 pixmap. Use the trueMatrix() function to retrieve the actual -
1230 matrix used for transforming the pixmap. -
1231 -
1232 This function is slow because it involves transformation to a -
1233 QImage, non-trivial computations and a transformation back to a -
1234 QPixmap. -
1235 -
1236 \sa trueMatrix(), {QPixmap#Pixmap Transformations}{Pixmap -
1237 Transformations} -
1238*/ -
1239QPixmap QPixmap::transformed(const QTransform &transform, -
1240 Qt::TransformationMode mode) const -
1241{ -
1242 if (isNull() || transform.type() <= QTransform::TxTranslate)
partially evaluated: isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:113
partially evaluated: transform.type() <= QTransform::TxTranslate
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:113
0-113
1243 return *this;
never executed: return *this;
0
1244 -
1245 return data->transformed(transform, mode);
executed: return data->transformed(transform, mode);
Execution Count:113
113
1246} -
1247 -
1248/*! -
1249 \overload -
1250 -
1251 This convenience function loads the \a matrix into a -
1252 QTransform and calls the overloaded function. -
1253 */ -
1254QPixmap QPixmap::transformed(const QMatrix &matrix, Qt::TransformationMode mode) const -
1255{ -
1256 return transformed(QTransform(matrix), mode);
never executed: return transformed(QTransform(matrix), mode);
0
1257} -
1258 -
1259 -
1260 -
1261 -
1262 -
1263 -
1264 -
1265 -
1266/*! -
1267 \class QPixmap -
1268 \inmodule QtGui -
1269 -
1270 \brief The QPixmap class is an off-screen image representation -
1271 that can be used as a paint device. -
1272 -
1273 \ingroup painting -
1274 \ingroup shared -
1275 -
1276 -
1277 Qt provides four classes for handling image data: QImage, QPixmap, -
1278 QBitmap and QPicture. QImage is designed and optimized for I/O, -
1279 and for direct pixel access and manipulation, while QPixmap is -
1280 designed and optimized for showing images on screen. QBitmap is -
1281 only a convenience class that inherits QPixmap, ensuring a depth -
1282 of 1. The isQBitmap() function returns true if a QPixmap object is -
1283 really a bitmap, otherwise returns false. Finally, the QPicture class -
1284 is a paint device that records and replays QPainter commands. -
1285 -
1286 A QPixmap can easily be displayed on the screen using QLabel or -
1287 one of QAbstractButton's subclasses (such as QPushButton and -
1288 QToolButton). QLabel has a pixmap property, whereas -
1289 QAbstractButton has an icon property. -
1290 -
1291 QPixmap objects can be passed around by value since the QPixmap -
1292 class uses implicit data sharing. For more information, see the \l -
1293 {Implicit Data Sharing} documentation. QPixmap objects can also be -
1294 streamed. -
1295 -
1296 Note that the pixel data in a pixmap is internal and is managed by -
1297 the underlying window system. Because QPixmap is a QPaintDevice -
1298 subclass, QPainter can be used to draw directly onto pixmaps. -
1299 Pixels can only be accessed through QPainter functions or by -
1300 converting the QPixmap to a QImage. However, the fill() function -
1301 is available for initializing the entire pixmap with a given color. -
1302 -
1303 There are functions to convert between QImage and -
1304 QPixmap. Typically, the QImage class is used to load an image -
1305 file, optionally manipulating the image data, before the QImage -
1306 object is converted into a QPixmap to be shown on -
1307 screen. Alternatively, if no manipulation is desired, the image -
1308 file can be loaded directly into a QPixmap. On Windows, the -
1309 QPixmap class also supports conversion between \c HBITMAP and -
1310 QPixmap. -
1311 -
1312 QPixmap provides a collection of functions that can be used to -
1313 obtain a variety of information about the pixmap. In addition, -
1314 there are several functions that enables transformation of the -
1315 pixmap. -
1316 -
1317 \tableofcontents -
1318 -
1319 \section1 Reading and Writing Image Files -
1320 -
1321 QPixmap provides several ways of reading an image file: The file -
1322 can be loaded when constructing the QPixmap object, or by using -
1323 the load() or loadFromData() functions later on. When loading an -
1324 image, the file name can either refer to an actual file on disk or -
1325 to one of the application's embedded resources. See \l{The Qt -
1326 Resource System} overview for details on how to embed images and -
1327 other resource files in the application's executable. -
1328 -
1329 Simply call the save() function to save a QPixmap object. -
1330 -
1331 The complete list of supported file formats are available through -
1332 the QImageReader::supportedImageFormats() and -
1333 QImageWriter::supportedImageFormats() functions. New file formats -
1334 can be added as plugins. By default, Qt supports the following -
1335 formats: -
1336 -
1337 \table -
1338 \header \li Format \li Description \li Qt's support -
1339 \row \li BMP \li Windows Bitmap \li Read/write -
1340 \row \li GIF \li Graphic Interchange Format (optional) \li Read -
1341 \row \li JPG \li Joint Photographic Experts Group \li Read/write -
1342 \row \li JPEG \li Joint Photographic Experts Group \li Read/write -
1343 \row \li PNG \li Portable Network Graphics \li Read/write -
1344 \row \li PBM \li Portable Bitmap \li Read -
1345 \row \li PGM \li Portable Graymap \li Read -
1346 \row \li PPM \li Portable Pixmap \li Read/write -
1347 \row \li XBM \li X11 Bitmap \li Read/write -
1348 \row \li XPM \li X11 Pixmap \li Read/write -
1349 \endtable -
1350 -
1351 \section1 Pixmap Information -
1352 -
1353 QPixmap provides a collection of functions that can be used to -
1354 obtain a variety of information about the pixmap: -
1355 -
1356 \table -
1357 \header -
1358 \li \li Available Functions -
1359 \row -
1360 \li Geometry -
1361 \li -
1362 The size(), width() and height() functions provide information -
1363 about the pixmap's size. The rect() function returns the image's -
1364 enclosing rectangle. -
1365 -
1366 \row -
1367 \li Alpha component -
1368 \li -
1369 -
1370 The hasAlphaChannel() returns true if the pixmap has a format that -
1371 respects the alpha channel, otherwise returns false. The hasAlpha(), -
1372 setMask() and mask() functions are legacy and should not be used. -
1373 They are potentially very slow. -
1374 -
1375 The createHeuristicMask() function creates and returns a 1-bpp -
1376 heuristic mask (i.e. a QBitmap) for this pixmap. It works by -
1377 selecting a color from one of the corners and then chipping away -
1378 pixels of that color, starting at all the edges. The -
1379 createMaskFromColor() function creates and returns a mask (i.e. a -
1380 QBitmap) for the pixmap based on a given color. -
1381 -
1382 \row -
1383 \li Low-level information -
1384 \li -
1385 -
1386 The depth() function returns the depth of the pixmap. The -
1387 defaultDepth() function returns the default depth, i.e. the depth -
1388 used by the application on the given screen. -
1389 -
1390 The cacheKey() function returns a number that uniquely -
1391 identifies the contents of the QPixmap object. -
1392 -
1393 The x11Info() function returns information about the configuration -
1394 of the X display used by the screen to which the pixmap currently -
1395 belongs. The x11PictureHandle() function returns the X11 Picture -
1396 handle of the pixmap for XRender support. Note that the two latter -
1397 functions are only available on x11. -
1398 -
1399 \endtable -
1400 -
1401 \section1 Pixmap Conversion -
1402 -
1403 A QPixmap object can be converted into a QImage using the -
1404 toImage() function. Likewise, a QImage can be converted into a -
1405 QPixmap using the fromImage(). If this is too expensive an -
1406 operation, you can use QBitmap::fromImage() instead. -
1407 -
1408 In addition, on Windows, the QPixmap class supports conversion to -
1409 and from HBITMAP: the toWinHBITMAP() function creates a HBITMAP -
1410 equivalent to the QPixmap, based on the given HBitmapFormat, and -
1411 returns the HBITMAP handle. The fromWinHBITMAP() function returns -
1412 a QPixmap that is equivalent to the given bitmap which has the -
1413 specified format. The QPixmap class also supports conversion to -
1414 and from HICON: the toWinHICON() function creates a HICON equivalent -
1415 to the QPixmap, and returns the HICON handle. The fromWinHICON() -
1416 function returns a QPixmap that is equivalent to the given icon. -
1417 -
1418 \section1 Pixmap Transformations -
1419 -
1420 QPixmap supports a number of functions for creating a new pixmap -
1421 that is a transformed version of the original: -
1422 -
1423 The scaled(), scaledToWidth() and scaledToHeight() functions -
1424 return scaled copies of the pixmap, while the copy() function -
1425 creates a QPixmap that is a plain copy of the original one. -
1426 -
1427 The transformed() function returns a copy of the pixmap that is -
1428 transformed with the given transformation matrix and -
1429 transformation mode: Internally, the transformation matrix is -
1430 adjusted to compensate for unwanted translation, -
1431 i.e. transformed() returns the smallest pixmap containing all -
1432 transformed points of the original pixmap. The static trueMatrix() -
1433 function returns the actual matrix used for transforming the -
1434 pixmap. -
1435 -
1436 \note When using the native X11 graphics system, the pixmap -
1437 becomes invalid when the QApplication instance is destroyed. -
1438 -
1439 \sa QBitmap, QImage, QImageReader, QImageWriter -
1440*/ -
1441 -
1442 -
1443/*! -
1444 \typedef QPixmap::DataPtr -
1445 \internal -
1446*/ -
1447 -
1448/*! -
1449 \fn DataPtr &QPixmap::data_ptr() -
1450 \internal -
1451*/ -
1452 -
1453/*! -
1454 Returns true if this pixmap has an alpha channel, \e or has a -
1455 mask, otherwise returns false. -
1456 -
1457 \sa hasAlphaChannel(), mask() -
1458*/ -
1459bool QPixmap::hasAlpha() const -
1460{ -
1461 return data && data->hasAlphaChannel();
executed: return data && data->hasAlphaChannel();
Execution Count:1
1
1462} -
1463 -
1464/*! -
1465 Returns true if the pixmap has a format that respects the alpha -
1466 channel, otherwise returns false. -
1467 -
1468 \sa hasAlpha() -
1469*/ -
1470bool QPixmap::hasAlphaChannel() const -
1471{ -
1472 return data && data->hasAlphaChannel();
executed: return data && data->hasAlphaChannel();
Execution Count:88
88
1473} -
1474 -
1475/*! -
1476 \internal -
1477*/ -
1478int QPixmap::metric(PaintDeviceMetric metric) const -
1479{ -
1480 return data ? data->metric(metric) : 0;
executed: return data ? data->metric(metric) : 0;
Execution Count:1916
1916
1481} -
1482 -
1483/*! -
1484 \internal -
1485*/ -
1486QPaintEngine *QPixmap::paintEngine() const -
1487{ -
1488 return data ? data->paintEngine() : 0;
executed: return data ? data->paintEngine() : 0;
Execution Count:1900
1900
1489} -
1490 -
1491/*! -
1492 \fn QBitmap QPixmap::mask() const -
1493 -
1494 Extracts a bitmap mask from the pixmap's alpha channel. -
1495 -
1496 \warning This is potentially an expensive operation. The mask of -
1497 the pixmap is extracted dynamically from the pixeldata. -
1498 -
1499 \sa setMask(), {QPixmap#Pixmap Information}{Pixmap Information} -
1500*/ -
1501QBitmap QPixmap::mask() const -
1502{ -
1503 if (!data || !hasAlphaChannel())
evaluated: !data
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:85
evaluated: !hasAlphaChannel()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:70
7-85
1504 return QBitmap();
executed: return QBitmap();
Execution Count:22
22
1505 -
1506 const QImage img = toImage();
executed (the execution status of this line is deduced): const QImage img = toImage();
-
1507 const QImage image = (img.depth() < 32 ? img.convertToFormat(QImage::Format_ARGB32_Premultiplied) : img);
partially evaluated: img.depth() < 32
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:70
0-70
1508 const int w = image.width();
executed (the execution status of this line is deduced): const int w = image.width();
-
1509 const int h = image.height();
executed (the execution status of this line is deduced): const int h = image.height();
-
1510 -
1511 QImage mask(w, h, QImage::Format_MonoLSB);
executed (the execution status of this line is deduced): QImage mask(w, h, QImage::Format_MonoLSB);
-
1512 if (mask.isNull()) // allocation failed
partially evaluated: mask.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:70
0-70
1513 return QBitmap();
never executed: return QBitmap();
0
1514 -
1515 mask.setColorCount(2);
executed (the execution status of this line is deduced): mask.setColorCount(2);
-
1516 mask.setColor(0, QColor(Qt::color0).rgba());
executed (the execution status of this line is deduced): mask.setColor(0, QColor(Qt::color0).rgba());
-
1517 mask.setColor(1, QColor(Qt::color1).rgba());
executed (the execution status of this line is deduced): mask.setColor(1, QColor(Qt::color1).rgba());
-
1518 -
1519 const int bpl = mask.bytesPerLine();
executed (the execution status of this line is deduced): const int bpl = mask.bytesPerLine();
-
1520 -
1521 for (int y = 0; y < h; ++y) {
evaluated: y < h
TRUEFALSE
yes
Evaluation Count:1078
yes
Evaluation Count:70
70-1078
1522 const QRgb *src = reinterpret_cast<const QRgb*>(image.scanLine(y));
executed (the execution status of this line is deduced): const QRgb *src = reinterpret_cast<const QRgb*>(image.scanLine(y));
-
1523 uchar *dest = mask.scanLine(y);
executed (the execution status of this line is deduced): uchar *dest = mask.scanLine(y);
-
1524 memset(dest, 0, bpl);
executed (the execution status of this line is deduced): memset(dest, 0, bpl);
-
1525 for (int x = 0; x < w; ++x) {
evaluated: x < w
TRUEFALSE
yes
Evaluation Count:33928
yes
Evaluation Count:1078
1078-33928
1526 if (qAlpha(*src) > 0)
evaluated: qAlpha(*src) > 0
TRUEFALSE
yes
Evaluation Count:11575
yes
Evaluation Count:22353
11575-22353
1527 dest[x >> 3] |= (1 << (x & 7));
executed: dest[x >> 3] |= (1 << (x & 7));
Execution Count:11575
11575
1528 ++src;
executed (the execution status of this line is deduced): ++src;
-
1529 }
executed: }
Execution Count:33928
33928
1530 }
executed: }
Execution Count:1078
1078
1531 -
1532 return QBitmap::fromImage(mask);
executed: return QBitmap::fromImage(mask);
Execution Count:70
70
1533} -
1534 -
1535/*! -
1536 Returns the default pixmap depth used by the application. -
1537 -
1538 On all platforms the depth of the primary screen will be returned. -
1539 -
1540 \sa depth(), QColormap::depth(), {QPixmap#Pixmap Information}{Pixmap Information} -
1541 -
1542*/ -
1543int QPixmap::defaultDepth() -
1544{ -
1545 return QGuiApplication::primaryScreen()->depth();
executed: return QGuiApplication::primaryScreen()->depth();
Execution Count:33
33
1546} -
1547 -
1548/*! -
1549 Detaches the pixmap from shared pixmap data. -
1550 -
1551 A pixmap is automatically detached by Qt whenever its contents are -
1552 about to change. This is done in almost all QPixmap member -
1553 functions that modify the pixmap (fill(), fromImage(), -
1554 load(), etc.), and in QPainter::begin() on a pixmap. -
1555 -
1556 There are two exceptions in which detach() must be called -
1557 explicitly, that is when calling the handle() or the -
1558 x11PictureHandle() function (only available on X11). Otherwise, -
1559 any modifications done using system calls, will be performed on -
1560 the shared data. -
1561 -
1562 The detach() function returns immediately if there is just a -
1563 single reference or if the pixmap has not been initialized yet. -
1564*/ -
1565void QPixmap::detach() -
1566{ -
1567 if (!data)
evaluated: !data
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1235
1-1235
1568 return;
executed: return;
Execution Count:1
1
1569 -
1570 // QPixmap.data member may be QRuntimePlatformPixmap so use handle() function to get -
1571 // the actual underlaying runtime pixmap data. -
1572 QPlatformPixmap *pd = handle();
executed (the execution status of this line is deduced): QPlatformPixmap *pd = handle();
-
1573 QPlatformPixmap::ClassId id = pd->classId();
executed (the execution status of this line is deduced): QPlatformPixmap::ClassId id = pd->classId();
-
1574 if (id == QPlatformPixmap::RasterClass) {
partially evaluated: id == QPlatformPixmap::RasterClass
TRUEFALSE
yes
Evaluation Count:1235
no
Evaluation Count:0
0-1235
1575 QRasterPlatformPixmap *rasterData = static_cast<QRasterPlatformPixmap*>(pd);
executed (the execution status of this line is deduced): QRasterPlatformPixmap *rasterData = static_cast<QRasterPlatformPixmap*>(pd);
-
1576 rasterData->image.detach();
executed (the execution status of this line is deduced): rasterData->image.detach();
-
1577 }
executed: }
Execution Count:1235
1235
1578 -
1579 if (data->is_cached && data->ref.load() == 1)
partially evaluated: data->is_cached
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1235
never evaluated: data->ref.load() == 1
0-1235
1580 QImagePixmapCleanupHooks::executePlatformPixmapModificationHooks(data.data());
never executed: QImagePixmapCleanupHooks::executePlatformPixmapModificationHooks(data.data());
0
1581 -
1582 if (data->ref.load() != 1) {
evaluated: data->ref.load() != 1
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:1229
6-1229
1583 *this = copy();
executed (the execution status of this line is deduced): *this = copy();
-
1584 }
executed: }
Execution Count:6
6
1585 ++data->detach_no;
executed (the execution status of this line is deduced): ++data->detach_no;
-
1586}
executed: }
Execution Count:1235
1235
1587 -
1588/*! -
1589 \fn QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) -
1590 -
1591 Converts the given \a image to a pixmap using the specified \a -
1592 flags to control the conversion. The \a flags argument is a -
1593 bitwise-OR of the \l{Qt::ImageConversionFlags}. Passing 0 for \a -
1594 flags sets all the default options. -
1595 -
1596 In case of monochrome and 8-bit images, the image is first -
1597 converted to a 32-bit pixmap and then filled with the colors in -
1598 the color table. If this is too expensive an operation, you can -
1599 use QBitmap::fromImage() instead. -
1600 -
1601 \sa fromImageReader(), toImage(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} -
1602*/ -
1603QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) -
1604{ -
1605 if (image.isNull())
evaluated: image.isNull()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3863
1-3863
1606 return QPixmap();
executed: return QPixmap();
Execution Count:1
1
1607 -
1608 QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
executed (the execution status of this line is deduced): QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
-
1609 data->fromImage(image, flags);
executed (the execution status of this line is deduced): data->fromImage(image, flags);
-
1610 return QPixmap(data.take());
executed: return QPixmap(data.take());
Execution Count:3863
3863
1611} -
1612 -
1613/*! -
1614 \fn QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags) -
1615 -
1616 Create a QPixmap from an image read directly from an \a imageReader. -
1617 The \a flags argument is a bitwise-OR of the \l{Qt::ImageConversionFlags}. -
1618 Passing 0 for \a flags sets all the default options. -
1619 -
1620 On some systems, reading an image directly to QPixmap can use less memory than -
1621 reading a QImage to convert it to QPixmap. -
1622 -
1623 \sa fromImage(), toImage(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} -
1624*/ -
1625QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags) -
1626{ -
1627 QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
executed (the execution status of this line is deduced): QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
-
1628 data->fromImageReader(imageReader, flags);
executed (the execution status of this line is deduced): data->fromImageReader(imageReader, flags);
-
1629 return QPixmap(data.take());
executed: return QPixmap(data.take());
Execution Count:15
15
1630} -
1631 -
1632/*! -
1633 \fn QPixmap QPixmap::grabWindow(WId window, int x, int y, int -
1634 width, int height) -
1635 -
1636 Creates and returns a pixmap constructed by grabbing the contents -
1637 of the given \a window restricted by QRect(\a x, \a y, \a width, -
1638 \a height). -
1639 -
1640 The arguments (\a{x}, \a{y}) specify the offset in the window, -
1641 whereas (\a{width}, \a{height}) specify the area to be copied. If -
1642 \a width is negative, the function copies everything to the right -
1643 border of the window. If \a height is negative, the function -
1644 copies everything to the bottom of the window. -
1645 -
1646 The window system identifier (\c WId) can be retrieved using the -
1647 QWidget::winId() function. The rationale for using a window -
1648 identifier and not a QWidget, is to enable grabbing of windows -
1649 that are not part of the application, window system frames, and so -
1650 on. -
1651 -
1652 The grabWindow() function grabs pixels from the screen, not from -
1653 the window, i.e. if there is another window partially or entirely -
1654 over the one you grab, you get pixels from the overlying window, -
1655 too. The mouse cursor is generally not grabbed. -
1656 -
1657 Note on X11 that if the given \a window doesn't have the same depth -
1658 as the root window, and another window partially or entirely -
1659 obscures the one you grab, you will \e not get pixels from the -
1660 overlying window. The contents of the obscured areas in the -
1661 pixmap will be undefined and uninitialized. -
1662 -
1663 On Windows Vista and above grabbing a layered window, which is -
1664 created by setting the Qt::WA_TranslucentBackground attribute, will -
1665 not work. Instead grabbing the desktop widget should work. -
1666 -
1667 \warning In general, grabbing an area outside the screen is not -
1668 safe. This depends on the underlying window system. -
1669 -
1670 \warning The function is deprecated in Qt 5.0 since there might be -
1671 platform plugins in which window system identifiers (\c WId) -
1672 are local to a screen. Use QScreen::grabWindow() instead. -
1673 -
1674 \sa grabWidget(), {Screenshot Example} -
1675 \sa QScreen -
1676 \deprecated -
1677*/ -
1678 -
1679QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h) -
1680{ -
1681 qWarning("%s is deprecated, use QScreen::grabWindow() instead."
never executed (the execution status of this line is deduced): QMessageLogger("image/qpixmap.cpp", 1681, __PRETTY_FUNCTION__).warning("%s is deprecated, use QScreen::grabWindow() instead."
-
1682 " Defaulting to primary screen.", Q_FUNC_INFO);
never executed (the execution status of this line is deduced): " Defaulting to primary screen.", __PRETTY_FUNCTION__);
-
1683 return QGuiApplication::primaryScreen()->grabWindow(window, x, y, w, h);
never executed: return QGuiApplication::primaryScreen()->grabWindow(window, x, y, w, h);
0
1684} -
1685 -
1686/*! -
1687 \internal -
1688*/ -
1689QPlatformPixmap* QPixmap::handle() const -
1690{ -
1691 return data.data();
executed: return data.data();
Execution Count:8313
8313
1692} -
1693 -
1694#ifndef QT_NO_DEBUG_STREAM -
1695QDebug operator<<(QDebug dbg, const QPixmap &r) -
1696{ -
1697 dbg.nospace() << "QPixmap(" << r.size() << ')';
executed (the execution status of this line is deduced): dbg.nospace() << "QPixmap(" << r.size() << ')';
-
1698 return dbg.space();
executed: return dbg.space();
Execution Count:2
2
1699} -
1700#endif -
1701 -
1702/*! -
1703 \fn QPixmap QPixmap::alphaChannel() const -
1704 -
1705 Most use cases for this can be achieved using a QPainter and QPainter::CompositionMode instead. -
1706*/ -
1707 -
1708/*! -
1709 \fn void QPixmap::setAlphaChannel(const QPixmap &p) -
1710 -
1711 Most use cases for this can be achieved using \a p with QPainter and QPainter::CompositionMode instead. -
1712*/ -
1713 -
1714QT_END_NAMESPACE -
1715 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial