Cleanup and optimization of qimage smoothscale
Cleaning up smoothscale code. Upscaling is improved using existing optimized interpolation methods, and downscale is given SSE4.1 optimized versions. Change-Id: I7cdc256c26850948aef7dae26fda1622be6b8179 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>bb10
parent
884679a7cc
commit
7432c7c08a
|
|
@ -4248,11 +4248,15 @@ int QImage::bitPlaneCount() const
|
|||
|
||||
static QImage smoothScaled(const QImage &source, int w, int h) {
|
||||
QImage src = source;
|
||||
bool canSkipConversion = (src.format() == QImage::Format_RGB32 || src.format() == QImage::Format_ARGB32_Premultiplied);
|
||||
switch (src.format()) {
|
||||
case QImage::Format_RGB32:
|
||||
case QImage::Format_ARGB32_Premultiplied:
|
||||
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
|
||||
canSkipConversion = canSkipConversion || (src.format() == QImage::Format_RGBX8888 || src.format() == QImage::Format_RGBA8888_Premultiplied);
|
||||
case QImage::Format_RGBX8888:
|
||||
#endif
|
||||
if (!canSkipConversion) {
|
||||
case QImage::Format_RGBA8888_Premultiplied:
|
||||
break;
|
||||
default:
|
||||
if (src.hasAlphaChannel())
|
||||
src = src.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -93,7 +93,8 @@ SOURCES += \
|
|||
|
||||
SSE2_SOURCES += painting/qdrawhelper_sse2.cpp
|
||||
SSSE3_SOURCES += painting/qdrawhelper_ssse3.cpp
|
||||
SSE4_1_SOURCES += painting/qdrawhelper_sse4.cpp
|
||||
SSE4_1_SOURCES += painting/qdrawhelper_sse4.cpp \
|
||||
painting/qimagescale_sse4.cpp
|
||||
AVX2_SOURCES += painting/qdrawhelper_avx2.cpp
|
||||
|
||||
!ios {
|
||||
|
|
|
|||
|
|
@ -1245,44 +1245,6 @@ static inline uint interpolate_4_pixels_16(uint tl, uint tr, uint bl, uint br, i
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(__SSE2__)
|
||||
static inline uint interpolate_4_pixels(uint tl, uint tr, uint bl, uint br, uint distx, uint disty)
|
||||
{
|
||||
// First interpolate right and left pixels in parallel.
|
||||
__m128i vl = _mm_unpacklo_epi32(_mm_cvtsi32_si128(tl), _mm_cvtsi32_si128(bl));
|
||||
__m128i vr = _mm_unpacklo_epi32(_mm_cvtsi32_si128(tr), _mm_cvtsi32_si128(br));
|
||||
vl = _mm_unpacklo_epi8(vl, _mm_setzero_si128());
|
||||
vr = _mm_unpacklo_epi8(vr, _mm_setzero_si128());
|
||||
vl = _mm_mullo_epi16(vl, _mm_set1_epi16(256 - distx));
|
||||
vr = _mm_mullo_epi16(vr, _mm_set1_epi16(distx));
|
||||
__m128i vtb = _mm_add_epi16(vl, vr);
|
||||
vtb = _mm_srli_epi16(vtb, 8);
|
||||
// vtb now contains the result of the first two interpolate calls vtb = unpacked((xbot << 64) | xtop)
|
||||
|
||||
// Now the last interpolate between top and bottom interpolations.
|
||||
const __m128i vidisty = _mm_shufflelo_epi16(_mm_cvtsi32_si128(256 - disty), _MM_SHUFFLE(0, 0, 0, 0));
|
||||
const __m128i vdisty = _mm_shufflelo_epi16(_mm_cvtsi32_si128(disty), _MM_SHUFFLE(0, 0, 0, 0));
|
||||
const __m128i vmuly = _mm_unpacklo_epi16(vidisty, vdisty);
|
||||
vtb = _mm_unpacklo_epi16(vtb, _mm_srli_si128(vtb, 8));
|
||||
// vtb now contains the colors of top and bottom interleaved { ta, ba, tr, br, tg, bg, tb, bb }
|
||||
vtb = _mm_madd_epi16(vtb, vmuly); // Multiply and horizontal add.
|
||||
vtb = _mm_srli_epi32(vtb, 8);
|
||||
vtb = _mm_packs_epi32(vtb, _mm_setzero_si128());
|
||||
vtb = _mm_packus_epi16(vtb, _mm_setzero_si128());
|
||||
return _mm_cvtsi128_si32(vtb);
|
||||
}
|
||||
#else
|
||||
static inline uint interpolate_4_pixels(uint tl, uint tr, uint bl, uint br, uint distx, uint disty)
|
||||
{
|
||||
uint idistx = 256 - distx;
|
||||
uint idisty = 256 - disty;
|
||||
uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
|
||||
uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
|
||||
return INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
template<TextureBlendType blendType>
|
||||
void fetchTransformedBilinear_pixelBounds(int max, int l1, int l2, int &v1, int &v2);
|
||||
|
||||
|
|
|
|||
|
|
@ -605,6 +605,42 @@ static Q_ALWAYS_INLINE uint BYTE_MUL(uint x, uint a) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef __SSE2__
|
||||
static inline uint interpolate_4_pixels(uint tl, uint tr, uint bl, uint br, uint distx, uint disty)
|
||||
{
|
||||
// First interpolate right and left pixels in parallel.
|
||||
__m128i vl = _mm_unpacklo_epi32(_mm_cvtsi32_si128(tl), _mm_cvtsi32_si128(bl));
|
||||
__m128i vr = _mm_unpacklo_epi32(_mm_cvtsi32_si128(tr), _mm_cvtsi32_si128(br));
|
||||
vl = _mm_unpacklo_epi8(vl, _mm_setzero_si128());
|
||||
vr = _mm_unpacklo_epi8(vr, _mm_setzero_si128());
|
||||
vl = _mm_mullo_epi16(vl, _mm_set1_epi16(256 - distx));
|
||||
vr = _mm_mullo_epi16(vr, _mm_set1_epi16(distx));
|
||||
__m128i vtb = _mm_add_epi16(vl, vr);
|
||||
vtb = _mm_srli_epi16(vtb, 8);
|
||||
// vtb now contains the result of the first two interpolate calls vtb = unpacked((xbot << 64) | xtop)
|
||||
|
||||
// Now the last interpolate between top and bottom interpolations.
|
||||
const __m128i vidisty = _mm_shufflelo_epi16(_mm_cvtsi32_si128(256 - disty), _MM_SHUFFLE(0, 0, 0, 0));
|
||||
const __m128i vdisty = _mm_shufflelo_epi16(_mm_cvtsi32_si128(disty), _MM_SHUFFLE(0, 0, 0, 0));
|
||||
const __m128i vmuly = _mm_unpacklo_epi16(vidisty, vdisty);
|
||||
vtb = _mm_unpacklo_epi16(vtb, _mm_srli_si128(vtb, 8));
|
||||
// vtb now contains the colors of top and bottom interleaved { ta, ba, tr, br, tg, bg, tb, bb }
|
||||
vtb = _mm_madd_epi16(vtb, vmuly); // Multiply and horizontal add.
|
||||
vtb = _mm_srli_epi32(vtb, 8);
|
||||
vtb = _mm_packs_epi32(vtb, _mm_setzero_si128());
|
||||
vtb = _mm_packus_epi16(vtb, _mm_setzero_si128());
|
||||
return _mm_cvtsi128_si32(vtb);
|
||||
}
|
||||
#else
|
||||
static inline uint interpolate_4_pixels(uint tl, uint tr, uint bl, uint br, uint distx, uint disty)
|
||||
{
|
||||
uint idistx = 256 - distx;
|
||||
uint idisty = 256 - disty;
|
||||
uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
|
||||
uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
|
||||
return INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
|
||||
static Q_ALWAYS_INLINE quint32 RGBA2ARGB(quint32 x) {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -53,6 +53,15 @@ QT_BEGIN_NAMESPACE
|
|||
*/
|
||||
QImage qSmoothScaleImage(const QImage &img, int w, int h);
|
||||
|
||||
namespace QImageScale {
|
||||
struct QImageScaleInfo {
|
||||
int *xpoints;
|
||||
const unsigned int **ypoints;
|
||||
int *xapoints, *yapoints;
|
||||
int xup_yup;
|
||||
};
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -0,0 +1,247 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL21$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see http://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** As a special exception, The Qt Company gives you certain additional
|
||||
** rights. These rights are described in The Qt Company LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qimagescale_p.h"
|
||||
#include "qimage.h"
|
||||
#include <private/qsimd_p.h>
|
||||
|
||||
#if defined(QT_COMPILER_SUPPORTS_SSE4_1)
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
using namespace QImageScale;
|
||||
|
||||
inline static __m128i qt_qimageScaleAARGBA_helper_x(const unsigned int *pix, int xap, int Cx, const __m128i vxap, const __m128i vCx)
|
||||
{
|
||||
__m128i vpix = _mm_cvtepu8_epi32(_mm_cvtsi32_si128(*pix));
|
||||
__m128i vx = _mm_mullo_epi32(vpix, vxap);
|
||||
int i;
|
||||
for (i = (1 << 14) - xap; i > Cx; i -= Cx) {
|
||||
pix++;
|
||||
vpix = _mm_cvtepu8_epi32(_mm_cvtsi32_si128(*pix));
|
||||
vx = _mm_add_epi32(vx, _mm_mullo_epi32(vpix, vCx));
|
||||
}
|
||||
pix++;
|
||||
vpix = _mm_cvtepu8_epi32(_mm_cvtsi32_si128(*pix));
|
||||
vx = _mm_add_epi32(vx, _mm_mullo_epi32(vpix, _mm_set1_epi32(i)));
|
||||
return vx;
|
||||
}
|
||||
|
||||
inline static __m128i qt_qimageScaleAARGBA_helper_y(const unsigned int *pix, int yap, int Cy, int sow, const __m128i vyap, const __m128i vCy)
|
||||
{
|
||||
__m128i vpix = _mm_cvtepu8_epi32(_mm_cvtsi32_si128(*pix));
|
||||
__m128i vx = _mm_mullo_epi32(vpix, vyap);
|
||||
int i;
|
||||
for (i = (1 << 14) - yap; i > Cy; i -= Cy) {
|
||||
pix += sow;
|
||||
vpix = _mm_cvtepu8_epi32(_mm_cvtsi32_si128(*pix));
|
||||
vx = _mm_add_epi32(vx, _mm_mullo_epi32(vpix, vCy));
|
||||
}
|
||||
pix += sow;
|
||||
vpix = _mm_cvtepu8_epi32(_mm_cvtsi32_si128(*pix));
|
||||
vx = _mm_add_epi32(vx, _mm_mullo_epi32(vpix, _mm_set1_epi32(i)));
|
||||
return vx;
|
||||
}
|
||||
|
||||
template<bool RGB>
|
||||
void qt_qimageScaleAARGBA_up_x_down_y_sse4(QImageScaleInfo *isi, unsigned int *dest,
|
||||
int dxx, int dyy, int dx, int dy,
|
||||
int dw, int dh, int dow, int sow)
|
||||
{
|
||||
const unsigned int **ypoints = isi->ypoints;
|
||||
int *xpoints = isi->xpoints;
|
||||
int *xapoints = isi->xapoints;
|
||||
int *yapoints = isi->yapoints;
|
||||
|
||||
int end = dxx + dw;
|
||||
|
||||
const __m128i v256 = _mm_set1_epi32(256);
|
||||
|
||||
/* go through every scanline in the output buffer */
|
||||
for (int y = 0; y < dh; y++) {
|
||||
int Cy = (yapoints[dyy + y]) >> 16;
|
||||
int yap = (yapoints[dyy + y]) & 0xffff;
|
||||
const __m128i vCy = _mm_set1_epi32(Cy);
|
||||
const __m128i vyap = _mm_set1_epi32(yap);
|
||||
|
||||
unsigned int *dptr = dest + dx + ((y + dy) * dow);
|
||||
for (int x = dxx; x < end; x++) {
|
||||
const unsigned int *sptr = ypoints[dyy + y] + xpoints[x];
|
||||
__m128i vx = qt_qimageScaleAARGBA_helper_y(sptr, yap, Cy, sow, vyap, vCy);
|
||||
|
||||
int xap = xapoints[x];
|
||||
if (xap > 0) {
|
||||
const __m128i vxap = _mm_set1_epi32(xap);
|
||||
const __m128i vinvxap = _mm_sub_epi32(v256, vxap);
|
||||
__m128i vr = qt_qimageScaleAARGBA_helper_y(sptr + 1, yap, Cy, sow, vyap, vCy);
|
||||
|
||||
vx = _mm_mullo_epi32(vx, vinvxap);
|
||||
vr = _mm_mullo_epi32(vr, vxap);
|
||||
vx = _mm_add_epi32(vx, vr);
|
||||
vx = _mm_srli_epi32(vx, 8);
|
||||
}
|
||||
vx = _mm_srli_epi32(vx, 14);
|
||||
vx = _mm_packus_epi32(vx, _mm_setzero_si128());
|
||||
vx = _mm_packus_epi16(vx, _mm_setzero_si128());
|
||||
*dptr = _mm_cvtsi128_si32(vx);
|
||||
if (RGB)
|
||||
*dptr |= 0xff000000;
|
||||
dptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<bool RGB>
|
||||
void qt_qimageScaleAARGBA_down_x_up_y_sse4(QImageScaleInfo *isi, unsigned int *dest,
|
||||
int dxx, int dyy, int dx, int dy,
|
||||
int dw, int dh, int dow, int sow)
|
||||
{
|
||||
const unsigned int **ypoints = isi->ypoints;
|
||||
int *xpoints = isi->xpoints;
|
||||
int *xapoints = isi->xapoints;
|
||||
int *yapoints = isi->yapoints;
|
||||
|
||||
int end = dxx + dw;
|
||||
|
||||
const __m128i v256 = _mm_set1_epi32(256);
|
||||
|
||||
/* go through every scanline in the output buffer */
|
||||
for (int y = 0; y < dh; y++) {
|
||||
unsigned int *dptr = dest + dx + ((y + dy) * dow);
|
||||
for (int x = dxx; x < end; x++) {
|
||||
int Cx = xapoints[x] >> 16;
|
||||
int xap = xapoints[x] & 0xffff;
|
||||
const __m128i vCx = _mm_set1_epi32(Cx);
|
||||
const __m128i vxap = _mm_set1_epi32(xap);
|
||||
|
||||
const unsigned int *sptr = ypoints[dyy + y] + xpoints[x];
|
||||
__m128i vx = qt_qimageScaleAARGBA_helper_x(sptr, xap, Cx, vxap, vCx);
|
||||
|
||||
int yap = yapoints[dyy + y];
|
||||
if (yap > 0) {
|
||||
const __m128i vyap = _mm_set1_epi32(yap);
|
||||
const __m128i vinvyap = _mm_sub_epi32(v256, vyap);
|
||||
__m128i vr = qt_qimageScaleAARGBA_helper_x(sptr + sow, xap, Cx, vxap, vCx);
|
||||
|
||||
vx = _mm_mullo_epi32(vx, vinvyap);
|
||||
vr = _mm_mullo_epi32(vr, vyap);
|
||||
vx = _mm_add_epi32(vx, vr);
|
||||
vx = _mm_srli_epi32(vx, 8);
|
||||
}
|
||||
vx = _mm_srli_epi32(vx, 14);
|
||||
vx = _mm_packus_epi32(vx, _mm_setzero_si128());
|
||||
vx = _mm_packus_epi16(vx, _mm_setzero_si128());
|
||||
*dptr = _mm_cvtsi128_si32(vx);
|
||||
if (RGB)
|
||||
*dptr |= 0xff000000;
|
||||
dptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<bool RGB>
|
||||
void qt_qimageScaleAARGBA_down_xy_sse4(QImageScaleInfo *isi, unsigned int *dest,
|
||||
int dxx, int dyy, int dx, int dy,
|
||||
int dw, int dh, int dow, int sow)
|
||||
{
|
||||
const unsigned int **ypoints = isi->ypoints;
|
||||
int *xpoints = isi->xpoints;
|
||||
int *xapoints = isi->xapoints;
|
||||
int *yapoints = isi->yapoints;
|
||||
|
||||
for (int y = 0; y < dh; y++) {
|
||||
int Cy = (yapoints[dyy + y]) >> 16;
|
||||
int yap = (yapoints[dyy + y]) & 0xffff;
|
||||
const __m128i vCy = _mm_set1_epi32(Cy);
|
||||
const __m128i vyap = _mm_set1_epi32(yap);
|
||||
|
||||
unsigned int *dptr = dest + dx + ((y + dy) * dow);
|
||||
int end = dxx + dw;
|
||||
for (int x = dxx; x < end; x++) {
|
||||
const int Cx = xapoints[x] >> 16;
|
||||
const int xap = xapoints[x] & 0xffff;
|
||||
const __m128i vCx = _mm_set1_epi32(Cx);
|
||||
const __m128i vxap = _mm_set1_epi32(xap);
|
||||
|
||||
const unsigned int *sptr = ypoints[dyy + y] + xpoints[x];
|
||||
__m128i vx = qt_qimageScaleAARGBA_helper_x(sptr, xap, Cx, vxap, vCx);
|
||||
__m128i vr = _mm_mullo_epi32(_mm_srli_epi32(vx, 4), vyap);
|
||||
|
||||
int j;
|
||||
for (j = (1 << 14) - yap; j > Cy; j -= Cy) {
|
||||
sptr += sow;
|
||||
vx = qt_qimageScaleAARGBA_helper_x(sptr, xap, Cx, vxap, vCx);
|
||||
vr = _mm_add_epi32(vr, _mm_mullo_epi32(_mm_srli_epi32(vx, 4), vCy));
|
||||
}
|
||||
sptr += sow;
|
||||
vx = qt_qimageScaleAARGBA_helper_x(sptr, xap, Cx, vxap, vCx);
|
||||
vr = _mm_add_epi32(vr, _mm_mullo_epi32(_mm_srli_epi32(vx, 4), _mm_set1_epi32(j)));
|
||||
|
||||
vr = _mm_srli_epi32(vr, 24);
|
||||
vr = _mm_packus_epi32(vr, _mm_setzero_si128());
|
||||
vr = _mm_packus_epi16(vr, _mm_setzero_si128());
|
||||
*dptr = _mm_cvtsi128_si32(vr);
|
||||
if (RGB)
|
||||
*dptr |= 0xff000000;
|
||||
dptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template void qt_qimageScaleAARGBA_up_x_down_y_sse4<false>(QImageScaleInfo *isi, unsigned int *dest,
|
||||
int dxx, int dyy, int dx, int dy,
|
||||
int dw, int dh, int dow, int sow);
|
||||
|
||||
template void qt_qimageScaleAARGBA_up_x_down_y_sse4<true>(QImageScaleInfo *isi, unsigned int *dest,
|
||||
int dxx, int dyy, int dx, int dy,
|
||||
int dw, int dh, int dow, int sow);
|
||||
|
||||
template void qt_qimageScaleAARGBA_down_x_up_y_sse4<false>(QImageScaleInfo *isi, unsigned int *dest,
|
||||
int dxx, int dyy, int dx, int dy,
|
||||
int dw, int dh, int dow, int sow);
|
||||
|
||||
template void qt_qimageScaleAARGBA_down_x_up_y_sse4<true>(QImageScaleInfo *isi, unsigned int *dest,
|
||||
int dxx, int dyy, int dx, int dy,
|
||||
int dw, int dh, int dow, int sow);
|
||||
|
||||
template void qt_qimageScaleAARGBA_down_xy_sse4<false>(QImageScaleInfo *isi, unsigned int *dest,
|
||||
int dxx, int dyy, int dx, int dy,
|
||||
int dw, int dh, int dow, int sow);
|
||||
|
||||
template void qt_qimageScaleAARGBA_down_xy_sse4<true>(QImageScaleInfo *isi, unsigned int *dest,
|
||||
int dxx, int dyy, int dx, int dy,
|
||||
int dw, int dh, int dow, int sow);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
@ -108,6 +108,7 @@ private slots:
|
|||
void cacheKey();
|
||||
|
||||
void smoothScale();
|
||||
void smoothScale2_data();
|
||||
void smoothScale2();
|
||||
void smoothScale3();
|
||||
|
||||
|
|
@ -1539,58 +1540,68 @@ void tst_QImage::smoothScale()
|
|||
}
|
||||
|
||||
// test area sampling
|
||||
void tst_QImage::smoothScale2_data()
|
||||
{
|
||||
QTest::addColumn<int>("format");
|
||||
QTest::addColumn<int>("size");
|
||||
|
||||
int sizes[] = { 2, 3, 4, 6, 7, 8, 10, 16, 20, 32, 40, 64, 100, 101, 128, 0 };
|
||||
QImage::Format formats[] = { QImage::Format_RGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_Invalid };
|
||||
for (int j = 0; formats[j] != QImage::Format_Invalid; ++j) {
|
||||
QString formatstr = formats[j] == QImage::Format_RGB32 ? QStringLiteral("rgb32") : QStringLiteral("argb32pm");
|
||||
for (int i = 0; sizes[i] != 0; ++i) {
|
||||
QTest::newRow(QString("%1 %2x%2").arg(formatstr).arg(sizes[i]).toUtf8()) << (int)formats[j] << sizes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QImage::smoothScale2()
|
||||
{
|
||||
int sizes[] = { 2, 4, 8, 10, 16, 20, 32, 40, 64, 100, 101, 128, 0 };
|
||||
QImage::Format formats[] = { QImage::Format_ARGB32, QImage::Format_RGB32, QImage::Format_Invalid };
|
||||
for (int i = 0; sizes[i] != 0; ++i) {
|
||||
for (int j = 0; formats[j] != QImage::Format_Invalid; ++j) {
|
||||
int size = sizes[i];
|
||||
QFETCH(int, format);
|
||||
QFETCH(int, size);
|
||||
|
||||
QRgb expected = formats[j] == QImage::Format_ARGB32 ? qRgba(63, 127, 255, 255) : qRgb(63, 127, 255);
|
||||
QRgb expected = format == QImage::Format_RGB32 ? qRgb(63, 127, 255) : qRgba(31, 63, 127, 127);
|
||||
|
||||
QImage img(size, size, formats[j]);
|
||||
img.fill(expected);
|
||||
QImage img(size, size, (QImage::Format)format);
|
||||
img.fill(expected);
|
||||
|
||||
// scale x down, y down
|
||||
QImage scaled = img.scaled(QSize(1, 1), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
QRgb pixel = scaled.pixel(0, 0);
|
||||
// scale x down, y down
|
||||
QImage scaled = img.scaled(QSize(1, 1), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
QRgb pixel = scaled.pixel(0, 0);
|
||||
QCOMPARE(qAlpha(pixel), qAlpha(expected));
|
||||
QCOMPARE(qRed(pixel), qRed(expected));
|
||||
QCOMPARE(qGreen(pixel), qGreen(expected));
|
||||
QCOMPARE(qBlue(pixel), qBlue(expected));
|
||||
|
||||
// scale x down, y up
|
||||
scaled = img.scaled(QSize(1, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
for (int y = 0; y < scaled.height(); ++y) {
|
||||
pixel = scaled.pixel(0, y);
|
||||
QCOMPARE(qAlpha(pixel), qAlpha(expected));
|
||||
QCOMPARE(qRed(pixel), qRed(expected));
|
||||
QCOMPARE(qGreen(pixel), qGreen(expected));
|
||||
QCOMPARE(qBlue(pixel), qBlue(expected));
|
||||
}
|
||||
|
||||
// scale x up, y down
|
||||
scaled = img.scaled(QSize(size * 2, 1), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
for (int x = 0; x < scaled.width(); ++x) {
|
||||
pixel = scaled.pixel(x, 0);
|
||||
QCOMPARE(qAlpha(pixel), qAlpha(expected));
|
||||
QCOMPARE(qRed(pixel), qRed(expected));
|
||||
QCOMPARE(qGreen(pixel), qGreen(expected));
|
||||
QCOMPARE(qBlue(pixel), qBlue(expected));
|
||||
}
|
||||
|
||||
// scale x up, y up
|
||||
scaled = img.scaled(QSize(size * 2, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
for (int y = 0; y < scaled.height(); ++y) {
|
||||
for (int x = 0; x < scaled.width(); ++x) {
|
||||
pixel = scaled.pixel(x, y);
|
||||
QCOMPARE(qAlpha(pixel), qAlpha(expected));
|
||||
QCOMPARE(qRed(pixel), qRed(expected));
|
||||
QCOMPARE(qGreen(pixel), qGreen(expected));
|
||||
QCOMPARE(qBlue(pixel), qBlue(expected));
|
||||
|
||||
// scale x down, y up
|
||||
scaled = img.scaled(QSize(1, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
for (int y = 0; y < scaled.height(); ++y) {
|
||||
pixel = scaled.pixel(0, y);
|
||||
QCOMPARE(qAlpha(pixel), qAlpha(expected));
|
||||
QCOMPARE(qRed(pixel), qRed(expected));
|
||||
QCOMPARE(qGreen(pixel), qGreen(expected));
|
||||
QCOMPARE(qBlue(pixel), qBlue(expected));
|
||||
}
|
||||
|
||||
// scale x up, y down
|
||||
scaled = img.scaled(QSize(size * 2, 1), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
for (int x = 0; x < scaled.width(); ++x) {
|
||||
pixel = scaled.pixel(x, 0);
|
||||
QCOMPARE(qAlpha(pixel), qAlpha(expected));
|
||||
QCOMPARE(qRed(pixel), qRed(expected));
|
||||
QCOMPARE(qGreen(pixel), qGreen(expected));
|
||||
QCOMPARE(qBlue(pixel), qBlue(expected));
|
||||
}
|
||||
|
||||
// scale x up, y up
|
||||
scaled = img.scaled(QSize(size * 2, size * 2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
for (int y = 0; y < scaled.height(); ++y) {
|
||||
for (int x = 0; x < scaled.width(); ++x) {
|
||||
pixel = scaled.pixel(x, y);
|
||||
QCOMPARE(qAlpha(pixel), qAlpha(expected));
|
||||
QCOMPARE(qRed(pixel), qRed(expected));
|
||||
QCOMPARE(qGreen(pixel), qGreen(expected));
|
||||
QCOMPARE(qBlue(pixel), qBlue(expected));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ SUBDIRS = \
|
|||
blendbench \
|
||||
qimageconversion \
|
||||
qimagereader \
|
||||
qimagescale \
|
||||
qpixmap \
|
||||
qpixmapcache
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
TEMPLATE = app
|
||||
TARGET = tst_bench_imageScale
|
||||
QT += testlib
|
||||
SOURCES += tst_qimagescale.cpp
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the test suite of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL21$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see http://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** As a special exception, The Qt Company gives you certain additional
|
||||
** rights. These rights are described in The Qt Company LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
#include <QImage>
|
||||
|
||||
class tst_QImageScale : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void scaleRgb32_data();
|
||||
void scaleRgb32();
|
||||
|
||||
void scaleArgb32pm_data();
|
||||
void scaleArgb32pm();
|
||||
|
||||
private:
|
||||
QImage generateImageRgb32(int width, int height);
|
||||
QImage generateImageArgb32(int width, int height);
|
||||
};
|
||||
|
||||
void tst_QImageScale::scaleRgb32_data()
|
||||
{
|
||||
QTest::addColumn<QImage>("inputImage");
|
||||
QTest::addColumn<QSize>("outputSize");
|
||||
|
||||
QImage image = generateImageRgb32(1000, 1000);
|
||||
QTest::newRow("1000x1000 -> 2000x2000") << image << QSize(2000, 2000);
|
||||
QTest::newRow("1000x1000 -> 2000x1000") << image << QSize(2000, 1000);
|
||||
QTest::newRow("1000x1000 -> 1000x2000") << image << QSize(1000, 2000);
|
||||
QTest::newRow("1000x1000 -> 2000x500") << image << QSize(2000, 500);
|
||||
QTest::newRow("1000x1000 -> 500x2000") << image << QSize(500, 2000);
|
||||
QTest::newRow("1000x1000 -> 500x500") << image << QSize(500, 500);
|
||||
QTest::newRow("1000x1000 -> 200x200") << image << QSize(200, 200);
|
||||
}
|
||||
|
||||
void tst_QImageScale::scaleRgb32()
|
||||
{
|
||||
QFETCH(QImage, inputImage);
|
||||
QFETCH(QSize, outputSize);
|
||||
|
||||
QBENCHMARK {
|
||||
volatile QImage output = inputImage.scaled(outputSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
// we need the volatile and the following to make sure the compiler does not do
|
||||
// anything stupid :)
|
||||
(void)output;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QImageScale::scaleArgb32pm_data()
|
||||
{
|
||||
QTest::addColumn<QImage>("inputImage");
|
||||
QTest::addColumn<QSize>("outputSize");
|
||||
|
||||
QImage image = generateImageArgb32(1000, 1000).convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
QTest::newRow("1000x1000 -> 2000x2000") << image << QSize(2000, 2000);
|
||||
QTest::newRow("1000x1000 -> 2000x1000") << image << QSize(2000, 1000);
|
||||
QTest::newRow("1000x1000 -> 1000x2000") << image << QSize(1000, 2000);
|
||||
QTest::newRow("1000x1000 -> 2000x500") << image << QSize(2000, 500);
|
||||
QTest::newRow("1000x1000 -> 500x2000") << image << QSize(500, 2000);
|
||||
QTest::newRow("1000x1000 -> 500x500") << image << QSize(500, 500);
|
||||
QTest::newRow("1000x1000 -> 200x200") << image << QSize(200, 200);
|
||||
}
|
||||
|
||||
void tst_QImageScale::scaleArgb32pm()
|
||||
{
|
||||
QFETCH(QImage, inputImage);
|
||||
QFETCH(QSize, outputSize);
|
||||
|
||||
QBENCHMARK {
|
||||
volatile QImage output = inputImage.scaled(outputSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
// we need the volatile and the following to make sure the compiler does not do
|
||||
// anything stupid :)
|
||||
(void)output;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Fill a RGB32 image with "random" pixel values.
|
||||
*/
|
||||
QImage tst_QImageScale::generateImageRgb32(int width, int height)
|
||||
{
|
||||
QImage image(width, height, QImage::Format_RGB32);
|
||||
|
||||
for (int y = 0; y < image.height(); ++y) {
|
||||
QRgb *scanline = (QRgb*)image.scanLine(y);
|
||||
for (int x = 0; x < width; ++x)
|
||||
scanline[x] = qRgb(x, y, x ^ y);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/*
|
||||
Fill a ARGB32 image with "random" pixel values.
|
||||
*/
|
||||
QImage tst_QImageScale::generateImageArgb32(int width, int height)
|
||||
{
|
||||
QImage image(width, height, QImage::Format_ARGB32);
|
||||
const int byteWidth = width * 4;
|
||||
|
||||
for (int y = 0; y < image.height(); ++y) {
|
||||
uchar *scanline = image.scanLine(y);
|
||||
for (int x = 0; x < byteWidth; ++x)
|
||||
scanline[x] = x ^ y;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QImageScale)
|
||||
#include "tst_qimagescale.moc"
|
||||
Loading…
Reference in New Issue