replace QRasterPixmapData::createPixmapForImage() with its body

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2020-04-04 07:47:52 +00:00
parent 3ebd923227
commit 40558f0630
2 changed files with 45 additions and 51 deletions

View file

@ -93,14 +93,56 @@ bool QRasterPixmapData::fromData(const uchar *buffer, uint len, const char *form
if (image.isNull())
return false;
createPixmapForImage(image, flags);
fromImage(image, flags);
return !isNull();
}
void QRasterPixmapData::fromImage(const QImage &sourceImage,
Qt::ImageConversionFlags flags)
{
createPixmapForImage(sourceImage, flags);
QImage::Format format;
if (flags & Qt::NoFormatConversion) {
format = sourceImage.format();
} else if (pixelType() == BitmapType) {
format = QImage::Format_MonoLSB;
} else {
if (sourceImage.depth() == 1) {
format = sourceImage.hasAlphaChannel()
? QImage::Format_ARGB32_Premultiplied
: QImage::Format_RGB32;
} else {
QImage::Format opaqueFormat = QImage::systemFormat();
QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied;
// We don't care about the others...
if (opaqueFormat == QImage::Format_RGB16) {
alphaFormat = QImage::Format_ARGB8565_Premultiplied;
}
if (!sourceImage.hasAlphaChannel()) {
format = opaqueFormat;
} else if ((flags & Qt::NoOpaqueDetection) == 0
&& !sourceImage.data_ptr()->checkForAlphaPixels())
{
format = opaqueFormat;
} else {
format = alphaFormat;
}
}
}
image = sourceImage.convertToFormat(format);
if (image.d) {
w = image.d->width;
h = image.d->height;
d = image.d->depth;
} else {
w = h = d = 0;
}
is_null = (w <= 0 || h <= 0);
setSerialNumber(image.cacheKey() >> 32);
}
void QRasterPixmapData::fromImageReader(QImageReader *imageReader,
@ -110,7 +152,7 @@ void QRasterPixmapData::fromImageReader(QImageReader *imageReader,
if (image.isNull())
return;
createPixmapForImage(image, flags);
fromImage(image, flags);
}
// from qwindowsurface.cpp
@ -261,53 +303,6 @@ int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
return 0;
}
void QRasterPixmapData::createPixmapForImage(const QImage &sourceImage, Qt::ImageConversionFlags flags)
{
QImage::Format format;
if (flags & Qt::NoFormatConversion) {
format = sourceImage.format();
} else if (pixelType() == BitmapType) {
format = QImage::Format_MonoLSB;
} else {
if (sourceImage.depth() == 1) {
format = sourceImage.hasAlphaChannel()
? QImage::Format_ARGB32_Premultiplied
: QImage::Format_RGB32;
} else {
QImage::Format opaqueFormat = QImage::systemFormat();
QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied;
// We don't care about the others...
if (opaqueFormat == QImage::Format_RGB16) {
alphaFormat = QImage::Format_ARGB8565_Premultiplied;
}
if (!sourceImage.hasAlphaChannel()) {
format = opaqueFormat;
} else if ((flags & Qt::NoOpaqueDetection) == 0
&& !sourceImage.data_ptr()->checkForAlphaPixels())
{
format = opaqueFormat;
} else {
format = alphaFormat;
}
}
}
image = sourceImage.convertToFormat(format);
if (image.d) {
w = image.d->width;
h = image.d->height;
d = image.d->depth;
} else {
w = h = d = 0;
}
is_null = (w <= 0 || h <= 0);
setSerialNumber(image.cacheKey() >> 32);
}
QImage* QRasterPixmapData::buffer()
{
return &image;

View file

@ -75,7 +75,6 @@ public:
protected:
int metric(QPaintDevice::PaintDeviceMetric metric) const;
void createPixmapForImage(const QImage &sourceImage, Qt::ImageConversionFlags flags);
void setImage(const QImage &image);
QImage image;