23QPlatformPixmap *QPlatformPixmap::create(
int w,
int h, PixelType type)
25 if (Q_UNLIKELY(!QGuiApplicationPrivate::platformIntegration()))
26 qFatal(
"QPlatformPixmap: QGuiApplication required");
28 QPlatformPixmap *data = QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(
static_cast<QPlatformPixmap::PixelType>(type));
70 if (d->pixelType() == QPlatformPixmap::BitmapType) {
71 QImage img = std::move(image).convertToFormat(QImage::Format_MonoLSB, flags);
75 const QRgb c0 = QColor(Qt::black).rgb();
76 const QRgb c1 = QColor(Qt::white).rgb();
77 if (img.color(0) == c0 && img.color(1) == c1) {
95bool QPlatformPixmap::fromFile(
const QString &fileName,
const char *format,
96 Qt::ImageConversionFlags flags)
98 QImage image = QImageReader(fileName, format).read();
101 fromImage(makeBitmapCompliantIfNeeded(
this, std::move(image), flags), flags);
105bool QPlatformPixmap::fromData(
const uchar *buf, uint len,
const char *format, Qt::ImageConversionFlags flags)
107 QByteArray a = QByteArray::fromRawData(
reinterpret_cast<
const char *>(buf), len);
109 b.open(QIODevice::ReadOnly);
110 QImage image = QImageReader(&b, format).read();
113 fromImage(makeBitmapCompliantIfNeeded(
this, std::move(image), flags), flags);
130QBitmap QPlatformPixmap::mask()
const
132 if (!hasAlphaChannel())
135 QImage img = toImage();
136 bool shouldConvert = (img.format() != QImage::Format_ARGB32 && img.format() != QImage::Format_ARGB32_Premultiplied);
137 const QImage image = (shouldConvert ? std::move(img).convertToFormat(QImage::Format_ARGB32_Premultiplied) : img);
138 const int w = image.width();
139 const int h = image.height();
141 QImage mask(w, h, QImage::Format_MonoLSB);
145 mask.setDevicePixelRatio(devicePixelRatio());
146 mask.setColorCount(2);
147 mask.setColor(0, QColor(Qt::color0).rgba());
148 mask.setColor(1, QColor(Qt::color1).rgba());
150 const qsizetype bpl = mask.bytesPerLine();
152 for (
int y = 0; y < h; ++y) {
153 const QRgb *src =
reinterpret_cast<
const QRgb*>(image.scanLine(y));
154 uchar *dest = mask.scanLine(y);
155 memset(dest, 0, bpl);
156 for (
int x = 0; x < w; ++x) {
157 if (qAlpha(*src) > 0)
158 dest[x >> 3] |= (1 << (x & 7));
163 return QBitmap::fromImage(std::move(mask));
166void QPlatformPixmap::setMask(
const QBitmap &mask)
168 QImage image = toImage();
169 if (mask.size().isEmpty()) {
170 if (image.depth() != 1) {
171 image = std::move(image).convertToFormat(QImage::Format_RGB32);
174 const int w = image.width();
175 const int h = image.height();
177 switch (image.depth()) {
179 const QImage imageMask = mask.toImage().convertToFormat(image.format());
180 for (
int y = 0; y < h; ++y) {
181 const uchar *mscan = imageMask.scanLine(y);
182 uchar *tscan = image.scanLine(y);
183 qsizetype bytesPerLine = image.bytesPerLine();
184 for (
int i = 0; i < bytesPerLine; ++i)
185 tscan[i] &= mscan[i];
190 const QImage imageMask = mask.toImage().convertToFormat(QImage::Format_MonoLSB);
191 image = std::move(image).convertToFormat(QImage::Format_ARGB32_Premultiplied);
192 for (
int y = 0; y < h; ++y) {
193 const uchar *mscan = imageMask.scanLine(y);
194 QRgb *tscan = (QRgb *)image.scanLine(y);
195 for (
int x = 0; x < w; ++x) {
196 if (!(mscan[x>>3] & (1 << (x&7))))
204 fromImage(image, Qt::AutoColor);