xref: /aoo42x/main/vcl/inc/impoct.hxx (revision ebfcd9af)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_IMPOCT_HXX
25 #define _SV_IMPOCT_HXX
26 
27 #include <vcl/octree.hxx>
28 
29 // ----------------
30 // - ImpErrorQuad -
31 // ----------------
32 
33 class ImpErrorQuad
34 {
35 	long					nRed;
36 	long					nGreen;
37 	long					nBlue;
38 	long					nReserved;
39 
40 public:
41 
ImpErrorQuad()42 	inline 					ImpErrorQuad() {}
ImpErrorQuad(const BitmapColor & rColor)43 	inline					ImpErrorQuad( const BitmapColor& rColor ) :
44 								nRed	( (long) rColor.GetRed() << 5L ),
45 								nGreen	( (long) rColor.GetGreen() << 5L ),
46 								nBlue	( (long) rColor.GetBlue() << 5L ) {}
47 
48 	inline void				operator=( const BitmapColor& rColor );
49 	inline ImpErrorQuad&	operator-=( const BitmapColor& rColor );
50 
51 	inline void				ImplAddColorError1( const ImpErrorQuad& rErrQuad );
52 	inline void				ImplAddColorError3( const ImpErrorQuad& rErrQuad );
53 	inline void				ImplAddColorError5( const ImpErrorQuad& rErrQuad );
54 	inline void				ImplAddColorError7( const ImpErrorQuad& rErrQuad );
55 
56 	inline BitmapColor		ImplGetColor();
57 };
58 
59 // ------------------------------------------------------------------------
60 
operator =(const BitmapColor & rColor)61 inline void ImpErrorQuad::operator=( const BitmapColor& rColor )
62 {
63 	nRed = (long) rColor.GetRed() << 5L;
64 	nGreen = (long) rColor.GetGreen() << 5L;
65 	nBlue = (long) rColor.GetBlue() << 5L;
66 }
67 
68 // ------------------------------------------------------------------------
69 
operator -=(const BitmapColor & rColor)70 inline ImpErrorQuad& ImpErrorQuad::operator-=( const BitmapColor& rColor )
71 {
72 	nRed -= ( (long) rColor.GetRed() << 5L );
73 	nGreen -= ( (long) rColor.GetGreen() << 5L );
74 	nBlue -= ( (long) rColor.GetBlue() << 5L );
75 
76 	return *this;
77 }
78 
79 // ------------------------------------------------------------------------
80 
ImplAddColorError1(const ImpErrorQuad & rErrQuad)81 inline void ImpErrorQuad::ImplAddColorError1( const ImpErrorQuad& rErrQuad )
82 {
83 	nRed += ( rErrQuad.nRed >> 4L );
84 	nGreen += ( rErrQuad.nGreen >> 4L );
85 	nBlue += ( rErrQuad.nBlue >> 4L );
86 }
87 
88 // ------------------------------------------------------------------------
89 
ImplAddColorError3(const ImpErrorQuad & rErrQuad)90 inline void ImpErrorQuad::ImplAddColorError3( const ImpErrorQuad& rErrQuad )
91 {
92 	nRed += ( rErrQuad.nRed * 3L >> 4L );
93 	nGreen += ( rErrQuad.nGreen * 3L >> 4L );
94 	nBlue += ( rErrQuad.nBlue * 3L >> 4L );
95 }
96 
97 // ------------------------------------------------------------------------
98 
ImplAddColorError5(const ImpErrorQuad & rErrQuad)99 inline void ImpErrorQuad::ImplAddColorError5( const ImpErrorQuad& rErrQuad )
100 {
101 	nRed += ( rErrQuad.nRed * 5L >> 4L );
102 	nGreen += ( rErrQuad.nGreen * 5L >> 4L );
103 	nBlue += ( rErrQuad.nBlue * 5L >> 4L );
104 }
105 
106 // ------------------------------------------------------------------------
107 
ImplAddColorError7(const ImpErrorQuad & rErrQuad)108 inline void ImpErrorQuad::ImplAddColorError7( const ImpErrorQuad& rErrQuad )
109 {
110 	nRed += ( rErrQuad.nRed * 7L >> 4L );
111 	nGreen += ( rErrQuad.nGreen * 7L >> 4L );
112 	nBlue += ( rErrQuad.nBlue *7L >> 4L );
113 }
114 
115 // ------------------------------------------------------------------------
116 
ImplGetColor()117 inline BitmapColor ImpErrorQuad::ImplGetColor()
118 {
119 	return BitmapColor( (sal_uInt8) ( ( nRed < 0L ? 0L : nRed > 8160L ? 8160L : nRed ) >> 5L ),
120 						(sal_uInt8) ( ( nGreen < 0L ? 0L : nGreen > 8160L ? 8160L : nGreen ) >> 5L ),
121 						(sal_uInt8) ( ( nBlue < 0L ? 0L : nBlue > 8160L ? 8160L : nBlue ) >> 5L ) );
122 }
123 
124 // -------------
125 // - NodeCache -
126 // -------------
127 
128 class ImpNodeCache
129 {
130 	OctreeNode*			pActNode;
131 	sal_uLong				nNew;
132 	sal_uLong				nDelete;
133 	sal_uLong				nGet;
134 	sal_uLong				nRelease;
135 
136 public:
137 
138 						ImpNodeCache( const sal_uLong nInitSize );
139 						~ImpNodeCache();
140 
141 	inline OctreeNode*	ImplGetFreeNode();
142 	inline void			ImplReleaseNode( OctreeNode* pNode );
143 };
144 
145 // ------------------------------------------------------------------------
146 
ImplGetFreeNode()147 inline OctreeNode* ImpNodeCache::ImplGetFreeNode()
148 {
149 	OctreeNode* pNode;
150 
151 	if ( !pActNode )
152 	{
153 		pActNode = new NODE;
154 		pActNode->pNextInCache = NULL;
155 	}
156 
157 	pNode = pActNode;
158 	pActNode = pNode->pNextInCache;
159 	memset( pNode, 0, sizeof( NODE ) );
160 
161 	return pNode;
162 }
163 
164 // ------------------------------------------------------------------------
165 
ImplReleaseNode(OctreeNode * pNode)166 inline void ImpNodeCache::ImplReleaseNode( OctreeNode* pNode )
167 {
168 	pNode->pNextInCache = pActNode;
169 	pActNode = pNode;
170 }
171 
172 #endif // _SV_IMPOCT_HXX
173