convert QPixmapData::create() method to specialized constructor

now QPixmap::load() and QPixmap::loadFromData() will be slightly faster

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-11-10 18:14:06 +02:00
parent c3892b017c
commit 8c9142d956
3 changed files with 24 additions and 14 deletions

View file

@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE
void QPixmap::init(int w, int h, int type)
{
if ((w > 0 && h > 0) || type == QPixmapData::BitmapType)
data = QPixmapData::create(w, h, (QPixmapData::PixelType) type);
data = new QPixmapData(w, h, static_cast<QPixmapData::PixelType>(type));
else
data = 0;
}
@ -575,7 +575,7 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
if (QPixmapCache::find(key, *this))
return true;
QScopedPointer<QPixmapData> tmp(QPixmapData::create(0, 0, data ? data->type : QPixmapData::PixmapType));
QScopedPointer<QPixmapData> tmp(new QPixmapData(data ? data->type : QPixmapData::PixmapType));
if (tmp->fromFile(fileName, format, flags)) {
data = tmp.take();
QPixmapCache::insert(key, *this);
@ -607,7 +607,7 @@ bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::I
return false;
if (!data)
data = QPixmapData::create(0, 0, QPixmapData::PixmapType);
data = new QPixmapData(QPixmapData::PixmapType);
return data->fromData(buf, len, format, flags);
}

View file

@ -47,14 +47,6 @@ static QImage makeBitmapCompliantIfNeeded(QPixmapData::PixelType type, const QIm
return image;
}
QPixmapData *QPixmapData::create(int w, int h, PixelType type)
{
QPixmapData *data = new QPixmapData(type);
data->resize(w, h);
return data;
}
QPixmapData::QPixmapData(PixelType pixelType)
: ref(0),
detach_no(0),
@ -63,6 +55,26 @@ QPixmapData::QPixmapData(PixelType pixelType)
{
}
QPixmapData::QPixmapData(int w, int h, PixelType pixelType)
: ref(0),
detach_no(0),
type(pixelType),
ser_no(0)
{
QImage::Format format = QImage::Format_ARGB32_Premultiplied;
if (type == QPixmapData::BitmapType) {
format = QImage::Format_MonoLSB;
}
image = QImage(w, h, format);
if (type == QPixmapData::BitmapType && !image.isNull()) {
image.setColorTable(monoColorTable());
}
setSerialNumber(image.cacheKey() >> 32);
}
QPixmapData::~QPixmapData()
{
}

View file

@ -51,6 +51,7 @@ public:
};
QPixmapData(PixelType pixelType);
QPixmapData(int w, int h, PixelType type);
~QPixmapData();
QPixmapData *createCompatiblePixmapData() const;
@ -95,9 +96,6 @@ public:
| (static_cast<qint64>(detach_no)));
}
static QPixmapData *create(int w, int h, PixelType type);
protected:
void setSerialNumber(int serNo);