Blob Blame History Raw
From e14efbfe1829ea54b5b794903282d3bf834e7e83 Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Thu, 15 Oct 2015 09:41:52 +0200
Subject: [PATCH 209/398] lok::Document::paintTile: fix non-rectangular tiles
 wrt. transparency

When copying the alpha channel, the offset was incorrect when canvas
width/height did not equal.

Change-Id: If0ab3ec7a4ad4dd958419b566fd473732965cfda
(cherry picked from commit d30f5bc3e65463f28c3087acad6f88e12d60e53b)
---
 desktop/qa/desktop_lib/test_desktop_lib.cxx | 21 +++++++++++++++++++++
 desktop/source/lib/init.cxx                 |  2 +-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 30d8ae7adaf0..c3cc748a5d61 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -61,6 +61,7 @@ public:
     void testGetFilterTypes();
     void testGetPartPageRectangles();
     void testSearchCalc();
+    void testPaintTile();
 
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
     CPPUNIT_TEST(testGetStyles);
@@ -69,6 +70,7 @@ public:
     CPPUNIT_TEST(testGetFilterTypes);
     CPPUNIT_TEST(testGetPartPageRectangles);
     CPPUNIT_TEST(testSearchCalc);
+    CPPUNIT_TEST(testPaintTile);
     CPPUNIT_TEST_SUITE_END();
 
     uno::Reference<lang::XComponent> mxComponent;
@@ -280,6 +282,25 @@ void DesktopLOKTest::testSearchCalc()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void DesktopLOKTest::testPaintTile()
+{
+    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
+    int nCanvasWidth = 100;
+    int nCanvasHeight = 300;
+    std::vector<unsigned char> aBuffer(nCanvasWidth * nCanvasHeight * 4);
+    int nTilePosX = 0;
+    int nTilePosY = 0;
+    int nTileWidth = 1000;
+    int nTileHeight = 3000;
+
+    // This used to crash: painTile() implementation did not handle
+    // nCanvasWidth != nCanvasHeight correctly, as usually both are just always
+    // 256.
+    pDocument->pClass->paintTile(pDocument, aBuffer.data(), nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+
+    closeDoc();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index b69e58a4af1f..053ab440bf55 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -788,7 +788,7 @@ void doc_paintTile (LibreOfficeKitDocument* pThis,
     {
         for (int nCol = 0; nCol < nCanvasWidth; ++nCol)
         {
-            const int nOffset = (nCanvasHeight * nRow) + nCol;
+            const int nOffset = (nCanvasWidth * nRow) + nCol;
             // VCL's transparent is 0, RGBA's transparent is 0xff.
             pBuffer[nOffset * 4 +3] = 0xff - aAlpha[nOffset];
         }
-- 
2.12.0