From 36e6376755ce0f5dcd022e11d2539f125980a96b Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 3 Jul 2013 15:13:55 +0200 Subject: Support RGBA image format Support the byte-ordered RGBA format which is used by OpenGL, and many endian neutral byte formats. Task-number: QTBUG-32201 Change-Id: I77cffb4c30c69545fa96ded2f537b2ebd9351acb Reviewed-by: Allan Sandfeld Jensen --- src/gui/opengl/qopenglframebufferobject.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/gui/opengl/qopenglframebufferobject.cpp') diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp index 90416db72bc..247ecf73514 100644 --- a/src/gui/opengl/qopenglframebufferobject.cpp +++ b/src/gui/opengl/qopenglframebufferobject.cpp @@ -1012,23 +1012,28 @@ QOpenGLFramebufferObjectFormat QOpenGLFramebufferObject::format() const Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, bool include_alpha) { - QImage img(size, (alpha_format && include_alpha) ? QImage::Format_ARGB32_Premultiplied - : QImage::Format_RGB32); int w = size.width(); int h = size.height(); + while (glGetError()); + +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN + QImage img(size, (alpha_format && include_alpha) ? QImage::Format_ARGB32_Premultiplied + : QImage::Format_RGB32); #ifdef QT_OPENGL_ES GLint fmt = GL_BGRA_EXT; #else GLint fmt = GL_BGRA; #endif - while (glGetError()); glReadPixels(0, 0, w, h, fmt, GL_UNSIGNED_BYTE, img.bits()); - if (glGetError()) { - glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); - img = img.rgbSwapped(); - } - return img.mirrored(); + if (!glGetError()) + return img.mirrored(); +#endif + + QImage rgbaImage(size, (alpha_format && include_alpha) ? QImage::Format_RGBA8888_Premultiplied + : QImage::Format_RGBX8888); + glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rgbaImage.bits()); + return rgbaImage.mirrored(); } /*! -- cgit v1.2.3