qpixmap_raster.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qpixmap_raster.cpp
Switch to Source codePreprocessed file
LineSourceCount
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
never executed: return QPixmap(data);
QPixmap(data);
never executed: return QPixmap(data);
0
18}-
19-
20QPixmap qt_toRasterPixmap(const QPixmap &pixmap)-
21{-
22 if (pixmap.isNull()
pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
23 return
never executed: return QPixmap();
QPixmap();
never executed: return QPixmap();
0
24-
25 if (QPixmap(pixmap).data_ptr()->classId() == QPlatformPixmap::RasterClass
QPixmap(pixmap...p::RasterClassDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
26 return
never executed: return pixmap;
pixmap;
never executed: return pixmap;
0
27-
28 return
never executed: return qt_toRasterPixmap(pixmap.toImage());
qt_toRasterPixmap(pixmap.toImage());
never executed: return qt_toRasterPixmap(pixmap.toImage());
0
29}-
30-
31QRasterPlatformPixmap::QRasterPlatformPixmap(PixelType type)-
32 : QPlatformPixmap(type, RasterClass)-
33{-
34}
never executed: end of block
0
35-
36QRasterPlatformPixmap::~QRasterPlatformPixmap()-
37{-
38}-
39-
40QPlatformPixmap *QRasterPlatformPixmap::createCompatiblePlatformPixmap() const-
41{-
42 return
never executed: return new QRasterPlatformPixmap(pixelType());
new QRasterPlatformPixmap(pixelType());
never executed: return new QRasterPlatformPixmap(pixelType());
0
43}-
44-
45void QRasterPlatformPixmap::resize(int width, int height)-
46{-
47 QImage::Format format;-
48 if (pixelType() == BitmapType
pixelType() == BitmapTypeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
49 format = QImage::Format_MonoLSB;
never executed: format = QImage::Format_MonoLSB;
0
50 else-
51 format = QNativeImage::systemFormat();
never executed: format = QNativeImage::systemFormat();
0
52-
53 image = QImage(width, height, format);-
54 w = width;-
55 h = height;-
56 d = image.depth();-
57 is_null = (w <= 0
w <= 0Description
TRUEnever evaluated
FALSEnever evaluated
|| h <= 0
h <= 0Description
TRUEnever evaluated
FALSEnever evaluated
);
0
58-
59 if (pixelType() == BitmapType
pixelType() == BitmapTypeDescription
TRUEnever evaluated
FALSEnever evaluated
&& !image.isNull()
!image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
60 image.setColorCount(2);-
61 image.setColor(0, QColor(Qt::color0).rgba());-
62 image.setColor(1, QColor(Qt::color1).rgba());-
63 }
never executed: end of block
0
64-
65 setSerialNumber(image.cacheKey() >> 32);-
66}
never executed: end of block
0
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()
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
76 return
never executed: return false;
false;
never executed: return false;
0
77-
78 createPixmapForImage(image, flags, true);-
79 return
never executed: return !isNull();
!isNull();
never executed: return !isNull();
0
80}-
81-
82void QRasterPlatformPixmap::fromImage(const QImage &sourceImage,-
83 Qt::ImageConversionFlags flags)-
84{-
85 QImage image = sourceImage;-
86 createPixmapForImage(image, flags, false);-
87}
never executed: end of block
0
88-
89void QRasterPlatformPixmap::fromImageInPlace(QImage &sourceImage,-
90 Qt::ImageConversionFlags flags)-
91{-
92 createPixmapForImage(sourceImage, flags, true);-
93}
never executed: end of block
0
94-
95void QRasterPlatformPixmap::fromImageReader(QImageReader *imageReader,-
96 Qt::ImageConversionFlags flags)-
97{-
98 (void)flags;;-
99 QImage image = imageReader->read();-
100 if (image.isNull()
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
101 return;
never executed: return;
0
102-
103 createPixmapForImage(image, flags, true);-
104}
never executed: end of block
0
105-
106-
107extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);-
108-
109void QRasterPlatformPixmap::copy(const QPlatformPixmap *data, const QRect &rect)-
110{-
111 fromImage(data->toImage(rect).copy(), Qt::NoOpaqueDetection);-
112}
never executed: end of block
0
113-
114bool QRasterPlatformPixmap::scroll(int dx, int dy, const QRect &rect)-
115{-
116 if (!image.isNull()
!image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
117 qt_scrollRectInImage(image, rect, QPoint(dx, dy));
never executed: qt_scrollRectInImage(image, rect, QPoint(dx, dy));
0
118 return
never executed: return true;
true;
never executed: return true;
0
119}-
120-
121void QRasterPlatformPixmap::fill(const QColor &color)-
122{-
123 uint pixel;-
124-
125 if (image.depth() == 1
image.depth() == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
126 int gray = qGray(color.rgba());-
127-
128 if (qAbs(qGray(image.color(0)) - gray) < qAbs(qGray(image.color(1)) - gray)
qAbs(qGray(ima...or(1)) - gray)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
129 pixel = 0;
never executed: pixel = 0;
0
130 else-
131 pixel = 1;
never executed: pixel = 1;
0
132 } else if (image.depth() >= 15
image.depth() >= 15Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
133 int alpha = color.alpha();-
134 if (alpha != 255
alpha != 255Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
135 if (!image.hasAlphaChannel()
!image.hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
136 QImage::Format toFormat = qt_alphaVersionForPainting(image.format());-
137 if (!image.isNull()
!image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
&& qt_depthForFormat(image.format()) == qt_depthForFormat(toFormat)
qt_depthForFor...rmat(toFormat)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
138 image.detach();-
139 image.d->format = toFormat;-
140 }
never executed: end of block
else {
0
141 image = QImage(image.width(), image.height(), toFormat);-
142 }
never executed: end of block
0
143 }-
144 }
never executed: end of block
0
145 pixel = qPremultiply(color.rgba());-
146 const QPixelLayout *layout = &qPixelLayouts[image.format()];-
147 layout->convertFromARGB32PM(&pixel, &pixel, 1, layout, 0);-
148 }
never executed: end of block
else if (image.format() == QImage::Format_Alpha8
image.format()...:Format_Alpha8Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
149 pixel = qAlpha(color.rgba());-
150 }
never executed: end of block
else if (image.format() == QImage::Format_Grayscale8
image.format()...mat_Grayscale8Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
151 pixel = qGray(color.rgba());-
152 }
never executed: end of block
else
0
153 {-
154 pixel = 0;-
155-
156 }
never executed: end of block
0
157-
158 image.fill(pixel);-
159}
never executed: end of block
0
160-
161bool QRasterPlatformPixmap::hasAlphaChannel() const-
162{-
163 return
never executed: return image.hasAlphaChannel();
image.hasAlphaChannel();
never executed: return image.hasAlphaChannel();
0
164}-
165-
166QImage QRasterPlatformPixmap::toImage() const-
167{-
168 if (!image.isNull()
!image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
169 QImageData *data = const_cast<QImage &>(image).data_ptr();-
170 if (data->paintEngine
data->paintEngineDescription
TRUEnever evaluated
FALSEnever evaluated
&& data->paintEngine->isActive()
data->paintEngine->isActive()Description
TRUEnever evaluated
FALSEnever evaluated
0
171 && data->paintEngine->paintDevice() == &image
data->paintEng...ce() == &imageDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
172 {-
173 return
never executed: return image.copy();
image.copy();
never executed: return image.copy();
0
174 }-
175 }
never executed: end of block
0
176-
177 return
never executed: return image;
image;
never executed: return image;
0
178}-
179-
180QImage QRasterPlatformPixmap::toImage(const QRect &rect) const-
181{-
182 if (rect.isNull()
rect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
183 return
never executed: return image;
image;
never executed: return image;
0
184-
185 QRect clipped = rect.intersected(QRect(0, 0, w, h));-
186 const uint du = uint(d);-
187 if ((
(du % 8 == 0)Description
TRUEnever evaluated
FALSEnever evaluated
du % 8 == 0)
(du % 8 == 0)Description
TRUEnever evaluated
FALSEnever evaluated
&& (((
(((uint(clippe...u)) % 32 == 0)Description
TRUEnever evaluated
FALSEnever evaluated
uint(clipped.x()) * du)) % 32 == 0)
(((uint(clippe...u)) % 32 == 0)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
188 QImage newImage(image.scanLine(clipped.y()) + clipped.x() * (du / 8),-
189 clipped.width(), clipped.height(),-
190 image.bytesPerLine(), image.format());-
191 newImage.setDevicePixelRatio(image.devicePixelRatio());-
192 return
never executed: return newImage;
newImage;
never executed: return newImage;
0
193 } else {-
194 return
never executed: return image.copy(clipped);
image.copy(clipped);
never executed: return image.copy(clipped);
0
195 }-
196}-
197-
198QPaintEngine* QRasterPlatformPixmap::paintEngine() const-
199{-
200 return
never executed: return image.paintEngine();
image.paintEngine();
never executed: return image.paintEngine();
0
201}-
202-
203int QRasterPlatformPixmap::metric(QPaintDevice::PaintDeviceMetric metric) const-
204{-
205 QImageData *d = image.d;-
206 if (!d
!dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
207 return
never executed: return 0;
0;
never executed: return 0;
0
208-
209-
210 switch (metric) {-
211 case
never executed: case QPaintDevice::PdmWidth:
QPaintDevice::PdmWidth:
never executed: case QPaintDevice::PdmWidth:
0
212 return
never executed: return w;
w;
never executed: return w;
0
213 case
never executed: case QPaintDevice::PdmHeight:
QPaintDevice::PdmHeight:
never executed: case QPaintDevice::PdmHeight:
0
214 return
never executed: return h;
h;
never executed: return h;
0
215 case
never executed: case QPaintDevice::PdmWidthMM:
QPaintDevice::PdmWidthMM:
never executed: case QPaintDevice::PdmWidthMM:
0
216 return
never executed: return qRound(d->width * 25.4 / qt_defaultDpiX());
qRound(d->width * 25.4 / qt_defaultDpiX());
never executed: return qRound(d->width * 25.4 / qt_defaultDpiX());
0
217 case
never executed: case QPaintDevice::PdmHeightMM:
QPaintDevice::PdmHeightMM:
never executed: case QPaintDevice::PdmHeightMM:
0
218 return
never executed: return qRound(d->height * 25.4 / qt_defaultDpiY());
qRound(d->height * 25.4 / qt_defaultDpiY());
never executed: return qRound(d->height * 25.4 / qt_defaultDpiY());
0
219 case
never executed: case QPaintDevice::PdmNumColors:
QPaintDevice::PdmNumColors:
never executed: case QPaintDevice::PdmNumColors:
0
220 return
never executed: return d->colortable.size();
d->colortable.size();
never executed: return d->colortable.size();
0
221 case
never executed: case QPaintDevice::PdmDepth:
QPaintDevice::PdmDepth:
never executed: case QPaintDevice::PdmDepth:
0
222 return
never executed: return this->d;
this->d;
never executed: return this->d;
0
223 case
never executed: case QPaintDevice::PdmDpiX:
QPaintDevice::PdmDpiX:
never executed: case QPaintDevice::PdmDpiX:
0
224 return
never executed: return qt_defaultDpiX();
qt_defaultDpiX();
never executed: return qt_defaultDpiX();
0
225 case
never executed: case QPaintDevice::PdmPhysicalDpiX:
QPaintDevice::PdmPhysicalDpiX:
never executed: case QPaintDevice::PdmPhysicalDpiX:
0
226 return
never executed: return qt_defaultDpiX();
qt_defaultDpiX();
never executed: return qt_defaultDpiX();
0
227 case
never executed: case QPaintDevice::PdmDpiY:
QPaintDevice::PdmDpiY:
never executed: case QPaintDevice::PdmDpiY:
0
228 return
never executed: return qt_defaultDpiX();
qt_defaultDpiX();
never executed: return qt_defaultDpiX();
0
229 case
never executed: case QPaintDevice::PdmPhysicalDpiY:
QPaintDevice::PdmPhysicalDpiY:
never executed: case QPaintDevice::PdmPhysicalDpiY:
0
230 return
never executed: return qt_defaultDpiY();
qt_defaultDpiY();
never executed: return qt_defaultDpiY();
0
231 case
never executed: case QPaintDevice::PdmDevicePixelRatio:
QPaintDevice::PdmDevicePixelRatio:
never executed: case QPaintDevice::PdmDevicePixelRatio:
0
232 return
never executed: return image.devicePixelRatio();
image.devicePixelRatio();
never executed: return image.devicePixelRatio();
0
233 case
never executed: case QPaintDevice::PdmDevicePixelRatioScaled:
QPaintDevice::PdmDevicePixelRatioScaled:
never executed: case QPaintDevice::PdmDevicePixelRatioScaled:
0
234 return
never executed: return image.devicePixelRatio() * QPaintDevice::devicePixelRatioFScale();
image.devicePixelRatio() * QPaintDevice::devicePixelRatioFScale();
never executed: return image.devicePixelRatio() * QPaintDevice::devicePixelRatioFScale();
0
235-
236 default
never executed: default:
:
never executed: default:
0
237 QMessageLogger(__FILE__, 288, __PRETTY_FUNCTION__).warning("QRasterPlatformPixmap::metric(): Unhandled metric type %d", metric);-
238 break;
never executed: break;
0
239 }-
240-
241 return
never executed: return 0;
0;
never executed: return 0;
0
242}-
243-
244void QRasterPlatformPixmap::createPixmapForImage(QImage &sourceImage, Qt::ImageConversionFlags flags, bool inPlace)-
245{-
246 QImage::Format format;-
247 if (flags & Qt::NoFormatConversion
flags & Qt::NoFormatConversionDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
248 format = sourceImage.format();
never executed: format = sourceImage.format();
0
249 else-
250 if (pixelType() == BitmapType
pixelType() == BitmapTypeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
251 format = QImage::Format_MonoLSB;-
252 }
never executed: end of block
else {
0
253 if (sourceImage.depth() == 1
sourceImage.depth() == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
254 format = sourceImage.hasAlphaChannel()
sourceImage.hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
0
255 ? QImage::Format_ARGB32_Premultiplied-
256 : QImage::Format_RGB32;-
257 }
never executed: end of block
else {
0
258 QImage::Format opaqueFormat = QNativeImage::systemFormat();-
259 QImage::Format alphaFormat = qt_alphaVersionForPainting(opaqueFormat);-
260-
261 if (!sourceImage.hasAlphaChannel()
!sourceImage.hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
262 format = opaqueFormat;-
263 }
never executed: end of block
else if ((
(flags & Qt::N...etection) == 0Description
TRUEnever evaluated
FALSEnever evaluated
flags & Qt::NoOpaqueDetection) == 0
(flags & Qt::N...etection) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
264 && !const_cast<QImage &>(sourceImage).data_ptr()->checkForAlphaPixels()
!const_cast<QI...rAlphaPixels()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
265 {-
266 format = opaqueFormat;-
267 }
never executed: end of block
else {
0
268 format = alphaFormat;-
269 }
never executed: end of block
0
270 }-
271 }-
272-
273-
274-
275 if (format == QImage::Format_RGB32
format == QImage::Format_RGB32Description
TRUEnever evaluated
FALSEnever evaluated
&& (sourceImage.format() == QImage::Format_ARGB32
sourceImage.fo...:Format_ARGB32Description
TRUEnever evaluated
FALSEnever evaluated
0
276 || sourceImage.format() == QImage::Format_ARGB32_Premultiplied
sourceImage.fo..._PremultipliedDescription
TRUEnever evaluated
FALSEnever evaluated
))
0
277 {-
278 inPlace = inPlace
inPlaceDescription
TRUEnever evaluated
FALSEnever evaluated
&& sourceImage.isDetached()
sourceImage.isDetached()Description
TRUEnever evaluated
FALSEnever evaluated
;
0
279 image = sourceImage;-
280 if (!inPlace
!inPlaceDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
281 image.detach();
never executed: image.detach();
0
282 if (image.d
image.dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
283 image.d->format = QImage::Format_RGB32;
never executed: image.d->format = QImage::Format_RGB32;
0
284 }
never executed: end of block
else if (inPlace
inPlaceDescription
TRUEnever evaluated
FALSEnever evaluated
&& sourceImage.d->convertInPlace(format, flags)
sourceImage.d-...format, flags)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
285 image = sourceImage;-
286 }
never executed: end of block
else {
0
287 image = sourceImage.convertToFormat(format);-
288 }
never executed: end of block
0
289-
290 if (image.d
image.dDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
291 w = image.d->width;-
292 h = image.d->height;-
293 d = image.d->depth;-
294 }
never executed: end of block
else {
0
295 w = h = d = 0;-
296 }
never executed: end of block
0
297 is_null = (w <= 0
w <= 0Description
TRUEnever evaluated
FALSEnever evaluated
|| h <= 0
h <= 0Description
TRUEnever evaluated
FALSEnever evaluated
);
0
298-
299 if (image.d
image.dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
300 image.d->devicePixelRatio = sourceImage.devicePixelRatio();
never executed: image.d->devicePixelRatio = sourceImage.devicePixelRatio();
0
301-
302 setSerialNumber(image.cacheKey() >> 32);-
303 if (image.d
image.dDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
304 setDetachNumber(image.d->detach_no);
never executed: setDetachNumber(image.d->detach_no);
0
305}
never executed: end of block
0
306-
307QImage* QRasterPlatformPixmap::buffer()-
308{-
309 return
never executed: return &image;
&image;
never executed: return &image;
0
310}-
311-
312qreal QRasterPlatformPixmap::devicePixelRatio() const-
313{-
314 return
never executed: return image.devicePixelRatio();
image.devicePixelRatio();
never executed: return image.devicePixelRatio();
0
315}-
316-
317void QRasterPlatformPixmap::setDevicePixelRatio(qreal scaleFactor)-
318{-
319 image.setDevicePixelRatio(scaleFactor);-
320}
never executed: end of block
0
321-
322-
Switch to Source codePreprocessed file

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