diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2015-08-26 13:50:57 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-09-01 16:28:45 +0100 |
commit | ebb0dc14547e698d7b53005178063da72d48f075 (patch) | |
tree | 8cf95d717f32672dc8e6ecf9f6b743227ada889f /vcl | |
parent | 7cc4cdc5ef6dff279e072af725c2d7fc1e5da0e8 (diff) |
Added support for computing 64-bit checksum of bitmap in OpenGL
Added a C++ and a GLSL implementation of a 64-bit CRC algorithm.
Changed hardcoded checksum value in ooxmlimport unit test (testN777345).
Change-Id: I16bb985a14866775efda49e21fe033ff64645896
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/Package_opengl.mk | 1 | ||||
-rw-r--r-- | vcl/inc/checksum.hxx | 154 | ||||
-rw-r--r-- | vcl/inc/impbmp.hxx | 7 | ||||
-rw-r--r-- | vcl/inc/opengl/program.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/opengl/salbmp.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/salbmp.hxx | 51 | ||||
-rw-r--r-- | vcl/opengl/areaHashCRC64TFragmentShader.glsl | 87 | ||||
-rw-r--r-- | vcl/opengl/program.cxx | 2 | ||||
-rw-r--r-- | vcl/opengl/salbmp.cxx | 90 | ||||
-rw-r--r-- | vcl/source/bitmap/checksum.cxx | 51 | ||||
-rw-r--r-- | vcl/source/gdi/bitmap.cxx | 50 | ||||
-rw-r--r-- | vcl/source/gdi/impbmp.cxx | 27 | ||||
-rw-r--r-- | vcl/unx/gtk/app/gtkinst.cxx | 2 |
14 files changed, 468 insertions, 60 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 306178c4e794..faa8f43c2f50 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -318,6 +318,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/bitmap/bitmapscalesuper \ vcl/source/bitmap/BitmapSymmetryCheck \ vcl/source/bitmap/BitmapFilterStackBlur \ + vcl/source/bitmap/checksum \ vcl/source/helper/canvasbitmap \ vcl/source/helper/canvastools \ vcl/source/helper/evntpost \ diff --git a/vcl/Package_opengl.mk b/vcl/Package_opengl.mk index 2628dcd5d0bb..df3520c8483f 100644 --- a/vcl/Package_opengl.mk +++ b/vcl/Package_opengl.mk @@ -10,6 +10,7 @@ $(eval $(call gb_Package_Package,vcl_opengl_shader,$(SRCDIR)/vcl/opengl)) $(eval $(call gb_Package_add_files,vcl_opengl_shader,$(LIBO_ETC_FOLDER)/opengl,\ + areaHashCRC64TFragmentShader.glsl \ areaScaleFastFragmentShader.glsl \ areaScaleFragmentShader.glsl \ blendedTextureFragmentShader.glsl \ diff --git a/vcl/inc/checksum.hxx b/vcl/inc/checksum.hxx new file mode 100644 index 000000000000..ae7c9d6f7ba4 --- /dev/null +++ b/vcl/inc/checksum.hxx @@ -0,0 +1,154 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#ifndef INCLUDED_VCL_INC_CHECKSUM_HXX +#define INCLUDED_VCL_INC_CHECKSUM_HXX + +#include <sal/config.h> + +#include <sal/saldllapi.h> +#include <sal/types.h> + +/*======================================================================== + * + * vcl_crc64Table (CRC polynomial 0x95AC9329AC4BC9B5ULL). + * + *======================================================================*/ +static const sal_uInt64 vcl_crc64Table[256] = { + 0x0000000000000000ULL, 0x7ad870c830358979ULL, 0xf5b0e190606b12f2ULL, + 0x8f689158505e9b8bULL, 0xc038e5739841b68fULL, 0xbae095bba8743ff6ULL, + 0x358804e3f82aa47dULL, 0x4f50742bc81f2d04ULL, 0xab28ecb46814fe75ULL, + 0xd1f09c7c5821770cULL, 0x5e980d24087fec87ULL, 0x24407dec384a65feULL, + 0x6b1009c7f05548faULL, 0x11c8790fc060c183ULL, 0x9ea0e857903e5a08ULL, + 0xe478989fa00bd371ULL, 0x7d08ff3b88be6f81ULL, 0x07d08ff3b88be6f8ULL, + 0x88b81eabe8d57d73ULL, 0xf2606e63d8e0f40aULL, 0xbd301a4810ffd90eULL, + 0xc7e86a8020ca5077ULL, 0x4880fbd87094cbfcULL, 0x32588b1040a14285ULL, + 0xd620138fe0aa91f4ULL, 0xacf86347d09f188dULL, 0x2390f21f80c18306ULL, + 0x594882d7b0f40a7fULL, 0x1618f6fc78eb277bULL, 0x6cc0863448deae02ULL, + 0xe3a8176c18803589ULL, 0x997067a428b5bcf0ULL, 0xfa11fe77117cdf02ULL, + 0x80c98ebf2149567bULL, 0x0fa11fe77117cdf0ULL, 0x75796f2f41224489ULL, + 0x3a291b04893d698dULL, 0x40f16bccb908e0f4ULL, 0xcf99fa94e9567b7fULL, + 0xb5418a5cd963f206ULL, 0x513912c379682177ULL, 0x2be1620b495da80eULL, + 0xa489f35319033385ULL, 0xde51839b2936bafcULL, 0x9101f7b0e12997f8ULL, + 0xebd98778d11c1e81ULL, 0x64b116208142850aULL, 0x1e6966e8b1770c73ULL, + 0x8719014c99c2b083ULL, 0xfdc17184a9f739faULL, 0x72a9e0dcf9a9a271ULL, + 0x08719014c99c2b08ULL, 0x4721e43f0183060cULL, 0x3df994f731b68f75ULL, + 0xb29105af61e814feULL, 0xc849756751dd9d87ULL, 0x2c31edf8f1d64ef6ULL, + 0x56e99d30c1e3c78fULL, 0xd9810c6891bd5c04ULL, 0xa3597ca0a188d57dULL, + 0xec09088b6997f879ULL, 0x96d1784359a27100ULL, 0x19b9e91b09fcea8bULL, + 0x636199d339c963f2ULL, 0xdf7adabd7a6e2d6fULL, 0xa5a2aa754a5ba416ULL, + 0x2aca3b2d1a053f9dULL, 0x50124be52a30b6e4ULL, 0x1f423fcee22f9be0ULL, + 0x659a4f06d21a1299ULL, 0xeaf2de5e82448912ULL, 0x902aae96b271006bULL, + 0x74523609127ad31aULL, 0x0e8a46c1224f5a63ULL, 0x81e2d7997211c1e8ULL, + 0xfb3aa75142244891ULL, 0xb46ad37a8a3b6595ULL, 0xceb2a3b2ba0eececULL, + 0x41da32eaea507767ULL, 0x3b024222da65fe1eULL, 0xa2722586f2d042eeULL, + 0xd8aa554ec2e5cb97ULL, 0x57c2c41692bb501cULL, 0x2d1ab4dea28ed965ULL, + 0x624ac0f56a91f461ULL, 0x1892b03d5aa47d18ULL, 0x97fa21650afae693ULL, + 0xed2251ad3acf6feaULL, 0x095ac9329ac4bc9bULL, 0x7382b9faaaf135e2ULL, + 0xfcea28a2faafae69ULL, 0x8632586aca9a2710ULL, 0xc9622c4102850a14ULL, + 0xb3ba5c8932b0836dULL, 0x3cd2cdd162ee18e6ULL, 0x460abd1952db919fULL, + 0x256b24ca6b12f26dULL, 0x5fb354025b277b14ULL, 0xd0dbc55a0b79e09fULL, + 0xaa03b5923b4c69e6ULL, 0xe553c1b9f35344e2ULL, 0x9f8bb171c366cd9bULL, + 0x10e3202993385610ULL, 0x6a3b50e1a30ddf69ULL, 0x8e43c87e03060c18ULL, + 0xf49bb8b633338561ULL, 0x7bf329ee636d1eeaULL, 0x012b592653589793ULL, + 0x4e7b2d0d9b47ba97ULL, 0x34a35dc5ab7233eeULL, 0xbbcbcc9dfb2ca865ULL, + 0xc113bc55cb19211cULL, 0x5863dbf1e3ac9decULL, 0x22bbab39d3991495ULL, + 0xadd33a6183c78f1eULL, 0xd70b4aa9b3f20667ULL, 0x985b3e827bed2b63ULL, + 0xe2834e4a4bd8a21aULL, 0x6debdf121b863991ULL, 0x1733afda2bb3b0e8ULL, + 0xf34b37458bb86399ULL, 0x8993478dbb8deae0ULL, 0x06fbd6d5ebd3716bULL, + 0x7c23a61ddbe6f812ULL, 0x3373d23613f9d516ULL, 0x49aba2fe23cc5c6fULL, + 0xc6c333a67392c7e4ULL, 0xbc1b436e43a74e9dULL, 0x95ac9329ac4bc9b5ULL, + 0xef74e3e19c7e40ccULL, 0x601c72b9cc20db47ULL, 0x1ac40271fc15523eULL, + 0x5594765a340a7f3aULL, 0x2f4c0692043ff643ULL, 0xa02497ca54616dc8ULL, + 0xdafce7026454e4b1ULL, 0x3e847f9dc45f37c0ULL, 0x445c0f55f46abeb9ULL, + 0xcb349e0da4342532ULL, 0xb1eceec59401ac4bULL, 0xfebc9aee5c1e814fULL, + 0x8464ea266c2b0836ULL, 0x0b0c7b7e3c7593bdULL, 0x71d40bb60c401ac4ULL, + 0xe8a46c1224f5a634ULL, 0x927c1cda14c02f4dULL, 0x1d148d82449eb4c6ULL, + 0x67ccfd4a74ab3dbfULL, 0x289c8961bcb410bbULL, 0x5244f9a98c8199c2ULL, + 0xdd2c68f1dcdf0249ULL, 0xa7f41839ecea8b30ULL, 0x438c80a64ce15841ULL, + 0x3954f06e7cd4d138ULL, 0xb63c61362c8a4ab3ULL, 0xcce411fe1cbfc3caULL, + 0x83b465d5d4a0eeceULL, 0xf96c151de49567b7ULL, 0x76048445b4cbfc3cULL, + 0x0cdcf48d84fe7545ULL, 0x6fbd6d5ebd3716b7ULL, 0x15651d968d029fceULL, + 0x9a0d8ccedd5c0445ULL, 0xe0d5fc06ed698d3cULL, 0xaf85882d2576a038ULL, + 0xd55df8e515432941ULL, 0x5a3569bd451db2caULL, 0x20ed197575283bb3ULL, + 0xc49581ead523e8c2ULL, 0xbe4df122e51661bbULL, 0x3125607ab548fa30ULL, + 0x4bfd10b2857d7349ULL, 0x04ad64994d625e4dULL, 0x7e7514517d57d734ULL, + 0xf11d85092d094cbfULL, 0x8bc5f5c11d3cc5c6ULL, 0x12b5926535897936ULL, + 0x686de2ad05bcf04fULL, 0xe70573f555e26bc4ULL, 0x9ddd033d65d7e2bdULL, + 0xd28d7716adc8cfb9ULL, 0xa85507de9dfd46c0ULL, 0x273d9686cda3dd4bULL, + 0x5de5e64efd965432ULL, 0xb99d7ed15d9d8743ULL, 0xc3450e196da80e3aULL, + 0x4c2d9f413df695b1ULL, 0x36f5ef890dc31cc8ULL, 0x79a59ba2c5dc31ccULL, + 0x037deb6af5e9b8b5ULL, 0x8c157a32a5b7233eULL, 0xf6cd0afa9582aa47ULL, + 0x4ad64994d625e4daULL, 0x300e395ce6106da3ULL, 0xbf66a804b64ef628ULL, + 0xc5bed8cc867b7f51ULL, 0x8aeeace74e645255ULL, 0xf036dc2f7e51db2cULL, + 0x7f5e4d772e0f40a7ULL, 0x05863dbf1e3ac9deULL, 0xe1fea520be311aafULL, + 0x9b26d5e88e0493d6ULL, 0x144e44b0de5a085dULL, 0x6e963478ee6f8124ULL, + 0x21c640532670ac20ULL, 0x5b1e309b16452559ULL, 0xd476a1c3461bbed2ULL, + 0xaeaed10b762e37abULL, 0x37deb6af5e9b8b5bULL, 0x4d06c6676eae0222ULL, + 0xc26e573f3ef099a9ULL, 0xb8b627f70ec510d0ULL, 0xf7e653dcc6da3dd4ULL, + 0x8d3e2314f6efb4adULL, 0x0256b24ca6b12f26ULL, 0x788ec2849684a65fULL, + 0x9cf65a1b368f752eULL, 0xe62e2ad306bafc57ULL, 0x6946bb8b56e467dcULL, + 0x139ecb4366d1eea5ULL, 0x5ccebf68aecec3a1ULL, 0x2616cfa09efb4ad8ULL, + 0xa97e5ef8cea5d153ULL, 0xd3a62e30fe90582aULL, 0xb0c7b7e3c7593bd8ULL, + 0xca1fc72bf76cb2a1ULL, 0x45775673a732292aULL, 0x3faf26bb9707a053ULL, + 0x70ff52905f188d57ULL, 0x0a2722586f2d042eULL, 0x854fb3003f739fa5ULL, + 0xff97c3c80f4616dcULL, 0x1bef5b57af4dc5adULL, 0x61372b9f9f784cd4ULL, + 0xee5fbac7cf26d75fULL, 0x9487ca0fff135e26ULL, 0xdbd7be24370c7322ULL, + 0xa10fceec0739fa5bULL, 0x2e675fb4576761d0ULL, 0x54bf2f7c6752e8a9ULL, + 0xcdcf48d84fe75459ULL, 0xb71738107fd2dd20ULL, 0x387fa9482f8c46abULL, + 0x42a7d9801fb9cfd2ULL, 0x0df7adabd7a6e2d6ULL, 0x772fdd63e7936bafULL, + 0xf8474c3bb7cdf024ULL, 0x829f3cf387f8795dULL, 0x66e7a46c27f3aa2cULL, + 0x1c3fd4a417c62355ULL, 0x935745fc4798b8deULL, 0xe98f353477ad31a7ULL, + 0xa6df411fbfb21ca3ULL, 0xdc0731d78f8795daULL, 0x536fa08fdfd90e51ULL, + 0x29b7d047efec8728ULL +}; + +#ifdef __cplusplus +extern "C" { +#endif + +/*======================================================================== + * + * vcl_crc64 interface. + * + *======================================================================*/ +/** Evaluate CRC64 over given data. + + This function evaluates the CRC polynomial 0xEDB88320. + + @param Crc [in] CRC64 over previous data or zero. + @param Data [in] data buffer. + @param DatLen [in] data buffer length. + @return new CRC64 value. + */ +SAL_DLLPUBLIC sal_uInt64 SAL_CALL vcl_crc64 ( + sal_uInt64 Crc, + const void *Data, sal_uInt32 DatLen +) SAL_THROW_EXTERN_C(); + + +#ifdef __cplusplus +} +#endif + + +#endif // INCLUDED_VCL_INC_CHECKSUM_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/impbmp.hxx b/vcl/inc/impbmp.hxx index 412dcecda242..9dd483a8a7f1 100644 --- a/vcl/inc/impbmp.hxx +++ b/vcl/inc/impbmp.hxx @@ -40,7 +40,6 @@ class ImpBitmap { private: sal_uLong mnRefCount; - sal_uInt32 mnChecksum; SalBitmap* mpSalBitmap; public: @@ -51,6 +50,8 @@ public: ImpBitmap(SalBitmap* pBitmap); ~ImpBitmap(); + bool ImplIsEqual(const ImpBitmap& rBmp) const; + SalBitmap* ImplGetSalBitmap() const { return mpSalBitmap; } bool ImplCreate( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal ); @@ -68,8 +69,8 @@ public: void ImplIncRefCount() { mnRefCount++; } void ImplDecRefCount() { mnRefCount--; } - inline void ImplSetChecksum( sal_uInt32 nChecksum ) { mnChecksum = nChecksum; } - inline sal_uInt32 ImplGetChecksum() const { return mnChecksum; } + sal_uLong ImplGetChecksum() const; + void ImplInvalidateChecksum(); bool ImplScale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ); bool ImplReplace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol ); diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx index 8289a56de4bf..7bdd43d3d51c 100644 --- a/vcl/inc/opengl/program.hxx +++ b/vcl/inc/opengl/program.hxx @@ -76,7 +76,7 @@ public: void ApplyMatrix(float fWidth, float fHeight, float fPixelOffset = 0.0f); - bool DrawTexture( OpenGLTexture& rTexture ); + bool DrawTexture( const OpenGLTexture& rTexture ); protected: void SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData ); diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx index 8baee941f1a4..b33d69f6e0e1 100644 --- a/vcl/inc/opengl/salbmp.hxx +++ b/vcl/inc/opengl/salbmp.hxx @@ -53,6 +53,9 @@ private: std::deque< OpenGLSalBitmapOp* > maPendingOps; void makeCurrent(); + virtual void updateChecksum() const; + + bool calcChecksumGL(OpenGLTexture& rHashTexture, ChecksumType& rHash) const; public: OpenGLSalBitmap(); diff --git a/vcl/inc/salbmp.hxx b/vcl/inc/salbmp.hxx index 91f69aeb2bdc..268e06cc384c 100644 --- a/vcl/inc/salbmp.hxx +++ b/vcl/inc/salbmp.hxx @@ -25,6 +25,8 @@ #include <vcl/dllapi.h> #include <vcl/salbtype.hxx> +#include <checksum.hxx> + #include <com/sun/star/rendering/XBitmapCanvas.hpp> struct BitmapBuffer; @@ -37,8 +39,11 @@ enum class BmpScaleFlag; class VCL_PLUGIN_PUBLIC SalBitmap { public: - SalBitmap() {} - virtual ~SalBitmap(); + + typedef sal_uInt64 ChecksumType; + + SalBitmap() : mbChecksumValid(false) {} + virtual ~SalBitmap(); virtual bool Create( const Size& rSize, sal_uInt16 nBitCount, @@ -61,6 +66,48 @@ 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 GetChecksum(ChecksumType& rChecksum) const + { + updateChecksum(); + assert(mbChecksumValid); + rChecksum = maChecksum; + return mbChecksumValid; + } + + virtual void InvalidateChecksum() + { + mbChecksumValid = false; + } + +protected: + ChecksumType maChecksum; + bool mbChecksumValid; + +protected: + virtual void updateChecksum() const + { + if (mbChecksumValid) + return; + + ChecksumType nCrc = 0; + SalBitmap* pThis = const_cast<SalBitmap*>(this); + BitmapBuffer* pBuf = pThis->AcquireBuffer(BITMAP_READ_ACCESS); + if (pBuf) + { + pThis->ReleaseBuffer(pBuf, BITMAP_READ_ACCESS); + nCrc = vcl_crc64(0, pBuf->mpBits, pBuf->mnScanlineSize * pBuf->mnHeight); + pThis->maChecksum = nCrc; + pThis->mbChecksumValid = true; + } + else + { + pThis->mbChecksumValid = false; + } + } + + }; #endif diff --git a/vcl/opengl/areaHashCRC64TFragmentShader.glsl b/vcl/opengl/areaHashCRC64TFragmentShader.glsl new file mode 100644 index 000000000000..901b481d8081 --- /dev/null +++ b/vcl/opengl/areaHashCRC64TFragmentShader.glsl @@ -0,0 +1,87 @@ +/* -*- 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/. + */ + +/* TODO Use textureOffset for newest version of GLSL */ + + +#version 130 + +uniform sampler2D crc_table; +uniform sampler2D sampler; +uniform float xstep; +uniform float ystep; + +varying vec2 tex_coord; + +const int scale = 4; +const float ratio = 16.0; + + +ivec2 crc64( ivec2 hval, int color ) +{ + int dx = 2 * ((hval[0] ^ color) & 0xff); + float s = dx / 255.0; + vec4 table_value_lo = round(texture2D( crc_table, vec2( s, 0.0 ) ) * 255.0); + s = (dx+1) / 255.0; + vec4 table_value_hi = round(texture2D( crc_table, vec2( s, 0.0 ) ) * 255.0); + + int tvalue_lo = int(table_value_lo[0]) | (int(table_value_lo[1]) << 8) | (int(table_value_lo[2]) << 16) | (int(table_value_lo[3]) << 24); + int tvalue_hi = int(table_value_hi[0]) | (int(table_value_hi[1]) << 8) | (int(table_value_hi[2]) << 16) | (int(table_value_hi[3]) << 24); + + hval[1] = tvalue_hi ^ (hval[1] >> 8); + hval[0] = tvalue_lo ^ ( (hval[1] << 24) | (hval[0] >> 8) ); + + return hval; +} + + +void main(void) +{ + ivec2 Crc = ivec2( 0xffffffff, 0xffffffff ); + vec2 offset = vec2( 0.0, 0.0 ); + vec2 next_coord = tex_coord.st; + for( int y = 0; y < scale && next_coord.y <= 1.0; ++y ) + { + for( int x = 0; x < scale && next_coord.x <= 1.0; ++x ) + { + vec4 pixel = round(texture2D( sampler, next_coord ) * 255.0); + + int r = int(pixel.r); // 0..255 + int g = int(pixel.g); // 0..255 + int b = int(pixel.b); // 0..255 + int a = int(pixel.a); // 0..255 + + Crc = crc64( Crc, r ); + Crc = crc64( Crc, g ); + Crc = crc64( Crc, b ); + Crc = crc64( Crc, a ); + + offset.x += xstep; + next_coord = tex_coord.st + offset; + } + offset.y += ystep; + offset.x = 0.0; + next_coord = tex_coord.st + offset; + } + + Crc[0] = ~Crc[0]; + Crc[1] = ~Crc[1]; + + int Hash = Crc[0] ^ Crc[1]; + + float fr = ( Hash & 0xff) / 255.0; + float fg = ((Hash >> 8) & 0xff) / 255.0; + float fb = ((Hash >> 16) & 0xff) / 255.0; + float fa = ((Hash >> 24) & 0xff) / 255.0; + + + gl_FragColor = vec4(fr, fg, fb, fa); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/opengl/program.cxx b/vcl/opengl/program.cxx index b1d3cfe8291d..eec4e92bad98 100644 --- a/vcl/opengl/program.cxx +++ b/vcl/opengl/program.cxx @@ -276,7 +276,7 @@ void OpenGLProgram::SetBlendMode( GLenum nSFactor, GLenum nDFactor ) mbBlending = true; } -bool OpenGLProgram::DrawTexture( OpenGLTexture& rTexture ) +bool OpenGLProgram::DrawTexture( const OpenGLTexture& rTexture ) { if (!rTexture) return false; diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx index d6e51d9bfd72..8ab721e25f6c 100644 --- a/vcl/opengl/salbmp.cxx +++ b/vcl/opengl/salbmp.cxx @@ -31,6 +31,7 @@ #include "opengl/program.hxx" #include "opengl/salbmp.hxx" +#include "../inc/checksum.hxx" #include "opengl/FixedTextureAtlas.hxx" namespace @@ -508,6 +509,94 @@ sal_uInt16 OpenGLSalBitmap::GetBitCount() const return mnBits; } +bool OpenGLSalBitmap::calcChecksumGL(OpenGLTexture& rInputTexture, ChecksumType& rChecksum) const +{ + OUString FragShader("areaHashCRC64TFragmentShader"); + + static const OpenGLTexture aCRCTableTexture(512, 1, GL_RGBA, GL_UNSIGNED_BYTE, + (sal_uInt8*)(vcl_crc64Table)); + + // First Pass + + int nWidth = rInputTexture.GetWidth(); + int nHeight = rInputTexture.GetHeight(); + + OpenGLProgram* pProgram = mpContext->UseProgram("textureVertexShader", FragShader); + if (pProgram == 0) + return false; + + int nNewWidth = ceil( nWidth / 4.0 ); + int nNewHeight = ceil( nHeight / 4.0 ); + + OpenGLTexture aFirstPassTexture = OpenGLTexture(nNewWidth, nNewHeight); + OpenGLFramebuffer* pFramebuffer = mpContext->AcquireFramebuffer(aFirstPassTexture); + + pProgram->SetUniform1f( "xstep", 1.0 / mnWidth ); + pProgram->SetUniform1f( "ystep", 1.0 / mnHeight ); + + pProgram->SetTexture("crc_table", (OpenGLTexture&)(aCRCTableTexture)); + pProgram->SetTexture("sampler", rInputTexture); + pProgram->DrawTexture(rInputTexture); + pProgram->Clean(); + + OpenGLContext::ReleaseFramebuffer(pFramebuffer); + + CHECK_GL_ERROR(); + + + // Second Pass + + nWidth = aFirstPassTexture.GetWidth(); + nHeight = aFirstPassTexture.GetHeight(); + + pProgram = mpContext->UseProgram("textureVertexShader", FragShader); + if (pProgram == 0) + return false; + + nNewWidth = ceil( nWidth / 4.0 ); + nNewHeight = ceil( nHeight / 4.0 ); + + OpenGLTexture aSecondPassTexture = OpenGLTexture(nNewWidth, nNewHeight); + pFramebuffer = mpContext->AcquireFramebuffer(aSecondPassTexture); + + pProgram->SetUniform1f( "xstep", 1.0 / mnWidth ); + pProgram->SetUniform1f( "ystep", 1.0 / mnHeight ); + + pProgram->SetTexture("crc_table", (OpenGLTexture&)(aCRCTableTexture)); + pProgram->SetTexture("sampler", aFirstPassTexture); + pProgram->DrawTexture(aFirstPassTexture); + pProgram->Clean(); + + OpenGLContext::ReleaseFramebuffer(pFramebuffer); + + CHECK_GL_ERROR(); + + // Final CRC on CPU + OpenGLTexture& aFinalTexture = aSecondPassTexture; + std::vector<sal_uInt8> aBuf( aFinalTexture.GetWidth() * aFinalTexture.GetHeight() * 4 ); + aFinalTexture.Read(GL_RGBA, GL_UNSIGNED_BYTE, aBuf.data()); + + ChecksumType nCrc = vcl_crc64(0, aBuf.data(), aBuf.size()); + + rChecksum = nCrc; + return true; +} + +void OpenGLSalBitmap::updateChecksum() const +{ + if (mbChecksumValid) + return; + + OpenGLSalBitmap* pThis = const_cast<OpenGLSalBitmap*>(this); + + if (!mpContext) + { + pThis->CreateTexture(); + } + + pThis->mbChecksumValid = calcChecksumGL(pThis->maTexture, pThis->maChecksum); +} + OpenGLContext* OpenGLSalBitmap::GetBitmapContext() { return ImplGetDefaultWindow()->GetGraphics()->GetOpenGLContext(); @@ -581,6 +670,7 @@ void OpenGLSalBitmap::ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMo { maTexture = OpenGLTexture(); mbDirtyTexture = true; + mbChecksumValid = false; } // The palette is modified on read during the BitmapWriteAccess, // but of course, often it is not modified; interesting. diff --git a/vcl/source/bitmap/checksum.cxx b/vcl/source/bitmap/checksum.cxx new file mode 100644 index 000000000000..a46db1e75265 --- /dev/null +++ b/vcl/source/bitmap/checksum.cxx @@ -0,0 +1,51 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/types.h> +#include <checksum.hxx> + +/*======================================================================== + * + * vcl_crc64 implementation. + * + *======================================================================*/ +#define UPDCRC64(crc, octet) \ + (vcl_crc64Table[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8)) + +/* + * rtl_crc64. + */ +sal_uInt64 SAL_CALL vcl_crc64 ( + sal_uInt64 Crc, + const void *Data, sal_uInt32 DatLen) SAL_THROW_EXTERN_C() +{ + if (Data) + { + const sal_uInt8 *p = static_cast<const sal_uInt8 *>(Data); + const sal_uInt8 *q = p + DatLen; + + Crc = ~Crc; + while (p < q) + Crc = UPDCRC64(Crc, *(p++)); + Crc = ~Crc; + } + return Crc; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/bitmap.cxx b/vcl/source/gdi/bitmap.cxx index 9a69eb0f8af1..6f96c050685d 100644 --- a/vcl/source/gdi/bitmap.cxx +++ b/vcl/source/gdi/bitmap.cxx @@ -245,10 +245,8 @@ Bitmap& Bitmap::operator=( const Bitmap& rBitmap ) bool Bitmap::IsEqual( const Bitmap& rBmp ) const { - return( IsSameInstance( rBmp ) || - ( rBmp.GetSizePixel() == GetSizePixel() && - rBmp.GetBitCount() == GetBitCount() && - rBmp.GetChecksum() == GetChecksum() ) ); + return(IsSameInstance(rBmp) || // Includes both are nullptr + (rBmp.mpImpBmp && mpImpBmp && mpImpBmp->ImplIsEqual(*rBmp.mpImpBmp))); } void Bitmap::SetEmpty() @@ -293,49 +291,6 @@ sal_uInt32 Bitmap::GetChecksum() const if( mpImpBmp ) { nRet = mpImpBmp->ImplGetChecksum(); - - if( !nRet ) - { - BitmapReadAccess* pRAcc = const_cast<Bitmap*>(this)->AcquireReadAccess(); - - if( pRAcc && pRAcc->Width() && pRAcc->Height() ) - { - sal_uInt32 nCrc = 0; - SVBT32 aBT32; - - pRAcc->ImplZeroInitUnusedBits(); - - UInt32ToSVBT32( pRAcc->Width(), aBT32 ); - nCrc = rtl_crc32( nCrc, aBT32, 4 ); - - UInt32ToSVBT32( pRAcc->Height(), aBT32 ); - nCrc = rtl_crc32( nCrc, aBT32, 4 ); - - UInt32ToSVBT32( pRAcc->GetBitCount(), aBT32 ); - nCrc = rtl_crc32( nCrc, aBT32, 4 ); - - UInt32ToSVBT32( pRAcc->GetColorMask().GetRedMask(), aBT32 ); - nCrc = rtl_crc32( nCrc, aBT32, 4 ); - - UInt32ToSVBT32( pRAcc->GetColorMask().GetGreenMask(), aBT32 ); - nCrc = rtl_crc32( nCrc, aBT32, 4 ); - - UInt32ToSVBT32( pRAcc->GetColorMask().GetBlueMask(), aBT32 ); - nCrc = rtl_crc32( nCrc, aBT32, 4 ); - - if( pRAcc->HasPalette() ) - { - nCrc = rtl_crc32( nCrc, pRAcc->GetPalette().ImplGetColorBuffer(), - pRAcc->GetPaletteEntryCount() * sizeof( BitmapColor ) ); - } - - nRet = rtl_crc32( nCrc, pRAcc->GetBuffer(), pRAcc->GetScanlineSize() * pRAcc->Height() ); - - mpImpBmp->ImplSetChecksum( nRet ); - } - - if (pRAcc) ReleaseAccess( pRAcc ); - } } return nRet; @@ -549,6 +504,7 @@ bool Bitmap::Invert() pAcc->SetPixel( nY, nX, pAcc->GetPixel( nY, nX ).Invert() ); } + mpImpBmp->ImplInvalidateChecksum(); ReleaseAccess( pAcc ); bRet = true; } diff --git a/vcl/source/gdi/impbmp.cxx b/vcl/source/gdi/impbmp.cxx index 298bfaa1cd0f..f70012202b07 100644 --- a/vcl/source/gdi/impbmp.cxx +++ b/vcl/source/gdi/impbmp.cxx @@ -26,14 +26,12 @@ ImpBitmap::ImpBitmap() : mnRefCount ( 1 ), - mnChecksum ( 0 ), mpSalBitmap ( ImplGetSVData()->mpDefInst->CreateSalBitmap() ) { } ImpBitmap::ImpBitmap(SalBitmap* pBitmap) : mnRefCount ( 1 ), - mnChecksum ( 0 ), mpSalBitmap ( pBitmap ) { } @@ -43,14 +41,20 @@ ImpBitmap::~ImpBitmap() delete mpSalBitmap; } -bool ImpBitmap::ImplCreate( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal ) +bool ImpBitmap::ImplIsEqual(const ImpBitmap& rBmp) const +{ + return (rBmp.ImplGetSize() == ImplGetSize() && + rBmp.ImplGetBitCount() == ImplGetBitCount() && + rBmp.ImplGetChecksum() == ImplGetChecksum()); +} + +bool ImpBitmap::ImplCreate(const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal) { return mpSalBitmap->Create( rSize, nBitCount, rPal ); } bool ImpBitmap::ImplCreate( const ImpBitmap& rImpBitmap ) { - mnChecksum = rImpBitmap.mnChecksum; return mpSalBitmap->Create( *rImpBitmap.mpSalBitmap ); } @@ -85,7 +89,20 @@ void ImpBitmap::ImplReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode mpSalBitmap->ReleaseBuffer( pBuffer, nMode ); if( nMode == BITMAP_WRITE_ACCESS ) - mnChecksum = 0; + ImplInvalidateChecksum(); +} + +sal_uLong ImpBitmap::ImplGetChecksum() const +{ + SalBitmap::ChecksumType aChecksum; + mpSalBitmap->GetChecksum(aChecksum); + sal_uLong a32BitChecksum = aChecksum; + return a32BitChecksum; +} + +void ImpBitmap::ImplInvalidateChecksum() +{ + mpSalBitmap->InvalidateChecksum(); } bool ImpBitmap::ImplScale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) diff --git a/vcl/unx/gtk/app/gtkinst.cxx b/vcl/unx/gtk/app/gtkinst.cxx index 53582c7e5b02..cbdbc6ece609 100644 --- a/vcl/unx/gtk/app/gtkinst.cxx +++ b/vcl/unx/gtk/app/gtkinst.cxx @@ -338,7 +338,7 @@ SalBitmap* GtkInstance::CreateSalBitmap() { EnsureInit(); #if GTK_CHECK_VERSION(3,0,0) - return new SvpSalBitmap(); + return SvpSalInstance::CreateSalBitmap();//new SvpSalBitmap(); #else return X11SalInstance::CreateSalBitmap(); #endif |