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