xref: /aoo42x/main/vcl/inc/impoct.hxx (revision cdf0e10c)
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_IMPOCT_HXX
29 #define _SV_IMPOCT_HXX
30 
31 #include <vcl/octree.hxx>
32 
33 // ----------------
34 // - ImpErrorQuad -
35 // ----------------
36 
37 class ImpErrorQuad
38 {
39 	long					nRed;
40 	long					nGreen;
41 	long					nBlue;
42 	long					nReserved;
43 
44 public:
45 
46 	inline 					ImpErrorQuad() {}
47 	inline					ImpErrorQuad( const BitmapColor& rColor ) :
48 								nRed	( (long) rColor.GetRed() << 5L ),
49 								nGreen	( (long) rColor.GetGreen() << 5L ),
50 								nBlue	( (long) rColor.GetBlue() << 5L ) {}
51 
52 	inline void				operator=( const BitmapColor& rColor );
53 	inline ImpErrorQuad&	operator-=( const BitmapColor& rColor );
54 
55 	inline void				ImplAddColorError1( const ImpErrorQuad& rErrQuad );
56 	inline void				ImplAddColorError3( const ImpErrorQuad& rErrQuad );
57 	inline void				ImplAddColorError5( const ImpErrorQuad& rErrQuad );
58 	inline void				ImplAddColorError7( const ImpErrorQuad& rErrQuad );
59 
60 	inline BitmapColor		ImplGetColor();
61 };
62 
63 // ------------------------------------------------------------------------
64 
65 inline void ImpErrorQuad::operator=( const BitmapColor& rColor )
66 {
67 	nRed = (long) rColor.GetRed() << 5L;
68 	nGreen = (long) rColor.GetGreen() << 5L;
69 	nBlue = (long) rColor.GetBlue() << 5L;
70 }
71 
72 // ------------------------------------------------------------------------
73 
74 inline ImpErrorQuad& ImpErrorQuad::operator-=( const BitmapColor& rColor )
75 {
76 	nRed -= ( (long) rColor.GetRed() << 5L );
77 	nGreen -= ( (long) rColor.GetGreen() << 5L );
78 	nBlue -= ( (long) rColor.GetBlue() << 5L );
79 
80 	return *this;
81 }
82 
83 // ------------------------------------------------------------------------
84 
85 inline void ImpErrorQuad::ImplAddColorError1( const ImpErrorQuad& rErrQuad )
86 {
87 	nRed += ( rErrQuad.nRed >> 4L );
88 	nGreen += ( rErrQuad.nGreen >> 4L );
89 	nBlue += ( rErrQuad.nBlue >> 4L );
90 }
91 
92 // ------------------------------------------------------------------------
93 
94 inline void ImpErrorQuad::ImplAddColorError3( const ImpErrorQuad& rErrQuad )
95 {
96 	nRed += ( rErrQuad.nRed * 3L >> 4L );
97 	nGreen += ( rErrQuad.nGreen * 3L >> 4L );
98 	nBlue += ( rErrQuad.nBlue * 3L >> 4L );
99 }
100 
101 // ------------------------------------------------------------------------
102 
103 inline void ImpErrorQuad::ImplAddColorError5( const ImpErrorQuad& rErrQuad )
104 {
105 	nRed += ( rErrQuad.nRed * 5L >> 4L );
106 	nGreen += ( rErrQuad.nGreen * 5L >> 4L );
107 	nBlue += ( rErrQuad.nBlue * 5L >> 4L );
108 }
109 
110 // ------------------------------------------------------------------------
111 
112 inline void ImpErrorQuad::ImplAddColorError7( const ImpErrorQuad& rErrQuad )
113 {
114 	nRed += ( rErrQuad.nRed * 7L >> 4L );
115 	nGreen += ( rErrQuad.nGreen * 7L >> 4L );
116 	nBlue += ( rErrQuad.nBlue *7L >> 4L );
117 }
118 
119 // ------------------------------------------------------------------------
120 
121 inline BitmapColor ImpErrorQuad::ImplGetColor()
122 {
123 	return BitmapColor( (sal_uInt8) ( ( nRed < 0L ? 0L : nRed > 8160L ? 8160L : nRed ) >> 5L ),
124 						(sal_uInt8) ( ( nGreen < 0L ? 0L : nGreen > 8160L ? 8160L : nGreen ) >> 5L ),
125 						(sal_uInt8) ( ( nBlue < 0L ? 0L : nBlue > 8160L ? 8160L : nBlue ) >> 5L ) );
126 }
127 
128 // -------------
129 // - NodeCache -
130 // -------------
131 
132 class ImpNodeCache
133 {
134 	OctreeNode*			pActNode;
135 	sal_uLong				nNew;
136 	sal_uLong				nDelete;
137 	sal_uLong				nGet;
138 	sal_uLong				nRelease;
139 
140 public:
141 
142 						ImpNodeCache( const sal_uLong nInitSize );
143 						~ImpNodeCache();
144 
145 	inline OctreeNode*	ImplGetFreeNode();
146 	inline void			ImplReleaseNode( OctreeNode* pNode );
147 };
148 
149 // ------------------------------------------------------------------------
150 
151 inline OctreeNode* ImpNodeCache::ImplGetFreeNode()
152 {
153 	OctreeNode* pNode;
154 
155 	if ( !pActNode )
156 	{
157 		pActNode = new NODE;
158 		pActNode->pNextInCache = NULL;
159 	}
160 
161 	pNode = pActNode;
162 	pActNode = pNode->pNextInCache;
163 	memset( pNode, 0, sizeof( NODE ) );
164 
165 	return pNode;
166 }
167 
168 // ------------------------------------------------------------------------
169 
170 inline void ImpNodeCache::ImplReleaseNode( OctreeNode* pNode )
171 {
172 	pNode->pNextInCache = pActNode;
173 	pActNode = pNode;
174 }
175 
176 #endif // _SV_IMPOCT_HXX
177