Ref qualified version of QImage::convertToFormat
Add ref qualified versions of QImage::convertToFormat, so that a temporary QImage can be converted in-place to a format of equal depth. [ChangeLog][QtGui][QImage]Added rvalue qualified convertToFormat method for in-place conversion Change-Id: I2eed5ffd63f5aea4ffa1147bf7607b02a49d9c5d Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
This commit is contained in:
parent
3d7d710424
commit
c695543f76
@ -1862,6 +1862,8 @@ QImage::Format QImage::format() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
\fn QImage QImage::convertToFormat(Format format, Qt::ImageConversionFlags flags) const
|
||||||
|
|
||||||
Returns a copy of the image in the given \a format.
|
Returns a copy of the image in the given \a format.
|
||||||
|
|
||||||
The specified image conversion \a flags control how the image data
|
The specified image conversion \a flags control how the image data
|
||||||
@ -1869,7 +1871,11 @@ QImage::Format QImage::format() const
|
|||||||
|
|
||||||
\sa {Image Formats}
|
\sa {Image Formats}
|
||||||
*/
|
*/
|
||||||
QImage QImage::convertToFormat(Format format, Qt::ImageConversionFlags flags) const
|
|
||||||
|
/*!
|
||||||
|
\internal
|
||||||
|
*/
|
||||||
|
QImage QImage::convertToFormat_helper(Format format, Qt::ImageConversionFlags flags) const
|
||||||
{
|
{
|
||||||
if (!d || d->format == format)
|
if (!d || d->format == format)
|
||||||
return *this;
|
return *this;
|
||||||
@ -1902,6 +1908,14 @@ QImage QImage::convertToFormat(Format format, Qt::ImageConversionFlags flags) co
|
|||||||
return convertToFormat(Format_ARGB32, flags).convertToFormat(format, flags);
|
return convertToFormat(Format_ARGB32, flags).convertToFormat(format, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\internal
|
||||||
|
*/
|
||||||
|
bool QImage::convertToFormat_inplace(Format format, Qt::ImageConversionFlags flags)
|
||||||
|
{
|
||||||
|
return d && d->convertInPlace(format, flags);
|
||||||
|
}
|
||||||
|
|
||||||
static inline int pixel_distance(QRgb p1, QRgb p2) {
|
static inline int pixel_distance(QRgb p1, QRgb p2) {
|
||||||
int r1 = qRed(p1);
|
int r1 = qRed(p1);
|
||||||
int g1 = qGreen(p1);
|
int g1 = qGreen(p1);
|
||||||
|
@ -172,7 +172,19 @@ public:
|
|||||||
|
|
||||||
Format format() const;
|
Format format() const;
|
||||||
|
|
||||||
|
#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QIMAGE_COMPAT_CPP)
|
||||||
|
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const & Q_REQUIRED_RESULT
|
||||||
|
{ return convertToFormat_helper(f, flags); }
|
||||||
|
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) && Q_REQUIRED_RESULT
|
||||||
|
{
|
||||||
|
if (convertToFormat_inplace(f, flags))
|
||||||
|
return std::move(*this);
|
||||||
|
else
|
||||||
|
return convertToFormat_helper(f, flags);
|
||||||
|
}
|
||||||
|
#else
|
||||||
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
|
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
|
||||||
|
#endif
|
||||||
QImage convertToFormat(Format f, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
|
QImage convertToFormat(Format f, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
|
||||||
|
|
||||||
int width() const;
|
int width() const;
|
||||||
@ -313,6 +325,8 @@ protected:
|
|||||||
QImage rgbSwapped_helper() const;
|
QImage rgbSwapped_helper() const;
|
||||||
void mirrored_inplace(bool horizontal, bool vertical);
|
void mirrored_inplace(bool horizontal, bool vertical);
|
||||||
void rgbSwapped_inplace();
|
void rgbSwapped_inplace();
|
||||||
|
QImage convertToFormat_helper(Format format, Qt::ImageConversionFlags flags) const;
|
||||||
|
bool convertToFormat_inplace(Format format, Qt::ImageConversionFlags flags);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class QWSOnScreenSurface;
|
friend class QWSOnScreenSurface;
|
||||||
|
@ -49,6 +49,12 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
// These implementations must be the same as the inline versions in qimage.h
|
// These implementations must be the same as the inline versions in qimage.h
|
||||||
|
|
||||||
|
QImage QImage::convertToFormat(Format f, Qt::ImageConversionFlags flags) const
|
||||||
|
{
|
||||||
|
return convertToFormat_helper(f, flags);
|
||||||
|
}
|
||||||
|
|
||||||
QImage QImage::mirrored(bool horizontally, bool vertically) const
|
QImage QImage::mirrored(bool horizontally, bool vertically) const
|
||||||
{
|
{
|
||||||
return mirrored_helper(horizontally, vertically);
|
return mirrored_helper(horizontally, vertically);
|
||||||
|
@ -158,7 +158,10 @@ private slots:
|
|||||||
void inplaceMirrored_data();
|
void inplaceMirrored_data();
|
||||||
void inplaceMirrored();
|
void inplaceMirrored();
|
||||||
|
|
||||||
void inplaceDoubleConversion();
|
void inplaceRgbMirrored();
|
||||||
|
|
||||||
|
void inplaceConversion_data();
|
||||||
|
void inplaceConversion();
|
||||||
|
|
||||||
void deepCopyWhenPaintingActive();
|
void deepCopyWhenPaintingActive();
|
||||||
void scaled_QTBUG19157();
|
void scaled_QTBUG19157();
|
||||||
@ -2342,7 +2345,7 @@ void tst_QImage::inplaceMirrored()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QImage::inplaceDoubleConversion()
|
void tst_QImage::inplaceRgbMirrored()
|
||||||
{
|
{
|
||||||
#if defined(Q_COMPILER_REF_QUALIFIERS)
|
#if defined(Q_COMPILER_REF_QUALIFIERS)
|
||||||
QImage image1(32, 32, QImage::Format_ARGB32);
|
QImage image1(32, 32, QImage::Format_ARGB32);
|
||||||
@ -2357,6 +2360,47 @@ void tst_QImage::inplaceDoubleConversion()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QImage::inplaceConversion_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QImage::Format>("format");
|
||||||
|
QTest::addColumn<QImage::Format>("dest_format");
|
||||||
|
|
||||||
|
QTest::newRow("Format_ARGB32 -> Format_RGBA8888") << QImage::Format_ARGB32 << QImage::Format_RGBA8888;
|
||||||
|
QTest::newRow("Format_RGB888 -> Format_ARGB6666_Premultiplied") << QImage::Format_RGB888 << QImage::Format_ARGB6666_Premultiplied;
|
||||||
|
QTest::newRow("Format_RGB16 -> Format_RGB555") << QImage::Format_RGB16 << QImage::Format_RGB555;
|
||||||
|
QTest::newRow("Format_RGB666 -> Format_RGB888") << QImage::Format_RGB666 << QImage::Format_RGB888;
|
||||||
|
QTest::newRow("Format_ARGB8565_Premultiplied, Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8565_Premultiplied << QImage::Format_ARGB8555_Premultiplied;
|
||||||
|
QTest::newRow("Format_ARGB4444_Premultiplied, Format_RGB444") << QImage::Format_ARGB4444_Premultiplied << QImage::Format_RGB444;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QImage::inplaceConversion()
|
||||||
|
{
|
||||||
|
// Test that conversions between RGB formats of the same bitwidth can be done inplace.
|
||||||
|
#if defined(Q_COMPILER_REF_QUALIFIERS)
|
||||||
|
QFETCH(QImage::Format, format);
|
||||||
|
QFETCH(QImage::Format, dest_format);
|
||||||
|
|
||||||
|
QImage image(16, 16, format);
|
||||||
|
|
||||||
|
for (int i = 0; i < image.height(); ++i)
|
||||||
|
for (int j = 0; j < image.width(); ++j)
|
||||||
|
image.setPixel(j, i, qRgb(j*16, i*16, 0));
|
||||||
|
|
||||||
|
const uchar* originalPtr = image.constScanLine(0);
|
||||||
|
|
||||||
|
QImage imageConverted = std::move(image).convertToFormat(dest_format);
|
||||||
|
for (int i = 0; i < imageConverted.height(); ++i) {
|
||||||
|
for (int j = 0; j < imageConverted.width(); ++j) {
|
||||||
|
QRgb convertedColor = imageConverted.pixel(j,i);
|
||||||
|
QCOMPARE(qRed(convertedColor) & 0xF0, j * 16);
|
||||||
|
QCOMPARE(qGreen(convertedColor) & 0xF0, i * 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QCOMPARE(imageConverted.constScanLine(0), originalPtr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QImage::deepCopyWhenPaintingActive()
|
void tst_QImage::deepCopyWhenPaintingActive()
|
||||||
{
|
{
|
||||||
QImage image(64, 64, QImage::Format_ARGB32_Premultiplied);
|
QImage image(64, 64, QImage::Format_ARGB32_Premultiplied);
|
||||||
|
Loading…
Reference in New Issue
Block a user