[Libreoffice-commits] core.git: Branch 'feature/nativealpha' - 7 commits - include/vcl svx/source vcl/CppunitTest_vcl_png_test.mk vcl/Library_vcl.mk vcl/Module_vcl.mk vcl/qa vcl/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Sun Jun 26 10:44:29 UTC 2016


 include/vcl/filter/PngReader.hxx                 |   40 +++++
 svx/source/dialog/dialcontrol.cxx                |    6 
 svx/source/tbxctrls/tbxcolorupdate.cxx           |   15 +
 vcl/CppunitTest_vcl_png_test.mk                  |   52 ++++++
 vcl/Library_vcl.mk                               |    2 
 vcl/Module_vcl.mk                                |    1 
 vcl/qa/cppunit/png/PngFilterTest.cxx             |  136 +++++++++++++++++
 vcl/qa/cppunit/png/data/alpha-rect-8bit-RGBA.png |binary
 vcl/qa/cppunit/png/data/color-rect-4bit-pal.png  |binary
 vcl/qa/cppunit/png/data/color-rect-8bit-RGB.png  |binary
 vcl/qa/cppunit/png/data/rect-1bit-pal.png        |binary
 vcl/source/bitmap/BitmapProcessor.cxx            |   20 ++
 vcl/source/filter/png/PngReader.cxx              |  180 +++++++++++++++++++++++
 vcl/source/gdi/bitmap3.cxx                       |    5 
 vcl/source/image/ImplImageTree.cxx               |    7 
 15 files changed, 455 insertions(+), 9 deletions(-)

New commits:
commit 7351c82c0bf3f58b1f89cade4a792750c9dad184
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Jun 26 11:31:07 2016 +0800

    vcl: Test for PngReader - reading of various PNG formats
    
    Change-Id: I2469751806e03c791c1882a32c31c090d7dac39f

diff --git a/vcl/CppunitTest_vcl_png_test.mk b/vcl/CppunitTest_vcl_png_test.mk
new file mode 100644
index 0000000..1f88209
--- /dev/null
+++ b/vcl/CppunitTest_vcl_png_test.mk
@@ -0,0 +1,52 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,vcl_png_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,vcl_png_test, \
+    vcl/qa/cppunit/png/PngFilterTest \
+))
+
+$(eval $(call gb_CppunitTest_set_include,vcl_png_test,\
+    $$(INCLUDE) \
+    -I$(SRCDIR)/vcl/inc \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,vcl_png_test, \
+	comphelper \
+	cppu \
+	cppuhelper \
+	sal \
+    svt \
+	test \
+	tl \
+	unotest \
+	vcl \
+	utl \
+	$(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,vcl_png_test,\
+    udkapi \
+    offapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,vcl_png_test))
+$(eval $(call gb_CppunitTest_use_vcl,vcl_png_test))
+
+$(eval $(call gb_CppunitTest_use_components,vcl_png_test,\
+    configmgr/source/configmgr \
+    i18npool/util/i18npool \
+    ucb/source/core/ucb1 \
+    unotools/util/utl \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,vcl_png_test))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 03c884c..a5c3f0f 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -107,6 +107,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\
 	CppunitTest_vcl_outdev \
 	CppunitTest_vcl_app_test \
 	CppunitTest_vcl_wmf_test \
+	CppunitTest_vcl_png_test \
 ))
 
 
