qimage.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qimage.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 "qimage.h"-
41#include "qdatastream.h"-
42#include "qbuffer.h"-
43#include "qmap.h"-
44#include "qmatrix.h"-
45#include "qtransform.h"-
46#include "qimagereader.h"-
47#include "qimagewriter.h"-
48#include "qstringlist.h"-
49#include "qvariant.h"-
50#include "qimagepixmapcleanuphooks_p.h"-
51#include <qpa/qplatformintegration.h>-
52#include <private/qguiapplication_p.h>-
53#include <ctype.h>-
54#include <stdlib.h>-
55#include <limits.h>-
56#include <qpa/qplatformpixmap.h>-
57#include <private/qdrawhelper_p.h>-
58#include <private/qmemrotate_p.h>-
59#include <private/qimagescale_p.h>-
60#include <private/qsimd_p.h>-
61-
62#include <qhash.h>-
63-
64#include <private/qpaintengine_raster_p.h>-
65-
66#include <private/qimage_p.h>-
67#include <private/qfont_p.h>-
68-
69QT_BEGIN_NAMESPACE-
70-
71static inline bool isLocked(QImageData *data)-
72{-
73 return data != 0 && data->is_locked;
never executed: return data != 0 && data->is_locked;
0
74}-
75-
76#if defined(Q_CC_DEC) && defined(__alpha) && (__DECCXX_VER-0 >= 50190001)-
77#pragma message disable narrowptr-
78#endif-
79-
80-
81#define QIMAGE_SANITYCHECK_MEMORY(image) \-
82 if ((image).isNull()) { \-
83 qWarning("QImage: out of memory, returning null image"); \-
84 return QImage(); \-
85 }-
86-
87-
88static QImage rotated90(const QImage &src);-
89static QImage rotated180(const QImage &src);-
90static QImage rotated270(const QImage &src);-
91-
92QBasicAtomicInt qimage_serial_number = Q_BASIC_ATOMIC_INITIALIZER(1);-
93-
94QImageData::QImageData()-
95 : ref(0), width(0), height(0), depth(0), nbytes(0), devicePixelRatio(1.0), data(0),-
96 format(QImage::Format_ARGB32), bytes_per_line(0),-
97 ser_no(qimage_serial_number.fetchAndAddRelaxed(1)),-
98 detach_no(0),-
99 dpmx(qt_defaultDpiX() * 100 / qreal(2.54)),-
100 dpmy(qt_defaultDpiY() * 100 / qreal(2.54)),-
101 offset(0, 0), own_data(true), ro_data(false), has_alpha_clut(false),-
102 is_cached(false), is_locked(false), cleanupFunction(0), cleanupInfo(0),-
103 paintEngine(0)-
104{-
105}
never executed: end of block
0
106-
107/*! \fn QImageData * QImageData::create(const QSize &size, QImage::Format format)-
108-
109 \internal-
110-
111 Creates a new image data.-
112 Returns 0 if invalid parameters are give or anything else failed.-
113*/-
114QImageData * QImageData::create(const QSize &size, QImage::Format format)-
115{-
116 if (!size.isValid() || format == QImage::Format_Invalid)
!size.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
format == QIma...Format_InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
0
117 return 0; // invalid parameter(s)
never executed: return 0;
0
118-
119 uint width = size.width();-
120 uint height = size.height();-
121 uint depth = qt_depthForFormat(format);-
122-
123 const int bytes_per_line = ((width * depth + 31) >> 5) << 2; // bytes per scanline (must be multiple of 4)-
124-
125 // sanity check for potential overflows-
126 if (INT_MAX/depth < width
2147483647/depth < widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
127 || bytes_per_line <= 0
bytes_per_line <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
128 || height <= 0
height <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
129 || INT_MAX/uint(bytes_per_line) < height
2147483647/uin...line) < heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
130 || INT_MAX/sizeof(uchar *) < uint(height))
2147483647/siz...< uint(height)Description
TRUEnever evaluated
FALSEnever evaluated
0
131 return 0;
never executed: return 0;
0
132-
133 QScopedPointer<QImageData> d(new QImageData);-
134-
135 switch (format) {-
136 case QImage::Format_Mono:
never executed: case QImage::Format_Mono:
0
137 case QImage::Format_MonoLSB:
never executed: case QImage::Format_MonoLSB:
0
138 d->colortable.resize(2);-
139 d->colortable[0] = QColor(Qt::black).rgba();-
140 d->colortable[1] = QColor(Qt::white).rgba();-
141 break;
never executed: break;
0
142 default:
never executed: default:
0
143 break;
never executed: break;
0
144 }-
145-
146 d->width = width;-
147 d->height = height;-
148 d->depth = depth;-
149 d->format = format;-
150 d->has_alpha_clut = false;-
151 d->is_cached = false;-
152-
153 d->bytes_per_line = bytes_per_line;-
154-
155 d->nbytes = d->bytes_per_line*height;-
156 d->data = (uchar *)malloc(d->nbytes);-
157-
158 if (!d->data) {
!d->dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
159 return 0;
never executed: return 0;
0
160 }-
161-
162 d->ref.ref();-
163 return d.take();
never executed: return d.take();
0
164-
165}-
166-
167QImageData::~QImageData()-
168{-
169 if (cleanupFunction)
cleanupFunctionDescription
TRUEnever evaluated
FALSEnever evaluated
0
170 cleanupFunction(cleanupInfo);
never executed: cleanupFunction(cleanupInfo);
0
171 if (is_cached)
is_cachedDescription
TRUEnever evaluated
FALSEnever evaluated
0
172 QImagePixmapCleanupHooks::executeImageHooks((((qint64) ser_no) << 32) | ((qint64) detach_no));
never executed: QImagePixmapCleanupHooks::executeImageHooks((((qint64) ser_no) << 32) | ((qint64) detach_no));
0
173 delete paintEngine;-
174 if (data && own_data)
dataDescription
TRUEnever evaluated
FALSEnever evaluated
own_dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
175 free(data);
never executed: free(data);
0
176 data = 0;-
177}
never executed: end of block
0
178-
179#if defined(_M_ARM)-
180#pragma optimize("", off)-
181#endif-
182-
183bool QImageData::checkForAlphaPixels() const-
184{-
185 bool has_alpha_pixels = false;-
186-
187 switch (format) {-
188-
189 case QImage::Format_Mono:
never executed: case QImage::Format_Mono:
0
190 case QImage::Format_MonoLSB:
never executed: case QImage::Format_MonoLSB:
0
191 case QImage::Format_Indexed8:
never executed: case QImage::Format_Indexed8:
0
192 has_alpha_pixels = has_alpha_clut;-
193 break;
never executed: break;
0
194 case QImage::Format_Alpha8:
never executed: case QImage::Format_Alpha8:
0
195 has_alpha_pixels = true;-
196 break;
never executed: break;
0
197 case QImage::Format_ARGB32:
never executed: case QImage::Format_ARGB32:
0
198 case QImage::Format_ARGB32_Premultiplied: {
never executed: case QImage::Format_ARGB32_Premultiplied:
0
199 const uchar *bits = data;-
200 for (int y=0; y<height && !has_alpha_pixels; ++y) {
y<heightDescription
TRUEnever evaluated
FALSEnever evaluated
!has_alpha_pixelsDescription
TRUEnever evaluated
FALSEnever evaluated
0
201 uint alphaAnd = 0xff000000;-
202 for (int x=0; x<width; ++x)
x<widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
203 alphaAnd &= reinterpret_cast<const uint*>(bits)[x];
never executed: alphaAnd &= reinterpret_cast<const uint*>(bits)[x];
0
204 has_alpha_pixels = (alphaAnd != 0xff000000);-
205 bits += bytes_per_line;-
206 }
never executed: end of block
0
207 } break;
never executed: break;
0
208-
209 case QImage::Format_RGBA8888:
never executed: case QImage::Format_RGBA8888:
0
210 case QImage::Format_RGBA8888_Premultiplied: {
never executed: case QImage::Format_RGBA8888_Premultiplied:
0
211 const uchar *bits = data;-
212 for (int y=0; y<height && !has_alpha_pixels; ++y) {
y<heightDescription
TRUEnever evaluated
FALSEnever evaluated
!has_alpha_pixelsDescription
TRUEnever evaluated
FALSEnever evaluated
0
213 uchar alphaAnd = 0xff;-
214 for (int x=0; x<width; ++x)
x<widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
215 alphaAnd &= bits[x * 4+ 3];
never executed: alphaAnd &= bits[x * 4+ 3];
0
216 has_alpha_pixels = (alphaAnd != 0xff);-
217 bits += bytes_per_line;-
218 }
never executed: end of block
0
219 } break;
never executed: break;
0
220-
221 case QImage::Format_A2BGR30_Premultiplied:
never executed: case QImage::Format_A2BGR30_Premultiplied:
0
222 case QImage::Format_A2RGB30_Premultiplied: {
never executed: case QImage::Format_A2RGB30_Premultiplied:
0
223 const uchar *bits = data;-
224 for (int y=0; y<height && !has_alpha_pixels; ++y) {
y<heightDescription
TRUEnever evaluated
FALSEnever evaluated
!has_alpha_pixelsDescription
TRUEnever evaluated
FALSEnever evaluated
0
225 uint alphaAnd = 0xc0000000;-
226 for (int x=0; x<width; ++x)
x<widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
227 alphaAnd &= reinterpret_cast<const uint*>(bits)[x];
never executed: alphaAnd &= reinterpret_cast<const uint*>(bits)[x];
0
228 has_alpha_pixels = (alphaAnd != 0xc0000000);-
229 bits += bytes_per_line;-
230 }
never executed: end of block
0
231 } break;
never executed: break;
0
232-
233 case QImage::Format_ARGB8555_Premultiplied:
never executed: case QImage::Format_ARGB8555_Premultiplied:
0
234 case QImage::Format_ARGB8565_Premultiplied: {
never executed: case QImage::Format_ARGB8565_Premultiplied:
0
235 const uchar *bits = data;-
236 const uchar *end_bits = data + bytes_per_line;-
237-
238 for (int y=0; y<height && !has_alpha_pixels; ++y) {
y<heightDescription
TRUEnever evaluated
FALSEnever evaluated
!has_alpha_pixelsDescription
TRUEnever evaluated
FALSEnever evaluated
0
239 uchar alphaAnd = 0xff;-
240 while (bits < end_bits) {
bits < end_bitsDescription
TRUEnever evaluated
FALSEnever evaluated
0
241 alphaAnd &= bits[0];-
242 bits += 3;-
243 }
never executed: end of block
0
244 has_alpha_pixels = (alphaAnd != 0xff);-
245 bits = end_bits;-
246 end_bits += bytes_per_line;-
247 }
never executed: end of block
0
248 } break;
never executed: break;
0
249-
250 case QImage::Format_ARGB6666_Premultiplied: {
never executed: case QImage::Format_ARGB6666_Premultiplied:
0
251 const uchar *bits = data;-
252 const uchar *end_bits = data + bytes_per_line;-
253-
254 for (int y=0; y<height && !has_alpha_pixels; ++y) {
y<heightDescription
TRUEnever evaluated
FALSEnever evaluated
!has_alpha_pixelsDescription
TRUEnever evaluated
FALSEnever evaluated
0
255 uchar alphaAnd = 0xfc;-
256 while (bits < end_bits) {
bits < end_bitsDescription
TRUEnever evaluated
FALSEnever evaluated
0
257 alphaAnd &= bits[0];-
258 bits += 3;-
259 }
never executed: end of block
0
260 has_alpha_pixels = (alphaAnd != 0xfc);-
261 bits = end_bits;-
262 end_bits += bytes_per_line;-
263 }
never executed: end of block
0
264 } break;
never executed: break;
0
265-
266 case QImage::Format_ARGB4444_Premultiplied: {
never executed: case QImage::Format_ARGB4444_Premultiplied:
0
267 const uchar *bits = data;-
268 for (int y=0; y<height && !has_alpha_pixels; ++y) {
y<heightDescription
TRUEnever evaluated
FALSEnever evaluated
!has_alpha_pixelsDescription
TRUEnever evaluated
FALSEnever evaluated
0
269 ushort alphaAnd = 0xf000;-
270 for (int x=0; x<width; ++x)
x<widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
271 alphaAnd &= reinterpret_cast<const ushort*>(bits)[x];
never executed: alphaAnd &= reinterpret_cast<const ushort*>(bits)[x];
0
272 has_alpha_pixels = (alphaAnd != 0xf000);-
273 bits += bytes_per_line;-
274 }
never executed: end of block
0
275 } break;
never executed: break;
0
276-
277 case QImage::Format_RGB32:
never executed: case QImage::Format_RGB32:
0
278 case QImage::Format_RGB16:
never executed: case QImage::Format_RGB16:
0
279 case QImage::Format_RGB444:
never executed: case QImage::Format_RGB444:
0
280 case QImage::Format_RGB555:
never executed: case QImage::Format_RGB555:
0
281 case QImage::Format_RGB666:
never executed: case QImage::Format_RGB666:
0
282 case QImage::Format_RGB888:
never executed: case QImage::Format_RGB888:
0
283 case QImage::Format_RGBX8888:
never executed: case QImage::Format_RGBX8888:
0
284 case QImage::Format_BGR30:
never executed: case QImage::Format_BGR30:
0
285 case QImage::Format_RGB30:
never executed: case QImage::Format_RGB30:
0
286 case QImage::Format_Grayscale8:
never executed: case QImage::Format_Grayscale8:
0
287 break;
never executed: break;
0
288 case QImage::Format_Invalid:
never executed: case QImage::Format_Invalid:
0
289 case QImage::NImageFormats:
never executed: case QImage::NImageFormats:
0
290 Q_UNREACHABLE();-
291 break;
never executed: break;
0
292 }-
293-
294 return has_alpha_pixels;
never executed: return has_alpha_pixels;
0
295}-
296#if defined(_M_ARM)-
297#pragma optimize("", on)-
298#endif-
299-
300/*!-
301 \class QImage-
302-
303 \inmodule QtGui-
304 \ingroup painting-
305 \ingroup shared-
306-
307 \reentrant-
308-
309 \brief The QImage class provides a hardware-independent image-
310 representation that allows direct access to the pixel data, and-
311 can be used as a paint device.-
312-
313 Qt provides four classes for handling image data: QImage, QPixmap,-
314 QBitmap and QPicture. QImage is designed and optimized for I/O,-
315 and for direct pixel access and manipulation, while QPixmap is-
316 designed and optimized for showing images on screen. QBitmap is-
317 only a convenience class that inherits QPixmap, ensuring a-
318 depth of 1. Finally, the QPicture class is a paint device that-
319 records and replays QPainter commands.-
320-
321 Because QImage is a QPaintDevice subclass, QPainter can be used to-
322 draw directly onto images. When using QPainter on a QImage, the-
323 painting can be performed in another thread than the current GUI-
324 thread.-
325-
326 The QImage class supports several image formats described by the-
327 \l Format enum. These include monochrome, 8-bit, 32-bit and-
328 alpha-blended images which are available in all versions of Qt-
329 4.x.-
330-
331 QImage provides a collection of functions that can be used to-
332 obtain a variety of information about the image. There are also-
333 several functions that enables transformation of the image.-
334-
335 QImage objects can be passed around by value since the QImage-
336 class uses \l{Implicit Data Sharing}{implicit data-
337 sharing}. QImage objects can also be streamed and compared.-
338-
339 \note If you would like to load QImage objects in a static build of Qt,-
340 refer to the \l{How to Create Qt Plugins}{Plugin HowTo}.-
341-
342 \warning Painting on a QImage with the format-
343 QImage::Format_Indexed8 is not supported.-
344-
345 \tableofcontents-
346-
347 \section1 Reading and Writing Image Files-
348-
349 QImage provides several ways of loading an image file: The file-
350 can be loaded when constructing the QImage object, or by using the-
351 load() or loadFromData() functions later on. QImage also provides-
352 the static fromData() function, constructing a QImage from the-
353 given data. When loading an image, the file name can either refer-
354 to an actual file on disk or to one of the application's embedded-
355 resources. See \l{The Qt Resource System} overview for details-
356 on how to embed images and other resource files in the-
357 application's executable.-
358-
359 Simply call the save() function to save a QImage object.-
360-
361 The complete list of supported file formats are available through-
362 the QImageReader::supportedImageFormats() and-
363 QImageWriter::supportedImageFormats() functions. New file formats-
364 can be added as plugins. By default, Qt supports the following-
365 formats:-
366-
367 \table-
368 \header \li Format \li Description \li Qt's support-
369 \row \li BMP \li Windows Bitmap \li Read/write-
370 \row \li GIF \li Graphic Interchange Format (optional) \li Read-
371 \row \li JPG \li Joint Photographic Experts Group \li Read/write-
372 \row \li JPEG \li Joint Photographic Experts Group \li Read/write-
373 \row \li PNG \li Portable Network Graphics \li Read/write-
374 \row \li PBM \li Portable Bitmap \li Read-
375 \row \li PGM \li Portable Graymap \li Read-
376 \row \li PPM \li Portable Pixmap \li Read/write-
377 \row \li XBM \li X11 Bitmap \li Read/write-
378 \row \li XPM \li X11 Pixmap \li Read/write-
379 \endtable-
380-
381 \section1 Image Information-
382-
383 QImage provides a collection of functions that can be used to-
384 obtain a variety of information about the image:-
385-
386 \table-
387 \header-
388 \li \li Available Functions-
389-
390 \row-
391 \li Geometry-
392 \li-
393-
394 The size(), width(), height(), dotsPerMeterX(), and-
395 dotsPerMeterY() functions provide information about the image size-
396 and aspect ratio.-
397-
398 The rect() function returns the image's enclosing rectangle. The-
399 valid() function tells if a given pair of coordinates is within-
400 this rectangle. The offset() function returns the number of pixels-
401 by which the image is intended to be offset by when positioned-
402 relative to other images, which also can be manipulated using the-
403 setOffset() function.-
404-
405 \row-
406 \li Colors-
407 \li-
408-
409 The color of a pixel can be retrieved by passing its coordinates-
410 to the pixel() function. The pixel() function returns the color-
411 as a QRgb value indepedent of the image's format.-
412-
413 In case of monochrome and 8-bit images, the colorCount() and-
414 colorTable() functions provide information about the color-
415 components used to store the image data: The colorTable() function-
416 returns the image's entire color table. To obtain a single entry,-
417 use the pixelIndex() function to retrieve the pixel index for a-
418 given pair of coordinates, then use the color() function to-
419 retrieve the color. Note that if you create an 8-bit image-
420 manually, you have to set a valid color table on the image as-
421 well.-
422-
423 The hasAlphaChannel() function tells if the image's format-
424 respects the alpha channel, or not. The allGray() and-
425 isGrayscale() functions tell whether an image's colors are all-
426 shades of gray.-
427-
428 See also the \l {QImage#Pixel Manipulation}{Pixel Manipulation}-
429 and \l {QImage#Image Transformations}{Image Transformations}-
430 sections.-
431-
432 \row-
433 \li Text-
434 \li-
435-
436 The text() function returns the image text associated with the-
437 given text key. An image's text keys can be retrieved using the-
438 textKeys() function. Use the setText() function to alter an-
439 image's text.-
440-
441 \row-
442 \li Low-level information-
443 \li-
444-
445 The depth() function returns the depth of the image. The supported-
446 depths are 1 (monochrome), 8, 16, 24 and 32 bits. The-
447 bitPlaneCount() function tells how many of those bits that are-
448 used. For more information see the-
449 \l {QImage#Image Formats}{Image Formats} section.-
450-
451 The format(), bytesPerLine(), and byteCount() functions provide-
452 low-level information about the data stored in the image.-
453-
454 The cacheKey() function returns a number that uniquely-
455 identifies the contents of this QImage object.-
456 \endtable-
457-
458 \section1 Pixel Manipulation-
459-
460 The functions used to manipulate an image's pixels depend on the-
461 image format. The reason is that monochrome and 8-bit images are-
462 index-based and use a color lookup table, while 32-bit images-
463 store ARGB values directly. For more information on image formats,-
464 see the \l {Image Formats} section.-
465-
466 In case of a 32-bit image, the setPixel() function can be used to-
467 alter the color of the pixel at the given coordinates to any other-
468 color specified as an ARGB quadruplet. To make a suitable QRgb-
469 value, use the qRgb() (adding a default alpha component to the-
470 given RGB values, i.e. creating an opaque color) or qRgba()-
471 function. For example:-
472-
473 \table-
474 \header-
475 \li {2,1}32-bit-
476 \row-
477 \li \inlineimage qimage-32bit_scaled.png-
478 \li-
479 \snippet code/src_gui_image_qimage.cpp 0-
480 \endtable-
481-
482 In case of a 8-bit and monchrome images, the pixel value is only-
483 an index from the image's color table. So the setPixel() function-
484 can only be used to alter the color of the pixel at the given-
485 coordinates to a predefined color from the image's color table,-
486 i.e. it can only change the pixel's index value. To alter or add a-
487 color to an image's color table, use the setColor() function.-
488-
489 An entry in the color table is an ARGB quadruplet encoded as an-
490 QRgb value. Use the qRgb() and qRgba() functions to make a-
491 suitable QRgb value for use with the setColor() function. For-
492 example:-
493-
494 \table-
495 \header-
496 \li {2,1} 8-bit-
497 \row-
498 \li \inlineimage qimage-8bit_scaled.png-
499 \li-
500 \snippet code/src_gui_image_qimage.cpp 1-
501 \endtable-
502-
503 For images with more than 8-bit per color-channel. The methods-
504 setPixelColor() and pixelColor() can be used to set and get-
505 with QColor values.-
506-
507 QImage also provide the scanLine() function which returns a-
508 pointer to the pixel data at the scanline with the given index,-
509 and the bits() function which returns a pointer to the first pixel-
510 data (this is equivalent to \c scanLine(0)).-
511-
512 \section1 Image Formats-
513-
514 Each pixel stored in a QImage is represented by an integer. The-
515 size of the integer varies depending on the format. QImage-
516 supports several image formats described by the \l Format-
517 enum.-
518-
519 Monochrome images are stored using 1-bit indexes into a color table-
520 with at most two colors. There are two different types of-
521 monochrome images: big endian (MSB first) or little endian (LSB-
522 first) bit order.-
523-
524 8-bit images are stored using 8-bit indexes into a color table,-
525 i.e. they have a single byte per pixel. The color table is a-
526 QVector<QRgb>, and the QRgb typedef is equivalent to an unsigned-
527 int containing an ARGB quadruplet on the format 0xAARRGGBB.-
528-
529 32-bit images have no color table; instead, each pixel contains an-
530 QRgb value. There are three different types of 32-bit images-
531 storing RGB (i.e. 0xffRRGGBB), ARGB and premultiplied ARGB-
532 values respectively. In the premultiplied format the red, green,-
533 and blue channels are multiplied by the alpha component divided by-
534 255.-
535-
536 An image's format can be retrieved using the format()-
537 function. Use the convertToFormat() functions to convert an image-
538 into another format. The allGray() and isGrayscale() functions-
539 tell whether a color image can safely be converted to a grayscale-
540 image.-
541-
542 \section1 Image Transformations-
543-
544 QImage supports a number of functions for creating a new image-
545 that is a transformed version of the original: The-
546 createAlphaMask() function builds and returns a 1-bpp mask from-
547 the alpha buffer in this image, and the createHeuristicMask()-
548 function creates and returns a 1-bpp heuristic mask for this-
549 image. The latter function works by selecting a color from one of-
550 the corners, then chipping away pixels of that color starting at-
551 all the edges.-
552-
553 The mirrored() function returns a mirror of the image in the-
554 desired direction, the scaled() returns a copy of the image scaled-
555 to a rectangle of the desired measures, and the rgbSwapped() function-
556 constructs a BGR image from a RGB image.-
557-
558 The scaledToWidth() and scaledToHeight() functions return scaled-
559 copies of the image.-
560-
561 The transformed() function returns a copy of the image that is-
562 transformed with the given transformation matrix and-
563 transformation mode: Internally, the transformation matrix is-
564 adjusted to compensate for unwanted translation,-
565 i.e. transformed() returns the smallest image containing all-
566 transformed points of the original image. The static trueMatrix()-
567 function returns the actual matrix used for transforming the-
568 image.-
569-
570 There are also functions for changing attributes of an image-
571 in-place:-
572-
573 \table-
574 \header \li Function \li Description-
575 \row-
576 \li setDotsPerMeterX()-
577 \li Defines the aspect ratio by setting the number of pixels that fit-
578 horizontally in a physical meter.-
579 \row-
580 \li setDotsPerMeterY()-
581 \li Defines the aspect ratio by setting the number of pixels that fit-
582 vertically in a physical meter.-
583 \row-
584 \li fill()-
585 \li Fills the entire image with the given pixel value.-
586 \row-
587 \li invertPixels()-
588 \li Inverts all pixel values in the image using the given InvertMode value.-
589 \row-
590 \li setColorTable()-
591 \li Sets the color table used to translate color indexes. Only-
592 monochrome and 8-bit formats.-
593 \row-
594 \li setColorCount()-
595 \li Resizes the color table. Only monochrome and 8-bit formats.-
596-
597 \endtable-
598-
599 \target qimage-legalese-
600 \section1 Legal Information-
601-
602 For smooth scaling, the transformed() functions use code based on-
603 smooth scaling algorithm by Daniel M. Duley.-
604-
605 \badcode-
606 Copyright (C) 2004, 2005 Daniel M. Duley-
607-
608 Redistribution and use in source and binary forms, with or without-
609 modification, are permitted provided that the following conditions-
610 are met:-
611-
612 1. Redistributions of source code must retain the above copyright-
613 notice, this list of conditions and the following disclaimer.-
614 2. Redistributions in binary form must reproduce the above copyright-
615 notice, this list of conditions and the following disclaimer in the-
616 documentation and/or other materials provided with the distribution.-
617-
618 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR-
619 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES-
620 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.-
621 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,-
622 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT-
623 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-
624 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-
625 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-
626 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF-
627 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.-
628 \endcode-
629-
630 \sa QImageReader, QImageWriter, QPixmap, QSvgRenderer, {Image Composition Example},-
631 {Image Viewer Example}, {Scribble Example}, {Pixelator Example}-
632*/-
633-
634/*!-
635 \fn QImage::QImage(QImage &&other)-
636-
637 Move-constructs a QImage instance, making it point at the same-
638 object that \a other was pointing to.-
639-
640 \since 5.2-
641*/-
642-
643/*!-
644 \fn QImage &QImage::operator=(QImage &&other)-
645-
646 Move-assigns \a other to this QImage instance.-
647-
648 \since 5.2-
649*/-
650-
651/*!-
652 \typedef QImageCleanupFunction-
653 \relates QImage-
654 \since 5.0-
655-
656 A function with the following signature that can be used to-
657 implement basic image memory management:-
658-
659 \code-
660 void myImageCleanupHandler(void *info);-
661 \endcode-
662*/-
663-
664/*!-
665 \enum QImage::InvertMode-
666-
667 This enum type is used to describe how pixel values should be-
668 inverted in the invertPixels() function.-
669-
670 \value InvertRgb Invert only the RGB values and leave the alpha-
671 channel unchanged.-
672-
673 \value InvertRgba Invert all channels, including the alpha channel.-
674-
675 \sa invertPixels()-
676*/-
677-
678/*!-
679 \enum QImage::Format-
680-
681 The following image formats are available in Qt. Values from Format_ARGB8565_Premultiplied-
682 to Format_ARGB4444_Premultiplied were added in Qt 4.4. Values Format_RGBX8888, Format_RGBA8888-
683 and Format_RGBA8888_Premultiplied were added in Qt 5.2. Values Format_BGR30, Format_A2BGR30_Premultiplied,-
684 Format_RGB30, Format_A2RGB30_Premultiplied were added in Qt 5.4. Format_Alpha8 and Format_Grayscale8-
685 were added in Qt 5.5.-
686 See the notes after the table.-
687-
688 \value Format_Invalid The image is invalid.-
689 \value Format_Mono The image is stored using 1-bit per pixel. Bytes are-
690 packed with the most significant bit (MSB) first.-
691 \value Format_MonoLSB The image is stored using 1-bit per pixel. Bytes are-
692 packed with the less significant bit (LSB) first.-
693-
694 \value Format_Indexed8 The image is stored using 8-bit indexes-
695 into a colormap.-
696-
697 \value Format_RGB32 The image is stored using a 32-bit RGB format (0xffRRGGBB).-
698-
699 \value Format_ARGB32 The image is stored using a 32-bit ARGB-
700 format (0xAARRGGBB).-
701-
702 \value Format_ARGB32_Premultiplied The image is stored using a premultiplied 32-bit-
703 ARGB format (0xAARRGGBB), i.e. the red,-
704 green, and blue channels are multiplied-
705 by the alpha component divided by 255. (If RR, GG, or BB-
706 has a higher value than the alpha channel, the results are-
707 undefined.) Certain operations (such as image composition-
708 using alpha blending) are faster using premultiplied ARGB32-
709 than with plain ARGB32.-
710-
711 \value Format_RGB16 The image is stored using a 16-bit RGB format (5-6-5).-
712-
713 \value Format_ARGB8565_Premultiplied The image is stored using a-
714 premultiplied 24-bit ARGB format (8-5-6-5).-
715 \value Format_RGB666 The image is stored using a 24-bit RGB format (6-6-6).-
716 The unused most significant bits is always zero.-
717 \value Format_ARGB6666_Premultiplied The image is stored using a-
718 premultiplied 24-bit ARGB format (6-6-6-6).-
719 \value Format_RGB555 The image is stored using a 16-bit RGB format (5-5-5).-
720 The unused most significant bit is always zero.-
721 \value Format_ARGB8555_Premultiplied The image is stored using a-
722 premultiplied 24-bit ARGB format (8-5-5-5).-
723 \value Format_RGB888 The image is stored using a 24-bit RGB format (8-8-8).-
724 \value Format_RGB444 The image is stored using a 16-bit RGB format (4-4-4).-
725 The unused bits are always zero.-
726 \value Format_ARGB4444_Premultiplied The image is stored using a-
727 premultiplied 16-bit ARGB format (4-4-4-4).-
728 \value Format_RGBX8888 The image is stored using a 32-bit byte-ordered RGB(x) format (8-8-8-8).-
729 This is the same as the Format_RGBA8888 except alpha must always be 255.-
730 \value Format_RGBA8888 The image is stored using a 32-bit byte-ordered RGBA format (8-8-8-8).-
731 Unlike ARGB32 this is a byte-ordered format, which means the 32bit-
732 encoding differs between big endian and little endian architectures,-
733 being respectively (0xRRGGBBAA) and (0xAABBGGRR). The order of the colors-
734 is the same on any architecture if read as bytes 0xRR,0xGG,0xBB,0xAA.-
735 \value Format_RGBA8888_Premultiplied The image is stored using a-
736 premultiplied 32-bit byte-ordered RGBA format (8-8-8-8).-
737 \value Format_BGR30 The image is stored using a 32-bit BGR format (x-10-10-10).-
738 \value Format_A2BGR30_Premultiplied The image is stored using a 32-bit premultiplied ABGR format (2-10-10-10).-
739 \value Format_RGB30 The image is stored using a 32-bit RGB format (x-10-10-10).-
740 \value Format_A2RGB30_Premultiplied The image is stored using a 32-bit premultiplied ARGB format (2-10-10-10).-
741 \value Format_Alpha8 The image is stored using an 8-bit alpha only format.-
742 \value Format_Grayscale8 The image is stored using an 8-bit grayscale format.-
743-
744 \note Drawing into a QImage with QImage::Format_Indexed8 is not-
745 supported.-
746-
747 \note Do not render into ARGB32 images using QPainter. Using-
748 QImage::Format_ARGB32_Premultiplied is significantly faster.-
749-
750 \note Formats with more than 8 bit per color channel will only be processed by the raster engine using 8 bit-
751 per color.-
752-
753 \sa format(), convertToFormat()-
754*/-
755-
756/*****************************************************************************-
757 QImage member functions-
758 *****************************************************************************/-
759-
760/*!-
761 Constructs a null image.-
762-
763 \sa isNull()-
764*/-
765-
766QImage::QImage() Q_DECL_NOEXCEPT-
767 : QPaintDevice()-
768{-
769 d = 0;-
770}
never executed: end of block
0
771-
772/*!-
773 Constructs an image with the given \a width, \a height and \a-
774 format.-
775-
776 A \l{isNull()}{null} image will be returned if memory cannot be allocated.-
777-
778 \warning This will create a QImage with uninitialized data. Call-
779 fill() to fill the image with an appropriate pixel value before-
780 drawing onto it with QPainter.-
781*/-
782QImage::QImage(int width, int height, Format format)-
783 : QPaintDevice()-
784{-
785 d = QImageData::create(QSize(width, height), format);-
786}
never executed: end of block
0
787-
788/*!-
789 Constructs an image with the given \a size and \a format.-
790-
791 A \l{isNull()}{null} image is returned if memory cannot be allocated.-
792-
793 \warning This will create a QImage with uninitialized data. Call-
794 fill() to fill the image with an appropriate pixel value before-
795 drawing onto it with QPainter.-
796*/-
797QImage::QImage(const QSize &size, Format format)-
798 : QPaintDevice()-
799{-
800 d = QImageData::create(size, format);-
801}
never executed: end of block
0
802-
803-
804-
805QImageData *QImageData::create(uchar *data, int width, int height, int bpl, QImage::Format format, bool readOnly, QImageCleanupFunction cleanupFunction, void *cleanupInfo)-
806{-
807 QImageData *d = 0;-
808-
809 if (format == QImage::Format_Invalid)
format == QIma...Format_InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
0
810 return d;
never executed: return d;
0
811-
812 const int depth = qt_depthForFormat(format);-
813 const int calc_bytes_per_line = ((width * depth + 31)/32) * 4;-
814 const int min_bytes_per_line = (width * depth + 7)/8;-
815-
816 if (bpl <= 0)
bpl <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
817 bpl = calc_bytes_per_line;
never executed: bpl = calc_bytes_per_line;
0
818-
819 if (width <= 0 || height <= 0 || !data
width <= 0Description
TRUEnever evaluated
FALSEnever evaluated
height <= 0Description
TRUEnever evaluated
FALSEnever evaluated
!dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
820 || INT_MAX/sizeof(uchar *) < uint(height)
2147483647/siz...< uint(height)Description
TRUEnever evaluated
FALSEnever evaluated
0
821 || INT_MAX/uint(depth) < uint(width)
2147483647/uin... < uint(width)Description
TRUEnever evaluated
FALSEnever evaluated
0
822 || bpl <= 0
bpl <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
823 || bpl < min_bytes_per_line
bpl < min_bytes_per_lineDescription
TRUEnever evaluated
FALSEnever evaluated
0
824 || INT_MAX/uint(bpl) < uint(height))
2147483647/uin...< uint(height)Description
TRUEnever evaluated
FALSEnever evaluated
0
825 return d; // invalid parameter(s)
never executed: return d;
0
826-
827 d = new QImageData;-
828 d->ref.ref();-
829-
830 d->own_data = false;-
831 d->ro_data = readOnly;-
832 d->data = data;-
833 d->width = width;-
834 d->height = height;-
835 d->depth = depth;-
836 d->format = format;-
837-
838 d->bytes_per_line = bpl;-
839 d->nbytes = d->bytes_per_line * height;-
840-
841 d->cleanupFunction = cleanupFunction;-
842 d->cleanupInfo = cleanupInfo;-
843-
844 return d;
never executed: return d;
0
845}-
846-
847/*!-
848 Constructs an image with the given \a width, \a height and \a-
849 format, that uses an existing memory buffer, \a data. The \a width-
850 and \a height must be specified in pixels, \a data must be 32-bit aligned,-
851 and each scanline of data in the image must also be 32-bit aligned.-
852-
853 The buffer must remain valid throughout the life of the QImage and-
854 all copies that have not been modified or otherwise detached from-
855 the original buffer. The image does not delete the buffer at destruction.-
856 You can provide a function pointer \a cleanupFunction along with an-
857 extra pointer \a cleanupInfo that will be called when the last copy-
858 is destroyed.-
859-
860 If \a format is an indexed color format, the image color table is-
861 initially empty and must be sufficiently expanded with-
862 setColorCount() or setColorTable() before the image is used.-
863*/-
864QImage::QImage(uchar* data, int width, int height, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo)-
865 : QPaintDevice()-
866{-
867 d = QImageData::create(data, width, height, 0, format, false, cleanupFunction, cleanupInfo);-
868}
never executed: end of block
0
869-
870/*!-
871 Constructs an image with the given \a width, \a height and \a-
872 format, that uses an existing read-only memory buffer, \a-
873 data. The \a width and \a height must be specified in pixels, \a-
874 data must be 32-bit aligned, and each scanline of data in the-
875 image must also be 32-bit aligned.-
876-
877 The buffer must remain valid throughout the life of the QImage and-
878 all copies that have not been modified or otherwise detached from-
879 the original buffer. The image does not delete the buffer at destruction.-
880 You can provide a function pointer \a cleanupFunction along with an-
881 extra pointer \a cleanupInfo that will be called when the last copy-
882 is destroyed.-
883-
884 If \a format is an indexed color format, the image color table is-
885 initially empty and must be sufficiently expanded with-
886 setColorCount() or setColorTable() before the image is used.-
887-
888 Unlike the similar QImage constructor that takes a non-const data buffer,-
889 this version will never alter the contents of the buffer. For example,-
890 calling QImage::bits() will return a deep copy of the image, rather than-
891 the buffer passed to the constructor. This allows for the efficiency of-
892 constructing a QImage from raw data, without the possibility of the raw-
893 data being changed.-
894*/-
895QImage::QImage(const uchar* data, int width, int height, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo)-
896 : QPaintDevice()-
897{-
898 d = QImageData::create(const_cast<uchar*>(data), width, height, 0, format, true, cleanupFunction, cleanupInfo);-
899}
never executed: end of block
0
900-
901/*!-
902 Constructs an image with the given \a width, \a height and \a-
903 format, that uses an existing memory buffer, \a data. The \a width-
904 and \a height must be specified in pixels. \a bytesPerLine-
905 specifies the number of bytes per line (stride).-
906-
907 The buffer must remain valid throughout the life of the QImage and-
908 all copies that have not been modified or otherwise detached from-
909 the original buffer. The image does not delete the buffer at destruction.-
910 You can provide a function pointer \a cleanupFunction along with an-
911 extra pointer \a cleanupInfo that will be called when the last copy-
912 is destroyed.-
913-
914 If \a format is an indexed color format, the image color table is-
915 initially empty and must be sufficiently expanded with-
916 setColorCount() or setColorTable() before the image is used.-
917*/-
918QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo)-
919 :QPaintDevice()-
920{-
921 d = QImageData::create(data, width, height, bytesPerLine, format, false, cleanupFunction, cleanupInfo);-
922}
never executed: end of block
0
923-
924-
925/*!-
926 Constructs an image with the given \a width, \a height and \a-
927 format, that uses an existing memory buffer, \a data. The \a width-
928 and \a height must be specified in pixels. \a bytesPerLine-
929 specifies the number of bytes per line (stride).-
930-
931 The buffer must remain valid throughout the life of the QImage and-
932 all copies that have not been modified or otherwise detached from-
933 the original buffer. The image does not delete the buffer at destruction.-
934 You can provide a function pointer \a cleanupFunction along with an-
935 extra pointer \a cleanupInfo that will be called when the last copy-
936 is destroyed.-
937-
938 If \a format is an indexed color format, the image color table is-
939 initially empty and must be sufficiently expanded with-
940 setColorCount() or setColorTable() before the image is used.-
941-
942 Unlike the similar QImage constructor that takes a non-const data buffer,-
943 this version will never alter the contents of the buffer. For example,-
944 calling QImage::bits() will return a deep copy of the image, rather than-
945 the buffer passed to the constructor. This allows for the efficiency of-
946 constructing a QImage from raw data, without the possibility of the raw-
947 data being changed.-
948*/-
949-
950QImage::QImage(const uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo)-
951 :QPaintDevice()-
952{-
953 d = QImageData::create(const_cast<uchar*>(data), width, height, bytesPerLine, format, true, cleanupFunction, cleanupInfo);-
954}
never executed: end of block
0
955-
956/*!-
957 Constructs an image and tries to load the image from the file with-
958 the given \a fileName.-
959-
960 The loader attempts to read the image using the specified \a-
961 format. If the \a format is not specified (which is the default),-
962 the loader probes the file for a header to guess the file format.-
963-
964 If the loading of the image failed, this object is a null image.-
965-
966 The file name can either refer to an actual file on disk or to one-
967 of the application's embedded resources. See the-
968 \l{resources.html}{Resource System} overview for details on how to-
969 embed images and other resource files in the application's-
970 executable.-
971-
972 \sa isNull(), {QImage#Reading and Writing Image Files}{Reading and Writing Image Files}-
973*/-
974-
975QImage::QImage(const QString &fileName, const char *format)-
976 : QPaintDevice()-
977{-
978 d = 0;-
979 load(fileName, format);-
980}
never executed: end of block
0
981-
982#ifndef QT_NO_IMAGEFORMAT_XPM-
983extern bool qt_read_xpm_image_or_array(QIODevice *device, const char * const *source, QImage &image);-
984-
985/*!-
986 Constructs an image from the given \a xpm image.-
987-
988 Make sure that the image is a valid XPM image. Errors are silently-
989 ignored.-
990-
991 Note that it's possible to squeeze the XPM variable a little bit-
992 by using an unusual declaration:-
993-
994 \snippet code/src_gui_image_qimage.cpp 2-
995-
996 The extra \c const makes the entire definition read-only, which is-
997 slightly more efficient (e.g., when the code is in a shared-
998 library) and able to be stored in ROM with the application.-
999*/-
1000-
1001QImage::QImage(const char * const xpm[])-
1002 : QPaintDevice()-
1003{-
1004 d = 0;-
1005 if (!xpm)
!xpmDescription
TRUEnever evaluated
FALSEnever evaluated
0
1006 return;
never executed: return;
0
1007 if (!qt_read_xpm_image_or_array(0, xpm, *this))
!qt_read_xpm_i...0, xpm, *this)Description
TRUEnever evaluated
FALSEnever evaluated
0
1008 // Issue: Warning because the constructor may be ambigious-
1009 qWarning("QImage::QImage(), XPM is not supported");
never executed: QMessageLogger(__FILE__, 1009, __PRETTY_FUNCTION__).warning("QImage::QImage(), XPM is not supported");
0
1010}
never executed: end of block
0
1011#endif // QT_NO_IMAGEFORMAT_XPM-
1012-
1013/*!-
1014 Constructs a shallow copy of the given \a image.-
1015-
1016 For more information about shallow copies, see the \l {Implicit-
1017 Data Sharing} documentation.-
1018-
1019 \sa copy()-
1020*/-
1021-
1022QImage::QImage(const QImage &image)-
1023 : QPaintDevice()-
1024{-
1025 if (image.paintingActive() || isLocked(image.d)) {
image.paintingActive()Description
TRUEnever evaluated
FALSEnever evaluated
isLocked(image.d)Description
TRUEnever evaluated
FALSEnever evaluated
0
1026 d = 0;-
1027 image.copy().swap(*this);-
1028 } else {
never executed: end of block
0
1029 d = image.d;-
1030 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1031 d->ref.ref();
never executed: d->ref.ref();
0
1032 }
never executed: end of block
0
1033}-
1034-
1035/*!-
1036 Destroys the image and cleans up.-
1037*/-
1038-
1039QImage::~QImage()-
1040{-
1041 if (d && !d->ref.deref())
dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
1042 delete d;
never executed: delete d;
0
1043}
never executed: end of block
0
1044-
1045/*!-
1046 Assigns a shallow copy of the given \a image to this image and-
1047 returns a reference to this image.-
1048-
1049 For more information about shallow copies, see the \l {Implicit-
1050 Data Sharing} documentation.-
1051-
1052 \sa copy(), QImage()-
1053*/-
1054-
1055QImage &QImage::operator=(const QImage &image)-
1056{-
1057 if (image.paintingActive() || isLocked(image.d)) {
image.paintingActive()Description
TRUEnever evaluated
FALSEnever evaluated
isLocked(image.d)Description
TRUEnever evaluated
FALSEnever evaluated
0
1058 operator=(image.copy());-
1059 } else {
never executed: end of block
0
1060 if (image.d)
image.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1061 image.d->ref.ref();
never executed: image.d->ref.ref();
0
1062 if (d && !d->ref.deref())
dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
1063 delete d;
never executed: delete d;
0
1064 d = image.d;-
1065 }
never executed: end of block
0
1066 return *this;
never executed: return *this;
0
1067}-
1068-
1069/*!-
1070 \fn void QImage::swap(QImage &other)-
1071 \since 4.8-
1072-
1073 Swaps image \a other with this image. This operation is very-
1074 fast and never fails.-
1075*/-
1076-
1077/*!-
1078 \internal-
1079*/-
1080int QImage::devType() const-
1081{-
1082 return QInternal::Image;
never executed: return QInternal::Image;
0
1083}-
1084-
1085/*!-
1086 Returns the image as a QVariant.-
1087*/-
1088QImage::operator QVariant() const-
1089{-
1090 return QVariant(QVariant::Image, this);
never executed: return QVariant(QVariant::Image, this);
0
1091}-
1092-
1093/*!-
1094 \internal-
1095-
1096 If multiple images share common data, this image makes a copy of-
1097 the data and detaches itself from the sharing mechanism, making-
1098 sure that this image is the only one referring to the data.-
1099-
1100 Nothing is done if there is just a single reference.-
1101-
1102 \sa copy(), isDetached(), {Implicit Data Sharing}-
1103*/-
1104void QImage::detach()-
1105{-
1106 if (d) {
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1107 if (d->is_cached && d->ref.load() == 1)
d->is_cachedDescription
TRUEnever evaluated
FALSEnever evaluated
d->ref.load() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1108 QImagePixmapCleanupHooks::executeImageHooks(cacheKey());
never executed: QImagePixmapCleanupHooks::executeImageHooks(cacheKey());
0
1109-
1110 if (d->ref.load() != 1 || d->ro_data)
d->ref.load() != 1Description
TRUEnever evaluated
FALSEnever evaluated
d->ro_dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
1111 *this = copy();
never executed: *this = copy();
0
1112-
1113 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1114 ++d->detach_no;
never executed: ++d->detach_no;
0
1115 }
never executed: end of block
0
1116}
never executed: end of block
0
1117-
1118-
1119static void copyMetadata(QImageData *dst, const QImageData *src)-
1120{-
1121 // Doesn't copy colortable and alpha_clut, or offset.-
1122 dst->dpmx = src->dpmx;-
1123 dst->dpmy = src->dpmy;-
1124 dst->devicePixelRatio = src->devicePixelRatio;-
1125 dst->text = src->text;-
1126}
never executed: end of block
0
1127-
1128/*!-
1129 \fn QImage QImage::copy(int x, int y, int width, int height) const-
1130 \overload-
1131-
1132 The returned image is copied from the position (\a x, \a y) in-
1133 this image, and will always have the given \a width and \a height.-
1134 In areas beyond this image, pixels are set to 0.-
1135-
1136*/-
1137-
1138/*!-
1139 \fn QImage QImage::copy(const QRect& rectangle) const-
1140-
1141 Returns a sub-area of the image as a new image.-
1142-
1143 The returned image is copied from the position (\a-
1144 {rectangle}.x(), \a{rectangle}.y()) in this image, and will always-
1145 have the size of the given \a rectangle.-
1146-
1147 In areas beyond this image, pixels are set to 0. For 32-bit RGB-
1148 images, this means black; for 32-bit ARGB images, this means-
1149 transparent black; for 8-bit images, this means the color with-
1150 index 0 in the color table which can be anything; for 1-bit-
1151 images, this means Qt::color0.-
1152-
1153 If the given \a rectangle is a null rectangle the entire image is-
1154 copied.-
1155-
1156 \sa QImage()-
1157*/-
1158QImage QImage::copy(const QRect& r) const-
1159{-
1160 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1161 return QImage();
never executed: return QImage();
0
1162-
1163 if (r.isNull()) {
r.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1164 QImage image(d->width, d->height, d->format);-
1165 if (image.isNull())
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1166 return image;
never executed: return image;
0
1167-
1168 // Qt for Embedded Linux can create images with non-default bpl-
1169 // make sure we don't crash.-
1170 if (image.d->nbytes != d->nbytes) {
image.d->nbytes != d->nbytesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1171 int bpl = qMin(bytesPerLine(), image.bytesPerLine());-
1172 for (int i = 0; i < height(); i++)
i < height()Description
TRUEnever evaluated
FALSEnever evaluated
0
1173 memcpy(image.scanLine(i), scanLine(i), bpl);
never executed: memcpy(image.scanLine(i), scanLine(i), bpl);
0
1174 } else
never executed: end of block
0
1175 memcpy(image.bits(), bits(), d->nbytes);
never executed: memcpy(image.bits(), bits(), d->nbytes);
0
1176 image.d->colortable = d->colortable;-
1177 image.d->offset = d->offset;-
1178 image.d->has_alpha_clut = d->has_alpha_clut;-
1179 copyMetadata(image.d, d);-
1180 return image;
never executed: return image;
0
1181 }-
1182-
1183 int x = r.x();-
1184 int y = r.y();-
1185 int w = r.width();-
1186 int h = r.height();-
1187-
1188 int dx = 0;-
1189 int dy = 0;-
1190 if (w <= 0 || h <= 0)
w <= 0Description
TRUEnever evaluated
FALSEnever evaluated
h <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1191 return QImage();
never executed: return QImage();
0
1192-
1193 QImage image(w, h, d->format);-
1194 if (image.isNull())
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1195 return image;
never executed: return image;
0
1196-
1197 if (x < 0 || y < 0 || x + w > d->width || y + h > d->height) {
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
x + w > d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
y + h > d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1198 // bitBlt will not cover entire image - clear it.-
1199 image.fill(0);-
1200 if (x < 0) {
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1201 dx = -x;-
1202 x = 0;-
1203 }
never executed: end of block
0
1204 if (y < 0) {
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1205 dy = -y;-
1206 y = 0;-
1207 }
never executed: end of block
0
1208 }
never executed: end of block
0
1209-
1210 image.d->colortable = d->colortable;-
1211-
1212 int pixels_to_copy = qMax(w - dx, 0);-
1213 if (x > d->width)
x > d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1214 pixels_to_copy = 0;
never executed: pixels_to_copy = 0;
0
1215 else if (pixels_to_copy > d->width - x)
pixels_to_copy > d->width - xDescription
TRUEnever evaluated
FALSEnever evaluated
0
1216 pixels_to_copy = d->width - x;
never executed: pixels_to_copy = d->width - x;
0
1217 int lines_to_copy = qMax(h - dy, 0);-
1218 if (y > d->height)
y > d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1219 lines_to_copy = 0;
never executed: lines_to_copy = 0;
0
1220 else if (lines_to_copy > d->height - y)
lines_to_copy > d->height - yDescription
TRUEnever evaluated
FALSEnever evaluated
0
1221 lines_to_copy = d->height - y;
never executed: lines_to_copy = d->height - y;
0
1222-
1223 bool byteAligned = true;-
1224 if (d->format == Format_Mono || d->format == Format_MonoLSB)
d->format == Format_MonoDescription
TRUEnever evaluated
FALSEnever evaluated
d->format == Format_MonoLSBDescription
TRUEnever evaluated
FALSEnever evaluated
0
1225 byteAligned = !(dx & 7) && !(x & 7) && !(pixels_to_copy & 7);
never executed: byteAligned = !(dx & 7) && !(x & 7) && !(pixels_to_copy & 7);
!(dx & 7)Description
TRUEnever evaluated
FALSEnever evaluated
!(x & 7)Description
TRUEnever evaluated
FALSEnever evaluated
!(pixels_to_copy & 7)Description
TRUEnever evaluated
FALSEnever evaluated
0
1226-
1227 if (byteAligned) {
byteAlignedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1228 const uchar *src = d->data + ((x * d->depth) >> 3) + y * d->bytes_per_line;-
1229 uchar *dest = image.d->data + ((dx * d->depth) >> 3) + dy * image.d->bytes_per_line;-
1230 const int bytes_to_copy = (pixels_to_copy * d->depth) >> 3;-
1231 for (int i = 0; i < lines_to_copy; ++i) {
i < lines_to_copyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1232 memcpy(dest, src, bytes_to_copy);-
1233 src += d->bytes_per_line;-
1234 dest += image.d->bytes_per_line;-
1235 }
never executed: end of block
0
1236 } else if (d->format == Format_Mono) {
never executed: end of block
d->format == Format_MonoDescription
TRUEnever evaluated
FALSEnever evaluated
0
1237 const uchar *src = d->data + y * d->bytes_per_line;-
1238 uchar *dest = image.d->data + dy * image.d->bytes_per_line;-
1239 for (int i = 0; i < lines_to_copy; ++i) {
i < lines_to_copyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1240 for (int j = 0; j < pixels_to_copy; ++j) {
j < pixels_to_copyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1241 if (src[(x + j) >> 3] & (0x80 >> ((x + j) & 7)))
src[(x + j) >>...((x + j) & 7))Description
TRUEnever evaluated
FALSEnever evaluated
0
1242 dest[(dx + j) >> 3] |= (0x80 >> ((dx + j) & 7));
never executed: dest[(dx + j) >> 3] |= (0x80 >> ((dx + j) & 7));
0
1243 else-
1244 dest[(dx + j) >> 3] &= ~(0x80 >> ((dx + j) & 7));
never executed: dest[(dx + j) >> 3] &= ~(0x80 >> ((dx + j) & 7));
0
1245 }-
1246 src += d->bytes_per_line;-
1247 dest += image.d->bytes_per_line;-
1248 }
never executed: end of block
0
1249 } else { // Format_MonoLSB
never executed: end of block
0
1250 Q_ASSERT(d->format == Format_MonoLSB);-
1251 const uchar *src = d->data + y * d->bytes_per_line;-
1252 uchar *dest = image.d->data + dy * image.d->bytes_per_line;-
1253 for (int i = 0; i < lines_to_copy; ++i) {
i < lines_to_copyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1254 for (int j = 0; j < pixels_to_copy; ++j) {
j < pixels_to_copyDescription
TRUEnever evaluated
FALSEnever evaluated
0
1255 if (src[(x + j) >> 3] & (0x1 << ((x + j) & 7)))
src[(x + j) >>...((x + j) & 7))Description
TRUEnever evaluated
FALSEnever evaluated
0
1256 dest[(dx + j) >> 3] |= (0x1 << ((dx + j) & 7));
never executed: dest[(dx + j) >> 3] |= (0x1 << ((dx + j) & 7));
0
1257 else-
1258 dest[(dx + j) >> 3] &= ~(0x1 << ((dx + j) & 7));
never executed: dest[(dx + j) >> 3] &= ~(0x1 << ((dx + j) & 7));
0
1259 }-
1260 src += d->bytes_per_line;-
1261 dest += image.d->bytes_per_line;-
1262 }
never executed: end of block
0
1263 }
never executed: end of block
0
1264-
1265 copyMetadata(image.d, d);-
1266 image.d->offset = offset();-
1267 image.d->has_alpha_clut = d->has_alpha_clut;-
1268 return image;
never executed: return image;
0
1269}-
1270-
1271-
1272/*!-
1273 \fn bool QImage::isNull() const-
1274-
1275 Returns \c true if it is a null image, otherwise returns \c false.-
1276-
1277 A null image has all parameters set to zero and no allocated data.-
1278*/-
1279bool QImage::isNull() const-
1280{-
1281 return !d;
never executed: return !d;
0
1282}-
1283-
1284/*!-
1285 \fn int QImage::width() const-
1286-
1287 Returns the width of the image.-
1288-
1289 \sa {QImage#Image Information}{Image Information}-
1290*/-
1291int QImage::width() const-
1292{-
1293 return d ? d->width : 0;
never executed: return d ? d->width : 0;
0
1294}-
1295-
1296/*!-
1297 \fn int QImage::height() const-
1298-
1299 Returns the height of the image.-
1300-
1301 \sa {QImage#Image Information}{Image Information}-
1302*/-
1303int QImage::height() const-
1304{-
1305 return d ? d->height : 0;
never executed: return d ? d->height : 0;
0
1306}-
1307-
1308/*!-
1309 \fn QSize QImage::size() const-
1310-
1311 Returns the size of the image, i.e. its width() and height().-
1312-
1313 \sa {QImage#Image Information}{Image Information}-
1314*/-
1315QSize QImage::size() const-
1316{-
1317 return d ? QSize(d->width, d->height) : QSize(0, 0);
never executed: return d ? QSize(d->width, d->height) : QSize(0, 0);
0
1318}-
1319-
1320/*!-
1321 \fn QRect QImage::rect() const-
1322-
1323 Returns the enclosing rectangle (0, 0, width(), height()) of the-
1324 image.-
1325-
1326 \sa {QImage#Image Information}{Image Information}-
1327*/-
1328QRect QImage::rect() const-
1329{-
1330 return d ? QRect(0, 0, d->width, d->height) : QRect();
never executed: return d ? QRect(0, 0, d->width, d->height) : QRect();
0
1331}-
1332-
1333/*!-
1334 Returns the depth of the image.-
1335-
1336 The image depth is the number of bits used to store a single-
1337 pixel, also called bits per pixel (bpp).-
1338-
1339 The supported depths are 1, 8, 16, 24 and 32.-
1340-
1341 \sa bitPlaneCount(), convertToFormat(), {QImage#Image Formats}{Image Formats},-
1342 {QImage#Image Information}{Image Information}-
1343-
1344*/-
1345int QImage::depth() const-
1346{-
1347 return d ? d->depth : 0;
never executed: return d ? d->depth : 0;
0
1348}-
1349-
1350/*!-
1351 \obsolete-
1352 \fn int QImage::numColors() const-
1353-
1354 Returns the size of the color table for the image.-
1355-
1356 \sa setColorCount()-
1357*/-
1358-
1359/*!-
1360 \since 4.6-
1361 \fn int QImage::colorCount() const-
1362-
1363 Returns the size of the color table for the image.-
1364-
1365 Notice that colorCount() returns 0 for 32-bpp images because these-
1366 images do not use color tables, but instead encode pixel values as-
1367 ARGB quadruplets.-
1368-
1369 \sa setColorCount(), {QImage#Image Information}{Image Information}-
1370*/-
1371int QImage::colorCount() const-
1372{-
1373 return d ? d->colortable.size() : 0;
never executed: return d ? d->colortable.size() : 0;
0
1374}-
1375-
1376/*!-
1377 Sets the color table used to translate color indexes to QRgb-
1378 values, to the specified \a colors.-
1379-
1380 When the image is used, the color table must be large enough to-
1381 have entries for all the pixel/index values present in the image,-
1382 otherwise the results are undefined.-
1383-
1384 \sa colorTable(), setColor(), {QImage#Image Transformations}{Image-
1385 Transformations}-
1386*/-
1387#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)-
1388void QImage::setColorTable(const QVector<QRgb> &colors)-
1389#else-
1390void QImage::setColorTable(const QVector<QRgb> colors)-
1391#endif-
1392{-
1393 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1394 return;
never executed: return;
0
1395 detach();-
1396-
1397 // In case detach() ran out of memory-
1398 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1399 return;
never executed: return;
0
1400-
1401#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)-
1402 d->colortable = colors;-
1403#else-
1404 d->colortable = qMove(const_cast<QVector<QRgb>&>(colors));-
1405#endif-
1406 d->has_alpha_clut = false;-
1407 for (int i = 0; i < d->colortable.size(); ++i) {
i < d->colortable.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1408 if (qAlpha(d->colortable.at(i)) != 255) {
qAlpha(d->colo....at(i)) != 255Description
TRUEnever evaluated
FALSEnever evaluated
0
1409 d->has_alpha_clut = true;-
1410 break;
never executed: break;
0
1411 }-
1412 }
never executed: end of block
0
1413}
never executed: end of block
0
1414-
1415/*!-
1416 Returns a list of the colors contained in the image's color table,-
1417 or an empty list if the image does not have a color table-
1418-
1419 \sa setColorTable(), colorCount(), color()-
1420*/-
1421QVector<QRgb> QImage::colorTable() const-
1422{-
1423 return d ? d->colortable : QVector<QRgb>();
never executed: return d ? d->colortable : QVector<QRgb>();
0
1424}-
1425-
1426/*!-
1427 Returns the device pixel ratio for the image. This is the-
1428 ratio between \e{device pixels} and \e{device independent pixels}.-
1429-
1430 Use this function when calculating layout geometry based on-
1431 the image size: QSize layoutSize = image.size() / image.devicePixelRatio()-
1432-
1433 The default value is 1.0.-
1434-
1435 \sa setDevicePixelRatio(), QImageReader-
1436*/-
1437qreal QImage::devicePixelRatio() const-
1438{-
1439 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1440 return 1.0;
never executed: return 1.0;
0
1441 return d->devicePixelRatio;
never executed: return d->devicePixelRatio;
0
1442}-
1443-
1444/*!-
1445 Sets the device pixel ratio for the image. This is the-
1446 ratio between image pixels and device-independent pixels.-
1447-
1448 The default \a scaleFactor is 1.0. Setting it to something else has-
1449 two effects:-
1450-
1451 QPainters that are opened on the image will be scaled. For-
1452 example, painting on a 200x200 image if with a ratio of 2.0-
1453 will result in effective (device-independent) painting bounds-
1454 of 100x100.-
1455-
1456 Code paths in Qt that calculate layout geometry based on the-
1457 image size will take the ratio into account:-
1458 QSize layoutSize = image.size() / image.devicePixelRatio()-
1459 The net effect of this is that the image is displayed as-
1460 high-DPI image rather than a large image-
1461 (see \l{Drawing High Resolution Versions of Pixmaps and Images}).-
1462-
1463 \sa devicePixelRatio()-
1464*/-
1465void QImage::setDevicePixelRatio(qreal scaleFactor)-
1466{-
1467 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1468 return;
never executed: return;
0
1469-
1470 if (scaleFactor == d->devicePixelRatio)
scaleFactor ==...vicePixelRatioDescription
TRUEnever evaluated
FALSEnever evaluated
0
1471 return;
never executed: return;
0
1472-
1473 detach();-
1474 d->devicePixelRatio = scaleFactor;-
1475}
never executed: end of block
0
1476-
1477/*!-
1478 \since 4.6-
1479 Returns the number of bytes occupied by the image data.-
1480-
1481 \sa bytesPerLine(), bits(), {QImage#Image Information}{Image-
1482 Information}-
1483*/-
1484int QImage::byteCount() const-
1485{-
1486 return d ? d->nbytes : 0;
never executed: return d ? d->nbytes : 0;
0
1487}-
1488-
1489/*!-
1490 Returns the number of bytes per image scanline.-
1491-
1492 This is equivalent to byteCount() / height().-
1493-
1494 \sa scanLine()-
1495*/-
1496int QImage::bytesPerLine() const-
1497{-
1498 return (d && d->height) ? d->nbytes / d->height : 0;
never executed: return (d && d->height) ? d->nbytes / d->height : 0;
0
1499}-
1500-
1501-
1502/*!-
1503 Returns the color in the color table at index \a i. The first-
1504 color is at index 0.-
1505-
1506 The colors in an image's color table are specified as ARGB-
1507 quadruplets (QRgb). Use the qAlpha(), qRed(), qGreen(), and-
1508 qBlue() functions to get the color value components.-
1509-
1510 \sa setColor(), pixelIndex(), {QImage#Pixel Manipulation}{Pixel-
1511 Manipulation}-
1512*/-
1513QRgb QImage::color(int i) const-
1514{-
1515 Q_ASSERT(i < colorCount());-
1516 return d ? d->colortable.at(i) : QRgb(uint(-1));
never executed: return d ? d->colortable.at(i) : QRgb(uint(-1));
0
1517}-
1518-
1519/*!-
1520 \fn void QImage::setColor(int index, QRgb colorValue)-
1521-
1522 Sets the color at the given \a index in the color table, to the-
1523 given to \a colorValue. The color value is an ARGB quadruplet.-
1524-
1525 If \a index is outside the current size of the color table, it is-
1526 expanded with setColorCount().-
1527-
1528 \sa color(), colorCount(), setColorTable(), {QImage#Pixel Manipulation}{Pixel-
1529 Manipulation}-
1530*/-
1531void QImage::setColor(int i, QRgb c)-
1532{-
1533 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1534 return;
never executed: return;
0
1535 if (i < 0 || d->depth > 8 || i >= 1<<d->depth) {
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
d->depth > 8Description
TRUEnever evaluated
FALSEnever evaluated
i >= 1<<d->depthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1536 qWarning("QImage::setColor: Index out of bound %d", i);-
1537 return;
never executed: return;
0
1538 }-
1539 detach();-
1540-
1541 // In case detach() run out of memory-
1542 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1543 return;
never executed: return;
0
1544-
1545 if (i >= d->colortable.size())
i >= d->colortable.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1546 setColorCount(i+1);
never executed: setColorCount(i+1);
0
1547 d->colortable[i] = c;-
1548 d->has_alpha_clut |= (qAlpha(c) != 255);-
1549}
never executed: end of block
0
1550-
1551/*!-
1552 Returns a pointer to the pixel data at the scanline with index \a-
1553 i. The first scanline is at index 0.-
1554-
1555 The scanline data is aligned on a 32-bit boundary.-
1556-
1557 \warning If you are accessing 32-bpp image data, cast the returned-
1558 pointer to \c{QRgb*} (QRgb has a 32-bit size) and use it to-
1559 read/write the pixel value. You cannot use the \c{uchar*} pointer-
1560 directly, because the pixel format depends on the byte order on-
1561 the underlying platform. Use qRed(), qGreen(), qBlue(), and-
1562 qAlpha() to access the pixels.-
1563-
1564 \sa bytesPerLine(), bits(), {QImage#Pixel Manipulation}{Pixel-
1565 Manipulation}, constScanLine()-
1566*/-
1567uchar *QImage::scanLine(int i)-
1568{-
1569 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1570 return 0;
never executed: return 0;
0
1571-
1572 detach();-
1573-
1574 // In case detach() ran out of memory-
1575 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1576 return 0;
never executed: return 0;
0
1577-
1578 return d->data + i * d->bytes_per_line;
never executed: return d->data + i * d->bytes_per_line;
0
1579}-
1580-
1581/*!-
1582 \overload-
1583*/-
1584const uchar *QImage::scanLine(int i) const-
1585{-
1586 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1587 return 0;
never executed: return 0;
0
1588-
1589 Q_ASSERT(i >= 0 && i < height());-
1590 return d->data + i * d->bytes_per_line;
never executed: return d->data + i * d->bytes_per_line;
0
1591}-
1592-
1593-
1594/*!-
1595 Returns a pointer to the pixel data at the scanline with index \a-
1596 i. The first scanline is at index 0.-
1597-
1598 The scanline data is aligned on a 32-bit boundary.-
1599-
1600 Note that QImage uses \l{Implicit Data Sharing} {implicit data-
1601 sharing}, but this function does \e not perform a deep copy of the-
1602 shared pixel data, because the returned data is const.-
1603-
1604 \sa scanLine(), constBits()-
1605 \since 4.7-
1606*/-
1607const uchar *QImage::constScanLine(int i) const-
1608{-
1609 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1610 return 0;
never executed: return 0;
0
1611-
1612 Q_ASSERT(i >= 0 && i < height());-
1613 return d->data + i * d->bytes_per_line;
never executed: return d->data + i * d->bytes_per_line;
0
1614}-
1615-
1616/*!-
1617 Returns a pointer to the first pixel data. This is equivalent to-
1618 scanLine(0).-
1619-
1620 Note that QImage uses \l{Implicit Data Sharing} {implicit data-
1621 sharing}. This function performs a deep copy of the shared pixel-
1622 data, thus ensuring that this QImage is the only one using the-
1623 current return value.-
1624-
1625 \sa scanLine(), byteCount(), constBits()-
1626*/-
1627uchar *QImage::bits()-
1628{-
1629 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1630 return 0;
never executed: return 0;
0
1631 detach();-
1632-
1633 // In case detach ran out of memory...-
1634 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1635 return 0;
never executed: return 0;
0
1636-
1637 return d->data;
never executed: return d->data;
0
1638}-
1639-
1640/*!-
1641 \overload-
1642-
1643 Note that QImage uses \l{Implicit Data Sharing} {implicit data-
1644 sharing}, but this function does \e not perform a deep copy of the-
1645 shared pixel data, because the returned data is const.-
1646*/-
1647const uchar *QImage::bits() const-
1648{-
1649 return d ? d->data : 0;
never executed: return d ? d->data : 0;
0
1650}-
1651-
1652-
1653/*!-
1654 Returns a pointer to the first pixel data.-
1655-
1656 Note that QImage uses \l{Implicit Data Sharing} {implicit data-
1657 sharing}, but this function does \e not perform a deep copy of the-
1658 shared pixel data, because the returned data is const.-
1659-
1660 \sa bits(), constScanLine()-
1661 \since 4.7-
1662*/-
1663const uchar *QImage::constBits() const-
1664{-
1665 return d ? d->data : 0;
never executed: return d ? d->data : 0;
0
1666}-
1667-
1668/*!-
1669 \fn void QImage::fill(uint pixelValue)-
1670-
1671 Fills the entire image with the given \a pixelValue.-
1672-
1673 If the depth of this image is 1, only the lowest bit is used. If-
1674 you say fill(0), fill(2), etc., the image is filled with 0s. If-
1675 you say fill(1), fill(3), etc., the image is filled with 1s. If-
1676 the depth is 8, the lowest 8 bits are used and if the depth is 16-
1677 the lowest 16 bits are used.-
1678-
1679 Note: QImage::pixel() returns the color of the pixel at the given-
1680 coordinates while QColor::pixel() returns the pixel value of the-
1681 underlying window system (essentially an index value), so normally-
1682 you will want to use QImage::pixel() to use a color from an-
1683 existing image or QColor::rgb() to use a specific color.-
1684-
1685 \sa depth(), {QImage#Image Transformations}{Image Transformations}-
1686*/-
1687-
1688void QImage::fill(uint pixel)-
1689{-
1690 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1691 return;
never executed: return;
0
1692-
1693 detach();-
1694-
1695 // In case detach() ran out of memory-
1696 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1697 return;
never executed: return;
0
1698-
1699 if (d->depth == 1 || d->depth == 8) {
d->depth == 1Description
TRUEnever evaluated
FALSEnever evaluated
d->depth == 8Description
TRUEnever evaluated
FALSEnever evaluated
0
1700 int w = d->width;-
1701 if (d->depth == 1) {
d->depth == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1702 if (pixel & 1)
pixel & 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1703 pixel = 0xffffffff;
never executed: pixel = 0xffffffff;
0
1704 else-
1705 pixel = 0;
never executed: pixel = 0;
0
1706 w = (w + 7) / 8;-
1707 } else {
never executed: end of block
0
1708 pixel &= 0xff;-
1709 }
never executed: end of block
0
1710 qt_rectfill<quint8>(d->data, pixel, 0, 0,-
1711 w, d->height, d->bytes_per_line);-
1712 return;
never executed: return;
0
1713 } else if (d->depth == 16) {
d->depth == 16Description
TRUEnever evaluated
FALSEnever evaluated
0
1714 qt_rectfill<quint16>(reinterpret_cast<quint16*>(d->data), pixel,-
1715 0, 0, d->width, d->height, d->bytes_per_line);-
1716 return;
never executed: return;
0
1717 } else if (d->depth == 24) {
d->depth == 24Description
TRUEnever evaluated
FALSEnever evaluated
0
1718 qt_rectfill<quint24>(reinterpret_cast<quint24*>(d->data), pixel,-
1719 0, 0, d->width, d->height, d->bytes_per_line);-
1720 return;
never executed: return;
0
1721 }-
1722-
1723 if (d->format == Format_RGB32)
d->format == Format_RGB32Description
TRUEnever evaluated
FALSEnever evaluated
0
1724 pixel |= 0xff000000;
never executed: pixel |= 0xff000000;
0
1725 if (d->format == Format_RGBX8888)
d->format == Format_RGBX8888Description
TRUEnever evaluated
FALSEnever evaluated
0
1726#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN-
1727 pixel |= 0xff000000;
never executed: pixel |= 0xff000000;
0
1728#else-
1729 pixel |= 0x000000ff;-
1730#endif-
1731 if (d->format == Format_BGR30 || d->format == Format_RGB30)
d->format == Format_BGR30Description
TRUEnever evaluated
FALSEnever evaluated
d->format == Format_RGB30Description
TRUEnever evaluated
FALSEnever evaluated
0
1732 pixel |= 0xc0000000;
never executed: pixel |= 0xc0000000;
0
1733-
1734 qt_rectfill<uint>(reinterpret_cast<uint*>(d->data), pixel,-
1735 0, 0, d->width, d->height, d->bytes_per_line);-
1736}
never executed: end of block
0
1737-
1738-
1739/*!-
1740 \fn void QImage::fill(Qt::GlobalColor color)-
1741 \overload-
1742 \since 4.8-
1743-
1744 Fills the image with the given \a color, described as a standard global-
1745 color.-
1746 */-
1747-
1748void QImage::fill(Qt::GlobalColor color)-
1749{-
1750 fill(QColor(color));-
1751}
never executed: end of block
0
1752-
1753-
1754-
1755/*!-
1756 \fn void QImage::fill(const QColor &color)-
1757-
1758 \overload-
1759-
1760 Fills the entire image with the given \a color.-
1761-
1762 If the depth of the image is 1, the image will be filled with 1 if-
1763 \a color equals Qt::color1; it will otherwise be filled with 0.-
1764-
1765 If the depth of the image is 8, the image will be filled with the-
1766 index corresponding the \a color in the color table if present; it-
1767 will otherwise be filled with 0.-
1768-
1769 \since 4.8-
1770*/-
1771-
1772void QImage::fill(const QColor &color)-
1773{-
1774 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1775 return;
never executed: return;
0
1776 detach();-
1777-
1778 // In case we run out of memory-
1779 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1780 return;
never executed: return;
0
1781-
1782 switch (d->format) {-
1783 case QImage::Format_RGB32:
never executed: case QImage::Format_RGB32:
0
1784 case QImage::Format_ARGB32:
never executed: case QImage::Format_ARGB32:
0
1785 fill(color.rgba());-
1786 break;
never executed: break;
0
1787 case QImage::Format_ARGB32_Premultiplied:
never executed: case QImage::Format_ARGB32_Premultiplied:
0
1788 fill(qPremultiply(color.rgba()));-
1789 break;
never executed: break;
0
1790 case QImage::Format_RGBX8888:
never executed: case QImage::Format_RGBX8888:
0
1791 fill(ARGB2RGBA(color.rgba() | 0xff000000));-
1792 break;
never executed: break;
0
1793 case QImage::Format_RGBA8888:
never executed: case QImage::Format_RGBA8888:
0
1794 fill(ARGB2RGBA(color.rgba()));-
1795 break;
never executed: break;
0
1796 case QImage::Format_RGBA8888_Premultiplied:
never executed: case QImage::Format_RGBA8888_Premultiplied:
0
1797 fill(ARGB2RGBA(qPremultiply(color.rgba())));-
1798 break;
never executed: break;
0
1799 case QImage::Format_BGR30:
never executed: case QImage::Format_BGR30:
0
1800 case QImage::Format_A2BGR30_Premultiplied:
never executed: case QImage::Format_A2BGR30_Premultiplied:
0
1801 fill(qConvertRgb64ToRgb30<PixelOrderBGR>(color.rgba64()));-
1802 break;
never executed: break;
0
1803 case QImage::Format_RGB30:
never executed: case QImage::Format_RGB30:
0
1804 case QImage::Format_A2RGB30_Premultiplied:
never executed: case QImage::Format_A2RGB30_Premultiplied:
0
1805 fill(qConvertRgb64ToRgb30<PixelOrderRGB>(color.rgba64()));-
1806 break;
never executed: break;
0
1807 case QImage::Format_RGB16:
never executed: case QImage::Format_RGB16:
0
1808 fill((uint) qConvertRgb32To16(color.rgba()));-
1809 break;
never executed: break;
0
1810 case QImage::Format_Indexed8: {
never executed: case QImage::Format_Indexed8:
0
1811 uint pixel = 0;-
1812 for (int i=0; i<d->colortable.size(); ++i) {
i<d->colortable.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1813 if (color.rgba() == d->colortable.at(i)) {
color.rgba() =...lortable.at(i)Description
TRUEnever evaluated
FALSEnever evaluated
0
1814 pixel = i;-
1815 break;
never executed: break;
0
1816 }-
1817 }
never executed: end of block
0
1818 fill(pixel);-
1819 break;
never executed: break;
0
1820 }-
1821 case QImage::Format_Mono:
never executed: case QImage::Format_Mono:
0
1822 case QImage::Format_MonoLSB:
never executed: case QImage::Format_MonoLSB:
0
1823 if (color == Qt::color1)
color == Qt::color1Description
TRUEnever evaluated
FALSEnever evaluated
0
1824 fill((uint) 1);
never executed: fill((uint) 1);
0
1825 else-
1826 fill((uint) 0);
never executed: fill((uint) 0);
0
1827 break;
never executed: break;
0
1828 default: {
never executed: default:
0
1829 QPainter p(this);-
1830 p.setCompositionMode(QPainter::CompositionMode_Source);-
1831 p.fillRect(rect(), color);-
1832 }}
never executed: end of block
0
1833}-
1834-
1835-
1836-
1837/*!-
1838 Inverts all pixel values in the image.-
1839-
1840 The given invert \a mode only have a meaning when the image's-
1841 depth is 32. The default \a mode is InvertRgb, which leaves the-
1842 alpha channel unchanged. If the \a mode is InvertRgba, the alpha-
1843 bits are also inverted.-
1844-
1845 Inverting an 8-bit image means to replace all pixels using color-
1846 index \e i with a pixel using color index 255 minus \e i. The same-
1847 is the case for a 1-bit image. Note that the color table is \e not-
1848 changed.-
1849-
1850 If the image has a premultiplied alpha channel, the image is first-
1851 converted to ARGB32 to be inverted and then converted back.-
1852-
1853 \sa {QImage#Image Transformations}{Image Transformations}-
1854*/-
1855-
1856void QImage::invertPixels(InvertMode mode)-
1857{-
1858 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1859 return;
never executed: return;
0
1860-
1861 detach();-
1862-
1863 // In case detach() ran out of memory-
1864 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1865 return;
never executed: return;
0
1866-
1867 QImage::Format originalFormat = d->format;-
1868 // Inverting premultiplied pixels would produce invalid image data.-
1869 if (hasAlphaChannel() && qPixelLayouts[d->format].premultiplied) {
hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
qPixelLayouts[....premultipliedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1870 if (!d->convertInPlace(QImage::Format_ARGB32, 0))
!d->convertInP...mat_ARGB32, 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1871 *this = convertToFormat(QImage::Format_ARGB32);
never executed: *this = convertToFormat(QImage::Format_ARGB32);
0
1872 }
never executed: end of block
0
1873-
1874 if (depth() < 32) {
depth() < 32Description
TRUEnever evaluated
FALSEnever evaluated
0
1875 // This assumes no alpha-channel as the only formats with non-premultipled alpha are 32bit.-
1876 int bpl = (d->width * d->depth + 7) / 8;-
1877 int pad = d->bytes_per_line - bpl;-
1878 uchar *sl = d->data;-
1879 for (int y=0; y<d->height; ++y) {
y<d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1880 for (int x=0; x<bpl; ++x)
x<bplDescription
TRUEnever evaluated
FALSEnever evaluated
0
1881 *sl++ ^= 0xff;
never executed: *sl++ ^= 0xff;
0
1882 sl += pad;-
1883 }
never executed: end of block
0
1884 } else {
never executed: end of block
0
1885 quint32 *p = (quint32*)d->data;-
1886 quint32 *end = (quint32*)(d->data + d->nbytes);-
1887 quint32 xorbits = 0xffffffff;-
1888 switch (d->format) {-
1889 case QImage::Format_RGBA8888:
never executed: case QImage::Format_RGBA8888:
0
1890 if (mode == InvertRgba)
mode == InvertRgbaDescription
TRUEnever evaluated
FALSEnever evaluated
0
1891 break;
never executed: break;
0
1892 // no break-
1893 case QImage::Format_RGBX8888:
code before this statement never executed: case QImage::Format_RGBX8888:
never executed: case QImage::Format_RGBX8888:
0
1894#if Q_BYTE_ORDER == Q_BIG_ENDIAN-
1895 xorbits = 0xffffff00;-
1896 break;-
1897#else-
1898 xorbits = 0x00ffffff;-
1899 break;
never executed: break;
0
1900#endif-
1901 case QImage::Format_ARGB32:
never executed: case QImage::Format_ARGB32:
0
1902 if (mode == InvertRgba)
mode == InvertRgbaDescription
TRUEnever evaluated
FALSEnever evaluated
0
1903 break;
never executed: break;
0
1904 // no break-
1905 case QImage::Format_RGB32:
code before this statement never executed: case QImage::Format_RGB32:
never executed: case QImage::Format_RGB32:
0
1906 xorbits = 0x00ffffff;-
1907 break;
never executed: break;
0
1908 case QImage::Format_BGR30:
never executed: case QImage::Format_BGR30:
0
1909 case QImage::Format_RGB30:
never executed: case QImage::Format_RGB30:
0
1910 xorbits = 0x3fffffff;-
1911 break;
never executed: break;
0
1912 default:
never executed: default:
0
1913 Q_UNREACHABLE();-
1914 xorbits = 0;-
1915 break;
never executed: break;
0
1916 }-
1917 while (p < end)
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
1918 *p++ ^= xorbits;
never executed: *p++ ^= xorbits;
0
1919 }
never executed: end of block
0
1920-
1921 if (originalFormat != d->format) {
originalFormat != d->formatDescription
TRUEnever evaluated
FALSEnever evaluated
0
1922 if (!d->convertInPlace(originalFormat, 0))
!d->convertInP...inalFormat, 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1923 *this = convertToFormat(originalFormat);
never executed: *this = convertToFormat(originalFormat);
0
1924 }
never executed: end of block
0
1925}
never executed: end of block
0
1926-
1927// Windows defines these-
1928#if defined(write)-
1929# undef write-
1930#endif-
1931#if defined(close)-
1932# undef close-
1933#endif-
1934#if defined(read)-
1935# undef read-
1936#endif-
1937-
1938/*!-
1939 \since 4.6-
1940 Resizes the color table to contain \a colorCount entries.-
1941-
1942 If the color table is expanded, all the extra colors will be set to-
1943 transparent (i.e qRgba(0, 0, 0, 0)).-
1944-
1945 When the image is used, the color table must be large enough to-
1946 have entries for all the pixel/index values present in the image,-
1947 otherwise the results are undefined.-
1948-
1949 \sa colorCount(), colorTable(), setColor(), {QImage#Image-
1950 Transformations}{Image Transformations}-
1951*/-
1952-
1953void QImage::setColorCount(int colorCount)-
1954{-
1955 if (!d) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1956 qWarning("QImage::setColorCount: null image");-
1957 return;
never executed: return;
0
1958 }-
1959-
1960 detach();-
1961-
1962 // In case detach() ran out of memory-
1963 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1964 return;
never executed: return;
0
1965-
1966 if (colorCount == d->colortable.size())
colorCount == ...ortable.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1967 return;
never executed: return;
0
1968 if (colorCount <= 0) { // use no color table
colorCount <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1969 d->colortable = QVector<QRgb>();-
1970 return;
never executed: return;
0
1971 }-
1972 int nc = d->colortable.size();-
1973 d->colortable.resize(colorCount);-
1974 for (int i = nc; i < colorCount; ++i)
i < colorCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
1975 d->colortable[i] = 0;
never executed: d->colortable[i] = 0;
0
1976}
never executed: end of block
0
1977-
1978/*!-
1979 Returns the format of the image.-
1980-
1981 \sa {QImage#Image Formats}{Image Formats}-
1982*/-
1983QImage::Format QImage::format() const-
1984{-
1985 return d ? d->format : Format_Invalid;
never executed: return d ? d->format : Format_Invalid;
0
1986}-
1987-
1988/*!-
1989 \fn QImage QImage::convertToFormat(Format format, Qt::ImageConversionFlags flags) const-
1990-
1991 Returns a copy of the image in the given \a format.-
1992-
1993 The specified image conversion \a flags control how the image data-
1994 is handled during the conversion process.-
1995-
1996 \sa {Image Formats}-
1997*/-
1998-
1999/*!-
2000 \internal-
2001*/-
2002QImage QImage::convertToFormat_helper(Format format, Qt::ImageConversionFlags flags) const-
2003{-
2004 if (!d || d->format == format)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
d->format == formatDescription
TRUEnever evaluated
FALSEnever evaluated
0
2005 return *this;
never executed: return *this;
0
2006-
2007 if (format == Format_Invalid || d->format == Format_Invalid)
format == Format_InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
d->format == Format_InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
0
2008 return QImage();
never executed: return QImage();
0
2009-
2010 Image_Converter converter = qimage_converter_map[d->format][format];-
2011 if (!converter && format > QImage::Format_Indexed8 && d->format > QImage::Format_Indexed8)
!converterDescription
TRUEnever evaluated
FALSEnever evaluated
format > QImag...ormat_Indexed8Description
TRUEnever evaluated
FALSEnever evaluated
d->format > QI...ormat_Indexed8Description
TRUEnever evaluated
FALSEnever evaluated
0
2012 converter = convert_generic;
never executed: converter = convert_generic;
0
2013 if (converter) {
converterDescription
TRUEnever evaluated
FALSEnever evaluated
0
2014 QImage image(d->width, d->height, format);-
2015-
2016 QIMAGE_SANITYCHECK_MEMORY(image);
never executed: return QImage();
(image).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2017-
2018 image.d->offset = offset();-
2019 copyMetadata(image.d, d);-
2020-
2021 converter(image.d, d, flags);-
2022 return image;
never executed: return image;
0
2023 }-
2024-
2025 // Convert indexed formats over ARGB32 or RGB32 to the final format.-
2026 Q_ASSERT(format != QImage::Format_ARGB32 && format != QImage::Format_RGB32);-
2027 Q_ASSERT(d->format != QImage::Format_ARGB32 && d->format != QImage::Format_RGB32);-
2028-
2029 if (!hasAlphaChannel())
!hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
0
2030 return convertToFormat(Format_RGB32, flags).convertToFormat(format, flags);
never executed: return convertToFormat(Format_RGB32, flags).convertToFormat(format, flags);
0
2031-
2032 return convertToFormat(Format_ARGB32, flags).convertToFormat(format, flags);
never executed: return convertToFormat(Format_ARGB32, flags).convertToFormat(format, flags);
0
2033}-
2034-
2035/*!-
2036 \internal-
2037*/-
2038bool QImage::convertToFormat_inplace(Format format, Qt::ImageConversionFlags flags)-
2039{-
2040 return d && d->convertInPlace(format, flags);
never executed: return d && d->convertInPlace(format, flags);
0
2041}-
2042-
2043static inline int pixel_distance(QRgb p1, QRgb p2) {-
2044 int r1 = qRed(p1);-
2045 int g1 = qGreen(p1);-
2046 int b1 = qBlue(p1);-
2047 int a1 = qAlpha(p1);-
2048-
2049 int r2 = qRed(p2);-
2050 int g2 = qGreen(p2);-
2051 int b2 = qBlue(p2);-
2052 int a2 = qAlpha(p2);-
2053-
2054 return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2) + abs(a1 - a2);
never executed: return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2) + abs(a1 - a2);
0
2055}-
2056-
2057static inline int closestMatch(QRgb pixel, const QVector<QRgb> &clut) {-
2058 int idx = 0;-
2059 int current_distance = INT_MAX;-
2060 for (int i=0; i<clut.size(); ++i) {
i<clut.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
2061 int dist = pixel_distance(pixel, clut.at(i));-
2062 if (dist < current_distance) {
dist < current_distanceDescription
TRUEnever evaluated
FALSEnever evaluated
0
2063 current_distance = dist;-
2064 idx = i;-
2065 }
never executed: end of block
0
2066 }
never executed: end of block
0
2067 return idx;
never executed: return idx;
0
2068}-
2069-
2070static QImage convertWithPalette(const QImage &src, QImage::Format format,-
2071 const QVector<QRgb> &clut) {-
2072 QImage dest(src.size(), format);-
2073 dest.setColorTable(clut);-
2074-
2075 QString textsKeys = src.text();-
2076 const auto textKeyList = textsKeys.splitRef(QLatin1Char('\n'), QString::SkipEmptyParts);-
2077 for (const auto &textKey : textKeyList) {-
2078 const auto textKeySplitted = textKey.split(QLatin1String(": "));-
2079 dest.setText(textKeySplitted[0].toString(), textKeySplitted[1].toString());-
2080 }
never executed: end of block
0
2081-
2082 int h = src.height();-
2083 int w = src.width();-
2084-
2085 QHash<QRgb, int> cache;-
2086-
2087 if (format == QImage::Format_Indexed8) {
format == QIma...ormat_Indexed8Description
TRUEnever evaluated
FALSEnever evaluated
0
2088 for (int y=0; y<h; ++y) {
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
0
2089 const QRgb *src_pixels = (const QRgb *) src.scanLine(y);-
2090 uchar *dest_pixels = (uchar *) dest.scanLine(y);-
2091 for (int x=0; x<w; ++x) {
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
2092 int src_pixel = src_pixels[x];-
2093 int value = cache.value(src_pixel, -1);-
2094 if (value == -1) {
value == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
2095 value = closestMatch(src_pixel, clut);-
2096 cache.insert(src_pixel, value);-
2097 }
never executed: end of block
0
2098 dest_pixels[x] = (uchar) value;-
2099 }
never executed: end of block
0
2100 }
never executed: end of block
0
2101 } else {
never executed: end of block
0
2102 QVector<QRgb> table = clut;-
2103 table.resize(2);-
2104 for (int y=0; y<h; ++y) {
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
0
2105 const QRgb *src_pixels = (const QRgb *) src.scanLine(y);-
2106 for (int x=0; x<w; ++x) {
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
2107 int src_pixel = src_pixels[x];-
2108 int value = cache.value(src_pixel, -1);-
2109 if (value == -1) {
value == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
2110 value = closestMatch(src_pixel, table);-
2111 cache.insert(src_pixel, value);-
2112 }
never executed: end of block
0
2113 dest.setPixel(x, y, value);-
2114 }
never executed: end of block
0
2115 }
never executed: end of block
0
2116 }
never executed: end of block
0
2117-
2118 return dest;
never executed: return dest;
0
2119}-
2120-
2121/*!-
2122 \overload-
2123-
2124 Returns a copy of the image converted to the given \a format,-
2125 using the specified \a colorTable.-
2126-
2127 Conversion from 32 bit to 8 bit indexed is a slow operation and-
2128 will use a straightforward nearest color approach, with no-
2129 dithering.-
2130*/-
2131QImage QImage::convertToFormat(Format format, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags) const-
2132{-
2133 if (!d || d->format == format)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
d->format == formatDescription
TRUEnever evaluated
FALSEnever evaluated
0
2134 return *this;
never executed: return *this;
0
2135-
2136 if (format <= QImage::Format_Indexed8 && depth() == 32) {
format <= QIma...ormat_Indexed8Description
TRUEnever evaluated
FALSEnever evaluated
depth() == 32Description
TRUEnever evaluated
FALSEnever evaluated
0
2137 return convertWithPalette(*this, format, colorTable);
never executed: return convertWithPalette(*this, format, colorTable);
0
2138 }-
2139-
2140 const Image_Converter *converterPtr = &qimage_converter_map[d->format][format];-
2141 Image_Converter converter = *converterPtr;-
2142 if (!converter)
!converterDescription
TRUEnever evaluated
FALSEnever evaluated
0
2143 return QImage();
never executed: return QImage();
0
2144-
2145 QImage image(d->width, d->height, format);-
2146 QIMAGE_SANITYCHECK_MEMORY(image);
never executed: return QImage();
(image).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2147-
2148 image.d->offset = offset();-
2149 copyMetadata(image.d, d);-
2150-
2151 converter(image.d, d, flags);-
2152 return image;
never executed: return image;
0
2153}-
2154-
2155/*!-
2156 \fn bool QImage::valid(const QPoint &pos) const-
2157-
2158 Returns \c true if \a pos is a valid coordinate pair within the-
2159 image; otherwise returns \c false.-
2160-
2161 \sa rect(), QRect::contains()-
2162*/-
2163-
2164/*!-
2165 \overload-
2166-
2167 Returns \c true if QPoint(\a x, \a y) is a valid coordinate pair-
2168 within the image; otherwise returns \c false.-
2169*/-
2170bool QImage::valid(int x, int y) const-
2171{-
2172 return d
never executed: return d && x >= 0 && x < d->width && y >= 0 && y < d->height;
0
2173 && x >= 0 && x < d->width
never executed: return d && x >= 0 && x < d->width && y >= 0 && y < d->height;
0
2174 && y >= 0 && y < d->height;
never executed: return d && x >= 0 && x < d->width && y >= 0 && y < d->height;
0
2175}-
2176-
2177/*!-
2178 \fn int QImage::pixelIndex(const QPoint &position) const-
2179-
2180 Returns the pixel index at the given \a position.-
2181-
2182 If \a position is not valid, or if the image is not a paletted-
2183 image (depth() > 8), the results are undefined.-
2184-
2185 \sa valid(), depth(), {QImage#Pixel Manipulation}{Pixel Manipulation}-
2186*/-
2187-
2188/*!-
2189 \overload-
2190-
2191 Returns the pixel index at (\a x, \a y).-
2192*/-
2193int QImage::pixelIndex(int x, int y) const-
2194{-
2195 if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
x >= d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
y >= height()Description
TRUEnever evaluated
FALSEnever evaluated
0
2196 qWarning("QImage::pixelIndex: coordinate (%d,%d) out of range", x, y);-
2197 return -12345;
never executed: return -12345;
0
2198 }-
2199 const uchar * s = scanLine(y);-
2200 switch(d->format) {-
2201 case Format_Mono:
never executed: case Format_Mono:
0
2202 return (*(s + (x >> 3)) >> (7- (x & 7))) & 1;
never executed: return (*(s + (x >> 3)) >> (7- (x & 7))) & 1;
0
2203 case Format_MonoLSB:
never executed: case Format_MonoLSB:
0
2204 return (*(s + (x >> 3)) >> (x & 7)) & 1;
never executed: return (*(s + (x >> 3)) >> (x & 7)) & 1;
0
2205 case Format_Indexed8:
never executed: case Format_Indexed8:
0
2206 return (int)s[x];
never executed: return (int)s[x];
0
2207 default:
never executed: default:
0
2208 qWarning("QImage::pixelIndex: Not applicable for %d-bpp images (no palette)", d->depth);-
2209 }
never executed: end of block
0
2210 return 0;
never executed: return 0;
0
2211}-
2212-
2213-
2214/*!-
2215 \fn QRgb QImage::pixel(const QPoint &position) const-
2216-
2217 Returns the color of the pixel at the given \a position.-
2218-
2219 If the \a position is not valid, the results are undefined.-
2220-
2221 \warning This function is expensive when used for massive pixel-
2222 manipulations. Use constBits() or constScanLine() when many-
2223 pixels needs to be read.-
2224-
2225 \sa setPixel(), valid(), constBits(), constScanLine(), {QImage#Pixel Manipulation}{Pixel-
2226 Manipulation}-
2227*/-
2228-
2229/*!-
2230 \overload-
2231-
2232 Returns the color of the pixel at coordinates (\a x, \a y).-
2233*/-
2234QRgb QImage::pixel(int x, int y) const-
2235{-
2236 if (!d || x < 0 || x >= d->width || y < 0 || y >= d->height) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
x >= d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
y >= d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
2237 qWarning("QImage::pixel: coordinate (%d,%d) out of range", x, y);-
2238 return 12345;
never executed: return 12345;
0
2239 }-
2240-
2241 const uchar *s = d->data + y * d->bytes_per_line;-
2242-
2243 int index = -1;-
2244 switch (d->format) {-
2245 case Format_Mono:
never executed: case Format_Mono:
0
2246 index = (*(s + (x >> 3)) >> (~x & 7)) & 1;-
2247 break;
never executed: break;
0
2248 case Format_MonoLSB:
never executed: case Format_MonoLSB:
0
2249 index = (*(s + (x >> 3)) >> (x & 7)) & 1;-
2250 break;
never executed: break;
0
2251 case Format_Indexed8:
never executed: case Format_Indexed8:
0
2252 index = s[x];-
2253 break;
never executed: break;
0
2254 default:
never executed: default:
0
2255 break;
never executed: break;
0
2256 }-
2257 if (index >= 0) { // Indexed format
index >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2258 if (index >= d->colortable.size()) {
index >= d->colortable.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
2259 qWarning("QImage::pixel: color table index %d out of range.", index);-
2260 return 0;
never executed: return 0;
0
2261 }-
2262 return d->colortable.at(index);
never executed: return d->colortable.at(index);
0
2263 }-
2264-
2265 switch (d->format) {-
2266 case Format_RGB32:
never executed: case Format_RGB32:
0
2267 return 0xff000000 | reinterpret_cast<const QRgb *>(s)[x];
never executed: return 0xff000000 | reinterpret_cast<const QRgb *>(s)[x];
0
2268 case Format_ARGB32: // Keep old behaviour.
never executed: case Format_ARGB32:
0
2269 case Format_ARGB32_Premultiplied:
never executed: case Format_ARGB32_Premultiplied:
0
2270 return reinterpret_cast<const QRgb *>(s)[x];
never executed: return reinterpret_cast<const QRgb *>(s)[x];
0
2271 case Format_RGBX8888:
never executed: case Format_RGBX8888:
0
2272 case Format_RGBA8888: // Match ARGB32 behavior.
never executed: case Format_RGBA8888:
0
2273 case Format_RGBA8888_Premultiplied:
never executed: case Format_RGBA8888_Premultiplied:
0
2274 return RGBA2ARGB(reinterpret_cast<const quint32 *>(s)[x]);
never executed: return RGBA2ARGB(reinterpret_cast<const quint32 *>(s)[x]);
0
2275 case Format_BGR30:
never executed: case Format_BGR30:
0
2276 case Format_A2BGR30_Premultiplied:
never executed: case Format_A2BGR30_Premultiplied:
0
2277 return qConvertA2rgb30ToArgb32<PixelOrderBGR>(reinterpret_cast<const quint32 *>(s)[x]);
never executed: return qConvertA2rgb30ToArgb32<PixelOrderBGR>(reinterpret_cast<const quint32 *>(s)[x]);
0
2278 case Format_RGB30:
never executed: case Format_RGB30:
0
2279 case Format_A2RGB30_Premultiplied:
never executed: case Format_A2RGB30_Premultiplied:
0
2280 return qConvertA2rgb30ToArgb32<PixelOrderRGB>(reinterpret_cast<const quint32 *>(s)[x]);
never executed: return qConvertA2rgb30ToArgb32<PixelOrderRGB>(reinterpret_cast<const quint32 *>(s)[x]);
0
2281 case Format_RGB16:
never executed: case Format_RGB16:
0
2282 return qConvertRgb16To32(reinterpret_cast<const quint16 *>(s)[x]);
never executed: return qConvertRgb16To32(reinterpret_cast<const quint16 *>(s)[x]);
0
2283 default:
never executed: default:
0
2284 break;
never executed: break;
0
2285 }-
2286 const QPixelLayout *layout = &qPixelLayouts[d->format];-
2287 uint result;-
2288 const uint *ptr = qFetchPixels[layout->bpp](&result, s, x, 1);-
2289 return *layout->convertToARGB32PM(&result, ptr, 1, layout, 0);
never executed: return *layout->convertToARGB32PM(&result, ptr, 1, layout, 0);
0
2290}-
2291-
2292/*!-
2293 \fn void QImage::setPixel(const QPoint &position, uint index_or_rgb)-
2294-
2295 Sets the pixel index or color at the given \a position to \a-
2296 index_or_rgb.-
2297-
2298 If the image's format is either monochrome or paletted, the given \a-
2299 index_or_rgb value must be an index in the image's color table,-
2300 otherwise the parameter must be a QRgb value.-
2301-
2302 If \a position is not a valid coordinate pair in the image, or if-
2303 \a index_or_rgb >= colorCount() in the case of monochrome and-
2304 paletted images, the result is undefined.-
2305-
2306 \warning This function is expensive due to the call of the internal-
2307 \c{detach()} function called within; if performance is a concern, we-
2308 recommend the use of scanLine() or bits() to access pixel data directly.-
2309-
2310 \sa pixel(), {QImage#Pixel Manipulation}{Pixel Manipulation}-
2311*/-
2312-
2313/*!-
2314 \overload-
2315-
2316 Sets the pixel index or color at (\a x, \a y) to \a index_or_rgb.-
2317*/-
2318void QImage::setPixel(int x, int y, uint index_or_rgb)-
2319{-
2320 if (!d || x < 0 || x >= width() || y < 0 || y >= height()) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
x >= width()Description
TRUEnever evaluated
FALSEnever evaluated
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
y >= height()Description
TRUEnever evaluated
FALSEnever evaluated
0
2321 qWarning("QImage::setPixel: coordinate (%d,%d) out of range", x, y);-
2322 return;
never executed: return;
0
2323 }-
2324 // detach is called from within scanLine-
2325 uchar * s = scanLine(y);-
2326 switch(d->format) {-
2327 case Format_Mono:
never executed: case Format_Mono:
0
2328 case Format_MonoLSB:
never executed: case Format_MonoLSB:
0
2329 if (index_or_rgb > 1) {
index_or_rgb > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
2330 qWarning("QImage::setPixel: Index %d out of range", index_or_rgb);-
2331 } else if (format() == Format_MonoLSB) {
never executed: end of block
format() == Format_MonoLSBDescription
TRUEnever evaluated
FALSEnever evaluated
0
2332 if (index_or_rgb==0)
index_or_rgb==0Description
TRUEnever evaluated
FALSEnever evaluated
0
2333 *(s + (x >> 3)) &= ~(1 << (x & 7));
never executed: *(s + (x >> 3)) &= ~(1 << (x & 7));
0
2334 else-
2335 *(s + (x >> 3)) |= (1 << (x & 7));
never executed: *(s + (x >> 3)) |= (1 << (x & 7));
0
2336 } else {-
2337 if (index_or_rgb==0)
index_or_rgb==0Description
TRUEnever evaluated
FALSEnever evaluated
0
2338 *(s + (x >> 3)) &= ~(1 << (7-(x & 7)));
never executed: *(s + (x >> 3)) &= ~(1 << (7-(x & 7)));
0
2339 else-
2340 *(s + (x >> 3)) |= (1 << (7-(x & 7)));
never executed: *(s + (x >> 3)) |= (1 << (7-(x & 7)));
0
2341 }-
2342 return;
never executed: return;
0
2343 case Format_Indexed8:
never executed: case Format_Indexed8:
0
2344 if (index_or_rgb >= (uint)d->colortable.size()) {
index_or_rgb >...ortable.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
2345 qWarning("QImage::setPixel: Index %d out of range", index_or_rgb);-
2346 return;
never executed: return;
0
2347 }-
2348 s[x] = index_or_rgb;-
2349 return;
never executed: return;
0
2350 case Format_RGB32:
never executed: case Format_RGB32:
0
2351 //make sure alpha is 255, we depend on it in qdrawhelper for cases-
2352 // when image is set as a texture pattern on a qbrush-
2353 ((uint *)s)[x] = 0xff000000 | index_or_rgb;-
2354 return;
never executed: return;
0
2355 case Format_ARGB32:
never executed: case Format_ARGB32:
0
2356 case Format_ARGB32_Premultiplied:
never executed: case Format_ARGB32_Premultiplied:
0
2357 ((uint *)s)[x] = index_or_rgb;-
2358 return;
never executed: return;
0
2359 case Format_RGB16:
never executed: case Format_RGB16:
0
2360 ((quint16 *)s)[x] = qConvertRgb32To16(qUnpremultiply(index_or_rgb));-
2361 return;
never executed: return;
0
2362 case Format_RGBX8888:
never executed: case Format_RGBX8888:
0
2363 ((uint *)s)[x] = ARGB2RGBA(0xff000000 | index_or_rgb);-
2364 return;
never executed: return;
0
2365 case Format_RGBA8888:
never executed: case Format_RGBA8888:
0
2366 case Format_RGBA8888_Premultiplied:
never executed: case Format_RGBA8888_Premultiplied:
0
2367 ((uint *)s)[x] = ARGB2RGBA(index_or_rgb);-
2368 return;
never executed: return;
0
2369 case Format_BGR30:
never executed: case Format_BGR30:
0
2370 ((uint *)s)[x] = qConvertRgb32ToRgb30<PixelOrderBGR>(index_or_rgb);-
2371 return;
never executed: return;
0
2372 case Format_A2BGR30_Premultiplied:
never executed: case Format_A2BGR30_Premultiplied:
0
2373 ((uint *)s)[x] = qConvertArgb32ToA2rgb30<PixelOrderBGR>(index_or_rgb);-
2374 return;
never executed: return;
0
2375 case Format_RGB30:
never executed: case Format_RGB30:
0
2376 ((uint *)s)[x] = qConvertRgb32ToRgb30<PixelOrderRGB>(index_or_rgb);-
2377 return;
never executed: return;
0
2378 case Format_A2RGB30_Premultiplied:
never executed: case Format_A2RGB30_Premultiplied:
0
2379 ((uint *)s)[x] = qConvertArgb32ToA2rgb30<PixelOrderRGB>(index_or_rgb);-
2380 return;
never executed: return;
0
2381 case Format_Invalid:
never executed: case Format_Invalid:
0
2382 case NImageFormats:
never executed: case NImageFormats:
0
2383 Q_ASSERT(false);-
2384 return;
never executed: return;
0
2385 default:
never executed: default:
0
2386 break;
never executed: break;
0
2387 }-
2388-
2389 const QPixelLayout *layout = &qPixelLayouts[d->format];-
2390 uint result;-
2391 const uint *ptr = layout->convertFromARGB32PM(&result, &index_or_rgb, 1, layout, 0);-
2392 qStorePixels[layout->bpp](s, ptr, x, 1);-
2393}
never executed: end of block
0
2394-
2395/*!-
2396 \fn QColor QImage::pixelColor(const QPoint &position) const-
2397 \since 5.6-
2398-
2399 Returns the color of the pixel at the given \a position as a QColor.-
2400-
2401 If the \a position is not valid, an invalid QColor is returned.-
2402-
2403 \warning This function is expensive when used for massive pixel-
2404 manipulations. Use constBits() or constScanLine() when many-
2405 pixels needs to be read.-
2406-
2407 \sa setPixel(), valid(), constBits(), constScanLine(), {QImage#Pixel Manipulation}{Pixel-
2408 Manipulation}-
2409*/-
2410-
2411/*!-
2412 \overload-
2413 \since 5.6-
2414-
2415 Returns the color of the pixel at coordinates (\a x, \a y) as a QColor.-
2416*/-
2417QColor QImage::pixelColor(int x, int y) const-
2418{-
2419 if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
x >= d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
y >= height()Description
TRUEnever evaluated
FALSEnever evaluated
0
2420 qWarning("QImage::pixelColor: coordinate (%d,%d) out of range", x, y);-
2421 return QColor();
never executed: return QColor();
0
2422 }-
2423-
2424 QRgba64 c;-
2425 const uchar * s = constScanLine(y);-
2426 switch (d->format) {-
2427 case Format_BGR30:
never executed: case Format_BGR30:
0
2428 case Format_A2BGR30_Premultiplied:
never executed: case Format_A2BGR30_Premultiplied:
0
2429 c = qConvertA2rgb30ToRgb64<PixelOrderBGR>(reinterpret_cast<const quint32 *>(s)[x]);-
2430 break;
never executed: break;
0
2431 case Format_RGB30:
never executed: case Format_RGB30:
0
2432 case Format_A2RGB30_Premultiplied:
never executed: case Format_A2RGB30_Premultiplied:
0
2433 c = qConvertA2rgb30ToRgb64<PixelOrderRGB>(reinterpret_cast<const quint32 *>(s)[x]);-
2434 break;
never executed: break;
0
2435 default:
never executed: default:
0
2436 c = QRgba64::fromArgb32(pixel(x, y));-
2437 break;
never executed: break;
0
2438 }-
2439 // QColor is always unpremultiplied-
2440 if (hasAlphaChannel() && qPixelLayouts[d->format].premultiplied)
hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
qPixelLayouts[....premultipliedDescription
TRUEnever evaluated
FALSEnever evaluated
0
2441 c = c.unpremultiplied();
never executed: c = c.unpremultiplied();
0
2442 return QColor(c);
never executed: return QColor(c);
0
2443}-
2444-
2445/*!-
2446 \fn void QImage::setPixelColor(const QPoint &position, const QColor &color)-
2447 \since 5.6-
2448-
2449 Sets the color at the given \a position to \a color.-
2450-
2451 If \a position is not a valid coordinate pair in the image, or-
2452 the image's format is either monochrome or paletted, the result is undefined.-
2453-
2454 \warning This function is expensive due to the call of the internal-
2455 \c{detach()} function called within; if performance is a concern, we-
2456 recommend the use of scanLine() or bits() to access pixel data directly.-
2457-
2458 \sa pixel(), bits(), scanLine(), {QImage#Pixel Manipulation}{Pixel Manipulation}-
2459*/-
2460-
2461/*!-
2462 \overload-
2463 \since 5.6-
2464-
2465 Sets the pixel color at (\a x, \a y) to \a color.-
2466*/-
2467void QImage::setPixelColor(int x, int y, const QColor &color)-
2468{-
2469 if (!d || x < 0 || x >= width() || y < 0 || y >= height()) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
x < 0Description
TRUEnever evaluated
FALSEnever evaluated
x >= width()Description
TRUEnever evaluated
FALSEnever evaluated
y < 0Description
TRUEnever evaluated
FALSEnever evaluated
y >= height()Description
TRUEnever evaluated
FALSEnever evaluated
0
2470 qWarning("QImage::setPixelColor: coordinate (%d,%d) out of range", x, y);-
2471 return;
never executed: return;
0
2472 }-
2473-
2474 if (!color.isValid()) {
!color.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
2475 qWarning("QImage::setPixelColor: color is invalid");-
2476 return;
never executed: return;
0
2477 }-
2478-
2479 // QColor is always unpremultiplied-
2480 QRgba64 c = color.rgba64();-
2481 if (!hasAlphaChannel())
!hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
0
2482 c.setAlpha(65535);
never executed: c.setAlpha(65535);
0
2483 else if (qPixelLayouts[d->format].premultiplied)
qPixelLayouts[....premultipliedDescription
TRUEnever evaluated
FALSEnever evaluated
0
2484 c = c.premultiplied();
never executed: c = c.premultiplied();
0
2485 // detach is called from within scanLine-
2486 uchar * s = scanLine(y);-
2487 switch (d->format) {-
2488 case Format_Mono:
never executed: case Format_Mono:
0
2489 case Format_MonoLSB:
never executed: case Format_MonoLSB:
0
2490 case Format_Indexed8:
never executed: case Format_Indexed8:
0
2491 qWarning("QImage::setPixelColor: called on monochrome or indexed format");-
2492 return;
never executed: return;
0
2493 case Format_BGR30:
never executed: case Format_BGR30:
0
2494 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderBGR>(c) | 0xc0000000;-
2495 return;
never executed: return;
0
2496 case Format_A2BGR30_Premultiplied:
never executed: case Format_A2BGR30_Premultiplied:
0
2497 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderBGR>(c);-
2498 return;
never executed: return;
0
2499 case Format_RGB30:
never executed: case Format_RGB30:
0
2500 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderRGB>(c) | 0xc0000000;-
2501 return;
never executed: return;
0
2502 case Format_A2RGB30_Premultiplied:
never executed: case Format_A2RGB30_Premultiplied:
0
2503 ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderRGB>(c);-
2504 return;
never executed: return;
0
2505 default:
never executed: default:
0
2506 setPixel(x, y, c.toArgb32());-
2507 return;
never executed: return;
0
2508 }-
2509}-
2510-
2511/*!-
2512 Returns \c true if all the colors in the image are shades of gray-
2513 (i.e. their red, green and blue components are equal); otherwise-
2514 false.-
2515-
2516 Note that this function is slow for images without color table.-
2517-
2518 \sa isGrayscale()-
2519*/-
2520bool QImage::allGray() const-
2521{-
2522 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2523 return true;
never executed: return true;
0
2524-
2525 switch (d->format) {-
2526 case Format_Mono:
never executed: case Format_Mono:
0
2527 case Format_MonoLSB:
never executed: case Format_MonoLSB:
0
2528 case Format_Indexed8:
never executed: case Format_Indexed8:
0
2529 for (int i = 0; i < d->colortable.size(); ++i) {
i < d->colortable.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
2530 if (!qIsGray(d->colortable.at(i)))
!qIsGray(d->colortable.at(i))Description
TRUEnever evaluated
FALSEnever evaluated
0
2531 return false;
never executed: return false;
0
2532 }
never executed: end of block
0
2533 return true;
never executed: return true;
0
2534 case Format_Alpha8:
never executed: case Format_Alpha8:
0
2535 return false;
never executed: return false;
0
2536 case Format_Grayscale8:
never executed: case Format_Grayscale8:
0
2537 return true;
never executed: return true;
0
2538 case Format_RGB32:
never executed: case Format_RGB32:
0
2539 case Format_ARGB32:
never executed: case Format_ARGB32:
0
2540 case Format_ARGB32_Premultiplied:
never executed: case Format_ARGB32_Premultiplied:
0
2541#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN-
2542 case Format_RGBX8888:
never executed: case Format_RGBX8888:
0
2543 case Format_RGBA8888:
never executed: case Format_RGBA8888:
0
2544 case Format_RGBA8888_Premultiplied:
never executed: case Format_RGBA8888_Premultiplied:
0
2545#endif-
2546 for (int j = 0; j < d->height; ++j) {
j < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
2547 const QRgb *b = (const QRgb *)constScanLine(j);-
2548 for (int i = 0; i < d->width; ++i) {
i < d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
2549 if (!qIsGray(b[i]))
!qIsGray(b[i])Description
TRUEnever evaluated
FALSEnever evaluated
0
2550 return false;
never executed: return false;
0
2551 }
never executed: end of block
0
2552 }
never executed: end of block
0
2553 return true;
never executed: return true;
0
2554 case Format_RGB16:
never executed: case Format_RGB16:
0
2555 for (int j = 0; j < d->height; ++j) {
j < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
2556 const quint16 *b = (const quint16 *)constScanLine(j);-
2557 for (int i = 0; i < d->width; ++i) {
i < d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
2558 if (!qIsGray(qConvertRgb16To32(b[i])))
!qIsGray(qConv...b16To32(b[i]))Description
TRUEnever evaluated
FALSEnever evaluated
0
2559 return false;
never executed: return false;
0
2560 }
never executed: end of block
0
2561 }
never executed: end of block
0
2562 return true;
never executed: return true;
0
2563 default:
never executed: default:
0
2564 break;
never executed: break;
0
2565 }-
2566-
2567 const int buffer_size = 2048;-
2568 uint buffer[buffer_size];-
2569 const QPixelLayout *layout = &qPixelLayouts[d->format];-
2570 FetchPixelsFunc fetch = qFetchPixels[layout->bpp];-
2571 for (int j = 0; j < d->height; ++j) {
j < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
2572 const uchar *b = constScanLine(j);-
2573 int x = 0;-
2574 while (x < d->width) {
x < d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
2575 int l = qMin(d->width - x, buffer_size);-
2576 const uint *ptr = fetch(buffer, b, x, l);-
2577 ptr = layout->convertToARGB32PM(buffer, ptr, l, layout, 0);-
2578 for (int i = 0; i < l; ++i) {
i < lDescription
TRUEnever evaluated
FALSEnever evaluated
0
2579 if (!qIsGray(ptr[i]))
!qIsGray(ptr[i])Description
TRUEnever evaluated
FALSEnever evaluated
0
2580 return false;
never executed: return false;
0
2581 }
never executed: end of block
0
2582 x += l;-
2583 }
never executed: end of block
0
2584 }
never executed: end of block
0
2585 return true;
never executed: return true;
0
2586}-
2587-
2588/*!-
2589 For 32-bit images, this function is equivalent to allGray().-
2590-
2591 For color indexed images, this function returns \c true if-
2592 color(i) is QRgb(i, i, i) for all indexes of the color table;-
2593 otherwise returns \c false.-
2594-
2595 \sa allGray(), {QImage#Image Formats}{Image Formats}-
2596*/-
2597bool QImage::isGrayscale() const-
2598{-
2599 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2600 return false;
never executed: return false;
0
2601-
2602 if (d->format == QImage::Format_Alpha8)
d->format == Q...:Format_Alpha8Description
TRUEnever evaluated
FALSEnever evaluated
0
2603 return false;
never executed: return false;
0
2604-
2605 if (d->format == QImage::Format_Grayscale8)
d->format == Q...mat_Grayscale8Description
TRUEnever evaluated
FALSEnever evaluated
0
2606 return true;
never executed: return true;
0
2607-
2608 switch (depth()) {-
2609 case 32:
never executed: case 32:
0
2610 case 24:
never executed: case 24:
0
2611 case 16:
never executed: case 16:
0
2612 return allGray();
never executed: return allGray();
0
2613 case 8: {
never executed: case 8:
0
2614 Q_ASSERT(d->format == QImage::Format_Indexed8);-
2615 for (int i = 0; i < colorCount(); i++)
i < colorCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
2616 if (d->colortable.at(i) != qRgb(i,i,i))
d->colortable....!= qRgb(i,i,i)Description
TRUEnever evaluated
FALSEnever evaluated
0
2617 return false;
never executed: return false;
0
2618 return true;
never executed: return true;
0
2619 }-
2620 }-
2621 return false;
never executed: return false;
0
2622}-
2623-
2624/*!-
2625 \fn QImage QImage::scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode,-
2626 Qt::TransformationMode transformMode) const-
2627 \overload-
2628-
2629 Returns a copy of the image scaled to a rectangle with the given-
2630 \a width and \a height according to the given \a aspectRatioMode-
2631 and \a transformMode.-
2632-
2633 If either the \a width or the \a height is zero or negative, this-
2634 function returns a null image.-
2635*/-
2636-
2637/*!-
2638 \fn QImage QImage::scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode,-
2639 Qt::TransformationMode transformMode) const-
2640-
2641 Returns a copy of the image scaled to a rectangle defined by the-
2642 given \a size according to the given \a aspectRatioMode and \a-
2643 transformMode.-
2644-
2645 \image qimage-scaling.png-
2646-
2647 \list-
2648 \li If \a aspectRatioMode is Qt::IgnoreAspectRatio, the image-
2649 is scaled to \a size.-
2650 \li If \a aspectRatioMode is Qt::KeepAspectRatio, the image is-
2651 scaled to a rectangle as large as possible inside \a size, preserving the aspect ratio.-
2652 \li If \a aspectRatioMode is Qt::KeepAspectRatioByExpanding,-
2653 the image is scaled to a rectangle as small as possible-
2654 outside \a size, preserving the aspect ratio.-
2655 \endlist-
2656-
2657 If the given \a size is empty, this function returns a null image.-
2658-
2659 \sa isNull(), {QImage#Image Transformations}{Image-
2660 Transformations}-
2661*/-
2662QImage QImage::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode) const-
2663{-
2664 if (!d) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2665 qWarning("QImage::scaled: Image is a null image");-
2666 return QImage();
never executed: return QImage();
0
2667 }-
2668 if (s.isEmpty())
s.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
2669 return QImage();
never executed: return QImage();
0
2670-
2671 QSize newSize = size();-
2672 newSize.scale(s, aspectMode);-
2673 newSize.rwidth() = qMax(newSize.width(), 1);-
2674 newSize.rheight() = qMax(newSize.height(), 1);-
2675 if (newSize == size())
newSize == size()Description
TRUEnever evaluated
FALSEnever evaluated
0
2676 return *this;
never executed: return *this;
0
2677-
2678 QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), (qreal)newSize.height() / height());-
2679 QImage img = transformed(wm, mode);-
2680 return img;
never executed: return img;
0
2681}-
2682-
2683/*!-
2684 \fn QImage QImage::scaledToWidth(int width, Qt::TransformationMode mode) const-
2685-
2686 Returns a scaled copy of the image. The returned image is scaled-
2687 to the given \a width using the specified transformation \a-
2688 mode.-
2689-
2690 This function automatically calculates the height of the image so-
2691 that its aspect ratio is preserved.-
2692-
2693 If the given \a width is 0 or negative, a null image is returned.-
2694-
2695 \sa {QImage#Image Transformations}{Image Transformations}-
2696*/-
2697QImage QImage::scaledToWidth(int w, Qt::TransformationMode mode) const-
2698{-
2699 if (!d) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2700 qWarning("QImage::scaleWidth: Image is a null image");-
2701 return QImage();
never executed: return QImage();
0
2702 }-
2703 if (w <= 0)
w <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2704 return QImage();
never executed: return QImage();
0
2705-
2706 qreal factor = (qreal) w / width();-
2707 QTransform wm = QTransform::fromScale(factor, factor);-
2708 return transformed(wm, mode);
never executed: return transformed(wm, mode);
0
2709}-
2710-
2711/*!-
2712 \fn QImage QImage::scaledToHeight(int height, Qt::TransformationMode mode) const-
2713-
2714 Returns a scaled copy of the image. The returned image is scaled-
2715 to the given \a height using the specified transformation \a-
2716 mode.-
2717-
2718 This function automatically calculates the width of the image so that-
2719 the ratio of the image is preserved.-
2720-
2721 If the given \a height is 0 or negative, a null image is returned.-
2722-
2723 \sa {QImage#Image Transformations}{Image Transformations}-
2724*/-
2725QImage QImage::scaledToHeight(int h, Qt::TransformationMode mode) const-
2726{-
2727 if (!d) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2728 qWarning("QImage::scaleHeight: Image is a null image");-
2729 return QImage();
never executed: return QImage();
0
2730 }-
2731 if (h <= 0)
h <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2732 return QImage();
never executed: return QImage();
0
2733-
2734 qreal factor = (qreal) h / height();-
2735 QTransform wm = QTransform::fromScale(factor, factor);-
2736 return transformed(wm, mode);
never executed: return transformed(wm, mode);
0
2737}-
2738-
2739-
2740/*!-
2741 \fn QMatrix QImage::trueMatrix(const QMatrix &matrix, int width, int height)-
2742-
2743 Returns the actual matrix used for transforming an image with the-
2744 given \a width, \a height and \a matrix.-
2745-
2746 When transforming an image using the transformed() function, the-
2747 transformation matrix is internally adjusted to compensate for-
2748 unwanted translation, i.e. transformed() returns the smallest-
2749 image containing all transformed points of the original image.-
2750 This function returns the modified matrix, which maps points-
2751 correctly from the original image into the new image.-
2752-
2753 \sa transformed(), {QImage#Image Transformations}{Image-
2754 Transformations}-
2755*/-
2756QMatrix QImage::trueMatrix(const QMatrix &matrix, int w, int h)-
2757{-
2758 return trueMatrix(QTransform(matrix), w, h).toAffine();
never executed: return trueMatrix(QTransform(matrix), w, h).toAffine();
0
2759}-
2760-
2761/*!-
2762 Returns a copy of the image that is transformed using the given-
2763 transformation \a matrix and transformation \a mode.-
2764-
2765 The transformation \a matrix is internally adjusted to compensate-
2766 for unwanted translation; i.e. the image produced is the smallest-
2767 image that contains all the transformed points of the original-
2768 image. Use the trueMatrix() function to retrieve the actual matrix-
2769 used for transforming an image.-
2770-
2771 \sa trueMatrix(), {QImage#Image Transformations}{Image-
2772 Transformations}-
2773*/-
2774QImage QImage::transformed(const QMatrix &matrix, Qt::TransformationMode mode) const-
2775{-
2776 return transformed(QTransform(matrix), mode);
never executed: return transformed(QTransform(matrix), mode);
0
2777}-
2778-
2779/*!-
2780 Builds and returns a 1-bpp mask from the alpha buffer in this-
2781 image. Returns a null image if the image's format is-
2782 QImage::Format_RGB32.-
2783-
2784 The \a flags argument is a bitwise-OR of the-
2785 Qt::ImageConversionFlags, and controls the conversion-
2786 process. Passing 0 for flags sets all the default options.-
2787-
2788 The returned image has little-endian bit order (i.e. the image's-
2789 format is QImage::Format_MonoLSB), which you can convert to-
2790 big-endian (QImage::Format_Mono) using the convertToFormat()-
2791 function.-
2792-
2793 \sa createHeuristicMask(), {QImage#Image Transformations}{Image-
2794 Transformations}-
2795*/-
2796QImage QImage::createAlphaMask(Qt::ImageConversionFlags flags) const-
2797{-
2798 if (!d || d->format == QImage::Format_RGB32)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
d->format == Q...::Format_RGB32Description
TRUEnever evaluated
FALSEnever evaluated
0
2799 return QImage();
never executed: return QImage();
0
2800-
2801 if (d->depth == 1) {
d->depth == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
2802 // A monochrome pixmap, with alpha channels on those two colors.-
2803 // Pretty unlikely, so use less efficient solution.-
2804 return convertToFormat(Format_Indexed8, flags).createAlphaMask(flags);
never executed: return convertToFormat(Format_Indexed8, flags).createAlphaMask(flags);
0
2805 }-
2806-
2807 QImage mask(d->width, d->height, Format_MonoLSB);-
2808 if (!mask.isNull())
!mask.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2809 dither_to_Mono(mask.d, d, flags, true);
never executed: dither_to_Mono(mask.d, d, flags, true);
0
2810 return mask;
never executed: return mask;
0
2811}-
2812-
2813#ifndef QT_NO_IMAGE_HEURISTIC_MASK-
2814/*!-
2815 Creates and returns a 1-bpp heuristic mask for this image.-
2816-
2817 The function works by selecting a color from one of the corners,-
2818 then chipping away pixels of that color starting at all the edges.-
2819 The four corners vote for which color is to be masked away. In-
2820 case of a draw (this generally means that this function is not-
2821 applicable to the image), the result is arbitrary.-
2822-
2823 The returned image has little-endian bit order (i.e. the image's-
2824 format is QImage::Format_MonoLSB), which you can convert to-
2825 big-endian (QImage::Format_Mono) using the convertToFormat()-
2826 function.-
2827-
2828 If \a clipTight is true (the default) the mask is just large-
2829 enough to cover the pixels; otherwise, the mask is larger than the-
2830 data pixels.-
2831-
2832 Note that this function disregards the alpha buffer.-
2833-
2834 \sa createAlphaMask(), {QImage#Image Transformations}{Image-
2835 Transformations}-
2836*/-
2837-
2838QImage QImage::createHeuristicMask(bool clipTight) const-
2839{-
2840 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2841 return QImage();
never executed: return QImage();
0
2842-
2843 if (d->depth != 32) {
d->depth != 32Description
TRUEnever evaluated
FALSEnever evaluated
0
2844 QImage img32 = convertToFormat(Format_RGB32);-
2845 return img32.createHeuristicMask(clipTight);
never executed: return img32.createHeuristicMask(clipTight);
0
2846 }-
2847-
2848#define PIX(x,y) (*((const QRgb*)scanLine(y)+x) & 0x00ffffff)-
2849-
2850 int w = width();-
2851 int h = height();-
2852 QImage m(w, h, Format_MonoLSB);-
2853 QIMAGE_SANITYCHECK_MEMORY(m);
never executed: return QImage();
(m).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2854 m.setColorCount(2);-
2855 m.setColor(0, QColor(Qt::color0).rgba());-
2856 m.setColor(1, QColor(Qt::color1).rgba());-
2857 m.fill(0xff);-
2858-
2859 QRgb background = PIX(0,0);-
2860 if (background != PIX(w-1,0) &&
background != ... & 0x00ffffff)Description
TRUEnever evaluated
FALSEnever evaluated
0
2861 background != PIX(0,h-1) &&
background != ... & 0x00ffffff)Description
TRUEnever evaluated
FALSEnever evaluated
0
2862 background != PIX(w-1,h-1)) {
background != ... & 0x00ffffff)Description
TRUEnever evaluated
FALSEnever evaluated
0
2863 background = PIX(w-1,0);-
2864 if (background != PIX(w-1,h-1) &&
background != ... & 0x00ffffff)Description
TRUEnever evaluated
FALSEnever evaluated
0
2865 background != PIX(0,h-1) &&
background != ... & 0x00ffffff)Description
TRUEnever evaluated
FALSEnever evaluated
0
2866 PIX(0,h-1) == PIX(w-1,h-1)) {
(*((const QRgb... & 0x00ffffff)Description
TRUEnever evaluated
FALSEnever evaluated
0
2867 background = PIX(w-1,h-1);-
2868 }
never executed: end of block
0
2869 }
never executed: end of block
0
2870-
2871 int x,y;-
2872 bool done = false;-
2873 uchar *ypp, *ypc, *ypn;-
2874 while(!done) {
!doneDescription
TRUEnever evaluated
FALSEnever evaluated
0
2875 done = true;-
2876 ypn = m.scanLine(0);-
2877 ypc = 0;-
2878 for (y = 0; y < h; y++) {
y < hDescription
TRUEnever evaluated
FALSEnever evaluated
0
2879 ypp = ypc;-
2880 ypc = ypn;-
2881 ypn = (y == h-1) ? 0 : m.scanLine(y+1);
(y == h-1)Description
TRUEnever evaluated
FALSEnever evaluated
0
2882 const QRgb *p = (const QRgb *)scanLine(y);-
2883 for (x = 0; x < w; x++) {
x < wDescription
TRUEnever evaluated
FALSEnever evaluated
0
2884 // slowness here - it's possible to do six of these tests-
2885 // together in one go. oh well.-
2886 if ((x == 0 || y == 0 || x == w-1 || y == h-1 ||
x == 0Description
TRUEnever evaluated
FALSEnever evaluated
y == 0Description
TRUEnever evaluated
FALSEnever evaluated
x == w-1Description
TRUEnever evaluated
FALSEnever evaluated
y == h-1Description
TRUEnever evaluated
FALSEnever evaluated
0
2887 !(*(ypc + ((x-1) >> 3)) & (1 << ((x-1) & 7))) ||
!(*(ypc + ((x-... ((x-1) & 7)))Description
TRUEnever evaluated
FALSEnever evaluated
0
2888 !(*(ypc + ((x+1) >> 3)) & (1 << ((x+1) & 7))) ||
!(*(ypc + ((x+... ((x+1) & 7)))Description
TRUEnever evaluated
FALSEnever evaluated
0
2889 !(*(ypp + (x >> 3)) & (1 << (x & 7))) ||
!(*(ypp + (x >...1 << (x & 7)))Description
TRUEnever evaluated
FALSEnever evaluated
0
2890 !(*(ypn + (x >> 3)) & (1 << (x & 7)))) &&
!(*(ypn + (x >...1 << (x & 7)))Description
TRUEnever evaluated
FALSEnever evaluated
0
2891 ( (*(ypc + (x >> 3)) & (1 << (x & 7)))) &&
( (*(ypc + (x ... << (x & 7))))Description
TRUEnever evaluated
FALSEnever evaluated
0
2892 ((*p & 0x00ffffff) == background)) {
((*p & 0x00fff...== background)Description
TRUEnever evaluated
FALSEnever evaluated
0
2893 done = false;-
2894 *(ypc + (x >> 3)) &= ~(1 << (x & 7));-
2895 }
never executed: end of block
0
2896 p++;-
2897 }
never executed: end of block
0
2898 }
never executed: end of block
0
2899 }
never executed: end of block
0
2900-
2901 if (!clipTight) {
!clipTightDescription
TRUEnever evaluated
FALSEnever evaluated
0
2902 ypn = m.scanLine(0);-
2903 ypc = 0;-
2904 for (y = 0; y < h; y++) {
y < hDescription
TRUEnever evaluated
FALSEnever evaluated
0
2905 ypp = ypc;-
2906 ypc = ypn;-
2907 ypn = (y == h-1) ? 0 : m.scanLine(y+1);
(y == h-1)Description
TRUEnever evaluated
FALSEnever evaluated
0
2908 const QRgb *p = (const QRgb *)scanLine(y);-
2909 for (x = 0; x < w; x++) {
x < wDescription
TRUEnever evaluated
FALSEnever evaluated
0
2910 if ((*p & 0x00ffffff) != background) {
(*p & 0x00ffff... != backgroundDescription
TRUEnever evaluated
FALSEnever evaluated
0
2911 if (x > 0)
x > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2912 *(ypc + ((x-1) >> 3)) |= (1 << ((x-1) & 7));
never executed: *(ypc + ((x-1) >> 3)) |= (1 << ((x-1) & 7));
0
2913 if (x < w-1)
x < w-1Description
TRUEnever evaluated
FALSEnever evaluated
0
2914 *(ypc + ((x+1) >> 3)) |= (1 << ((x+1) & 7));
never executed: *(ypc + ((x+1) >> 3)) |= (1 << ((x+1) & 7));
0
2915 if (y > 0)
y > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2916 *(ypp + (x >> 3)) |= (1 << (x & 7));
never executed: *(ypp + (x >> 3)) |= (1 << (x & 7));
0
2917 if (y < h-1)
y < h-1Description
TRUEnever evaluated
FALSEnever evaluated
0
2918 *(ypn + (x >> 3)) |= (1 << (x & 7));
never executed: *(ypn + (x >> 3)) |= (1 << (x & 7));
0
2919 }
never executed: end of block
0
2920 p++;-
2921 }
never executed: end of block
0
2922 }
never executed: end of block
0
2923 }
never executed: end of block
0
2924-
2925#undef PIX-
2926-
2927 return m;
never executed: return m;
0
2928}-
2929#endif //QT_NO_IMAGE_HEURISTIC_MASK-
2930-
2931/*!-
2932 Creates and returns a mask for this image based on the given \a-
2933 color value. If the \a mode is MaskInColor (the default value),-
2934 all pixels matching \a color will be opaque pixels in the mask. If-
2935 \a mode is MaskOutColor, all pixels matching the given color will-
2936 be transparent.-
2937-
2938 \sa createAlphaMask(), createHeuristicMask()-
2939*/-
2940-
2941QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode) const-
2942{-
2943 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
2944 return QImage();
never executed: return QImage();
0
2945 QImage maskImage(size(), QImage::Format_MonoLSB);-
2946 QIMAGE_SANITYCHECK_MEMORY(maskImage);
never executed: return QImage();
(maskImage).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
2947 maskImage.fill(0);-
2948 uchar *s = maskImage.bits();-
2949-
2950 if (depth() == 32) {
depth() == 32Description
TRUEnever evaluated
FALSEnever evaluated
0
2951 for (int h = 0; h < d->height; h++) {
h < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
2952 const uint *sl = (const uint *) scanLine(h);-
2953 for (int w = 0; w < d->width; w++) {
w < d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
2954 if (sl[w] == color)
sl[w] == colorDescription
TRUEnever evaluated
FALSEnever evaluated
0
2955 *(s + (w >> 3)) |= (1 << (w & 7));
never executed: *(s + (w >> 3)) |= (1 << (w & 7));
0
2956 }
never executed: end of block
0
2957 s += maskImage.bytesPerLine();-
2958 }
never executed: end of block
0
2959 } else {
never executed: end of block
0
2960 for (int h = 0; h < d->height; h++) {
h < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
2961 for (int w = 0; w < d->width; w++) {
w < d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
2962 if ((uint) pixel(w, h) == color)
(uint) pixel(w, h) == colorDescription
TRUEnever evaluated
FALSEnever evaluated
0
2963 *(s + (w >> 3)) |= (1 << (w & 7));
never executed: *(s + (w >> 3)) |= (1 << (w & 7));
0
2964 }
never executed: end of block
0
2965 s += maskImage.bytesPerLine();-
2966 }
never executed: end of block
0
2967 }
never executed: end of block
0
2968 if (mode == Qt::MaskOutColor)
mode == Qt::MaskOutColorDescription
TRUEnever evaluated
FALSEnever evaluated
0
2969 maskImage.invertPixels();
never executed: maskImage.invertPixels();
0
2970 return maskImage;
never executed: return maskImage;
0
2971}-
2972-
2973/*!-
2974 \fn QImage QImage::mirrored(bool horizontal = false, bool vertical = true) const-
2975 Returns a mirror of the image, mirrored in the horizontal and/or-
2976 the vertical direction depending on whether \a horizontal and \a-
2977 vertical are set to true or false.-
2978-
2979 Note that the original image is not changed.-
2980-
2981 \sa {QImage#Image Transformations}{Image Transformations}-
2982*/-
2983-
2984template<class T> inline void do_mirror_data(QImageData *dst, QImageData *src,-
2985 int dstX0, int dstY0,-
2986 int dstXIncr, int dstYIncr,-
2987 int w, int h)-
2988{-
2989 if (dst == src) {
dst == srcDescription
TRUEnever evaluated
FALSEnever evaluated
0
2990 // When mirroring in-place, stop in the middle for one of the directions, since we-
2991 // are swapping the bytes instead of merely copying.-
2992 const int srcXEnd = (dstX0 && !dstY0) ? w / 2 : w;-
2993 const int srcYEnd = dstY0 ? h / 2 : h;-
2994 for (int srcY = 0, dstY = dstY0; srcY < srcYEnd; ++srcY, dstY += dstYIncr) {
srcY < srcYEndDescription
TRUEnever evaluated
FALSEnever evaluated
0
2995 T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);-
2996 T *dstPtr = (T *) (dst->data + dstY * dst->bytes_per_line);-
2997 for (int srcX = 0, dstX = dstX0; srcX < srcXEnd; ++srcX, dstX += dstXIncr)
srcX < srcXEndDescription
TRUEnever evaluated
FALSEnever evaluated
0
2998 std::swap(srcPtr[srcX], dstPtr[dstX]);
never executed: std::swap(srcPtr[srcX], dstPtr[dstX]);
0
2999 }
never executed: end of block
0
3000 // If mirroring both ways, the middle line needs to be mirrored horizontally only.-
3001 if (dstX0 && dstY0 && (h & 1)) {
dstX0Description
TRUEnever evaluated
FALSEnever evaluated
dstY0Description
TRUEnever evaluated
FALSEnever evaluated
(h & 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
3002 int srcY = h / 2;-
3003 int srcXEnd2 = w / 2;-
3004 T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);-
3005 for (int srcX = 0, dstX = dstX0; srcX < srcXEnd2; ++srcX, dstX += dstXIncr)
srcX < srcXEnd2Description
TRUEnever evaluated
FALSEnever evaluated
0
3006 std::swap(srcPtr[srcX], srcPtr[dstX]);
never executed: std::swap(srcPtr[srcX], srcPtr[dstX]);
0
3007 }
never executed: end of block
0
3008 } else {
never executed: end of block
0
3009 for (int srcY = 0, dstY = dstY0; srcY < h; ++srcY, dstY += dstYIncr) {
srcY < hDescription
TRUEnever evaluated
FALSEnever evaluated
0
3010 T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line);-
3011 T *dstPtr = (T *) (dst->data + dstY * dst->bytes_per_line);-
3012 for (int srcX = 0, dstX = dstX0; srcX < w; ++srcX, dstX += dstXIncr)
srcX < wDescription
TRUEnever evaluated
FALSEnever evaluated
0
3013 dstPtr[dstX] = srcPtr[srcX];
never executed: dstPtr[dstX] = srcPtr[srcX];
0
3014 }
never executed: end of block
0
3015 }
never executed: end of block
0
3016}-
3017-
3018inline void do_mirror(QImageData *dst, QImageData *src, bool horizontal, bool vertical)-
3019{-
3020 Q_ASSERT(src->width == dst->width && src->height == dst->height && src->depth == dst->depth);-
3021 int w = src->width;-
3022 int h = src->height;-
3023 int depth = src->depth;-
3024-
3025 if (src->depth == 1) {
src->depth == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
3026 w = (w + 7) / 8; // byte aligned width-
3027 depth = 8;-
3028 }
never executed: end of block
0
3029-
3030 int dstX0 = 0, dstXIncr = 1;-
3031 int dstY0 = 0, dstYIncr = 1;-
3032 if (horizontal) {
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
3033 // 0 -> w-1, 1 -> w-2, 2 -> w-3, ...-
3034 dstX0 = w - 1;-
3035 dstXIncr = -1;-
3036 }
never executed: end of block
0
3037 if (vertical) {
verticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
3038 // 0 -> h-1, 1 -> h-2, 2 -> h-3, ...-
3039 dstY0 = h - 1;-
3040 dstYIncr = -1;-
3041 }
never executed: end of block
0
3042-
3043 switch (depth) {-
3044 case 32:
never executed: case 32:
0
3045 do_mirror_data<quint32>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);-
3046 break;
never executed: break;
0
3047 case 24:
never executed: case 24:
0
3048 do_mirror_data<quint24>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);-
3049 break;
never executed: break;
0
3050 case 16:
never executed: case 16:
0
3051 do_mirror_data<quint16>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);-
3052 break;
never executed: break;
0
3053 case 8:
never executed: case 8:
0
3054 do_mirror_data<quint8>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h);-
3055 break;
never executed: break;
0
3056 default:
never executed: default:
0
3057 Q_ASSERT(false);-
3058 break;
never executed: break;
0
3059 }-
3060-
3061 // The bytes are now all in the correct place. In addition, the bits in the individual-
3062 // bytes have to be flipped too when horizontally mirroring a 1 bit-per-pixel image.-
3063 if (horizontal && dst->depth == 1) {
horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
dst->depth == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
3064 Q_ASSERT(dst->format == QImage::Format_Mono || dst->format == QImage::Format_MonoLSB);-
3065 const int shift = 8 - (dst->width % 8);-
3066 const uchar *bitflip = qt_get_bitflip_array();-
3067 for (int y = 0; y < h; ++y) {
y < hDescription
TRUEnever evaluated
FALSEnever evaluated
0
3068 uchar *begin = dst->data + y * dst->bytes_per_line;-
3069 uchar *end = begin + dst->bytes_per_line;-
3070 for (uchar *p = begin; p < end; ++p) {
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
3071 *p = bitflip[*p];-
3072 // When the data is non-byte aligned, an extra bit shift (of the number of-
3073 // unused bits at the end) is needed for the entire scanline.-
3074 if (shift != 8 && p != begin) {
shift != 8Description
TRUEnever evaluated
FALSEnever evaluated
p != beginDescription
TRUEnever evaluated
FALSEnever evaluated
0
3075 if (dst->format == QImage::Format_Mono) {
dst->format ==...e::Format_MonoDescription
TRUEnever evaluated
FALSEnever evaluated
0
3076 for (int i = 0; i < shift; ++i) {
i < shiftDescription
TRUEnever evaluated
FALSEnever evaluated
0
3077 p[-1] <<= 1;-
3078 p[-1] |= (*p & (128 >> i)) >> (7 - i);-
3079 }
never executed: end of block
0
3080 } else {
never executed: end of block
0
3081 for (int i = 0; i < shift; ++i) {
i < shiftDescription
TRUEnever evaluated
FALSEnever evaluated
0
3082 p[-1] >>= 1;-
3083 p[-1] |= (*p & (1 << i)) << (7 - i);-
3084 }
never executed: end of block
0
3085 }
never executed: end of block
0
3086 }-
3087 }
never executed: end of block
0
3088 if (shift != 8) {
shift != 8Description
TRUEnever evaluated
FALSEnever evaluated
0
3089 if (dst->format == QImage::Format_Mono)
dst->format ==...e::Format_MonoDescription
TRUEnever evaluated
FALSEnever evaluated
0
3090 end[-1] <<= shift;
never executed: end[-1] <<= shift;
0
3091 else-
3092 end[-1] >>= shift;
never executed: end[-1] >>= shift;
0
3093 }-
3094 }
never executed: end of block
0
3095 }
never executed: end of block
0
3096}
never executed: end of block
0
3097-
3098/*!-
3099 \internal-
3100*/-
3101QImage QImage::mirrored_helper(bool horizontal, bool vertical) const-
3102{-
3103 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3104 return QImage();
never executed: return QImage();
0
3105-
3106 if ((d->width <= 1 && d->height <= 1) || (!horizontal && !vertical))
d->width <= 1Description
TRUEnever evaluated
FALSEnever evaluated
d->height <= 1Description
TRUEnever evaluated
FALSEnever evaluated
!horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
!verticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
3107 return *this;
never executed: return *this;
0
3108-
3109 // Create result image, copy colormap-
3110 QImage result(d->width, d->height, d->format);-
3111 QIMAGE_SANITYCHECK_MEMORY(result);
never executed: return QImage();
(result).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
3112-
3113 // check if we ran out of of memory..-
3114 if (!result.d)
!result.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3115 return QImage();
never executed: return QImage();
0
3116-
3117 result.d->colortable = d->colortable;-
3118 result.d->has_alpha_clut = d->has_alpha_clut;-
3119 copyMetadata(result.d, d);-
3120-
3121 do_mirror(result.d, d, horizontal, vertical);-
3122-
3123 return result;
never executed: return result;
0
3124}-
3125-
3126/*!-
3127 \internal-
3128*/-
3129void QImage::mirrored_inplace(bool horizontal, bool vertical)-
3130{-
3131 if (!d || (d->width <= 1 && d->height <= 1) || (!horizontal && !vertical))
!dDescription
TRUEnever evaluated
FALSEnever evaluated
d->width <= 1Description
TRUEnever evaluated
FALSEnever evaluated
d->height <= 1Description
TRUEnever evaluated
FALSEnever evaluated
!horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
!verticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
3132 return;
never executed: return;
0
3133-
3134 detach();-
3135 if (!d->own_data)
!d->own_dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
3136 *this = copy();
never executed: *this = copy();
0
3137-
3138 do_mirror(d, d, horizontal, vertical);-
3139}
never executed: end of block
0
3140-
3141/*!-
3142 \fn QImage QImage::rgbSwapped() const-
3143 Returns a QImage in which the values of the red and blue-
3144 components of all pixels have been swapped, effectively converting-
3145 an RGB image to an BGR image.-
3146-
3147 The original QImage is not changed.-
3148-
3149 \sa {QImage#Image Transformations}{Image Transformations}-
3150*/-
3151-
3152inline void rgbSwapped_generic(int width, int height, const QImage *src, QImage *dst, const QPixelLayout* layout)-
3153{-
3154 Q_ASSERT(layout->redWidth == layout->blueWidth);-
3155 FetchPixelsFunc fetch = qFetchPixels[layout->bpp];-
3156 StorePixelsFunc store = qStorePixels[layout->bpp];-
3157-
3158 const uint redBlueMask = (1 << layout->redWidth) - 1;-
3159 const uint alphaGreenMask = (((1 << layout->alphaWidth) - 1) << layout->alphaShift)-
3160 | (((1 << layout->greenWidth) - 1) << layout->greenShift);-
3161-
3162 const int buffer_size = 2048;-
3163 uint buffer[buffer_size];-
3164 for (int i = 0; i < height; ++i) {
i < heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
3165 uchar *q = dst->scanLine(i);-
3166 const uchar *p = src->constScanLine(i);-
3167 int x = 0;-
3168 while (x < width) {
x < widthDescription
TRUEnever evaluated
FALSEnever evaluated
0
3169 int l = qMin(width - x, buffer_size);-
3170 const uint *ptr = fetch(buffer, p, x, l);-
3171 for (int j = 0; j < l; ++j) {
j < lDescription
TRUEnever evaluated
FALSEnever evaluated
0
3172 uint red = (ptr[j] >> layout->redShift) & redBlueMask;-
3173 uint blue = (ptr[j] >> layout->blueShift) & redBlueMask;-
3174 buffer[j] = (ptr[j] & alphaGreenMask)-
3175 | (red << layout->blueShift)-
3176 | (blue << layout->redShift);-
3177 }
never executed: end of block
0
3178 store(q, buffer, x, l);-
3179 x += l;-
3180 }
never executed: end of block
0
3181 }
never executed: end of block
0
3182}
never executed: end of block
0
3183-
3184/*!-
3185 \internal-
3186*/-
3187QImage QImage::rgbSwapped_helper() const-
3188{-
3189 if (isNull())
isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
3190 return *this;
never executed: return *this;
0
3191-
3192 QImage res;-
3193-
3194 switch (d->format) {-
3195 case Format_Invalid:
never executed: case Format_Invalid:
0
3196 case NImageFormats:
never executed: case NImageFormats:
0
3197 Q_ASSERT(false);-
3198 break;
never executed: break;
0
3199 case Format_Alpha8:
never executed: case Format_Alpha8:
0
3200 case Format_Grayscale8:
never executed: case Format_Grayscale8:
0
3201 return *this;
never executed: return *this;
0
3202 case Format_Mono:
never executed: case Format_Mono:
0
3203 case Format_MonoLSB:
never executed: case Format_MonoLSB:
0
3204 case Format_Indexed8:
never executed: case Format_Indexed8:
0
3205 res = copy();-
3206 for (int i = 0; i < res.d->colortable.size(); i++) {
i < res.d->colortable.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
3207 QRgb c = res.d->colortable.at(i);-
3208 res.d->colortable[i] = QRgb(((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00));-
3209 }
never executed: end of block
0
3210 break;
never executed: break;
0
3211 case Format_RGB32:
never executed: case Format_RGB32:
0
3212 case Format_ARGB32:
never executed: case Format_ARGB32:
0
3213 case Format_ARGB32_Premultiplied:
never executed: case Format_ARGB32_Premultiplied:
0
3214#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN-
3215 case Format_RGBX8888:
never executed: case Format_RGBX8888:
0
3216 case Format_RGBA8888:
never executed: case Format_RGBA8888:
0
3217 case Format_RGBA8888_Premultiplied:
never executed: case Format_RGBA8888_Premultiplied:
0
3218#endif-
3219 res = QImage(d->width, d->height, d->format);-
3220 QIMAGE_SANITYCHECK_MEMORY(res);
never executed: return QImage();
(res).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
3221 for (int i = 0; i < d->height; i++) {
i < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
3222 uint *q = (uint*)res.scanLine(i);-
3223 const uint *p = (const uint*)constScanLine(i);-
3224 const uint *end = p + d->width;-
3225 while (p < end) {
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
3226 uint c = *p;-
3227 *q = ((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00);-
3228 p++;-
3229 q++;-
3230 }
never executed: end of block
0
3231 }
never executed: end of block
0
3232 break;
never executed: break;
0
3233 case Format_RGB16:
never executed: case Format_RGB16:
0
3234 res = QImage(d->width, d->height, d->format);-
3235 QIMAGE_SANITYCHECK_MEMORY(res);
never executed: return QImage();
(res).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
3236 for (int i = 0; i < d->height; i++) {
i < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
3237 ushort *q = (ushort*)res.scanLine(i);-
3238 const ushort *p = (const ushort*)constScanLine(i);-
3239 const ushort *end = p + d->width;-
3240 while (p < end) {
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
3241 ushort c = *p;-
3242 *q = ((c << 11) & 0xf800) | ((c >> 11) & 0x1f) | (c & 0x07e0);-
3243 p++;-
3244 q++;-
3245 }
never executed: end of block
0
3246 }
never executed: end of block
0
3247 break;
never executed: break;
0
3248 case Format_BGR30:
never executed: case Format_BGR30:
0
3249 case Format_A2BGR30_Premultiplied:
never executed: case Format_A2BGR30_Premultiplied:
0
3250 case Format_RGB30:
never executed: case Format_RGB30:
0
3251 case Format_A2RGB30_Premultiplied:
never executed: case Format_A2RGB30_Premultiplied:
0
3252 res = QImage(d->width, d->height, d->format);-
3253 QIMAGE_SANITYCHECK_MEMORY(res);
never executed: return QImage();
(res).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
3254 for (int i = 0; i < d->height; i++) {
i < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
3255 uint *q = (uint*)res.scanLine(i);-
3256 const uint *p = (const uint*)constScanLine(i);-
3257 const uint *end = p + d->width;-
3258 while (p < end) {
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
3259 *q = qRgbSwapRgb30(*p);-
3260 p++;-
3261 q++;-
3262 }
never executed: end of block
0
3263 }
never executed: end of block
0
3264 break;
never executed: break;
0
3265 default:
never executed: default:
0
3266 res = QImage(d->width, d->height, d->format);-
3267 rgbSwapped_generic(d->width, d->height, this, &res, &qPixelLayouts[d->format]);-
3268 break;
never executed: break;
0
3269 }-
3270 copyMetadata(res.d, d);-
3271 return res;
never executed: return res;
0
3272}-
3273-
3274/*!-
3275 \internal-
3276*/-
3277void QImage::rgbSwapped_inplace()-
3278{-
3279 if (isNull())
isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
3280 return;
never executed: return;
0
3281-
3282 detach();-
3283 if (!d->own_data)
!d->own_dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
3284 *this = copy();
never executed: *this = copy();
0
3285-
3286 switch (d->format) {-
3287 case Format_Invalid:
never executed: case Format_Invalid:
0
3288 case NImageFormats:
never executed: case NImageFormats:
0
3289 Q_ASSERT(false);-
3290 break;
never executed: break;
0
3291 case Format_Alpha8:
never executed: case Format_Alpha8:
0
3292 case Format_Grayscale8:
never executed: case Format_Grayscale8:
0
3293 return;
never executed: return;
0
3294 case Format_Mono:
never executed: case Format_Mono:
0
3295 case Format_MonoLSB:
never executed: case Format_MonoLSB:
0
3296 case Format_Indexed8:
never executed: case Format_Indexed8:
0
3297 for (int i = 0; i < d->colortable.size(); i++) {
i < d->colortable.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
3298 QRgb c = d->colortable.at(i);-
3299 d->colortable[i] = QRgb(((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00));-
3300 }
never executed: end of block
0
3301 break;
never executed: break;
0
3302 case Format_RGB32:
never executed: case Format_RGB32:
0
3303 case Format_ARGB32:
never executed: case Format_ARGB32:
0
3304 case Format_ARGB32_Premultiplied:
never executed: case Format_ARGB32_Premultiplied:
0
3305#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN-
3306 case Format_RGBX8888:
never executed: case Format_RGBX8888:
0
3307 case Format_RGBA8888:
never executed: case Format_RGBA8888:
0
3308 case Format_RGBA8888_Premultiplied:
never executed: case Format_RGBA8888_Premultiplied:
0
3309#endif-
3310 for (int i = 0; i < d->height; i++) {
i < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
3311 uint *p = (uint*)scanLine(i);-
3312 uint *end = p + d->width;-
3313 while (p < end) {
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
3314 uint c = *p;-
3315 *p = ((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00);-
3316 p++;-
3317 }
never executed: end of block
0
3318 }
never executed: end of block
0
3319 break;
never executed: break;
0
3320 case Format_RGB16:
never executed: case Format_RGB16:
0
3321 for (int i = 0; i < d->height; i++) {
i < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
3322 ushort *p = (ushort*)scanLine(i);-
3323 ushort *end = p + d->width;-
3324 while (p < end) {
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
3325 ushort c = *p;-
3326 *p = ((c << 11) & 0xf800) | ((c >> 11) & 0x1f) | (c & 0x07e0);-
3327 p++;-
3328 }
never executed: end of block
0
3329 }
never executed: end of block
0
3330 break;
never executed: break;
0
3331 case Format_BGR30:
never executed: case Format_BGR30:
0
3332 case Format_A2BGR30_Premultiplied:
never executed: case Format_A2BGR30_Premultiplied:
0
3333 case Format_RGB30:
never executed: case Format_RGB30:
0
3334 case Format_A2RGB30_Premultiplied:
never executed: case Format_A2RGB30_Premultiplied:
0
3335 for (int i = 0; i < d->height; i++) {
i < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
3336 uint *p = (uint*)scanLine(i);-
3337 uint *end = p + d->width;-
3338 while (p < end) {
p < endDescription
TRUEnever evaluated
FALSEnever evaluated
0
3339 *p = qRgbSwapRgb30(*p);-
3340 p++;-
3341 }
never executed: end of block
0
3342 }
never executed: end of block
0
3343 break;
never executed: break;
0
3344 default:
never executed: default:
0
3345 rgbSwapped_generic(d->width, d->height, this, this, &qPixelLayouts[d->format]);-
3346 break;
never executed: break;
0
3347 }-
3348}-
3349-
3350/*!-
3351 Loads an image from the file with the given \a fileName. Returns \c true if-
3352 the image was successfully loaded; otherwise invalidates the image-
3353 and returns \c false.-
3354-
3355 The loader attempts to read the image using the specified \a format, e.g.,-
3356 PNG or JPG. If \a format is not specified (which is the default), the-
3357 loader probes the file for a header to guess the file format.-
3358-
3359 The file name can either refer to an actual file on disk or to one-
3360 of the application's embedded resources. See the-
3361 \l{resources.html}{Resource System} overview for details on how to-
3362 embed images and other resource files in the application's-
3363 executable.-
3364-
3365 \sa {QImage#Reading and Writing Image Files}{Reading and Writing Image Files}-
3366*/-
3367-
3368bool QImage::load(const QString &fileName, const char* format)-
3369{-
3370 QImage image = QImageReader(fileName, format).read();-
3371 operator=(image);-
3372 return !isNull();
never executed: return !isNull();
0
3373}-
3374-
3375/*!-
3376 \overload-
3377-
3378 This function reads a QImage from the given \a device. This can,-
3379 for example, be used to load an image directly into a QByteArray.-
3380*/-
3381-
3382bool QImage::load(QIODevice* device, const char* format)-
3383{-
3384 QImage image = QImageReader(device, format).read();-
3385 operator=(image);-
3386 return !isNull();
never executed: return !isNull();
0
3387}-
3388-
3389/*!-
3390 \fn bool QImage::loadFromData(const uchar *data, int len, const char *format)-
3391-
3392 Loads an image from the first \a len bytes of the given binary \a-
3393 data. Returns \c true if the image was successfully loaded; otherwise-
3394 invalidates the image and returns \c false.-
3395-
3396 The loader attempts to read the image using the specified \a format, e.g.,-
3397 PNG or JPG. If \a format is not specified (which is the default), the-
3398 loader probes the file for a header to guess the file format.-
3399-
3400 \sa {QImage#Reading and Writing Image Files}{Reading and Writing Image Files}-
3401*/-
3402-
3403bool QImage::loadFromData(const uchar *data, int len, const char *format)-
3404{-
3405 QImage image = fromData(data, len, format);-
3406 operator=(image);-
3407 return !isNull();
never executed: return !isNull();
0
3408}-
3409-
3410/*!-
3411 \fn bool QImage::loadFromData(const QByteArray &data, const char *format)-
3412-
3413 \overload-
3414-
3415 Loads an image from the given QByteArray \a data.-
3416*/-
3417-
3418/*!-
3419 \fn QImage QImage::fromData(const uchar *data, int size, const char *format)-
3420-
3421 Constructs a QImage from the first \a size bytes of the given-
3422 binary \a data. The loader attempts to read the image using the-
3423 specified \a format. If \a format is not specified (which is the default),-
3424 the loader probes the file for a header to guess the file format.-
3425 binary \a data. The loader attempts to read the image, either using the-
3426 optional image \a format specified or by determining the image format from-
3427 the data.-
3428-
3429 If \a format is not specified (which is the default), the loader probes the-
3430 file for a header to determine the file format. If \a format is specified,-
3431 it must be one of the values returned by QImageReader::supportedImageFormats().-
3432-
3433 If the loading of the image fails, the image returned will be a null image.-
3434-
3435 \sa load(), save(), {QImage#Reading and Writing Image Files}{Reading and Writing Image Files}-
3436 */-
3437-
3438QImage QImage::fromData(const uchar *data, int size, const char *format)-
3439{-
3440 QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(data), size);-
3441 QBuffer b;-
3442 b.setData(a);-
3443 b.open(QIODevice::ReadOnly);-
3444 return QImageReader(&b, format).read();
never executed: return QImageReader(&b, format).read();
0
3445}-
3446-
3447/*!-
3448 \fn QImage QImage::fromData(const QByteArray &data, const char *format)-
3449-
3450 \overload-
3451-
3452 Loads an image from the given QByteArray \a data.-
3453*/-
3454-
3455/*!-
3456 Saves the image to the file with the given \a fileName, using the-
3457 given image file \a format and \a quality factor. If \a format is-
3458 0, QImage will attempt to guess the format by looking at \a fileName's-
3459 suffix.-
3460-
3461 The \a quality factor must be in the range 0 to 100 or -1. Specify-
3462 0 to obtain small compressed files, 100 for large uncompressed-
3463 files, and -1 (the default) to use the default settings.-
3464-
3465 Returns \c true if the image was successfully saved; otherwise-
3466 returns \c false.-
3467-
3468 \sa {QImage#Reading and Writing Image Files}{Reading and Writing-
3469 Image Files}-
3470*/-
3471bool QImage::save(const QString &fileName, const char *format, int quality) const-
3472{-
3473 if (isNull())
isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
3474 return false;
never executed: return false;
0
3475 QImageWriter writer(fileName, format);-
3476 return d->doImageIO(this, &writer, quality);
never executed: return d->doImageIO(this, &writer, quality);
0
3477}-
3478-
3479/*!-
3480 \overload-
3481-
3482 This function writes a QImage to the given \a device.-
3483-
3484 This can, for example, be used to save an image directly into a-
3485 QByteArray:-
3486-
3487 \snippet image/image.cpp 0-
3488*/-
3489-
3490bool QImage::save(QIODevice* device, const char* format, int quality) const-
3491{-
3492 if (isNull())
isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
3493 return false; // nothing to save
never executed: return false;
0
3494 QImageWriter writer(device, format);-
3495 return d->doImageIO(this, &writer, quality);
never executed: return d->doImageIO(this, &writer, quality);
0
3496}-
3497-
3498/* \internal-
3499*/-
3500-
3501bool QImageData::doImageIO(const QImage *image, QImageWriter *writer, int quality) const-
3502{-
3503 if (quality > 100 || quality < -1)
quality > 100Description
TRUEnever evaluated
FALSEnever evaluated
quality < -1Description
TRUEnever evaluated
FALSEnever evaluated
0
3504 qWarning("QPixmap::save: Quality out of range [-1, 100]");
never executed: QMessageLogger(__FILE__, 3504, __PRETTY_FUNCTION__).warning("QPixmap::save: Quality out of range [-1, 100]");
0
3505 if (quality >= 0)
quality >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
3506 writer->setQuality(qMin(quality,100));
never executed: writer->setQuality(qMin(quality,100));
0
3507 return writer->write(*image);
never executed: return writer->write(*image);
0
3508}-
3509-
3510/*****************************************************************************-
3511 QImage stream functions-
3512 *****************************************************************************/-
3513#if !defined(QT_NO_DATASTREAM)-
3514/*!-
3515 \fn QDataStream &operator<<(QDataStream &stream, const QImage &image)-
3516 \relates QImage-
3517-
3518 Writes the given \a image to the given \a stream as a PNG image,-
3519 or as a BMP image if the stream's version is 1. Note that writing-
3520 the stream to a file will not produce a valid image file.-
3521-
3522 \sa QImage::save(), {Serializing Qt Data Types}-
3523*/-
3524-
3525QDataStream &operator<<(QDataStream &s, const QImage &image)-
3526{-
3527 if (s.version() >= 5) {
s.version() >= 5Description
TRUEnever evaluated
FALSEnever evaluated
0
3528 if (image.isNull()) {
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
3529 s << (qint32) 0; // null image marker-
3530 return s;
never executed: return s;
0
3531 } else {-
3532 s << (qint32) 1;-
3533 // continue ...-
3534 }
never executed: end of block
0
3535 }-
3536 QImageWriter writer(s.device(), s.version() == 1 ? "bmp" : "png");-
3537 writer.write(image);-
3538 return s;
never executed: return s;
0
3539}-
3540-
3541/*!-
3542 \fn QDataStream &operator>>(QDataStream &stream, QImage &image)-
3543 \relates QImage-
3544-
3545 Reads an image from the given \a stream and stores it in the given-
3546 \a image.-
3547-
3548 \sa QImage::load(), {Serializing Qt Data Types}-
3549*/-
3550-
3551QDataStream &operator>>(QDataStream &s, QImage &image)-
3552{-
3553 if (s.version() >= 5) {
s.version() >= 5Description
TRUEnever evaluated
FALSEnever evaluated
0
3554 qint32 nullMarker;-
3555 s >> nullMarker;-
3556 if (!nullMarker) {
!nullMarkerDescription
TRUEnever evaluated
FALSEnever evaluated
0
3557 image = QImage(); // null image-
3558 return s;
never executed: return s;
0
3559 }-
3560 }
never executed: end of block
0
3561 image = QImageReader(s.device(), 0).read();-
3562 return s;
never executed: return s;
0
3563}-
3564#endif // QT_NO_DATASTREAM-
3565-
3566-
3567-
3568/*!-
3569 \fn bool QImage::operator==(const QImage & image) const-
3570-
3571 Returns \c true if this image and the given \a image have the same-
3572 contents; otherwise returns \c false.-
3573-
3574 The comparison can be slow, unless there is some obvious-
3575 difference (e.g. different size or format), in which case the-
3576 function will return quickly.-
3577-
3578 \sa operator=()-
3579*/-
3580-
3581bool QImage::operator==(const QImage & i) const-
3582{-
3583 // same object, or shared?-
3584 if (i.d == d)
i.d == dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3585 return true;
never executed: return true;
0
3586 if (!i.d || !d)
!i.dDescription
TRUEnever evaluated
FALSEnever evaluated
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3587 return false;
never executed: return false;
0
3588-
3589 // obviously different stuff?-
3590 if (i.d->height != d->height || i.d->width != d->width || i.d->format != d->format)
i.d->height != d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
i.d->width != d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
i.d->format != d->formatDescription
TRUEnever evaluated
FALSEnever evaluated
0
3591 return false;
never executed: return false;
0
3592-
3593 if (d->format != Format_RGB32) {
d->format != Format_RGB32Description
TRUEnever evaluated
FALSEnever evaluated
0
3594 if (d->format >= Format_ARGB32) { // all bits defined
d->format >= Format_ARGB32Description
TRUEnever evaluated
FALSEnever evaluated
0
3595 const int n = d->width * d->depth / 8;-
3596 if (n == d->bytes_per_line && n == i.d->bytes_per_line) {
n == d->bytes_per_lineDescription
TRUEnever evaluated
FALSEnever evaluated
n == i.d->bytes_per_lineDescription
TRUEnever evaluated
FALSEnever evaluated
0
3597 if (memcmp(bits(), i.bits(), d->nbytes))
memcmp(bits(),...(), d->nbytes)Description
TRUEnever evaluated
FALSEnever evaluated
0
3598 return false;
never executed: return false;
0
3599 } else {
never executed: end of block
0
3600 for (int y = 0; y < d->height; ++y) {
y < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
3601 if (memcmp(scanLine(y), i.scanLine(y), n))
memcmp(scanLin...canLine(y), n)Description
TRUEnever evaluated
FALSEnever evaluated
0
3602 return false;
never executed: return false;
0
3603 }
never executed: end of block
0
3604 }
never executed: end of block
0
3605 } else {-
3606 const int w = width();-
3607 const int h = height();-
3608 const QVector<QRgb> &colortable = d->colortable;-
3609 const QVector<QRgb> &icolortable = i.d->colortable;-
3610 for (int y=0; y<h; ++y) {
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
0
3611 for (int x=0; x<w; ++x) {
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
3612 if (colortable[pixelIndex(x, y)] != icolortable[i.pixelIndex(x, y)])
colortable[pix...elIndex(x, y)]Description
TRUEnever evaluated
FALSEnever evaluated
0
3613 return false;
never executed: return false;
0
3614 }
never executed: end of block
0
3615 }
never executed: end of block
0
3616 }
never executed: end of block
0
3617 } else {-
3618 //alpha channel undefined, so we must mask it out-
3619 for(int l = 0; l < d->height; l++) {
l < d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
3620 int w = d->width;-
3621 const uint *p1 = reinterpret_cast<const uint*>(scanLine(l));-
3622 const uint *p2 = reinterpret_cast<const uint*>(i.scanLine(l));-
3623 while (w--) {
w--Description
TRUEnever evaluated
FALSEnever evaluated
0
3624 if ((*p1++ & 0x00ffffff) != (*p2++ & 0x00ffffff))
(*p1++ & 0x00f... & 0x00ffffff)Description
TRUEnever evaluated
FALSEnever evaluated
0
3625 return false;
never executed: return false;
0
3626 }
never executed: end of block
0
3627 }
never executed: end of block
0
3628 }
never executed: end of block
0
3629 return true;
never executed: return true;
0
3630}-
3631-
3632-
3633/*!-
3634 \fn bool QImage::operator!=(const QImage & image) const-
3635-
3636 Returns \c true if this image and the given \a image have different-
3637 contents; otherwise returns \c false.-
3638-
3639 The comparison can be slow, unless there is some obvious-
3640 difference, such as different widths, in which case the function-
3641 will return quickly.-
3642-
3643 \sa operator=()-
3644*/-
3645-
3646bool QImage::operator!=(const QImage & i) const-
3647{-
3648 return !(*this == i);
never executed: return !(*this == i);
0
3649}-
3650-
3651-
3652-
3653-
3654/*!-
3655 Returns the number of pixels that fit horizontally in a physical-
3656 meter. Together with dotsPerMeterY(), this number defines the-
3657 intended scale and aspect ratio of the image.-
3658-
3659 \sa setDotsPerMeterX(), {QImage#Image Information}{Image-
3660 Information}-
3661*/-
3662int QImage::dotsPerMeterX() const-
3663{-
3664 return d ? qRound(d->dpmx) : 0;
never executed: return d ? qRound(d->dpmx) : 0;
0
3665}-
3666-
3667/*!-
3668 Returns the number of pixels that fit vertically in a physical-
3669 meter. Together with dotsPerMeterX(), this number defines the-
3670 intended scale and aspect ratio of the image.-
3671-
3672 \sa setDotsPerMeterY(), {QImage#Image Information}{Image-
3673 Information}-
3674*/-
3675int QImage::dotsPerMeterY() const-
3676{-
3677 return d ? qRound(d->dpmy) : 0;
never executed: return d ? qRound(d->dpmy) : 0;
0
3678}-
3679-
3680/*!-
3681 Sets the number of pixels that fit horizontally in a physical-
3682 meter, to \a x.-
3683-
3684 Together with dotsPerMeterY(), this number defines the intended-
3685 scale and aspect ratio of the image, and determines the scale-
3686 at which QPainter will draw graphics on the image. It does not-
3687 change the scale or aspect ratio of the image when it is rendered-
3688 on other paint devices.-
3689-
3690 \sa dotsPerMeterX(), {QImage#Image Information}{Image Information}-
3691*/-
3692void QImage::setDotsPerMeterX(int x)-
3693{-
3694 if (!d || !x)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!xDescription
TRUEnever evaluated
FALSEnever evaluated
0
3695 return;
never executed: return;
0
3696 detach();-
3697-
3698 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3699 d->dpmx = x;
never executed: d->dpmx = x;
0
3700}
never executed: end of block
0
3701-
3702/*!-
3703 Sets the number of pixels that fit vertically in a physical meter,-
3704 to \a y.-
3705-
3706 Together with dotsPerMeterX(), this number defines the intended-
3707 scale and aspect ratio of the image, and determines the scale-
3708 at which QPainter will draw graphics on the image. It does not-
3709 change the scale or aspect ratio of the image when it is rendered-
3710 on other paint devices.-
3711-
3712 \sa dotsPerMeterY(), {QImage#Image Information}{Image Information}-
3713*/-
3714void QImage::setDotsPerMeterY(int y)-
3715{-
3716 if (!d || !y)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!yDescription
TRUEnever evaluated
FALSEnever evaluated
0
3717 return;
never executed: return;
0
3718 detach();-
3719-
3720 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3721 d->dpmy = y;
never executed: d->dpmy = y;
0
3722}
never executed: end of block
0
3723-
3724/*!-
3725 \fn QPoint QImage::offset() const-
3726-
3727 Returns the number of pixels by which the image is intended to be-
3728 offset by when positioning relative to other images.-
3729-
3730 \sa setOffset(), {QImage#Image Information}{Image Information}-
3731*/-
3732QPoint QImage::offset() const-
3733{-
3734 return d ? d->offset : QPoint();
never executed: return d ? d->offset : QPoint();
0
3735}-
3736-
3737-
3738/*!-
3739 \fn void QImage::setOffset(const QPoint& offset)-
3740-
3741 Sets the number of pixels by which the image is intended to be-
3742 offset by when positioning relative to other images, to \a offset.-
3743-
3744 \sa offset(), {QImage#Image Information}{Image Information}-
3745*/-
3746void QImage::setOffset(const QPoint& p)-
3747{-
3748 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3749 return;
never executed: return;
0
3750 detach();-
3751-
3752 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3753 d->offset = p;
never executed: d->offset = p;
0
3754}
never executed: end of block
0
3755-
3756/*!-
3757 Returns the text keys for this image.-
3758-
3759 You can use these keys with text() to list the image text for a-
3760 certain key.-
3761-
3762 \sa text()-
3763*/-
3764QStringList QImage::textKeys() const-
3765{-
3766 return d ? QStringList(d->text.keys()) : QStringList();
never executed: return d ? QStringList(d->text.keys()) : QStringList();
0
3767}-
3768-
3769/*!-
3770 Returns the image text associated with the given \a key. If the-
3771 specified \a key is an empty string, the whole image text is-
3772 returned, with each key-text pair separated by a newline.-
3773-
3774 \sa setText(), textKeys()-
3775*/-
3776QString QImage::text(const QString &key) const-
3777{-
3778 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3779 return QString();
never executed: return QString();
0
3780-
3781 if (!key.isEmpty())
!key.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
3782 return d->text.value(key);
never executed: return d->text.value(key);
0
3783-
3784 QString tmp;-
3785 for (auto it = d->text.begin(), end = d->text.end(); it != end; ++it)
it != endDescription
TRUEnever evaluated
FALSEnever evaluated
0
3786 tmp += it.key() + QLatin1String(": ") + it.value().simplified() + QLatin1String("\n\n");
never executed: tmp += it.key() + QLatin1String(": ") + it.value().simplified() + QLatin1String("\n\n");
0
3787 if (!tmp.isEmpty())
!tmp.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
3788 tmp.chop(2); // remove final \n\n
never executed: tmp.chop(2);
0
3789 return tmp;
never executed: return tmp;
0
3790}-
3791-
3792/*!-
3793 \fn void QImage::setText(const QString &key, const QString &text)-
3794-
3795 Sets the image text to the given \a text and associate it with the-
3796 given \a key.-
3797-
3798 If you just want to store a single text block (i.e., a "comment"-
3799 or just a description), you can either pass an empty key, or use a-
3800 generic key like "Description".-
3801-
3802 The image text is embedded into the image data when you-
3803 call save() or QImageWriter::write().-
3804-
3805 Not all image formats support embedded text. You can find out-
3806 if a specific image or format supports embedding text-
3807 by using QImageWriter::supportsOption(). We give an example:-
3808-
3809 \snippet image/supportedformat.cpp 0-
3810-
3811 You can use QImageWriter::supportedImageFormats() to find out-
3812 which image formats are available to you.-
3813-
3814 \sa text(), textKeys()-
3815*/-
3816void QImage::setText(const QString &key, const QString &value)-
3817{-
3818 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3819 return;
never executed: return;
0
3820 detach();-
3821-
3822 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3823 d->text.insert(key, value);
never executed: d->text.insert(key, value);
0
3824}
never executed: end of block
0
3825-
3826/*!-
3827 \fn QString QImage::text(const char* key, const char* language) const-
3828 \obsolete-
3829-
3830 Returns the text recorded for the given \a key in the given \a-
3831 language, or in a default language if \a language is 0.-
3832-
3833 Use text() instead.-
3834-
3835 The language the text is recorded in is no longer relevant since-
3836 the text is always set using QString and UTF-8 representation.-
3837*/-
3838-
3839/*!-
3840 \fn QString QImage::text(const QImageTextKeyLang& keywordAndLanguage) const-
3841 \overload-
3842 \obsolete-
3843-
3844 Returns the text recorded for the given \a keywordAndLanguage.-
3845-
3846 Use text() instead.-
3847-
3848 The language the text is recorded in is no longer relevant since-
3849 the text is always set using QString and UTF-8 representation.-
3850*/-
3851-
3852/*!-
3853 \fn void QImage::setText(const char* key, const char* language, const QString& text)-
3854 \obsolete-
3855-
3856 Sets the image text to the given \a text and associate it with the-
3857 given \a key. The text is recorded in the specified \a language,-
3858 or in a default language if \a language is 0.-
3859-
3860 Use setText() instead.-
3861-
3862 The language the text is recorded in is no longer relevant since-
3863 the text is always set using QString and UTF-8 representation.-
3864-
3865 \omit-
3866 Records string \a for the keyword \a key. The \a key should be-
3867 a portable keyword recognizable by other software - some suggested-
3868 values can be found in-
3869 \l{http://www.libpng.org/pub/png/spec/1.2/png-1.2-pdg.html#C.Anc-text}-
3870 {the PNG specification}. \a s can be any text. \a lang should-
3871 specify the language code (see-
3872 \l{http://www.rfc-editor.org/rfc/rfc1766.txt}{RFC 1766}) or 0.-
3873 \endomit-
3874*/-
3875-
3876/*-
3877 Sets the image bits to the \a pixmap contents and returns a-
3878 reference to the image.-
3879-
3880 If the image shares data with other images, it will first-
3881 dereference the shared data.-
3882-
3883 Makes a call to QPixmap::convertToImage().-
3884*/-
3885-
3886/*!-
3887 \internal-
3888-
3889 Used by QPainter to retrieve a paint engine for the image.-
3890*/-
3891-
3892QPaintEngine *QImage::paintEngine() const-
3893{-
3894 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3895 return 0;
never executed: return 0;
0
3896-
3897 if (!d->paintEngine) {
!d->paintEngineDescription
TRUEnever evaluated
FALSEnever evaluated
0
3898 QPaintDevice *paintDevice = const_cast<QImage *>(this);-
3899 QPaintEngine *paintEngine = 0;-
3900 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();-
3901 if (platformIntegration)
platformIntegrationDescription
TRUEnever evaluated
FALSEnever evaluated
0
3902 paintEngine = platformIntegration->createImagePaintEngine(paintDevice);
never executed: paintEngine = platformIntegration->createImagePaintEngine(paintDevice);
0
3903 d->paintEngine = paintEngine ? paintEngine : new QRasterPaintEngine(paintDevice);
paintEngineDescription
TRUEnever evaluated
FALSEnever evaluated
0
3904 }
never executed: end of block
0
3905-
3906 return d->paintEngine;
never executed: return d->paintEngine;
0
3907}-
3908-
3909-
3910/*!-
3911 \internal-
3912-
3913 Returns the size for the specified \a metric on the device.-
3914*/-
3915int QImage::metric(PaintDeviceMetric metric) const-
3916{-
3917 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
3918 return 0;
never executed: return 0;
0
3919-
3920 switch (metric) {-
3921 case PdmWidth:
never executed: case PdmWidth:
0
3922 return d->width;
never executed: return d->width;
0
3923-
3924 case PdmHeight:
never executed: case PdmHeight:
0
3925 return d->height;
never executed: return d->height;
0
3926-
3927 case PdmWidthMM:
never executed: case PdmWidthMM:
0
3928 return qRound(d->width * 1000 / d->dpmx);
never executed: return qRound(d->width * 1000 / d->dpmx);
0
3929-
3930 case PdmHeightMM:
never executed: case PdmHeightMM:
0
3931 return qRound(d->height * 1000 / d->dpmy);
never executed: return qRound(d->height * 1000 / d->dpmy);
0
3932-
3933 case PdmNumColors:
never executed: case PdmNumColors:
0
3934 return d->colortable.size();
never executed: return d->colortable.size();
0
3935-
3936 case PdmDepth:
never executed: case PdmDepth:
0
3937 return d->depth;
never executed: return d->depth;
0
3938-
3939 case PdmDpiX:
never executed: case PdmDpiX:
0
3940 return qRound(d->dpmx * 0.0254);
never executed: return qRound(d->dpmx * 0.0254);
0
3941 break;
dead code: break;
-
3942-
3943 case PdmDpiY:
never executed: case PdmDpiY:
0
3944 return qRound(d->dpmy * 0.0254);
never executed: return qRound(d->dpmy * 0.0254);
0
3945 break;
dead code: break;
-
3946-
3947 case PdmPhysicalDpiX:
never executed: case PdmPhysicalDpiX:
0
3948 return qRound(d->dpmx * 0.0254);
never executed: return qRound(d->dpmx * 0.0254);
0
3949 break;
dead code: break;
-
3950-
3951 case PdmPhysicalDpiY:
never executed: case PdmPhysicalDpiY:
0
3952 return qRound(d->dpmy * 0.0254);
never executed: return qRound(d->dpmy * 0.0254);
0
3953 break;
dead code: break;
-
3954-
3955 case PdmDevicePixelRatio:
never executed: case PdmDevicePixelRatio:
0
3956 return d->devicePixelRatio;
never executed: return d->devicePixelRatio;
0
3957 break;
dead code: break;
-
3958-
3959 case PdmDevicePixelRatioScaled:
never executed: case PdmDevicePixelRatioScaled:
0
3960 return d->devicePixelRatio * QPaintDevice::devicePixelRatioFScale();
never executed: return d->devicePixelRatio * QPaintDevice::devicePixelRatioFScale();
0
3961 break;
dead code: break;
-
3962-
3963 default:
never executed: default:
0
3964 qWarning("QImage::metric(): Unhandled metric type %d", metric);-
3965 break;
never executed: break;
0
3966 }-
3967 return 0;
never executed: return 0;
0
3968}-
3969-
3970-
3971-
3972/*****************************************************************************-
3973 QPixmap (and QImage) helper functions-
3974 *****************************************************************************/-
3975/*-
3976 This internal function contains the common (i.e. platform independent) code-
3977 to do a transformation of pixel data. It is used by QPixmap::transform() and by-
3978 QImage::transform().-
3979-
3980 \a trueMat is the true transformation matrix (see QPixmap::trueMatrix()) and-
3981 \a xoffset is an offset to the matrix.-
3982-
3983 \a msbfirst specifies for 1bpp images, if the MSB or LSB comes first and \a-
3984 depth specifies the colordepth of the data.-
3985-
3986 \a dptr is a pointer to the destination data, \a dbpl specifies the bits per-
3987 line for the destination data, \a p_inc is the offset that we advance for-
3988 every scanline and \a dHeight is the height of the destination image.-
3989-
3990 \a sprt is the pointer to the source data, \a sbpl specifies the bits per-
3991 line of the source data, \a sWidth and \a sHeight are the width and height of-
3992 the source data.-
3993*/-
3994-
3995#undef IWX_MSB-
3996#define IWX_MSB(b) if (trigx < maxws && trigy < maxhs) { \-
3997 if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & \-
3998 (1 << (7-((trigx>>12)&7)))) \-
3999 *dptr |= b; \-
4000 } \-
4001 trigx += m11; \-
4002 trigy += m12;-
4003 // END OF MACRO-
4004#undef IWX_LSB-
4005#define IWX_LSB(b) if (trigx < maxws && trigy < maxhs) { \-
4006 if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & \-
4007 (1 << ((trigx>>12)&7))) \-
4008 *dptr |= b; \-
4009 } \-
4010 trigx += m11; \-
4011 trigy += m12;-
4012 // END OF MACRO-
4013#undef IWX_PIX-
4014#define IWX_PIX(b) if (trigx < maxws && trigy < maxhs) { \-
4015 if ((*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & \-
4016 (1 << (7-((trigx>>12)&7)))) == 0) \-
4017 *dptr &= ~b; \-
4018 } \-
4019 trigx += m11; \-
4020 trigy += m12;-
4021 // END OF MACRO-
4022bool qt_xForm_helper(const QTransform &trueMat, int xoffset, int type, int depth,-
4023 uchar *dptr, int dbpl, int p_inc, int dHeight,-
4024 const uchar *sptr, int sbpl, int sWidth, int sHeight)-
4025{-
4026 int m11 = int(trueMat.m11()*4096.0);-
4027 int m12 = int(trueMat.m12()*4096.0);-
4028 int m21 = int(trueMat.m21()*4096.0);-
4029 int m22 = int(trueMat.m22()*4096.0);-
4030 int dx = qRound(trueMat.dx()*4096.0);-
4031 int dy = qRound(trueMat.dy()*4096.0);-
4032-
4033 int m21ydx = dx + (xoffset<<16) + (m11 + m21) / 2;-
4034 int m22ydy = dy + (m12 + m22) / 2;-
4035 uint trigx;-
4036 uint trigy;-
4037 uint maxws = sWidth<<12;-
4038 uint maxhs = sHeight<<12;-
4039-
4040 for (int y=0; y<dHeight; y++) { // for each target scanline
y<dHeightDescription
TRUEnever evaluated
FALSEnever evaluated
0
4041 trigx = m21ydx;-
4042 trigy = m22ydy;-
4043 uchar *maxp = dptr + dbpl;-
4044 if (depth != 1) {
depth != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
4045 switch (depth) {-
4046 case 8: // 8 bpp transform
never executed: case 8:
0
4047 while (dptr < maxp) {
dptr < maxpDescription
TRUEnever evaluated
FALSEnever evaluated
0
4048 if (trigx < maxws && trigy < maxhs)
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4049 *dptr = *(sptr+sbpl*(trigy>>12)+(trigx>>12));
never executed: *dptr = *(sptr+sbpl*(trigy>>12)+(trigx>>12));
0
4050 trigx += m11;-
4051 trigy += m12;-
4052 dptr++;-
4053 }
never executed: end of block
0
4054 break;
never executed: break;
0
4055-
4056 case 16: // 16 bpp transform
never executed: case 16:
0
4057 while (dptr < maxp) {
dptr < maxpDescription
TRUEnever evaluated
FALSEnever evaluated
0
4058 if (trigx < maxws && trigy < maxhs)
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4059 *((ushort*)dptr) = *((const ushort *)(sptr+sbpl*(trigy>>12) +
never executed: *((ushort*)dptr) = *((const ushort *)(sptr+sbpl*(trigy>>12) + ((trigx>>12)<<1)));
0
4060 ((trigx>>12)<<1)));
never executed: *((ushort*)dptr) = *((const ushort *)(sptr+sbpl*(trigy>>12) + ((trigx>>12)<<1)));
0
4061 trigx += m11;-
4062 trigy += m12;-
4063 dptr++;-
4064 dptr++;-
4065 }
never executed: end of block
0
4066 break;
never executed: break;
0
4067-
4068 case 24: // 24 bpp transform
never executed: case 24:
0
4069 while (dptr < maxp) {
dptr < maxpDescription
TRUEnever evaluated
FALSEnever evaluated
0
4070 if (trigx < maxws && trigy < maxhs) {
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4071 const uchar *p2 = sptr+sbpl*(trigy>>12) + ((trigx>>12)*3);-
4072 dptr[0] = p2[0];-
4073 dptr[1] = p2[1];-
4074 dptr[2] = p2[2];-
4075 }
never executed: end of block
0
4076 trigx += m11;-
4077 trigy += m12;-
4078 dptr += 3;-
4079 }
never executed: end of block
0
4080 break;
never executed: break;
0
4081-
4082 case 32: // 32 bpp transform
never executed: case 32:
0
4083 while (dptr < maxp) {
dptr < maxpDescription
TRUEnever evaluated
FALSEnever evaluated
0
4084 if (trigx < maxws && trigy < maxhs)
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4085 *((uint*)dptr) = *((const uint *)(sptr+sbpl*(trigy>>12) +
never executed: *((uint*)dptr) = *((const uint *)(sptr+sbpl*(trigy>>12) + ((trigx>>12)<<2)));
0
4086 ((trigx>>12)<<2)));
never executed: *((uint*)dptr) = *((const uint *)(sptr+sbpl*(trigy>>12) + ((trigx>>12)<<2)));
0
4087 trigx += m11;-
4088 trigy += m12;-
4089 dptr += 4;-
4090 }
never executed: end of block
0
4091 break;
never executed: break;
0
4092-
4093 default: {
never executed: default:
0
4094 return false;
never executed: return false;
0
4095 }-
4096 }-
4097 } else {-
4098 switch (type) {-
4099 case QT_XFORM_TYPE_MSBFIRST:
never executed: case 0:
0
4100 while (dptr < maxp) {
dptr < maxpDescription
TRUEnever evaluated
FALSEnever evaluated
0
4101 IWX_MSB(128);
never executed: *dptr |= 128;
never executed: end of block
*(sptr+sbpl*(t...rigx>>12)&7)))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4102 IWX_MSB(64);
never executed: *dptr |= 64;
never executed: end of block
*(sptr+sbpl*(t...rigx>>12)&7)))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4103 IWX_MSB(32);
never executed: *dptr |= 32;
never executed: end of block
*(sptr+sbpl*(t...rigx>>12)&7)))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4104 IWX_MSB(16);
never executed: *dptr |= 16;
never executed: end of block
*(sptr+sbpl*(t...rigx>>12)&7)))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4105 IWX_MSB(8);
never executed: *dptr |= 8;
never executed: end of block
*(sptr+sbpl*(t...rigx>>12)&7)))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4106 IWX_MSB(4);
never executed: *dptr |= 4;
never executed: end of block
*(sptr+sbpl*(t...rigx>>12)&7)))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4107 IWX_MSB(2);
never executed: *dptr |= 2;
never executed: end of block
*(sptr+sbpl*(t...rigx>>12)&7)))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4108 IWX_MSB(1);
never executed: *dptr |= 1;
never executed: end of block
*(sptr+sbpl*(t...rigx>>12)&7)))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4109 dptr++;-
4110 }
never executed: end of block
0
4111 break;
never executed: break;
0
4112 case QT_XFORM_TYPE_LSBFIRST:
never executed: case 1:
0
4113 while (dptr < maxp) {
dptr < maxpDescription
TRUEnever evaluated
FALSEnever evaluated
0
4114 IWX_LSB(1);
never executed: *dptr |= 1;
never executed: end of block
*(sptr+sbpl*(t...trigx>>12)&7))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4115 IWX_LSB(2);
never executed: *dptr |= 2;
never executed: end of block
*(sptr+sbpl*(t...trigx>>12)&7))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4116 IWX_LSB(4);
never executed: *dptr |= 4;
never executed: end of block
*(sptr+sbpl*(t...trigx>>12)&7))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4117 IWX_LSB(8);
never executed: *dptr |= 8;
never executed: end of block
*(sptr+sbpl*(t...trigx>>12)&7))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4118 IWX_LSB(16);
never executed: *dptr |= 16;
never executed: end of block
*(sptr+sbpl*(t...trigx>>12)&7))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4119 IWX_LSB(32);
never executed: *dptr |= 32;
never executed: end of block
*(sptr+sbpl*(t...trigx>>12)&7))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4120 IWX_LSB(64);
never executed: *dptr |= 64;
never executed: end of block
*(sptr+sbpl*(t...trigx>>12)&7))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4121 IWX_LSB(128);
never executed: *dptr |= 128;
never executed: end of block
*(sptr+sbpl*(t...trigx>>12)&7))Description
TRUEnever evaluated
FALSEnever evaluated
trigx < maxwsDescription
TRUEnever evaluated
FALSEnever evaluated
trigy < maxhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
4122 dptr++;-
4123 }
never executed: end of block
0
4124 break;
never executed: break;
0
4125 }-
4126 }
never executed: end of block
0
4127 m21ydx += m21;-
4128 m22ydy += m22;-
4129 dptr += p_inc;-
4130 }
never executed: end of block
0
4131 return true;
never executed: return true;
0
4132}-
4133#undef IWX_MSB-
4134#undef IWX_LSB-
4135#undef IWX_PIX-
4136-
4137/*! \fn int QImage::serialNumber() const-
4138 \obsolete-
4139 Returns a number that identifies the contents of this-
4140 QImage object. Distinct QImage objects can only have the same-
4141 serial number if they refer to the same contents (but they don't-
4142 have to).-
4143-
4144 Use cacheKey() instead.-
4145-
4146 \warning The serial number doesn't necessarily change when the-
4147 image is altered. This means that it may be dangerous to use-
4148 it as a cache key.-
4149-
4150 \sa operator==()-
4151*/-
4152-
4153/*!-
4154 Returns a number that identifies the contents of this QImage-
4155 object. Distinct QImage objects can only have the same key if they-
4156 refer to the same contents.-
4157-
4158 The key will change when the image is altered.-
4159*/-
4160qint64 QImage::cacheKey() const-
4161{-
4162 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
4163 return 0;
never executed: return 0;
0
4164 else-
4165 return (((qint64) d->ser_no) << 32) | ((qint64) d->detach_no);
never executed: return (((qint64) d->ser_no) << 32) | ((qint64) d->detach_no);
0
4166}-
4167-
4168/*!-
4169 \internal-
4170-
4171 Returns \c true if the image is detached; otherwise returns \c false.-
4172-
4173 \sa detach(), {Implicit Data Sharing}-
4174*/-
4175-
4176bool QImage::isDetached() const-
4177{-
4178 return d && d->ref.load() == 1;
never executed: return d && d->ref.load() == 1;
0
4179}-
4180-
4181-
4182/*!-
4183 \obsolete-
4184 Sets the alpha channel of this image to the given \a alphaChannel.-
4185-
4186 If \a alphaChannel is an 8 bit grayscale image, the intensity values are-
4187 written into this buffer directly. Otherwise, \a alphaChannel is converted-
4188 to 32 bit and the intensity of the RGB pixel values is used.-
4189-
4190 Note that the image will be converted to the Format_ARGB32_Premultiplied-
4191 format if the function succeeds.-
4192-
4193 Use one of the composition modes in QPainter::CompositionMode instead.-
4194-
4195 \warning This function is expensive.-
4196-
4197 \sa alphaChannel(), {QImage#Image Transformations}{Image-
4198 Transformations}, {QImage#Image Formats}{Image Formats}-
4199*/-
4200-
4201void QImage::setAlphaChannel(const QImage &alphaChannel)-
4202{-
4203 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
4204 return;
never executed: return;
0
4205-
4206 int w = d->width;-
4207 int h = d->height;-
4208-
4209 if (w != alphaChannel.d->width || h != alphaChannel.d->height) {
w != alphaChannel.d->widthDescription
TRUEnever evaluated
FALSEnever evaluated
h != alphaChannel.d->heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
4210 qWarning("QImage::setAlphaChannel: "-
4211 "Alpha channel must have same dimensions as the target image");-
4212 return;
never executed: return;
0
4213 }-
4214-
4215 if (d->paintEngine && d->paintEngine->isActive()) {
d->paintEngineDescription
TRUEnever evaluated
FALSEnever evaluated
d->paintEngine->isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
4216 qWarning("QImage::setAlphaChannel: "-
4217 "Unable to set alpha channel while image is being painted on");-
4218 return;
never executed: return;
0
4219 }-
4220-
4221 if (d->format == QImage::Format_ARGB32_Premultiplied)
d->format == Q..._PremultipliedDescription
TRUEnever evaluated
FALSEnever evaluated
0
4222 detach();
never executed: detach();
0
4223 else-
4224 *this = convertToFormat(QImage::Format_ARGB32_Premultiplied);
never executed: *this = convertToFormat(QImage::Format_ARGB32_Premultiplied);
0
4225-
4226 if (isNull())
isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
4227 return;
never executed: return;
0
4228-
4229 // Slight optimization since alphachannels are returned as 8-bit grays.-
4230 if (alphaChannel.format() == QImage::Format_Alpha8 ||( alphaChannel.d->depth == 8 && alphaChannel.isGrayscale())) {
alphaChannel.f...:Format_Alpha8Description
TRUEnever evaluated
FALSEnever evaluated
alphaChannel.d->depth == 8Description
TRUEnever evaluated
FALSEnever evaluated
alphaChannel.isGrayscale()Description
TRUEnever evaluated
FALSEnever evaluated
0
4231 const uchar *src_data = alphaChannel.d->data;-
4232 uchar *dest_data = d->data;-
4233 for (int y=0; y<h; ++y) {
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
0
4234 const uchar *src = src_data;-
4235 QRgb *dest = (QRgb *)dest_data;-
4236 for (int x=0; x<w; ++x) {
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
4237 int alpha = *src;-
4238 int destAlpha = qt_div_255(alpha * qAlpha(*dest));-
4239 *dest = ((destAlpha << 24)-
4240 | (qt_div_255(qRed(*dest) * alpha) << 16)-
4241 | (qt_div_255(qGreen(*dest) * alpha) << 8)-
4242 | (qt_div_255(qBlue(*dest) * alpha)));-
4243 ++dest;-
4244 ++src;-
4245 }
never executed: end of block
0
4246 src_data += alphaChannel.d->bytes_per_line;-
4247 dest_data += d->bytes_per_line;-
4248 }
never executed: end of block
0
4249-
4250 } else {
never executed: end of block
0
4251 const QImage sourceImage = alphaChannel.convertToFormat(QImage::Format_RGB32);-
4252 if (sourceImage.isNull())
sourceImage.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
4253 return;
never executed: return;
0
4254 const uchar *src_data = sourceImage.d->data;-
4255 uchar *dest_data = d->data;-
4256 for (int y=0; y<h; ++y) {
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
0
4257 const QRgb *src = (const QRgb *) src_data;-
4258 QRgb *dest = (QRgb *) dest_data;-
4259 for (int x=0; x<w; ++x) {
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
4260 int alpha = qGray(*src);-
4261 int destAlpha = qt_div_255(alpha * qAlpha(*dest));-
4262 *dest = ((destAlpha << 24)-
4263 | (qt_div_255(qRed(*dest) * alpha) << 16)-
4264 | (qt_div_255(qGreen(*dest) * alpha) << 8)-
4265 | (qt_div_255(qBlue(*dest) * alpha)));-
4266 ++dest;-
4267 ++src;-
4268 }
never executed: end of block
0
4269 src_data += sourceImage.d->bytes_per_line;-
4270 dest_data += d->bytes_per_line;-
4271 }
never executed: end of block
0
4272 }
never executed: end of block
0
4273}-
4274-
4275-
4276/*!-
4277 \obsolete-
4278-
4279 Returns the alpha channel of the image as a new grayscale QImage in which-
4280 each pixel's red, green, and blue values are given the alpha value of the-
4281 original image. The color depth of the returned image is 8-bit.-
4282-
4283 You can see an example of use of this function in QPixmap's-
4284 \l{QPixmap::}{alphaChannel()}, which works in the same way as-
4285 this function on QPixmaps.-
4286-
4287 Most usecases for this function can be replaced with QPainter and-
4288 using composition modes.-
4289-
4290 Note this returns a color-indexed image if you want the alpha channel in-
4291 the alpha8 format instead use convertToFormat(Format_Alpha8) on the source-
4292 image.-
4293-
4294 \warning This is an expensive function.-
4295-
4296 \sa setAlphaChannel(), hasAlphaChannel(), convertToFormat(),-
4297 {QPixmap#Pixmap Information}{Pixmap},-
4298 {QImage#Image Transformations}{Image Transformations}-
4299*/-
4300-
4301QImage QImage::alphaChannel() const-
4302{-
4303 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
4304 return QImage();
never executed: return QImage();
0
4305-
4306 int w = d->width;-
4307 int h = d->height;-
4308-
4309 QImage image(w, h, Format_Indexed8);-
4310 image.setColorCount(256);-
4311-
4312 // set up gray scale table.-
4313 for (int i=0; i<256; ++i)
i<256Description
TRUEnever evaluated
FALSEnever evaluated
0
4314 image.setColor(i, qRgb(i, i, i));
never executed: image.setColor(i, qRgb(i, i, i));
0
4315-
4316 if (!hasAlphaChannel()) {
!hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
0
4317 image.fill(255);-
4318 return image;
never executed: return image;
0
4319 }-
4320-
4321 if (d->format == Format_Indexed8) {
d->format == Format_Indexed8Description
TRUEnever evaluated
FALSEnever evaluated
0
4322 const uchar *src_data = d->data;-
4323 uchar *dest_data = image.d->data;-
4324 for (int y=0; y<h; ++y) {
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
0
4325 const uchar *src = src_data;-
4326 uchar *dest = dest_data;-
4327 for (int x=0; x<w; ++x) {
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
4328 *dest = qAlpha(d->colortable.at(*src));-
4329 ++dest;-
4330 ++src;-
4331 }
never executed: end of block
0
4332 src_data += d->bytes_per_line;-
4333 dest_data += image.d->bytes_per_line;-
4334 }
never executed: end of block
0
4335 } else if (d->format == Format_Alpha8) {
never executed: end of block
d->format == Format_Alpha8Description
TRUEnever evaluated
FALSEnever evaluated
0
4336 const uchar *src_data = d->data;-
4337 uchar *dest_data = image.d->data;-
4338 memcpy(dest_data, src_data, d->bytes_per_line * h);-
4339 } else {
never executed: end of block
0
4340 QImage alpha32 = *this;-
4341 bool canSkipConversion = (d->format == Format_ARGB32 || d->format == Format_ARGB32_Premultiplied);
d->format == Format_ARGB32Description
TRUEnever evaluated
FALSEnever evaluated
d->format == F..._PremultipliedDescription
TRUEnever evaluated
FALSEnever evaluated
0
4342#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN-
4343 canSkipConversion = canSkipConversion || (d->format == Format_RGBA8888 || d->format == Format_RGBA8888_Premultiplied);
canSkipConversionDescription
TRUEnever evaluated
FALSEnever evaluated
d->format == Format_RGBA8888Description
TRUEnever evaluated
FALSEnever evaluated
d->format == F..._PremultipliedDescription
TRUEnever evaluated
FALSEnever evaluated
0
4344#endif-
4345 if (!canSkipConversion)
!canSkipConversionDescription
TRUEnever evaluated
FALSEnever evaluated
0
4346 alpha32 = convertToFormat(Format_ARGB32);
never executed: alpha32 = convertToFormat(Format_ARGB32);
0
4347-
4348 const uchar *src_data = alpha32.d->data;-
4349 uchar *dest_data = image.d->data;-
4350 for (int y=0; y<h; ++y) {
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
0
4351 const QRgb *src = (const QRgb *) src_data;-
4352 uchar *dest = dest_data;-
4353 for (int x=0; x<w; ++x) {
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
4354 *dest = qAlpha(*src);-
4355 ++dest;-
4356 ++src;-
4357 }
never executed: end of block
0
4358 src_data += alpha32.d->bytes_per_line;-
4359 dest_data += image.d->bytes_per_line;-
4360 }
never executed: end of block
0
4361 }
never executed: end of block
0
4362-
4363 return image;
never executed: return image;
0
4364}-
4365-
4366/*!-
4367 Returns \c true if the image has a format that respects the alpha-
4368 channel, otherwise returns \c false.-
4369-
4370 \sa {QImage#Image Information}{Image Information}-
4371*/-
4372bool QImage::hasAlphaChannel() const-
4373{-
4374 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
4375 return false;
never executed: return false;
0
4376 const QPixelFormat format = pixelFormat();-
4377 if (format.alphaUsage() == QPixelFormat::UsesAlpha)
format.alphaUs...mat::UsesAlphaDescription
TRUEnever evaluated
FALSEnever evaluated
0
4378 return true;
never executed: return true;
0
4379 if (format.colorModel() == QPixelFormat::Indexed)
format.colorMo...ormat::IndexedDescription
TRUEnever evaluated
FALSEnever evaluated
0
4380 return d->has_alpha_clut;
never executed: return d->has_alpha_clut;
0
4381 return false;
never executed: return false;
0
4382}-
4383-
4384/*!-
4385 \since 4.7-
4386 Returns the number of bit planes in the image.-
4387-
4388 The number of bit planes is the number of bits of color and-
4389 transparency information for each pixel. This is different from-
4390 (i.e. smaller than) the depth when the image format contains-
4391 unused bits.-
4392-
4393 \sa depth(), format(), {QImage#Image Formats}{Image Formats}-
4394*/-
4395int QImage::bitPlaneCount() const-
4396{-
4397 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
4398 return 0;
never executed: return 0;
0
4399 int bpc = 0;-
4400 switch (d->format) {-
4401 case QImage::Format_Invalid:
never executed: case QImage::Format_Invalid:
0
4402 break;
never executed: break;
0
4403 case QImage::Format_BGR30:
never executed: case QImage::Format_BGR30:
0
4404 case QImage::Format_RGB30:
never executed: case QImage::Format_RGB30:
0
4405 bpc = 30;-
4406 break;
never executed: break;
0
4407 case QImage::Format_RGB32:
never executed: case QImage::Format_RGB32:
0
4408 case QImage::Format_RGBX8888:
never executed: case QImage::Format_RGBX8888:
0
4409 bpc = 24;-
4410 break;
never executed: break;
0
4411 case QImage::Format_RGB666:
never executed: case QImage::Format_RGB666:
0
4412 bpc = 18;-
4413 break;
never executed: break;
0
4414 case QImage::Format_RGB555:
never executed: case QImage::Format_RGB555:
0
4415 bpc = 15;-
4416 break;
never executed: break;
0
4417 case QImage::Format_ARGB8555_Premultiplied:
never executed: case QImage::Format_ARGB8555_Premultiplied:
0
4418 bpc = 23;-
4419 break;
never executed: break;
0
4420 case QImage::Format_RGB444:
never executed: case QImage::Format_RGB444:
0
4421 bpc = 12;-
4422 break;
never executed: break;
0
4423 default:
never executed: default:
0
4424 bpc = qt_depthForFormat(d->format);-
4425 break;
never executed: break;
0
4426 }-
4427 return bpc;
never executed: return bpc;
0
4428}-
4429-
4430/*!-
4431 Returns a smoothly scaled copy of the image. The returned image has a size-
4432 of width \a w by height \a h pixels.-
4433*/-
4434QImage QImage::smoothScaled(int w, int h) const {-
4435 QImage src = *this;-
4436 switch (src.format()) {-
4437 case QImage::Format_RGB32:
never executed: case QImage::Format_RGB32:
0
4438 case QImage::Format_ARGB32_Premultiplied:
never executed: case QImage::Format_ARGB32_Premultiplied:
0
4439#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN-
4440 case QImage::Format_RGBX8888:
never executed: case QImage::Format_RGBX8888:
0
4441#endif-
4442 case QImage::Format_RGBA8888_Premultiplied:
never executed: case QImage::Format_RGBA8888_Premultiplied:
0
4443 break;
never executed: break;
0
4444 default:
never executed: default:
0
4445 if (src.hasAlphaChannel())
src.hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
0
4446 src = src.convertToFormat(QImage::Format_ARGB32_Premultiplied);
never executed: src = src.convertToFormat(QImage::Format_ARGB32_Premultiplied);
0
4447 else-
4448 src = src.convertToFormat(QImage::Format_RGB32);
never executed: src = src.convertToFormat(QImage::Format_RGB32);
0
4449 }-
4450 src = qSmoothScaleImage(src, w, h);-
4451 if (!src.isNull())
!src.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
4452 copyMetadata(src.d, d);
never executed: copyMetadata(src.d, d);
0
4453 return src;
never executed: return src;
0
4454}-
4455-
4456static QImage rotated90(const QImage &image) {-
4457 QImage out(image.height(), image.width(), image.format());-
4458 out.setDotsPerMeterX(image.dotsPerMeterY());-
4459 out.setDotsPerMeterY(image.dotsPerMeterX());-
4460 if (image.colorCount() > 0)
image.colorCount() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
4461 out.setColorTable(image.colorTable());
never executed: out.setColorTable(image.colorTable());
0
4462 int w = image.width();-
4463 int h = image.height();-
4464 switch (image.format()) {-
4465 case QImage::Format_RGB32:
never executed: case QImage::Format_RGB32:
0
4466 case QImage::Format_ARGB32:
never executed: case QImage::Format_ARGB32:
0
4467 case QImage::Format_ARGB32_Premultiplied:
never executed: case QImage::Format_ARGB32_Premultiplied:
0
4468 case QImage::Format_RGBX8888:
never executed: case QImage::Format_RGBX8888:
0
4469 case QImage::Format_RGBA8888:
never executed: case QImage::Format_RGBA8888:
0
4470 case QImage::Format_RGBA8888_Premultiplied:
never executed: case QImage::Format_RGBA8888_Premultiplied:
0
4471 case QImage::Format_BGR30:
never executed: case QImage::Format_BGR30:
0
4472 case QImage::Format_A2BGR30_Premultiplied:
never executed: case QImage::Format_A2BGR30_Premultiplied:
0
4473 case QImage::Format_RGB30:
never executed: case QImage::Format_RGB30:
0
4474 case QImage::Format_A2RGB30_Premultiplied:
never executed: case QImage::Format_A2RGB30_Premultiplied:
0
4475 qt_memrotate270(reinterpret_cast<const quint32*>(image.bits()),-
4476 w, h, image.bytesPerLine(),-
4477 reinterpret_cast<quint32*>(out.bits()),-
4478 out.bytesPerLine());-
4479 break;
never executed: break;
0
4480 case QImage::Format_RGB666:
never executed: case QImage::Format_RGB666:
0
4481 case QImage::Format_ARGB6666_Premultiplied:
never executed: case QImage::Format_ARGB6666_Premultiplied:
0
4482 case QImage::Format_ARGB8565_Premultiplied:
never executed: case QImage::Format_ARGB8565_Premultiplied:
0
4483 case QImage::Format_ARGB8555_Premultiplied:
never executed: case QImage::Format_ARGB8555_Premultiplied:
0
4484 case QImage::Format_RGB888:
never executed: case QImage::Format_RGB888:
0
4485 qt_memrotate270(reinterpret_cast<const quint24*>(image.bits()),-
4486 w, h, image.bytesPerLine(),-
4487 reinterpret_cast<quint24*>(out.bits()),-
4488 out.bytesPerLine());-
4489 break;
never executed: break;
0
4490 case QImage::Format_RGB555:
never executed: case QImage::Format_RGB555:
0
4491 case QImage::Format_RGB16:
never executed: case QImage::Format_RGB16:
0
4492 case QImage::Format_ARGB4444_Premultiplied:
never executed: case QImage::Format_ARGB4444_Premultiplied:
0
4493 qt_memrotate270(reinterpret_cast<const quint16*>(image.bits()),-
4494 w, h, image.bytesPerLine(),-
4495 reinterpret_cast<quint16*>(out.bits()),-
4496 out.bytesPerLine());-
4497 break;
never executed: break;
0
4498 case QImage::Format_Alpha8:
never executed: case QImage::Format_Alpha8:
0
4499 case QImage::Format_Grayscale8:
never executed: case QImage::Format_Grayscale8:
0
4500 case QImage::Format_Indexed8:
never executed: case QImage::Format_Indexed8:
0
4501 qt_memrotate270(reinterpret_cast<const quint8*>(image.bits()),-
4502 w, h, image.bytesPerLine(),-
4503 reinterpret_cast<quint8*>(out.bits()),-
4504 out.bytesPerLine());-
4505 break;
never executed: break;
0
4506 default:
never executed: default:
0
4507 for (int y=0; y<h; ++y) {
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
0
4508 if (image.colorCount())
image.colorCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
4509 for (int x=0; x<w; ++x)
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
4510 out.setPixel(h-y-1, x, image.pixelIndex(x, y));
never executed: out.setPixel(h-y-1, x, image.pixelIndex(x, y));
0
4511 else-
4512 for (int x=0; x<w; ++x)
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
4513 out.setPixel(h-y-1, x, image.pixel(x, y));
never executed: out.setPixel(h-y-1, x, image.pixel(x, y));
0
4514 }
never executed: end of block
0
4515 break;
never executed: break;
0
4516 }-
4517 return out;
never executed: return out;
0
4518}-
4519-
4520-
4521static QImage rotated180(const QImage &image) {-
4522 return image.mirrored(true, true);
never executed: return image.mirrored(true, true);
0
4523}-
4524-
4525-
4526static QImage rotated270(const QImage &image) {-
4527 QImage out(image.height(), image.width(), image.format());-
4528 out.setDotsPerMeterX(image.dotsPerMeterY());-
4529 out.setDotsPerMeterY(image.dotsPerMeterX());-
4530 if (image.colorCount() > 0)
image.colorCount() > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
4531 out.setColorTable(image.colorTable());
never executed: out.setColorTable(image.colorTable());
0
4532 int w = image.width();-
4533 int h = image.height();-
4534 switch (image.format()) {-
4535 case QImage::Format_RGB32:
never executed: case QImage::Format_RGB32:
0
4536 case QImage::Format_ARGB32:
never executed: case QImage::Format_ARGB32:
0
4537 case QImage::Format_ARGB32_Premultiplied:
never executed: case QImage::Format_ARGB32_Premultiplied:
0
4538 case QImage::Format_RGBX8888:
never executed: case QImage::Format_RGBX8888:
0
4539 case QImage::Format_RGBA8888:
never executed: case QImage::Format_RGBA8888:
0
4540 case QImage::Format_RGBA8888_Premultiplied:
never executed: case QImage::Format_RGBA8888_Premultiplied:
0
4541 case QImage::Format_BGR30:
never executed: case QImage::Format_BGR30:
0
4542 case QImage::Format_A2BGR30_Premultiplied:
never executed: case QImage::Format_A2BGR30_Premultiplied:
0
4543 case QImage::Format_RGB30:
never executed: case QImage::Format_RGB30:
0
4544 case QImage::Format_A2RGB30_Premultiplied:
never executed: case QImage::Format_A2RGB30_Premultiplied:
0
4545 qt_memrotate90(reinterpret_cast<const quint32*>(image.bits()),-
4546 w, h, image.bytesPerLine(),-
4547 reinterpret_cast<quint32*>(out.bits()),-
4548 out.bytesPerLine());-
4549 break;
never executed: break;
0
4550 case QImage::Format_RGB666:
never executed: case QImage::Format_RGB666:
0
4551 case QImage::Format_ARGB6666_Premultiplied:
never executed: case QImage::Format_ARGB6666_Premultiplied:
0
4552 case QImage::Format_ARGB8565_Premultiplied:
never executed: case QImage::Format_ARGB8565_Premultiplied:
0
4553 case QImage::Format_ARGB8555_Premultiplied:
never executed: case QImage::Format_ARGB8555_Premultiplied:
0
4554 case QImage::Format_RGB888:
never executed: case QImage::Format_RGB888:
0
4555 qt_memrotate90(reinterpret_cast<const quint24*>(image.bits()),-
4556 w, h, image.bytesPerLine(),-
4557 reinterpret_cast<quint24*>(out.bits()),-
4558 out.bytesPerLine());-
4559 break;
never executed: break;
0
4560 case QImage::Format_RGB555:
never executed: case QImage::Format_RGB555:
0
4561 case QImage::Format_RGB16:
never executed: case QImage::Format_RGB16:
0
4562 case QImage::Format_ARGB4444_Premultiplied:
never executed: case QImage::Format_ARGB4444_Premultiplied:
0
4563 qt_memrotate90(reinterpret_cast<const quint16*>(image.bits()),-
4564 w, h, image.bytesPerLine(),-
4565 reinterpret_cast<quint16*>(out.bits()),-
4566 out.bytesPerLine());-
4567 break;
never executed: break;
0
4568 case QImage::Format_Alpha8:
never executed: case QImage::Format_Alpha8:
0
4569 case QImage::Format_Grayscale8:
never executed: case QImage::Format_Grayscale8:
0
4570 case QImage::Format_Indexed8:
never executed: case QImage::Format_Indexed8:
0
4571 qt_memrotate90(reinterpret_cast<const quint8*>(image.bits()),-
4572 w, h, image.bytesPerLine(),-
4573 reinterpret_cast<quint8*>(out.bits()),-
4574 out.bytesPerLine());-
4575 break;
never executed: break;
0
4576 default:
never executed: default:
0
4577 for (int y=0; y<h; ++y) {
y<hDescription
TRUEnever evaluated
FALSEnever evaluated
0
4578 if (image.colorCount())
image.colorCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
4579 for (int x=0; x<w; ++x)
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
4580 out.setPixel(y, w-x-1, image.pixelIndex(x, y));
never executed: out.setPixel(y, w-x-1, image.pixelIndex(x, y));
0
4581 else-
4582 for (int x=0; x<w; ++x)
x<wDescription
TRUEnever evaluated
FALSEnever evaluated
0
4583 out.setPixel(y, w-x-1, image.pixel(x, y));
never executed: out.setPixel(y, w-x-1, image.pixel(x, y));
0
4584 }
never executed: end of block
0
4585 break;
never executed: break;
0
4586 }-
4587 return out;
never executed: return out;
0
4588}-
4589-
4590/*!-
4591 Returns a copy of the image that is transformed using the given-
4592 transformation \a matrix and transformation \a mode.-
4593-
4594 The transformation \a matrix is internally adjusted to compensate-
4595 for unwanted translation; i.e. the image produced is the smallest-
4596 image that contains all the transformed points of the original-
4597 image. Use the trueMatrix() function to retrieve the actual matrix-
4598 used for transforming an image.-
4599-
4600 Unlike the other overload, this function can be used to perform perspective-
4601 transformations on images.-
4602-
4603 \sa trueMatrix(), {QImage#Image Transformations}{Image-
4604 Transformations}-
4605*/-
4606-
4607QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode ) const-
4608{-
4609 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
4610 return QImage();
never executed: return QImage();
0
4611-
4612 // source image data-
4613 int ws = width();-
4614 int hs = height();-
4615-
4616 // target image data-
4617 int wd;-
4618 int hd;-
4619-
4620 // compute size of target image-
4621 QTransform mat = trueMatrix(matrix, ws, hs);-
4622 bool complex_xform = false;-
4623 bool scale_xform = false;-
4624 if (mat.type() <= QTransform::TxScale) {
mat.type() <= ...sform::TxScaleDescription
TRUEnever evaluated
FALSEnever evaluated
0
4625 if (mat.type() == QTransform::TxNone) // identity matrix
mat.type() == ...nsform::TxNoneDescription
TRUEnever evaluated
FALSEnever evaluated
0
4626 return *this;
never executed: return *this;
0
4627 else if (mat.m11() == -1. && mat.m22() == -1.)
mat.m11() == -1.Description
TRUEnever evaluated
FALSEnever evaluated
mat.m22() == -1.Description
TRUEnever evaluated
FALSEnever evaluated
0
4628 return rotated180(*this);
never executed: return rotated180(*this);
0
4629-
4630 if (mode == Qt::FastTransformation) {
mode == Qt::FastTransformationDescription
TRUEnever evaluated
FALSEnever evaluated
0
4631 hd = qRound(qAbs(mat.m22()) * hs);-
4632 wd = qRound(qAbs(mat.m11()) * ws);-
4633 } else {
never executed: end of block
0
4634 hd = int(qAbs(mat.m22()) * hs + 0.9999);-
4635 wd = int(qAbs(mat.m11()) * ws + 0.9999);-
4636 }
never executed: end of block
0
4637 scale_xform = true;-
4638 } else {
never executed: end of block
0
4639 if (mat.type() <= QTransform::TxRotate && mat.m11() == 0 && mat.m22() == 0) {
mat.type() <= ...form::TxRotateDescription
TRUEnever evaluated
FALSEnever evaluated
mat.m11() == 0Description
TRUEnever evaluated
FALSEnever evaluated
mat.m22() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
4640 if (mat.m12() == 1. && mat.m21() == -1.)
mat.m12() == 1.Description
TRUEnever evaluated
FALSEnever evaluated
mat.m21() == -1.Description
TRUEnever evaluated
FALSEnever evaluated
0
4641 return rotated90(*this);
never executed: return rotated90(*this);
0
4642 else if (mat.m12() == -1. && mat.m21() == 1.)
mat.m12() == -1.Description
TRUEnever evaluated
FALSEnever evaluated
mat.m21() == 1.Description
TRUEnever evaluated
FALSEnever evaluated
0
4643 return rotated270(*this);
never executed: return rotated270(*this);
0
4644 }
never executed: end of block
0
4645-
4646 QPolygonF a(QRectF(0, 0, ws, hs));-
4647 a = mat.map(a);-
4648 QRect r = a.boundingRect().toAlignedRect();-
4649 wd = r.width();-
4650 hd = r.height();-
4651 complex_xform = true;-
4652 }
never executed: end of block
0
4653-
4654 if (wd == 0 || hd == 0)
wd == 0Description
TRUEnever evaluated
FALSEnever evaluated
hd == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
4655 return QImage();
never executed: return QImage();
0
4656-
4657 // Make use of the optimized algorithm when we're scaling-
4658 if (scale_xform && mode == Qt::SmoothTransformation) {
scale_xformDescription
TRUEnever evaluated
FALSEnever evaluated
mode == Qt::Sm...TransformationDescription
TRUEnever evaluated
FALSEnever evaluated
0
4659 if (mat.m11() < 0.0F && mat.m22() < 0.0F) { // horizontal/vertical flip
mat.m11() < 0.0FDescription
TRUEnever evaluated
FALSEnever evaluated
mat.m22() < 0.0FDescription
TRUEnever evaluated
FALSEnever evaluated
0
4660 return smoothScaled(wd, hd).mirrored(true, true);
never executed: return smoothScaled(wd, hd).mirrored(true, true);
0
4661 } else if (mat.m11() < 0.0F) { // horizontal flip
mat.m11() < 0.0FDescription
TRUEnever evaluated
FALSEnever evaluated
0
4662 return smoothScaled(wd, hd).mirrored(true, false);
never executed: return smoothScaled(wd, hd).mirrored(true, false);
0
4663 } else if (mat.m22() < 0.0F) { // vertical flip
mat.m22() < 0.0FDescription
TRUEnever evaluated
FALSEnever evaluated
0
4664 return smoothScaled(wd, hd).mirrored(false, true);
never executed: return smoothScaled(wd, hd).mirrored(false, true);
0
4665 } else { // no flipping-
4666 return smoothScaled(wd, hd);
never executed: return smoothScaled(wd, hd);
0
4667 }-
4668 }-
4669-
4670 int bpp = depth();-
4671-
4672 int sbpl = bytesPerLine();-
4673 const uchar *sptr = bits();-
4674-
4675 QImage::Format target_format = d->format;-
4676-
4677 if (complex_xform || mode == Qt::SmoothTransformation) {
complex_xformDescription
TRUEnever evaluated
FALSEnever evaluated
mode == Qt::Sm...TransformationDescription
TRUEnever evaluated
FALSEnever evaluated
0
4678 if (d->format < QImage::Format_RGB32 || !hasAlphaChannel()) {
d->format < QI...::Format_RGB32Description
TRUEnever evaluated
FALSEnever evaluated
!hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
0
4679 target_format = qt_alphaVersion(d->format);-
4680 }
never executed: end of block
0
4681 }
never executed: end of block
0
4682-
4683 QImage dImage(wd, hd, target_format);-
4684 QIMAGE_SANITYCHECK_MEMORY(dImage);
never executed: return QImage();
(dImage).isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
4685-
4686 if (target_format == QImage::Format_MonoLSB
target_format ...Format_MonoLSBDescription
TRUEnever evaluated
FALSEnever evaluated
0
4687 || target_format == QImage::Format_Mono
target_format ...e::Format_MonoDescription
TRUEnever evaluated
FALSEnever evaluated
0
4688 || target_format == QImage::Format_Indexed8) {
target_format ...ormat_Indexed8Description
TRUEnever evaluated
FALSEnever evaluated
0
4689 dImage.d->colortable = d->colortable;-
4690 dImage.d->has_alpha_clut = d->has_alpha_clut | complex_xform;-
4691 }
never executed: end of block
0
4692-
4693 // initizialize the data-
4694 if (d->format == QImage::Format_Indexed8) {
d->format == Q...ormat_Indexed8Description
TRUEnever evaluated
FALSEnever evaluated
0
4695 if (dImage.d->colortable.size() < 256) {
dImage.d->colo...e.size() < 256Description
TRUEnever evaluated
FALSEnever evaluated
0
4696 // colors are left in the color table, so pick that one as transparent-
4697 dImage.d->colortable.append(0x0);-
4698 memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.byteCount());-
4699 } else {
never executed: end of block
0
4700 memset(dImage.bits(), 0, dImage.byteCount());-
4701 }
never executed: end of block
0
4702 } else-
4703 memset(dImage.bits(), 0x00, dImage.byteCount());
never executed: memset(dImage.bits(), 0x00, dImage.byteCount());
0
4704-
4705 if (target_format >= QImage::Format_RGB32) {
target_format ...::Format_RGB32Description
TRUEnever evaluated
FALSEnever evaluated
0
4706 // Prevent QPainter from applying devicePixelRatio corrections-
4707 const QImage sImage = (devicePixelRatio() != 1) ? QImage(constBits(), width(), height(), format()) : *this;
(devicePixelRatio() != 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
4708-
4709 Q_ASSERT(sImage.devicePixelRatio() == 1);-
4710 Q_ASSERT(sImage.devicePixelRatio() == dImage.devicePixelRatio());-
4711-
4712 QPainter p(&dImage);-
4713 if (mode == Qt::SmoothTransformation) {
mode == Qt::Sm...TransformationDescription
TRUEnever evaluated
FALSEnever evaluated
0
4714 p.setRenderHint(QPainter::Antialiasing);-
4715 p.setRenderHint(QPainter::SmoothPixmapTransform);-
4716 }
never executed: end of block
0
4717 p.setTransform(mat);-
4718 p.drawImage(QPoint(0, 0), sImage);-
4719 } else {
never executed: end of block
0
4720 bool invertible;-
4721 mat = mat.inverted(&invertible); // invert matrix-
4722 if (!invertible) // error, return null image
!invertibleDescription
TRUEnever evaluated
FALSEnever evaluated
0
4723 return QImage();
never executed: return QImage();
0
4724-
4725 // create target image (some of the code is from QImage::copy())-
4726 int type = format() == Format_Mono ? QT_XFORM_TYPE_MSBFIRST : QT_XFORM_TYPE_LSBFIRST;
format() == Format_MonoDescription
TRUEnever evaluated
FALSEnever evaluated
0
4727 int dbpl = dImage.bytesPerLine();-
4728 qt_xForm_helper(mat, 0, type, bpp, dImage.bits(), dbpl, 0, hd, sptr, sbpl, ws, hs);-
4729 }
never executed: end of block
0
4730 copyMetadata(dImage.d, d);-
4731-
4732 return dImage;
never executed: return dImage;
0
4733}-
4734-
4735/*!-
4736 \fn QTransform QImage::trueMatrix(const QTransform &matrix, int width, int height)-
4737-
4738 Returns the actual matrix used for transforming an image with the-
4739 given \a width, \a height and \a matrix.-
4740-
4741 When transforming an image using the transformed() function, the-
4742 transformation matrix is internally adjusted to compensate for-
4743 unwanted translation, i.e. transformed() returns the smallest-
4744 image containing all transformed points of the original image.-
4745 This function returns the modified matrix, which maps points-
4746 correctly from the original image into the new image.-
4747-
4748 Unlike the other overload, this function creates transformation-
4749 matrices that can be used to perform perspective-
4750 transformations on images.-
4751-
4752 \sa transformed(), {QImage#Image Transformations}{Image-
4753 Transformations}-
4754*/-
4755-
4756QTransform QImage::trueMatrix(const QTransform &matrix, int w, int h)-
4757{-
4758 const QRectF rect(0, 0, w, h);-
4759 const QRect mapped = matrix.mapRect(rect).toAlignedRect();-
4760 const QPoint delta = mapped.topLeft();-
4761 return matrix * QTransform().translate(-delta.x(), -delta.y());
never executed: return matrix * QTransform().translate(-delta.x(), -delta.y());
0
4762}-
4763-
4764bool QImageData::convertInPlace(QImage::Format newFormat, Qt::ImageConversionFlags flags)-
4765{-
4766 if (format == newFormat)
format == newFormatDescription
TRUEnever evaluated
FALSEnever evaluated
0
4767 return true;
never executed: return true;
0
4768-
4769 // No in-place conversion if we have to detach-
4770 if (ref.load() > 1 || !own_data)
ref.load() > 1Description
TRUEnever evaluated
FALSEnever evaluated
!own_dataDescription
TRUEnever evaluated
FALSEnever evaluated
0
4771 return false;
never executed: return false;
0
4772-
4773 InPlace_Image_Converter converter = qimage_inplace_converter_map[format][newFormat];-
4774 if (converter)
converterDescription
TRUEnever evaluated
FALSEnever evaluated
0
4775 return converter(this, flags);
never executed: return converter(this, flags);
0
4776 else if (format > QImage::Format_Indexed8 && newFormat > QImage::Format_Indexed8 && !qimage_converter_map[format][newFormat])
format > QImag...ormat_Indexed8Description
TRUEnever evaluated
FALSEnever evaluated
newFormat > QI...ormat_Indexed8Description
TRUEnever evaluated
FALSEnever evaluated
!qimage_conver...at][newFormat]Description
TRUEnever evaluated
FALSEnever evaluated
0
4777 // Convert inplace generic, but only if there are no direct converters,-
4778 // any direct ones are probably better even if not inplace.-
4779 return convert_generic_inplace(this, newFormat, flags);
never executed: return convert_generic_inplace(this, newFormat, flags);
0
4780 else-
4781 return false;
never executed: return false;
0
4782}-
4783-
4784/*!-
4785 \typedef QImage::DataPtr-
4786 \internal-
4787*/-
4788-
4789/*!-
4790 \fn DataPtr & QImage::data_ptr()-
4791 \internal-
4792*/-
4793-
4794#ifndef QT_NO_DEBUG_STREAM-
4795QDebug operator<<(QDebug dbg, const QImage &i)-
4796{-
4797 QDebugStateSaver saver(dbg);-
4798 dbg.resetFormat();-
4799 dbg.nospace();-
4800 dbg << "QImage(";-
4801 if (i.isNull()) {
i.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
4802 dbg << "null";-
4803 } else {
never executed: end of block
0
4804 dbg << i.size() << ",format=" << i.format() << ",depth=" << i.depth();-
4805 if (i.colorCount())
i.colorCount()Description
TRUEnever evaluated
FALSEnever evaluated
0
4806 dbg << ",colorCount=" << i.colorCount();
never executed: dbg << ",colorCount=" << i.colorCount();
0
4807 dbg << ",devicePixelRatio=" << i.devicePixelRatio()-
4808 << ",bytesPerLine=" << i.bytesPerLine() << ",byteCount=" << i.byteCount();-
4809 }
never executed: end of block
0
4810 dbg << ')';-
4811 return dbg;
never executed: return dbg;
0
4812}-
4813#endif-
4814-
4815/*!-
4816 \fn void QImage::setNumColors(int n)-
4817 \obsolete-
4818-
4819 Resizes the color table to contain \a n entries.-
4820-
4821 \sa setColorCount()-
4822 */-
4823-
4824/*!-
4825 \fn int QImage::numBytes() const-
4826 \obsolete-
4827-
4828 Returns the number of bytes occupied by the image data.-
4829-
4830 \sa byteCount()-
4831 */-
4832-
4833/*!-
4834 \fn QStringList QImage::textLanguages() const-
4835 \obsolete-
4836-
4837 Returns the language identifiers for which some texts are recorded.-
4838 Note that if you want to iterate over the list, you should iterate over a copy.-
4839-
4840 The language the text is recorded in is no longer relevant since the text is-
4841 always set using QString and UTF-8 representation.-
4842-
4843 \sa textKeys()-
4844 */-
4845-
4846/*!-
4847 \fn QList<QImageTextKeyLang> QImage::textList() const-
4848 \obsolete-
4849-
4850 Returns a list of QImageTextKeyLang objects that enumerate all the texts-
4851 key/language pairs set for this image.-
4852-
4853 The language the text is recorded in is no longer relevant since the text-
4854 is always set using QString and UTF-8 representation.-
4855-
4856 \sa textKeys()-
4857 */-
4858-
4859static Q_CONSTEXPR QPixelFormat pixelformats[] = {-
4860 //QImage::Format_Invalid:-
4861 QPixelFormat(),-
4862 //QImage::Format_Mono:-
4863 QPixelFormat(QPixelFormat::Indexed,-
4864 /*RED*/ 1,-
4865 /*GREEN*/ 0,-
4866 /*BLUE*/ 0,-
4867 /*FOURTH*/ 0,-
4868 /*FIFTH*/ 0,-
4869 /*ALPHA*/ 0,-
4870 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
4871 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
4872 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
4873 /*INTERPRETATION*/ QPixelFormat::UnsignedByte,-
4874 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
4875 //QImage::Format_MonoLSB:-
4876 QPixelFormat(QPixelFormat::Indexed,-
4877 /*RED*/ 1,-
4878 /*GREEN*/ 0,-
4879 /*BLUE*/ 0,-
4880 /*FOURTH*/ 0,-
4881 /*FIFTH*/ 0,-
4882 /*ALPHA*/ 0,-
4883 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
4884 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
4885 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
4886 /*INTERPRETATION*/ QPixelFormat::UnsignedByte,-
4887 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
4888 //QImage::Format_Indexed8:-
4889 QPixelFormat(QPixelFormat::Indexed,-
4890 /*RED*/ 8,-
4891 /*GREEN*/ 0,-
4892 /*BLUE*/ 0,-
4893 /*FOURTH*/ 0,-
4894 /*FIFTH*/ 0,-
4895 /*ALPHA*/ 0,-
4896 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
4897 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
4898 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
4899 /*INTERPRETATION*/ QPixelFormat::UnsignedByte,-
4900 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
4901 //QImage::Format_RGB32:-
4902 QPixelFormat(QPixelFormat::RGB,-
4903 /*RED*/ 8,-
4904 /*GREEN*/ 8,-
4905 /*BLUE*/ 8,-
4906 /*FOURTH*/ 0,-
4907 /*FIFTH*/ 0,-
4908 /*ALPHA*/ 8,-
4909 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
4910 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
4911 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
4912 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
4913 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
4914 //QImage::Format_ARGB32:-
4915 QPixelFormat(QPixelFormat::RGB,-
4916 /*RED*/ 8,-
4917 /*GREEN*/ 8,-
4918 /*BLUE*/ 8,-
4919 /*FOURTH*/ 0,-
4920 /*FIFTH*/ 0,-
4921 /*ALPHA*/ 8,-
4922 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
4923 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
4924 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
4925 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
4926 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
4927 //QImage::Format_ARGB32_Premultiplied:-
4928 QPixelFormat(QPixelFormat::RGB,-
4929 /*RED*/ 8,-
4930 /*GREEN*/ 8,-
4931 /*BLUE*/ 8,-
4932 /*FOURTH*/ 0,-
4933 /*FIFTH*/ 0,-
4934 /*ALPHA*/ 8,-
4935 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
4936 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
4937 /*PREMULTIPLIED*/ QPixelFormat::Premultiplied,-
4938 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
4939 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
4940 //QImage::Format_RGB16:-
4941 QPixelFormat(QPixelFormat::RGB,-
4942 /*RED*/ 5,-
4943 /*GREEN*/ 6,-
4944 /*BLUE*/ 5,-
4945 /*FOURTH*/ 0,-
4946 /*FIFTH*/ 0,-
4947 /*ALPHA*/ 0,-
4948 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
4949 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
4950 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
4951 /*INTERPRETATION*/ QPixelFormat::UnsignedShort,-
4952 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
4953 //QImage::Format_ARGB8565_Premultiplied:-
4954 QPixelFormat(QPixelFormat::RGB,-
4955 /*RED*/ 5,-
4956 /*GREEN*/ 6,-
4957 /*BLUE*/ 5,-
4958 /*FOURTH*/ 0,-
4959 /*FIFTH*/ 0,-
4960 /*ALPHA*/ 8,-
4961 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
4962 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
4963 /*PREMULTIPLIED*/ QPixelFormat::Premultiplied,-
4964 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
4965 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
4966 //QImage::Format_RGB666:-
4967 QPixelFormat(QPixelFormat::RGB,-
4968 /*RED*/ 6,-
4969 /*GREEN*/ 6,-
4970 /*BLUE*/ 6,-
4971 /*FOURTH*/ 0,-
4972 /*FIFTH*/ 0,-
4973 /*ALPHA*/ 0,-
4974 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
4975 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
4976 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
4977 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
4978 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
4979 //QImage::Format_ARGB6666_Premultiplied:-
4980 QPixelFormat(QPixelFormat::RGB,-
4981 /*RED*/ 6,-
4982 /*GREEN*/ 6,-
4983 /*BLUE*/ 6,-
4984 /*FOURTH*/ 0,-
4985 /*FIFTH*/ 0,-
4986 /*ALPHA*/ 6,-
4987 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
4988 /*ALPHA POSITION*/ QPixelFormat::AtEnd,-
4989 /*PREMULTIPLIED*/ QPixelFormat::Premultiplied,-
4990 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
4991 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
4992 //QImage::Format_RGB555:-
4993 QPixelFormat(QPixelFormat::RGB,-
4994 /*RED*/ 5,-
4995 /*GREEN*/ 5,-
4996 /*BLUE*/ 5,-
4997 /*FOURTH*/ 0,-
4998 /*FIFTH*/ 0,-
4999 /*ALPHA*/ 0,-
5000 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
5001 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
5002 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
5003 /*INTERPRETATION*/ QPixelFormat::UnsignedShort,-
5004 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5005 //QImage::Format_ARGB8555_Premultiplied:-
5006 QPixelFormat(QPixelFormat::RGB,-
5007 /*RED*/ 5,-
5008 /*GREEN*/ 5,-
5009 /*BLUE*/ 5,-
5010 /*FOURTH*/ 0,-
5011 /*FIFTH*/ 0,-
5012 /*ALPHA*/ 8,-
5013 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
5014 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
5015 /*PREMULTIPLIED*/ QPixelFormat::Premultiplied,-
5016 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
5017 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5018 //QImage::Format_RGB888:-
5019 QPixelFormat(QPixelFormat::RGB,-
5020 /*RED*/ 8,-
5021 /*GREEN*/ 8,-
5022 /*BLUE*/ 8,-
5023 /*FOURTH*/ 0,-
5024 /*FIFTH*/ 0,-
5025 /*ALPHA*/ 0,-
5026 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
5027 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
5028 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
5029 /*INTERPRETATION*/ QPixelFormat::UnsignedByte,-
5030 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5031 //QImage::Format_RGB444:-
5032 QPixelFormat(QPixelFormat::RGB,-
5033 /*RED*/ 4,-
5034 /*GREEN*/ 4,-
5035 /*BLUE*/ 4,-
5036 /*FOURTH*/ 0,-
5037 /*FIFTH*/ 0,-
5038 /*ALPHA*/ 0,-
5039 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
5040 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
5041 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
5042 /*INTERPRETATION*/ QPixelFormat::UnsignedShort,-
5043 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5044 //QImage::Format_ARGB4444_Premultiplied:-
5045 QPixelFormat(QPixelFormat::RGB,-
5046 /*RED*/ 4,-
5047 /*GREEN*/ 4,-
5048 /*BLUE*/ 4,-
5049 /*FOURTH*/ 0,-
5050 /*FIFTH*/ 0,-
5051 /*ALPHA*/ 4,-
5052 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
5053 /*ALPHA POSITION*/ QPixelFormat::AtEnd,-
5054 /*PREMULTIPLIED*/ QPixelFormat::Premultiplied,-
5055 /*INTERPRETATION*/ QPixelFormat::UnsignedShort,-
5056 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5057 //QImage::Format_RGBX8888:-
5058 QPixelFormat(QPixelFormat::RGB,-
5059 /*RED*/ 8,-
5060 /*GREEN*/ 8,-
5061 /*BLUE*/ 8,-
5062 /*FOURTH*/ 0,-
5063 /*FIFTH*/ 0,-
5064 /*ALPHA*/ 8,-
5065 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
5066 /*ALPHA POSITION*/ QPixelFormat::AtEnd,-
5067 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
5068 /*INTERPRETATION*/ QPixelFormat::UnsignedByte,-
5069 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5070 //QImage::Format_RGBA8888:-
5071 QPixelFormat(QPixelFormat::RGB,-
5072 /*RED*/ 8,-
5073 /*GREEN*/ 8,-
5074 /*BLUE*/ 8,-
5075 /*FOURTH*/ 0,-
5076 /*FIFTH*/ 0,-
5077 /*ALPHA*/ 8,-
5078 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
5079 /*ALPHA POSITION*/ QPixelFormat::AtEnd,-
5080 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
5081 /*INTERPRETATION*/ QPixelFormat::UnsignedByte,-
5082 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5083 //QImage::Format_RGBA8888_Premultiplied:-
5084 QPixelFormat(QPixelFormat::RGB,-
5085 /*RED*/ 8,-
5086 /*GREEN*/ 8,-
5087 /*BLUE*/ 8,-
5088 /*FOURTH*/ 0,-
5089 /*FIFTH*/ 0,-
5090 /*ALPHA*/ 8,-
5091 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
5092 /*ALPHA POSITION*/ QPixelFormat::AtEnd,-
5093 /*PREMULTIPLIED*/ QPixelFormat::Premultiplied,-
5094 /*INTERPRETATION*/ QPixelFormat::UnsignedByte,-
5095 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5096 //QImage::Format_BGR30:-
5097 QPixelFormat(QPixelFormat::BGR,-
5098 /*RED*/ 10,-
5099 /*GREEN*/ 10,-
5100 /*BLUE*/ 10,-
5101 /*FOURTH*/ 0,-
5102 /*FIFTH*/ 0,-
5103 /*ALPHA*/ 2,-
5104 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
5105 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
5106 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
5107 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
5108 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5109 //QImage::Format_A2BGR30_Premultiplied:-
5110 QPixelFormat(QPixelFormat::BGR,-
5111 /*RED*/ 10,-
5112 /*GREEN*/ 10,-
5113 /*BLUE*/ 10,-
5114 /*FOURTH*/ 0,-
5115 /*FIFTH*/ 0,-
5116 /*ALPHA*/ 2,-
5117 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
5118 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
5119 /*PREMULTIPLIED*/ QPixelFormat::Premultiplied,-
5120 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
5121 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5122 //QImage::Format_RGB30:-
5123 QPixelFormat(QPixelFormat::RGB,-
5124 /*RED*/ 10,-
5125 /*GREEN*/ 10,-
5126 /*BLUE*/ 10,-
5127 /*FOURTH*/ 0,-
5128 /*FIFTH*/ 0,-
5129 /*ALPHA*/ 2,-
5130 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
5131 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
5132 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
5133 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
5134 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5135 //QImage::Format_A2RGB30_Premultiplied:-
5136 QPixelFormat(QPixelFormat::RGB,-
5137 /*RED*/ 10,-
5138 /*GREEN*/ 10,-
5139 /*BLUE*/ 10,-
5140 /*FOURTH*/ 0,-
5141 /*FIFTH*/ 0,-
5142 /*ALPHA*/ 2,-
5143 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
5144 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
5145 /*PREMULTIPLIED*/ QPixelFormat::Premultiplied,-
5146 /*INTERPRETATION*/ QPixelFormat::UnsignedInteger,-
5147 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5148 //QImage::Format_Alpha8:-
5149 QPixelFormat(QPixelFormat::Alpha,-
5150 /*First*/ 0,-
5151 /*SECOND*/ 0,-
5152 /*THIRD*/ 0,-
5153 /*FOURTH*/ 0,-
5154 /*FIFTH*/ 0,-
5155 /*ALPHA*/ 8,-
5156 /*ALPHA USAGE*/ QPixelFormat::UsesAlpha,-
5157 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
5158 /*PREMULTIPLIED*/ QPixelFormat::Premultiplied,-
5159 /*INTERPRETATION*/ QPixelFormat::UnsignedByte,-
5160 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5161 //QImage::Format_Grayscale8:-
5162 QPixelFormat(QPixelFormat::Grayscale,-
5163 /*GRAY*/ 8,-
5164 /*SECOND*/ 0,-
5165 /*THIRD*/ 0,-
5166 /*FOURTH*/ 0,-
5167 /*FIFTH*/ 0,-
5168 /*ALPHA*/ 0,-
5169 /*ALPHA USAGE*/ QPixelFormat::IgnoresAlpha,-
5170 /*ALPHA POSITION*/ QPixelFormat::AtBeginning,-
5171 /*PREMULTIPLIED*/ QPixelFormat::NotPremultiplied,-
5172 /*INTERPRETATION*/ QPixelFormat::UnsignedByte,-
5173 /*BYTE ORDER*/ QPixelFormat::CurrentSystemEndian),-
5174};-
5175Q_STATIC_ASSERT(sizeof(pixelformats) / sizeof(*pixelformats) == QImage::NImageFormats);-
5176-
5177/*!-
5178 Returns the QImage::Format as a QPixelFormat-
5179*/-
5180QPixelFormat QImage::pixelFormat() const Q_DECL_NOTHROW-
5181{-
5182 return toPixelFormat(format());
never executed: return toPixelFormat(format());
0
5183}-
5184-
5185/*!-
5186 Converts \a format into a QPixelFormat-
5187*/-
5188QPixelFormat QImage::toPixelFormat(QImage::Format format) Q_DECL_NOTHROW-
5189{-
5190 Q_ASSERT(static_cast<int>(format) < NImageFormats);-
5191 return pixelformats[format];
never executed: return pixelformats[format];
0
5192}-
5193-
5194/*!-
5195 Converts \a format into a QImage::Format-
5196*/-
5197QImage::Format QImage::toImageFormat(QPixelFormat format) Q_DECL_NOTHROW-
5198{-
5199 for (int i = 0; i < NImageFormats; i++) {
i < NImageFormatsDescription
TRUEnever evaluated
FALSEnever evaluated
0
5200 if (format == pixelformats[i])
format == pixelformats[i]Description
TRUEnever evaluated
FALSEnever evaluated
0
5201 return Format(i);
never executed: return Format(i);
0
5202 }
never executed: end of block
0
5203 return Format_Invalid;
never executed: return Format_Invalid;
0
5204}-
5205-
5206Q_GUI_EXPORT void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient)-
5207{-
5208 if (orient == QImageIOHandler::TransformationNone)
orient == QIma...sformationNoneDescription
TRUEnever evaluated
FALSEnever evaluated
0
5209 return;
never executed: return;
0
5210 if (orient == QImageIOHandler::TransformationRotate270) {
orient == QIma...ationRotate270Description
TRUEnever evaluated
FALSEnever evaluated
0
5211 src = rotated270(src);-
5212 } else {
never executed: end of block
0
5213 src = qMove(src).mirrored(orient & QImageIOHandler::TransformationMirror,-
5214 orient & QImageIOHandler::TransformationFlip);-
5215 if (orient & QImageIOHandler::TransformationRotate90)
orient & QImag...mationRotate90Description
TRUEnever evaluated
FALSEnever evaluated
0
5216 src = rotated90(src);
never executed: src = rotated90(src);
0
5217 }
never executed: end of block
0
5218}-
5219-
5220QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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