1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _SV_OCTREE_HXX 29 #define _SV_OCTREE_HXX 30 31 #include <vcl/salbtype.hxx> 32 #include <vcl/dllapi.h> 33 34 // ----------- 35 // - Defines - 36 // ----------- 37 38 #define OCTREE_BITS 5 39 #define OCTREE_BITS_1 10 40 41 // -------------- 42 // - OctreeNode - 43 // -------------- 44 45 typedef struct OctreeNode 46 { 47 sal_uLong nCount; 48 sal_uLong nRed; 49 sal_uLong nGreen; 50 sal_uLong nBlue; 51 OctreeNode* pChild[ 8 ]; 52 OctreeNode* pNext; 53 OctreeNode* pNextInCache; 54 sal_uInt16 nPalIndex; 55 sal_Bool bLeaf; 56 } NODE; 57 58 typedef NODE* PNODE; 59 typedef PNODE* PPNODE; 60 61 // ---------- 62 // - Octree - 63 // ---------- 64 65 class ImpNodeCache; 66 class BitmapReadAccess; 67 68 class VCL_PLUGIN_PUBLIC Octree 69 { 70 private: 71 72 BitmapPalette aPal; 73 sal_uLong nMax; 74 sal_uLong nLeafCount; 75 sal_uLong nLevel; 76 PNODE pTree; 77 PNODE pReduce[ OCTREE_BITS + 1 ]; 78 BitmapColor* pColor; 79 ImpNodeCache* pNodeCache; 80 const BitmapReadAccess* pAcc; 81 sal_uInt16 nPalIndex; 82 83 Octree() {}; 84 85 void CreatePalette( PNODE pNode ); 86 void GetPalIndex( PNODE pNode ); 87 88 SAL_DLLPRIVATE void ImplCreateOctree(); 89 SAL_DLLPRIVATE void ImplDeleteOctree( PPNODE ppNode ); 90 SAL_DLLPRIVATE void ImplAdd( PPNODE ppNode ); 91 SAL_DLLPRIVATE void ImplReduce(); 92 93 public: 94 95 Octree( const BitmapReadAccess& rReadAcc, sal_uLong nColors ); 96 Octree( sal_uLong nColors ); 97 ~Octree(); 98 99 void AddColor( const BitmapColor& rColor ); 100 101 inline const BitmapPalette& GetPalette(); 102 inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor ); 103 }; 104 105 // ------------------------------------------------------------------------ 106 107 inline const BitmapPalette& Octree::GetPalette() 108 { 109 aPal.SetEntryCount( (sal_uInt16) nLeafCount ); 110 nPalIndex = 0; 111 CreatePalette( pTree ); 112 return aPal; 113 } 114 115 // ------------------------------------------------------------------------ 116 117 inline sal_uInt16 Octree::GetBestPaletteIndex( const BitmapColor& rColor ) 118 { 119 pColor = &(BitmapColor&) rColor; 120 nPalIndex = 65535; 121 nLevel = 0L; 122 GetPalIndex( pTree ); 123 return nPalIndex; 124 } 125 126 // ------------------- 127 // - InverseColorMap - 128 // ------------------- 129 130 class VCL_PLUGIN_PUBLIC InverseColorMap 131 { 132 private: 133 134 sal_uInt8* pBuffer; 135 sal_uInt8* pMap; 136 const sal_uLong nBits; 137 138 //#if 0 // _SOLAR__PRIVATE 139 140 SAL_DLLPRIVATE void ImplCreateBuffers( const sal_uLong nMax ); 141 142 //#endif // __PRIVATE 143 144 public: 145 146 explicit InverseColorMap( const BitmapPalette& rPal ); 147 ~InverseColorMap(); 148 149 inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor ); 150 }; 151 152 // ------------------------------------------------------------------------ 153 154 inline sal_uInt16 InverseColorMap::GetBestPaletteIndex( const BitmapColor& rColor ) 155 { 156 return pMap[ ( ( (sal_uLong) rColor.GetRed() >> nBits ) << OCTREE_BITS_1 ) | 157 ( ( (sal_uLong) rColor.GetGreen() >> nBits ) << OCTREE_BITS ) | 158 ( (sal_uLong) rColor.GetBlue() >> nBits ) ]; 159 } 160 161 #endif // _SV_OCTREE_HXX 162