diff --git a/vcl/qa/cppunit/png/PngFilterTest.cxx b/vcl/qa/cppunit/png/PngFilterTest.cxx
new file mode 100644
index 0000000..14e32a6
--- /dev/null
+++ b/vcl/qa/cppunit/png/PngFilterTest.cxx
@@ -0,0 +1,136 @@
+/* -*- 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 <test/bootstrapfixture.hxx>
+#include <vcl/filter/PngReader.hxx>
+#include <vcl/bitmapaccess.hxx>
+
+using namespace css;
+
+class PngFilterTest : public test::BootstrapFixture
+{
+    OUString maDataUrl;
+
+    OUString getFullUrl(const OUString& sFileName)
+    {
+        return m_directories.getURLFromSrc(maDataUrl) + sFileName;
+    }
+
+public:
+    PngFilterTest() :
+        BootstrapFixture(true, false),
+        maDataUrl("/vcl/qa/cppunit/png/data/")
+    {}
+
+    void testPng();
+
+    CPPUNIT_TEST_SUITE(PngFilterTest);
+    CPPUNIT_TEST(testPng);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void PngFilterTest::testPng()
+{
+    for (const OUString& aFileName: { OUString("rect-1bit-pal.png") })
+    {
+        SvFileStream aFileStream(getFullUrl(aFileName), StreamMode::READ);
+
+        Graphic aGraphic;
+        vcl::PngReader aPngReader(aFileStream);
+        aPngReader.Read(aGraphic);
+
+        Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap();
+        {
+            Bitmap::ScopedReadAccess pAccess(aBitmap);
+            CPPUNIT_ASSERT_EQUAL(32, int(pAccess->GetBitCount()));
+            CPPUNIT_ASSERT_EQUAL(4l, pAccess->Width());
+            CPPUNIT_ASSERT_EQUAL(4l, pAccess->Height());
+
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(0,0)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(3,3)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(3,0)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(0,3)).GetColor());
+
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00000000), Color(pAccess->GetPixel(1,1)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00000000), Color(pAccess->GetPixel(1,2)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00000000), Color(pAccess->GetPixel(2,1)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00000000), Color(pAccess->GetPixel(2,2)).GetColor());
+        }
+    }
+    for (const OUString& aFileName: { OUString("color-rect-8bit-RGB.png"), OUString("color-rect-4bit-pal.png") })
+    {
+        SvFileStream aFileStream(getFullUrl(aFileName), StreamMode::READ);
+
+        Graphic aGraphic;
+        vcl::PngReader aPngReader(aFileStream);
+        aPngReader.Read(aGraphic);
+
+        Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap();
+        {
+            Bitmap::ScopedReadAccess pAccess(aBitmap);
+            CPPUNIT_ASSERT_EQUAL(32, int(pAccess->GetBitCount()));
+            CPPUNIT_ASSERT_EQUAL(4l, pAccess->Width());
+            CPPUNIT_ASSERT_EQUAL(4l, pAccess->Height());
+
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(0,0)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(3,3)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(3,0)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(0,3)).GetColor());
+
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00FF0000), Color(pAccess->GetPixel(1,1)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x0000FF00), Color(pAccess->GetPixel(1,2)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x000000FF), Color(pAccess->GetPixel(2,1)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFF00), Color(pAccess->GetPixel(2,2)).GetColor());
+        }
+    }
+    for (const OUString& aFileName: { OUString("alpha-rect-8bit-RGBA.png") })
+    {
+        SvFileStream aFileStream(getFullUrl(aFileName), StreamMode::READ);
+
+        Graphic aGraphic;
+        vcl::PngReader aPngReader(aFileStream);
+        aPngReader.Read(aGraphic);
+
+        Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap();
+        {
+            Bitmap::ScopedReadAccess pAccess(aBitmap);
+            CPPUNIT_ASSERT_EQUAL(32, int(pAccess->GetBitCount()));
+            CPPUNIT_ASSERT_EQUAL(4l, pAccess->Width());
+            CPPUNIT_ASSERT_EQUAL(4l, pAccess->Height());
+
+            printf("%08X\n", Color(pAccess->GetPixel(1,1)).GetColor());
+
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x80FFFFFF), Color(pAccess->GetPixel(0,0)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x80FFFFFF), Color(pAccess->GetPixel(3,3)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x80FFFFFF), Color(pAccess->GetPixel(3,0)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x80FFFFFF), Color(pAccess->GetPixel(0,3)).GetColor());
+
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x40FF0000), Color(pAccess->GetPixel(1,1)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0xC000FF00), Color(pAccess->GetPixel(1,2)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0xC00000FF), Color(pAccess->GetPixel(2,1)).GetColor());
+            CPPUNIT_ASSERT_EQUAL(ColorData(0x40FFFF00), Color(pAccess->GetPixel(2,2)).GetColor());
+        }
+    }
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PngFilterTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/png/data/alpha-rect-8bit-RGBA.png b/vcl/qa/cppunit/png/data/alpha-rect-8bit-RGBA.png
new file mode 100644
index 0000000..1e90e1a
Binary files /dev/null and b/vcl/qa/cppunit/png/data/alpha-rect-8bit-RGBA.png differ
diff --git a/vcl/qa/cppunit/png/data/color-rect-4bit-pal.png b/vcl/qa/cppunit/png/data/color-rect-4bit-pal.png
new file mode 100644
index 0000000..740eede
Binary files /dev/null and b/vcl/qa/cppunit/png/data/color-rect-4bit-pal.png differ
diff --git a/vcl/qa/cppunit/png/data/color-rect-8bit-RGB.png b/vcl/qa/cppunit/png/data/color-rect-8bit-RGB.png
new file mode 100644
index 0000000..727859d
Binary files /dev/null and b/vcl/qa/cppunit/png/data/color-rect-8bit-RGB.png differ
diff --git a/vcl/qa/cppunit/png/data/rect-1bit-pal.png b/vcl/qa/cppunit/png/data/rect-1bit-pal.png
new file mode 100644
index 0000000..cf7ac3e
Binary files /dev/null and b/vcl/qa/cppunit/png/data/rect-1bit-pal.png differ
commit 2bfd5d8347170634dcce5efc06446466f0951ec6
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Jun 26 11:25:01 2016 +0800

    vcl: Support converting to 32-bit bitmap
    
    Change-Id: Ic1c252fcc23ba6b8581c89f17f7fd62eb501e888

diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx
index 16c7a09..959feae 100644
--- a/vcl/source/gdi/bitmap3.cxx
+++ b/vcl/source/gdi/bitmap3.cxx
@@ -1071,6 +1071,11 @@ void Bitmap::ImplAdaptBitCount(Bitmap& rNew) const
                 rNew.Convert(BMP_CONVERSION_24BIT);
                 break;
             }
+            case 32:
+            {
+                rNew.Convert(BMP_CONVERSION_32BIT);
+                break;
+            }
             default:
             {
                 OSL_ENSURE(false, "BitDepth adaption failed (!)");
commit dad11ad66d600d586ce28df0940fbaf636954284
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Jun 26 11:21:15 2016 +0800

    svx: add support for 32-bit bitmaps to toolbar color icon
    
    A color icon (like background or font color) has an additional
    rectangle which shows the current selected color as a colored
    rectangle. Because it didn't support 32-bit colors correctly, the
    background of the icon was always white. This fixes this issue.
    
    Change-Id: I045e03f45937ba9394ba2590bc3d2228a4cd9cfe

diff --git a/svx/source/tbxctrls/tbxcolorupdate.cxx b/svx/source/tbxctrls/tbxcolorupdate.cxx
index c773a1c..8082b5c 100644
--- a/svx/source/tbxctrls/tbxcolorupdate.cxx
+++ b/svx/source/tbxctrls/tbxcolorupdate.cxx
@@ -96,12 +96,23 @@ namespace svx
         if ((maCurColor != aColor) || (aColor == COL_BLACK) ||
             bSizeChanged || bDisplayModeChanged || bForceUpdate )
         {
+            BitmapEx aSource(aImage.GetBitmapEx());
+            BitmapEx aBmpEx;
+
             // create an empty bitmap, and copy the original bitmap inside
             // (so that it grows in case the original bitmap was smaller)
             sal_uInt8 nAlpha = 255;
-            BitmapEx aBmpEx(Bitmap(aItemSize, 24), AlphaMask(aItemSize, &nAlpha));
 
-            BitmapEx aSource(aImage.GetBitmapEx());
+            if (aSource.GetBitmap().GetBitCount() == 32)
+            {
+                aBmpEx = BitmapEx(Bitmap(aItemSize, 32));
+
+            }
+            else
+            {
+                aBmpEx = BitmapEx(Bitmap(aItemSize, 24), AlphaMask(aItemSize, &nAlpha));
+            }
+
             long nWidth = std::min(aItemSize.Width(), aSource.GetSizePixel().Width());
             long nHeight = std::min(aItemSize.Height(), aSource.GetSizePixel().Height());
 
commit e25ff7d08444f32a2060995041891af8148e0c93
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Jun 26 11:18:50 2016 +0800

    Use the libpng based PngReader for reading "Image" resources
    
    This adds support for reading "Image" resources (maily icons for
    menus, toolbars,..).
    
    Change-Id: I50200b70bb2d73dd23524138ab7c853d4884d18c

diff --git a/vcl/source/image/ImplImageTree.cxx b/vcl/source/image/ImplImageTree.cxx
index b512dd4..4188a6f 100644
--- a/vcl/source/image/ImplImageTree.cxx
+++ b/vcl/source/image/ImplImageTree.cxx
@@ -45,6 +45,8 @@
 #include <vcl/svapp.hxx>
 #include <vcldemo-debug.hxx>
 
+#include <vcl/filter/PngReader.hxx>
+
 #include <vcl/BitmapProcessor.hxx>
 #include <vcl/BitmapTools.hxx>
 
@@ -82,9 +84,8 @@ void loadImageFromStream(std::shared_ptr<SvStream> xStream, OUString const & rPa
 {
     if (rPath.endsWith(".png"))
     {
-        vcl::PNGReader aPNGReader(*xStream);
-        aPNGReader.SetIgnoreGammaChunk( true );
-        rBitmap = aPNGReader.Read();
+        vcl::PngReader aPNGReader(*xStream);
+        aPNGReader.Read(rBitmap);
     }
     else if (rPath.endsWith(".svg"))
     {
commit 204888fe1dee540e00d3e42e29ab9f03c1aef7fc
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Jun 26 11:13:13 2016 +0800

    vcl: PngReader which uses libpng for PNG decoding
    
    We already need libpng for some of the dependencies and in LO
    itself (splash). However in vcl we have our own implementation
    for reading and writing PNG images. This adds a PNG reader that
    uses libpng and always decodes to a 32-bit RGBA bitmap, however
    it doesn't replace the existing PNGReader - yet.
    
    Change-Id: I95663886ea599603bb3d18826b0a640596ce3724

diff --git a/include/vcl/filter/PngReader.hxx b/include/vcl/filter/PngReader.hxx
new file mode 100644
index 0000000..957539c
--- /dev/null
+++ b/include/vcl/filter/PngReader.hxx
@@ -0,0 +1,40 @@
+/* -*- 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/.
+ *
+ */
+
+#include <vcl/graph.hxx>
+#include <vcl/dllapi.h>
+#include <com/sun/star/task/XStatusIndicator.hpp>
+
+#ifndef INCLUDED_VCL_SOURCE_FILTER_PNG_PNGREADER_HXX
+#define INCLUDED_VCL_SOURCE_FILTER_PNG_PNGREADER_HXX
+
+namespace vcl
+{
+
+class VCL_DLLPUBLIC PngReader
+{
+    SvStream& mrStream;
+    css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator;
+
+public:
+    PngReader(SvStream& rStream);
+
+    virtual ~PngReader()
+    {}
+
+    bool Read(BitmapEx& rBitmap);
+    bool Read(Graphic& rGraphic);
+};
+
+} // namespace vcl
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 83383ff..3e01ed9 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -119,6 +119,7 @@ $(eval $(call gb_Library_use_externals,vcl,\
 	icuuc \
 	lcms2 \
 	mdds_headers \
+	png \
 ))
 ifneq ($(ENABLE_OPENGL)$(if $(filter ANDROID,$(OS)),TRUE),)
 $(eval $(call gb_Library_use_externals,vcl,\
@@ -369,6 +370,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/filter/jpeg/JpegReader \
     vcl/source/filter/jpeg/JpegWriter \
     vcl/source/filter/jpeg/JpegTransform \
+    vcl/source/filter/png/PngReader \
     vcl/source/filter/wmf/emfwr \
     vcl/source/filter/wmf/enhwmf \
     vcl/source/filter/wmf/winmtf \
diff --git a/vcl/source/filter/png/PngReader.cxx b/vcl/source/filter/png/PngReader.cxx
new file mode 100644
index 0000000..6470aa1
--- /dev/null
+++ b/vcl/source/filter/png/PngReader.cxx
@@ -0,0 +1,180 @@
+/* -*- 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/.
+ *
+ */
+
+#include <vcl/filter/PngReader.hxx>
+
+#include <png.h>
+
+#include <vcl/bitmapaccess.hxx>
+
+namespace
+{
+
+void lclReadStream(png_structp pPng, png_bytep pOutBytes, png_size_t nBytesToRead)
+{
+    png_voidp pIO = png_get_io_ptr(pPng);
+
+    if (pIO == nullptr)
+        return;
+
+    SvStream* pStream = reinterpret_cast<SvStream*>(pIO);
+
+    sal_Size nBytesRead = pStream->ReadBytes(pOutBytes, nBytesToRead);
+
+    if (nBytesRead != nBytesToRead)
+        png_error(pPng, "Error reading");
+}
+
+bool reader(SvStream& rStream, Bitmap& rBitmap)
+{
+    enum { PNG_SIGNATURE_SIZE = 8 };
+
+    sal_uInt8 aHeader[PNG_SIGNATURE_SIZE];
+    rStream.ReadBytes(aHeader, PNG_SIGNATURE_SIZE);
+
+    if (png_sig_cmp(aHeader, 0, PNG_SIGNATURE_SIZE))
+        return false;
+
+    png_structp pPng = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
+    if (!pPng)
+        return false;
+
+    png_infop pInfo = png_create_info_struct(pPng);
+    if (!pInfo)
+    {
+        png_destroy_read_struct(&pPng, nullptr, nullptr);
+        return false;
+    }
+
+    if (setjmp(png_jmpbuf(pPng)))
+    {
+        png_destroy_read_struct(&pPng, &pInfo, nullptr);
+        return false;
+    }
+
+    png_set_read_fn(pPng, &rStream, lclReadStream);
+
+    png_set_crc_action(pPng, PNG_CRC_WARN_USE, PNG_CRC_WARN_DISCARD);
+
+    png_set_sig_bytes(pPng, PNG_SIGNATURE_SIZE);
+
+    png_read_info(pPng, pInfo);
+
+    png_uint_32 width = 0;
+    png_uint_32 height = 0;
+    int bitDepth = 0;
+    int colorType = -1;
+    int interlace = -1;
+
+    png_uint_32 returnValue = png_get_IHDR(pPng, pInfo, &width, &height, &bitDepth, &colorType, &interlace, nullptr, nullptr);
+
+    if (returnValue != 1)
+    {
+        png_destroy_read_struct(&pPng, &pInfo, nullptr);
+        return false;
+    }
+
+    Bitmap aBitmap(Size(width, height), 32);
+
+    png_set_bgr(pPng);
+
+    if (colorType == PNG_COLOR_TYPE_PALETTE)
+        png_set_palette_to_rgb(pPng);
+
+    if (colorType == PNG_COLOR_TYPE_GRAY)
+        png_set_expand_gray_1_2_4_to_8(pPng);
+
+    if (png_get_valid(pPng, pInfo, PNG_INFO_tRNS))
+        png_set_tRNS_to_alpha(pPng);
+
+
+    if (bitDepth == 16)
+        png_set_scale_16(pPng);
+
+    if (bitDepth < 8)
+        png_set_packing(pPng);
+
+    if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
+    {
+        png_set_gray_to_rgb(pPng);
+    }
+
+    png_set_filler(pPng, 0xFF, PNG_FILLER_AFTER);
+
+    int nNumberOfPasses = png_set_interlace_handling(pPng);
+
+    png_read_update_info(pPng, pInfo);
+    returnValue = png_get_IHDR(pPng, pInfo, &width, &height, &bitDepth, &colorType, nullptr, nullptr, nullptr);
+
+    if (returnValue != 1)
+    {
+        png_destroy_read_struct(&pPng, &pInfo, nullptr);
+        return false;
+    }
+
+    if (bitDepth != 8 || !(colorType == PNG_COLOR_TYPE_RGB ||
+                           colorType == PNG_COLOR_TYPE_RGB_ALPHA))
+    {
+        png_destroy_read_struct(&pPng, &pInfo, nullptr);
+        return false;
+    }
+
+    {
+        Bitmap::ScopedWriteAccess pWriteAccess(aBitmap);
+
+        for (int pass = 0; pass < nNumberOfPasses; pass++)
+        {
+            for (png_uint_32 y = 0; y < height; y++)
+            {
+                Scanline pScanline = pWriteAccess->GetScanline(y);
+                png_read_rows(pPng, &pScanline, nullptr, 1);
+            }
+        }
+    }
+
+    png_read_end(pPng, pInfo);
+
+    png_destroy_read_struct(&pPng, &pInfo, nullptr);
+
+    rBitmap = aBitmap;
+
+    return true;
+}
+
+} // anonymous namespace
+
+namespace vcl
+{
+
+PngReader::PngReader(SvStream& rStream)
+    : mrStream(rStream)
+{}
+
+bool PngReader::Read(BitmapEx& rBitmap)
+{
+    Bitmap aBitmap;
+    if (!reader(mrStream, aBitmap))
+        return false;
+    rBitmap = BitmapEx(aBitmap);
+    return true;
+}
+
+bool PngReader::Read(Graphic& rGraphic)
+{
+    Bitmap aBitmap;
+    if (!reader(mrStream, aBitmap))
+        return false;
+    rGraphic = Graphic(aBitmap);
+    return true;
+}
+
+} // namespace vcl
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 8379ecdf8d8246cae35fded5dbc3ab51d6503fb2
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Jun 26 11:01:58 2016 +0800

    BitmapProcessor: support creating a "disabled" RGBA bitmap
    
    Change-Id: I782514808a767084f159b5956a0bda898f0eb48e

diff --git a/vcl/source/bitmap/BitmapProcessor.cxx b/vcl/source/bitmap/BitmapProcessor.cxx
index acbac9a..ea32705 100644
--- a/vcl/source/bitmap/BitmapProcessor.cxx
+++ b/vcl/source/bitmap/BitmapProcessor.cxx
@@ -70,7 +70,25 @@ BitmapEx BitmapProcessor::createDisabledImage(const BitmapEx& rBitmapEx)
 
     BitmapEx aReturnBitmap;
 
-    if (rBitmapEx.IsTransparent())
+    if (rBitmapEx.GetBitmap().GetBitCount() == 32)
+    {
+        if (pRead && pGrey && pGreyAlpha)
+        {
+            for (long nY = 0; nY < aSize.Height(); ++nY)
+            {
+                for (long nX = 0; nX < aSize.Width(); ++nX)
+                {
+                    BitmapColor aColor = pRead->GetPixel(nY, nX);
+                    const sal_uInt8 nLum(aColor.GetLuminance());
+                    const sal_uInt8 nAlpha(std::min(aColor.GetAlpha() + 178ul, 255ul));
+                    BitmapColor aGreyValue(nLum, nLum, nLum, nAlpha);
+                    pGrey->SetPixel(nY, nX, aGreyValue);
+                }
+            }
+        }
+        aReturnBitmap = BitmapEx(aGrey);
+    }
+    else if (rBitmapEx.IsTransparent())
     {
         AlphaMask aBitmapAlpha(rBitmapEx.GetAlpha());
         BitmapReadAccess* pReadAlpha(aBitmapAlpha.AcquireReadAccess());
commit 69ad9d8ae9d186a9aa593fa38602db49c5375038
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Jun 26 10:53:12 2016 +0800

    use DrawOutDev from dialcontrol, explicitly set background
    
    When drawing the dialcontrol's VirtualDevices we can use the more
    direct DrawOutDev instead of the DrawBitmapEx. This should avoid
    creating a BitmapEx and draw directly.
    
    In addition, explicitly set the initial background even if it will
    be overdrawn or changed later.
    
    Change-Id: I06f05ac18c556fc7918709b5d3e88e30ed4d50d6

diff --git a/svx/source/dialog/dialcontrol.cxx b/svx/source/dialog/dialcontrol.cxx
index 7067ab7..abb6c72 100644
--- a/svx/source/dialog/dialcontrol.cxx
+++ b/svx/source/dialog/dialcontrol.cxx
@@ -56,7 +56,7 @@ void DialControlBmp::CopyBackground( const DialControlBmp& rSrc )
     SetSize(rSrc.maRect.GetSize());
     mbEnabled = rSrc.mbEnabled;
     Point aPos;
-    DrawBitmapEx( aPos, rSrc.GetBitmapEx( aPos, maRect.GetSize() ) );
+    DrawOutDev(aPos, maRect.GetSize(), aPos, maRect.GetSize(), rSrc);
 }
 
 void DialControlBmp::DrawBackground( const Size& rSize, bool bEnabled )
@@ -144,7 +144,7 @@ const Color& DialControlBmp::GetButtonFillColor( bool bMain ) const
 void DialControlBmp::Init()
 {
     SetSettings(mrParent.GetSettings());
-    SetBackground();
+    SetBackground(Wallpaper(COL_WHITE));
 }
 
 void DialControlBmp::SetSize( const Size& rSize )
@@ -276,7 +276,7 @@ void DialControl::Resize()
 void DialControl::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
 {
     Point aPos;
-    rRenderContext.DrawBitmapEx(aPos, mpImpl->mxBmpBuffered->GetBitmapEx(aPos, mpImpl->maWinSize));
+    rRenderContext.DrawOutDev(aPos, mpImpl->maWinSize, aPos, mpImpl->maWinSize, *mpImpl->mxBmpBuffered.get());
 }
 
 void DialControl::StateChanged( StateChangedType nStateChange )


More information about the Libreoffice-commits mailing list