Kaydet (Commit) 22421a40 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Miklos Vajna

opengl: when scaling, create a new texture with equal settings

Change-Id: Id0258fe0db89aa06b91233ae2052f018d606cc74
(cherry picked from commit 6d9ddfb9)
Reviewed-on: https://gerrit.libreoffice.org/17558Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst c02d01ba
...@@ -106,6 +106,8 @@ private: ...@@ -106,6 +106,8 @@ private:
bool ImplScaleConvolution( const double& rScaleX, const double& rScaleY, const Kernel& aKernel ); bool ImplScaleConvolution( const double& rScaleX, const double& rScaleY, const Kernel& aKernel );
bool ImplScaleArea( double rScaleX, double rScaleY ); bool ImplScaleArea( double rScaleX, double rScaleY );
bool getFormatAndType(GLenum& nFormat, GLenum& nType);
public: public:
bool ImplScale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ); bool ImplScale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag );
......
...@@ -43,6 +43,31 @@ public: ...@@ -43,6 +43,31 @@ public:
void GetSize( Size& rSize ) const SAL_OVERRIDE; void GetSize( Size& rSize ) const SAL_OVERRIDE;
}; };
bool OpenGLSalBitmap::getFormatAndType(GLenum& nFormat, GLenum& nType)
{
switch(mnBits)
{
case 8:
nFormat = GL_LUMINANCE;
nType = GL_UNSIGNED_BYTE;
break;
case 16:
nFormat = GL_RGB;
nType = GL_UNSIGNED_SHORT_5_6_5;
break;
case 24:
nFormat = GL_RGB;
nType = GL_UNSIGNED_BYTE;
break;
case 32:
default:
nFormat = GL_RGBA;
nType = GL_UNSIGNED_BYTE;
break;
}
return true;
}
bool OpenGLSalBitmap::ImplScaleFilter( bool OpenGLSalBitmap::ImplScaleFilter(
const double& rScaleX, const double& rScaleX,
const double& rScaleY, const double& rScaleY,
...@@ -59,7 +84,11 @@ bool OpenGLSalBitmap::ImplScaleFilter( ...@@ -59,7 +84,11 @@ bool OpenGLSalBitmap::ImplScaleFilter(
if( !pProgram ) if( !pProgram )
return false; return false;
OpenGLTexture aNewTex = OpenGLTexture( nNewWidth, nNewHeight ); GLenum nFormat;
GLenum nType;
getFormatAndType(nFormat, nType);
OpenGLTexture aNewTex = OpenGLTexture(nNewWidth, nNewHeight, nFormat, nType, nullptr);
pFramebuffer = mpContext->AcquireFramebuffer( aNewTex ); pFramebuffer = mpContext->AcquireFramebuffer( aNewTex );
pProgram->SetTexture( "sampler", maTexture ); pProgram->SetTexture( "sampler", maTexture );
...@@ -138,10 +167,15 @@ bool OpenGLSalBitmap::ImplScaleConvolution( ...@@ -138,10 +167,15 @@ bool OpenGLSalBitmap::ImplScaleConvolution(
if( pProgram == 0 ) if( pProgram == 0 )
return false; return false;
GLenum nFormat;
GLenum nType;
getFormatAndType(nFormat, nType);
// horizontal scaling in scratch texture // horizontal scaling in scratch texture
if( mnWidth != nNewWidth ) if( mnWidth != nNewWidth )
{ {
OpenGLTexture aScratchTex = OpenGLTexture( nNewWidth, mnHeight ); OpenGLTexture aScratchTex = OpenGLTexture(nNewWidth, mnHeight, nFormat, nType, nullptr);
pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex ); pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex );
for( sal_uInt32 i = 0; i < 16; i++ ) for( sal_uInt32 i = 0; i < 16; i++ )
...@@ -163,7 +197,8 @@ bool OpenGLSalBitmap::ImplScaleConvolution( ...@@ -163,7 +197,8 @@ bool OpenGLSalBitmap::ImplScaleConvolution(
// vertical scaling in final texture // vertical scaling in final texture
if( mnHeight != nNewHeight ) if( mnHeight != nNewHeight )
{ {
OpenGLTexture aScratchTex = OpenGLTexture( nNewWidth, nNewHeight ); OpenGLTexture aScratchTex = OpenGLTexture(nNewWidth, nNewHeight, nFormat, nType, nullptr);
pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex ); pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex );
for( sal_uInt32 i = 0; i < 16; i++ ) for( sal_uInt32 i = 0; i < 16; i++ )
...@@ -223,7 +258,12 @@ bool OpenGLSalBitmap::ImplScaleArea( double rScaleX, double rScaleY ) ...@@ -223,7 +258,12 @@ bool OpenGLSalBitmap::ImplScaleArea( double rScaleX, double rScaleY )
if( pProgram == 0 ) if( pProgram == 0 )
return false; return false;
OpenGLTexture aScratchTex = OpenGLTexture( nNewWidth, nNewHeight ); GLenum nFormat;
GLenum nType;
getFormatAndType(nFormat, nType);
OpenGLTexture aScratchTex = OpenGLTexture(nNewWidth, nNewHeight, nFormat, nType, nullptr);
OpenGLFramebuffer* pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex ); OpenGLFramebuffer* pFramebuffer = mpContext->AcquireFramebuffer( aScratchTex );
// NOTE: This setup is also done in OpenGLSalGraphicsImpl::DrawTransformedTexture(). // NOTE: This setup is also done in OpenGLSalGraphicsImpl::DrawTransformedTexture().
...@@ -325,7 +365,9 @@ void ScaleOp::GetSize( Size& rSize ) const ...@@ -325,7 +365,9 @@ void ScaleOp::GetSize( Size& rSize ) const
bool OpenGLSalBitmap::Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) bool OpenGLSalBitmap::Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag )
{ {
SAL_INFO( "vcl.opengl", "::Scale " << static_cast<int>(nScaleFlag) ); SAL_INFO("vcl.opengl", "::Scale " << int(nScaleFlag)
<< " from " << mnWidth << "x" << mnHeight
<< " to " << (mnWidth * rScaleX) << "x" << (mnHeight * rScaleY) );
if( nScaleFlag == BmpScaleFlag::Fast || if( nScaleFlag == BmpScaleFlag::Fast ||
nScaleFlag == BmpScaleFlag::BiLinear || nScaleFlag == BmpScaleFlag::BiLinear ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment