LCOV - code coverage report
Current view: top level - include/vcl - salbtype.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 185 226 81.9 %
Date: 2014-04-11 Functions: 49 59 83.1 %
Legend: Lines: hit not hit

          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 INCLUDED_VCL_SALBTYPE_HXX
      21             : #define INCLUDED_VCL_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             :     explicit inline     BitmapColor( sal_uInt8 cIndex );
     121             : 
     122  2202037552 :     inline              ~BitmapColor() {};
     123             : 
     124             :     inline bool         operator==( const BitmapColor& rBitmapColor ) const;
     125             :     inline bool         operator!=( const BitmapColor& rBitmapColor ) const;
     126             :     inline BitmapColor& operator=( const BitmapColor& rBitmapColor );
     127             : 
     128             :     inline bool         IsIndex() const;
     129             : 
     130             :     inline sal_uInt8        GetRed() const;
     131             :     inline void         SetRed( sal_uInt8 cRed );
     132             : 
     133             :     inline sal_uInt8        GetGreen() const;
     134             :     inline void         SetGreen( sal_uInt8 cGreen );
     135             : 
     136             :     inline sal_uInt8        GetBlue() const;
     137             :     inline void         SetBlue( sal_uInt8 cBlue );
     138             : 
     139             :     inline sal_uInt8        GetIndex() const;
     140             :     inline void         SetIndex( sal_uInt8 cIndex );
     141             : 
     142             :     operator            Color() 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 bool             operator==( const BitmapPalette& rBitmapPalette ) const;
     188             :     inline bool             operator!=( const BitmapPalette& rBitmapPalette ) const;
     189             :     inline 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     1106630 :     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         GetColorAndAlphaFor32Bit( BitmapColor& rColor, sal_uInt8& rAlpha, ConstHPBYTE pPixel ) const;
     244             :     inline void         SetColorFor32Bit( const BitmapColor& rColor, HPBYTE pPixel ) const;
     245             : };
     246             : 
     247             : 
     248             : // - BitmapBuffer -
     249             : 
     250             : 
     251           0 : struct VCL_DLLPUBLIC BitmapBuffer
     252             : {
     253             :     sal_uLong           mnFormat;
     254             :     long            mnWidth;
     255             :     long            mnHeight;
     256             :     long            mnScanlineSize;
     257             :     sal_uInt16          mnBitCount;
     258             :     ColorMask       maColorMask;
     259             :     BitmapPalette   maPalette;
     260             :     sal_uInt8*          mpBits;
     261             : 
     262      553284 :                     BitmapBuffer(){}
     263      553284 :                     ~BitmapBuffer() {}
     264             : };
     265             : 
     266             : 
     267             : // - StretchAndConvert -
     268             : 
     269             : 
     270             : VCL_DLLPUBLIC BitmapBuffer* StretchAndConvert(
     271             :     const BitmapBuffer& rSrcBuffer, const SalTwoRect& rTwoRect,
     272             :     sal_uLong nDstBitmapFormat, const BitmapPalette* pDstPal = NULL, const ColorMask* pDstMask = NULL );
     273             : 
     274             : 
     275             : 
     276  1651715775 : inline BitmapColor::BitmapColor() :
     277             :             mcBlueOrIndex   ( 0 ),
     278             :             mcGreen         ( 0 ),
     279             :             mcRed           ( 0 ),
     280  1651715775 :             mbIndex         ( false )
     281             : {
     282  1651715775 : }
     283             : 
     284             : 
     285             : 
     286   152930626 : inline BitmapColor::BitmapColor( sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue ) :
     287             :             mcBlueOrIndex   ( cBlue ),
     288             :             mcGreen         ( cGreen ),
     289             :             mcRed           ( cRed ),
     290   152930626 :             mbIndex         ( false )
     291             : {
     292   152930626 : }
     293             : 
     294             : 
     295             : 
     296     9505952 : inline BitmapColor::BitmapColor( const BitmapColor& rBitmapColor ) :
     297             :             mcBlueOrIndex   ( rBitmapColor.mcBlueOrIndex ),
     298             :             mcGreen         ( rBitmapColor.mcGreen ),
     299             :             mcRed           ( rBitmapColor.mcRed ),
     300     9505952 :             mbIndex         ( rBitmapColor.mbIndex )
     301             : {
     302     9505952 : }
     303             : 
     304             : 
     305             : 
     306      622440 : inline BitmapColor::BitmapColor( const Color& rColor ) :
     307      622440 :             mcBlueOrIndex   ( rColor.GetBlue() ),
     308      622440 :             mcGreen         ( rColor.GetGreen() ),
     309      622440 :             mcRed           ( rColor.GetRed() ),
     310     1867320 :             mbIndex         ( 0 )
     311             : {
     312      622440 : }
     313             : 
     314             : 
     315             : 
     316   387262759 : inline BitmapColor::BitmapColor( sal_uInt8 cIndex ) :
     317             :             mcBlueOrIndex   ( cIndex ),
     318             :             mcGreen         ( 0 ),
     319             :             mcRed           ( 0 ),
     320   387262759 :             mbIndex         ( true )
     321             : {
     322   387262759 : }
     323             : 
     324             : 
     325             : 
     326    98765690 : inline bool BitmapColor::operator==( const BitmapColor& rBitmapColor ) const
     327             : {
     328   136432883 :     return( ( mcBlueOrIndex == rBitmapColor.mcBlueOrIndex ) &&
     329             :             ( mbIndex ? rBitmapColor.mbIndex :
     330   136474374 :             ( mcGreen == rBitmapColor.mcGreen && mcRed == rBitmapColor.mcRed ) ) );
     331             : }
     332             : 
     333             : 
     334             : 
     335    37903728 : inline bool BitmapColor::operator!=( const BitmapColor& rBitmapColor ) const
     336             : {
     337    37903728 :     return !( *this == rBitmapColor );
     338             : }
     339             : 
     340             : 
     341             : 
     342  1140644423 : inline BitmapColor& BitmapColor::operator=( const BitmapColor& rBitmapColor )
     343             : {
     344  1140644423 :     mcBlueOrIndex = rBitmapColor.mcBlueOrIndex;
     345  1140644423 :     mcGreen = rBitmapColor.mcGreen;
     346  1140644423 :     mcRed = rBitmapColor.mcRed;
     347  1140644423 :     mbIndex = rBitmapColor.mbIndex;
     348             : 
     349  1140644423 :     return *this;
     350             : }
     351             : 
     352             : 
     353             : 
     354           0 : inline bool BitmapColor::IsIndex() const
     355             : {
     356           0 :     return mbIndex;
     357             : }
     358             : 
     359             : 
     360             : 
     361  1246008084 : inline sal_uInt8 BitmapColor::GetRed() const
     362             : {
     363             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     364  1246008084 :     return mcRed;
     365             : }
     366             : 
     367             : 
     368             : 
     369   730502093 : inline void BitmapColor::SetRed( sal_uInt8 cRed )
     370             : {
     371             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     372   730502093 :     mcRed = cRed;
     373   730502093 : }
     374             : 
     375             : 
     376             : 
     377  1245875137 : inline sal_uInt8 BitmapColor::GetGreen() const
     378             : {
     379             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     380  1245875137 :     return mcGreen;
     381             : }
     382             : 
     383             : 
     384             : 
     385   730502093 : inline void BitmapColor::SetGreen( sal_uInt8 cGreen )
     386             : {
     387             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     388   730502093 :     mcGreen = cGreen;
     389   730502093 : }
     390             : 
     391             : 
     392             : 
     393  1245874863 : inline sal_uInt8 BitmapColor::GetBlue() const
     394             : {
     395             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     396  1245874863 :     return mcBlueOrIndex;
     397             : }
     398             : 
     399             : 
     400             : 
     401   730502093 : inline void BitmapColor::SetBlue( sal_uInt8 cBlue )
     402             : {
     403             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     404   730502093 :     mcBlueOrIndex = cBlue;
     405   730502093 : }
     406             : 
     407             : 
     408             : 
     409    36255054 : inline sal_uInt8 BitmapColor::GetIndex() const
     410             : {
     411             :     DBG_ASSERT( mbIndex, "Pixel represents color values!" );
     412    36255054 :     return mcBlueOrIndex;
     413             : }
     414             : 
     415             : 
     416             : 
     417     4103816 : inline void BitmapColor::SetIndex( sal_uInt8 cIndex )
     418             : {
     419             :     DBG_ASSERT( mbIndex, "Pixel represents color values!" );
     420     4103816 :     mcBlueOrIndex = cIndex;
     421     4103816 : }
     422             : 
     423             : 
     424             : 
     425         204 : inline BitmapColor::operator Color() const
     426             : {
     427             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     428         204 :     return Color( mcRed, mcGreen, mcBlueOrIndex );
     429             : }
     430             : 
     431             : 
     432             : 
     433   352922126 : inline sal_uInt8 BitmapColor::GetBlueOrIndex() const
     434             : {
     435             :     // #i47518# Yield a value regardless of mbIndex
     436   352922126 :     return mcBlueOrIndex;
     437             : }
     438             : 
     439             : 
     440             : 
     441        3084 : inline BitmapColor& BitmapColor::Invert()
     442             : {
     443             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     444        3084 :     mcBlueOrIndex = ~mcBlueOrIndex, mcGreen = ~mcGreen, mcRed = ~mcRed;
     445             : 
     446        3084 :     return *this;
     447             : }
     448             : 
     449             : 
     450             : 
     451     9525020 : inline sal_uInt8 BitmapColor::GetLuminance() const
     452             : {
     453             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     454     9525020 :     return( (sal_uInt8) ( ( mcBlueOrIndex * 28UL + mcGreen * 151UL + mcRed * 77UL ) >> 8UL ) );
     455             : }
     456             : 
     457             : 
     458             : 
     459             : inline BitmapColor& BitmapColor::IncreaseLuminance( sal_uInt8 cGreyInc )
     460             : {
     461             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     462             :     mcBlueOrIndex = (sal_uInt8) MinMax( (long) mcBlueOrIndex + cGreyInc, 0L, 255L );
     463             :     mcGreen = (sal_uInt8) MinMax( (long) mcGreen + cGreyInc, 0L, 255L );
     464             :     mcRed = (sal_uInt8) MinMax( (long) mcRed + cGreyInc, 0L, 255L );
     465             : 
     466             :     return *this;
     467             : }
     468             : 
     469             : 
     470             : 
     471             : inline BitmapColor& BitmapColor::DecreaseLuminance( sal_uInt8 cGreyDec )
     472             : {
     473             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     474             :     mcBlueOrIndex = (sal_uInt8) MinMax( (long) mcBlueOrIndex - cGreyDec, 0L, 255L );
     475             :     mcGreen = (sal_uInt8) MinMax( (long) mcGreen - cGreyDec, 0L, 255L );
     476             :     mcRed = (sal_uInt8) MinMax( (long) mcRed - cGreyDec, 0L, 255L );
     477             : 
     478             :     return *this;
     479             : }
     480             : 
     481             : 
     482             : 
     483     4290201 : inline BitmapColor& BitmapColor::Merge( const BitmapColor& rBitmapColor, sal_uInt8 cTransparency )
     484             : {
     485             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     486             :     DBG_ASSERT( !rBitmapColor.mbIndex, "Pixel represents index into colortable!" );
     487     4290201 :     mcBlueOrIndex = COLOR_CHANNEL_MERGE( mcBlueOrIndex, rBitmapColor.mcBlueOrIndex, cTransparency );
     488     4290201 :     mcGreen = COLOR_CHANNEL_MERGE( mcGreen, rBitmapColor.mcGreen, cTransparency );
     489     4290201 :     mcRed = COLOR_CHANNEL_MERGE( mcRed, rBitmapColor.mcRed, cTransparency );
     490             : 
     491     4290201 :     return *this;
     492             : }
     493             : 
     494             : 
     495             : 
     496   123633558 : inline BitmapColor& BitmapColor::Merge( sal_uInt8 cR, sal_uInt8 cG, sal_uInt8 cB, sal_uInt8 cTransparency )
     497             : {
     498             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     499   123633558 :     mcBlueOrIndex = COLOR_CHANNEL_MERGE( mcBlueOrIndex, cB, cTransparency );
     500   123633558 :     mcGreen = COLOR_CHANNEL_MERGE( mcGreen, cG, cTransparency );
     501   123633558 :     mcRed = COLOR_CHANNEL_MERGE( mcRed, cR, cTransparency );
     502             : 
     503   123633558 :     return *this;
     504             : }
     505             : 
     506             : 
     507             : 
     508       17938 : inline sal_uLong BitmapColor::GetColorError( const BitmapColor& rBitmapColor ) const
     509             : {
     510             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     511             :     DBG_ASSERT( !rBitmapColor.mbIndex, "Pixel represents index into colortable!" );
     512       35876 :     return( (sal_uLong) ( labs( mcBlueOrIndex - rBitmapColor.mcBlueOrIndex ) +
     513       35876 :                       labs( mcGreen - rBitmapColor.mcGreen ) +
     514       35876 :                       labs( mcRed - rBitmapColor.mcRed ) ) );
     515             : }
     516             : 
     517             : 
     518             : 
     519      604379 : inline BitmapPalette::BitmapPalette() :
     520             :             mpBitmapColor   ( NULL ),
     521      604379 :             mnCount         ( 0 )
     522             : {
     523      604379 : }
     524             : 
     525             : 
     526             : 
     527           6 : inline BitmapPalette::BitmapPalette( const BitmapPalette& rBitmapPalette ) :
     528           6 :             mnCount( rBitmapPalette.mnCount )
     529             : {
     530           6 :     if( mnCount )
     531             :     {
     532           6 :         const sal_uLong nSize = mnCount * sizeof( BitmapColor );
     533           6 :         mpBitmapColor = (BitmapColor*) new sal_uInt8[ nSize ];
     534           6 :         memcpy( mpBitmapColor, rBitmapPalette.mpBitmapColor, nSize );
     535             :     }
     536             :     else
     537           0 :         mpBitmapColor = NULL;
     538           6 : }
     539             : 
     540             : 
     541             : 
     542         123 : inline BitmapPalette::BitmapPalette( sal_uInt16 nCount ) :
     543         123 :             mnCount( nCount )
     544             : {
     545         123 :     if( mnCount )
     546             :     {
     547         123 :         const sal_uLong nSize = mnCount * sizeof( BitmapColor );
     548         123 :         mpBitmapColor = (BitmapColor*) new sal_uInt8[ nSize ];
     549         123 :         memset( mpBitmapColor, 0, nSize );
     550             :     }
     551             :     else
     552           0 :         mpBitmapColor = NULL;
     553         123 : }
     554             : 
     555             : 
     556             : 
     557      604508 : inline BitmapPalette::~BitmapPalette()
     558             : {
     559      604508 :     delete[] (sal_uInt8*) mpBitmapColor;
     560      604508 : }
     561             : 
     562             : 
     563             : 
     564         952 : inline BitmapPalette& BitmapPalette::operator=( const BitmapPalette& rBitmapPalette )
     565             : {
     566         952 :     delete[] (sal_uInt8*) mpBitmapColor;
     567         952 :     mnCount = rBitmapPalette.mnCount;
     568             : 
     569         952 :     if( mnCount )
     570             :     {
     571         952 :         const sal_uLong nSize = mnCount * sizeof( BitmapColor );
     572         952 :         mpBitmapColor = (BitmapColor*) new sal_uInt8[ nSize ];
     573         952 :         memcpy( mpBitmapColor, rBitmapPalette.mpBitmapColor, nSize );
     574             :     }
     575             :     else
     576           0 :         mpBitmapColor = NULL;
     577             : 
     578         952 :     return *this;
     579             : }
     580             : 
     581             : 
     582             : 
     583      131794 : inline bool BitmapPalette::operator==( const BitmapPalette& rBitmapPalette ) const
     584             : {
     585      131794 :     bool bRet = false;
     586             : 
     587      131794 :     if( rBitmapPalette.mnCount == mnCount )
     588             :     {
     589      131794 :         bRet = true;
     590             : 
     591    33609172 :         for( sal_uInt16 i = 0; i < mnCount; i++ )
     592             :         {
     593    33478405 :             if( mpBitmapColor[ i ] != rBitmapPalette.mpBitmapColor[ i ] )
     594             :             {
     595        1027 :                 bRet = false;
     596        1027 :                 break;
     597             :             }
     598             :         }
     599             :     }
     600             : 
     601      131794 :     return bRet;
     602             : }
     603             : 
     604             : 
     605             : 
     606      130055 : inline bool BitmapPalette::operator!=( const BitmapPalette& rBitmapPalette ) const
     607             : {
     608      130055 :     return !( *this == rBitmapPalette );
     609             : }
     610             : 
     611             : 
     612             : 
     613   953221855 : inline bool BitmapPalette::operator!()
     614             : {
     615   953221855 :     return( !mnCount || !mpBitmapColor );
     616             : }
     617             : 
     618             : 
     619             : 
     620      688860 : inline sal_uInt16 BitmapPalette::GetEntryCount() const
     621             : {
     622      688860 :     return mnCount;
     623             : }
     624             : 
     625             : 
     626             : 
     627      320803 : inline void BitmapPalette::SetEntryCount( sal_uInt16 nCount )
     628             : {
     629      320803 :     if( !nCount )
     630             :     {
     631           0 :         delete[] (sal_uInt8*) mpBitmapColor;
     632           0 :         mpBitmapColor = NULL;
     633           0 :         mnCount = 0;
     634             :     }
     635      320803 :     else if( nCount != mnCount )
     636             :     {
     637      320585 :         const sal_uLong nNewSize = nCount * sizeof( BitmapColor );
     638      320585 :         const sal_uLong nMinSize = std::min( mnCount, nCount ) * sizeof( BitmapColor );
     639      320585 :         sal_uInt8*      pNewColor = new sal_uInt8[ nNewSize ];
     640             : 
     641      320585 :         if ( nMinSize && mpBitmapColor )
     642         701 :             memcpy( pNewColor, mpBitmapColor, nMinSize );
     643      320585 :         delete[] (sal_uInt8*) mpBitmapColor;
     644      320585 :         memset( pNewColor + nMinSize, 0, nNewSize - nMinSize );
     645      320585 :         mpBitmapColor = (BitmapColor*) pNewColor;
     646      320585 :         mnCount = nCount;
     647             :     }
     648      320803 : }
     649             : 
     650             : 
     651             : 
     652     8395075 : inline const BitmapColor& BitmapPalette::operator[]( sal_uInt16 nIndex ) const
     653             : {
     654             :     DBG_ASSERT( nIndex < mnCount, "Palette index is out of range!" );
     655     8395075 :     return mpBitmapColor[ nIndex ];
     656             : }
     657             : 
     658             : 
     659             : 
     660   490053133 : inline BitmapColor& BitmapPalette::operator[]( sal_uInt16 nIndex )
     661             : {
     662             :     DBG_ASSERT( nIndex < mnCount, "Palette index is out of range!" );
     663   490053133 :     return mpBitmapColor[ nIndex ];
     664             : }
     665             : 
     666             : 
     667             : 
     668         436 : inline BitmapColor* BitmapPalette::ImplGetColorBuffer() const
     669             : {
     670             :     DBG_ASSERT( mpBitmapColor, "No color buffer available!" );
     671         436 :     return mpBitmapColor;
     672             : }
     673             : 
     674             : 
     675      470785 : inline sal_uInt16 BitmapPalette::GetBestIndex( const BitmapColor& rCol ) const
     676             : {
     677      470785 :     sal_uInt16 nRetIndex = 0;
     678             : 
     679      470785 :     if( mpBitmapColor && mnCount )
     680             :     {
     681      470785 :         bool bFound = false;
     682             : 
     683    58180069 :         for( long j = 0L; ( j < mnCount ) && !bFound; j++ )
     684    57709284 :             if( rCol == mpBitmapColor[ j ] )
     685      470653 :                 nRetIndex = ( (sal_uInt16) j ), bFound = true;
     686             : 
     687      470785 :         if( !bFound )
     688             :         {
     689         132 :             long nActErr, nLastErr = rCol.GetColorError( mpBitmapColor[ nRetIndex = mnCount - 1 ] );
     690             : 
     691       17938 :             for( long i = nRetIndex - 1; i >= 0L; i-- )
     692       17806 :                 if ( ( nActErr = rCol.GetColorError( mpBitmapColor[ i ] ) ) < nLastErr )
     693          85 :                     nLastErr = nActErr, nRetIndex = (sal_uInt16) i;
     694             :         }
     695             :     }
     696             : 
     697      470785 :     return nRetIndex;
     698             : }
     699             : 
     700             : 
     701             : 
     702     1106630 : inline ColorMask::ColorMask( sal_uLong nRedMask, sal_uLong nGreenMask, sal_uLong nBlueMask ) :
     703             :             mnRMask( nRedMask ),
     704             :             mnGMask( nGreenMask ),
     705             :             mnBMask( nBlueMask ),
     706             :             mnROrShift( 0L ),
     707             :             mnGOrShift( 0L ),
     708             :             mnBOrShift( 0L ),
     709             :             mnROr( 0L ),
     710             :             mnGOr( 0L ),
     711     1106630 :             mnBOr( 0L )
     712             : {
     713     1106630 :     mnRShift = ( mnRMask ? ImplCalcMaskShift( mnRMask, mnROr, mnROrShift ) : 0L );
     714     1106630 :     mnGShift = ( mnGMask ? ImplCalcMaskShift( mnGMask, mnGOr, mnGOrShift ) : 0L );
     715     1106630 :     mnBShift = ( mnBMask ? ImplCalcMaskShift( mnBMask, mnBOr, mnBOrShift ) : 0L );
     716     1106630 : }
     717             : 
     718             : 
     719             : 
     720         174 : inline long ColorMask::ImplCalcMaskShift( sal_uLong nMask, sal_uLong& rOr, sal_uLong& rOrShift ) const
     721             : {
     722             :     long    nShift;
     723             :     long    nRet;
     724         174 :     sal_uLong   nLen = 0UL;
     725             : 
     726             :     // from which bit starts the mask?
     727         174 :     for( nShift = 31L; ( nShift >= 0L ) && !( nMask & ( 1 << (sal_uLong) nShift ) ); nShift-- )
     728             :     {}
     729             : 
     730         174 :     nRet = nShift;
     731             : 
     732             :     // XXX determine number of bits set => walk right until null
     733        1652 :     while( ( nShift >= 0L ) && ( nMask & ( 1 << (sal_uLong) nShift ) ) )
     734             :     {
     735        1304 :         nShift--;
     736        1304 :         nLen++;
     737             :     }
     738             : 
     739         174 :     rOrShift = 8L - nLen;
     740         174 :     rOr = (sal_uInt8) ( ( 0xffUL >> nLen ) << rOrShift );
     741             : 
     742         174 :     return( nRet -= 7 );
     743             : }
     744             : 
     745             : 
     746             : 
     747         729 : inline sal_uLong ColorMask::GetRedMask() const
     748             : {
     749         729 :     return mnRMask;
     750             : }
     751             : 
     752             : 
     753             : 
     754         729 : inline sal_uLong ColorMask::GetGreenMask() const
     755             : {
     756         729 :     return mnGMask;
     757             : }
     758             : 
     759             : 
     760             : 
     761         729 : inline sal_uLong ColorMask::GetBlueMask() const
     762             : {
     763         729 :     return mnBMask;
     764             : }
     765             : 
     766             : 
     767             : 
     768           0 : inline void ColorMask::GetColorFor8Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const
     769             : {
     770           0 :     const sal_uInt32 nVal = *pPixel;
     771           0 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     772           0 : }
     773             : 
     774             : 
     775             : 
     776           0 : inline void ColorMask::SetColorFor8Bit( const BitmapColor& rColor, HPBYTE pPixel ) const
     777             : {
     778           0 :     *pPixel = (sal_uInt8) COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
     779           0 : }
     780             : 
     781             : 
     782             : 
     783           0 : inline void ColorMask::GetColorFor16BitMSB( BitmapColor& rColor, ConstHPBYTE pPixel ) const
     784             : {
     785             : #ifdef OSL_BIGENDIAN
     786             :     const sal_uInt32 nVal = *(sal_uInt16*) pPixel;
     787             : #else
     788           0 :     const sal_uInt32 nVal = pPixel[ 1 ] | ( (sal_uInt32) pPixel[ 0 ] << 8UL );
     789             : #endif
     790             : 
     791           0 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     792           0 : }
     793             : 
     794             : 
     795             : 
     796           0 : inline void ColorMask::SetColorFor16BitMSB( const BitmapColor& rColor, HPBYTE pPixel ) const
     797             : {
     798           0 :     const sal_uInt16 nVal = (sal_uInt16)COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
     799             : 
     800             : #ifdef OSL_BIGENDIAN
     801             :     *(sal_uInt16*) pPixel = nVal;
     802             : #else
     803           0 :     pPixel[ 0 ] = (sal_uInt8)(nVal >> 8U);
     804           0 :     pPixel[ 1 ] = (sal_uInt8) nVal;
     805             : #endif
     806           0 : }
     807             : 
     808             : 
     809             : 
     810     1501200 : inline void ColorMask::GetColorFor16BitLSB( BitmapColor& rColor, ConstHPBYTE pPixel ) const
     811             : {
     812             : #ifdef OSL_BIGENDIAN
     813             :     const sal_uInt32 nVal = pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL );
     814             : #else
     815     1501200 :     const sal_uInt32 nVal = *(sal_uInt16*) pPixel;
     816             : #endif
     817             : 
     818     1501200 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     819     1501200 : }
     820             : 
     821             : 
     822             : 
     823       50208 : inline void ColorMask::SetColorFor16BitLSB( const BitmapColor& rColor, HPBYTE pPixel ) const
     824             : {
     825       50208 :     const sal_uInt16 nVal = (sal_uInt16)COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
     826             : 
     827             : #ifdef OSL_BIGENDIAN
     828             :     pPixel[ 0 ] = (sal_uInt8) nVal;
     829             :     pPixel[ 1 ] = (sal_uInt8)(nVal >> 8U);
     830             : #else
     831       50208 :     *(sal_uInt16*) pPixel = nVal;
     832             : #endif
     833       50208 : }
     834             : 
     835             : 
     836             : 
     837             : 
     838           0 : inline void ColorMask::GetColorFor24Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const
     839             : {
     840           0 :     const sal_uInt32 nVal = pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL ) | ( (sal_uInt32) pPixel[ 2 ] << 16UL );
     841           0 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     842           0 : }
     843             : 
     844             : 
     845             : 
     846           0 : inline void ColorMask::SetColorFor24Bit( const BitmapColor& rColor, HPBYTE pPixel ) const
     847             : {
     848           0 :     const sal_uInt32 nVal = COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
     849           0 :     pPixel[ 0 ] = (sal_uInt8) nVal; pPixel[ 1 ] = (sal_uInt8) ( nVal >> 8UL ); pPixel[ 2 ] = (sal_uInt8) ( nVal >> 16UL );
     850           0 : }
     851             : 
     852             : 
     853             : 
     854      408177 : inline void ColorMask::GetColorFor32Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const
     855             : {
     856             : #ifdef OSL_BIGENDIAN
     857             :     const sal_uInt32 nVal = (sal_uInt32) pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL ) |
     858             :                         ( (sal_uInt32) pPixel[ 2 ] << 16UL ) | ( (sal_uInt32) pPixel[ 3 ] << 24UL );
     859             : #else
     860      408177 :     const sal_uInt32 nVal = *(sal_uInt32*) pPixel;
     861             : #endif
     862             : 
     863      408177 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     864      408177 : }
     865             : 
     866             : 
     867             : 
     868           0 : inline void ColorMask::GetColorAndAlphaFor32Bit( BitmapColor& rColor, sal_uInt8& rAlpha, ConstHPBYTE pPixel ) const
     869             : {
     870             : #ifdef OSL_BIGENDIAN
     871             :     const sal_uInt32 nVal = (sal_uInt32) pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL ) |
     872             :                         ( (sal_uInt32) pPixel[ 2 ] << 16UL ) | ( (sal_uInt32) pPixel[ 3 ] << 24UL );
     873             : #else
     874           0 :     const sal_uInt32 nVal = *(sal_uInt32*) pPixel;
     875             : #endif
     876           0 :     rAlpha = (sal_uInt8)(nVal >> 24);
     877             : 
     878           0 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     879           0 : }
     880             : 
     881             : 
     882             : 
     883           0 : inline void ColorMask::SetColorFor32Bit( const BitmapColor& rColor, HPBYTE pPixel ) const
     884             : {
     885             : #ifdef OSL_BIGENDIAN
     886             :     const sal_uInt32 nVal = COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
     887             :     pPixel[ 0 ] = (sal_uInt8) nVal; pPixel[ 1 ] = (sal_uInt8) ( nVal >> 8UL );
     888             :     pPixel[ 2 ] = (sal_uInt8) ( nVal >> 16UL ); pPixel[ 3 ] = (sal_uInt8) ( nVal >> 24UL );
     889             : #else
     890           0 :     *(sal_uInt32*) pPixel = COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift );
     891             : #endif
     892           0 : }
     893             : 
     894             : #endif // INCLUDED_VCL_SALBTYPE_HXX
     895             : 
     896             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10