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