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_SALBTYPE_HXX
21 : : #define _SV_SALBTYPE_HXX
22 : : #include <stdio.h>
23 : : #include <string.h>
24 : : #include <stdlib.h>
25 : : #include <osl/endian.h>
26 : : #include <tools/debug.hxx>
27 : : #include <vcl/salgtype.hxx>
28 : : #include <tools/color.hxx>
29 : : #include <tools/helpers.hxx>
30 : : #include <tools/solar.h>
31 : : #include <vcl/dllapi.h>
32 : :
33 : : // ----------
34 : : // - Memory -
35 : : // ----------
36 : :
37 : : typedef sal_uInt8* HPBYTE;
38 : : typedef HPBYTE Scanline;
39 : : typedef const sal_uInt8* ConstHPBYTE;
40 : : typedef ConstHPBYTE ConstScanline;
41 : :
42 : : // ------------------
43 : : // - Bitmap formats -
44 : : // ------------------
45 : :
46 : : #define BMP_FORMAT_BOTTOM_UP 0x00000000UL
47 : : #define BMP_FORMAT_TOP_DOWN 0x80000000UL
48 : :
49 : : #define BMP_FORMAT_1BIT_MSB_PAL 0x00000001UL
50 : : #define BMP_FORMAT_1BIT_LSB_PAL 0x00000002UL
51 : :
52 : : #define BMP_FORMAT_4BIT_MSN_PAL 0x00000004UL
53 : : #define BMP_FORMAT_4BIT_LSN_PAL 0x00000008UL
54 : :
55 : : #define BMP_FORMAT_8BIT_PAL 0x00000010UL
56 : : #define BMP_FORMAT_8BIT_TC_MASK 0x00000020UL
57 : :
58 : : // #define BMP_FORMAT_16BIT_TC_MASK 0x00000040UL
59 : :
60 : : #define BMP_FORMAT_24BIT_TC_BGR 0x00000080UL
61 : : #define BMP_FORMAT_24BIT_TC_RGB 0x00000100UL
62 : : #define BMP_FORMAT_24BIT_TC_MASK 0x00000200UL
63 : :
64 : : #define BMP_FORMAT_32BIT_TC_ABGR 0x00000400UL
65 : : #define BMP_FORMAT_32BIT_TC_ARGB 0x00000800UL
66 : : #define BMP_FORMAT_32BIT_TC_BGRA 0x00001000UL
67 : : #define BMP_FORMAT_32BIT_TC_RGBA 0x00002000UL
68 : : #define BMP_FORMAT_32BIT_TC_MASK 0x00004000UL
69 : :
70 : : #define BMP_FORMAT_16BIT_TC_MSB_MASK 0x00008000UL
71 : : #define BMP_FORMAT_16BIT_TC_LSB_MASK 0x00010000UL
72 : :
73 : : #define BMP_SCANLINE_ADJUSTMENT( Mac_nBmpFormat ) ( (Mac_nBmpFormat) & 0x80000000UL )
74 : : #define BMP_SCANLINE_FORMAT( Mac_nBmpFormat ) ( (Mac_nBmpFormat) & 0x7FFFFFFFUL )
75 : :
76 : : // ------------------------------------------------------------------
77 : :
78 : : #define MASK_TO_COLOR( d_nVal, d_RM, d_GM, d_BM, d_RS, d_GS, d_BS, d_Col ) \
79 : : sal_uLong _def_cR = (sal_uInt8) ( d_RS < 0L ? ( (d_nVal) & d_RM ) << -d_RS : ( (d_nVal) & d_RM ) >> d_RS ); \
80 : : sal_uLong _def_cG = (sal_uInt8) ( d_GS < 0L ? ( (d_nVal) & d_GM ) << -d_GS : ( (d_nVal) & d_GM ) >> d_GS ); \
81 : : sal_uLong _def_cB = (sal_uInt8) ( d_BS < 0L ? ( (d_nVal) & d_BM ) << -d_BS : ( (d_nVal) & d_BM ) >> d_BS ); \
82 : : d_Col = BitmapColor( (sal_uInt8) ( _def_cR | ( ( _def_cR & mnROr ) >> mnROrShift ) ), \
83 : : (sal_uInt8) ( _def_cG | ( ( _def_cG & mnGOr ) >> mnGOrShift ) ), \
84 : : (sal_uInt8) ( _def_cB | ( ( _def_cB & mnBOr ) >> mnBOrShift ) ) );
85 : :
86 : : // ------------------------------------------------------------------
87 : :
88 : : #define COLOR_TO_MASK( d_rCol, d_RM, d_GM, d_BM, d_RS, d_GS, d_BS ) \
89 : : ( ( ( ( d_RS < 0L ) ? ( (sal_uInt32) (d_rCol).GetRed() >> -d_RS ) : \
90 : : ( (sal_uInt32) (d_rCol).GetRed() << d_RS ) ) & d_RM ) | \
91 : : ( ( ( d_GS < 0L ) ? ( (sal_uInt32) (d_rCol).GetGreen() >> -d_GS ) : \
92 : : ( (sal_uInt32) (d_rCol).GetGreen() << d_GS ) ) & d_GM ) | \
93 : : ( ( ( d_BS < 0L ) ? ( (sal_uInt32) (d_rCol).GetBlue() >> -d_BS ) : \
94 : : ( (sal_uInt32) (d_rCol).GetBlue() << d_BS ) ) & d_BM ) )
95 : :
96 : : // ---------------
97 : : // - BitmapColor -
98 : : // ---------------
99 : :
100 : : class Color;
101 : :
102 : : class VCL_DLLPUBLIC BitmapColor
103 : : {
104 : : private:
105 : :
106 : : // ATTENTION:
107 : : // Because the members of this class are accessed via memcpy,
108 : : // you MUST NOT CHANGE the order of the members or the size of this class!
109 : : sal_uInt8 mcBlueOrIndex;
110 : : sal_uInt8 mcGreen;
111 : : sal_uInt8 mcRed;
112 : : sal_uInt8 mbIndex;
113 : :
114 : : public:
115 : :
116 : : inline BitmapColor();
117 : : inline BitmapColor( const BitmapColor& rBitmapColor );
118 : : inline BitmapColor( sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue );
119 : : inline BitmapColor( const Color& rColor );
120 : : inline BitmapColor( sal_uInt8 cIndex );
121 : 1776198745 : inline ~BitmapColor() {};
122 : :
123 : : inline sal_Bool operator==( const BitmapColor& rBitmapColor ) const;
124 : : inline sal_Bool operator!=( const BitmapColor& rBitmapColor ) const;
125 : : inline BitmapColor& operator=( const BitmapColor& rBitmapColor );
126 : :
127 : : inline sal_Bool IsIndex() const;
128 : :
129 : : inline sal_uInt8 GetRed() const;
130 : : inline void SetRed( sal_uInt8 cRed );
131 : :
132 : : inline sal_uInt8 GetGreen() const;
133 : : inline void SetGreen( sal_uInt8 cGreen );
134 : :
135 : : inline sal_uInt8 GetBlue() const;
136 : : inline void SetBlue( sal_uInt8 cBlue );
137 : :
138 : : inline sal_uInt8 GetIndex() const;
139 : : inline void SetIndex( sal_uInt8 cIndex );
140 : :
141 : : operator Color() const;
142 : : inline operator sal_uInt8() const;
143 : :
144 : : inline sal_uInt8 GetBlueOrIndex() const;
145 : :
146 : : inline BitmapColor& Invert();
147 : :
148 : : inline sal_uInt8 GetLuminance() const;
149 : : inline BitmapColor& IncreaseLuminance( sal_uInt8 cGreyInc );
150 : : inline BitmapColor& DecreaseLuminance( sal_uInt8 cGreyDec );
151 : :
152 : : inline BitmapColor& Merge( const BitmapColor& rColor, sal_uInt8 cTransparency );
153 : : inline BitmapColor& Merge( sal_uInt8 cR, sal_uInt8 cG, sal_uInt8 cB, sal_uInt8 cTransparency );
154 : :
155 : : inline sal_uLong GetColorError( const BitmapColor& rBitmapColor ) const;
156 : : };
157 : :
158 : : // ---------------
159 : : // - BitmapPalette -
160 : : // ---------------
161 : :
162 : : class Palette;
163 : :
164 : : class VCL_DLLPUBLIC BitmapPalette
165 : : {
166 : : friend class SalBitmap;
167 : : friend class BitmapAccess;
168 : :
169 : : private:
170 : :
171 : : BitmapColor* mpBitmapColor;
172 : : sal_uInt16 mnCount;
173 : :
174 : : public:
175 : :
176 : : SAL_DLLPRIVATE inline BitmapColor* ImplGetColorBuffer() const;
177 : :
178 : :
179 : : public:
180 : :
181 : : inline BitmapPalette();
182 : : inline BitmapPalette( const BitmapPalette& rBitmapPalette );
183 : : inline BitmapPalette( sal_uInt16 nCount );
184 : : inline ~BitmapPalette();
185 : :
186 : : inline BitmapPalette& operator=( const BitmapPalette& rBitmapPalette );
187 : : inline sal_Bool operator==( const BitmapPalette& rBitmapPalette ) const;
188 : : inline sal_Bool operator!=( const BitmapPalette& rBitmapPalette ) const;
189 : : inline sal_Bool operator!();
190 : :
191 : : inline sal_uInt16 GetEntryCount() const;
192 : : inline void SetEntryCount( sal_uInt16 nCount );
193 : :
194 : : inline const BitmapColor& operator[]( sal_uInt16 nIndex ) const;
195 : : inline BitmapColor& operator[]( sal_uInt16 nIndex );
196 : :
197 : : inline sal_uInt16 GetBestIndex( const BitmapColor& rCol ) const;
198 : : bool IsGreyPalette() const;
199 : : };
200 : :
201 : : // ---------------
202 : : // - ColorMask -
203 : : // ---------------
204 : :
205 : : class VCL_DLLPUBLIC ColorMask
206 : : {
207 : : sal_uLong mnRMask;
208 : : sal_uLong mnGMask;
209 : : sal_uLong mnBMask;
210 : : long mnRShift;
211 : : long mnGShift;
212 : : long mnBShift;
213 : : sal_uLong mnROrShift;
214 : : sal_uLong mnGOrShift;
215 : : sal_uLong mnBOrShift;
216 : : sal_uLong mnROr;
217 : : sal_uLong mnGOr;
218 : : sal_uLong mnBOr;
219 : :
220 : : SAL_DLLPRIVATE inline long ImplCalcMaskShift( sal_uLong nMask, sal_uLong& rOr, sal_uLong& rOrShift ) const;
221 : :
222 : : public:
223 : :
224 : : inline ColorMask( sal_uLong nRedMask = 0UL, sal_uLong nGreenMask = 0UL, sal_uLong nBlueMask = 0UL );
225 : 2564936 : inline ~ColorMask() {}
226 : :
227 : : inline sal_uLong GetRedMask() const;
228 : : inline sal_uLong GetGreenMask() const;
229 : : inline sal_uLong GetBlueMask() const;
230 : :
231 : : inline void GetColorFor8Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const;
232 : : inline void SetColorFor8Bit( const BitmapColor& rColor, HPBYTE pPixel ) const;
233 : :
234 : : inline void GetColorFor16BitMSB( BitmapColor& rColor, ConstHPBYTE pPixel ) const;
235 : : inline void SetColorFor16BitMSB( const BitmapColor& rColor, HPBYTE pPixel ) const;
236 : : inline void GetColorFor16BitLSB( BitmapColor& rColor, ConstHPBYTE pPixel ) const;
237 : : inline void SetColorFor16BitLSB( const BitmapColor& rColor, HPBYTE pPixel ) const;
238 : :
239 : : inline void GetColorFor24Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const;
240 : : inline void SetColorFor24Bit( const BitmapColor& rColor, HPBYTE pPixel ) const;
241 : :
242 : : inline void GetColorFor32Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const;
243 : : inline void SetColorFor32Bit( const BitmapColor& rColor, HPBYTE pPixel ) const;
244 : : };
245 : :
246 : : // ---------------
247 : : // - BitmapBuffer -
248 : : // ---------------
249 : :
250 : 0 : struct VCL_DLLPUBLIC BitmapBuffer
251 : : {
252 : : sal_uLong mnFormat;
253 : : long mnWidth;
254 : : long mnHeight;
255 : : long mnScanlineSize;
256 : : sal_uInt16 mnBitCount;
257 : : ColorMask maColorMask;
258 : : BitmapPalette maPalette;
259 : : sal_uInt8* mpBits;
260 : :
261 : 1279942 : BitmapBuffer(){}
262 : 1279942 : ~BitmapBuffer() {}
263 : : };
264 : :
265 : : // ---------------------
266 : : // - StretchAndConvert -
267 : : // ---------------------
268 : :
269 : : VCL_DLLPUBLIC BitmapBuffer* StretchAndConvert( const BitmapBuffer& rSrcBuffer, const SalTwoRect& rTwoRect,
270 : : sal_uLong nDstBitmapFormat, BitmapPalette* pDstPal = NULL, ColorMask* pDstMask = NULL );
271 : :
272 : : // ------------------------------------------------------------------
273 : :
274 : 768585385 : inline BitmapColor::BitmapColor() :
275 : : mcBlueOrIndex ( 0 ),
276 : : mcGreen ( 0 ),
277 : : mcRed ( 0 ),
278 : 768585385 : mbIndex ( sal_False )
279 : : {
280 : 768585385 : }
281 : :
282 : : // ------------------------------------------------------------------
283 : :
284 : 751610825 : inline BitmapColor::BitmapColor( sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue ) :
285 : : mcBlueOrIndex ( cBlue ),
286 : : mcGreen ( cGreen ),
287 : : mcRed ( cRed ),
288 : 751610825 : mbIndex ( sal_False )
289 : : {
290 : 751610825 : }
291 : :
292 : : // ------------------------------------------------------------------
293 : :
294 : 420148 : inline BitmapColor::BitmapColor( const BitmapColor& rBitmapColor ) :
295 : : mcBlueOrIndex ( rBitmapColor.mcBlueOrIndex ),
296 : : mcGreen ( rBitmapColor.mcGreen ),
297 : : mcRed ( rBitmapColor.mcRed ),
298 : 420148 : mbIndex ( rBitmapColor.mbIndex )
299 : : {
300 : 420148 : }
301 : :
302 : : // ------------------------------------------------------------------
303 : :
304 : 1818222 : inline BitmapColor::BitmapColor( const Color& rColor ) :
305 : 1818222 : mcBlueOrIndex ( rColor.GetBlue() ),
306 : 1818222 : mcGreen ( rColor.GetGreen() ),
307 : 1818222 : mcRed ( rColor.GetRed() ),
308 : 5454666 : mbIndex ( 0 )
309 : : {
310 : 1818222 : }
311 : :
312 : : // ------------------------------------------------------------------
313 : :
314 : 253764165 : inline BitmapColor::BitmapColor( sal_uInt8 cIndex ) :
315 : : mcBlueOrIndex ( cIndex ),
316 : : mcGreen ( 0 ),
317 : : mcRed ( 0 ),
318 : 253764165 : mbIndex ( sal_True )
319 : : {
320 : 253764165 : }
321 : :
322 : : // ------------------------------------------------------------------
323 : :
324 : 179339794 : inline sal_Bool BitmapColor::operator==( const BitmapColor& rBitmapColor ) const
325 : : {
326 : : return( ( mcBlueOrIndex == rBitmapColor.mcBlueOrIndex ) &&
327 : : ( mbIndex ? rBitmapColor.mbIndex :
328 [ + + ][ + + ]: 179339794 : ( mcGreen == rBitmapColor.mcGreen && mcRed == rBitmapColor.mcRed ) ) );
[ + - ][ + + ]
[ + + ]
329 : : }
330 : :
331 : : // ------------------------------------------------------------------
332 : :
333 : 57295435 : inline sal_Bool BitmapColor::operator!=( const BitmapColor& rBitmapColor ) const
334 : : {
335 : 57295435 : return !( *this == rBitmapColor );
336 : : }
337 : :
338 : : // ------------------------------------------------------------------
339 : :
340 : 1046490319 : inline BitmapColor& BitmapColor::operator=( const BitmapColor& rBitmapColor )
341 : : {
342 : 1046490319 : mcBlueOrIndex = rBitmapColor.mcBlueOrIndex;
343 : 1046490319 : mcGreen = rBitmapColor.mcGreen;
344 : 1046490319 : mcRed = rBitmapColor.mcRed;
345 : 1046490319 : mbIndex = rBitmapColor.mbIndex;
346 : :
347 : 1046490319 : return *this;
348 : : }
349 : :
350 : : // ------------------------------------------------------------------
351 : :
352 : 0 : inline sal_Bool BitmapColor::IsIndex() const
353 : : {
354 : 0 : return mbIndex;
355 : : }
356 : :
357 : : // ------------------------------------------------------------------
358 : :
359 : 1501439838 : inline sal_uInt8 BitmapColor::GetRed() const
360 : : {
361 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
362 : 1501439838 : return mcRed;
363 : : }
364 : :
365 : : // ------------------------------------------------------------------
366 : :
367 : 797106610 : inline void BitmapColor::SetRed( sal_uInt8 cRed )
368 : : {
369 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
370 : 797106610 : mcRed = cRed;
371 : 797106610 : }
372 : :
373 : : // ------------------------------------------------------------------
374 : :
375 : 1501201350 : inline sal_uInt8 BitmapColor::GetGreen() const
376 : : {
377 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
378 : 1501201350 : return mcGreen;
379 : : }
380 : :
381 : : // ------------------------------------------------------------------
382 : :
383 : 797106610 : inline void BitmapColor::SetGreen( sal_uInt8 cGreen )
384 : : {
385 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
386 : 797106610 : mcGreen = cGreen;
387 : 797106610 : }
388 : :
389 : : // ------------------------------------------------------------------
390 : :
391 : 1501200866 : inline sal_uInt8 BitmapColor::GetBlue() const
392 : : {
393 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
394 : 1501200866 : return mcBlueOrIndex;
395 : : }
396 : :
397 : : // ------------------------------------------------------------------
398 : :
399 : 797106610 : inline void BitmapColor::SetBlue( sal_uInt8 cBlue )
400 : : {
401 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
402 : 797106610 : mcBlueOrIndex = cBlue;
403 : 797106610 : }
404 : :
405 : : // ------------------------------------------------------------------
406 : :
407 : 194116145 : inline sal_uInt8 BitmapColor::GetIndex() const
408 : : {
409 : : DBG_ASSERT( mbIndex, "Pixel represents color values!" );
410 : 194116145 : return mcBlueOrIndex;
411 : : }
412 : :
413 : : // ------------------------------------------------------------------
414 : :
415 : 6557330 : inline void BitmapColor::SetIndex( sal_uInt8 cIndex )
416 : : {
417 : : DBG_ASSERT( mbIndex, "Pixel represents color values!" );
418 : 6557330 : mcBlueOrIndex = cIndex;
419 : 6557330 : }
420 : :
421 : : // ------------------------------------------------------------------
422 : :
423 : 393 : inline BitmapColor::operator Color() const
424 : : {
425 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
426 : 393 : return Color( mcRed, mcGreen, mcBlueOrIndex );
427 : : }
428 : :
429 : : // ------------------------------------------------------------------
430 : :
431 : 61872696 : inline BitmapColor::operator sal_uInt8() const
432 : : {
433 : : DBG_ASSERT( mbIndex, "Pixel represents color values!" );
434 : 61872696 : return mcBlueOrIndex;
435 : : }
436 : :
437 : : // ------------------------------------------------------------------
438 : :
439 : 74094 : inline sal_uInt8 BitmapColor::GetBlueOrIndex() const
440 : : {
441 : : // #i47518# Yield a value regardless of mbIndex
442 : 74094 : return mcBlueOrIndex;
443 : : }
444 : :
445 : : // ------------------------------------------------------------------
446 : :
447 : 40 : inline BitmapColor& BitmapColor::Invert()
448 : : {
449 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
450 : 40 : mcBlueOrIndex = ~mcBlueOrIndex, mcGreen = ~mcGreen, mcRed = ~mcRed;
451 : :
452 : 40 : return *this;
453 : : }
454 : :
455 : : // ------------------------------------------------------------------
456 : :
457 : 3319870 : inline sal_uInt8 BitmapColor::GetLuminance() const
458 : : {
459 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
460 : 3319870 : return( (sal_uInt8) ( ( mcBlueOrIndex * 28UL + mcGreen * 151UL + mcRed * 77UL ) >> 8UL ) );
461 : : }
462 : :
463 : : // ------------------------------------------------------------------
464 : :
465 : : inline BitmapColor& BitmapColor::IncreaseLuminance( sal_uInt8 cGreyInc )
466 : : {
467 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
468 : : mcBlueOrIndex = (sal_uInt8) MinMax( (long) mcBlueOrIndex + cGreyInc, 0L, 255L );
469 : : mcGreen = (sal_uInt8) MinMax( (long) mcGreen + cGreyInc, 0L, 255L );
470 : : mcRed = (sal_uInt8) MinMax( (long) mcRed + cGreyInc, 0L, 255L );
471 : :
472 : : return *this;
473 : : }
474 : :
475 : : // ------------------------------------------------------------------
476 : :
477 : : inline BitmapColor& BitmapColor::DecreaseLuminance( sal_uInt8 cGreyDec )
478 : : {
479 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
480 : : mcBlueOrIndex = (sal_uInt8) MinMax( (long) mcBlueOrIndex - cGreyDec, 0L, 255L );
481 : : mcGreen = (sal_uInt8) MinMax( (long) mcGreen - cGreyDec, 0L, 255L );
482 : : mcRed = (sal_uInt8) MinMax( (long) mcRed - cGreyDec, 0L, 255L );
483 : :
484 : : return *this;
485 : : }
486 : :
487 : : // ------------------------------------------------------------------
488 : :
489 : 8996882 : inline BitmapColor& BitmapColor::Merge( const BitmapColor& rBitmapColor, sal_uInt8 cTransparency )
490 : : {
491 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
492 : : DBG_ASSERT( !rBitmapColor.mbIndex, "Pixel represents index into colortable!" );
493 : 8996882 : mcBlueOrIndex = COLOR_CHANNEL_MERGE( mcBlueOrIndex, rBitmapColor.mcBlueOrIndex, cTransparency );
494 : 8996882 : mcGreen = COLOR_CHANNEL_MERGE( mcGreen, rBitmapColor.mcGreen, cTransparency );
495 : 8996882 : mcRed = COLOR_CHANNEL_MERGE( mcRed, rBitmapColor.mcRed, cTransparency );
496 : :
497 : 8996882 : return *this;
498 : : }
499 : :
500 : : // ------------------------------------------------------------------
501 : :
502 : 118927947 : inline BitmapColor& BitmapColor::Merge( sal_uInt8 cR, sal_uInt8 cG, sal_uInt8 cB, sal_uInt8 cTransparency )
503 : : {
504 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
505 : 118927947 : mcBlueOrIndex = COLOR_CHANNEL_MERGE( mcBlueOrIndex, cB, cTransparency );
506 : 118927947 : mcGreen = COLOR_CHANNEL_MERGE( mcGreen, cG, cTransparency );
507 : 118927947 : mcRed = COLOR_CHANNEL_MERGE( mcRed, cR, cTransparency );
508 : :
509 : 118927947 : return *this;
510 : : }
511 : :
512 : : // ------------------------------------------------------------------
513 : :
514 : 4192 : inline sal_uLong BitmapColor::GetColorError( const BitmapColor& rBitmapColor ) const
515 : : {
516 : : DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
517 : : DBG_ASSERT( !rBitmapColor.mbIndex, "Pixel represents index into colortable!" );
518 : 4192 : return( (sal_uLong) ( labs( mcBlueOrIndex - rBitmapColor.mcBlueOrIndex ) +
519 : 4192 : labs( mcGreen - rBitmapColor.mcGreen ) +
520 : 4192 : labs( mcRed - rBitmapColor.mcRed ) ) );
521 : : }
522 : :
523 : : // ------------------------------------------------------------------
524 : :
525 : 1531394 : inline BitmapPalette::BitmapPalette() :
526 : : mpBitmapColor ( NULL ),
527 : 1531394 : mnCount ( 0 )
528 : : {
529 : 1531394 : }
530 : :
531 : : // ------------------------------------------------------------------
532 : :
533 : 12 : inline BitmapPalette::BitmapPalette( const BitmapPalette& rBitmapPalette ) :
534 : 12 : mnCount( rBitmapPalette.mnCount )
535 : : {
536 [ + - ]: 12 : if( mnCount )
537 : : {
538 : 12 : const sal_uLong nSize = mnCount * sizeof( BitmapColor );
539 : 12 : mpBitmapColor = (BitmapColor*) new sal_uInt8[ nSize ];
540 : 12 : memcpy( mpBitmapColor, rBitmapPalette.mpBitmapColor, nSize );
541 : : }
542 : : else
543 : 0 : mpBitmapColor = NULL;
544 : 12 : }
545 : :
546 : : // ------------------------------------------------------------------
547 : :
548 : 55 : inline BitmapPalette::BitmapPalette( sal_uInt16 nCount ) :
549 : 55 : mnCount( nCount )
550 : : {
551 [ + - ]: 55 : if( mnCount )
552 : : {
553 : 55 : const sal_uLong nSize = mnCount * sizeof( BitmapColor );
554 : 55 : mpBitmapColor = (BitmapColor*) new sal_uInt8[ nSize ];
555 : 55 : memset( mpBitmapColor, 0, nSize );
556 : : }
557 : : else
558 : 0 : mpBitmapColor = NULL;
559 : 55 : }
560 : :
561 : : // ------------------------------------------------------------------
562 : :
563 : 1531461 : inline BitmapPalette::~BitmapPalette()
564 : : {
565 [ + + ]: 1531461 : delete[] (sal_uInt8*) mpBitmapColor;
566 : 1531461 : }
567 : :
568 : : // ------------------------------------------------------------------
569 : :
570 : 138 : inline BitmapPalette& BitmapPalette::operator=( const BitmapPalette& rBitmapPalette )
571 : : {
572 [ + - ]: 138 : delete[] (sal_uInt8*) mpBitmapColor;
573 : 138 : mnCount = rBitmapPalette.mnCount;
574 : :
575 [ + - ]: 138 : if( mnCount )
576 : : {
577 : 138 : const sal_uLong nSize = mnCount * sizeof( BitmapColor );
578 : 138 : mpBitmapColor = (BitmapColor*) new sal_uInt8[ nSize ];
579 : 138 : memcpy( mpBitmapColor, rBitmapPalette.mpBitmapColor, nSize );
580 : : }
581 : : else
582 : 0 : mpBitmapColor = NULL;
583 : :
584 : 138 : return *this;
585 : : }
586 : :
587 : : // ------------------------------------------------------------------
588 : :
589 : 223799 : inline sal_Bool BitmapPalette::operator==( const BitmapPalette& rBitmapPalette ) const
590 : : {
591 : 223799 : sal_Bool bRet = sal_False;
592 : :
593 [ + - ]: 223799 : if( rBitmapPalette.mnCount == mnCount )
594 : : {
595 : 223799 : bRet = sal_True;
596 : :
597 [ + + ]: 57516343 : for( sal_uInt16 i = 0; i < mnCount; i++ )
598 : : {
599 [ - + ]: 57292544 : if( mpBitmapColor[ i ] != rBitmapPalette.mpBitmapColor[ i ] )
600 : : {
601 : 0 : bRet = sal_False;
602 : 0 : break;
603 : : }
604 : : }
605 : : }
606 : :
607 : 223799 : return bRet;
608 : : }
609 : :
610 : : // ------------------------------------------------------------------
611 : :
612 : 223786 : inline sal_Bool BitmapPalette::operator!=( const BitmapPalette& rBitmapPalette ) const
613 : : {
614 : 223786 : return !( *this == rBitmapPalette );
615 : : }
616 : :
617 : : // ------------------------------------------------------------------
618 : :
619 : 610378019 : inline sal_Bool BitmapPalette::operator!()
620 : : {
621 [ + + ][ - + ]: 610378019 : return( !mnCount || !mpBitmapColor );
622 : : }
623 : :
624 : : // ------------------------------------------------------------------
625 : :
626 : 1440369 : inline sal_uInt16 BitmapPalette::GetEntryCount() const
627 : : {
628 : 1440369 : return mnCount;
629 : : }
630 : :
631 : : // ------------------------------------------------------------------
632 : :
633 : 664421 : inline void BitmapPalette::SetEntryCount( sal_uInt16 nCount )
634 : : {
635 [ - + ]: 664421 : if( !nCount )
636 : : {
637 [ # # ]: 0 : delete[] (sal_uInt8*) mpBitmapColor;
638 : 0 : mpBitmapColor = NULL;
639 : 0 : mnCount = 0;
640 : : }
641 [ + + ]: 664421 : else if( nCount != mnCount )
642 : : {
643 : 663867 : const sal_uLong nNewSize = nCount * sizeof( BitmapColor );
644 : 663867 : const sal_uLong nMinSize = Min( mnCount, nCount ) * sizeof( BitmapColor );
645 : 663867 : sal_uInt8* pNewColor = new sal_uInt8[ nNewSize ];
646 : :
647 [ + - ][ + + ]: 663867 : if ( nMinSize && mpBitmapColor )
648 : 1153 : memcpy( pNewColor, mpBitmapColor, nMinSize );
649 [ + + ]: 663867 : delete[] (sal_uInt8*) mpBitmapColor;
650 : 663867 : memset( pNewColor + nMinSize, 0, nNewSize - nMinSize );
651 : 663867 : mpBitmapColor = (BitmapColor*) pNewColor;
652 : 663867 : mnCount = nCount;
653 : : }
654 : 664421 : }
655 : :
656 : : // ------------------------------------------------------------------
657 : :
658 : 28417142 : inline const BitmapColor& BitmapPalette::operator[]( sal_uInt16 nIndex ) const
659 : : {
660 : : DBG_ASSERT( nIndex < mnCount, "Palette index is out of range!" );
661 : 28417142 : return mpBitmapColor[ nIndex ];
662 : : }
663 : :
664 : : // ------------------------------------------------------------------
665 : :
666 : 270183857 : inline BitmapColor& BitmapPalette::operator[]( sal_uInt16 nIndex )
667 : : {
668 : : DBG_ASSERT( nIndex < mnCount, "Palette index is out of range!" );
669 : 270183857 : return mpBitmapColor[ nIndex ];
670 : : }
671 : :
672 : : // ------------------------------------------------------------------
673 : :
674 : 1598 : inline BitmapColor* BitmapPalette::ImplGetColorBuffer() const
675 : : {
676 : : DBG_ASSERT( mpBitmapColor, "No color buffer available!" );
677 : 1598 : return mpBitmapColor;
678 : : }
679 : : // ------------------------------------------------------------------
680 : :
681 : 968318 : inline sal_uInt16 BitmapPalette::GetBestIndex( const BitmapColor& rCol ) const
682 : : {
683 : 968318 : sal_uInt16 nRetIndex = 0;
684 : :
685 [ + - ][ + - ]: 968318 : if( mpBitmapColor && mnCount )
686 : : {
687 : 968318 : sal_Bool bFound = sal_False;
688 : :
689 [ + + ][ + + ]: 118453991 : for( long j = 0L; ( j < mnCount ) && !bFound; j++ )
[ + + ]
690 [ + + ]: 117485673 : if( rCol == mpBitmapColor[ j ] )
691 : 968296 : nRetIndex = ( (sal_uInt16) j ), bFound = sal_True;
692 : :
693 [ + + ]: 968318 : if( !bFound )
694 : : {
695 : 22 : long nActErr, nLastErr = rCol.GetColorError( mpBitmapColor[ nRetIndex = mnCount - 1 ] );
696 : :
697 [ + + ]: 4192 : for( long i = nRetIndex - 1; i >= 0L; i-- )
698 [ + + ]: 4170 : if ( ( nActErr = rCol.GetColorError( mpBitmapColor[ i ] ) ) < nLastErr )
699 : 14 : nLastErr = nActErr, nRetIndex = (sal_uInt16) i;
700 : : }
701 : : }
702 : :
703 : 968318 : return nRetIndex;
704 : : }
705 : :
706 : : // ------------------------------------------------------------------
707 : :
708 : 2564936 : inline ColorMask::ColorMask( sal_uLong nRedMask, sal_uLong nGreenMask, sal_uLong nBlueMask ) :
709 : : mnRMask( nRedMask ),
710 : : mnGMask( nGreenMask ),
711 : : mnBMask( nBlueMask ),
712 : : mnROrShift( 0L ),
713 : : mnGOrShift( 0L ),
714 : : mnBOrShift( 0L ),
715 : : mnROr( 0L ),
716 : : mnGOr( 0L ),
717 : 2564936 : mnBOr( 0L )
718 : : {
719 [ - + ]: 2564936 : mnRShift = ( mnRMask ? ImplCalcMaskShift( mnRMask, mnROr, mnROrShift ) : 0L );
720 [ - + ]: 2564936 : mnGShift = ( mnGMask ? ImplCalcMaskShift( mnGMask, mnGOr, mnGOrShift ) : 0L );
721 [ - + ]: 2564936 : mnBShift = ( mnBMask ? ImplCalcMaskShift( mnBMask, mnBOr, mnBOrShift ) : 0L );
722 : 2564936 : }
723 : :
724 : : // ------------------------------------------------------------------
725 : :
726 : 0 : inline long ColorMask::ImplCalcMaskShift( sal_uLong nMask, sal_uLong& rOr, sal_uLong& rOrShift ) const
727 : : {
728 : : long nShift;
729 : : long nRet;
730 : 0 : sal_uLong nLen = 0UL;
731 : :
732 : : // from which bit starts the mask?
733 [ # # ][ # # ]: 0 : for( nShift = 31L; ( nShift >= 0L ) && !( nMask & ( 1 << (sal_uLong) nShift ) ); nShift-- )
[ # # ]
734 : : {}
735 : :
736 : 0 : nRet = nShift;
737 : :
738 : : // XXX determine number of bits set => walk right until null
739 [ # # ][ # # ]: 0 : while( ( nShift >= 0L ) && ( nMask & ( 1 << (sal_uLong) nShift ) ) )
[ # # ]
740 : : {
741 : 0 : nShift--;
742 : 0 : nLen++;
743 : : }
744 : :
745 : 0 : rOrShift = 8L - nLen;
746 : 0 : rOr = (sal_uInt8) ( ( 0xffUL >> nLen ) << rOrShift );
747 : :
748 : 0 : return( nRet -= 7 );
749 : : }
750 : :
751 : : // ------------------------------------------------------------------
752 : :
753 : 2877 : inline sal_uLong ColorMask::GetRedMask() const
754 : : {
755 : 2877 : return mnRMask;
756 : : }
757 : :
758 : : // ------------------------------------------------------------------
759 : :
760 : 2877 : inline sal_uLong ColorMask::GetGreenMask() const
761 : : {
762 : 2877 : return mnGMask;
763 : : }
764 : :
765 : : // ------------------------------------------------------------------
766 : :
767 : 2877 : inline sal_uLong ColorMask::GetBlueMask() const
768 : : {
769 : 2877 : return mnBMask;
770 : : }
771 : :
772 : : // ------------------------------------------------------------------
773 : :
774 : 0 : inline void ColorMask::GetColorFor8Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const
775 : : {
776 : 0 : const sal_uInt32 nVal = *pPixel;
777 [ # # ][ # # ]: 0 : MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
[ # # ]
778 : 0 : }
779 : :
780 : : // ------------------------------------------------------------------
781 : :
782 : 0 : inline void ColorMask::SetColorFor8Bit( const BitmapColor& rColor, HPBYTE pPixel ) const
783 : : {
784 [ # # ][ # # ]: 0 : *pPixel = (sal_uInt8) COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
[ # # ]
785 : 0 : }
786 : :
787 : : // ------------------------------------------------------------------
788 : :
789 : 0 : inline void ColorMask::GetColorFor16BitMSB( BitmapColor& rColor, ConstHPBYTE pPixel ) const
790 : : {
791 : : #ifdef OSL_BIGENDIAN
792 : : const sal_uInt32 nVal = *(sal_uInt16*) pPixel;
793 : : #else
794 : 0 : const sal_uInt32 nVal = pPixel[ 1 ] | ( (sal_uInt32) pPixel[ 0 ] << 8UL );
795 : : #endif
796 : :
797 [ # # ][ # # ]: 0 : MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
[ # # ]
798 : 0 : }
799 : :
800 : : // ------------------------------------------------------------------
801 : :
802 : 0 : inline void ColorMask::SetColorFor16BitMSB( const BitmapColor& rColor, HPBYTE pPixel ) const
803 : : {
804 [ # # ][ # # ]: 0 : const sal_uInt16 nVal = (sal_uInt16)COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
[ # # ]
805 : :
806 : : #ifdef OSL_BIGENDIAN
807 : : *(sal_uInt16*) pPixel = nVal;
808 : : #else
809 : 0 : pPixel[ 0 ] = (sal_uInt8)(nVal >> 8U);
810 : 0 : pPixel[ 1 ] = (sal_uInt8) nVal;
811 : : #endif
812 : 0 : }
813 : :
814 : : // ------------------------------------------------------------------
815 : :
816 : 0 : inline void ColorMask::GetColorFor16BitLSB( BitmapColor& rColor, ConstHPBYTE pPixel ) const
817 : : {
818 : : #ifdef OSL_BIGENDIAN
819 : : const sal_uInt32 nVal = pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL );
820 : : #else
821 : 0 : const sal_uInt32 nVal = *(sal_uInt16*) pPixel;
822 : : #endif
823 : :
824 [ # # ][ # # ]: 0 : MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
[ # # ]
825 : 0 : }
826 : :
827 : : // ------------------------------------------------------------------
828 : :
829 : 0 : inline void ColorMask::SetColorFor16BitLSB( const BitmapColor& rColor, HPBYTE pPixel ) const
830 : : {
831 [ # # ][ # # ]: 0 : const sal_uInt16 nVal = (sal_uInt16)COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
[ # # ]
832 : :
833 : : #ifdef OSL_BIGENDIAN
834 : : pPixel[ 0 ] = (sal_uInt8) nVal;
835 : : pPixel[ 1 ] = (sal_uInt8)(nVal >> 8U);
836 : : #else
837 : 0 : *(sal_uInt16*) pPixel = nVal;
838 : : #endif
839 : 0 : }
840 : :
841 : :
842 : : // ------------------------------------------------------------------
843 : :
844 : 0 : inline void ColorMask::GetColorFor24Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const
845 : : {
846 : 0 : const sal_uInt32 nVal = pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL ) | ( (sal_uInt32) pPixel[ 2 ] << 16UL );
847 [ # # ][ # # ]: 0 : MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
[ # # ]
848 : 0 : }
849 : :
850 : : // ------------------------------------------------------------------
851 : :
852 : 0 : inline void ColorMask::SetColorFor24Bit( const BitmapColor& rColor, HPBYTE pPixel ) const
853 : : {
854 [ # # ][ # # ]: 0 : const sal_uInt32 nVal = COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
[ # # ]
855 : 0 : pPixel[ 0 ] = (sal_uInt8) nVal; pPixel[ 1 ] = (sal_uInt8) ( nVal >> 8UL ); pPixel[ 2 ] = (sal_uInt8) ( nVal >> 16UL );
856 : 0 : }
857 : :
858 : : // ------------------------------------------------------------------
859 : :
860 : 0 : inline void ColorMask::GetColorFor32Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const
861 : : {
862 : : #ifdef OSL_BIGENDIAN
863 : : const sal_uInt32 nVal = (sal_uInt32) pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL ) |
864 : : ( (sal_uInt32) pPixel[ 2 ] << 16UL ) | ( (sal_uInt32) pPixel[ 3 ] << 24UL );
865 : : #else
866 : 0 : const sal_uInt32 nVal = *(sal_uInt32*) pPixel;
867 : : #endif
868 : :
869 [ # # ][ # # ]: 0 : MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
[ # # ]
870 : 0 : }
871 : :
872 : : // ------------------------------------------------------------------
873 : :
874 : 0 : inline void ColorMask::SetColorFor32Bit( const BitmapColor& rColor, HPBYTE pPixel ) const
875 : : {
876 : : #ifdef OSL_BIGENDIAN
877 : : const sal_uInt32 nVal = COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
878 : : pPixel[ 0 ] = (sal_uInt8) nVal; pPixel[ 1 ] = (sal_uInt8) ( nVal >> 8UL );
879 : : pPixel[ 2 ] = (sal_uInt8) ( nVal >> 16UL ); pPixel[ 3 ] = (sal_uInt8) ( nVal >> 24UL );
880 : : #else
881 [ # # ][ # # ]: 0 : *(sal_uInt32*) pPixel = COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
[ # # ]
882 : : #endif
883 : 0 : }
884 : :
885 : : #endif // _SV_SALBTYPE_HXX
886 : :
887 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|