[Libreoffice-commits] online.git: loolwsd/bundled loolwsd/LOKitClient.cpp loolwsd/LOOLSession.cpp loolwsd/Util.cpp loolwsd/Util.hpp

Miklos Vajna vmiklos at collabora.co.uk
Tue Nov 24 00:20:02 PST 2015


 loolwsd/LOKitClient.cpp                                      |    3 +-
 loolwsd/LOOLSession.cpp                                      |    3 +-
 loolwsd/Util.cpp                                             |   15 +++++++++--
 loolwsd/Util.hpp                                             |    5 ++-
 loolwsd/bundled/include/LibreOfficeKit/LibreOfficeKitEnums.h |    2 -
 5 files changed, 22 insertions(+), 6 deletions(-)

New commits:
commit 195aa3a953bc5b4d9cf681fe84742d69c8ad78d5
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 24 09:19:17 2015 +0100

    loolwsd: use png_set_write_user_transform_fn() only for BGRA pixel format

diff --git a/loolwsd/LOKitClient.cpp b/loolwsd/LOKitClient.cpp
index 6f2f016..afbc62d 100644
--- a/loolwsd/LOKitClient.cpp
+++ b/loolwsd/LOKitClient.cpp
@@ -166,7 +166,8 @@ protected:
                     continue;
 
                 std::vector<char> png;
-                Util::encodePNGAndAppendToBuffer(pixmap.data(), canvasWidth, canvasHeight, png);
+                LibreOfficeKitTileMode mode = static_cast<LibreOfficeKitTileMode>(loKitDocument->pClass->getTileMode(loKitDocument));
+                Util::encodePNGAndAppendToBuffer(pixmap.data(), canvasWidth, canvasHeight, png, mode);
 
                 TemporaryFile pngFile;
                 std::ofstream pngStream(pngFile.path(), std::ios::binary);
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 9f64f81..ff15806 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -1108,7 +1108,8 @@ void ChildProcessSession::sendTile(const char* /*buffer*/, int /*length*/, Strin
     _loKitDocument->pClass->paintTile(_loKitDocument, pixmap, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
     std::cout << Util::logPrefix() << "paintTile called, tile at [" << tilePosX << ", " << tilePosY << "] rendered in " << double(timestamp.elapsed())/1000 <<  "ms" << std::endl;
 
-    if (!Util::encodePNGAndAppendToBuffer(pixmap, width, height, output))
+    LibreOfficeKitTileMode mode = static_cast<LibreOfficeKitTileMode>(_loKitDocument->pClass->getTileMode(_loKitDocument));
+    if (!Util::encodePNGAndAppendToBuffer(pixmap, width, height, output, mode))
     {
         sendTextFrame("error: cmd=tile kind=failure");
         return;
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 1b42d86..232e425 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -12,6 +12,7 @@
 #include <iomanip>
 #include <sstream>
 #include <string>
+#include <cassert>
 
 #include <png.h>
 
@@ -81,7 +82,7 @@ namespace Util
         return false;
     }
 
-    bool encodePNGAndAppendToBuffer(unsigned char *pixmap, int width, int height, std::vector<char>& output)
+    bool encodePNGAndAppendToBuffer(unsigned char *pixmap, int width, int height, std::vector<char>& output, LibreOfficeKitTileMode mode)
     {
         png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 
@@ -100,7 +101,17 @@ namespace Util
 
         png_write_info(png_ptr, info_ptr);
 
-        png_set_write_user_transform_fn (png_ptr, unpremultiply_data);
+        switch (mode)
+        {
+        case LOK_TILEMODE_RGBA:
+            break;
+        case LOK_TILEMODE_BGRA:
+            png_set_write_user_transform_fn (png_ptr, unpremultiply_data);
+            break;
+        default:
+            assert(false);
+        }
+
         for (int y = 0; y < height; ++y)
             png_write_row(png_ptr, pixmap + y * width * 4);
 
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 64e48d0..02a21d6 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -14,6 +14,9 @@
 
 #include <Poco/Net/WebSocket.h>
 
+#define LOK_USE_UNSTABLE_API
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+
 namespace Util
 {
     std::string logPrefix();
@@ -22,7 +25,7 @@ namespace Util
 
     // Sadly, older libpng headers don't use const for the pixmap pointer parameter to
     // png_write_row(), so can't use const here for pixmap.
-    bool encodePNGAndAppendToBuffer(unsigned char *pixmap, int width, int height, std::vector<char>& output);
+    bool encodePNGAndAppendToBuffer(unsigned char *pixmap, int width, int height, std::vector<char>& output, LibreOfficeKitTileMode mode);
 
     // Call WebSocket::shutdown() ignoring Poco::IOException
     void shutdownWebSocket(Poco::Net::WebSocket& ws);
diff --git a/loolwsd/bundled/include/LibreOfficeKit/LibreOfficeKitEnums.h b/loolwsd/bundled/include/LibreOfficeKit/LibreOfficeKitEnums.h
index b713f0e..a0f5e88 100644
--- a/loolwsd/bundled/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/loolwsd/bundled/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -36,7 +36,7 @@ LibreOfficeKitPartMode;
 typedef enum
 {
     LOK_TILEMODE_RGBA,
-    LOK_TILEMODE_ARGB
+    LOK_TILEMODE_BGRA
 }
 LibreOfficeKitTileMode;
 


More information about the Libreoffice-commits mailing list