Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
recover snapshot function
Browse files Browse the repository at this point in the history
  • Loading branch information
bylee20 committed Oct 21, 2013
1 parent 1c4e6cd commit 0151bd6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
33 changes: 33 additions & 0 deletions src/cmplayer/openglcompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,36 @@ void setLutIntCoord(const in vec2 vCoord) {
)";
return code;
}



template<typename T>
static QImage getImage(const QSize &size, const OpenGLTextureFormat &format) {
if (size.isEmpty())
return QImage();
QImage image(size, QImage::Format_ARGB32);
QVector<T> data(size.width()*size.height()*4);
auto src = data.data();
glReadPixels(0, 0, size.width(), size.height(), format.pixel, format.type, src);
uchar *dst = image.bits();
const qreal r = qreal(_Max<uchar>())/qreal(_Max<T>());
for (int i=0; i<size.width()*size.height()*4; ++i)
*dst++ = qRound(qreal(*src++)*r);
return image;
}

QImage OpenGLFramebufferObject::toImage() const {
bind();
Q_ASSERT(QOpenGLContext::currentContext() != nullptr);
switch (m_texture.format.type) {
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_INT_8_8_8_8:
case GL_UNSIGNED_INT_8_8_8_8_REV:
return getImage<uchar>(m_texture.size(), m_texture.format);
case GL_UNSIGNED_SHORT:
return getImage<GLushort>(m_texture.size(), m_texture.format);
default:
return QImage();
}
release();
}
11 changes: 3 additions & 8 deletions src/cmplayer/openglcompat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,10 @@ class OpenGLFramebufferObject {
int width() const { return m_texture.width; }
int height() const { return m_texture.height; }
QSize size() const { return {m_texture.width, m_texture.height}; }
void bind() { func()->glBindFramebuffer(GL_FRAMEBUFFER, m_id); }
void release() { QOpenGLFramebufferObject::bindDefault(); }
void bind() const { func()->glBindFramebuffer(GL_FRAMEBUFFER, m_id); }
void release() const { QOpenGLFramebufferObject::bindDefault(); }
const OpenGLTexture &texture() const { return m_texture; }
QImage toImage() const {
QImage image(m_texture.width, m_texture.height, QImage::Format_ARGB32);
m_texture.bind();
glGetTexImage(m_texture.target, 0, m_texture.format.pixel, m_texture.format.type, image.bits());
return image;
}
QImage toImage() const;
void getCoords(double &x1, double &y1, double &x2, double &y2) {
if (m_texture.target == GL_TEXTURE_RECTANGLE) {
x1 = y1 = 0; x2 = m_texture.width; y2 = m_texture.height;
Expand Down
2 changes: 1 addition & 1 deletion src/cmplayer/videorendereritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void VideoRendererItem::prepare(QSGGeometryNode *node) {

if (d->render && !d->frameSize.isEmpty()) {
if (!d->fbo || d->fbo->size() != d->frameSize) {
_Renew(d->fbo, d->frameSize, OpenGLCompat::textureFormat(GL_BGRA, 2), GL_TEXTURE_2D);
_Renew(d->fbo, d->frameSize, OpenGLCompat::textureFormat(GL_BGRA, 1), GL_TEXTURE_2D);
setRenderTarget(d->fbo->texture());
}
d->fbo->bind();
Expand Down

0 comments on commit 0151bd6

Please sign in to comment.