From 8db9363c8ef6138d2420366cc4f42ca1d662bdd7 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sun, 14 Apr 2019 18:37:54 +0900 Subject: move octree to bitmap folder, and *octree headers to inc/bitmap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Octree is a tree, that's used for color quantization, so it's better to move it there. Headers are also moved to bitmap subfolder so it's better organized. Change-Id: I2b84a5469c1479cf0a060ba8eb46591dabab2883 Reviewed-on: https://gerrit.libreoffice.org/70726 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- solenv/clang-format/blacklist | 6 +- vcl/Library_vcl.mk | 2 +- vcl/inc/bitmap/Octree.hxx | 119 ++++++++ vcl/inc/bitmap/impoctree.hxx | 147 ++++++++++ vcl/inc/impoctree.hxx | 147 ---------- vcl/inc/octree.hxx | 119 -------- .../bitmap/BitmapSimpleColorQuantizationFilter.cxx | 2 +- vcl/source/bitmap/Octree.cxx | 298 +++++++++++++++++++++ vcl/source/gdi/bitmap3.cxx | 4 +- vcl/source/gdi/octree.cxx | 298 --------------------- 10 files changed, 571 insertions(+), 571 deletions(-) create mode 100644 vcl/inc/bitmap/Octree.hxx create mode 100644 vcl/inc/bitmap/impoctree.hxx delete mode 100644 vcl/inc/impoctree.hxx delete mode 100644 vcl/inc/octree.hxx create mode 100644 vcl/source/bitmap/Octree.cxx delete mode 100644 vcl/source/gdi/octree.cxx diff --git a/solenv/clang-format/blacklist b/solenv/clang-format/blacklist index 830cfe7fa9d8..732fc7c40550 100644 --- a/solenv/clang-format/blacklist +++ b/solenv/clang-format/blacklist @@ -17331,13 +17331,13 @@ vcl/inc/impfontmetric.hxx vcl/inc/impfontmetricdata.hxx vcl/inc/impgraph.hxx vcl/inc/implimagetree.hxx -vcl/inc/impoctree.hxx vcl/inc/ios/iosinst.hxx vcl/inc/ios/svsys.h vcl/inc/jobset.h vcl/inc/langboost.hxx vcl/inc/listbox.hxx -vcl/inc/octree.hxx +vcl/inc/bitmap/Octree.hxx +vcl/inc/bitmap/impoctree.hxx vcl/inc/opengl/BufferObject.hxx vcl/inc/opengl/DeviceInfo.hxx vcl/inc/opengl/FixedTextureAtlas.hxx @@ -17777,6 +17777,7 @@ vcl/source/bitmap/BitmapTools.cxx vcl/source/bitmap/bitmap.cxx vcl/source/bitmap/bitmapfilter.cxx vcl/source/bitmap/checksum.cxx +vcl/source/bitmap/Octree.cxx vcl/source/components/dtranscomp.cxx vcl/source/components/factory.cxx vcl/source/components/fontident.cxx @@ -17909,7 +17910,6 @@ vcl/source/gdi/lineinfo.cxx vcl/source/gdi/mapmod.cxx vcl/source/gdi/metaact.cxx vcl/source/gdi/mtfxmldump.cxx -vcl/source/gdi/octree.cxx vcl/source/gdi/oldprintadaptor.cxx vcl/source/gdi/pdfextoutdevdata.cxx vcl/source/gdi/pdffontcache.cxx diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 7265eb39811f..242af6a996fb 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -280,7 +280,6 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/gdi/lineinfo \ vcl/source/gdi/mapmod \ vcl/source/gdi/metaact \ - vcl/source/gdi/octree \ vcl/source/gdi/oldprintadaptor \ vcl/source/gdi/pdfbuildin_fonts \ vcl/source/gdi/pdfextoutdevdata \ @@ -344,6 +343,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/bitmap/BitmapSimpleColorQuantizationFilter \ vcl/source/bitmap/BitmapTools \ vcl/source/bitmap/checksum \ + vcl/source/bitmap/Octree \ vcl/source/image/Image \ vcl/source/image/ImageTree \ vcl/source/image/ImageRepository \ diff --git a/vcl/inc/bitmap/Octree.hxx b/vcl/inc/bitmap/Octree.hxx new file mode 100644 index 000000000000..cec8e4171494 --- /dev/null +++ b/vcl/inc/bitmap/Octree.hxx @@ -0,0 +1,119 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_VCL_INC_OCTREE_HXX +#define INCLUDED_VCL_INC_OCTREE_HXX + +#include +#include + +#define OCTREE_BITS 5 +#define OCTREE_BITS_1 10 + +struct OctreeNode +{ + sal_uLong nCount; + sal_uLong nRed; + sal_uLong nGreen; + sal_uLong nBlue; + OctreeNode* pChild[ 8 ]; + OctreeNode* pNext; + OctreeNode* pNextInCache; + sal_uInt16 nPalIndex; + bool bLeaf; +}; + +class ImpNodeCache; +class BitmapReadAccess; + +class VCL_PLUGIN_PUBLIC Octree +{ +private: + void CreatePalette( OctreeNode* pNode ); + void GetPalIndex( OctreeNode* pNode ); + + SAL_DLLPRIVATE void ImplDeleteOctree( OctreeNode** ppNode ); + SAL_DLLPRIVATE void ImplAdd( OctreeNode** ppNode ); + SAL_DLLPRIVATE void ImplReduce(); + + + BitmapPalette aPal; + sal_uLong nLeafCount; + sal_uLong nLevel; + OctreeNode* pTree; + OctreeNode* pReduce[ OCTREE_BITS + 1 ]; + BitmapColor const * pColor; + std::unique_ptr pNodeCache; + const BitmapReadAccess* pAcc; + sal_uInt16 nPalIndex; + +public: + + Octree( const BitmapReadAccess& rReadAcc, sal_uLong nColors ); + ~Octree(); + + inline const BitmapPalette& GetPalette(); + inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor ); +}; + +inline const BitmapPalette& Octree::GetPalette() +{ + aPal.SetEntryCount( static_cast(nLeafCount) ); + nPalIndex = 0; + CreatePalette( pTree ); + return aPal; +} + +inline sal_uInt16 Octree::GetBestPaletteIndex( const BitmapColor& rColor ) +{ + pColor = &rColor; + nPalIndex = 65535; + nLevel = 0; + GetPalIndex( pTree ); + return nPalIndex; +} + +class VCL_PLUGIN_PUBLIC InverseColorMap +{ +private: + + std::unique_ptr pBuffer; + std::unique_ptr pMap; + static constexpr sal_uLong gnBits = 8 -OCTREE_BITS; + + SAL_DLLPRIVATE void ImplCreateBuffers( const sal_uLong nMax ); + +public: + + explicit InverseColorMap( const BitmapPalette& rPal ); + ~InverseColorMap(); + + inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor ); +}; + +inline sal_uInt16 InverseColorMap::GetBestPaletteIndex( const BitmapColor& rColor ) +{ + return pMap[ ( ( static_cast(rColor.GetRed()) >> gnBits ) << OCTREE_BITS_1 ) | + ( ( static_cast(rColor.GetGreen()) >> gnBits ) << OCTREE_BITS ) | + ( static_cast(rColor.GetBlue()) >> gnBits ) ]; +} + +#endif // INCLUDED_VCL_INC_OCTREE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/bitmap/impoctree.hxx b/vcl/inc/bitmap/impoctree.hxx new file mode 100644 index 000000000000..b2f05b351c5a --- /dev/null +++ b/vcl/inc/bitmap/impoctree.hxx @@ -0,0 +1,147 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_VCL_INC_IMPOCTREE_HXX +#define INCLUDED_VCL_INC_IMPOCTREE_HXX + +#include "Octree.hxx" + +class ImpErrorQuad +{ + long nRed; + long nGreen; + long nBlue; + +public: + + ImpErrorQuad() + : nRed(0) + , nGreen(0) + , nBlue(0) + { + } + + ImpErrorQuad( const BitmapColor& rColor ) + : nRed( static_cast(rColor.GetRed()) << 5 ) + , nGreen( static_cast(rColor.GetGreen()) << 5 ) + , nBlue( static_cast(rColor.GetBlue()) << 5 ) + { + } + + inline void operator=( const BitmapColor& rColor ); + inline ImpErrorQuad& operator-=( const BitmapColor& rColor ); + + inline void ImplAddColorError1( const ImpErrorQuad& rErrQuad ); + inline void ImplAddColorError3( const ImpErrorQuad& rErrQuad ); + inline void ImplAddColorError5( const ImpErrorQuad& rErrQuad ); + inline void ImplAddColorError7( const ImpErrorQuad& rErrQuad ); + + inline BitmapColor ImplGetColor(); +}; + +inline void ImpErrorQuad::operator=( const BitmapColor& rColor ) +{ + nRed = static_cast(rColor.GetRed()) << 5; + nGreen = static_cast(rColor.GetGreen()) << 5; + nBlue = static_cast(rColor.GetBlue()) << 5; +} + +inline ImpErrorQuad& ImpErrorQuad::operator-=( const BitmapColor& rColor ) +{ + nRed -= ( static_cast(rColor.GetRed()) << 5 ); + nGreen -= ( static_cast(rColor.GetGreen()) << 5 ); + nBlue -= ( static_cast(rColor.GetBlue()) << 5 ); + + return *this; +} + +inline void ImpErrorQuad::ImplAddColorError1( const ImpErrorQuad& rErrQuad ) +{ + nRed += ( rErrQuad.nRed >> 4 ); + nGreen += ( rErrQuad.nGreen >> 4 ); + nBlue += ( rErrQuad.nBlue >> 4 ); +} + +inline void ImpErrorQuad::ImplAddColorError3( const ImpErrorQuad& rErrQuad ) +{ + nRed += ( rErrQuad.nRed * 3L >> 4 ); + nGreen += ( rErrQuad.nGreen * 3L >> 4 ); + nBlue += ( rErrQuad.nBlue * 3L >> 4 ); +} + +inline void ImpErrorQuad::ImplAddColorError5( const ImpErrorQuad& rErrQuad ) +{ + nRed += ( rErrQuad.nRed * 5L >> 4 ); + nGreen += ( rErrQuad.nGreen * 5L >> 4 ); + nBlue += ( rErrQuad.nBlue * 5L >> 4 ); +} + +inline void ImpErrorQuad::ImplAddColorError7( const ImpErrorQuad& rErrQuad ) +{ + nRed += ( rErrQuad.nRed * 7L >> 4 ); + nGreen += ( rErrQuad.nGreen * 7L >> 4 ); + nBlue += ( rErrQuad.nBlue *7L >> 4 ); +} + +inline BitmapColor ImpErrorQuad::ImplGetColor() +{ + return BitmapColor( static_cast( ( nRed < 0 ? 0L : nRed > 8160 ? 8160L : nRed ) >> 5 ), + static_cast( ( nGreen < 0 ? 0L : nGreen > 8160 ? 8160L : nGreen ) >> 5 ), + static_cast( ( nBlue < 0 ? 0L : nBlue > 8160 ? 8160L : nBlue ) >> 5 ) ); +} + +class ImpNodeCache +{ + OctreeNode* pActNode; + +public: + + ImpNodeCache( const sal_uLong nInitSize ); + ~ImpNodeCache(); + + inline OctreeNode* ImplGetFreeNode(); + inline void ImplReleaseNode( OctreeNode* pNode ); +}; + +inline OctreeNode* ImpNodeCache::ImplGetFreeNode() +{ + OctreeNode* pNode; + + if ( !pActNode ) + { + pActNode = new OctreeNode; + pActNode->pNextInCache = nullptr; + } + + pNode = pActNode; + pActNode = pNode->pNextInCache; + memset( pNode, 0, sizeof( OctreeNode ) ); + + return pNode; +} + +inline void ImpNodeCache::ImplReleaseNode( OctreeNode* pNode ) +{ + pNode->pNextInCache = pActNode; + pActNode = pNode; +} + +#endif // INCLUDED_VCL_INC_IMPOCTREE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/impoctree.hxx b/vcl/inc/impoctree.hxx deleted file mode 100644 index 97de164ed405..000000000000 --- a/vcl/inc/impoctree.hxx +++ /dev/null @@ -1,147 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_VCL_INC_IMPOCTREE_HXX -#define INCLUDED_VCL_INC_IMPOCTREE_HXX - -#include "octree.hxx" - -class ImpErrorQuad -{ - long nRed; - long nGreen; - long nBlue; - -public: - - ImpErrorQuad() - : nRed(0) - , nGreen(0) - , nBlue(0) - { - } - - ImpErrorQuad( const BitmapColor& rColor ) - : nRed( static_cast(rColor.GetRed()) << 5 ) - , nGreen( static_cast(rColor.GetGreen()) << 5 ) - , nBlue( static_cast(rColor.GetBlue()) << 5 ) - { - } - - inline void operator=( const BitmapColor& rColor ); - inline ImpErrorQuad& operator-=( const BitmapColor& rColor ); - - inline void ImplAddColorError1( const ImpErrorQuad& rErrQuad ); - inline void ImplAddColorError3( const ImpErrorQuad& rErrQuad ); - inline void ImplAddColorError5( const ImpErrorQuad& rErrQuad ); - inline void ImplAddColorError7( const ImpErrorQuad& rErrQuad ); - - inline BitmapColor ImplGetColor(); -}; - -inline void ImpErrorQuad::operator=( const BitmapColor& rColor ) -{ - nRed = static_cast(rColor.GetRed()) << 5; - nGreen = static_cast(rColor.GetGreen()) << 5; - nBlue = static_cast(rColor.GetBlue()) << 5; -} - -inline ImpErrorQuad& ImpErrorQuad::operator-=( const BitmapColor& rColor ) -{ - nRed -= ( static_cast(rColor.GetRed()) << 5 ); - nGreen -= ( static_cast(rColor.GetGreen()) << 5 ); - nBlue -= ( static_cast(rColor.GetBlue()) << 5 ); - - return *this; -} - -inline void ImpErrorQuad::ImplAddColorError1( const ImpErrorQuad& rErrQuad ) -{ - nRed += ( rErrQuad.nRed >> 4 ); - nGreen += ( rErrQuad.nGreen >> 4 ); - nBlue += ( rErrQuad.nBlue >> 4 ); -} - -inline void ImpErrorQuad::ImplAddColorError3( const ImpErrorQuad& rErrQuad ) -{ - nRed += ( rErrQuad.nRed * 3L >> 4 ); - nGreen += ( rErrQuad.nGreen * 3L >> 4 ); - nBlue += ( rErrQuad.nBlue * 3L >> 4 ); -} - -inline void ImpErrorQuad::ImplAddColorError5( const ImpErrorQuad& rErrQuad ) -{ - nRed += ( rErrQuad.nRed * 5L >> 4 ); - nGreen += ( rErrQuad.nGreen * 5L >> 4 ); - nBlue += ( rErrQuad.nBlue * 5L >> 4 ); -} - -inline void ImpErrorQuad::ImplAddColorError7( const ImpErrorQuad& rErrQuad ) -{ - nRed += ( rErrQuad.nRed * 7L >> 4 ); - nGreen += ( rErrQuad.nGreen * 7L >> 4 ); - nBlue += ( rErrQuad.nBlue *7L >> 4 ); -} - -inline BitmapColor ImpErrorQuad::ImplGetColor() -{ - return BitmapColor( static_cast( ( nRed < 0 ? 0L : nRed > 8160 ? 8160L : nRed ) >> 5 ), - static_cast( ( nGreen < 0 ? 0L : nGreen > 8160 ? 8160L : nGreen ) >> 5 ), - static_cast( ( nBlue < 0 ? 0L : nBlue > 8160 ? 8160L : nBlue ) >> 5 ) ); -} - -class ImpNodeCache -{ - OctreeNode* pActNode; - -public: - - ImpNodeCache( const sal_uLong nInitSize ); - ~ImpNodeCache(); - - inline OctreeNode* ImplGetFreeNode(); - inline void ImplReleaseNode( OctreeNode* pNode ); -}; - -inline OctreeNode* ImpNodeCache::ImplGetFreeNode() -{ - OctreeNode* pNode; - - if ( !pActNode ) - { - pActNode = new OctreeNode; - pActNode->pNextInCache = nullptr; - } - - pNode = pActNode; - pActNode = pNode->pNextInCache; - memset( pNode, 0, sizeof( OctreeNode ) ); - - return pNode; -} - -inline void ImpNodeCache::ImplReleaseNode( OctreeNode* pNode ) -{ - pNode->pNextInCache = pActNode; - pActNode = pNode; -} - -#endif // INCLUDED_VCL_INC_IMPOCTREE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/octree.hxx b/vcl/inc/octree.hxx deleted file mode 100644 index cec8e4171494..000000000000 --- a/vcl/inc/octree.hxx +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_VCL_INC_OCTREE_HXX -#define INCLUDED_VCL_INC_OCTREE_HXX - -#include -#include - -#define OCTREE_BITS 5 -#define OCTREE_BITS_1 10 - -struct OctreeNode -{ - sal_uLong nCount; - sal_uLong nRed; - sal_uLong nGreen; - sal_uLong nBlue; - OctreeNode* pChild[ 8 ]; - OctreeNode* pNext; - OctreeNode* pNextInCache; - sal_uInt16 nPalIndex; - bool bLeaf; -}; - -class ImpNodeCache; -class BitmapReadAccess; - -class VCL_PLUGIN_PUBLIC Octree -{ -private: - void CreatePalette( OctreeNode* pNode ); - void GetPalIndex( OctreeNode* pNode ); - - SAL_DLLPRIVATE void ImplDeleteOctree( OctreeNode** ppNode ); - SAL_DLLPRIVATE void ImplAdd( OctreeNode** ppNode ); - SAL_DLLPRIVATE void ImplReduce(); - - - BitmapPalette aPal; - sal_uLong nLeafCount; - sal_uLong nLevel; - OctreeNode* pTree; - OctreeNode* pReduce[ OCTREE_BITS + 1 ]; - BitmapColor const * pColor; - std::unique_ptr pNodeCache; - const BitmapReadAccess* pAcc; - sal_uInt16 nPalIndex; - -public: - - Octree( const BitmapReadAccess& rReadAcc, sal_uLong nColors ); - ~Octree(); - - inline const BitmapPalette& GetPalette(); - inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor ); -}; - -inline const BitmapPalette& Octree::GetPalette() -{ - aPal.SetEntryCount( static_cast(nLeafCount) ); - nPalIndex = 0; - CreatePalette( pTree ); - return aPal; -} - -inline sal_uInt16 Octree::GetBestPaletteIndex( const BitmapColor& rColor ) -{ - pColor = &rColor; - nPalIndex = 65535; - nLevel = 0; - GetPalIndex( pTree ); - return nPalIndex; -} - -class VCL_PLUGIN_PUBLIC InverseColorMap -{ -private: - - std::unique_ptr pBuffer; - std::unique_ptr pMap; - static constexpr sal_uLong gnBits = 8 -OCTREE_BITS; - - SAL_DLLPRIVATE void ImplCreateBuffers( const sal_uLong nMax ); - -public: - - explicit InverseColorMap( const BitmapPalette& rPal ); - ~InverseColorMap(); - - inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor ); -}; - -inline sal_uInt16 InverseColorMap::GetBestPaletteIndex( const BitmapColor& rColor ) -{ - return pMap[ ( ( static_cast(rColor.GetRed()) >> gnBits ) << OCTREE_BITS_1 ) | - ( ( static_cast(rColor.GetGreen()) >> gnBits ) << OCTREE_BITS ) | - ( static_cast(rColor.GetBlue()) >> gnBits ) ]; -} - -#endif // INCLUDED_VCL_INC_OCTREE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx b/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx index 2f1fb9906a1f..ae066cc66cf6 100644 --- a/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx +++ b/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx @@ -14,7 +14,7 @@ #include #include -#include +#include #include diff --git a/vcl/source/bitmap/Octree.cxx b/vcl/source/bitmap/Octree.cxx new file mode 100644 index 000000000000..64914f76385e --- /dev/null +++ b/vcl/source/bitmap/Octree.cxx @@ -0,0 +1,298 @@ +/* -*- 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 + +#include +#include + +#include +#include + +static const sal_uInt8 pImplMask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; + +ImpNodeCache::ImpNodeCache( const sal_uLong nInitSize ) : + pActNode( nullptr ) +{ + const sal_uLong nSize = nInitSize + 4; + + for( sal_uLong i = 0; i < nSize; i++ ) + { + OctreeNode* pNewNode = new OctreeNode; + + pNewNode->pNextInCache = pActNode; + pActNode = pNewNode; + } +} + +ImpNodeCache::~ImpNodeCache() +{ + while( pActNode ) + { + OctreeNode* pNode = pActNode; + + pActNode = pNode->pNextInCache; + delete pNode; + } +} + +Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors) + : nLeafCount(0) + , nLevel(0) + , pTree(nullptr) + , pColor(nullptr) + , pAcc(&rReadAcc) + , nPalIndex(0) +{ + sal_uLong nMax(nColors); + pNodeCache.reset( new ImpNodeCache( nColors ) ); + memset( pReduce, 0, ( OCTREE_BITS + 1 ) * sizeof( OctreeNode* ) ); + + if( !!*pAcc ) + { + const long nWidth = pAcc->Width(); + const long nHeight = pAcc->Height(); + + if( pAcc->HasPalette() ) + { + for( long nY = 0; nY < nHeight; nY++ ) + { + Scanline pScanline = pAcc->GetScanline( nY ); + for( long nX = 0; nX < nWidth; nX++ ) + { + pColor = &pAcc->GetPaletteColor( pAcc->GetIndexFromData( pScanline, nX ) ); + nLevel = 0; + ImplAdd( &pTree ); + + while( nLeafCount > nMax ) + ImplReduce(); + } + } + } + else + { + BitmapColor aColor; + + pColor = &aColor; + + for( long nY = 0; nY < nHeight; nY++ ) + { + Scanline pScanline = pAcc->GetScanline( nY ); + for( long nX = 0; nX < nWidth; nX++ ) + { + aColor = pAcc->GetPixelFromData( pScanline, nX ); + nLevel = 0; + ImplAdd( &pTree ); + + while( nLeafCount > nMax ) + ImplReduce(); + } + } + } + } +} + +Octree::~Octree() +{ + ImplDeleteOctree( &pTree ); + pNodeCache.reset(); +} + +void Octree::ImplDeleteOctree( OctreeNode** ppNode ) +{ + for (OctreeNode* i : (*ppNode)->pChild) + { + if ( i ) + ImplDeleteOctree( &i ); + } + + pNodeCache->ImplReleaseNode( *ppNode ); + *ppNode = nullptr; +} + +void Octree::ImplAdd( OctreeNode** ppNode ) +{ + // possibly generate new nodes + if( !*ppNode ) + { + *ppNode = pNodeCache->ImplGetFreeNode(); + (*ppNode)->bLeaf = ( OCTREE_BITS == nLevel ); + + if( (*ppNode)->bLeaf ) + nLeafCount++; + else + { + (*ppNode)->pNext = pReduce[ nLevel ]; + pReduce[ nLevel ] = *ppNode; + } + } + + if( (*ppNode)->bLeaf ) + { + (*ppNode)->nCount++; + (*ppNode)->nRed += pColor->GetRed(); + (*ppNode)->nGreen += pColor->GetGreen(); + (*ppNode)->nBlue += pColor->GetBlue(); + } + else + { + const sal_uLong nShift = 7 - nLevel; + const sal_uInt8 cMask = pImplMask[ nLevel ]; + const sal_uLong nIndex = ( ( ( pColor->GetRed() & cMask ) >> nShift ) << 2 ) | + ( ( ( pColor->GetGreen() & cMask ) >> nShift ) << 1 ) | + ( ( pColor->GetBlue() & cMask ) >> nShift ); + + nLevel++; + ImplAdd( &(*ppNode)->pChild[ nIndex ] ); + } +} + +void Octree::ImplReduce() +{ + sal_uLong i; + OctreeNode* pNode; + sal_uLong nRedSum = 0; + sal_uLong nGreenSum = 0; + sal_uLong nBlueSum = 0; + sal_uLong nChildren = 0; + + for ( i = OCTREE_BITS - 1; i && !pReduce[i]; i-- ) {} + + pNode = pReduce[ i ]; + pReduce[ i ] = pNode->pNext; + + for ( i = 0; i < 8; i++ ) + { + if ( pNode->pChild[ i ] ) + { + OctreeNode* pChild = pNode->pChild[ i ]; + + nRedSum += pChild->nRed; + nGreenSum += pChild->nGreen; + nBlueSum += pChild->nBlue; + pNode->nCount += pChild->nCount; + + pNodeCache->ImplReleaseNode( pNode->pChild[ i ] ); + pNode->pChild[ i ] = nullptr; + nChildren++; + } + } + + pNode->bLeaf = true; + pNode->nRed = nRedSum; + pNode->nGreen = nGreenSum; + pNode->nBlue = nBlueSum; + nLeafCount -= --nChildren; +} + +void Octree::CreatePalette( OctreeNode* pNode ) +{ + if( pNode->bLeaf ) + { + pNode->nPalIndex = nPalIndex; + aPal[ nPalIndex++ ] = BitmapColor( static_cast( static_cast(pNode->nRed) / pNode->nCount ), + static_cast( static_cast(pNode->nGreen) / pNode->nCount ), + static_cast( static_cast(pNode->nBlue) / pNode->nCount ) ); + } + else for(OctreeNode* i : pNode->pChild) + if( i ) + CreatePalette( i ); + +} + +void Octree::GetPalIndex( OctreeNode* pNode ) +{ + if ( pNode->bLeaf ) + nPalIndex = pNode->nPalIndex; + else + { + const sal_uLong nShift = 7 - nLevel; + const sal_uInt8 cMask = pImplMask[ nLevel++ ]; + const sal_uLong nIndex = ( ( ( pColor->GetRed() & cMask ) >> nShift ) << 2 ) | + ( ( ( pColor->GetGreen() & cMask ) >> nShift ) << 1 ) | + ( ( pColor->GetBlue() & cMask ) >> nShift ); + + GetPalIndex( pNode->pChild[ nIndex ] ); + } +} + +InverseColorMap::InverseColorMap( const BitmapPalette& rPal ) +{ + const int nColorMax = 1 << OCTREE_BITS; + const unsigned long xsqr = 1 << ( gnBits << 1 ); + const unsigned long xsqr2 = xsqr << 1; + const int nColors = rPal.GetEntryCount(); + const long x = 1 << gnBits; + const long x2 = x >> 1; + sal_uLong r, g, b; + long rxx, gxx, bxx; + + ImplCreateBuffers( nColorMax ); + + for( int nIndex = 0; nIndex < nColors; nIndex++ ) + { + const BitmapColor& rColor = rPal[ static_cast(nIndex) ]; + const long cRed = rColor.GetRed(); + const long cGreen = rColor.GetGreen(); + const long cBlue = rColor.GetBlue(); + + long rdist = cRed - x2; + long gdist = cGreen - x2; + long bdist = cBlue - x2; + rdist = rdist*rdist + gdist*gdist + bdist*bdist; + + const long crinc = ( xsqr - ( cRed << gnBits ) ) << 1; + const long cginc = ( xsqr - ( cGreen << gnBits ) ) << 1; + const long cbinc = ( xsqr - ( cBlue << gnBits ) ) << 1; + + sal_uLong* cdp = reinterpret_cast(pBuffer.get()); + sal_uInt8* crgbp = pMap.get(); + + for( r = 0, rxx = crinc; r < nColorMax; rdist += rxx, r++, rxx += xsqr2 ) + { + for( g = 0, gdist = rdist, gxx = cginc; g < nColorMax; gdist += gxx, g++, gxx += xsqr2 ) + { + for( b = 0, bdist = gdist, bxx = cbinc; b < nColorMax; bdist += bxx, b++, cdp++, crgbp++, bxx += xsqr2 ) + if ( !nIndex || static_cast(*cdp) > bdist ) + { + *cdp = bdist; + *crgbp = static_cast(nIndex); + } + } + } + } +} + +InverseColorMap::~InverseColorMap() +{ +} + +void InverseColorMap::ImplCreateBuffers( const sal_uLong nMax ) +{ + const sal_uLong nCount = nMax * nMax * nMax; + const sal_uLong nSize = nCount * sizeof( sal_uLong ); + + pMap.reset(new sal_uInt8[ nCount ]); + memset( pMap.get(), 0x00, nCount ); + + pBuffer.reset(new sal_uInt8[ nSize ]); + memset( pBuffer.get(), 0xff, nSize ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx index 23aa996b6a2d..71a3bc468876 100644 --- a/vcl/source/gdi/bitmap3.cxx +++ b/vcl/source/gdi/bitmap3.cxx @@ -32,13 +32,13 @@ #endif #include -#include #include #include #include #include #include -#include +#include +#include #include #include #include diff --git a/vcl/source/gdi/octree.cxx b/vcl/source/gdi/octree.cxx deleted file mode 100644 index 4635067901f8..000000000000 --- a/vcl/source/gdi/octree.cxx +++ /dev/null @@ -1,298 +0,0 @@ -/* -*- 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 - -#include -#include - -#include -#include - -static const sal_uInt8 pImplMask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; - -ImpNodeCache::ImpNodeCache( const sal_uLong nInitSize ) : - pActNode( nullptr ) -{ - const sal_uLong nSize = nInitSize + 4; - - for( sal_uLong i = 0; i < nSize; i++ ) - { - OctreeNode* pNewNode = new OctreeNode; - - pNewNode->pNextInCache = pActNode; - pActNode = pNewNode; - } -} - -ImpNodeCache::~ImpNodeCache() -{ - while( pActNode ) - { - OctreeNode* pNode = pActNode; - - pActNode = pNode->pNextInCache; - delete pNode; - } -} - -Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors) - : nLeafCount(0) - , nLevel(0) - , pTree(nullptr) - , pColor(nullptr) - , pAcc(&rReadAcc) - , nPalIndex(0) -{ - sal_uLong nMax(nColors); - pNodeCache.reset( new ImpNodeCache( nColors ) ); - memset( pReduce, 0, ( OCTREE_BITS + 1 ) * sizeof( OctreeNode* ) ); - - if( !!*pAcc ) - { - const long nWidth = pAcc->Width(); - const long nHeight = pAcc->Height(); - - if( pAcc->HasPalette() ) - { - for( long nY = 0; nY < nHeight; nY++ ) - { - Scanline pScanline = pAcc->GetScanline( nY ); - for( long nX = 0; nX < nWidth; nX++ ) - { - pColor = &pAcc->GetPaletteColor( pAcc->GetIndexFromData( pScanline, nX ) ); - nLevel = 0; - ImplAdd( &pTree ); - - while( nLeafCount > nMax ) - ImplReduce(); - } - } - } - else - { - BitmapColor aColor; - - pColor = &aColor; - - for( long nY = 0; nY < nHeight; nY++ ) - { - Scanline pScanline = pAcc->GetScanline( nY ); - for( long nX = 0; nX < nWidth; nX++ ) - { - aColor = pAcc->GetPixelFromData( pScanline, nX ); - nLevel = 0; - ImplAdd( &pTree ); - - while( nLeafCount > nMax ) - ImplReduce(); - } - } - } - } -} - -Octree::~Octree() -{ - ImplDeleteOctree( &pTree ); - pNodeCache.reset(); -} - -void Octree::ImplDeleteOctree( OctreeNode** ppNode ) -{ - for (OctreeNode* i : (*ppNode)->pChild) - { - if ( i ) - ImplDeleteOctree( &i ); - } - - pNodeCache->ImplReleaseNode( *ppNode ); - *ppNode = nullptr; -} - -void Octree::ImplAdd( OctreeNode** ppNode ) -{ - // possibly generate new nodes - if( !*ppNode ) - { - *ppNode = pNodeCache->ImplGetFreeNode(); - (*ppNode)->bLeaf = ( OCTREE_BITS == nLevel ); - - if( (*ppNode)->bLeaf ) - nLeafCount++; - else - { - (*ppNode)->pNext = pReduce[ nLevel ]; - pReduce[ nLevel ] = *ppNode; - } - } - - if( (*ppNode)->bLeaf ) - { - (*ppNode)->nCount++; - (*ppNode)->nRed += pColor->GetRed(); - (*ppNode)->nGreen += pColor->GetGreen(); - (*ppNode)->nBlue += pColor->GetBlue(); - } - else - { - const sal_uLong nShift = 7 - nLevel; - const sal_uInt8 cMask = pImplMask[ nLevel ]; - const sal_uLong nIndex = ( ( ( pColor->GetRed() & cMask ) >> nShift ) << 2 ) | - ( ( ( pColor->GetGreen() & cMask ) >> nShift ) << 1 ) | - ( ( pColor->GetBlue() & cMask ) >> nShift ); - - nLevel++; - ImplAdd( &(*ppNode)->pChild[ nIndex ] ); - } -} - -void Octree::ImplReduce() -{ - sal_uLong i; - OctreeNode* pNode; - sal_uLong nRedSum = 0; - sal_uLong nGreenSum = 0; - sal_uLong nBlueSum = 0; - sal_uLong nChildren = 0; - - for ( i = OCTREE_BITS - 1; i && !pReduce[i]; i-- ) {} - - pNode = pReduce[ i ]; - pReduce[ i ] = pNode->pNext; - - for ( i = 0; i < 8; i++ ) - { - if ( pNode->pChild[ i ] ) - { - OctreeNode* pChild = pNode->pChild[ i ]; - - nRedSum += pChild->nRed; - nGreenSum += pChild->nGreen; - nBlueSum += pChild->nBlue; - pNode->nCount += pChild->nCount; - - pNodeCache->ImplReleaseNode( pNode->pChild[ i ] ); - pNode->pChild[ i ] = nullptr; - nChildren++; - } - } - - pNode->bLeaf = true; - pNode->nRed = nRedSum; - pNode->nGreen = nGreenSum; - pNode->nBlue = nBlueSum; - nLeafCount -= --nChildren; -} - -void Octree::CreatePalette( OctreeNode* pNode ) -{ - if( pNode->bLeaf ) - { - pNode->nPalIndex = nPalIndex; - aPal[ nPalIndex++ ] = BitmapColor( static_cast( static_cast(pNode->nRed) / pNode->nCount ), - static_cast( static_cast(pNode->nGreen) / pNode->nCount ), - static_cast( static_cast(pNode->nBlue) / pNode->nCount ) ); - } - else for(OctreeNode* i : pNode->pChild) - if( i ) - CreatePalette( i ); - -} - -void Octree::GetPalIndex( OctreeNode* pNode ) -{ - if ( pNode->bLeaf ) - nPalIndex = pNode->nPalIndex; - else - { - const sal_uLong nShift = 7 - nLevel; - const sal_uInt8 cMask = pImplMask[ nLevel++ ]; - const sal_uLong nIndex = ( ( ( pColor->GetRed() & cMask ) >> nShift ) << 2 ) | - ( ( ( pColor->GetGreen() & cMask ) >> nShift ) << 1 ) | - ( ( pColor->GetBlue() & cMask ) >> nShift ); - - GetPalIndex( pNode->pChild[ nIndex ] ); - } -} - -InverseColorMap::InverseColorMap( const BitmapPalette& rPal ) -{ - const int nColorMax = 1 << OCTREE_BITS; - const unsigned long xsqr = 1 << ( gnBits << 1 ); - const unsigned long xsqr2 = xsqr << 1; - const int nColors = rPal.GetEntryCount(); - const long x = 1 << gnBits; - const long x2 = x >> 1; - sal_uLong r, g, b; - long rxx, gxx, bxx; - - ImplCreateBuffers( nColorMax ); - - for( int nIndex = 0; nIndex < nColors; nIndex++ ) - { - const BitmapColor& rColor = rPal[ static_cast(nIndex) ]; - const long cRed = rColor.GetRed(); - const long cGreen = rColor.GetGreen(); - const long cBlue = rColor.GetBlue(); - - long rdist = cRed - x2; - long gdist = cGreen - x2; - long bdist = cBlue - x2; - rdist = rdist*rdist + gdist*gdist + bdist*bdist; - - const long crinc = ( xsqr - ( cRed << gnBits ) ) << 1; - const long cginc = ( xsqr - ( cGreen << gnBits ) ) << 1; - const long cbinc = ( xsqr - ( cBlue << gnBits ) ) << 1; - - sal_uLong* cdp = reinterpret_cast(pBuffer.get()); - sal_uInt8* crgbp = pMap.get(); - - for( r = 0, rxx = crinc; r < nColorMax; rdist += rxx, r++, rxx += xsqr2 ) - { - for( g = 0, gdist = rdist, gxx = cginc; g < nColorMax; gdist += gxx, g++, gxx += xsqr2 ) - { - for( b = 0, bdist = gdist, bxx = cbinc; b < nColorMax; bdist += bxx, b++, cdp++, crgbp++, bxx += xsqr2 ) - if ( !nIndex || static_cast(*cdp) > bdist ) - { - *cdp = bdist; - *crgbp = static_cast(nIndex); - } - } - } - } -} - -InverseColorMap::~InverseColorMap() -{ -} - -void InverseColorMap::ImplCreateBuffers( const sal_uLong nMax ) -{ - const sal_uLong nCount = nMax * nMax * nMax; - const sal_uLong nSize = nCount * sizeof( sal_uLong ); - - pMap.reset(new sal_uInt8[ nCount ]); - memset( pMap.get(), 0x00, nCount ); - - pBuffer.reset(new sal_uInt8[ nSize ]); - memset( pBuffer.get(), 0xff, nSize ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit