1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _SV_SALBTYPE_HXX
21 #define _SV_SALBTYPE_HXX
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>
37 typedef sal_uInt8
* HPBYTE
;
38 typedef HPBYTE Scanline
;
39 typedef const sal_uInt8
* ConstHPBYTE
;
40 typedef ConstHPBYTE ConstScanline
;
46 #define BMP_FORMAT_BOTTOM_UP 0x00000000UL
47 #define BMP_FORMAT_TOP_DOWN 0x80000000UL
49 #define BMP_FORMAT_1BIT_MSB_PAL 0x00000001UL
50 #define BMP_FORMAT_1BIT_LSB_PAL 0x00000002UL
52 #define BMP_FORMAT_4BIT_MSN_PAL 0x00000004UL
53 #define BMP_FORMAT_4BIT_LSN_PAL 0x00000008UL
55 #define BMP_FORMAT_8BIT_PAL 0x00000010UL
56 #define BMP_FORMAT_8BIT_TC_MASK 0x00000020UL
58 // #define BMP_FORMAT_16BIT_TC_MASK 0x00000040UL
60 #define BMP_FORMAT_24BIT_TC_BGR 0x00000080UL
61 #define BMP_FORMAT_24BIT_TC_RGB 0x00000100UL
62 #define BMP_FORMAT_24BIT_TC_MASK 0x00000200UL
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
70 #define BMP_FORMAT_16BIT_TC_MSB_MASK 0x00008000UL
71 #define BMP_FORMAT_16BIT_TC_LSB_MASK 0x00010000UL
73 #define BMP_SCANLINE_ADJUSTMENT( Mac_nBmpFormat ) ( (Mac_nBmpFormat) & 0x80000000UL )
74 #define BMP_SCANLINE_FORMAT( Mac_nBmpFormat ) ( (Mac_nBmpFormat) & 0x7FFFFFFFUL )
76 // ------------------------------------------------------------------
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 ) ) );
86 // ------------------------------------------------------------------
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 ) )
102 class VCL_DLLPUBLIC BitmapColor
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
;
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 explicit inline BitmapColor( sal_uInt8 cIndex
);
122 inline ~BitmapColor() {};
124 inline sal_Bool
operator==( const BitmapColor
& rBitmapColor
) const;
125 inline sal_Bool
operator!=( const BitmapColor
& rBitmapColor
) const;
126 inline BitmapColor
& operator=( const BitmapColor
& rBitmapColor
);
128 inline sal_Bool
IsIndex() const;
130 inline sal_uInt8
GetRed() const;
131 inline void SetRed( sal_uInt8 cRed
);
133 inline sal_uInt8
GetGreen() const;
134 inline void SetGreen( sal_uInt8 cGreen
);
136 inline sal_uInt8
GetBlue() const;
137 inline void SetBlue( sal_uInt8 cBlue
);
139 inline sal_uInt8
GetIndex() const;
140 inline void SetIndex( sal_uInt8 cIndex
);
142 operator Color() const;
144 inline sal_uInt8
GetBlueOrIndex() const;
146 inline BitmapColor
& Invert();
148 inline sal_uInt8
GetLuminance() const;
149 inline BitmapColor
& IncreaseLuminance( sal_uInt8 cGreyInc
);
150 inline BitmapColor
& DecreaseLuminance( sal_uInt8 cGreyDec
);
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
);
155 inline sal_uLong
GetColorError( const BitmapColor
& rBitmapColor
) const;
164 class VCL_DLLPUBLIC BitmapPalette
166 friend class SalBitmap
;
167 friend class BitmapAccess
;
171 BitmapColor
* mpBitmapColor
;
176 SAL_DLLPRIVATE
inline BitmapColor
* ImplGetColorBuffer() const;
181 inline BitmapPalette();
182 inline BitmapPalette( const BitmapPalette
& rBitmapPalette
);
183 inline BitmapPalette( sal_uInt16 nCount
);
184 inline ~BitmapPalette();
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!();
191 inline sal_uInt16
GetEntryCount() const;
192 inline void SetEntryCount( sal_uInt16 nCount
);
194 inline const BitmapColor
& operator[]( sal_uInt16 nIndex
) const;
195 inline BitmapColor
& operator[]( sal_uInt16 nIndex
);
197 inline sal_uInt16
GetBestIndex( const BitmapColor
& rCol
) const;
198 bool IsGreyPalette() const;
205 class VCL_DLLPUBLIC ColorMask
213 sal_uLong mnROrShift
;
214 sal_uLong mnGOrShift
;
215 sal_uLong mnBOrShift
;
220 SAL_DLLPRIVATE
inline long ImplCalcMaskShift( sal_uLong nMask
, sal_uLong
& rOr
, sal_uLong
& rOrShift
) const;
224 inline ColorMask( sal_uLong nRedMask
= 0UL, sal_uLong nGreenMask
= 0UL, sal_uLong nBlueMask
= 0UL );
225 inline ~ColorMask() {}
227 inline sal_uLong
GetRedMask() const;
228 inline sal_uLong
GetGreenMask() const;
229 inline sal_uLong
GetBlueMask() const;
231 inline void GetColorFor8Bit( BitmapColor
& rColor
, ConstHPBYTE pPixel
) const;
232 inline void SetColorFor8Bit( const BitmapColor
& rColor
, HPBYTE pPixel
) const;
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;
239 inline void GetColorFor24Bit( BitmapColor
& rColor
, ConstHPBYTE pPixel
) const;
240 inline void SetColorFor24Bit( const BitmapColor
& rColor
, HPBYTE pPixel
) const;
242 inline void GetColorFor32Bit( BitmapColor
& rColor
, ConstHPBYTE pPixel
) const;
243 inline void SetColorFor32Bit( const BitmapColor
& rColor
, HPBYTE pPixel
) const;
250 struct VCL_DLLPUBLIC BitmapBuffer
256 sal_uInt16 mnBitCount
;
257 ColorMask maColorMask
;
258 BitmapPalette maPalette
;
265 // ---------------------
266 // - StretchAndConvert -
267 // ---------------------
269 VCL_DLLPUBLIC BitmapBuffer
* StretchAndConvert( const BitmapBuffer
& rSrcBuffer
, const SalTwoRect
& rTwoRect
,
270 sal_uLong nDstBitmapFormat
, BitmapPalette
* pDstPal
= NULL
, ColorMask
* pDstMask
= NULL
);
272 // ------------------------------------------------------------------
274 inline BitmapColor::BitmapColor() :
278 mbIndex ( sal_False
)
282 // ------------------------------------------------------------------
284 inline BitmapColor::BitmapColor( sal_uInt8 cRed
, sal_uInt8 cGreen
, sal_uInt8 cBlue
) :
285 mcBlueOrIndex ( cBlue
),
288 mbIndex ( sal_False
)
292 // ------------------------------------------------------------------
294 inline BitmapColor::BitmapColor( const BitmapColor
& rBitmapColor
) :
295 mcBlueOrIndex ( rBitmapColor
.mcBlueOrIndex
),
296 mcGreen ( rBitmapColor
.mcGreen
),
297 mcRed ( rBitmapColor
.mcRed
),
298 mbIndex ( rBitmapColor
.mbIndex
)
302 // ------------------------------------------------------------------
304 inline BitmapColor::BitmapColor( const Color
& rColor
) :
305 mcBlueOrIndex ( rColor
.GetBlue() ),
306 mcGreen ( rColor
.GetGreen() ),
307 mcRed ( rColor
.GetRed() ),
312 // ------------------------------------------------------------------
314 inline BitmapColor::BitmapColor( sal_uInt8 cIndex
) :
315 mcBlueOrIndex ( cIndex
),
322 // ------------------------------------------------------------------
324 inline sal_Bool
BitmapColor::operator==( const BitmapColor
& rBitmapColor
) const
326 return( ( mcBlueOrIndex
== rBitmapColor
.mcBlueOrIndex
) &&
327 ( mbIndex
? rBitmapColor
.mbIndex
:
328 ( mcGreen
== rBitmapColor
.mcGreen
&& mcRed
== rBitmapColor
.mcRed
) ) );
331 // ------------------------------------------------------------------
333 inline sal_Bool
BitmapColor::operator!=( const BitmapColor
& rBitmapColor
) const
335 return !( *this == rBitmapColor
);
338 // ------------------------------------------------------------------
340 inline BitmapColor
& BitmapColor::operator=( const BitmapColor
& rBitmapColor
)
342 mcBlueOrIndex
= rBitmapColor
.mcBlueOrIndex
;
343 mcGreen
= rBitmapColor
.mcGreen
;
344 mcRed
= rBitmapColor
.mcRed
;
345 mbIndex
= rBitmapColor
.mbIndex
;
350 // ------------------------------------------------------------------
352 inline sal_Bool
BitmapColor::IsIndex() const
357 // ------------------------------------------------------------------
359 inline sal_uInt8
BitmapColor::GetRed() const
361 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
365 // ------------------------------------------------------------------
367 inline void BitmapColor::SetRed( sal_uInt8 cRed
)
369 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
373 // ------------------------------------------------------------------
375 inline sal_uInt8
BitmapColor::GetGreen() const
377 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
381 // ------------------------------------------------------------------
383 inline void BitmapColor::SetGreen( sal_uInt8 cGreen
)
385 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
389 // ------------------------------------------------------------------
391 inline sal_uInt8
BitmapColor::GetBlue() const
393 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
394 return mcBlueOrIndex
;
397 // ------------------------------------------------------------------
399 inline void BitmapColor::SetBlue( sal_uInt8 cBlue
)
401 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
402 mcBlueOrIndex
= cBlue
;
405 // ------------------------------------------------------------------
407 inline sal_uInt8
BitmapColor::GetIndex() const
409 DBG_ASSERT( mbIndex
, "Pixel represents color values!" );
410 return mcBlueOrIndex
;
413 // ------------------------------------------------------------------
415 inline void BitmapColor::SetIndex( sal_uInt8 cIndex
)
417 DBG_ASSERT( mbIndex
, "Pixel represents color values!" );
418 mcBlueOrIndex
= cIndex
;
421 // ------------------------------------------------------------------
423 inline BitmapColor::operator Color() const
425 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
426 return Color( mcRed
, mcGreen
, mcBlueOrIndex
);
429 // ------------------------------------------------------------------
431 inline sal_uInt8
BitmapColor::GetBlueOrIndex() const
433 // #i47518# Yield a value regardless of mbIndex
434 return mcBlueOrIndex
;
437 // ------------------------------------------------------------------
439 inline BitmapColor
& BitmapColor::Invert()
441 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
442 mcBlueOrIndex
= ~mcBlueOrIndex
, mcGreen
= ~mcGreen
, mcRed
= ~mcRed
;
447 // ------------------------------------------------------------------
449 inline sal_uInt8
BitmapColor::GetLuminance() const
451 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
452 return( (sal_uInt8
) ( ( mcBlueOrIndex
* 28UL + mcGreen
* 151UL + mcRed
* 77UL ) >> 8UL ) );
455 // ------------------------------------------------------------------
457 inline BitmapColor
& BitmapColor::IncreaseLuminance( sal_uInt8 cGreyInc
)
459 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
460 mcBlueOrIndex
= (sal_uInt8
) MinMax( (long) mcBlueOrIndex
+ cGreyInc
, 0L, 255L );
461 mcGreen
= (sal_uInt8
) MinMax( (long) mcGreen
+ cGreyInc
, 0L, 255L );
462 mcRed
= (sal_uInt8
) MinMax( (long) mcRed
+ cGreyInc
, 0L, 255L );
467 // ------------------------------------------------------------------
469 inline BitmapColor
& BitmapColor::DecreaseLuminance( sal_uInt8 cGreyDec
)
471 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
472 mcBlueOrIndex
= (sal_uInt8
) MinMax( (long) mcBlueOrIndex
- cGreyDec
, 0L, 255L );
473 mcGreen
= (sal_uInt8
) MinMax( (long) mcGreen
- cGreyDec
, 0L, 255L );
474 mcRed
= (sal_uInt8
) MinMax( (long) mcRed
- cGreyDec
, 0L, 255L );
479 // ------------------------------------------------------------------
481 inline BitmapColor
& BitmapColor::Merge( const BitmapColor
& rBitmapColor
, sal_uInt8 cTransparency
)
483 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
484 DBG_ASSERT( !rBitmapColor
.mbIndex
, "Pixel represents index into colortable!" );
485 mcBlueOrIndex
= COLOR_CHANNEL_MERGE( mcBlueOrIndex
, rBitmapColor
.mcBlueOrIndex
, cTransparency
);
486 mcGreen
= COLOR_CHANNEL_MERGE( mcGreen
, rBitmapColor
.mcGreen
, cTransparency
);
487 mcRed
= COLOR_CHANNEL_MERGE( mcRed
, rBitmapColor
.mcRed
, cTransparency
);
492 // ------------------------------------------------------------------
494 inline BitmapColor
& BitmapColor::Merge( sal_uInt8 cR
, sal_uInt8 cG
, sal_uInt8 cB
, sal_uInt8 cTransparency
)
496 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
497 mcBlueOrIndex
= COLOR_CHANNEL_MERGE( mcBlueOrIndex
, cB
, cTransparency
);
498 mcGreen
= COLOR_CHANNEL_MERGE( mcGreen
, cG
, cTransparency
);
499 mcRed
= COLOR_CHANNEL_MERGE( mcRed
, cR
, cTransparency
);
504 // ------------------------------------------------------------------
506 inline sal_uLong
BitmapColor::GetColorError( const BitmapColor
& rBitmapColor
) const
508 DBG_ASSERT( !mbIndex
, "Pixel represents index into colortable!" );
509 DBG_ASSERT( !rBitmapColor
.mbIndex
, "Pixel represents index into colortable!" );
510 return( (sal_uLong
) ( labs( mcBlueOrIndex
- rBitmapColor
.mcBlueOrIndex
) +
511 labs( mcGreen
- rBitmapColor
.mcGreen
) +
512 labs( mcRed
- rBitmapColor
.mcRed
) ) );
515 // ------------------------------------------------------------------
517 inline BitmapPalette::BitmapPalette() :
518 mpBitmapColor ( NULL
),
523 // ------------------------------------------------------------------
525 inline BitmapPalette::BitmapPalette( const BitmapPalette
& rBitmapPalette
) :
526 mnCount( rBitmapPalette
.mnCount
)
530 const sal_uLong nSize
= mnCount
* sizeof( BitmapColor
);
531 mpBitmapColor
= (BitmapColor
*) new sal_uInt8
[ nSize
];
532 memcpy( mpBitmapColor
, rBitmapPalette
.mpBitmapColor
, nSize
);
535 mpBitmapColor
= NULL
;
538 // ------------------------------------------------------------------
540 inline BitmapPalette::BitmapPalette( sal_uInt16 nCount
) :
545 const sal_uLong nSize
= mnCount
* sizeof( BitmapColor
);
546 mpBitmapColor
= (BitmapColor
*) new sal_uInt8
[ nSize
];
547 memset( mpBitmapColor
, 0, nSize
);
550 mpBitmapColor
= NULL
;
553 // ------------------------------------------------------------------
555 inline BitmapPalette::~BitmapPalette()
557 delete[] (sal_uInt8
*) mpBitmapColor
;
560 // ------------------------------------------------------------------
562 inline BitmapPalette
& BitmapPalette::operator=( const BitmapPalette
& rBitmapPalette
)
564 delete[] (sal_uInt8
*) mpBitmapColor
;
565 mnCount
= rBitmapPalette
.mnCount
;
569 const sal_uLong nSize
= mnCount
* sizeof( BitmapColor
);
570 mpBitmapColor
= (BitmapColor
*) new sal_uInt8
[ nSize
];
571 memcpy( mpBitmapColor
, rBitmapPalette
.mpBitmapColor
, nSize
);
574 mpBitmapColor
= NULL
;
579 // ------------------------------------------------------------------
581 inline sal_Bool
BitmapPalette::operator==( const BitmapPalette
& rBitmapPalette
) const
583 sal_Bool bRet
= sal_False
;
585 if( rBitmapPalette
.mnCount
== mnCount
)
589 for( sal_uInt16 i
= 0; i
< mnCount
; i
++ )
591 if( mpBitmapColor
[ i
] != rBitmapPalette
.mpBitmapColor
[ i
] )
602 // ------------------------------------------------------------------
604 inline sal_Bool
BitmapPalette::operator!=( const BitmapPalette
& rBitmapPalette
) const
606 return !( *this == rBitmapPalette
);
609 // ------------------------------------------------------------------
611 inline sal_Bool
BitmapPalette::operator!()
613 return( !mnCount
|| !mpBitmapColor
);
616 // ------------------------------------------------------------------
618 inline sal_uInt16
BitmapPalette::GetEntryCount() const
623 // ------------------------------------------------------------------
625 inline void BitmapPalette::SetEntryCount( sal_uInt16 nCount
)
629 delete[] (sal_uInt8
*) mpBitmapColor
;
630 mpBitmapColor
= NULL
;
633 else if( nCount
!= mnCount
)
635 const sal_uLong nNewSize
= nCount
* sizeof( BitmapColor
);
636 const sal_uLong nMinSize
= std::min( mnCount
, nCount
) * sizeof( BitmapColor
);
637 sal_uInt8
* pNewColor
= new sal_uInt8
[ nNewSize
];
639 if ( nMinSize
&& mpBitmapColor
)
640 memcpy( pNewColor
, mpBitmapColor
, nMinSize
);
641 delete[] (sal_uInt8
*) mpBitmapColor
;
642 memset( pNewColor
+ nMinSize
, 0, nNewSize
- nMinSize
);
643 mpBitmapColor
= (BitmapColor
*) pNewColor
;
648 // ------------------------------------------------------------------
650 inline const BitmapColor
& BitmapPalette::operator[]( sal_uInt16 nIndex
) const
652 DBG_ASSERT( nIndex
< mnCount
, "Palette index is out of range!" );
653 return mpBitmapColor
[ nIndex
];
656 // ------------------------------------------------------------------
658 inline BitmapColor
& BitmapPalette::operator[]( sal_uInt16 nIndex
)
660 DBG_ASSERT( nIndex
< mnCount
, "Palette index is out of range!" );
661 return mpBitmapColor
[ nIndex
];
664 // ------------------------------------------------------------------
666 inline BitmapColor
* BitmapPalette::ImplGetColorBuffer() const
668 DBG_ASSERT( mpBitmapColor
, "No color buffer available!" );
669 return mpBitmapColor
;
671 // ------------------------------------------------------------------
673 inline sal_uInt16
BitmapPalette::GetBestIndex( const BitmapColor
& rCol
) const
675 sal_uInt16 nRetIndex
= 0;
677 if( mpBitmapColor
&& mnCount
)
679 sal_Bool bFound
= sal_False
;
681 for( long j
= 0L; ( j
< mnCount
) && !bFound
; j
++ )
682 if( rCol
== mpBitmapColor
[ j
] )
683 nRetIndex
= ( (sal_uInt16
) j
), bFound
= sal_True
;
687 long nActErr
, nLastErr
= rCol
.GetColorError( mpBitmapColor
[ nRetIndex
= mnCount
- 1 ] );
689 for( long i
= nRetIndex
- 1; i
>= 0L; i
-- )
690 if ( ( nActErr
= rCol
.GetColorError( mpBitmapColor
[ i
] ) ) < nLastErr
)
691 nLastErr
= nActErr
, nRetIndex
= (sal_uInt16
) i
;
698 // ------------------------------------------------------------------
700 inline ColorMask::ColorMask( sal_uLong nRedMask
, sal_uLong nGreenMask
, sal_uLong nBlueMask
) :
702 mnGMask( nGreenMask
),
703 mnBMask( nBlueMask
),
711 mnRShift
= ( mnRMask
? ImplCalcMaskShift( mnRMask
, mnROr
, mnROrShift
) : 0L );
712 mnGShift
= ( mnGMask
? ImplCalcMaskShift( mnGMask
, mnGOr
, mnGOrShift
) : 0L );
713 mnBShift
= ( mnBMask
? ImplCalcMaskShift( mnBMask
, mnBOr
, mnBOrShift
) : 0L );
716 // ------------------------------------------------------------------
718 inline long ColorMask::ImplCalcMaskShift( sal_uLong nMask
, sal_uLong
& rOr
, sal_uLong
& rOrShift
) const
722 sal_uLong nLen
= 0UL;
724 // from which bit starts the mask?
725 for( nShift
= 31L; ( nShift
>= 0L ) && !( nMask
& ( 1 << (sal_uLong
) nShift
) ); nShift
-- )
730 // XXX determine number of bits set => walk right until null
731 while( ( nShift
>= 0L ) && ( nMask
& ( 1 << (sal_uLong
) nShift
) ) )
737 rOrShift
= 8L - nLen
;
738 rOr
= (sal_uInt8
) ( ( 0xffUL
>> nLen
) << rOrShift
);
743 // ------------------------------------------------------------------
745 inline sal_uLong
ColorMask::GetRedMask() const
750 // ------------------------------------------------------------------
752 inline sal_uLong
ColorMask::GetGreenMask() const
757 // ------------------------------------------------------------------
759 inline sal_uLong
ColorMask::GetBlueMask() const
764 // ------------------------------------------------------------------
766 inline void ColorMask::GetColorFor8Bit( BitmapColor
& rColor
, ConstHPBYTE pPixel
) const
768 const sal_uInt32 nVal
= *pPixel
;
769 MASK_TO_COLOR( nVal
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
, rColor
);
772 // ------------------------------------------------------------------
774 inline void ColorMask::SetColorFor8Bit( const BitmapColor
& rColor
, HPBYTE pPixel
) const
776 *pPixel
= (sal_uInt8
) COLOR_TO_MASK( rColor
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
);
779 // ------------------------------------------------------------------
781 inline void ColorMask::GetColorFor16BitMSB( BitmapColor
& rColor
, ConstHPBYTE pPixel
) const
784 const sal_uInt32 nVal
= *(sal_uInt16
*) pPixel
;
786 const sal_uInt32 nVal
= pPixel
[ 1 ] | ( (sal_uInt32
) pPixel
[ 0 ] << 8UL );
789 MASK_TO_COLOR( nVal
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
, rColor
);
792 // ------------------------------------------------------------------
794 inline void ColorMask::SetColorFor16BitMSB( const BitmapColor
& rColor
, HPBYTE pPixel
) const
796 const sal_uInt16 nVal
= (sal_uInt16
)COLOR_TO_MASK( rColor
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
);
799 *(sal_uInt16
*) pPixel
= nVal
;
801 pPixel
[ 0 ] = (sal_uInt8
)(nVal
>> 8U);
802 pPixel
[ 1 ] = (sal_uInt8
) nVal
;
806 // ------------------------------------------------------------------
808 inline void ColorMask::GetColorFor16BitLSB( BitmapColor
& rColor
, ConstHPBYTE pPixel
) const
811 const sal_uInt32 nVal
= pPixel
[ 0 ] | ( (sal_uInt32
) pPixel
[ 1 ] << 8UL );
813 const sal_uInt32 nVal
= *(sal_uInt16
*) pPixel
;
816 MASK_TO_COLOR( nVal
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
, rColor
);
819 // ------------------------------------------------------------------
821 inline void ColorMask::SetColorFor16BitLSB( const BitmapColor
& rColor
, HPBYTE pPixel
) const
823 const sal_uInt16 nVal
= (sal_uInt16
)COLOR_TO_MASK( rColor
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
);
826 pPixel
[ 0 ] = (sal_uInt8
) nVal
;
827 pPixel
[ 1 ] = (sal_uInt8
)(nVal
>> 8U);
829 *(sal_uInt16
*) pPixel
= nVal
;
834 // ------------------------------------------------------------------
836 inline void ColorMask::GetColorFor24Bit( BitmapColor
& rColor
, ConstHPBYTE pPixel
) const
838 const sal_uInt32 nVal
= pPixel
[ 0 ] | ( (sal_uInt32
) pPixel
[ 1 ] << 8UL ) | ( (sal_uInt32
) pPixel
[ 2 ] << 16UL );
839 MASK_TO_COLOR( nVal
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
, rColor
);
842 // ------------------------------------------------------------------
844 inline void ColorMask::SetColorFor24Bit( const BitmapColor
& rColor
, HPBYTE pPixel
) const
846 const sal_uInt32 nVal
= COLOR_TO_MASK( rColor
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
);
847 pPixel
[ 0 ] = (sal_uInt8
) nVal
; pPixel
[ 1 ] = (sal_uInt8
) ( nVal
>> 8UL ); pPixel
[ 2 ] = (sal_uInt8
) ( nVal
>> 16UL );
850 // ------------------------------------------------------------------
852 inline void ColorMask::GetColorFor32Bit( BitmapColor
& rColor
, ConstHPBYTE pPixel
) const
855 const sal_uInt32 nVal
= (sal_uInt32
) pPixel
[ 0 ] | ( (sal_uInt32
) pPixel
[ 1 ] << 8UL ) |
856 ( (sal_uInt32
) pPixel
[ 2 ] << 16UL ) | ( (sal_uInt32
) pPixel
[ 3 ] << 24UL );
858 const sal_uInt32 nVal
= *(sal_uInt32
*) pPixel
;
861 MASK_TO_COLOR( nVal
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
, rColor
);
864 // ------------------------------------------------------------------
866 inline void ColorMask::SetColorFor32Bit( const BitmapColor
& rColor
, HPBYTE pPixel
) const
869 const sal_uInt32 nVal
= COLOR_TO_MASK( rColor
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
);
870 pPixel
[ 0 ] = (sal_uInt8
) nVal
; pPixel
[ 1 ] = (sal_uInt8
) ( nVal
>> 8UL );
871 pPixel
[ 2 ] = (sal_uInt8
) ( nVal
>> 16UL ); pPixel
[ 3 ] = (sal_uInt8
) ( nVal
>> 24UL );
873 *(sal_uInt32
*) pPixel
= COLOR_TO_MASK( rColor
, mnRMask
, mnGMask
, mnBMask
, mnRShift
, mnGShift
, mnBShift
);
877 #endif // _SV_SALBTYPE_HXX
879 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */