gl: Check for image validity in readback
Returning a null QImage is preferable over passing a null bits() to glReadPixels. (matters when QImage's malloc() gives null, thus 'd' is null -> isNull() == true) Fixes: QTBUG-113127 Change-Id: Ieca4d91eefdea47da5251dabe77cc31b48eb0e28 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit 11209cfde68e9b8b8722859c690e57c7d6e8a338) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
44ab03068c
commit
67f78a1e7f
@ -1370,7 +1370,8 @@ static inline QImage qt_gl_read_framebuffer_rgba8(const QSize &size, bool includ
|
|||||||
bool isOpenGL12orBetter = !context->isOpenGLES() && (context->format().majorVersion() >= 2 || context->format().minorVersion() >= 2);
|
bool isOpenGL12orBetter = !context->isOpenGLES() && (context->format().majorVersion() >= 2 || context->format().minorVersion() >= 2);
|
||||||
if (isOpenGL12orBetter) {
|
if (isOpenGL12orBetter) {
|
||||||
QImage img(size, include_alpha ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32);
|
QImage img(size, include_alpha ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32);
|
||||||
funcs->glReadPixels(0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, img.bits());
|
if (!img.isNull())
|
||||||
|
funcs->glReadPixels(0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, img.bits());
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1380,7 +1381,8 @@ static inline QImage qt_gl_read_framebuffer_rgba8(const QSize &size, bool includ
|
|||||||
// BGRA capable impl would return BGRA from there)
|
// BGRA capable impl would return BGRA from there)
|
||||||
|
|
||||||
QImage rgbaImage(size, include_alpha ? QImage::Format_RGBA8888_Premultiplied : QImage::Format_RGBX8888);
|
QImage rgbaImage(size, include_alpha ? QImage::Format_RGBA8888_Premultiplied : QImage::Format_RGBX8888);
|
||||||
funcs->glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rgbaImage.bits());
|
if (!rgbaImage.isNull())
|
||||||
|
funcs->glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rgbaImage.bits());
|
||||||
return rgbaImage;
|
return rgbaImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1388,7 +1390,8 @@ static inline QImage qt_gl_read_framebuffer_rgb10a2(const QSize &size, bool incl
|
|||||||
{
|
{
|
||||||
// We assume OpenGL 1.2+ or ES 3.0+ here.
|
// We assume OpenGL 1.2+ or ES 3.0+ here.
|
||||||
QImage img(size, include_alpha ? QImage::Format_A2BGR30_Premultiplied : QImage::Format_BGR30);
|
QImage img(size, include_alpha ? QImage::Format_A2BGR30_Premultiplied : QImage::Format_BGR30);
|
||||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, img.bits());
|
if (!img.isNull())
|
||||||
|
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, img.bits());
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1396,7 +1399,8 @@ static inline QImage qt_gl_read_framebuffer_rgba16(const QSize &size, bool inclu
|
|||||||
{
|
{
|
||||||
// We assume OpenGL 1.2+ or ES 3.0+ here.
|
// We assume OpenGL 1.2+ or ES 3.0+ here.
|
||||||
QImage img(size, include_alpha ? QImage::Format_RGBA64_Premultiplied : QImage::Format_RGBX64);
|
QImage img(size, include_alpha ? QImage::Format_RGBA64_Premultiplied : QImage::Format_RGBX64);
|
||||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_SHORT, img.bits());
|
if (!img.isNull())
|
||||||
|
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_SHORT, img.bits());
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1404,14 +1408,16 @@ static inline QImage qt_gl_read_framebuffer_rgba16f(const QSize &size, bool incl
|
|||||||
{
|
{
|
||||||
// We assume OpenGL (ES) 3.0+ here.
|
// We assume OpenGL (ES) 3.0+ here.
|
||||||
QImage img(size, include_alpha ? QImage::Format_RGBA16FPx4_Premultiplied : QImage::Format_RGBX16FPx4);
|
QImage img(size, include_alpha ? QImage::Format_RGBA16FPx4_Premultiplied : QImage::Format_RGBX16FPx4);
|
||||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_HALF_FLOAT, img.bits());
|
if (!img.isNull())
|
||||||
|
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_HALF_FLOAT, img.bits());
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QImage qt_gl_read_framebuffer_rgba32f(const QSize &size, bool include_alpha, QOpenGLContext *context)
|
static inline QImage qt_gl_read_framebuffer_rgba32f(const QSize &size, bool include_alpha, QOpenGLContext *context)
|
||||||
{
|
{
|
||||||
QImage img(size, include_alpha ? QImage::Format_RGBA32FPx4_Premultiplied : QImage::Format_RGBX32FPx4);
|
QImage img(size, include_alpha ? QImage::Format_RGBA32FPx4_Premultiplied : QImage::Format_RGBX32FPx4);
|
||||||
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_FLOAT, img.bits());
|
if (!img.isNull())
|
||||||
|
context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_FLOAT, img.bits());
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user