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