[Libreoffice-commits] online.git: common/Png.hpp kit/Kit.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Nov 28 05:03:36 UTC 2016
common/Png.hpp | 6 ++++++
kit/Kit.cpp | 28 ++++++++++++++++++----------
2 files changed, 24 insertions(+), 10 deletions(-)
New commits:
commit b35725ab709864ad8680cc84986d27048687c5d3
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Nov 27 11:55:19 2016 -0500
loolwsd: support more efficient full-buffer hashing
Change-Id: Ie30929ad4665b51e280c1126adde645742814dad
Reviewed-on: https://gerrit.libreoffice.org/31294
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/common/Png.hpp b/common/Png.hpp
index 96fa165..b4ff059 100644
--- a/common/Png.hpp
+++ b/common/Png.hpp
@@ -160,6 +160,12 @@ bool encodeBufferToPNG(unsigned char* pixmap, int width, int height,
}
inline
+uint64_t hashBuffer(unsigned char* pixmap, int width, int height)
+{
+ return SpookyHash::Hash64(pixmap, width * height * 4, 1073741789);
+}
+
+inline
uint64_t hashSubBuffer(unsigned char* pixmap, size_t startX, size_t startY,
int width, int height, int bufferWidth, int bufferHeight)
{
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index f070b3a..28df0d8 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -348,15 +348,9 @@ class PngCache
bool cacheEncodeSubBufferToPNG(unsigned char* pixmap, size_t startX, size_t startY,
int width, int height,
int bufferWidth, int bufferHeight,
- std::vector<char>& output, LibreOfficeKitTileMode mode)
+ std::vector<char>& output, LibreOfficeKitTileMode mode,
+ const uint64_t hash)
{
- uint64_t hash = png::hashSubBuffer(pixmap, startX, startY, width, height,
- bufferWidth, bufferHeight);
- if (cacheTest(hash, output))
- {
- return true;
- }
-
LOG_DBG("PNG cache with hash " << hash << " missed.");
CacheEntry newEntry(bufferWidth * bufferHeight * 1);
if (png::encodeSubBufferToPNG(pixmap, startX, startY, width, height,
@@ -390,16 +384,30 @@ public:
bool encodeBufferToPNG(unsigned char* pixmap, int width, int height,
std::vector<char>& output, LibreOfficeKitTileMode mode)
{
+ const uint64_t hash = png::hashBuffer(pixmap, width, height);
+ if (cacheTest(hash, output))
+ {
+ return true;
+ }
+
return cacheEncodeSubBufferToPNG(pixmap, 0, 0, width, height,
- width, height, output, mode);
+ width, height, output, mode, hash);
}
+
bool encodeSubBufferToPNG(unsigned char* pixmap, size_t startX, size_t startY,
int width, int height,
int bufferWidth, int bufferHeight,
std::vector<char>& output, LibreOfficeKitTileMode mode)
{
+ const uint64_t hash = png::hashSubBuffer(pixmap, startX, startY, width, height,
+ bufferWidth, bufferHeight);
+ if (cacheTest(hash, output))
+ {
+ return true;
+ }
+
return cacheEncodeSubBufferToPNG(pixmap, startX, startY, width, height,
- bufferWidth, bufferHeight, output, mode);
+ bufferWidth, bufferHeight, output, mode, hash);
}
};
More information about the Libreoffice-commits
mailing list