diff options
author | Allan Sandfeld Jensen <[email protected]> | 2024-10-02 09:57:19 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <[email protected]> | 2024-11-29 15:07:14 +0100 |
commit | 577946c1f05aaaa2a3f9682001aeb4144386b26b (patch) | |
tree | ca8d724b6411b744d6ce9e3b7d7e93386a2ed7f3 | |
parent | 7539b659d9ffbb3c44e45bdb7d9669a6df8915c8 (diff) |
Add Qt::Orientations based flip and flipped functions
Is easier to read and more bool-trap safe. Old form header deprecated from 6.10
Fixes: QTBUG-129575
Change-Id: Id785b9ce159007ce745c04120b2112c8bb9b0802
Reviewed-by: Volker Hilsheimer <[email protected]>
30 files changed, 223 insertions, 100 deletions
diff --git a/examples/gui/rhiwindow/rhiwindow.cpp b/examples/gui/rhiwindow/rhiwindow.cpp index 3ae6faa8024..baf9e200cdb 100644 --- a/examples/gui/rhiwindow/rhiwindow.cpp +++ b/examples/gui/rhiwindow/rhiwindow.cpp @@ -298,7 +298,7 @@ void HelloWindow::ensureFullscreenTexture(const QSize &pixelSize, QRhiResourceUp painter.end(); if (m_rhi->isYUpInNDC()) - image = image.mirrored(); + image.flip(); //! [ensure-texture-2] u->uploadTexture(m_texture.get(), image); diff --git a/examples/opengl/cube/mainwidget.cpp b/examples/opengl/cube/mainwidget.cpp index e67c93da5a0..b11242c49da 100644 --- a/examples/opengl/cube/mainwidget.cpp +++ b/examples/opengl/cube/mainwidget.cpp @@ -103,7 +103,7 @@ void MainWidget::initShaders() void MainWidget::initTextures() { // Load cube.png image - texture = new QOpenGLTexture(QImage(":/cube.png").mirrored()); + texture = new QOpenGLTexture(QImage(":/cube.png").flipped()); // Set nearest filtering mode for texture minification texture->setMinificationFilter(QOpenGLTexture::Nearest); diff --git a/examples/opengl/hellogles3/glwindow.cpp b/examples/opengl/hellogles3/glwindow.cpp index 921230fb445..1ff29feb8fa 100644 --- a/examples/opengl/hellogles3/glwindow.cpp +++ b/examples/opengl/hellogles3/glwindow.cpp @@ -144,7 +144,7 @@ void GLWindow::initializeGL() QImage img(":/qtlogo.png"); Q_ASSERT(!img.isNull()); delete m_texture; - m_texture = new QOpenGLTexture(img.scaled(32, 36).mirrored()); + m_texture = new QOpenGLTexture(img.scaled(32, 36).flipped()); delete m_program; m_program = new QOpenGLShaderProgram; diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp index cca08f4c917..4377cb40559 100644 --- a/examples/opengl/textures/glwidget.cpp +++ b/examples/opengl/textures/glwidget.cpp @@ -152,7 +152,7 @@ void GLWidget::makeObject() }; for (int j = 0; j < 6; ++j) - textures[j] = new QOpenGLTexture(QImage(QString(":/images/side%1.png").arg(j + 1)).mirrored()); + textures[j] = new QOpenGLTexture(QImage(QString(":/images/side%1.png").arg(j + 1)).flipped()); QList<GLfloat> vertData; for (int i = 0; i < 6; ++i) { diff --git a/src/gui/doc/snippets/rhioffscreen/main.cpp b/src/gui/doc/snippets/rhioffscreen/main.cpp index c2c6f74dc1b..b7312addaaf 100644 --- a/src/gui/doc/snippets/rhioffscreen/main.cpp +++ b/src/gui/doc/snippets/rhioffscreen/main.cpp @@ -142,7 +142,7 @@ int main(int argc, char **argv) readbackResult.pixelSize.height(), QImage::Format_RGBA8888_Premultiplied); if (rhi->isYUpInFramebuffer()) - image = image.mirrored(); + image.flip(); image.save(QString::asprintf("frame%d.png", frame)); } diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index ebec640b47d..9cfe722bb5f 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -3293,6 +3293,7 @@ QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode) const /*! \fn QImage QImage::mirrored(bool horizontal = false, bool vertical = true) const & \fn QImage QImage::mirrored(bool horizontal = false, bool vertical = true) && + \deprecated [6.9] Use flipped(Qt::Orientations) instead. Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on whether \a horizontal and \a @@ -3306,6 +3307,7 @@ QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode) const /*! \fn void QImage::mirror(bool horizontal = false, bool vertical = true) \since 6.0 + \deprecated [6.9] Use flip(Qt::Orientations) instead. Mirrors of the image in the horizontal and/or the vertical direction depending on whether \a horizontal and \a vertical are set to true or false. @@ -3313,6 +3315,29 @@ QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode) const \sa mirrored(), {QImage#Image Transformations}{Image Transformations} */ +/*! + \fn QImage QImage::flipped(Qt::Orientations orient) const & + \fn QImage QImage::flipped(Qt::Orientations orient) && + \since 6.9 + + Returns a flipped or mirror version of the image, mirrored in the horizontal and/or + the vertical direction depending on \a orient. + + Note that the original image is not changed. + + \sa flip(Qt::Orientations), {QImage#Image Transformations}{Image Transformations} +*/ + +/*! + \fn void QImage::flip(Qt::Orientations orient) + \since 6.9 + + Flips or mirrors the image in the horizontal and/or the vertical direction depending + on \a orient. + + \sa flipped(Qt::Orientations), {QImage#Image Transformations}{Image Transformations} +*/ + template<class T> inline void do_mirror_data(QImageData *dst, QImageData *src, int dstX0, int dstY0, int dstXIncr, int dstYIncr, @@ -4739,7 +4764,7 @@ static QImage rotated180(const QImage &image) { const MemRotateFunc memrotate = qMemRotateFunctions[qPixelLayouts[image.format()].bpp][1]; if (!memrotate) - return image.mirrored(true, true); + return image.flipped(Qt::Horizontal | Qt::Vertical); QImage out(image.width(), image.height(), image.format()); if (out.isNull()) @@ -4889,11 +4914,11 @@ QImage Q_TRACE_INSTRUMENT(qtgui) QImage::transformed(const QTransform &matrix, Q ) { QImage scaledImage; if (mat.m11() < 0.0F && mat.m22() < 0.0F) { // horizontal/vertical flip - scaledImage = smoothScaled(wd, hd).mirrored(true, true); + scaledImage = smoothScaled(wd, hd).flipped(Qt::Horizontal | Qt::Vertical); } else if (mat.m11() < 0.0F) { // horizontal flip - scaledImage = smoothScaled(wd, hd).mirrored(true, false); + scaledImage = smoothScaled(wd, hd).flipped(Qt::Horizontal); } else if (mat.m22() < 0.0F) { // vertical flip - scaledImage = smoothScaled(wd, hd).mirrored(false, true); + scaledImage = smoothScaled(wd, hd).flipped(Qt::Vertical); } else { // no flipping scaledImage = smoothScaled(wd, hd); } @@ -6440,6 +6465,16 @@ QImage::Format QImage::toImageFormat(QPixelFormat format) noexcept return Format_Invalid; } +static inline Qt::Orientations toOrientations(QImageIOHandler::Transformations orient) +{ + Qt::Orientations orients = {}; + if (orient.testFlag(QImageIOHandler::TransformationMirror)) + orients |= Qt::Horizontal; + if (orient.testFlag(QImageIOHandler::TransformationFlip)) + orients |= Qt::Vertical; + return orients; +} + Q_GUI_EXPORT void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient) { if (orient == QImageIOHandler::TransformationNone) @@ -6447,8 +6482,7 @@ Q_GUI_EXPORT void qt_imageTransform(QImage &src, QImageIOHandler::Transformation if (orient == QImageIOHandler::TransformationRotate270) { src = rotated270(src); } else { - src = std::move(src).mirrored(orient & QImageIOHandler::TransformationMirror, - orient & QImageIOHandler::TransformationFlip); + src.flip(toOrientations(orient)); if (orient & QImageIOHandler::TransformationRotate90) src = rotated90(src); } diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index cad506c1282..e30ec551322 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -215,17 +215,27 @@ public: [[nodiscard]] QImage scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const; [[nodiscard]] QImage transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const; static QTransform trueMatrix(const QTransform &, int w, int h); - +#if QT_DEPRECATED_SINCE(6, 10) + QT_DEPRECATED_VERSION_X_6_10("Use flipped(Qt::Orientations) instead") [[nodiscard]] QImage mirrored(bool horizontally = false, bool vertically = true) const & { return mirrored_helper(horizontally, vertically); } + QT_DEPRECATED_VERSION_X_6_10("Use flipped(Qt::Orientations) instead") [[nodiscard]] QImage mirrored(bool horizontally = false, bool vertically = true) && { mirrored_inplace(horizontally, vertically); return std::move(*this); } + QT_DEPRECATED_VERSION_X_6_10("Use flip(Qt::Orientations) instead") + void mirror(bool horizontally = false, bool vertically = true) + { mirrored_inplace(horizontally, vertically); } +#endif [[nodiscard]] QImage rgbSwapped() const & { return rgbSwapped_helper(); } [[nodiscard]] QImage rgbSwapped() && { rgbSwapped_inplace(); return std::move(*this); } - void mirror(bool horizontally = false, bool vertically = true) - { mirrored_inplace(horizontally, vertically); } + [[nodiscard]] QImage flipped(Qt::Orientations orient = Qt::Vertical) const & + { return mirrored_helper(orient.testFlag(Qt::Horizontal), orient.testFlag(Qt::Vertical)); } + [[nodiscard]] QImage flipped(Qt::Orientations orient = Qt::Vertical) && + { mirrored_inplace(orient.testFlag(Qt::Horizontal), orient.testFlag(Qt::Vertical)); return std::move(*this); } + void flip(Qt::Orientations orient = Qt::Vertical) + { mirrored_inplace(orient.testFlag(Qt::Horizontal), orient.testFlag(Qt::Vertical)); } void rgbSwap() { rgbSwapped_inplace(); } void invertPixels(InvertMode = InvertRgb); diff --git a/src/opengl/qopenglframebufferobject.cpp b/src/opengl/qopenglframebufferobject.cpp index 5c8f769d399..cd329ba03aa 100644 --- a/src/opengl/qopenglframebufferobject.cpp +++ b/src/opengl/qopenglframebufferobject.cpp @@ -1418,30 +1418,31 @@ static QImage qt_gl_read_framebuffer(const QSize &size, GLenum internal_format, if (error == GL_NO_ERROR || error == GL_CONTEXT_LOST) break; } + Qt::Orientations orient = flip ? Qt::Vertical : Qt::Orientations{}; switch (internal_format) { case GL_RGB: case GL_RGB8: - return qt_gl_read_framebuffer_rgba8(size, false, ctx).mirrored(false, flip); + return qt_gl_read_framebuffer_rgba8(size, false, ctx).flipped(orient); case GL_RGB10: - return qt_gl_read_framebuffer_rgb10a2(size, false, ctx).mirrored(false, flip); + return qt_gl_read_framebuffer_rgb10a2(size, false, ctx).flipped(orient); case GL_RGB10_A2: - return qt_gl_read_framebuffer_rgb10a2(size, include_alpha, ctx).mirrored(false, flip); + return qt_gl_read_framebuffer_rgb10a2(size, include_alpha, ctx).flipped(orient); case GL_RGB16: - return qt_gl_read_framebuffer_rgba16(size, false, ctx).mirrored(false, flip); + return qt_gl_read_framebuffer_rgba16(size, false, ctx).flipped(orient); case GL_RGBA16: - return qt_gl_read_framebuffer_rgba16(size, include_alpha, ctx).mirrored(false, flip); + return qt_gl_read_framebuffer_rgba16(size, include_alpha, ctx).flipped(orient); case GL_RGB16F: - return qt_gl_read_framebuffer_rgba16f(size, false, ctx).mirrored(false, flip); + return qt_gl_read_framebuffer_rgba16f(size, false, ctx).flipped(orient); case GL_RGBA16F: - return qt_gl_read_framebuffer_rgba16f(size, include_alpha, ctx).mirrored(false, flip); + return qt_gl_read_framebuffer_rgba16f(size, include_alpha, ctx).flipped(orient); case GL_RGB32F: - return qt_gl_read_framebuffer_rgba32f(size, false, ctx).mirrored(false, flip); + return qt_gl_read_framebuffer_rgba32f(size, false, ctx).flipped(orient); case GL_RGBA32F: - return qt_gl_read_framebuffer_rgba32f(size, include_alpha, ctx).mirrored(false, flip); + return qt_gl_read_framebuffer_rgba32f(size, include_alpha, ctx).flipped(orient); case GL_RGBA: case GL_RGBA8: default: - return qt_gl_read_framebuffer_rgba8(size, include_alpha, ctx).mirrored(false, flip); + return qt_gl_read_framebuffer_rgba8(size, include_alpha, ctx).flipped(orient); } Q_UNREACHABLE_RETURN(QImage()); diff --git a/src/opengl/qopengltexture.cpp b/src/opengl/qopengltexture.cpp index 6754d7828db..d6e9f374b4e 100644 --- a/src/opengl/qopengltexture.cpp +++ b/src/opengl/qopengltexture.cpp @@ -2059,7 +2059,7 @@ QOpenGLTexture *QOpenGLTexturePrivate::createTextureView(QOpenGLTexture::Target \code // Prepare texture - QOpenGLTexture *texture = new QOpenGLTexture(QImage(fileName).mirrored()); + QOpenGLTexture *texture = new QOpenGLTexture(QImage(fileName).flipped()); texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear); texture->setMagnificationFilter(QOpenGLTexture::Linear); ... @@ -2068,7 +2068,7 @@ QOpenGLTexture *QOpenGLTexturePrivate::createTextureView(QOpenGLTexture::Target glDrawArrays(...); \endcode - Note that the QImage is mirrored vertically to account for the fact that + Note that the QImage is flipped vertically to account for the fact that OpenGL and QImage use opposite directions for the y axis. Another option would be to transform your texture coordinates. */ diff --git a/src/opengl/qopengltextureblitter.cpp b/src/opengl/qopengltextureblitter.cpp index 41d230869c6..75b8b754018 100644 --- a/src/opengl/qopengltextureblitter.cpp +++ b/src/opengl/qopengltextureblitter.cpp @@ -674,7 +674,7 @@ void QOpenGLTextureBlitter::setOpacity(float opacity) \a texture corresponds to a texture attached to an FBO pass OriginBottomLeft. On the other hand, when \a texture is based on unflipped image data, pass OriginTopLeft. This is more efficient - than using QImage::mirrored(). + than using QImage::flipped(). \sa targetTransform(), Origin, bind() */ diff --git a/src/plugins/styles/modernwindows/qwindowsvistastyle.cpp b/src/plugins/styles/modernwindows/qwindowsvistastyle.cpp index 3be252a20a3..6c95c3343af 100644 --- a/src/plugins/styles/modernwindows/qwindowsvistastyle.cpp +++ b/src/plugins/styles/modernwindows/qwindowsvistastyle.cpp @@ -978,8 +978,13 @@ bool QWindowsVistaStylePrivate::drawBackgroundThruNativeBuffer(QWindowsThemeData rotMatrix.rotate(themeData.rotate); imgCopy = imgCopy.transformed(rotMatrix); } + Qt::Orientations orient = {}; + if (themeData.mirrorHorizontally) + orient |= Qt::Horizontal; + if (themeData.mirrorVertically) + orient |= Qt::Vertical; if (themeData.mirrorHorizontally || themeData.mirrorVertically) - imgCopy = imgCopy.mirrored(themeData.mirrorHorizontally, themeData.mirrorVertically); + imgCopy.flip(orient); painter->drawImage(themeData.rect, imgCopy); } diff --git a/src/widgets/kernel/qrhiwidget.cpp b/src/widgets/kernel/qrhiwidget.cpp index 276069cf83f..8259715e98a 100644 --- a/src/widgets/kernel/qrhiwidget.cpp +++ b/src/widgets/kernel/qrhiwidget.cpp @@ -438,7 +438,7 @@ QImage QRhiWidgetPrivate::grabFramebuffer() imageFormat); QImage result; if (rhi->isYUpInFramebuffer()) - result = wrapperImage.mirrored(); + result = wrapperImage.flipped(); else result = wrapperImage.copy(); result.setDevicePixelRatio(q->devicePixelRatio()); diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 095199ceb6a..63740829bc0 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -5545,7 +5545,7 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti switch (sp) { case QStyle::SP_ToolBarHorizontalExtensionButton: if (d->rtl(option)) { - auto im = QImage(tb_extension_arrow_h_xpm).convertToFormat(QImage::Format_ARGB32).mirrored(true, false); + auto im = QImage(tb_extension_arrow_h_xpm).convertToFormat(QImage::Format_ARGB32).flipped(Qt::Horizontal); return QPixmap::fromImage(std::move(im)); } return cachedPixmapFromXPM(tb_extension_arrow_h_xpm); diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index dfe28796991..5df5278783d 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -148,6 +148,8 @@ private slots: void mirrored_data(); void mirrored(); + void flipped_data(); + void flipped(); void inplaceRgbSwapped_data(); void inplaceRgbSwapped(); @@ -2766,6 +2768,7 @@ void tst_QImage::mirrored_data() QTest::newRow("Format_MonoLSB, horizontal+vertical, non-aligned") << QImage::Format_MonoLSB << true << true << 21 << 16; } +#if QT_DEPRECATED_SINCE(6, 10) void tst_QImage::mirrored() { QFETCH(QImage::Format, format); @@ -2823,6 +2826,83 @@ void tst_QImage::mirrored() QCOMPARE(image.pixel(j,i), imageMirrored.pixel(j,i)); } } +#endif + +void tst_QImage::flipped_data() +{ + mirrored_data(); +} + +void tst_QImage::flipped() +{ + QFETCH(QImage::Format, format); + QFETCH(bool, swap_vertical); + QFETCH(bool, swap_horizontal); + QFETCH(int, width); + QFETCH(int, height); + Q_ASSERT(swap_vertical | swap_horizontal); + + QImage image(width, height, format); + + switch (format) { + case QImage::Format_Mono: + case QImage::Format_MonoLSB: + for (int i = 0; i < image.height(); ++i) { + ushort* scanLine = (ushort*)image.scanLine(i); + *scanLine = (i % 2) ? 0x5555U : 0xCCCCU; + } + break; + case QImage::Format_Indexed8: + for (int i = 0; i < image.height(); ++i) { + for (int j = 0; j < image.width(); ++j) { + image.setColor(i*16+j, qRgb(j*16, i*16, 0)); + image.setPixel(j, i, i*16+j); + } + } + break; + default: + 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)); + break; + } + + QImage imageMirrored; + if (swap_vertical && swap_horizontal) + imageMirrored = image.flipped(Qt::Horizontal | Qt::Vertical); + else if (swap_horizontal) + imageMirrored = image.flipped(Qt::Horizontal); + else + imageMirrored = image.flipped(Qt::Vertical); + + for (int i = 0; i < image.height(); ++i) { + int mirroredI = swap_vertical ? (image.height() - i - 1) : i; + for (int j = 0; j < image.width(); ++j) { + QRgb referenceColor = image.pixel(j, i); + int mirroredJ = swap_horizontal ? (image.width() - j - 1) : j; + QRgb mirroredColor = imageMirrored.pixel(mirroredJ, mirroredI); + QCOMPARE(mirroredColor, referenceColor); + } + } + + if (swap_vertical && swap_horizontal) + imageMirrored.flip(Qt::Horizontal | Qt::Vertical); + else if (swap_horizontal) + imageMirrored.flip(Qt::Horizontal); + else + imageMirrored.flip(Qt::Vertical); + + QCOMPARE(image, imageMirrored); + + if (format != QImage::Format_Mono && format != QImage::Format_MonoLSB) + QCOMPARE(memcmp(image.constBits(), imageMirrored.constBits(), image.sizeInBytes()), 0); + else { + for (int i = 0; i < image.height(); ++i) + for (int j = 0; j < image.width(); ++j) + QCOMPARE(image.pixel(j,i), imageMirrored.pixel(j,i)); + } +} + void tst_QImage::inplaceRgbSwapped_data() { @@ -2897,8 +2977,7 @@ void tst_QImage::inplaceRgbSwapped() void tst_QImage::inplaceMirrored_data() { QTest::addColumn<QImage::Format>("format"); - QTest::addColumn<bool>("swap_vertical"); - QTest::addColumn<bool>("swap_horizontal"); + QTest::addColumn<Qt::Orientations>("swap_orient"); for (int i = QImage::Format_Mono; i < QImage::NImageFormats; ++i) { if (i == QImage::Format_Alpha8 @@ -2910,20 +2989,20 @@ void tst_QImage::inplaceMirrored_data() continue; const auto fmt = formatToString(QImage::Format(i)); QTest::addRow("%s, vertical", fmt.data()) - << QImage::Format(i) << true << false; + << QImage::Format(i) << Qt::Orientations(Qt::Vertical); QTest::addRow("%s, horizontal", fmt.data()) - << QImage::Format(i) << false << true; + << QImage::Format(i) << Qt::Orientations(Qt::Horizontal); QTest::addRow("%s, horizontal+vertical", fmt.data()) - << QImage::Format(i) << true << true; + << QImage::Format(i) << (Qt::Vertical | Qt::Horizontal); } } void tst_QImage::inplaceMirrored() { -#if defined(Q_COMPILER_REF_QUALIFIERS) QFETCH(QImage::Format, format); - QFETCH(bool, swap_vertical); - QFETCH(bool, swap_horizontal); + QFETCH(Qt::Orientations, swap_orient); + bool swap_horizontal = swap_orient.testFlag(Qt::Horizontal); + bool swap_vertical = swap_orient.testFlag(Qt::Vertical); QImage image(16, 16, format); @@ -2951,7 +3030,7 @@ void tst_QImage::inplaceMirrored() const uchar* originalPtr = image.constScanLine(0); - QImage imageMirrored = std::move(image).mirrored(swap_horizontal, swap_vertical); + QImage imageMirrored = std::move(image).flipped(swap_orient); if (format != QImage::Format_Mono && format != QImage::Format_MonoLSB) { for (int i = 0; i < imageMirrored.height(); ++i) { int mirroredI = swap_vertical ? (imageMirrored.height() - i - 1) : i; @@ -2996,43 +3075,40 @@ void tst_QImage::inplaceMirrored() if (orig.colorCount()) dataImage.setColorTable(orig.colorTable()); - dataSwapped = std::move(dataImage).mirrored(swap_horizontal, swap_vertical); + dataSwapped = std::move(dataImage).flipped(swap_orient); QVERIFY(!dataSwapped.isNull()); delete[] volatileData; } QVERIFY2(dataSwapped.constBits() != volatileData, rw ? "non-const" : "const"); - QCOMPARE(dataSwapped, orig.mirrored(swap_horizontal, swap_vertical)); + QCOMPARE(dataSwapped, orig.flipped(swap_orient)); } - -#endif } void tst_QImage::inplaceMirroredOdd_data() { QTest::addColumn<QImage::Format>("format"); - QTest::addColumn<bool>("swap_vertical"); - QTest::addColumn<bool>("swap_horizontal"); + QTest::addColumn<Qt::Orientations>("swap_orient"); - QTest::newRow("Format_ARGB32, vertical") << QImage::Format_ARGB32 << true << false; - QTest::newRow("Format_RGB888, vertical") << QImage::Format_RGB888 << true << false; - QTest::newRow("Format_RGB16, vertical") << QImage::Format_RGB16 << true << false; + QTest::newRow("Format_ARGB32, vertical") << QImage::Format_ARGB32 << Qt::Orientations(Qt::Vertical); + QTest::newRow("Format_RGB888, vertical") << QImage::Format_RGB888 << Qt::Orientations(Qt::Vertical); + QTest::newRow("Format_RGB16, vertical") << QImage::Format_RGB16 << Qt::Orientations(Qt::Vertical); - QTest::newRow("Format_ARGB32, horizontal") << QImage::Format_ARGB32 << false << true; - QTest::newRow("Format_RGB888, horizontal") << QImage::Format_RGB888 << false << true; - QTest::newRow("Format_RGB16, horizontal") << QImage::Format_RGB16 << false << true; + QTest::newRow("Format_ARGB32, horizontal") << QImage::Format_ARGB32 << Qt::Orientations(Qt::Horizontal); + QTest::newRow("Format_RGB888, horizontal") << QImage::Format_RGB888 << Qt::Orientations(Qt::Horizontal); + QTest::newRow("Format_RGB16, horizontal") << QImage::Format_RGB16 << Qt::Orientations(Qt::Horizontal); - QTest::newRow("Format_ARGB32, horizontal+vertical") << QImage::Format_ARGB32 << true << true; - QTest::newRow("Format_RGB888, horizontal+vertical") << QImage::Format_RGB888 << true << true; - QTest::newRow("Format_RGB16, horizontal+vertical") << QImage::Format_RGB16 << true << true; + QTest::newRow("Format_ARGB32, horizontal+vertical") << QImage::Format_ARGB32 << (Qt::Vertical | Qt::Horizontal); + QTest::newRow("Format_RGB888, horizontal+vertical") << QImage::Format_RGB888 << (Qt::Vertical | Qt::Horizontal); + QTest::newRow("Format_RGB16, horizontal+vertical") << QImage::Format_RGB16 << (Qt::Vertical | Qt::Horizontal); } void tst_QImage::inplaceMirroredOdd() { -#if defined(Q_COMPILER_REF_QUALIFIERS) QFETCH(QImage::Format, format); - QFETCH(bool, swap_vertical); - QFETCH(bool, swap_horizontal); + QFETCH(Qt::Orientations, swap_orient); + bool swap_horizontal = swap_orient.testFlag(Qt::Horizontal); + bool swap_vertical = swap_orient.testFlag(Qt::Vertical); QImage image(15, 15, format); @@ -3042,7 +3118,7 @@ void tst_QImage::inplaceMirroredOdd() const uchar* originalPtr = image.constScanLine(0); - QImage imageMirrored = std::move(image).mirrored(swap_horizontal, swap_vertical); + QImage imageMirrored = std::move(image).flipped(swap_orient); for (int i = 0; i < imageMirrored.height(); ++i) { int mirroredI = swap_vertical ? (imageMirrored.height() - i - 1) : i; for (int j = 0; j < imageMirrored.width(); ++j) { @@ -3053,12 +3129,10 @@ void tst_QImage::inplaceMirroredOdd() } } QCOMPARE(imageMirrored.constScanLine(0), originalPtr); -#endif } void tst_QImage::inplaceRgbMirrored() { -#if defined(Q_COMPILER_REF_QUALIFIERS) QImage image1(32, 32, QImage::Format_ARGB32); QImage image2(32, 32, QImage::Format_ARGB32); image1.fill(0); @@ -3066,9 +3140,8 @@ void tst_QImage::inplaceRgbMirrored() const uchar* originalPtr1 = image1.constScanLine(0); const uchar* originalPtr2 = image2.constScanLine(0); - QCOMPARE(std::move(image1).rgbSwapped().mirrored().constScanLine(0), originalPtr1); - QCOMPARE(std::move(image2).mirrored().rgbSwapped().constScanLine(0), originalPtr2); -#endif + QCOMPARE(std::move(image1).rgbSwapped().flipped().constScanLine(0), originalPtr1); + QCOMPARE(std::move(image2).flipped().rgbSwapped().constScanLine(0), originalPtr2); } void tst_QImage::genericRgbConversion_data() @@ -4013,7 +4086,7 @@ void tst_QImage::metadataPassthrough() QCOMPARE(scaled.devicePixelRatio(), a.devicePixelRatio()); QCOMPARE(scaled.colorSpace(), a.colorSpace()); - QImage mirrored = a.mirrored(); + QImage mirrored = a.flipped(); QCOMPARE(mirrored.text(QStringLiteral("Test")), a.text(QStringLiteral("Test"))); QCOMPARE(mirrored.dotsPerMeterX(), a.dotsPerMeterX()); QCOMPARE(mirrored.dotsPerMeterY(), a.dotsPerMeterY()); diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 61dcc494e44..168026f9aa4 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -3864,7 +3864,7 @@ void tst_QPainter::linearGradientSymmetry() pb.fillRect(b.rect(), inverseGradient(gradient)); pb.end(); - b = b.mirrored(true); + b = b.flipped(Qt::Horizontal | Qt::Vertical); QCOMPARE(a, b); } diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp index 9129bbdbf9d..88b561c6428 100644 --- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp +++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp @@ -2286,7 +2286,7 @@ void tst_QRhi::renderToTextureTexturedQuad() // just happens to give correct results with our OpenGL-targeted vertex and // UV data. if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) - result = std::move(result).mirrored(); + result.flip(); // check a few points that are expected to match regardless of the implementation QRgb white = qRgba(255, 255, 255, 255); @@ -2412,7 +2412,7 @@ void tst_QRhi::renderToTextureSampleWithSeparateTextureAndSampler() return; if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) - result = std::move(result).mirrored(); + result.flip(); QRgb white = qRgba(255, 255, 255, 255); QCOMPARE(result.pixel(79, 77), white); @@ -2556,7 +2556,7 @@ void tst_QRhi::renderToTextureArrayOfTexturedQuad() // just happens to give correct results with our OpenGL-targeted vertex and // UV data. if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) - result = std::move(result).mirrored(); + result.flip(); // we added the input image + red + green together, so red and green must be all 1 for (int y = 0; y < result.height(); ++y) { @@ -2721,8 +2721,8 @@ void tst_QRhi::renderToTextureTexturedQuadAndUniformBuffer() QVERIFY(!result1.isNull()); if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) { - result0 = std::move(result0).mirrored(); - result1 = std::move(result1).mirrored(); + result0.flip(); + result1.flip(); } if (impl == QRhi::Null) @@ -2928,8 +2928,8 @@ void tst_QRhi::renderToTextureTexturedQuadAllDynamicBuffers() QVERIFY(!result1.isNull()); if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) { - result0 = std::move(result0).mirrored(); - result1 = std::move(result1).mirrored(); + result0.flip(); + result1.flip(); } if (impl == QRhi::Null) @@ -3089,7 +3089,7 @@ void tst_QRhi::renderToTextureDeferredSrb() return; if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) - result = std::move(result).mirrored(); + result.flip(); // opacity 0.5 (premultiplied) static const auto checkSemiWhite = [](const QRgb &c) { @@ -3230,7 +3230,7 @@ void tst_QRhi::renderToTextureDeferredUpdateSamplerInSrb() return; if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) - result = std::move(result).mirrored(); + result.flip(); // opacity 0.5 (premultiplied) static const auto checkSemiWhite = [](const QRgb &c) { @@ -3393,7 +3393,7 @@ void tst_QRhi::renderToTextureMultipleUniformBuffersAndDynamicOffset() return; if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) - result = std::move(result).mirrored(); + result.flip(); // opacity 0.5 (premultiplied) static const auto checkSemiWhite = [](const QRgb &c) { @@ -3542,7 +3542,7 @@ void tst_QRhi::renderToTextureSrbReuse() return; if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) - result = std::move(result).mirrored(); + result.flip(); // opacity 0.5 (premultiplied) static const auto checkSemiWhite = [](const QRgb &c) { @@ -3848,13 +3848,13 @@ void tst_QRhi::renderToTextureArrayMultiView() readResult[0].pixelSize.width(), readResult[0].pixelSize.height(), QImage::Format_RGBA8888); if (rhi->isYUpInFramebuffer()) // note that we used clipSpaceCorrMatrix - image0 = image0.mirrored(); + image0.flip(); QImage image1 = QImage(reinterpret_cast<const uchar *>(readResult[1].data.constData()), readResult[1].pixelSize.width(), readResult[1].pixelSize.height(), QImage::Format_RGBA8888); if (rhi->isYUpInFramebuffer()) - image1 = image1.mirrored(); + image1.flip(); QVERIFY(!image0.isNull()); QVERIFY(!image1.isNull()); @@ -3964,7 +3964,7 @@ void tst_QRhi::renderToWindowSimple() if (readResult.format == QRhiTexture::RGBA8) wrapperImage = wrapperImage.rgbSwapped(); if (rhi->isYUpInFramebuffer() == rhi->isYUpInNDC()) - result = wrapperImage.mirrored(); + result = wrapperImage.flipped(); else result = wrapperImage.copy(); }; @@ -6069,7 +6069,7 @@ void tst_QRhi::renderToFloatTexture() return; if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) - result = std::move(result).mirrored(); + result.flip(); // Now we have a red rectangle on blue background. const int y = 100; @@ -6158,7 +6158,7 @@ void tst_QRhi::renderToRgb10Texture() return; if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC()) - result = std::move(result).mirrored(); + result.flip(); // Now we have a red rectangle on blue background. const int y = 100; @@ -6300,7 +6300,7 @@ void tst_QRhi::tessellation() rhi->endOffscreenFrame(); if (rhi->isYUpInFramebuffer()) // we used clipSpaceCorrMatrix so this is different from many other tests - result = std::move(result).mirrored(); + result.flip(); QCOMPARE(result.size(), rt->pixelSize()); @@ -6490,7 +6490,7 @@ void tst_QRhi::tessellationInterfaceBlocks() if (rhi->isYUpInFramebuffer()) // we used clipSpaceCorrMatrix so this is different from many // other tests - result = std::move(result).mirrored(); + result.flip(); QCOMPARE(result.size(), rt->pixelSize()); diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 7f3e204ec68..3eb3bce17ec 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -8368,7 +8368,7 @@ void tst_QWidget::renderRTL() menu.setLayoutDirection(Qt::RightToLeft); QImage imageRTL(menu.size(), QImage::Format_ARGB32); menu.render(&imageRTL); - imageRTL = imageRTL.mirrored(true, false); + imageRTL.flip(Qt::Horizontal); //imageRTL.save("/tmp/rendered_2.png"); QCOMPARE(imageLTR.height(), imageRTL.height()); diff --git a/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp b/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp index 7a102180e70..457df2159b1 100644 --- a/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp +++ b/tests/auto/widgets/widgets/qrhiwidget/tst_qrhiwidget.cpp @@ -398,7 +398,7 @@ void tst_QRhiWidget::simple() readResult.pixelSize.width(), readResult.pixelSize.height(), QImage::Format_RGBA8888); if (rhi->isYUpInFramebuffer()) - resultOne = wrapperImage.mirrored(); + resultOne = wrapperImage.flipped(); else resultOne = wrapperImage.copy(); @@ -481,7 +481,7 @@ void tst_QRhiWidget::msaa() QImage::Format_RGBA8888); QImage result; if (rhi->isYUpInFramebuffer()) - result = wrapperImage.mirrored(); + result = wrapperImage.flipped(); else result = wrapperImage.copy(); @@ -726,7 +726,7 @@ void tst_QRhiWidget::grabFramebufferWhileStillInvisible() readResult.pixelSize.width(), readResult.pixelSize.height(), QImage::Format_RGBA8888); if (w.rhi()->isYUpInFramebuffer()) - image = wrapperImage.mirrored(); + image = wrapperImage.flipped(); else image = wrapperImage.copy(); QRgb c = image.pixel(image.width() / 2, image.height() / 2); @@ -810,7 +810,7 @@ void tst_QRhiWidget::mirror() QImage::Format_RGBA8888); QImage image; if (rhi->isYUpInFramebuffer()) - image = wrapperImage.mirrored(); + image = wrapperImage.flipped(); else image = wrapperImage.copy(); diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp index b03365a480d..6354fa70c2f 100644 --- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp @@ -2328,7 +2328,7 @@ void tst_QTextEdit::noWrapBackgrounds() topLevel.show(); const QImage img = edit.viewport()->grab().toImage(); - QCOMPARE(img, img.mirrored(true, false)); + QCOMPARE(img, img.flipped(Qt::Horizontal)); } void tst_QTextEdit::preserveCharFormatAfterUnchangingSetPosition() diff --git a/tests/manual/examples/opengl/computegles31/glwindow.cpp b/tests/manual/examples/opengl/computegles31/glwindow.cpp index 98533e714ef..b0ed6207b0c 100644 --- a/tests/manual/examples/opengl/computegles31/glwindow.cpp +++ b/tests/manual/examples/opengl/computegles31/glwindow.cpp @@ -271,7 +271,7 @@ void GLWindow::initializeGL() QImage img(":/Qt-logo-medium.png"); Q_ASSERT(!img.isNull()); delete m_texImageInput; - m_texImageInput = new QOpenGLTexture(img.convertToFormat(QImage::Format_RGBA8888).mirrored()); + m_texImageInput = new QOpenGLTexture(img.convertToFormat(QImage::Format_RGBA8888).flipped()); delete m_texImageTmp; m_texImageTmp = new QOpenGLTexture(QOpenGLTexture::Target2D); diff --git a/tests/manual/qgraphicslayout/weatheranchorlayout/main.cpp b/tests/manual/qgraphicslayout/weatheranchorlayout/main.cpp index bdf7c00942b..ee5c6a0d3bf 100644 --- a/tests/manual/qgraphicslayout/weatheranchorlayout/main.cpp +++ b/tests/manual/qgraphicslayout/weatheranchorlayout/main.cpp @@ -123,7 +123,7 @@ public: // paint the image flipped p.setCompositionMode(QPainter::CompositionMode_DestinationOver); - p.drawPixmap(0, 0, QPixmap::fromImage(scaled.toImage().mirrored(false, true))); + p.drawPixmap(0, 0, QPixmap::fromImage(scaled.toImage().flipped())); p.end(); painter->drawPixmap(reflection, tmp); diff --git a/tests/manual/qopengltextureblitter/qopengltextureblitwindow.cpp b/tests/manual/qopengltextureblitter/qopengltextureblitwindow.cpp index 90557c7dc44..6e00d7ad564 100644 --- a/tests/manual/qopengltextureblitter/qopengltextureblitwindow.cpp +++ b/tests/manual/qopengltextureblitter/qopengltextureblitwindow.cpp @@ -148,6 +148,6 @@ void QOpenGLTextureBlitWindow::resizeEvent(QResizeEvent *event) p.drawRect(QRectF(2.5,2.5,dWidth() - 5, dHeight() - 5)); - m_image_mirrord = m_image.mirrored(false,true); + m_image_mirrord = m_image.flipped(); } diff --git a/tests/manual/qopenglwidget/dockedopenglwidget/mainwidget.cpp b/tests/manual/qopenglwidget/dockedopenglwidget/mainwidget.cpp index b9dc4c5fe24..4127995b8e5 100644 --- a/tests/manual/qopenglwidget/dockedopenglwidget/mainwidget.cpp +++ b/tests/manual/qopenglwidget/dockedopenglwidget/mainwidget.cpp @@ -110,7 +110,7 @@ void MainWidget::initShaders() void MainWidget::initTextures() { // Load cube.png image - texture = new QOpenGLTexture(QImage(":/cube.png").mirrored()); + texture = new QOpenGLTexture(QImage(":/cube.png").flipped()); // Set nearest filtering mode for texture minification texture->setMinificationFilter(QOpenGLTexture::Nearest); diff --git a/tests/manual/rhi/cubemap/cubemap.cpp b/tests/manual/rhi/cubemap/cubemap.cpp index bf027b49de3..e7a0ceb7657 100644 --- a/tests/manual/rhi/cubemap/cubemap.cpp +++ b/tests/manual/rhi/cubemap/cubemap.cpp @@ -34,7 +34,7 @@ void Window::customInit() d.initialUpdates = m_r->nextResourceUpdateBatch(); d.initialUpdates->uploadStaticBuffer(d.vbuf, cube); - QImage img = QImage(":/c.png").mirrored().convertToFormat(QImage::Format_RGBA8888); + QImage img = QImage(":/c.png").flipped().convertToFormat(QImage::Format_RGBA8888); // just use the same image for all faces for now QRhiTextureSubresourceUploadDescription subresDesc(img); QRhiTextureUploadDescription desc({ diff --git a/tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp index 78933830a14..5e26022a79a 100644 --- a/tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp +++ b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp @@ -45,7 +45,7 @@ void Window::customInit() d.initialUpdates = m_r->nextResourceUpdateBatch(); d.initialUpdates->uploadStaticBuffer(d.vbuf, cube); - QImage img = QImage(":/c.png").mirrored().convertToFormat(QImage::Format_RGBA8888); + QImage img = QImage(":/c.png").flipped().convertToFormat(QImage::Format_RGBA8888); // just use the same image for all faces for now QRhiTextureSubresourceUploadDescription subresDesc(img); QRhiTextureUploadDescription desc({ diff --git a/tests/manual/rhi/imguirenderer/imguirenderer.cpp b/tests/manual/rhi/imguirenderer/imguirenderer.cpp index ef675c2e5b8..41329895c8c 100644 --- a/tests/manual/rhi/imguirenderer/imguirenderer.cpp +++ b/tests/manual/rhi/imguirenderer/imguirenderer.cpp @@ -36,7 +36,7 @@ void Window::customInit() float opacity = 1.0f; d.initialUpdates->updateDynamicBuffer(d.ubuf, 64, 4, &opacity); - QImage image = QImage(QLatin1String(":/qt256.png")).convertToFormat(QImage::Format_RGBA8888).mirrored(); + QImage image = QImage(QLatin1String(":/qt256.png")).convertToFormat(QImage::Format_RGBA8888).flipped(); d.tex = m_r->newTexture(QRhiTexture::RGBA8, QSize(image.width(), image.height()), 1, {}); d.releasePool << d.tex; d.tex->create(); diff --git a/tests/manual/rhi/offscreen/offscreen.cpp b/tests/manual/rhi/offscreen/offscreen.cpp index 86bf5ad5a9e..5f7c824d2cf 100644 --- a/tests/manual/rhi/offscreen/offscreen.cpp +++ b/tests/manual/rhi/offscreen/offscreen.cpp @@ -275,7 +275,7 @@ int main(int argc, char **argv) fn = QFileInfo(fn).absoluteFilePath(); qDebug("Saving into %s", qPrintable(fn)); if (r->isYUpInFramebuffer()) - image.mirrored().save(fn); + image.flipped().save(fn); else image.save(fn); } else { diff --git a/tests/manual/rhi/triquadcube/triangleoncuberenderer.cpp b/tests/manual/rhi/triquadcube/triangleoncuberenderer.cpp index 33dc0776d74..40111aa0bfd 100644 --- a/tests/manual/rhi/triquadcube/triangleoncuberenderer.cpp +++ b/tests/manual/rhi/triquadcube/triangleoncuberenderer.cpp @@ -41,7 +41,7 @@ void TriangleOnCubeRenderer::initResources(QRhiRenderPassDescriptor *rp) if (IMAGE_UNDER_OFFSCREEN_RENDERING) { m_image = QImage(QLatin1String(":/qt256.png")).scaled(OFFSCREEN_SIZE).convertToFormat(QImage::Format_RGBA8888); if (m_r->isYUpInFramebuffer()) - m_image = m_image.mirrored(); // just cause we'll flip texcoord Y when y up so accommodate our static background image as well + m_image.flip(); // just cause we'll flip texcoord Y when y up so accommodate our static background image as well } m_tex = m_r->newTexture(QRhiTexture::RGBA8, OFFSCREEN_SIZE, 1, QRhiTexture::RenderTarget); diff --git a/tests/manual/rhi/triquadcube/triquadcube.cpp b/tests/manual/rhi/triquadcube/triquadcube.cpp index 2ef0d567dbf..047134af7e6 100644 --- a/tests/manual/rhi/triquadcube/triquadcube.cpp +++ b/tests/manual/rhi/triquadcube/triquadcube.cpp @@ -224,7 +224,7 @@ void Window::customRender() fn = QFileInfo(fn).absoluteFilePath(); qDebug("Saving into %s", qPrintable(fn)); if (m_r->isYUpInFramebuffer()) - image.mirrored().save(fn); + image.flipped().save(fn); else image.save(fn); } diff --git a/tests/manual/rhi/vrs/vrs.cpp b/tests/manual/rhi/vrs/vrs.cpp index cda827238ab..3cb568a8f62 100644 --- a/tests/manual/rhi/vrs/vrs.cpp +++ b/tests/manual/rhi/vrs/vrs.cpp @@ -77,7 +77,7 @@ void Window::customInit() d.ubuf->create(); d.releasePool << d.ubuf; - QImage image = QImage(QLatin1String(":/qt256.png")).convertToFormat(QImage::Format_RGBA8888).mirrored(); + QImage image = QImage(QLatin1String(":/qt256.png")).convertToFormat(QImage::Format_RGBA8888).flipped(); d.tex = m_r->newTexture(QRhiTexture::RGBA8, QSize(image.width(), image.height()), 1, {}); d.releasePool << d.tex; d.tex->create(); |