image/qpixmap_raster.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8QPixmap qt_toRasterPixmap(const QImage &image) -
9{ -
10 QPlatformPixmap *data = -
11 new QRasterPlatformPixmap(image.depth() == 1 -
12 ? QPlatformPixmap::BitmapType -
13 : QPlatformPixmap::PixmapType); -
14 -
15 data->fromImage(image, Qt::AutoColor); -
16 -
17 return QPixmap(data);
never executed: return QPixmap(data);
0
18} -
19 -
20QPixmap qt_toRasterPixmap(const QPixmap &pixmap) -
21{ -
22 if (pixmap.isNull())
never evaluated: pixmap.isNull()
0
23 return QPixmap();
never executed: return QPixmap();
0
24 -
25 if (QPixmap(pixmap).data_ptr()->classId() == QPlatformPixmap::RasterClass)
never evaluated: QPixmap(pixmap).data_ptr()->classId() == QPlatformPixmap::RasterClass
0
26 return pixmap;
never executed: return pixmap;
0
27 -
28 return qt_toRasterPixmap(pixmap.toImage());
never executed: return qt_toRasterPixmap(pixmap.toImage());
0
29} -
30 -
31QRasterPlatformPixmap::QRasterPlatformPixmap(PixelType type) -
32 : QPlatformPixmap(type, RasterClass) -
33{ -
34}
executed: }
Execution Count:5017
5017
35 -
36QRasterPlatformPixmap::~QRasterPlatformPixmap() -
37{ -
38} -
39 -
40QPlatformPixmap *QRasterPlatformPixmap::createCompatiblePlatformPixmap() const -
41{ -
42 return new QRasterPlatformPixmap(pixelType());
executed: return new QRasterPlatformPixmap(pixelType());
Execution Count:65
65
43} -
44 -
45void QRasterPlatformPixmap::resize(int width, int height) -
46{ -
47 QImage::Format format; -
48 if (pixelType() == BitmapType)
evaluated: pixelType() == BitmapType
TRUEFALSE
yes
Evaluation Count:130
yes
Evaluation Count:818
130-818
49 format = QImage::Format_MonoLSB;
executed: format = QImage::Format_MonoLSB;
Execution Count:130
130
50 else -
51 format = QNativeImage::systemFormat();
executed: format = QNativeImage::systemFormat();
Execution Count:818
818
52 -
53 image = QImage(width, height, format); -
54 w = width; -
55 h = height; -
56 d = image.depth(); -
57 is_null = (w <= 0 || h <= 0);
evaluated: w <= 0
TRUEFALSE
yes
Evaluation Count:256
yes
Evaluation Count:692
partially evaluated: h <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:692
0-692
58 -
59 if (pixelType() == BitmapType && !image.isNull()) {
evaluated: pixelType() == BitmapType
TRUEFALSE
yes
Evaluation Count:130
yes
Evaluation Count:818
evaluated: !image.isNull()
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:113
17-818
60 image.setColorCount(2); -
61 image.setColor(0, QColor(Qt::color0).rgba()); -
62 image.setColor(1, QColor(Qt::color1).rgba()); -
63 }
executed: }
Execution Count:17
17
64 -
65 setSerialNumber(image.cacheKey() >> 32); -
66}
executed: }
Execution Count:948
948
67 -
68bool QRasterPlatformPixmap::fromData(const uchar *buffer, uint len, const char *format, -
69 Qt::ImageConversionFlags flags) -
70{ -
71 QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer), len); -
72 QBuffer b(&a); -
73 b.open(QIODevice::ReadOnly); -
74 QImage image = QImageReader(&b, format).read(); -
75 if (image.isNull())
partially evaluated: image.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
76 return false;
never executed: return false;
0
77 -
78 createPixmapForImage(image, flags, true); -
79 return !isNull();
executed: return !isNull();
Execution Count:18
18
80} -
81 -
82void QRasterPlatformPixmap::fromImage(const QImage &sourceImage, -
83 Qt::ImageConversionFlags flags) -
84{ -
85 (void)flags;; -
86 QImage image = sourceImage; -
87 createPixmapForImage(image, flags, false); -
88}
executed: }
Execution Count:4238
4238
89 -
90void QRasterPlatformPixmap::fromImageReader(QImageReader *imageReader, -
91 Qt::ImageConversionFlags flags) -
92{ -
93 (void)flags;; -
94 QImage image = imageReader->read(); -
95 if (image.isNull())
partially evaluated: image.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
0-15
96 return;
never executed: return;
0
97 -
98 createPixmapForImage(image, flags, true); -
99}
executed: }
Execution Count:15
15
100 -
101 -
102extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset); -
103 -
104void QRasterPlatformPixmap::copy(const QPlatformPixmap *data, const QRect &rect) -
105{ -
106 fromImage(data->toImage(rect).copy(), Qt::NoOpaqueDetection); -
107}
executed: }
Execution Count:55
55
108 -
109bool QRasterPlatformPixmap::scroll(int dx, int dy, const QRect &rect) -
110{ -
111 if (!image.isNull())
partially evaluated: !image.isNull()
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
0-12
112 qt_scrollRectInImage(image, rect, QPoint(dx, dy));
executed: qt_scrollRectInImage(image, rect, QPoint(dx, dy));
Execution Count:12
12
113 return true;
executed: return true;
Execution Count:12
12
114} -
115 -
116void QRasterPlatformPixmap::fill(const QColor &color) -
117{ -
118 uint pixel; -
119 -
120 if (image.depth() == 1) {
evaluated: image.depth() == 1
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:409
14-409
121 int gray = qGray(color.rgba()); -
122 -
123 if (qAbs(qGray(image.color(0)) - gray) < qAbs(qGray(image.color(1)) - gray))
evaluated: qAbs(qGray(image.color(0)) - gray) < qAbs(qGray(image.color(1)) - gray)
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:6
6-8
124 pixel = 0;
executed: pixel = 0;
Execution Count:8
8
125 else -
126 pixel = 1;
executed: pixel = 1;
Execution Count:6
6
127 } else if (image.depth() >= 15) {
partially evaluated: image.depth() >= 15
TRUEFALSE
yes
Evaluation Count:409
no
Evaluation Count:0
0-409
128 int alpha = color.alpha(); -
129 if (alpha != 255) {
evaluated: alpha != 255
TRUEFALSE
yes
Evaluation Count:83
yes
Evaluation Count:326
83-326
130 if (!image.hasAlphaChannel()) {
partially evaluated: !image.hasAlphaChannel()
TRUEFALSE
yes
Evaluation Count:83
no
Evaluation Count:0
0-83
131 QImage::Format toFormat; -
132 toFormat = QImage::Format_ARGB32_Premultiplied; -
133 -
134 if (!image.isNull() && qt_depthForFormat(image.format()) == qt_depthForFormat(toFormat)) {
partially evaluated: !image.isNull()
TRUEFALSE
yes
Evaluation Count:83
no
Evaluation Count:0
partially evaluated: qt_depthForFormat(image.format()) == qt_depthForFormat(toFormat)
TRUEFALSE
yes
Evaluation Count:83
no
Evaluation Count:0
0-83
135 image.detach(); -
136 image.d->format = toFormat; -
137 } else {
executed: }
Execution Count:83
83
138 image = QImage(image.width(), image.height(), toFormat); -
139 }
never executed: }
0
140 } -
141 }
executed: }
Execution Count:83
83
142 pixel = PREMUL(color.rgba()); -
143 const QPixelLayout *layout = &qPixelLayouts[image.format()]; -
144 layout->convertFromARGB32PM(&pixel, &pixel, 1, layout, 0); -
145 } else {
executed: }
Execution Count:409
409
146 pixel = 0; -
147 -
148 }
never executed: }
0
149 -
150 image.fill(pixel); -
151}
executed: }
Execution Count:423
423
152 -
153bool QRasterPlatformPixmap::hasAlphaChannel() const -
154{ -
155 return image.hasAlphaChannel();
executed: return image.hasAlphaChannel();
Execution Count:89
89
156} -
157 -
158QImage QRasterPlatformPixmap::toImage() const -
159{ -
160 if (!image.isNull()) {
partially evaluated: !image.isNull()
TRUEFALSE
yes
Evaluation Count:2189
no
Evaluation Count:0
0-2189
161 QImageData *data = const_cast<QImage &>(image).data_ptr(); -
162 if (data->paintEngine && data->paintEngine->isActive()
evaluated: data->paintEngine
TRUEFALSE
yes
Evaluation Count:276
yes
Evaluation Count:1913
evaluated: data->paintEngine->isActive()
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:269
7-1913
163 && data->paintEngine->paintDevice() == &image)
partially evaluated: data->paintEngine->paintDevice() == &image
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
164 { -
165 return image.copy();
executed: return image.copy();
Execution Count:7
7
166 } -
167 }
executed: }
Execution Count:2182
2182
168 -
169 return image;
executed: return image;
Execution Count:2182
2182
170} -
171 -
172QImage QRasterPlatformPixmap::toImage(const QRect &rect) const -
173{ -
174 if (rect.isNull())
partially evaluated: rect.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:55
0-55
175 return image;
never executed: return image;
0
176 -
177 QRect clipped = rect.intersected(QRect(0, 0, w, h)); -
178 const uint du = uint(d); -
179 if ((du % 8 == 0) && (((uint(clipped.x()) * du)) % 32 == 0))
evaluated: (du % 8 == 0)
TRUEFALSE
yes
Evaluation Count:54
yes
Evaluation Count:1
evaluated: (((uint(clipped.x()) * du)) % 32 == 0)
TRUEFALSE
yes
Evaluation Count:53
yes
Evaluation Count:1
1-54
180 return QImage(image.scanLine(clipped.y()) + clipped.x() * (du / 8), 53
181 clipped.width(), clipped.height(), 53
182 image.bytesPerLine(), image.format());
executed: return QImage(image.scanLine(clipped.y()) + clipped.x() * (du / 8), clipped.width(), clipped.height(), image.bytesPerLine(), image.format());
Execution Count:53
53
183 else -
184 return image.copy(clipped);
executed: return image.copy(clipped);
Execution Count:2
2
185} -
186 -
187QPaintEngine* QRasterPlatformPixmap::paintEngine() const -
188{ -
189 return image.paintEngine();
executed: return image.paintEngine();
Execution Count:2155
2155
190} -
191 -
192int QRasterPlatformPixmap::metric(QPaintDevice::PaintDeviceMetric metric) const -
193{ -
194 QImageData *d = image.d; -
195 if (!d)
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1963
0-1963
196 return 0;
never executed: return 0;
0
197 -
198 -
199 switch (metric) { -
200 case QPaintDevice::PdmWidth: -
201 return w;
executed: return w;
Execution Count:485
485
202 case QPaintDevice::PdmHeight: -
203 return h;
executed: return h;
Execution Count:485
485
204 case QPaintDevice::PdmWidthMM: -
205 return qRound(d->width * 25.4 / qt_defaultDpiX());
never executed: return qRound(d->width * 25.4 / qt_defaultDpiX());
0
206 case QPaintDevice::PdmHeightMM: -
207 return qRound(d->height * 25.4 / qt_defaultDpiY());
never executed: return qRound(d->height * 25.4 / qt_defaultDpiY());
0
208 case QPaintDevice::PdmNumColors: -
209 return d->colortable.size();
never executed: return d->colortable.size();
0
210 case QPaintDevice::PdmDepth: -
211 return this->d;
never executed: return this->d;
0
212 case QPaintDevice::PdmDpiX: -
213 return qt_defaultDpiX();
executed: return qt_defaultDpiX();
Execution Count:6
6
214 case QPaintDevice::PdmPhysicalDpiX: -
215 return qt_defaultDpiX() * image.devicePixelRatio();
never executed: return qt_defaultDpiX() * image.devicePixelRatio();
0
216 case QPaintDevice::PdmDpiY: -
217 return qt_defaultDpiX();
executed: return qt_defaultDpiX();
Execution Count:987
987
218 case QPaintDevice::PdmPhysicalDpiY: -
219 return qt_defaultDpiY() * image.devicePixelRatio();
never executed: return qt_defaultDpiY() * image.devicePixelRatio();
0
220 default: -
221 QMessageLogger("image/qpixmap_raster.cpp", 285, __PRETTY_FUNCTION__).warning("QRasterPlatformPixmap::metric(): Unhandled metric type %d", metric); -
222 break;
never executed: break;
0
223 } -
224 -
225 return 0;
never executed: return 0;
0
226} -
227 -
228void QRasterPlatformPixmap::createPixmapForImage(QImage &sourceImage, Qt::ImageConversionFlags flags, bool inPlace) -
229{ -
230 QImage::Format format; -
231 if (flags & Qt::NoFormatConversion)
evaluated: flags & Qt::NoFormatConversion
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4270
1-4270
232 format = sourceImage.format();
executed: format = sourceImage.format();
Execution Count:1
1
233 else -
234 if (pixelType() == BitmapType) {
evaluated: pixelType() == BitmapType
TRUEFALSE
yes
Evaluation Count:212
yes
Evaluation Count:4058
212-4058
235 format = QImage::Format_MonoLSB; -
236 } else {
executed: }
Execution Count:212
212
237 if (sourceImage.depth() == 1) {
evaluated: sourceImage.depth() == 1
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:4053
5-4053
238 format = sourceImage.hasAlphaChannel()
partially evaluated: sourceImage.hasAlphaChannel()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
239 ? QImage::Format_ARGB32_Premultiplied -
240 : QImage::Format_RGB32; -
241 } else {
executed: }
Execution Count:5
5
242 QImage::Format opaqueFormat = QNativeImage::systemFormat(); -
243 QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied; -
244 if (!sourceImage.hasAlphaChannel()) {
evaluated: !sourceImage.hasAlphaChannel()
TRUEFALSE
yes
Evaluation Count:230
yes
Evaluation Count:3823
230-3823
245 format = opaqueFormat; -
246 } else if ((flags & Qt::NoOpaqueDetection) == 0
executed: }
Execution Count:230
evaluated: (flags & Qt::NoOpaqueDetection) == 0
TRUEFALSE
yes
Evaluation Count:3822
yes
Evaluation Count:1
1-3822
247 && !const_cast<QImage &>(sourceImage).data_ptr()->checkForAlphaPixels())
evaluated: !const_cast<QImage &>(sourceImage).data_ptr()->checkForAlphaPixels()
TRUEFALSE
yes
Evaluation Count:1108
yes
Evaluation Count:2714
1108-2714
248 { -
249 format = opaqueFormat; -
250 } else {
executed: }
Execution Count:1108
1108
251 format = alphaFormat; -
252 }
executed: }
Execution Count:2715
2715
253 } -
254 } -
255 -
256 -
257 -
258 if (format == QImage::Format_RGB32 && (sourceImage.format() == QImage::Format_ARGB32
evaluated: format == QImage::Format_RGB32
TRUEFALSE
yes
Evaluation Count:1343
yes
Evaluation Count:2928
evaluated: sourceImage.format() == QImage::Format_ARGB32
TRUEFALSE
yes
Evaluation Count:121
yes
Evaluation Count:1222
121-2928
259 || sourceImage.format() == QImage::Format_ARGB32_Premultiplied))
evaluated: sourceImage.format() == QImage::Format_ARGB32_Premultiplied
TRUEFALSE
yes
Evaluation Count:987
yes
Evaluation Count:235
235-987
260 { -
261 image = sourceImage; -
262 if (!inPlace)
evaluated: !inPlace
TRUEFALSE
yes
Evaluation Count:1105
yes
Evaluation Count:3
3-1105
263 image.detach();
executed: image.detach();
Execution Count:1105
1105
264 if (image.d)
partially evaluated: image.d
TRUEFALSE
yes
Evaluation Count:1108
no
Evaluation Count:0
0-1108
265 image.d->format = QImage::Format_RGB32;
executed: image.d->format = QImage::Format_RGB32;
Execution Count:1108
1108
266 } else if (inPlace && sourceImage.d->convertInPlace(format, flags)) {
evaluated: inPlace
TRUEFALSE
yes
Evaluation Count:30
yes
Evaluation Count:3133
evaluated: sourceImage.d->convertInPlace(format, flags)
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:5
executed: }
Execution Count:1108
5-3133
267 image = sourceImage; -
268 } else {
executed: }
Execution Count:25
25
269 image = sourceImage.convertToFormat(format); -
270 }
executed: }
Execution Count:3138
3138
271 -
272 if (image.d) {
partially evaluated: image.d
TRUEFALSE
yes
Evaluation Count:4271
no
Evaluation Count:0
0-4271
273 w = image.d->width; -
274 h = image.d->height; -
275 d = image.d->depth; -
276 } else {
executed: }
Execution Count:4271
4271
277 w = h = d = 0; -
278 }
never executed: }
0
279 is_null = (w <= 0 || h <= 0);
partially evaluated: w <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4271
partially evaluated: h <= 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4271
0-4271
280 -
281 image.d->devicePixelRatio = sourceImage.devicePixelRatio(); -
282 setSerialNumber(image.cacheKey() >> 32); -
283}
executed: }
Execution Count:4271
4271
284 -
285QImage* QRasterPlatformPixmap::buffer() -
286{ -
287 return &image;
executed: return &image;
Execution Count:833
833
288} -
289 -
290qreal QRasterPlatformPixmap::devicePixelRatio() const -
291{ -
292 return image.devicePixelRatio();
executed: return image.devicePixelRatio();
Execution Count:5502
5502
293} -
294 -
295void QRasterPlatformPixmap::setDevicePixelRatio(qreal scaleFactor) -
296{ -
297 image.setDevicePixelRatio(scaleFactor); -
298}
executed: }
Execution Count:8
8
299 -
300 -
301 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial