Rebased ref, commits from common ancestor: commit 8bf696e5689280528ae625c80d8c8844d40264e8 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Jul 24 22:14:27 2016 +0900
vcl: use same bitdepth when performing super scaling Change-Id: I379c4aa9aa83470961fa972eec8cdb67261f749c diff --git a/vcl/source/bitmap/bitmapscalesuper.cxx b/vcl/source/bitmap/bitmapscalesuper.cxx index ff01aae..ddb3a85 100644 --- a/vcl/source/bitmap/bitmapscalesuper.cxx +++ b/vcl/source/bitmap/bitmapscalesuper.cxx @@ -937,7 +937,7 @@ bool BitmapScaleSuper::filter(Bitmap& rBitmap) Bitmap::ScopedReadAccess pReadAccess(rBitmap); - Bitmap aOutBmp(Size(nDstW, nDstH), 24); + Bitmap aOutBmp(Size(nDstW, nDstH), rBitmap.GetBitCount()); Bitmap::ScopedWriteAccess pWriteAccess(aOutBmp); const long nStartY = 0; commit 59c7e1287a2ba3efe66ce8fa692840552b2a6ed5 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Jun 28 16:39:57 2016 +0800 BitmapProcessor: support 32-bit bitmap in createLightImage Change-Id: If28c715f9737f34b9d71c1342cae88fcc69231dd diff --git a/vcl/source/bitmap/BitmapProcessor.cxx b/vcl/source/bitmap/BitmapProcessor.cxx index 1a89da5..e64fd2a 100644 --- a/vcl/source/bitmap/BitmapProcessor.cxx +++ b/vcl/source/bitmap/BitmapProcessor.cxx @@ -17,7 +17,9 @@ BitmapEx BitmapProcessor::createLightImage(const BitmapEx& rBitmapEx) const Size aSize(rBitmapEx.GetSizePixel()); Bitmap aBitmap(rBitmapEx.GetBitmap()); - Bitmap aDarkBitmap(aSize, 24); + int nBitcount = aBitmap.GetBitCount() == 32 ? 32 : 24; + + Bitmap aDarkBitmap(aSize, nBitcount); BitmapReadAccess* pRead(aBitmap.AcquireReadAccess()); BitmapWriteAccess* pWrite(aDarkBitmap.AcquireWriteAccess()); commit 006f9fa1eb1b90481468d8f5460d74843ba26dc9 Author: Tomaž Vajngerl <tomaz.vajng...@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 97e20f0..3bc4f64 100644 --- a/vcl/Module_vcl.mk +++ b/vcl/Module_vcl.mk @@ -109,6 +109,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\ CppunitTest_vcl_app_test \ $(if $(MERGELIBS),,CppunitTest_vcl_wmf_test) \ CppunitTest_vcl_jpeg_read_write_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 558bb53111d01165da7e9af88d4057fc8f687385 Author: Tomaž Vajngerl <tomaz.vajng...@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 daec7b4..15f4731 100644 --- a/vcl/source/gdi/bitmap3.cxx +++ b/vcl/source/gdi/bitmap3.cxx @@ -1072,6 +1072,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 a3b5d389967396970f3e0934d510cc1d231d194d Author: Tomaž Vajngerl <tomaz.vajng...@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 e452bc1..89665ad 100644 --- a/svx/source/tbxctrls/tbxcolorupdate.cxx +++ b/svx/source/tbxctrls/tbxcolorupdate.cxx @@ -86,12 +86,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 7f96c112c54c70de949ca1ee3fbd7105bd39af5d Author: Tomaž Vajngerl <tomaz.vajng...@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 bd36080..a62da57 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> #include <vcl/pngwrite.hxx> @@ -146,9 +148,8 @@ void loadImageFromStream(std::shared_ptr<SvStream> const & xStream, OUString con 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 0d2ccc149e468bea5e1e98a8885c2730eaf64a05 Author: Tomaž Vajngerl <tomaz.vajng...@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 888a9d0..b27bd37 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -122,6 +122,7 @@ $(eval $(call gb_Library_use_externals,vcl,\ icuuc \ lcms2 \ mdds_headers \ + png \ )) ifeq ($(ENABLE_HEADLESS),) $(eval $(call gb_Library_use_externals,vcl,\ @@ -374,6 +375,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 2e5a113adb1cf87caf39dd19d59eb51014576da6 Author: Tomaž Vajngerl <tomaz.vajng...@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 91b46bc..1a89da5 100644 --- a/vcl/source/bitmap/BitmapProcessor.cxx +++ b/vcl/source/bitmap/BitmapProcessor.cxx @@ -77,7 +77,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 74c708d747bead352b06cbbc72c797a4da284c10 Author: Tomaž Vajngerl <tomaz.vajng...@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 4f7a240..afedc4d 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 ) commit 7d07ed16b1f41b1ef0fb4ce240a10fddcab61a4c Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Jun 19 10:13:28 2016 +0800 svp: premultiply the buffer when drawing a 32-bit bitmap Cairo uses premultiplied alpha for RGBA bitmap buffers. As our bitmap buffer doesn't currently do this, we have to do it just before we draw a bitmap. Change-Id: I551ba6d589b7339b2e081452c2720b39e7278b68 diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index df4e487..b9f4f1d 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -83,6 +83,16 @@ namespace aDamageRect.intersect(getClipBox(cr)); return aDamageRect; } + + static sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a) + { + return (a > 0) ? (c * 255 + a / 2) / a : 0; + } + + static sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a) + { + return (c * a + 127) / 255; + } } bool SvpSalGraphics::blendBitmap( const SalTwoRect&, const SalBitmap& /*rBitmap*/ ) @@ -99,6 +109,28 @@ bool SvpSalGraphics::blendAlphaBitmap( const SalTwoRect&, const SalBitmap&, cons namespace { + void premultiplyBuffer(int width, int height, int stride, unsigned char* data) + { + for (int y = 0; y < height; ++y) + { + unsigned int* row = reinterpret_cast<unsigned int*>(data + y * stride); + for (int x = 0; x < width; ++x) + { + unsigned int px = row[x]; + unsigned char a = (px & 0xff000000) >> 24; + unsigned char r = (px & 0x00ff0000) >> 16; + unsigned char g = (px & 0x0000ff00) >> 8; + unsigned char b = (px & 0x000000ff); + + r = premultiply(r, a); + g = premultiply(g, a); + b = premultiply(b, a); + + row[x] = (a << 24) | (r << 16) | (g << 8) | b; + } + } + } + class SourceHelper { public: @@ -123,7 +155,25 @@ namespace source = SvpSalGraphics::createCairoSurface(aTmpBmp.GetBuffer()); } else - source = SvpSalGraphics::createCairoSurface(rSrcBmp.GetBuffer()); + { + const BitmapBuffer* pSrc = rSrcBmp.GetBuffer(); + if (pSrc->mnColorChannelBitCount == 32) + { + aTmpBmp.Create(rSrcBmp); + source = SvpSalGraphics::createCairoSurface(aTmpBmp.GetBuffer()); + cairo_surface_flush(source); + int w = cairo_image_surface_get_width(source); + int h = cairo_image_surface_get_height(source); + int stride = cairo_image_surface_get_stride(source); + unsigned char* data = cairo_image_surface_get_data(source); + premultiplyBuffer(w, h, stride, data); + cairo_surface_mark_dirty(source); + } + else + { + source = SvpSalGraphics::createCairoSurface(rSrcBmp.GetBuffer()); + } + } } ~SourceHelper() { @@ -1026,16 +1076,6 @@ void SvpSalGraphics::drawBitmap( const SalTwoRect& rTR, drawAlphaBitmap(rTR, rSourceBitmap, rTransparentBitmap); } -static sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a) -{ - return (a > 0) ? (c * 255 + a / 2) / a : 0; -} - -static sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a) -{ - return (c * a + 127) / 255; -} - void SvpSalGraphics::drawMask( const SalTwoRect& rTR, const SalBitmap& rSalBitmap, SalColor nMaskColor ) commit 12237fd172be7287451d770e4f18208a757caa6e Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Jun 12 16:55:33 2016 +0900 Support native alpha in outdev / virdev + support in headless This adds support for native alpha surface (RGBA) to OutputDevice and VirtualDevice. Mainly this removes restrictions that set the alpha value to opaque (1.0f). All the functions still use a separate "alpha" device for now. As the headless backend already uses a 32-bit surface there was not a big change necessary to make it work. Change-Id: Ic2f2319a006764395d70b64c473749cd6d47f812 diff --git a/include/vcl/salgtype.hxx b/include/vcl/salgtype.hxx index b9eb6ae..37b1329 100644 --- a/include/vcl/salgtype.hxx +++ b/include/vcl/salgtype.hxx @@ -33,11 +33,14 @@ enum class DeviceFormat { }; typedef sal_uInt32 SalColor; -#define MAKE_SALCOLOR( r, g, b ) ((SalColor)(((sal_uInt32)((sal_uInt8)(b))))|(((sal_uInt32)((sal_uInt8)(g)))<<8)|(((sal_uInt32)((sal_uInt8)(r)))<<16)) + +#define MAKE_SALCOLOR(r, g, b) MAKE_SALCOLOR_ALPHA(r, g, b, 0xFF) +#define MAKE_SALCOLOR_ALPHA(r, g, b, a) ((SalColor)(((sal_uInt32)((sal_uInt8)(b))))|(((sal_uInt32)((sal_uInt8)(g)))<<8)|(((sal_uInt32)((sal_uInt8)(r)))<<16)|(((sal_uInt32)((sal_uInt8)(a)))<<24)) +#define SALCOLOR_ALPHA( n ) ((sal_uInt8)((n)>>24)) #define SALCOLOR_RED( n ) ((sal_uInt8)((n)>>16)) #define SALCOLOR_GREEN( n ) ((sal_uInt8)(((sal_uInt16)(n)) >> 8)) #define SALCOLOR_BLUE( n ) ((sal_uInt8)(n)) -#define SALCOLOR_NONE (~(SalColor)0) +#define SALCOLOR_NONE ((SalColor)0) // must equal to class Point struct SalPoint diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index f26a8d6..df4e487 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -886,7 +886,7 @@ void SvpSalGraphics::applyColor(cairo_t *cr, SalColor aColor) cairo_set_source_rgba(cr, SALCOLOR_RED(aColor)/255.0, SALCOLOR_GREEN(aColor)/255.0, SALCOLOR_BLUE(aColor)/255.0, - 1.0); + SALCOLOR_ALPHA(aColor)/255.0); } else { @@ -1101,7 +1101,7 @@ void SvpSalGraphics::drawMask( const SalTwoRect& rTR, SalBitmap* SvpSalGraphics::getBitmap( long nX, long nY, long nWidth, long nHeight ) { SvpSalBitmap* pBitmap = new SvpSalBitmap(); - pBitmap->Create(Size(nWidth, nHeight), 32, BitmapPalette()); + pBitmap->Create(Size(nWidth, nHeight), 24, BitmapPalette()); cairo_surface_t* target = SvpSalGraphics::createCairoSurface(pBitmap->GetBuffer()); cairo_t* cr = cairo_create(target); @@ -1125,10 +1125,12 @@ SalColor SvpSalGraphics::getPixel( long nX, long nY ) unsigned char *surface_data = cairo_image_surface_get_data(m_pSurface); unsigned char *row = surface_data + (nStride*nY); unsigned char *data = row + (nX * 4); - sal_uInt8 b = unpremultiply(data[SVP_CAIRO_BLUE], data[SVP_CAIRO_ALPHA]); - sal_uInt8 g = unpremultiply(data[SVP_CAIRO_GREEN], data[SVP_CAIRO_ALPHA]); - sal_uInt8 r = unpremultiply(data[SVP_CAIRO_RED], data[SVP_CAIRO_ALPHA]); - return MAKE_SALCOLOR(r, g, b); + sal_uInt8 alpha = data[SVP_CAIRO_ALPHA]; + sal_uInt8 b = unpremultiply(data[SVP_CAIRO_BLUE], alpha); + sal_uInt8 g = unpremultiply(data[SVP_CAIRO_GREEN], alpha); + sal_uInt8 r = unpremultiply(data[SVP_CAIRO_RED], alpha); + SalColor aSalColor = MAKE_SALCOLOR_ALPHA(r, g, b, alpha); + return aSalColor; } namespace diff --git a/vcl/inc/outdata.hxx b/vcl/inc/outdata.hxx index f48f0f9..a92f739 100644 --- a/vcl/inc/outdata.hxx +++ b/vcl/inc/outdata.hxx @@ -23,9 +23,25 @@ #include <tools/color.hxx> #include <vcl/salgtype.hxx> +inline Color ImplSalToColor(SalColor aSalColor) +{ + Color aColor = Color(0xFF - SALCOLOR_ALPHA(aSalColor), + SALCOLOR_RED(aSalColor), + SALCOLOR_GREEN(aSalColor), + SALCOLOR_BLUE(aSalColor)); + return aColor; +} + inline SalColor ImplColorToSal( Color aColor ) { - return MAKE_SALCOLOR( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() ); + return MAKE_SALCOLOR(aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue()); +} + +inline SalColor ImplColorToSalWithAlpha(Color aColor) +{ + SalColor aSalColor = MAKE_SALCOLOR_ALPHA(aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue(), + 0xFF - aColor.GetTransparency()); + return aSalColor; } inline bool ImplIsColorTransparent( Color aColor ) diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx index 4a44770..26dc929 100644 --- a/vcl/qa/cppunit/outdev.cxx +++ b/vcl/qa/cppunit/outdev.cxx @@ -24,12 +24,36 @@ public: VclOutdevTest() : BootstrapFixture(true, false) {} void testVirtualDevice(); + void testAlphaVirtualDevice(); CPPUNIT_TEST_SUITE(VclOutdevTest); CPPUNIT_TEST(testVirtualDevice); + CPPUNIT_TEST(testAlphaVirtualDevice); CPPUNIT_TEST_SUITE_END(); }; +void VclOutdevTest::testAlphaVirtualDevice() +{ + Size aSize(32,32); + ScopedVclPtrInstance< VirtualDevice > pVDev; + pVDev->SetOutputSizePixel(aSize); + pVDev->DrawPixel(Point(1,1), Color(0x00, 0x11, 0x22, 0x33)); + pVDev->DrawPixel(Point(2,2), Color(0x10, 0xEE, 0xEE, 0xEE)); + pVDev->DrawPixel(Point(3,3), Color(0xEE, 0xEE, 0xEE, 0xEE)); + + CPPUNIT_ASSERT_EQUAL(TRGB_COLORDATA(0xFF, 0x00, 0x00, 0x00), pVDev->GetPixel(Point(0,0)).GetColor()); + CPPUNIT_ASSERT_EQUAL(TRGB_COLORDATA(0x00, 0x11, 0x22, 0x33), pVDev->GetPixel(Point(1,1)).GetColor()); + CPPUNIT_ASSERT_EQUAL(TRGB_COLORDATA(0x10, 0xEE, 0xEE, 0xEE), pVDev->GetPixel(Point(2,2)).GetColor()); + + Bitmap aBitmap = pVDev->GetBitmap(Point(), aSize); + + Bitmap::ScopedReadAccess pReadAccess(aBitmap); + CPPUNIT_ASSERT_EQUAL(TRGB_COLORDATA(0xFF, 0x00, 0x00, 0x00), Color(pReadAccess->GetPixel(0, 0)).GetColor()); + CPPUNIT_ASSERT_EQUAL(TRGB_COLORDATA(0x00, 0x11, 0x22, 0x33), Color(pReadAccess->GetPixel(1, 1)).GetColor()); + //CPPUNIT_ASSERT_EQUAL(TRGB_COLORDATA(0xEE, 0xEE, 0xEE, 0xEE), Color(pReadAccess->GetPixel(3, 3)).GetColor()); + //CPPUNIT_ASSERT_EQUAL(TRGB_COLORDATA(0x10, 0xEE, 0xEE, 0xEE), Color(pReadAccess->GetPixel(2, 2)).GetColor()); +} + void VclOutdevTest::testVirtualDevice() { ScopedVclPtrInstance< VirtualDevice > pVDev; diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx index 2e80762..7222ece 100644 --- a/vcl/source/gdi/virdev.cxx +++ b/vcl/source/gdi/virdev.cxx @@ -191,11 +191,11 @@ void VirtualDevice::ImplInitVirDev( const OutputDevice* pOutDev, } // virtual devices have white background by default - SetBackground( Wallpaper( Color( COL_WHITE ) ) ); + SetBackground( Wallpaper( Color( COL_TRANSPARENT ) ) ); // #i59283# don't erase user-provided surface if( !pData && bErase) - Erase(); + //Erase(); // register VirDev in the list mpNext = pSVData->maGDIData.mpFirstVirDev; diff --git a/vcl/source/outdev/outdevstate.cxx b/vcl/source/outdev/outdevstate.cxx index cf2ef0d..9819400 100644 --- a/vcl/source/outdev/outdevstate.cxx +++ b/vcl/source/outdev/outdevstate.cxx @@ -367,23 +367,11 @@ void OutputDevice::SetFillColor( const Color& rColor ) if ( mpMetaFile ) mpMetaFile->AddAction( new MetaFillColorAction( aColor, true ) ); - if ( ImplIsColorTransparent( aColor ) ) + if ( maFillColor != aColor ) { - if ( mbFillColor ) - { - mbInitFillColor = true; - mbFillColor = false; - maFillColor = Color( COL_TRANSPARENT ); - } - } - else - { - if ( maFillColor != aColor ) - { - mbInitFillColor = true; - mbFillColor = true; - maFillColor = aColor; - } + mbInitFillColor = true; + mbFillColor = true; + maFillColor = aColor; } if( mpAlphaVDev ) @@ -415,23 +403,11 @@ void OutputDevice::SetLineColor( const Color& rColor ) if( mpMetaFile ) mpMetaFile->AddAction( new MetaLineColorAction( aColor, true ) ); - if( ImplIsColorTransparent( aColor ) ) + if( maLineColor != aColor ) { - if ( mbLineColor ) - { - mbInitLineColor = true; - mbLineColor = false; - maLineColor = Color( COL_TRANSPARENT ); - } - } - else - { - if( maLineColor != aColor ) - { - mbInitLineColor = true; - mbLineColor = true; - maLineColor = aColor; - } + mbInitLineColor = true; + mbLineColor = true; + maLineColor = aColor; } if( mpAlphaVDev ) @@ -583,7 +559,7 @@ void OutputDevice::InitLineColor() else if( RasterOp::Invert == meRasterOp ) mpGraphics->SetROPLineColor( SalROPColor::Invert ); else - mpGraphics->SetLineColor( ImplColorToSal( maLineColor ) ); + mpGraphics->SetLineColor( ImplColorToSalWithAlpha( maLineColor ) ); } else mpGraphics->SetLineColor(); @@ -605,7 +581,7 @@ void OutputDevice::InitFillColor() else if( RasterOp::Invert == meRasterOp ) mpGraphics->SetROPFillColor( SalROPColor::Invert ); else - mpGraphics->SetFillColor( ImplColorToSal( maFillColor ) ); + mpGraphics->SetFillColor( ImplColorToSalWithAlpha( maFillColor ) ); } else mpGraphics->SetFillColor(); diff --git a/vcl/source/outdev/pixel.cxx b/vcl/source/outdev/pixel.cxx index 478a693..45a7e82 100644 --- a/vcl/source/outdev/pixel.cxx +++ b/vcl/source/outdev/pixel.cxx @@ -44,9 +44,7 @@ Color OutputDevice::GetPixel( const Point& rPt ) const const long nX = ImplLogicXToDevicePixel( rPt.X() ); const long nY = ImplLogicYToDevicePixel( rPt.Y() ); const SalColor aSalCol = mpGraphics->GetPixel( nX, nY, this ); - aColor.SetRed( SALCOLOR_RED( aSalCol ) ); - aColor.SetGreen( SALCOLOR_GREEN( aSalCol ) ); - aColor.SetBlue( SALCOLOR_BLUE( aSalCol ) ); + aColor = ImplSalToColor(aSalCol); } } return aColor; @@ -91,7 +89,7 @@ void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor ) if ( mpMetaFile ) mpMetaFile->AddAction( new MetaPixelAction( rPt, aColor ) ); - if ( !IsDeviceOutputNecessary() || ImplIsColorTransparent( aColor ) || ImplIsRecordLayout() ) + if ( !IsDeviceOutputNecessary() || ImplIsRecordLayout() ) return; Point aPt = ImplLogicToDevicePixel( rPt ); @@ -105,7 +103,7 @@ void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor ) if ( mbOutputClipped ) return; - mpGraphics->DrawPixel( aPt.X(), aPt.Y(), ImplColorToSal( aColor ), this ); + mpGraphics->DrawPixel( aPt.X(), aPt.Y(), ImplColorToSalWithAlpha( aColor ), this ); if( mpAlphaVDev ) mpAlphaVDev->DrawPixel( rPt ); commit 6e79d32ec759c6140791d88e9c09b342dee31c0e Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Jun 12 16:53:17 2016 +0900 Add testcases for 32-bit bitmap Change-Id: I531b8ba7cd691a526392a85da9cb8456a1f16177 diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx index bc36366..96adffe 100644 --- a/vcl/qa/cppunit/BitmapTest.cxx +++ b/vcl/qa/cppunit/BitmapTest.cxx @@ -16,6 +16,7 @@ #include <vcl/bitmap.hxx> #include <vcl/bitmapaccess.hxx> +#include <vcl/alpha.hxx> #include <vcl/virdev.hxx> #include <rtl/strbuf.hxx> @@ -33,18 +34,57 @@ namespace class BitmapTest : public CppUnit::TestFixture { + void testBitmap32(); + void testErase(); void testConvert(); void testScale(); void testCRC(); - void testBitmap32(); CPPUNIT_TEST_SUITE(BitmapTest); + CPPUNIT_TEST(testBitmap32); + CPPUNIT_TEST(testErase); CPPUNIT_TEST(testConvert); CPPUNIT_TEST(testScale); CPPUNIT_TEST(testCRC); CPPUNIT_TEST_SUITE_END(); }; +void BitmapTest::testErase() +{ + Bitmap aBitmap(Size(3, 3), 24); + { + Bitmap::ScopedWriteAccess pWriteAccess(aBitmap); + pWriteAccess->Erase(Color(0x11, 0x22, 0x33)); + } + { + Bitmap::ScopedReadAccess pReadAccess(aBitmap); + Color aColor((Color)pReadAccess->GetPixel(0, 0)); + CPPUNIT_ASSERT_EQUAL(RGB_COLORDATA(0x11, 0x22, 0x33), aColor.GetColor()); + } +} + +void BitmapTest::testBitmap32() +{ + Bitmap aBitmap(Size(3, 3), 32); + { + Bitmap::ScopedWriteAccess pWriteAccess(aBitmap); + pWriteAccess->Erase(TRGB_COLORDATA(0xFF, 0x11, 0x22, 0x33)); + pWriteAccess->SetPixel(1, 1, BitmapColor(0x44, 0xFF, 0xBB, 0x00)); + pWriteAccess->SetPixel(2, 2, BitmapColor(0x88, 0x77, 0x66, 0x55)); + } + { + Bitmap::ScopedReadAccess pReadAccess(aBitmap); + BitmapColor aColor = pReadAccess->GetPixel(0, 0); + CPPUNIT_ASSERT_EQUAL(TRGB_COLORDATA(0xFF, 0x00, 0x00, 0x00), Color(aColor).GetColor()); + + aColor = pReadAccess->GetPixel(1, 1); + CPPUNIT_ASSERT_EQUAL(TRGB_COLORDATA(0x00, 0x44, 0xFF, 0xBB), Color(aColor).GetColor()); + + aColor = pReadAccess->GetPixel(2, 2); + CPPUNIT_ASSERT_EQUAL(TRGB_COLORDATA(0x55, 0x88, 0x77, 0x66), Color(aColor).GetColor()); + } +} + void BitmapTest::testConvert() { Bitmap aBitmap(Size(10, 10), 8); commit 54d35c7e4081b403e49ae3eff47ff1eda7d8d170 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Jun 12 16:50:39 2016 +0900 general support for 32-bit Bitmaps + support in "gen" backend Change-Id: Iad57414a21dfa4e84e471d288923a1417a3535a3 diff --git a/vcl/source/gdi/bmpacc2.cxx b/vcl/source/gdi/bmpacc2.cxx index 72c569a..a3db5e6 100644 --- a/vcl/source/gdi/bmpacc2.cxx +++ b/vcl/source/gdi/bmpacc2.cxx @@ -169,78 +169,98 @@ void BitmapReadAccess::SetPixelForN24BitTcMask(Scanline pScanline, long nX, cons BitmapColor BitmapReadAccess::GetPixelForN32BitTcAbgr(ConstScanline pScanline, long nX, const ColorMask&) { - BitmapColor aBitmapColor; + pScanline = pScanline + (nX << 2); - aBitmapColor.SetBlue( *( pScanline = pScanline + ( nX << 2 ) + 1 )++ ); - aBitmapColor.SetGreen( *pScanline++ ); - aBitmapColor.SetRed( *pScanline ); + sal_uInt8 a = *pScanline++; + sal_uInt8 b = *pScanline++; + sal_uInt8 g = *pScanline++; + sal_uInt8 r = *pScanline; - return aBitmapColor; + return BitmapColor(r, g, b, 0xFF - a); } void BitmapReadAccess::SetPixelForN32BitTcAbgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&) { - *( pScanline = pScanline + ( nX << 2 ) )++ = 0xFF; + pScanline = pScanline + (nX << 2); + + sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha(); + + *pScanline++ = alpha; *pScanline++ = rBitmapColor.GetBlue(); *pScanline++ = rBitmapColor.GetGreen(); - *pScanline = rBitmapColor.GetRed(); + *pScanline = rBitmapColor.GetRed(); } BitmapColor BitmapReadAccess::GetPixelForN32BitTcArgb(ConstScanline pScanline, long nX, const ColorMask&) { - BitmapColor aBitmapColor; + pScanline = pScanline + (nX << 2); - aBitmapColor.SetRed( *( pScanline = pScanline + ( nX << 2 ) + 1 )++ ); - aBitmapColor.SetGreen( *pScanline++ ); - aBitmapColor.SetBlue( *pScanline ); + sal_uInt8 a = *pScanline++; + sal_uInt8 r = *pScanline++; + sal_uInt8 g = *pScanline++; + sal_uInt8 b = *pScanline; - return aBitmapColor; + return BitmapColor(r, g, b, 0xFF - a); } void BitmapReadAccess::SetPixelForN32BitTcArgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&) { - *( pScanline = pScanline + ( nX << 2 ) )++ = 0xFF; + pScanline = pScanline + (nX << 2); + + sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha(); + + *pScanline++ = alpha; *pScanline++ = rBitmapColor.GetRed(); *pScanline++ = rBitmapColor.GetGreen(); - *pScanline = rBitmapColor.GetBlue(); + *pScanline = rBitmapColor.GetBlue(); } BitmapColor BitmapReadAccess::GetPixelForN32BitTcBgra(ConstScanline pScanline, long nX, const ColorMask&) { - BitmapColor aBitmapColor; + pScanline = pScanline + (nX << 2); - aBitmapColor.SetBlue( *( pScanline = pScanline + ( nX << 2 ) )++ ); - aBitmapColor.SetGreen( *pScanline++ ); - aBitmapColor.SetRed( *pScanline ); + sal_uInt8 b = *pScanline++; + sal_uInt8 g = *pScanline++; + sal_uInt8 r = *pScanline++; + sal_uInt8 a = *pScanline; - return aBitmapColor; + return BitmapColor(r, g, b, 0xFF - a); } void BitmapReadAccess::SetPixelForN32BitTcBgra(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&) { - *( pScanline = pScanline + ( nX << 2 ) )++ = rBitmapColor.GetBlue(); + pScanline = pScanline + (nX << 2); + + sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha(); + + *pScanline++ = rBitmapColor.GetBlue(); *pScanline++ = rBitmapColor.GetGreen(); *pScanline++ = rBitmapColor.GetRed(); - *pScanline = 0xFF; + *pScanline = alpha; } BitmapColor BitmapReadAccess::GetPixelForN32BitTcRgba(ConstScanline pScanline, long nX, const ColorMask&) { - BitmapColor aBitmapColor; + pScanline = pScanline + (nX << 2); - aBitmapColor.SetRed( *( pScanline = pScanline + ( nX << 2 ) )++ ); - aBitmapColor.SetGreen( *pScanline++ ); - aBitmapColor.SetBlue( *pScanline ); + sal_uInt8 r = *pScanline++; + sal_uInt8 g = *pScanline++; + sal_uInt8 b = *pScanline++; + sal_uInt8 a = *pScanline; - return aBitmapColor; + return BitmapColor(r, g, b, 0xFF - a); } void BitmapReadAccess::SetPixelForN32BitTcRgba(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&) { - *( pScanline = pScanline + ( nX << 2 ) )++ = rBitmapColor.GetRed(); + pScanline = pScanline + (nX << 2); + + sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha(); + + *pScanline++ = rBitmapColor.GetRed(); *pScanline++ = rBitmapColor.GetGreen(); *pScanline++ = rBitmapColor.GetBlue(); - *pScanline = 0xFF; + *pScanline = alpha; } BitmapColor BitmapReadAccess::GetPixelForN32BitTcMask(ConstScanline pScanline, long nX, const ColorMask& rMask) diff --git a/vcl/source/gdi/impbmp.cxx b/vcl/source/gdi/impbmp.cxx index e232b50..2f45fdd 100644 --- a/vcl/source/gdi/impbmp.cxx +++ b/vcl/source/gdi/impbmp.cxx @@ -80,8 +80,10 @@ sal_uInt16 ImpBitmap::ImplGetBitCount() const return 4; else if (nBitCount <= 8) return 8; - else + else if (nBitCount <= 24) return 24; + else + return 32; } BitmapBuffer* ImpBitmap::ImplAcquireBuffer( BitmapAccessMode nMode ) diff --git a/vcl/unx/generic/gdi/salbmp.cxx b/vcl/unx/generic/gdi/salbmp.cxx index 844c9c7..2037918 100644 --- a/vcl/unx/generic/gdi/salbmp.cxx +++ b/vcl/unx/generic/gdi/salbmp.cxx @@ -129,6 +129,7 @@ BitmapBuffer* X11SalBitmap::ImplCreateDIB( || nBitCount == 8 || nBitCount == 16 || nBitCount == 24 + || nBitCount == 32 , "Unsupported BitCount!" ); @@ -183,12 +184,16 @@ BitmapBuffer* X11SalBitmap::ImplCreateDIB( break; } #endif - default: - nBitCount = 24; - SAL_FALLTHROUGH; + case 32: + pDIB->mnFormat |= ScanlineFormat::N32BitTcBgra; + break; case 24: pDIB->mnFormat |= ScanlineFormat::N24BitTcBgr; - break; + break; + default: + pDIB->mnFormat |= ScanlineFormat::N24BitTcBgr; + nBitCount = 24; + break; } pDIB->mnWidth = rSize.Width(); commit 5f803a2b18c43b40762fbcc51a73e5e29876e1ec Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Jun 12 16:47:25 2016 +0900 bitmap: support 32bit conversion Change-Id: Ia97cb00a7f311088a8ab2c52c069a570f8c269b4 diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx index 0f773ba..d0975a9 100644 --- a/include/vcl/bitmap.hxx +++ b/include/vcl/bitmap.hxx @@ -83,9 +83,10 @@ enum BmpConversion BMP_CONVERSION_8BIT_GREYS = 5, BMP_CONVERSION_8BIT_COLORS = 6, BMP_CONVERSION_24BIT = 7, - BMP_CONVERSION_4BIT_TRANS = 8, - BMP_CONVERSION_8BIT_TRANS = 9, - BMP_CONVERSION_GHOSTED = 10 + BMP_CONVERSION_32BIT = 8, + BMP_CONVERSION_4BIT_TRANS = 9, + BMP_CONVERSION_8BIT_TRANS = 10, + BMP_CONVERSION_GHOSTED = 11 }; enum BmpCombine diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx index acc6c4b..daec7b4 100644 --- a/vcl/source/gdi/bitmap3.cxx +++ b/vcl/source/gdi/bitmap3.cxx @@ -332,6 +332,15 @@ bool Bitmap::Convert( BmpConversion eConversion ) } break; + case BMP_CONVERSION_32BIT: + { + if( nBitCount < 32 ) + bRet = ImplConvertUp( 32 ); + else + bRet = true; + } + break; + case BMP_CONVERSION_GHOSTED: bRet = ImplConvertGhosted(); break; commit e1249b8a9ab720f3a2eabbab0aa9c6490f8c2a9c Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Jun 12 16:38:02 2016 +0900 ColorData - for RGB macro use TRGB with transparency set to 0 Change-Id: Ia363e05768ac76a7cf4b4da6cbb57174b2d64682 diff --git a/include/tools/colordata.hxx b/include/tools/colordata.hxx index 1d0fb42..2d8dbef 100644 --- a/include/tools/colordata.hxx +++ b/include/tools/colordata.hxx @@ -25,9 +25,12 @@ typedef sal_uInt32 ColorData; #define TRGB_COLORDATA(TRANSPARENCE,RED,GREEN,BLUE) \ - ((sal_Int32)(((sal_uInt32)((sal_uInt8)(BLUE))))|(((sal_uInt32)((sal_uInt8)(GREEN)))<<8)|(((sal_uInt32)((sal_uInt8)(RED)))<<16)|(((sal_uInt32)((sal_uInt8)(TRANSPARENCE)))<<24)) + ((sal_Int32)(((sal_uInt32)((sal_uInt8)(BLUE)))) | \ + (((sal_uInt32)((sal_uInt8)(GREEN)))<<8) | \ + (((sal_uInt32)((sal_uInt8)(RED)))<<16) | \ + (((sal_uInt32)((sal_uInt8)(TRANSPARENCE)))<<24)) -#define RGB_COLORDATA( r,g,b ) ((ColorData)(((sal_uInt32)((sal_uInt8)(b))))|(((sal_uInt32)((sal_uInt8)(g)))<<8)|(((sal_uInt32)((sal_uInt8)(r)))<<16)) +#define RGB_COLORDATA( r,g,b ) TRGB_COLORDATA(0, r, g, b) #define COLORDATA_RED( n ) ((sal_uInt8)((n)>>16)) #define COLORDATA_GREEN( n ) ((sal_uInt8)(((sal_uInt16)(n)) >> 8)) commit a82e0191736f88a8fc31ef4f6c926011192a591e Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Jun 7 18:33:34 2016 +0900 vcl: add "color channel bitcount" for an bitmap buffer (Linux) In addition to "bitcount" on bitmap buffer, which represents the number of bits one pixel takes, we also need the bitcount that the color channels take of one pixel take. For example RGB can be contined in 32 bits (because that the underlaying buffer supports) In this case GetBitCount returns 32bit so we can traverse the buffer correctly. However, we also need to know the bitcount of the actual color channels - in this case this would be 24 bits. Change-Id: I0a64928336540dc66d60659c46d64f369e786c3a diff --git a/include/vcl/salbtype.hxx b/include/vcl/salbtype.hxx index 04baf90..25f4159 100644 --- a/include/vcl/salbtype.hxx +++ b/include/vcl/salbtype.hxx @@ -267,7 +267,18 @@ struct VCL_DLLPUBLIC BitmapBuffer long mnWidth; long mnHeight; long mnScanlineSize; + + /** + * Bitcount of one pixel in the buffer. + * color + alpha channels with padding (for example in an RGBX format) + */ sal_uInt16 mnBitCount; + + /** + * Bitcount color channels of one pixel. + * color + alpha channels only (i.e. 8, 16, 24, 32) + */ + sal_uInt16 mnColorChannelBitCount; ColorMask maColorMask; BitmapPalette maPalette; sal_uInt8* mpBits; diff --git a/vcl/headless/svpbmp.cxx b/vcl/headless/svpbmp.cxx index 202d63c..1dc6c19 100644 --- a/vcl/headless/svpbmp.cxx +++ b/vcl/headless/svpbmp.cxx @@ -70,6 +70,7 @@ BitmapBuffer* ImplCreateDIB( { const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0; + pDIB->mnColorChannelBitCount = nBitCount; switch (nBitCount) { case 1: @@ -229,16 +230,14 @@ Size SvpSalBitmap::GetSize() const return aSize; } -sal_uInt16 SvpSalBitmap::GetBitCount() const +sal_uInt16 SvpSalBitmap::GetColorChannelBitCount() const { - sal_uInt16 nBitCount; - - if (mpDIB) - nBitCount = mpDIB->mnBitCount; - else - nBitCount = 0; + return (mpDIB) ? mpDIB->mnColorChannelBitCount : 0; +} - return nBitCount; +sal_uInt16 SvpSalBitmap::GetBitCount() const +{ + return (mpDIB) ? mpDIB->mnBitCount : 0; } BitmapBuffer* SvpSalBitmap::AcquireBuffer(BitmapAccessMode) diff --git a/vcl/inc/headless/svpbmp.hxx b/vcl/inc/headless/svpbmp.hxx index af50ecf..8e90399 100644 --- a/vcl/inc/headless/svpbmp.hxx +++ b/vcl/inc/headless/svpbmp.hxx @@ -52,6 +52,7 @@ public: virtual void Destroy() final override; virtual Size GetSize() const override; virtual sal_uInt16 GetBitCount() const override; + virtual sal_uInt16 GetColorChannelBitCount() const override; virtual BitmapBuffer* AcquireBuffer( BitmapAccessMode nMode ) override; virtual void ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode ) override; diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx index d10129c..4579e34 100644 --- a/vcl/inc/opengl/salbmp.hxx +++ b/vcl/inc/opengl/salbmp.hxx @@ -68,6 +68,7 @@ public: Size GetSize() const override; sal_uInt16 GetBitCount() const override; + sal_uInt16 GetColorChannelBitCount() const override; BitmapBuffer* AcquireBuffer( BitmapAccessMode nMode ) override; void ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode ) override; diff --git a/vcl/inc/salbmp.hxx b/vcl/inc/salbmp.hxx index 69d2539..91e4e5c 100644 --- a/vcl/inc/salbmp.hxx +++ b/vcl/inc/salbmp.hxx @@ -61,6 +61,7 @@ public: virtual void Destroy() = 0; virtual Size GetSize() const = 0; virtual sal_uInt16 GetBitCount() const = 0; + virtual sal_uInt16 GetColorChannelBitCount() const = 0; virtual BitmapBuffer* AcquireBuffer( BitmapAccessMode nMode ) = 0; virtual void ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode ) = 0; diff --git a/vcl/inc/unx/salbmp.h b/vcl/inc/unx/salbmp.h index 81998ba..a1cc20c 100644 --- a/vcl/inc/unx/salbmp.h +++ b/vcl/inc/unx/salbmp.h @@ -139,6 +139,7 @@ public: virtual Size GetSize() const override; virtual sal_uInt16 GetBitCount() const override; + virtual sal_uInt16 GetColorChannelBitCount() const override; virtual BitmapBuffer* AcquireBuffer( BitmapAccessMode nMode ) override; virtual void ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode ) override; diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx index bce9fb7..2d33178 100644 --- a/vcl/opengl/salbmp.cxx +++ b/vcl/opengl/salbmp.cxx @@ -627,6 +627,11 @@ sal_uInt16 OpenGLSalBitmap::GetBitCount() const return mnBits; } +sal_uInt16 OpenGLSalBitmap::GetColorChannelBitCount() const +{ + return mnBits; +} + bool OpenGLSalBitmap::calcChecksumGL(OpenGLTexture& rInputTexture, ChecksumType& rChecksum) const { OUString FragShader("areaHashCRC64TFragmentShader"); diff --git a/vcl/source/gdi/impbmp.cxx b/vcl/source/gdi/impbmp.cxx index ab06a71..e232b50 100644 --- a/vcl/source/gdi/impbmp.cxx +++ b/vcl/source/gdi/impbmp.cxx @@ -73,9 +73,15 @@ Size ImpBitmap::ImplGetSize() const sal_uInt16 ImpBitmap::ImplGetBitCount() const { - sal_uInt16 nBitCount = mpSalBitmap->GetBitCount(); - return ( nBitCount <= 4 ) ? ( ( nBitCount <= 1 ) ? 1 : 4 ): - ( ( nBitCount <= 8 ) ? 8 : 24); + sal_uInt16 nBitCount = mpSalBitmap->GetColorChannelBitCount(); + if (nBitCount <= 1) + return 1; + else if (nBitCount <= 4) + return 4; + else if (nBitCount <= 8) + return 8; + else + return 24; } BitmapBuffer* ImpBitmap::ImplAcquireBuffer( BitmapAccessMode nMode ) diff --git a/vcl/unx/generic/gdi/salbmp.cxx b/vcl/unx/generic/gdi/salbmp.cxx index 158a2f5..844c9c7 100644 --- a/vcl/unx/generic/gdi/salbmp.cxx +++ b/vcl/unx/generic/gdi/salbmp.cxx @@ -148,7 +148,7 @@ BitmapBuffer* X11SalBitmap::ImplCreateDIB( if( pDIB ) { const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0; - + pDIB->mnColorChannelBitCount = nBitCount; pDIB->mnFormat = ScanlineFormat::NONE; switch( nBitCount ) @@ -259,6 +259,7 @@ BitmapBuffer* X11SalBitmap::ImplCreateDIB( aSrcBuf.mnWidth = nWidth; aSrcBuf.mnHeight = nHeight; aSrcBuf.mnBitCount = pImage->bits_per_pixel; + aSrcBuf.mnColorChannelBitCount = aSrcBuf.mnBitCount; aSrcBuf.mnScanlineSize = pImage->bytes_per_line; aSrcBuf.mpBits = reinterpret_cast<sal_uInt8*>(pImage->data); @@ -847,6 +848,11 @@ sal_uInt16 X11SalBitmap::GetBitCount() const return nBitCount; } +sal_uInt16 X11SalBitmap::GetColorChannelBitCount() const +{ + return GetBitCount(); +} + BitmapBuffer* X11SalBitmap::AcquireBuffer( BitmapAccessMode /*nMode*/ ) { if( !mpDIB && mpDDB ) commit 37de228a696695408131a3969608b993a3d41558 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Jun 5 18:58:58 2016 +0900 Alpha channel in BitmapColor - change bIndex to alpha We what to store the alpha channel in BitmapColor. To achieve this we can repurpose bIndex attribute for alpha. Generally we don't need bIndex at all as we can infer if we use index colors or not from the context. Change-Id: I18fe748beeca59e2869368a1c3c2ee9d2062b41e diff --git a/canvas/source/cairo/cairo_canvashelper.cxx b/canvas/source/cairo/cairo_canvashelper.cxx index b2f673b..5b0baed 100644 --- a/canvas/source/cairo/cairo_canvashelper.cxx +++ b/canvas/source/cairo/cairo_canvashelper.cxx @@ -328,22 +328,6 @@ namespace cairocanvas return ::BitmapEx(); } - static sal_uInt8 lcl_GetColor(BitmapColor const& rColor) - { - sal_uInt8 nTemp(0); - if (rColor.IsIndex()) - { - nTemp = rColor.GetIndex(); - } - else - { - nTemp = rColor.GetBlue(); - // greyscale expected here, or what would non-grey colors mean? - assert(rColor.GetRed() == nTemp && rColor.GetGreen() == nTemp); - } - return nTemp; - } - static bool readAlpha( BitmapReadAccess* pAlphaReadAcc, long nY, const long nWidth, unsigned char* data, long nOff ) { bool bIsAlpha = false; @@ -372,7 +356,7 @@ namespace cairocanvas BitmapColor const& rColor( pAlphaReadAcc->GetPaletteColor(*pReadScan)); pReadScan++; - nAlpha = data[ nOff ] = 255 - lcl_GetColor(rColor); + nAlpha = data[ nOff ] = 255 - rColor.GetBlueOrIndex(); if( nAlpha != 255 ) bIsAlpha = true; nOff += 4; diff --git a/include/vcl/alpha.hxx b/include/vcl/alpha.hxx index 9e3f497..3d227ba 100644 --- a/include/vcl/alpha.hxx +++ b/include/vcl/alpha.hxx @@ -73,6 +73,8 @@ public: typedef vcl::ScopedBitmapAccess< BitmapWriteAccess, AlphaMask, &AlphaMask::AcquireWriteAccess > ScopedWriteAccess; + using Bitmap::IsEmpty; + private: friend class BitmapEx; friend class ::OutputDevice; diff --git a/include/vcl/salbtype.hxx b/include/vcl/salbtype.hxx index a40f24f..04baf90 100644 --- a/include/vcl/salbtype.hxx +++ b/include/vcl/salbtype.hxx @@ -98,20 +98,17 @@ private: sal_uInt8 mcBlueOrIndex; sal_uInt8 mcGreen; sal_uInt8 mcRed; - sal_uInt8 mbIndex; // should be bool, but see above warning - + sal_uInt8 mcAlpha; public: inline BitmapColor(); - inline BitmapColor( sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue ); + inline BitmapColor( sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue, sal_uInt8 cAlpha = 0 ); inline BitmapColor( const Color& rColor ); explicit inline BitmapColor( sal_uInt8 cIndex ); inline bool operator==( const BitmapColor& rBitmapColor ) const; inline bool operator!=( const BitmapColor& rBitmapColor ) const; - inline bool IsIndex() const; - inline sal_uInt8 GetRed() const; inline void SetRed( sal_uInt8 cRed ); @@ -124,6 +121,9 @@ public: inline sal_uInt8 GetIndex() const; inline void SetIndex( sal_uInt8 cIndex ); + inline sal_uInt8 GetAlpha() const; + inline void SetAlpha( sal_uInt8 cAlpha ); + operator Color() const; inline sal_uInt8 GetBlueOrIndex() const; @@ -288,15 +288,15 @@ inline BitmapColor::BitmapColor() : mcBlueOrIndex ( 0 ), mcGreen ( 0 ), mcRed ( 0 ), - mbIndex ( sal_uInt8(false) ) + mcAlpha ( 0 ) { } -inline BitmapColor::BitmapColor( sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue ) : +inline BitmapColor::BitmapColor( sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue, sal_uInt8 cAlpha ) : mcBlueOrIndex ( cBlue ), mcGreen ( cGreen ), mcRed ( cRed ), - mbIndex ( sal_uInt8(false) ) + mcAlpha ( cAlpha ) { } @@ -304,7 +304,7 @@ inline BitmapColor::BitmapColor( const Color& rColor ) : mcBlueOrIndex ( rColor.GetBlue() ), mcGreen ( rColor.GetGreen() ), mcRed ( rColor.GetRed() ), - mbIndex ( sal_uInt8(false) ) + mcAlpha ( rColor.GetTransparency() ) { } @@ -312,15 +312,16 @@ inline BitmapColor::BitmapColor( sal_uInt8 cIndex ) : mcBlueOrIndex ( cIndex ), mcGreen ( 0 ), mcRed ( 0 ), - mbIndex ( sal_uInt8(true) ) + mcAlpha ( 0 ) { } inline bool BitmapColor::operator==( const BitmapColor& rBitmapColor ) const { - return( ( mcBlueOrIndex == rBitmapColor.mcBlueOrIndex ) && - ( mbIndex ? bool(rBitmapColor.mbIndex) : - ( mcGreen == rBitmapColor.mcGreen && mcRed == rBitmapColor.mcRed ) ) ); + return mcBlueOrIndex == rBitmapColor.mcBlueOrIndex && + mcGreen == rBitmapColor.mcGreen && + mcRed == rBitmapColor.mcRed && + mcAlpha == rBitmapColor.mcAlpha; } inline bool BitmapColor::operator!=( const BitmapColor& rBitmapColor ) const @@ -328,63 +329,59 @@ inline bool BitmapColor::operator!=( const BitmapColor& rBitmapColor ) const return !( *this == rBitmapColor ); } -inline bool BitmapColor::IsIndex() const -{ - return mbIndex; -} - inline sal_uInt8 BitmapColor::GetRed() const { - assert( !mbIndex && "Pixel represents index into colortable" ); return mcRed; } inline void BitmapColor::SetRed( sal_uInt8 cRed ) { - assert( !mbIndex && "Pixel represents index into colortable" ); mcRed = cRed; } inline sal_uInt8 BitmapColor::GetGreen() const { - assert( !mbIndex && "Pixel represents index into colortable" ); return mcGreen; } inline void BitmapColor::SetGreen( sal_uInt8 cGreen ) { - assert( !mbIndex && "Pixel represents index into colortable" ); mcGreen = cGreen; } inline sal_uInt8 BitmapColor::GetBlue() const { - assert( !mbIndex && "Pixel represents index into colortable" ); return mcBlueOrIndex; } inline void BitmapColor::SetBlue( sal_uInt8 cBlue ) { - assert( !mbIndex && "Pixel represents index into colortable" ); mcBlueOrIndex = cBlue; } inline sal_uInt8 BitmapColor::GetIndex() const { - assert( mbIndex && "Pixel represents color values" ); return mcBlueOrIndex; } inline void BitmapColor::SetIndex( sal_uInt8 cIndex ) { - assert( mbIndex && "Pixel represents color values" ); mcBlueOrIndex = cIndex; } +inline sal_uInt8 BitmapColor::GetAlpha() const +{ + return mcAlpha; +} + +inline void BitmapColor::SetAlpha( sal_uInt8 cAlpha ) +{ + mcAlpha = cAlpha; +} + inline BitmapColor::operator Color() const { - assert( !mbIndex && "Pixel represents index into colortable" ); - return Color( mcRed, mcGreen, mcBlueOrIndex ); + return Color(mcAlpha, mcRed, mcGreen, mcBlueOrIndex); } inline sal_uInt8 BitmapColor::GetBlueOrIndex() const @@ -395,7 +392,6 @@ inline sal_uInt8 BitmapColor::GetBlueOrIndex() const inline BitmapColor& BitmapColor::Invert() { - assert( !mbIndex && "Pixel represents index into colortable" ); mcBlueOrIndex = ~mcBlueOrIndex; mcGreen = ~mcGreen; mcRed = ~mcRed; @@ -405,15 +401,12 @@ inline BitmapColor& BitmapColor::Invert() inline sal_uInt8 BitmapColor::GetLuminance() const { - assert( !mbIndex && "Pixel represents index into colortable" ); return (static_cast<unsigned long>(mcBlueOrIndex) * 28UL + static_cast<unsigned long>(mcGreen) * 151UL + static_cast<unsigned long>(mcRed) * 77UL) >> 8; } inline BitmapColor& BitmapColor::Merge( const BitmapColor& rBitmapColor, sal_uInt8 cTransparency ) { - assert( !mbIndex && "Pixel represents index into colortable" ); - assert( !rBitmapColor.mbIndex && "Pixel represents index into colortable" ); mcBlueOrIndex = COLOR_CHANNEL_MERGE( mcBlueOrIndex, rBitmapColor.mcBlueOrIndex, cTransparency ); mcGreen = COLOR_CHANNEL_MERGE( mcGreen, rBitmapColor.mcGreen, cTransparency ); mcRed = COLOR_CHANNEL_MERGE( mcRed, rBitmapColor.mcRed, cTransparency ); @@ -424,8 +417,6 @@ inline BitmapColor& BitmapColor::Merge( const BitmapColor& rBitmapColor, sal_uIn inline sal_uInt16 BitmapColor::GetColorError( const BitmapColor& rBitmapColor ) const { - assert( !mbIndex && "Pixel represents index into colortable" ); - assert( !rBitmapColor.mbIndex && "Pixel represents index into colortable" ); return static_cast<sal_uInt16>( abs( static_cast<int>(mcBlueOrIndex) - static_cast<int>(rBitmapColor.mcBlueOrIndex) ) + abs( static_cast<int>(mcGreen) - static_cast<int>(rBitmapColor.mcGreen) ) + diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx index 35b31fd..bc36366 100644 --- a/vcl/qa/cppunit/BitmapTest.cxx +++ b/vcl/qa/cppunit/BitmapTest.cxx @@ -36,6 +36,7 @@ class BitmapTest : public CppUnit::TestFixture void testConvert(); void testScale(); void testCRC(); + void testBitmap32(); CPPUNIT_TEST_SUITE(BitmapTest); CPPUNIT_TEST(testConvert); diff --git a/vcl/source/gdi/bmpacc2.cxx b/vcl/source/gdi/bmpacc2.cxx index 8501f00..72c569a 100644 --- a/vcl/source/gdi/bmpacc2.cxx +++ b/vcl/source/gdi/bmpacc2.cxx @@ -79,11 +79,7 @@ BitmapColor BitmapReadAccess::GetPixelForN8BitPal(ConstScanline pScanline, long void BitmapReadAccess::SetPixelForN8BitPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&) { - if (rBitmapColor.IsIndex()) - pScanline[ nX ] = rBitmapColor.GetIndex(); - else - // Let's hope that the RGB color values equal, so it doesn't matter what do we pick - pScanline[ nX ] = rBitmapColor.GetBlueOrIndex(); + pScanline[ nX ] = rBitmapColor.GetBlueOrIndex(); } BitmapColor BitmapReadAccess::GetPixelForN8BitTcMask(ConstScanline pScanline, long nX, const ColorMask& rMask) diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx index 0a7c849..f08b058 100644 --- a/vcl/unx/generic/print/genpspgraphics.cxx +++ b/vcl/unx/generic/print/genpspgraphics.cxx @@ -77,8 +77,8 @@ private: Scanline mpScanAccess; sal_PtrDiff mnScanOffset; - sal_uInt32 ColorOf (BitmapColor& rColor) const; - sal_uInt8 GrayOf (BitmapColor& rColor) const; + sal_uInt32 ColorOf (BitmapColor& rColor, bool bIndex) const; + sal_uInt8 GrayOf (BitmapColor& rColor, bool bIndex) const; public: @@ -189,10 +189,10 @@ SalPrinterBmp::GetDepth () const } sal_uInt32 -SalPrinterBmp::ColorOf (BitmapColor& rColor) const +SalPrinterBmp::ColorOf(BitmapColor& rColor, bool bIndex) const { - if (rColor.IsIndex()) - return ColorOf (mpBmpBuffer->maPalette[rColor.GetIndex()]); + if (bIndex) + return ColorOf(mpBmpBuffer->maPalette[rColor.GetIndex()], false); else return ((rColor.GetBlue()) & 0x000000ff) | ((rColor.GetGreen() << 8) & 0x0000ff00) @@ -200,10 +200,10 @@ SalPrinterBmp::ColorOf (BitmapColor& rColor) const } sal_uInt8 -SalPrinterBmp::GrayOf (BitmapColor& rColor) const +SalPrinterBmp::GrayOf(BitmapColor& rColor, bool bIndex) const { - if (rColor.IsIndex()) - return GrayOf (mpBmpBuffer->maPalette[rColor.GetIndex()]); + if (bIndex) + return GrayOf(mpBmpBuffer->maPalette[rColor.GetIndex()], false); else return ( rColor.GetBlue() * 28UL + rColor.GetGreen() * 151UL @@ -213,13 +213,13 @@ SalPrinterBmp::GrayOf (BitmapColor& rColor) const sal_uInt32 SalPrinterBmp::GetPaletteEntryCount () const { - return mpBmpBuffer->maPalette.GetEntryCount (); + return mpBmpBuffer->maPalette.GetEntryCount(); } sal_uInt32 SalPrinterBmp::GetPaletteColor (sal_uInt32 nIdx) const { - return ColorOf (mpBmpBuffer->maPalette[nIdx]); + return ColorOf(mpBmpBuffer->maPalette[nIdx], false); } sal_uInt32 @@ -228,7 +228,7 @@ SalPrinterBmp::GetPixelRGB (sal_uInt32 nRow, sal_uInt32 nColumn) const Scanline pScan = mpScanAccess + nRow * mnScanOffset; BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask); - return ColorOf (aColor); + return ColorOf(aColor, !!mpBmpBuffer->maPalette); } sal_uInt8 @@ -237,7 +237,7 @@ SalPrinterBmp::GetPixelGray (sal_uInt32 nRow, sal_uInt32 nColumn) const Scanline pScan = mpScanAccess + nRow * mnScanOffset; BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask); - return GrayOf (aColor); + return GrayOf(aColor, !!mpBmpBuffer->maPalette); } sal_uInt8 @@ -246,7 +246,7 @@ SalPrinterBmp::GetPixelIdx (sal_uInt32 nRow, sal_uInt32 nColumn) const Scanline pScan = mpScanAccess + nRow * mnScanOffset; BitmapColor aColor = mpFncGetPixel (pScan, nColumn, mpBmpBuffer->maColorMask); - if (aColor.IsIndex()) + if (!!mpBmpBuffer->maPalette) return aColor.GetIndex(); else return 0; commit a5f8c5f9338e140c8ec3198228917a8a1a54dc35 Author: Justin Luth <justin_l...@sil.org> Date: Sat Nov 5 15:40:29 2016 +0300 make a useful function - SvxBoxItem::CalcLineWidth It saves lots of extra code: no separately checking if a line exists, and then getting the width. Closely matches the existing CalcLineSpace. sc/source/ui/view/printfun.cxx is another place that could use this heavily to replace their lcl_LineTotal function. Perhaps something good for an easyHack. (Wait until LO5.4, since much of the logic should use CalcLineSpace(,true) instead, and that function probably will have the default bEvenIfNoLine changed to true. Compiler doesn't like providing "true" when the default value is also "true".) Change-Id: I298d057b2bf04959434736f6ab2666d2de4222f9 Reviewed-on: https://gerrit.libreoffice.org/30589 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Justin Luth <justin_l...@sil.org> diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx index ffd0caf..7de28e3 100644 --- a/editeng/source/items/frmitems.cxx +++ b/editeng/source/items/frmitems.cxx @@ -2420,6 +2420,33 @@ void SvxBoxItem::SetDistance( sal_uInt16 nNew, SvxBoxItemLine nLine ) } } +sal_uInt16 SvxBoxItem::CalcLineWidth( SvxBoxItemLine nLine ) const +{ + SvxBorderLine* pTmp = nullptr; + sal_uInt16 nWidth = 0; + switch ( nLine ) + { + case SvxBoxItemLine::TOP: + pTmp = pTop; + break; + case SvxBoxItemLine::BOTTOM: + pTmp = pBottom; + break; + case SvxBoxItemLine::LEFT: + pTmp = pLeft; + break; + case SvxBoxItemLine::RIGHT: + pTmp = pRight; + break; + default: + OSL_FAIL( "wrong line" ); + } + + if( pTmp ) + nWidth = pTmp->GetScaledWidth(); + + return nWidth; +} sal_uInt16 SvxBoxItem::CalcLineSpace( SvxBoxItemLine nLine, bool bEvenIfNoLine ) const { diff --git a/include/editeng/boxitem.hxx b/include/editeng/boxitem.hxx index 00227a4..a63d4a1 100644 --- a/include/editeng/boxitem.hxx +++ b/include/editeng/boxitem.hxx @@ -110,6 +110,7 @@ public: // Line width plus Space plus inward distance // bEvenIfNoLine = TRUE -> Also return distance, when no Line is set + sal_uInt16 CalcLineWidth( SvxBoxItemLine nLine ) const; sal_uInt16 CalcLineSpace( SvxBoxItemLine nLine, bool bEvenIfNoLine = false ) const; bool HasBorder( bool bTreatPaddingAsBorder = false ) const; static css::table::BorderLine2 SvxLineToLine( const editeng::SvxBorderLine* pLine, bool bConvert ); diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx index b20d5e2..35059e4 100644 --- a/sw/source/filter/ww8/ww8graf.cxx +++ b/sw/source/filter/ww8/ww8graf.cxx @@ -1678,26 +1678,10 @@ void SwWW8ImplReader::MatchSdrItemsIntoFlySet( SdrObject* pSdrObj, rInnerDist.Right()+=nLineThick; rInnerDist.Bottom()+=nLineThick; - const SvxBorderLine *pLine; - if (nullptr != (pLine = aBox.GetLine(SvxBoxItemLine::LEFT))) - { - rInnerDist.Left() -= (pLine->GetScaledWidth()); - } - - if (nullptr != (pLine = aBox.GetLine(SvxBoxItemLine::TOP))) - { - rInnerDist.Top() -= (pLine->GetScaledWidth()); - } - - if (nullptr != (pLine = aBox.GetLine(SvxBoxItemLine::RIGHT))) - { - rInnerDist.Right() -= (pLine->GetScaledWidth()); - } - - if (nullptr != (pLine = aBox.GetLine(SvxBoxItemLine::BOTTOM))) - { - rInnerDist.Bottom() -= (pLine->GetScaledWidth()); - } + rInnerDist.Left() -= aBox.CalcLineWidth( SvxBoxItemLine::LEFT ); + rInnerDist.Top() -= aBox.CalcLineWidth( SvxBoxItemLine::TOP ); + rInnerDist.Right() -= aBox.CalcLineWidth( SvxBoxItemLine::RIGHT ); + rInnerDist.Bottom() -= aBox.CalcLineWidth( SvxBoxItemLine::BOTTOM ); // set distances from box's border to text contained within the box if( 0 < rInnerDist.Left() ) diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx index 0f9f245..d737553 100644 --- a/sw/source/filter/ww8/ww8par2.cxx +++ b/sw/source/filter/ww8/ww8par2.cxx @@ -3231,21 +3231,11 @@ void WW8TabDesc::AdjustNewBand() // we have to mimic this in the filter by picking the larger of the // sides and using that one on one side of the line (right) SvxBoxItem aCurrentBox(sw::util::ItemGet<SvxBoxItem>(*(pBox->GetFrameFormat()), RES_BOX)); - const ::editeng::SvxBorderLine *pLeftLine = aCurrentBox.GetLine(SvxBoxItemLine::LEFT); - int nCurrentRightLineWidth = 0; - if(pLeftLine) - nCurrentRightLineWidth = pLeftLine->GetScaledWidth(); - if (i != 0) { SwTableBox* pBox2 = (*m_pTabBoxes)[i-1]; SvxBoxItem aOldBox(sw::util::ItemGet<SvxBoxItem>(*(pBox2->GetFrameFormat()), RES_BOX)); - const ::editeng::SvxBorderLine *pRightLine = aOldBox.GetLine(SvxBoxItemLine::RIGHT); - int nOldBoxRightLineWidth = 0; - if(pRightLine) - nOldBoxRightLineWidth = pRightLine->GetScaledWidth(); - - if(nOldBoxRightLineWidth>nCurrentRightLineWidth) + if( aOldBox.CalcLineWidth(SvxBoxItemLine::RIGHT) > aCurrentBox.CalcLineWidth(SvxBoxItemLine::LEFT) ) aCurrentBox.SetLine(aOldBox.GetLine(SvxBoxItemLine::RIGHT), SvxBoxItemLine::LEFT); aOldBox.SetLine(nullptr, SvxBoxItemLine::RIGHT); commit db380aab1063e8a5e40111c40ee9f7921aa82601 Author: Norbert Thiebaud <nthieb...@gmail.com> Date: Sat Nov 5 13:28:17 2016 -0500 Reverts a commit series that cripple windows ci. Revert "SvxShadowTabPage::Construct was removed" f9a2c1c12ecad833c63b894c89d6008907477eb5. Revert "replace OColorPopup with SvxColorWindow" f300754bb1c6a347c92bb9548be7a65237176542. Revert "drop AutoColorInvalid/SID_ATTR_AUTO_COLOR_INVALID" 347c2c334589b18cc62af292674bb3df1dd54b71. Revert "replace last ColorLB use with a listbox of colors" 604b35bf55351751a396e34dcca3f85e75860fd5. Revert "simplify, its just a vector of colors" 351a97ce6bda3075677b59fa1387ba3d1ab17d7a. Revert "replace user draw with an Image of the color" df738e0f8ceedb4bad756960be14d9c41adc165d. Revert "strip down to the used pieces" commit 08d6cd788f2584ce10ab8fa10665245e953c59d9. Revert "move now combined ColorLB to location of last user" a19b18ad7c9eb0197c10e6d7e451ec4542e4bc9e. Revert "fold ColorListBox and ColorLB together" a989a0b1f2b425f05b58d0e44ce2de31c842ed65. Revert "move ColorListBox beside sole thing that uses it" 760a198e697f3070a5e0e029e4eff7be220eb9cd. Revert "extensions leaks out details of Color Selector, patch it up" 8bea644d6117a49405e6426dc97214220fc869d1. Revert "inherit FillAttrLB from ListBox not ColorListBox" d2ce812f1d3a7a2aad89ca0bd11948b63d2db7b0. Revert "unify color selectors" 43bc3031483d172eccd72c3804e2d4fc2ef37de4. diff --git a/chart2/source/controller/dialogs/dlg_View3D.cxx b/chart2/source/controller/dialogs/dlg_View3D.cxx index 7cfd50f..eb0150b 100644 --- a/chart2/source/controller/dialogs/dlg_View3D.cxx +++ b/chart2/source/controller/dialogs/dlg_View3D.cxx @@ -39,7 +39,7 @@ using namespace ::com::sun::star::chart2; sal_uInt16 View3DDialog::m_nLastPageId = 0; -View3DDialog::View3DDialog(vcl::Window* pParent, const uno::Reference< frame::XModel > & xChartModel) +View3DDialog::View3DDialog(vcl::Window* pParent, const uno::Reference< frame::XModel > & xChartModel, const XColorListRef &pColorTable ) : TabDialog(pParent, "3DViewDialog", "modules/schart/ui/3dviewdialog.ui") , m_pGeometry(nullptr) , m_pAppearance(nullptr) @@ -51,7 +51,7 @@ View3DDialog::View3DDialog(vcl::Window* pParent, const uno::Reference< frame::XM uno::Reference< beans::XPropertySet > xSceneProperties( ChartModelHelper::findDiagram( xChartModel ), uno::UNO_QUERY ); m_pGeometry = VclPtr<ThreeD_SceneGeometry_TabPage>::Create(m_pTabControl,xSceneProperties,m_aControllerLocker); m_pAppearance = VclPtr<ThreeD_SceneAppearance_TabPage>::Create(m_pTabControl,xChartModel,m_aControllerLocker); - m_pIllumination = VclPtr<ThreeD_SceneIllumination_TabPage>::Create(m_pTabControl,xSceneProperties,xChartModel); + m_pIllumination = VclPtr<ThreeD_SceneIllumination_TabPage>::Create(m_pTabControl,xSceneProperties,xChartModel,pColorTable); m_pTabControl->InsertPage( TP_3D_SCENEGEOMETRY, SCH_RESSTR(STR_PAGE_PERSPECTIVE) ); m_pTabControl->InsertPage( TP_3D_SCENEAPPEARANCE, SCH_RESSTR(STR_PAGE_APPEARANCE) ); diff --git a/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx b/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx index 40f2857..bdd53ff 100644 --- a/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx +++ b/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx @@ -22,7 +22,6 @@ #include "Bitmaps.hrc" #include "CommonConverters.hxx" -#include <svx/colorbox.hxx> #include "svx/dialogs.hrc" #include <svx/dialmgr.hxx> #include <rtl/math.hxx> @@ -104,7 +103,7 @@ void LightSourceInfo::initButtonFromSource() namespace { - OUString lcl_makeColorName(const Color& rColor) + OUString lcl_makeColorName( Color rColor ) { OUString aStr = SVX_RESSTR(RID_SVXFLOAT3D_FIX_R) + OUString::number(rColor.GetRed()) + @@ -116,11 +115,15 @@ namespace OUString::number(rColor.GetBlue()); return aStr; } - - void lcl_selectColor(SvxColorListBox& rListBox, const Color& rColor) + void lcl_selectColor( ColorListBox& rListBox, const Color& rColor ) { rListBox.SetNoSelection(); - rListBox.SelectEntry(std::make_pair(rColor, lcl_makeColorName(rColor))); + rListBox.SelectEntry( rColor ); + if( rListBox.GetSelectEntryCount() == 0 ) + { + const sal_Int32 nPos = rListBox.InsertEntry( rColor, lcl_makeColorName( rColor ) ); + rListBox.SelectEntryPos( nPos ); + } } ::chart::LightSource lcl_getLightSourceFromProperties( @@ -212,7 +215,8 @@ namespace ThreeD_SceneIllumination_TabPage::ThreeD_SceneIllumination_TabPage( vcl::Window* pWindow , const uno::Reference< beans::XPropertySet > & xSceneProperties - , const uno::Reference< frame::XModel >& xChartModel ) + , const uno::Reference< frame::XModel >& xChartModel + , const XColorListRef & pColorTable ) : TabPage ( pWindow ,"tp_3D_SceneIllumination" ,"modules/schart/ui/tp_3D_SceneIllumination.ui") @@ -238,6 +242,14 @@ ThreeD_SceneIllumination_TabPage::ThreeD_SceneIllumination_TabPage( vcl::Window* get(m_pCtl_Preview, "CTL_LIGHT_PREVIEW"); + if( pColorTable.is() ) + { + m_pLB_AmbientLight->Fill( pColorTable ); + m_pLB_LightSource->Fill( pColorTable ); + } + m_pLB_AmbientLight->SetDropDownLineCount(10); + m_pLB_LightSource->SetDropDownLineCount(10); + m_pLightSourceInfoList = new LightSourceInfo[8]; m_pLightSourceInfoList[0].pButton = m_pBtn_Light1; m_pLightSourceInfoList[1].pButton = m_pBtn_Light2; @@ -396,7 +408,7 @@ IMPL_LINK_NOARG(ThreeD_SceneIllumination_TabPage, PreviewSelectHdl, SvxLightCtl3 IMPL_LINK( ThreeD_SceneIllumination_TabPage, ColorDialogHdl, Button*, pButton, void ) { bool bIsAmbientLight = (pButton==m_pBtn_AmbientLight_Color); - SvxColorListBox* pListBox = ( bIsAmbientLight ? m_pLB_AmbientLight : m_pLB_LightSource); + ColorLB* pListBox = ( bIsAmbientLight ? m_pLB_AmbientLight : m_pLB_LightSource); SvColorDialog aColorDlg( this ); aColorDlg.SetColor( pListBox->GetSelectEntryColor() ); @@ -429,9 +441,9 @@ IMPL_LINK( ThreeD_SceneIllumination_TabPage, ColorDialogHdl, Button*, pButton, v } } -IMPL_LINK( ThreeD_SceneIllumination_TabPage, SelectColorHdl, SvxColorListBox&, rBox, void ) +IMPL_LINK( ThreeD_SceneIllumination_TabPage, SelectColorHdl, ListBox&, rBox, void ) { - SvxColorListBox* pListBox = &rBox; + ColorLB* pListBox = static_cast<ColorLB*>(&rBox); if(pListBox==m_pLB_AmbientLight) { m_bInCommitToModel = true; diff --git a/chart2/source/controller/dialogs/tp_3D_SceneIllumination.hxx b/chart2/source/controller/dialogs/tp_3D_SceneIllumination.hxx index 4251735..515ace1 100644 --- a/chart2/source/controller/dialogs/tp_3D_SceneIllumination.hxx +++ b/chart2/source/controller/dialogs/tp_3D_SceneIllumination.hxx @@ -29,8 +29,6 @@ #include <svx/dlgctrl.hxx> #include <svx/dlgctl3d.hxx> -class SvxColorListBox; - namespace chart { @@ -54,13 +52,14 @@ public: ThreeD_SceneIllumination_TabPage( vcl::Window* pWindow, const css::uno::Reference< css::beans::XPropertySet > & xSceneProperties, - const css::uno::Reference< css::frame::XModel >& xChartModel ); + const css::uno::Reference< css::frame::XModel >& xChartModel, + const XColorListRef &pColorTable ); virtual ~ThreeD_SceneIllumination_TabPage() override; virtual void dispose() override; private: DECL_LINK( ClickLightSourceButtonHdl, Button*, void ); - DECL_LINK( SelectColorHdl, SvxColorListBox&, void ); + DECL_LINK( SelectColorHdl, ListBox&, void ); DECL_LINK( ColorDialogHdl, Button*, void ); DECL_LINK( PreviewChangeHdl, SvxLightCtl3D*, void ); DECL_LINK( PreviewSelectHdl, SvxLightCtl3D*, void ); @@ -82,10 +81,10 @@ private: VclPtr<LightButton> m_pBtn_Light7; VclPtr<LightButton> m_pBtn_Light8; - VclPtr<SvxColorListBox> m_pLB_LightSource; + VclPtr<ColorLB> m_pLB_LightSource; VclPtr<PushButton> m_pBtn_LightSource_Color; - VclPtr<SvxColorListBox> m_pLB_AmbientLight; + VclPtr<ColorLB> m_pLB_AmbientLight; VclPtr<PushButton> m_pBtn_AmbientLight_Color; VclPtr<SvxLightCtl3D> m_pCtl_Preview; diff --git a/chart2/source/controller/inc/dlg_View3D.hxx b/chart2/source/controller/inc/dlg_View3D.hxx index a5646ab..b63ece7 100644 --- a/chart2/source/controller/inc/dlg_View3D.hxx +++ b/chart2/source/controller/inc/dlg_View3D.hxx @@ -38,7 +38,8 @@ class View3DDialog : public TabDialog { public: View3DDialog( vcl::Window* pWindow, - const css::uno::Reference< css::frame::XModel > & xChartModel ); + const css::uno::Reference< css::frame::XModel > & xChartModel, + const XColorListRef &pColorTable ); virtual ~View3DDialog() override; virtual void dispose() override; diff --git a/chart2/source/controller/main/ChartController_Properties.cxx b/chart2/source/controller/main/ChartController_Properties.cxx index 7636aa9..00e7294 100644 --- a/chart2/source/controller/main/ChartController_Properties.cxx +++ b/chart2/source/controller/main/ChartController_Properties.cxx @@ -823,7 +823,7 @@ void ChartController::executeDispatch_View3D() //open dialog SolarMutexGuard aSolarGuard; - ScopedVclPtrInstance< View3DDialog > aDlg(m_pChartWindow, getModel()); + ScopedVclPtrInstance< View3DDialog > aDlg( m_pChartWindow, getModel(), m_pDrawModelWrapper->GetColorList() ); if( aDlg->Execute() == RET_OK ) aUndoGuard.commit(); } diff --git a/chart2/source/controller/sidebar/ChartColorWrapper.cxx b/chart2/source/controller/sidebar/ChartColorWrapper.cxx index ee931d0..b2ff619 100644 --- a/chart2/source/controller/sidebar/ChartColorWrapper.cxx +++ b/chart2/source/controller/sidebar/ChartColorWrapper.cxx @@ -67,12 +67,12 @@ ChartColorWrapper::ChartColorWrapper( { } -void ChartColorWrapper::operator()(const OUString& , const NamedColor& rColor) +void ChartColorWrapper::operator()(const OUString& , const Color& rColor) { css::uno::Reference<css::beans::XPropertySet> xPropSet = getPropSet(mxModel); assert(xPropSet.is()); - xPropSet->setPropertyValue(maPropertyName, css::uno::makeAny(rColor.first.GetColor())); + xPropSet->setPropertyValue(maPropertyName, css::uno::makeAny(rColor.GetColor())); } void ChartColorWrapper::updateModel(const css::uno::Reference<css::frame::XModel>& xModel) diff --git a/chart2/source/controller/sidebar/ChartColorWrapper.hxx b/chart2/source/controller/sidebar/ChartColorWrapper.hxx index b987503..68fb514 100644 --- a/chart2/source/controller/sidebar/ChartColorWrapper.hxx +++ b/chart2/source/controller/sidebar/ChartColorWrapper.hxx @@ -12,7 +12,6 @@ #include <com/sun/star/frame/XFramesSupplier.hpp> #include <tools/color.hxx> -#include <svx/Palette.hxx> class SvxColorToolBoxControl; @@ -27,7 +26,7 @@ public: SvxColorToolBoxControl* pControl, const OUString& rPropertyName); - void operator()(const OUString& rCommand, const NamedColor& rColor); + void operator()(const OUString& rCommand, const Color& rColor); void updateModel(const css::uno::Reference<css::frame::XModel>& xModel); diff --git a/chart2/uiconfig/ui/tp_3D_SceneIllumination.ui b/chart2/uiconfig/ui/tp_3D_SceneIllumination.ui index e445660..7ff9fbf 100644 --- a/chart2/uiconfig/ui/tp_3D_SceneIllumination.ui +++ b/chart2/uiconfig/ui/tp_3D_SceneIllumination.ui @@ -236,7 +236,7 @@ <property name="can_focus">False</property> <property name="spacing">12</property> <child> - <object class="svxlo-SvxColorListBox" id="LB_LIGHTSOURCE"> + <object class="svxlo-ColorLB" id="LB_LIGHTSOURCE"> <property name="visible">True</property> <property name="can_focus">False</property> </object> @@ -310,7 +310,7 @@ <property name="can_focus">False</property> <property name="spacing">12</property> <child> - <object class="svxlo-SvxColorListBox" id="LB_AMBIENTLIGHT"> + <object class="svxlo-ColorLB" id="LB_AMBIENTLIGHT"> <property name="visible">True</property> <property name="can_focus">False</property> </object> diff --git a/cui/source/inc/border.hxx b/cui/source/inc/border.hxx index 915deba..9675b10 100644 --- a/cui/source/inc/border.hxx +++ b/cui/source/inc/border.hxx @@ -25,7 +25,6 @@ #include <vcl/fixed.hxx> #include <svtools/valueset.hxx> #include <sfx2/tabdlg.hxx> -#include <svx/colorbox.hxx> #include <svx/frmsel.hxx> #include <svx/flagsdef.hxx> @@ -73,7 +72,7 @@ private: VclPtr<svx::FrameSelector> m_pFrameSel; VclPtr<LineListBox> m_pLbLineStyle; - VclPtr<SvxColorListBox> m_pLbLineColor; + VclPtr<ColorListBox> m_pLbLineColor; VclPtr<MetricField> m_pLineWidthMF; VclPtr<VclContainer> m_pSpacingFrame; @@ -92,7 +91,7 @@ private: VclPtr<FixedText> m_pFtShadowSize; VclPtr<MetricField> m_pEdShadowSize; VclPtr<FixedText> m_pFtShadowColor; - VclPtr<SvxColorListBox> m_pLbShadowColor; + VclPtr<ColorListBox> m_pLbShadowColor; VclPtr<VclContainer> m_pPropertiesFrame;///< properties - "Merge with next paragraph" in Writer @@ -121,7 +120,7 @@ private: // Handler DECL_LINK( SelStyleHdl_Impl, ListBox&, void ); - DECL_LINK( SelColHdl_Impl, SvxColorListBox&, void ); + DECL_LINK( SelColHdl_Impl, ListBox&, void ); DECL_LINK( SelPreHdl_Impl, ValueSet*, void ); DECL_LINK( SelSdwHdl_Impl, ValueSet*, void ); DECL_LINK( LinesChanged_Impl, LinkParamNone*, void ); diff --git a/cui/source/inc/chardlg.hxx b/cui/source/inc/chardlg.hxx index 484897d..bea73e4 100644 --- a/cui/source/inc/chardlg.hxx +++ b/cui/source/inc/chardlg.hxx @@ -23,7 +23,6 @@ #include <sfx2/tabdlg.hxx> #include <svx/fntctrl.hxx> #include <svx/checklbx.hxx> -#include <svx/colorbox.hxx> #include <svx/langbox.hxx> #include <vcl/layout.hxx> #include <memory> @@ -176,7 +175,7 @@ class SvxCharEffectsPage : public SvxCharBasePage private: static const sal_uInt16 pEffectsRanges[]; VclPtr<FixedText> m_pFontColorFT; - VclPtr<SvxColorListBox> m_pFontColorLB; + VclPtr<ColorListBox> m_pFontColorLB; VclPtr<FixedText> m_pEffectsFT; VclPtr<ListBox> m_pEffectsLB; @@ -191,13 +190,13 @@ private: VclPtr<ListBox> m_pOverlineLB; VclPtr<FixedText> m_pOverlineColorFT; - VclPtr<SvxColorListBox> m_pOverlineColorLB; + VclPtr<ColorListBox> m_pOverlineColorLB; VclPtr<ListBox> m_pStrikeoutLB; VclPtr<ListBox> m_pUnderlineLB; VclPtr<FixedText> m_pUnderlineColorFT; - VclPtr<SvxColorListBox> m_pUnderlineColorLB; + VclPtr<ColorListBox> m_pUnderlineColorLB; VclPtr<CheckBox> m_pIndividualWordsBtn; @@ -211,6 +210,8 @@ private: sal_uInt16 m_nHtmlMode; + OUString m_aTransparentColorName; + SvxCharEffectsPage( vcl::Window* pParent, const SfxItemSet& rSet ); void Initialize(); @@ -224,7 +225,7 @@ private: DECL_LINK(CbClickHdl_Impl, Button*, void); DECL_LINK(TristClickHdl_Impl, Button*, void); DECL_LINK(UpdatePreview_Impl, ListBox&, void); - DECL_LINK(ColorBoxSelectHdl_Impl, SvxColorListBox&, void); + DECL_LINK(ColorBoxSelectHdl_Impl, ListBox&, void); public: virtual ~SvxCharEffectsPage() override; diff --git a/cui/source/inc/cuires.hrc b/cui/source/inc/cuires.hrc index 33f5ea3..0f57cf6 100644 --- a/cui/source/inc/cuires.hrc +++ b/cui/source/inc/cuires.hrc @@ -85,6 +85,7 @@ #define RID_SVXSTR_CONNECTOR (RID_SVX_START + 221) #define RID_SVXSTR_DIMENSION_LINE (RID_SVX_START + 222) +#define RID_SVXSTR_CHARNAME_TRANSPARENT (RID_SVX_START + 237) #define RID_SVXSTR_DESC_LINEEND (RID_SVX_START + 238) #define RID_SVXSTR_CHARNAME_NOSTYLE (RID_SVX_START + 239) #define RID_SVXSTR_CHARNAME_FAMILY (RID_SVX_START + 240) diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx index 362777a..52d4fce 100644 --- a/cui/source/inc/cuitabarea.hxx +++ b/cui/source/inc/cuitabarea.hxx @@ -39,7 +39,6 @@ class SdrModel; class SvxBitmapCtl; -class SvxColorListBox; /************************************************************************/ class ButtonBox @@ -322,7 +321,7 @@ private: VclPtr<VclGrid> m_pGridShadow; VclPtr<SvxRectCtl> m_pCtlPosition; VclPtr<MetricField> m_pMtrDistance; - VclPtr<SvxColorListBox> m_pLbShadowColor; + VclPtr<ColorLB> m_pLbShadowColor; VclPtr<MetricField> m_pMtrTransparent; VclPtr<SvxXShadowPreview> m_pCtlXRectPreview; @@ -341,13 +340,14 @@ private: DECL_LINK( ClickShadowHdl_Impl, Button*, void ); DECL_LINK( ModifyShadowHdl_Impl, Edit&, void ); - DECL_LINK( SelectShadowHdl_Impl, SvxColorListBox&, void ); + DECL_LINK( SelectShadowHdl_Impl, ListBox&, void ); public: SvxShadowTabPage( vcl::Window* pParent, const SfxItemSet& rInAttrs ); virtual ~SvxShadowTabPage() override; virtual void dispose() override; + void Construct(); static VclPtr<SfxTabPage> Create( vcl::Window*, const SfxItemSet* ); static const sal_uInt16* GetRanges() { return pShadowRanges; } @@ -381,9 +381,9 @@ private: VclPtr<MetricField> m_pMtrAngle; VclPtr<MetricField> m_pMtrBorder; VclPtr<Slider> m_pSliderBorder; - VclPtr<SvxColorListBox> m_pLbColorFrom; + VclPtr<ColorLB> m_pLbColorFrom; VclPtr<MetricField> m_pMtrColorFrom; - VclPtr<SvxColorListBox> m_pLbColorTo; + VclPtr<ColorLB> m_pLbColorTo; VclPtr<MetricField> m_pMtrColorTo; VclPtr<SvxPresetListBox> m_pGradientLB; VclPtr<NumericField> m_pMtrIncrement; @@ -413,7 +413,6 @@ private: DECL_LINK( ClickRenameHdl_Impl, SvxPresetListBox*, void ); DECL_LINK( ClickDeleteHdl_Impl, SvxPresetListBox*, void ); DECL_LINK( ModifiedEditHdl_Impl, Edit&, void ); - DECL_LINK( ModifiedColorListBoxHdl_Impl, SvxColorListBox&, void ); DECL_LINK( ModifiedListBoxHdl_Impl, ListBox&, void ); DECL_LINK( ChangeAutoStepHdl_Impl, CheckBox&, void ); DECL_LINK( ModifiedSliderHdl_Impl, Slider*, void ); @@ -456,9 +455,9 @@ private: VclPtr<MetricField> m_pMtrAngle; VclPtr<Slider> m_pSliderAngle; VclPtr<ListBox> m_pLbLineType; - VclPtr<SvxColorListBox> m_pLbLineColor; + VclPtr<ColorLB> m_pLbLineColor; VclPtr<CheckBox> m_pCbBackgroundColor; - VclPtr<SvxColorListBox> m_pLbBackgroundColor; + VclPtr<ColorLB> m_pLbBackgroundColor; VclPtr<SvxPresetListBox> m_pHatchLB; VclPtr<SvxXRectPreview> m_pCtlPreview; VclPtr<PushButton> m_pBtnAdd; @@ -484,9 +483,8 @@ private: void ChangeHatchHdl_Impl(); DECL_LINK( ModifiedEditHdl_Impl, Edit&, void ); DECL_LINK( ModifiedListBoxHdl_Impl, ListBox&, void ); - DECL_LINK( ModifiedColorListBoxHdl_Impl, SvxColorListBox&, void ); DECL_LINK( ToggleHatchBackgroundColor_Impl, CheckBox&, void ); - DECL_LINK( ModifiedBackgroundHdl_Impl, SvxColorListBox&, void ); + DECL_LINK( ModifiedBackgroundHdl_Impl, ListBox&, void ); DECL_LINK( ModifiedSliderHdl_Impl, Slider*, void ); void ModifiedHdl_Impl(void*); DECL_LINK( ClickAddHdl_Impl, Button*, void ); @@ -615,8 +613,8 @@ class SvxPatternTabPage : public SvxTabPage private: VclPtr<VclBox> m_pBxPixelEditor; VclPtr<SvxPixelCtl> m_pCtlPixel; - VclPtr<SvxColorListBox> m_pLbColor; - VclPtr<SvxColorListBox> m_pLbBackgroundColor; + VclPtr<ColorLB> m_pLbColor; + VclPtr<ColorLB> m_pLbBackgroundColor; VclPtr<SvxPresetListBox> m_pPatternLB; VclPtr<SvxXRectPreview> m_pCtlPreview; VclPtr<PushButton> m_pBtnAdd; @@ -644,7 +642,7 @@ private: DECL_LINK( ClickAddHdl_Impl, Button*, void ); DECL_LINK( ClickModifyHdl_Impl, Button*, void ); DECL_LINK( ChangePatternHdl_Impl, ValueSet*, void ); - DECL_LINK( ChangeColorHdl_Impl, SvxColorListBox&, void ); + DECL_LINK( ChangeColorHdl_Impl, ListBox&, void ); DECL_LINK( ClickRenameHdl_Impl, SvxPresetListBox*, void ); DECL_LINK( ClickDeleteHdl_Impl, SvxPresetListBox*, void ); diff --git a/cui/source/inc/cuitabline.hxx b/cui/source/inc/cuitabline.hxx index 39e7498..957b421 100644 --- a/cui/source/inc/cuitabline.hxx +++ b/cui/source/inc/cuitabline.hxx @@ -25,7 +25,6 @@ #include <svx/tabarea.hxx> enum class PageType; -class SvxColorListBox; class SvxLineTabDialog : public SfxTabDialog { @@ -93,7 +92,7 @@ class SvxLineTabPage : public SvxTabPage private: VclPtr<VclBox> m_pBoxColor; VclPtr<LineLB> m_pLbLineStyle; - VclPtr<SvxColorListBox> m_pLbColor; + VclPtr<ColorLB> m_pLbColor; VclPtr<VclBox> m_pBoxWidth; VclPtr<MetricField> m_pMtrLineWidth; VclPtr<VclBox> m_pBoxTransparency; @@ -183,7 +182,7 @@ private: DECL_LINK( ChangeEndModifyHdl_Impl, Edit&, void ); DECL_LINK( ChangeEndClickHdl_Impl, Button*, void ); void ChangeEndHdl_Impl(void*); - DECL_LINK( ChangePreviewListBoxHdl_Impl, SvxColorListBox&, void ); + DECL_LINK( ChangePreviewListBoxHdl_Impl, ListBox&, void ); DECL_LINK( ChangePreviewModifyHdl_Impl, Edit&, void ); void ChangePreviewHdl_Impl(void*); ... etc. - the rest is truncated
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits