Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef _SV_IMPOCT_HXX
21 : : #define _SV_IMPOCT_HXX
22 : :
23 : : #include <vcl/octree.hxx>
24 : :
25 : : // ----------------
26 : : // - ImpErrorQuad -
27 : : // ----------------
28 : :
29 : : class ImpErrorQuad
30 : : {
31 : : long nRed;
32 : : long nGreen;
33 : : long nBlue;
34 : :
35 : : public:
36 : :
37 : 0 : inline ImpErrorQuad() {}
38 : 0 : inline ImpErrorQuad( const BitmapColor& rColor ) :
39 : 0 : nRed ( (long) rColor.GetRed() << 5L ),
40 : 0 : nGreen ( (long) rColor.GetGreen() << 5L ),
41 : 0 : nBlue ( (long) rColor.GetBlue() << 5L ) {}
42 : :
43 : : inline void operator=( const BitmapColor& rColor );
44 : : inline ImpErrorQuad& operator-=( const BitmapColor& rColor );
45 : :
46 : : inline void ImplAddColorError1( const ImpErrorQuad& rErrQuad );
47 : : inline void ImplAddColorError3( const ImpErrorQuad& rErrQuad );
48 : : inline void ImplAddColorError5( const ImpErrorQuad& rErrQuad );
49 : : inline void ImplAddColorError7( const ImpErrorQuad& rErrQuad );
50 : :
51 : : inline BitmapColor ImplGetColor();
52 : : };
53 : :
54 : : // ------------------------------------------------------------------------
55 : :
56 : 0 : inline void ImpErrorQuad::operator=( const BitmapColor& rColor )
57 : : {
58 : 0 : nRed = (long) rColor.GetRed() << 5L;
59 : 0 : nGreen = (long) rColor.GetGreen() << 5L;
60 : 0 : nBlue = (long) rColor.GetBlue() << 5L;
61 : 0 : }
62 : :
63 : : // ------------------------------------------------------------------------
64 : :
65 : 0 : inline ImpErrorQuad& ImpErrorQuad::operator-=( const BitmapColor& rColor )
66 : : {
67 : 0 : nRed -= ( (long) rColor.GetRed() << 5L );
68 : 0 : nGreen -= ( (long) rColor.GetGreen() << 5L );
69 : 0 : nBlue -= ( (long) rColor.GetBlue() << 5L );
70 : :
71 : 0 : return *this;
72 : : }
73 : :
74 : : // ------------------------------------------------------------------------
75 : :
76 : 0 : inline void ImpErrorQuad::ImplAddColorError1( const ImpErrorQuad& rErrQuad )
77 : : {
78 : 0 : nRed += ( rErrQuad.nRed >> 4L );
79 : 0 : nGreen += ( rErrQuad.nGreen >> 4L );
80 : 0 : nBlue += ( rErrQuad.nBlue >> 4L );
81 : 0 : }
82 : :
83 : : // ------------------------------------------------------------------------
84 : :
85 : 0 : inline void ImpErrorQuad::ImplAddColorError3( const ImpErrorQuad& rErrQuad )
86 : : {
87 : 0 : nRed += ( rErrQuad.nRed * 3L >> 4L );
88 : 0 : nGreen += ( rErrQuad.nGreen * 3L >> 4L );
89 : 0 : nBlue += ( rErrQuad.nBlue * 3L >> 4L );
90 : 0 : }
91 : :
92 : : // ------------------------------------------------------------------------
93 : :
94 : 0 : inline void ImpErrorQuad::ImplAddColorError5( const ImpErrorQuad& rErrQuad )
95 : : {
96 : 0 : nRed += ( rErrQuad.nRed * 5L >> 4L );
97 : 0 : nGreen += ( rErrQuad.nGreen * 5L >> 4L );
98 : 0 : nBlue += ( rErrQuad.nBlue * 5L >> 4L );
99 : 0 : }
100 : :
101 : : // ------------------------------------------------------------------------
102 : :
103 : 0 : inline void ImpErrorQuad::ImplAddColorError7( const ImpErrorQuad& rErrQuad )
104 : : {
105 : 0 : nRed += ( rErrQuad.nRed * 7L >> 4L );
106 : 0 : nGreen += ( rErrQuad.nGreen * 7L >> 4L );
107 : 0 : nBlue += ( rErrQuad.nBlue *7L >> 4L );
108 : 0 : }
109 : :
110 : : // ------------------------------------------------------------------------
111 : :
112 : 0 : inline BitmapColor ImpErrorQuad::ImplGetColor()
113 : : {
114 : : return BitmapColor( (sal_uInt8) ( ( nRed < 0L ? 0L : nRed > 8160L ? 8160L : nRed ) >> 5L ),
115 : : (sal_uInt8) ( ( nGreen < 0L ? 0L : nGreen > 8160L ? 8160L : nGreen ) >> 5L ),
116 [ # # ][ # # ]: 0 : (sal_uInt8) ( ( nBlue < 0L ? 0L : nBlue > 8160L ? 8160L : nBlue ) >> 5L ) );
[ # # ]
117 : : }
118 : :
119 : : // -------------
120 : : // - NodeCache -
121 : : // -------------
122 : :
123 : : class ImpNodeCache
124 : : {
125 : : OctreeNode* pActNode;
126 : :
127 : : public:
128 : :
129 : : ImpNodeCache( const sal_uLong nInitSize );
130 : : ~ImpNodeCache();
131 : :
132 : : inline OctreeNode* ImplGetFreeNode();
133 : : inline void ImplReleaseNode( OctreeNode* pNode );
134 : : };
135 : :
136 : : // ------------------------------------------------------------------------
137 : :
138 : 0 : inline OctreeNode* ImpNodeCache::ImplGetFreeNode()
139 : : {
140 : : OctreeNode* pNode;
141 : :
142 [ # # ]: 0 : if ( !pActNode )
143 : : {
144 : 0 : pActNode = new NODE;
145 : 0 : pActNode->pNextInCache = NULL;
146 : : }
147 : :
148 : 0 : pNode = pActNode;
149 : 0 : pActNode = pNode->pNextInCache;
150 : 0 : memset( pNode, 0, sizeof( NODE ) );
151 : :
152 : 0 : return pNode;
153 : : }
154 : :
155 : : // ------------------------------------------------------------------------
156 : :
157 : 0 : inline void ImpNodeCache::ImplReleaseNode( OctreeNode* pNode )
158 : : {
159 : 0 : pNode->pNextInCache = pActNode;
160 : 0 : pActNode = pNode;
161 : 0 : }
162 : :
163 : : #endif // _SV_IMPOCT_HXX
164 : :
165 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|