[Libreoffice-commits] core.git: Branch 'feature/fixes14' - vcl/inc vcl/opengl vcl/Package_opengl.mk vcl/source
Tomaž Vajngerl
tomaz.vajngerl at collabora.com
Mon Feb 8 21:28:32 UTC 2016
vcl/Package_opengl.mk | 1
vcl/inc/impbmp.hxx | 1
vcl/inc/opengl/salbmp.hxx | 1
vcl/inc/salbmp.hxx | 4 ++
vcl/opengl/greyscaleFragmentShader.glsl | 18 ++++++++++++
vcl/opengl/salbmp.cxx | 48 ++++++++++++++++++++++++++++++++
vcl/source/gdi/bitmap3.cxx | 19 ++++++++++++
vcl/source/gdi/impbmp.cxx | 10 ++++++
8 files changed, 102 insertions(+)
New commits:
commit 04352f2f9e598fc79c9ba9c54aa7f17ed56d8d19
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Mon Feb 8 22:25:59 2016 +0100
opengl: convert the bitmap to 8bit grays using GL shader
Change-Id: I4d48d29ab752814f71c697a201e70a26ae937775
diff --git a/vcl/Package_opengl.mk b/vcl/Package_opengl.mk
index 9d42502..b8851df 100644
--- a/vcl/Package_opengl.mk
+++ b/vcl/Package_opengl.mk
@@ -17,6 +17,7 @@ $(eval $(call gb_Package_add_files,vcl_opengl_shader,$(LIBO_ETC_FOLDER)/opengl,\
blendedTextureVertexShader.glsl \
dumbVertexShader.glsl \
diffTextureFragmentShader.glsl \
+ greyscaleFragmentShader.glsl \
invert50FragmentShader.glsl \
convolutionFragmentShader.glsl \
linearGradientFragmentShader.glsl \
diff --git a/vcl/inc/impbmp.hxx b/vcl/inc/impbmp.hxx
index f2bd27d..9527c5d 100644
--- a/vcl/inc/impbmp.hxx
+++ b/vcl/inc/impbmp.hxx
@@ -74,6 +74,7 @@ public:
bool ImplScale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag );
bool ImplReplace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol );
+ bool ImplConvert( BmpConversion eConversion );
};
#endif // INCLUDED_VCL_INC_IMPBMP_HXX
diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx
index dcf2f17..6128523 100644
--- a/vcl/inc/opengl/salbmp.hxx
+++ b/vcl/inc/opengl/salbmp.hxx
@@ -84,6 +84,7 @@ public:
bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) override;
bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol ) override;
+ bool ConvertToGreyscale() override;
public:
diff --git a/vcl/inc/salbmp.hxx b/vcl/inc/salbmp.hxx
index 49d2657..49b8319 100644
--- a/vcl/inc/salbmp.hxx
+++ b/vcl/inc/salbmp.hxx
@@ -71,6 +71,10 @@ public:
virtual bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) = 0;
virtual bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol ) = 0;
+ virtual bool ConvertToGreyscale()
+ {
+ return false;
+ }
bool GetChecksum(ChecksumType& rChecksum) const
{
diff --git a/vcl/opengl/greyscaleFragmentShader.glsl b/vcl/opengl/greyscaleFragmentShader.glsl
new file mode 100644
index 0000000..5117c488
--- /dev/null
+++ b/vcl/opengl/greyscaleFragmentShader.glsl
@@ -0,0 +1,18 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+varying vec2 tex_coord;
+uniform sampler2D sampler;
+
+void main() {
+ vec4 texel = texture2D(sampler, tex_coord);
+ gl_FragColor = vec4(vec3(dot(texel.rgb, vec3(0.302, 0.592, 0.109))), 1.0);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx
index 0c6ea6d..6eaced6 100644
--- a/vcl/opengl/salbmp.cxx
+++ b/vcl/opengl/salbmp.cxx
@@ -898,4 +898,52 @@ bool OpenGLSalBitmap::Replace( const Color& rSearchColor, const Color& rReplaceC
return true;
}
+// Convert texture to greyscale and adjust bitmap metadata
+bool OpenGLSalBitmap::ConvertToGreyscale()
+{
+ VCL_GL_INFO("::ConvertToGreyscale");
+
+ if (false)
+ return false;
+
+ OpenGLZone aZone;
+ rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext();
+
+ OpenGLFramebuffer* pFramebuffer;
+ OpenGLProgram* pProgram;
+
+ GetTexture();
+ pProgram = xContext->UseProgram("textureVertexShader", "greyscaleFragmentShader");
+
+ if (!pProgram)
+ return false;
+
+ OpenGLTexture aNewTex(mnWidth, mnHeight);
+ pFramebuffer = xContext->AcquireFramebuffer(aNewTex);
+ pProgram->ApplyMatrix(mnWidth, mnHeight);
+ pProgram->SetTexture("sampler", maTexture);
+ pProgram->DrawTexture(maTexture);
+ pProgram->Clean();
+
+ OpenGLContext::ReleaseFramebuffer( pFramebuffer );
+ maTexture = aNewTex;
+ mnBits = 8;
+
+ static BitmapPalette aGreyPalette256;
+ if (!aGreyPalette256.GetEntryCount())
+ {
+ aGreyPalette256.SetEntryCount(256);
+
+ for (sal_uInt16 i = 0; i < 256; i++)
+ {
+ sal_uInt8 nValue = sal_uInt8(i);
+ aGreyPalette256[i] = BitmapColor(nValue, nValue, nValue);
+ }
+ }
+ maPalette = aGreyPalette256;
+
+ CHECK_GL_ERROR();
+ return true;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx
index 9359fb9..30a4f92 100644
--- a/vcl/source/gdi/bitmap3.cxx
+++ b/vcl/source/gdi/bitmap3.cxx
@@ -250,6 +250,25 @@ void ImplCreateDitherMatrix( sal_uInt8 (*pDitherMatrix)[16][16] )
bool Bitmap::Convert( BmpConversion eConversion )
{
+ // try to convert in backend
+ if (mpImpBmp)
+ {
+ ImpBitmap* pImpBmp = new ImpBitmap;
+
+ if (pImpBmp->ImplCreate(*mpImpBmp) && pImpBmp->ImplConvert(eConversion))
+ {
+ ImplSetImpBitmap(pImpBmp);
+ SAL_INFO( "vcl.opengl", "Ref count: " << mpImpBmp->ImplGetRefCount() );
+ //maPrefMapMode = MapMode(MAP_PIXEL);
+ //maPrefSize = pImpBmp->ImplGetSize();
+ return true;
+ }
+ else
+ {
+ delete pImpBmp;
+ }
+ }
+
const sal_uInt16 nBitCount = GetBitCount ();
bool bRet = false;
diff --git a/vcl/source/gdi/impbmp.cxx b/vcl/source/gdi/impbmp.cxx
index b79b0d4..ea9a859 100644
--- a/vcl/source/gdi/impbmp.cxx
+++ b/vcl/source/gdi/impbmp.cxx
@@ -114,4 +114,14 @@ bool ImpBitmap::ImplReplace( const Color& rSearchColor, const Color& rReplaceCol
return mpSalBitmap->Replace( rSearchColor, rReplaceColor, nTol );
}
+bool ImpBitmap::ImplConvert( BmpConversion eConversion )
+{
+ // avoid large chunk of obsolete and hopefully rarely used conversions.
+ if (eConversion != BMP_CONVERSION_8BIT_GREYS)
+ return false;
+
+ // frequently used conversion for creating alpha masks
+ return mpSalBitmap->ConvertToGreyscale();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list