LCOV - code coverage report
Current view: top level - include/vcl - salbtype.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 191 226 84.5 %
Date: 2015-06-13 12:38:46 Functions: 51 58 87.9 %
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 <string.h>
      23             : #include <stdlib.h>
      24             : #include <tools/debug.hxx>
      25             : #include <vcl/salgtype.hxx>
      26             : #include <tools/color.hxx>
      27             : #include <tools/helpers.hxx>
      28             : #include <tools/solar.h>
      29             : #include <vcl/dllapi.h>
      30             : 
      31             : 
      32             : // - Memory -
      33             : 
      34             : typedef sal_uInt8*        HPBYTE;
      35             : typedef HPBYTE            Scanline;
      36             : typedef const sal_uInt8*  ConstHPBYTE;
      37             : typedef ConstHPBYTE       ConstScanline;
      38             : 
      39             : 
      40             : // - Bitmap formats -
      41             : 
      42             : #define BMP_FORMAT_BOTTOM_UP                        0x00000000UL
      43             : #define BMP_FORMAT_TOP_DOWN                         0x80000000UL
      44             : 
      45             : #define BMP_FORMAT_1BIT_MSB_PAL                     0x00000001UL
      46             : #define BMP_FORMAT_1BIT_LSB_PAL                     0x00000002UL
      47             : 
      48             : #define BMP_FORMAT_4BIT_MSN_PAL                     0x00000004UL
      49             : #define BMP_FORMAT_4BIT_LSN_PAL                     0x00000008UL
      50             : 
      51             : #define BMP_FORMAT_8BIT_PAL                         0x00000010UL
      52             : #define BMP_FORMAT_8BIT_TC_MASK                     0x00000020UL
      53             : 
      54             : #define BMP_FORMAT_24BIT_TC_BGR                     0x00000080UL
      55             : #define BMP_FORMAT_24BIT_TC_RGB                     0x00000100UL
      56             : #define BMP_FORMAT_24BIT_TC_MASK                    0x00000200UL
      57             : 
      58             : #define BMP_FORMAT_32BIT_TC_ABGR                    0x00000400UL
      59             : #define BMP_FORMAT_32BIT_TC_ARGB                    0x00000800UL
      60             : #define BMP_FORMAT_32BIT_TC_BGRA                    0x00001000UL
      61             : #define BMP_FORMAT_32BIT_TC_RGBA                    0x00002000UL
      62             : #define BMP_FORMAT_32BIT_TC_MASK                    0x00004000UL
      63             : 
      64             : #define BMP_FORMAT_16BIT_TC_MSB_MASK                0x00008000UL
      65             : #define BMP_FORMAT_16BIT_TC_LSB_MASK                0x00010000UL
      66             : 
      67             : #define BMP_SCANLINE_ADJUSTMENT( Mac_nBmpFormat )   ( (Mac_nBmpFormat) & 0x80000000UL )
      68             : #define BMP_SCANLINE_FORMAT( Mac_nBmpFormat )       ( (Mac_nBmpFormat) & 0x7FFFFFFFUL )
      69             : 
      70             : 
      71             : 
      72             : #define MASK_TO_COLOR( d_nVal, d_RM, d_GM, d_BM, d_RS, d_GS, d_BS, d_Col )                          \
      73             : sal_uLong _def_cR = (sal_uInt8) ( d_RS < 0L ? ( (d_nVal) & d_RM ) << -d_RS : ( (d_nVal) & d_RM ) >> d_RS ); \
      74             : sal_uLong _def_cG = (sal_uInt8) ( d_GS < 0L ? ( (d_nVal) & d_GM ) << -d_GS : ( (d_nVal) & d_GM ) >> d_GS ); \
      75             : sal_uLong _def_cB = (sal_uInt8) ( d_BS < 0L ? ( (d_nVal) & d_BM ) << -d_BS : ( (d_nVal) & d_BM ) >> d_BS ); \
      76             : d_Col = BitmapColor( (sal_uInt8) ( _def_cR | ( ( _def_cR & mnROr ) >> mnROrShift ) ),                   \
      77             :                      (sal_uInt8) ( _def_cG | ( ( _def_cG & mnGOr ) >> mnGOrShift ) ),                   \
      78             :                      (sal_uInt8) ( _def_cB | ( ( _def_cB & mnBOr ) >> mnBOrShift ) ) );
      79             : 
      80             : 
      81             : 
      82             : #define COLOR_TO_MASK( d_rCol, d_RM, d_GM, d_BM, d_RS, d_GS, d_BS, d_ALPHA ) \
      83             : ( ( ( ( d_RS < 0L ) ? ( (sal_uInt32) (d_rCol).GetRed() >> -d_RS ) :     \
      84             :     ( (sal_uInt32) (d_rCol).GetRed() << d_RS ) ) & d_RM ) |             \
      85             :   ( ( ( d_GS < 0L ) ? ( (sal_uInt32) (d_rCol).GetGreen() >> -d_GS ) :   \
      86             :     ( (sal_uInt32) (d_rCol).GetGreen() << d_GS ) ) & d_GM ) |           \
      87             :   ( ( ( d_BS < 0L ) ? ( (sal_uInt32) (d_rCol).GetBlue() >> -d_BS ) :    \
      88             :     ( (sal_uInt32) (d_rCol).GetBlue() << d_BS ) ) & d_BM ) | \
      89             :     d_ALPHA )
      90             : 
      91             : // - BitmapColor -
      92             : 
      93             : class Color;
      94             : 
      95             : class VCL_DLLPUBLIC BitmapColor
      96             : {
      97             : private:
      98             : 
      99             : // ATTENTION:
     100             : //   Because the members of this class are accessed via memcpy,
     101             : //   you MUST NOT CHANGE the order of the members or the size of this class!
     102             :     sal_uInt8               mcBlueOrIndex;
     103             :     sal_uInt8               mcGreen;
     104             :     sal_uInt8               mcRed;
     105             :     sal_uInt8               mbIndex; // should be bool, but see above warning
     106             : 
     107             : public:
     108             : 
     109             :     inline              BitmapColor();
     110             :     inline              BitmapColor( const BitmapColor& rBitmapColor );
     111             :     inline              BitmapColor( sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue );
     112             :     inline              BitmapColor( const Color& rColor );
     113             :     explicit inline     BitmapColor( sal_uInt8 cIndex );
     114             : 
     115  4675763480 :     inline              ~BitmapColor() {};
     116             : 
     117             :     inline bool         operator==( const BitmapColor& rBitmapColor ) const;
     118             :     inline bool         operator!=( const BitmapColor& rBitmapColor ) const;
     119             :     inline BitmapColor& operator=( const BitmapColor& rBitmapColor );
     120             : 
     121             :     inline bool         IsIndex() const;
     122             : 
     123             :     inline sal_uInt8    GetRed() const;
     124             :     inline void         SetRed( sal_uInt8 cRed );
     125             : 
     126             :     inline sal_uInt8    GetGreen() const;
     127             :     inline void         SetGreen( sal_uInt8 cGreen );
     128             : 
     129             :     inline sal_uInt8    GetBlue() const;
     130             :     inline void         SetBlue( sal_uInt8 cBlue );
     131             : 
     132             :     inline sal_uInt8    GetIndex() const;
     133             :     inline void         SetIndex( sal_uInt8 cIndex );
     134             : 
     135             :     operator            Color() const;
     136             : 
     137             :     inline sal_uInt8    GetBlueOrIndex() const;
     138             : 
     139             :     inline BitmapColor& Invert();
     140             : 
     141             :     inline sal_uInt8    GetLuminance() const;
     142             :     inline BitmapColor& IncreaseLuminance( sal_uInt8 cGreyInc );
     143             :     inline BitmapColor& DecreaseLuminance( sal_uInt8 cGreyDec );
     144             : 
     145             :     inline BitmapColor& Merge( const BitmapColor& rColor, sal_uInt8 cTransparency );
     146             :     inline BitmapColor& Merge( sal_uInt8 cR, sal_uInt8 cG, sal_uInt8 cB, sal_uInt8 cTransparency );
     147             : 
     148             :     inline sal_uLong    GetColorError( const BitmapColor& rBitmapColor ) const;
     149             : };
     150             : 
     151             : // - BitmapPalette -
     152             : class Palette;
     153             : 
     154             : class VCL_DLLPUBLIC BitmapPalette
     155             : {
     156             :     friend class SalBitmap;
     157             :     friend class BitmapAccess;
     158             : 
     159             : private:
     160             : 
     161             :     BitmapColor*                mpBitmapColor;
     162             :     sal_uInt16                  mnCount;
     163             : 
     164             : public:
     165             : 
     166             :     SAL_DLLPRIVATE inline BitmapColor* ImplGetColorBuffer() const;
     167             : 
     168             : 
     169             : public:
     170             : 
     171             :     inline                      BitmapPalette();
     172             :     inline                      BitmapPalette( const BitmapPalette& rBitmapPalette );
     173             :     inline                      BitmapPalette( sal_uInt16 nCount );
     174             :     inline                      ~BitmapPalette();
     175             : 
     176             :     inline BitmapPalette&       operator=( const BitmapPalette& rBitmapPalette );
     177             :     inline bool                 operator==( const BitmapPalette& rBitmapPalette ) const;
     178             :     inline bool                 operator!=( const BitmapPalette& rBitmapPalette ) const;
     179             :     inline bool                 operator!();
     180             : 
     181             :     inline sal_uInt16           GetEntryCount() const;
     182             :     inline void                 SetEntryCount( sal_uInt16 nCount );
     183             : 
     184             :     inline const BitmapColor&   operator[]( sal_uInt16 nIndex ) const;
     185             :     inline BitmapColor&         operator[]( sal_uInt16 nIndex );
     186             : 
     187             :     inline sal_uInt16           GetBestIndex( const BitmapColor& rCol ) const;
     188             :     bool                        IsGreyPalette() const;
     189             : };
     190             : 
     191             : // - ColorMask -
     192             : class VCL_DLLPUBLIC ColorMask
     193             : {
     194             :     sal_uLong               mnRMask;
     195             :     sal_uLong               mnGMask;
     196             :     sal_uLong               mnBMask;
     197             :     long                    mnRShift;
     198             :     long                    mnGShift;
     199             :     long                    mnBShift;
     200             :     sal_uLong               mnROrShift;
     201             :     sal_uLong               mnGOrShift;
     202             :     sal_uLong               mnBOrShift;
     203             :     sal_uLong               mnROr;
     204             :     sal_uLong               mnGOr;
     205             :     sal_uLong               mnBOr;
     206             :     sal_uLong               mnAlphaChannel;
     207             : 
     208             :     SAL_DLLPRIVATE inline long ImplCalcMaskShift( sal_uLong nMask, sal_uLong& rOr, sal_uLong& rOrShift ) const;
     209             : 
     210             : public:
     211             : 
     212             :     inline              ColorMask( sal_uLong nRedMask = 0UL,
     213             :                                    sal_uLong nGreenMask = 0UL,
     214             :                                    sal_uLong nBlueMask = 0UL,
     215             :                                    sal_uLong nAlphaChannel = 0UL );
     216     2673543 :     inline              ~ColorMask() {}
     217             : 
     218             :     inline sal_uLong    GetRedMask() const;
     219             :     inline sal_uLong    GetGreenMask() const;
     220             :     inline sal_uLong    GetBlueMask() const;
     221             : 
     222             :     inline void         GetColorFor8Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const;
     223             :     inline void         SetColorFor8Bit( const BitmapColor& rColor, HPBYTE pPixel ) const;
     224             : 
     225             :     inline void         GetColorFor16BitMSB( BitmapColor& rColor, ConstHPBYTE pPixel ) const;
     226             :     inline void         SetColorFor16BitMSB( const BitmapColor& rColor, HPBYTE pPixel ) const;
     227             :     inline void         GetColorFor16BitLSB( BitmapColor& rColor, ConstHPBYTE pPixel ) const;
     228             :     inline void         SetColorFor16BitLSB( const BitmapColor& rColor, HPBYTE pPixel ) const;
     229             : 
     230             :     inline void         GetColorFor24Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const;
     231             :     inline void         SetColorFor24Bit( const BitmapColor& rColor, HPBYTE pPixel ) const;
     232             : 
     233             :     inline void         GetColorFor32Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const;
     234             :     inline void         GetColorAndAlphaFor32Bit( BitmapColor& rColor, sal_uInt8& rAlpha, ConstHPBYTE pPixel ) const;
     235             :     inline void         SetColorFor32Bit( const BitmapColor& rColor, HPBYTE pPixel ) const;
     236             : };
     237             : 
     238             : // - BitmapBuffer -
     239           2 : struct VCL_DLLPUBLIC BitmapBuffer
     240             : {
     241             :     sal_uLong       mnFormat;
     242             :     long            mnWidth;
     243             :     long            mnHeight;
     244             :     long            mnScanlineSize;
     245             :     sal_uInt16      mnBitCount;
     246             :     ColorMask       maColorMask;
     247             :     BitmapPalette   maPalette;
     248             :     sal_uInt8*      mpBits;
     249             : 
     250      887295 :                     BitmapBuffer(){}
     251      887240 :                     ~BitmapBuffer() {}
     252             : };
     253             : 
     254             : // - Access modes -
     255             : typedef enum
     256             : {
     257             :     BITMAP_INFO_ACCESS,
     258             :     BITMAP_READ_ACCESS,
     259             :     BITMAP_WRITE_ACCESS
     260             : }
     261             : BitmapAccessMode;
     262             : 
     263             : // - StretchAndConvert -
     264             : VCL_DLLPUBLIC BitmapBuffer* StretchAndConvert(
     265             :     const BitmapBuffer& rSrcBuffer, const SalTwoRect& rTwoRect,
     266             :     sal_uLong nDstBitmapFormat, const BitmapPalette* pDstPal = NULL, const ColorMask* pDstMask = NULL );
     267             : 
     268  2417654282 : inline BitmapColor::BitmapColor() :
     269             :             mcBlueOrIndex   ( 0 ),
     270             :             mcGreen         ( 0 ),
     271             :             mcRed           ( 0 ),
     272  2417654282 :             mbIndex         ( sal_uInt8(false) )
     273             : {
     274  2417654282 : }
     275             : 
     276  1590828863 : inline BitmapColor::BitmapColor( sal_uInt8 cRed, sal_uInt8 cGreen, sal_uInt8 cBlue ) :
     277             :             mcBlueOrIndex   ( cBlue ),
     278             :             mcGreen         ( cGreen ),
     279             :             mcRed           ( cRed ),
     280  1590828863 :             mbIndex         ( sal_uInt8(false) )
     281             : {
     282  1590828863 : }
     283             : 
     284     9070311 : inline BitmapColor::BitmapColor( const BitmapColor& rBitmapColor ) :
     285             :             mcBlueOrIndex   ( rBitmapColor.mcBlueOrIndex ),
     286             :             mcGreen         ( rBitmapColor.mcGreen ),
     287             :             mcRed           ( rBitmapColor.mcRed ),
     288     9070311 :             mbIndex         ( rBitmapColor.mbIndex )
     289             : {
     290     9070311 : }
     291             : 
     292     2095973 : inline BitmapColor::BitmapColor( const Color& rColor ) :
     293     2095973 :             mcBlueOrIndex   ( rColor.GetBlue() ),
     294     2095973 :             mcGreen         ( rColor.GetGreen() ),
     295     2095973 :             mcRed           ( rColor.GetRed() ),
     296     6287919 :             mbIndex         ( sal_uInt8(false) )
     297             : {
     298     2095973 : }
     299             : 
     300   656114051 : inline BitmapColor::BitmapColor( sal_uInt8 cIndex ) :
     301             :             mcBlueOrIndex   ( cIndex ),
     302             :             mcGreen         ( 0 ),
     303             :             mcRed           ( 0 ),
     304   656114051 :             mbIndex         ( sal_uInt8(true) )
     305             : {
     306   656114051 : }
     307             : 
     308   232260340 : inline bool BitmapColor::operator==( const BitmapColor& rBitmapColor ) const
     309             : {
     310   336292879 :     return( ( mcBlueOrIndex == rBitmapColor.mcBlueOrIndex ) &&
     311             :             ( mbIndex ? bool(rBitmapColor.mbIndex) :
     312   333232115 :             ( mcGreen == rBitmapColor.mcGreen && mcRed == rBitmapColor.mcRed ) ) );
     313             : }
     314             : 
     315    49653766 : inline bool BitmapColor::operator!=( const BitmapColor& rBitmapColor ) const
     316             : {
     317    49653766 :     return !( *this == rBitmapColor );
     318             : }
     319             : 
     320  2653569695 : inline BitmapColor& BitmapColor::operator=( const BitmapColor& rBitmapColor )
     321             : {
     322  2653569695 :     mcBlueOrIndex = rBitmapColor.mcBlueOrIndex;
     323  2653569695 :     mcGreen = rBitmapColor.mcGreen;
     324  2653569695 :     mcRed = rBitmapColor.mcRed;
     325  2653569695 :     mbIndex = rBitmapColor.mbIndex;
     326             : 
     327  2653569695 :     return *this;
     328             : }
     329             : 
     330      422912 : inline bool BitmapColor::IsIndex() const
     331             : {
     332      422912 :     return mbIndex;
     333             : }
     334             : 
     335  1635258539 : inline sal_uInt8 BitmapColor::GetRed() const
     336             : {
     337             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     338  1635258539 :     return mcRed;
     339             : }
     340             : 
     341   218994239 : inline void BitmapColor::SetRed( sal_uInt8 cRed )
     342             : {
     343             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     344   218994239 :     mcRed = cRed;
     345   218994239 : }
     346             : 
     347  1634341291 : inline sal_uInt8 BitmapColor::GetGreen() const
     348             : {
     349             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     350  1634341291 :     return mcGreen;
     351             : }
     352             : 
     353   218994239 : inline void BitmapColor::SetGreen( sal_uInt8 cGreen )
     354             : {
     355             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     356   218994239 :     mcGreen = cGreen;
     357   218994239 : }
     358             : 
     359  1634764024 : inline sal_uInt8 BitmapColor::GetBlue() const
     360             : {
     361             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     362  1634764024 :     return mcBlueOrIndex;
     363             : }
     364             : 
     365   218994239 : inline void BitmapColor::SetBlue( sal_uInt8 cBlue )
     366             : {
     367             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     368   218994239 :     mcBlueOrIndex = cBlue;
     369   218994239 : }
     370             : 
     371   293188010 : inline sal_uInt8 BitmapColor::GetIndex() const
     372             : {
     373             :     DBG_ASSERT( mbIndex, "Pixel represents color values!" );
     374   293188010 :     return mcBlueOrIndex;
     375             : }
     376             : 
     377     4241876 : inline void BitmapColor::SetIndex( sal_uInt8 cIndex )
     378             : {
     379             :     DBG_ASSERT( mbIndex, "Pixel represents color values!" );
     380     4241876 :     mcBlueOrIndex = cIndex;
     381     4241876 : }
     382             : 
     383         171 : inline BitmapColor::operator Color() const
     384             : {
     385             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     386         171 :     return Color( mcRed, mcGreen, mcBlueOrIndex );
     387             : }
     388             : 
     389   363213217 : inline sal_uInt8 BitmapColor::GetBlueOrIndex() const
     390             : {
     391             :     // #i47518# Yield a value regardless of mbIndex
     392   363213217 :     return mcBlueOrIndex;
     393             : }
     394             : 
     395        5154 : inline BitmapColor& BitmapColor::Invert()
     396             : {
     397             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     398        5154 :     mcBlueOrIndex = ~mcBlueOrIndex, mcGreen = ~mcGreen, mcRed = ~mcRed;
     399             : 
     400        5154 :     return *this;
     401             : }
     402             : 
     403   234107258 : inline sal_uInt8 BitmapColor::GetLuminance() const
     404             : {
     405             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     406   234107258 :     return (static_cast<unsigned long>(mcBlueOrIndex) * 28UL + static_cast<unsigned long>(mcGreen) * 151UL + static_cast<unsigned long>(mcRed) * 77UL) >> 8;
     407             : }
     408             : 
     409             : inline BitmapColor& BitmapColor::IncreaseLuminance( sal_uInt8 cGreyInc )
     410             : {
     411             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     412             :     mcBlueOrIndex = (sal_uInt8) MinMax( (long) mcBlueOrIndex + cGreyInc, 0L, 255L );
     413             :     mcGreen = (sal_uInt8) MinMax( (long) mcGreen + cGreyInc, 0L, 255L );
     414             :     mcRed = (sal_uInt8) MinMax( (long) mcRed + cGreyInc, 0L, 255L );
     415             : 
     416             :     return *this;
     417             : }
     418             : 
     419             : inline BitmapColor& BitmapColor::DecreaseLuminance( sal_uInt8 cGreyDec )
     420             : {
     421             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     422             :     mcBlueOrIndex = (sal_uInt8) MinMax( (long) mcBlueOrIndex - cGreyDec, 0L, 255L );
     423             :     mcGreen = (sal_uInt8) MinMax( (long) mcGreen - cGreyDec, 0L, 255L );
     424             :     mcRed = (sal_uInt8) MinMax( (long) mcRed - cGreyDec, 0L, 255L );
     425             : 
     426             :     return *this;
     427             : }
     428             : 
     429   286879664 : inline BitmapColor& BitmapColor::Merge( const BitmapColor& rBitmapColor, sal_uInt8 cTransparency )
     430             : {
     431             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     432             :     DBG_ASSERT( !rBitmapColor.mbIndex, "Pixel represents index into colortable!" );
     433   286879664 :     mcBlueOrIndex = COLOR_CHANNEL_MERGE( mcBlueOrIndex, rBitmapColor.mcBlueOrIndex, cTransparency );
     434   286879664 :     mcGreen = COLOR_CHANNEL_MERGE( mcGreen, rBitmapColor.mcGreen, cTransparency );
     435   286879664 :     mcRed = COLOR_CHANNEL_MERGE( mcRed, rBitmapColor.mcRed, cTransparency );
     436             : 
     437   286879664 :     return *this;
     438             : }
     439             : 
     440             : inline BitmapColor& BitmapColor::Merge( sal_uInt8 cR, sal_uInt8 cG, sal_uInt8 cB, sal_uInt8 cTransparency )
     441             : {
     442             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     443             :     mcBlueOrIndex = COLOR_CHANNEL_MERGE( mcBlueOrIndex, cB, cTransparency );
     444             :     mcGreen = COLOR_CHANNEL_MERGE( mcGreen, cG, cTransparency );
     445             :     mcRed = COLOR_CHANNEL_MERGE( mcRed, cR, cTransparency );
     446             : 
     447             :     return *this;
     448             : }
     449             : 
     450        9290 : inline sal_uLong BitmapColor::GetColorError( const BitmapColor& rBitmapColor ) const
     451             : {
     452             :     DBG_ASSERT( !mbIndex, "Pixel represents index into colortable!" );
     453             :     DBG_ASSERT( !rBitmapColor.mbIndex, "Pixel represents index into colortable!" );
     454       18580 :     return( (sal_uLong) ( labs( mcBlueOrIndex - rBitmapColor.mcBlueOrIndex ) +
     455       18580 :                       labs( mcGreen - rBitmapColor.mcGreen ) +
     456       18580 :                       labs( mcRed - rBitmapColor.mcRed ) ) );
     457             : }
     458             : 
     459      962338 : inline BitmapPalette::BitmapPalette() :
     460             :             mpBitmapColor   ( NULL ),
     461      962338 :             mnCount         ( 0 )
     462             : {
     463      962338 : }
     464             : 
     465          22 : inline BitmapPalette::BitmapPalette( const BitmapPalette& rBitmapPalette ) :
     466          22 :             mnCount( rBitmapPalette.mnCount )
     467             : {
     468          22 :     if( mnCount )
     469             :     {
     470          22 :         const sal_uLong nSize = mnCount * sizeof( BitmapColor );
     471          22 :         mpBitmapColor = reinterpret_cast<BitmapColor*>(new sal_uInt8[ nSize ]);
     472          22 :         memcpy( mpBitmapColor, rBitmapPalette.mpBitmapColor, nSize );
     473             :     }
     474             :     else
     475           0 :         mpBitmapColor = NULL;
     476          22 : }
     477             : 
     478         393 : inline BitmapPalette::BitmapPalette( sal_uInt16 nCount ) :
     479         393 :             mnCount( nCount )
     480             : {
     481         393 :     if( mnCount )
     482             :     {
     483         393 :         const sal_uLong nSize = mnCount * sizeof( BitmapColor );
     484         393 :         mpBitmapColor = reinterpret_cast<BitmapColor*>(new sal_uInt8[ nSize ]);
     485         393 :         memset( mpBitmapColor, 0, nSize );
     486             :     }
     487             :     else
     488           0 :         mpBitmapColor = NULL;
     489         393 : }
     490             : 
     491      962692 : inline BitmapPalette::~BitmapPalette()
     492             : {
     493      962692 :     delete[] reinterpret_cast<sal_uInt8*>(mpBitmapColor);
     494      962692 : }
     495             : 
     496        1230 : inline BitmapPalette& BitmapPalette::operator=( const BitmapPalette& rBitmapPalette )
     497             : {
     498        1230 :     delete[] reinterpret_cast<sal_uInt8*>(mpBitmapColor);
     499        1230 :     mnCount = rBitmapPalette.mnCount;
     500             : 
     501        1230 :     if( mnCount )
     502             :     {
     503        1229 :         const sal_uLong nSize = mnCount * sizeof( BitmapColor );
     504        1229 :         mpBitmapColor = reinterpret_cast<BitmapColor*>(new sal_uInt8[ nSize ]);
     505        1229 :         memcpy( mpBitmapColor, rBitmapPalette.mpBitmapColor, nSize );
     506             :     }
     507             :     else
     508           1 :         mpBitmapColor = NULL;
     509             : 
     510        1230 :     return *this;
     511             : }
     512             : 
     513      176682 : inline bool BitmapPalette::operator==( const BitmapPalette& rBitmapPalette ) const
     514             : {
     515      176682 :     bool bRet = false;
     516             : 
     517      176682 :     if( rBitmapPalette.mnCount == mnCount )
     518             :     {
     519      176682 :         bRet = true;
     520             : 
     521    45399094 :         for( sal_uInt16 i = 0; i < mnCount; i++ )
     522             :         {
     523    45222437 :             if( mpBitmapColor[ i ] != rBitmapPalette.mpBitmapColor[ i ] )
     524             :             {
     525          25 :                 bRet = false;
     526          25 :                 break;
     527             :             }
     528             :         }
     529             :     }
     530             : 
     531      176682 :     return bRet;
     532             : }
     533             : 
     534      175770 : inline bool BitmapPalette::operator!=( const BitmapPalette& rBitmapPalette ) const
     535             : {
     536      175770 :     return !( *this == rBitmapPalette );
     537             : }
     538             : 
     539  1124265678 : inline bool BitmapPalette::operator!()
     540             : {
     541  1124265678 :     return( !mnCount || !mpBitmapColor );
     542             : }
     543             : 
     544     1108484 : inline sal_uInt16 BitmapPalette::GetEntryCount() const
     545             : {
     546     1108484 :     return mnCount;
     547             : }
     548             : 
     549      473821 : inline void BitmapPalette::SetEntryCount( sal_uInt16 nCount )
     550             : {
     551      473821 :     if( !nCount )
     552             :     {
     553           0 :         delete[] reinterpret_cast<sal_uInt8*>(mpBitmapColor);
     554           0 :         mpBitmapColor = NULL;
     555           0 :         mnCount = 0;
     556             :     }
     557      473821 :     else if( nCount != mnCount )
     558             :     {
     559      472292 :         const sal_uLong nNewSize = nCount * sizeof( BitmapColor );
     560      472292 :         const sal_uLong nMinSize = std::min( mnCount, nCount ) * sizeof( BitmapColor );
     561      472292 :         sal_uInt8*      pNewColor = new sal_uInt8[ nNewSize ];
     562             : 
     563      472292 :         if ( nMinSize && mpBitmapColor )
     564        1286 :             memcpy( pNewColor, mpBitmapColor, nMinSize );
     565      472292 :         delete[] reinterpret_cast<sal_uInt8*>(mpBitmapColor);
     566      472292 :         memset( pNewColor + nMinSize, 0, nNewSize - nMinSize );
     567      472292 :         mpBitmapColor = reinterpret_cast<BitmapColor*>(pNewColor);
     568      472292 :         mnCount = nCount;
     569             :     }
     570      473821 : }
     571             : 
     572    12572136 : inline const BitmapColor& BitmapPalette::operator[]( sal_uInt16 nIndex ) const
     573             : {
     574             :     DBG_ASSERT( nIndex < mnCount, "Palette index is out of range!" );
     575    12572136 :     return mpBitmapColor[ nIndex ];
     576             : }
     577             : 
     578   510293790 : inline BitmapColor& BitmapPalette::operator[]( sal_uInt16 nIndex )
     579             : {
     580             :     DBG_ASSERT( nIndex < mnCount, "Palette index is out of range!" );
     581   510293790 :     return mpBitmapColor[ nIndex ];
     582             : }
     583             : 
     584         944 : inline BitmapColor* BitmapPalette::ImplGetColorBuffer() const
     585             : {
     586             :     DBG_ASSERT( mpBitmapColor, "No color buffer available!" );
     587         944 :     return mpBitmapColor;
     588             : }
     589             : 
     590     1420022 : inline sal_uInt16 BitmapPalette::GetBestIndex( const BitmapColor& rCol ) const
     591             : {
     592     1420022 :     sal_uInt16 nRetIndex = 0;
     593             : 
     594     1420022 :     if( mpBitmapColor && mnCount )
     595             :     {
     596     1420022 :         bool bFound = false;
     597             : 
     598   176559184 :         for( long j = 0L; ( j < mnCount ) && !bFound; j++ )
     599   175139162 :             if( rCol == mpBitmapColor[ j ] )
     600     1419707 :                 nRetIndex = ( (sal_uInt16) j ), bFound = true;
     601             : 
     602     1420022 :         if( !bFound )
     603             :         {
     604         315 :             long nActErr, nLastErr = rCol.GetColorError( mpBitmapColor[ nRetIndex = mnCount - 1 ] );
     605             : 
     606        9290 :             for( long i = nRetIndex - 1; i >= 0L; i-- )
     607        8975 :                 if ( ( nActErr = rCol.GetColorError( mpBitmapColor[ i ] ) ) < nLastErr )
     608         454 :                     nLastErr = nActErr, nRetIndex = (sal_uInt16) i;
     609             :         }
     610             :     }
     611             : 
     612     1420022 :     return nRetIndex;
     613             : }
     614             : 
     615     2673598 : inline ColorMask::ColorMask( sal_uLong nRedMask,
     616             :                              sal_uLong nGreenMask,
     617             :                              sal_uLong nBlueMask,
     618             :                              sal_uLong nAlphaChannel ) :
     619             :             mnRMask( nRedMask ),
     620             :             mnGMask( nGreenMask ),
     621             :             mnBMask( nBlueMask ),
     622             :             mnROrShift( 0L ),
     623             :             mnGOrShift( 0L ),
     624             :             mnBOrShift( 0L ),
     625             :             mnROr( 0L ),
     626             :             mnGOr( 0L ),
     627             :             mnBOr( 0L ),
     628     2673598 :             mnAlphaChannel( nAlphaChannel )
     629             : {
     630     2673598 :     mnRShift = ( mnRMask ? ImplCalcMaskShift( mnRMask, mnROr, mnROrShift ) : 0L );
     631     2673598 :     mnGShift = ( mnGMask ? ImplCalcMaskShift( mnGMask, mnGOr, mnGOrShift ) : 0L );
     632     2673598 :     mnBShift = ( mnBMask ? ImplCalcMaskShift( mnBMask, mnBOr, mnBOrShift ) : 0L );
     633     2673598 : }
     634             : 
     635     1264032 : inline long ColorMask::ImplCalcMaskShift( sal_uLong nMask, sal_uLong& rOr, sal_uLong& rOrShift ) const
     636             : {
     637             :     long    nShift;
     638             :     long    nRet;
     639     1264032 :     sal_uLong   nLen = 0UL;
     640             : 
     641             :     // from which bit starts the mask?
     642     1264032 :     for( nShift = 31L; ( nShift >= 0L ) && !( nMask & ( (sal_uLong)1 << (sal_uLong) nShift ) ); nShift-- )
     643             :     {}
     644             : 
     645     1264032 :     nRet = nShift;
     646             : 
     647             :     // XXX determine number of bits set => walk right until null
     648    12640224 :     while( ( nShift >= 0L ) && ( nMask & ( (sal_uLong)1 << (sal_uLong) nShift ) ) )
     649             :     {
     650    10112160 :         nShift--;
     651    10112160 :         nLen++;
     652             :     }
     653             : 
     654             :     assert( nLen <= 8 ); // mask length must be 8 bits or less
     655     1264032 :     rOrShift = 8UL - nLen;
     656     1264032 :     rOr = (sal_uInt8) ( ( 0xffUL >> nLen ) << rOrShift );
     657             : 
     658     1264032 :     return( nRet -= 7 );
     659             : }
     660             : 
     661        2449 : inline sal_uLong ColorMask::GetRedMask() const
     662             : {
     663        2449 :     return mnRMask;
     664             : }
     665             : 
     666        2449 : inline sal_uLong ColorMask::GetGreenMask() const
     667             : {
     668        2449 :     return mnGMask;
     669             : }
     670             : 
     671        2449 : inline sal_uLong ColorMask::GetBlueMask() const
     672             : {
     673        2449 :     return mnBMask;
     674             : }
     675             : 
     676           0 : inline void ColorMask::GetColorFor8Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const
     677             : {
     678           0 :     const sal_uInt32 nVal = *pPixel;
     679           0 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     680           0 : }
     681             : 
     682           0 : inline void ColorMask::SetColorFor8Bit( const BitmapColor& rColor, HPBYTE pPixel ) const
     683             : {
     684           0 :     *pPixel = (sal_uInt8) COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, mnAlphaChannel );
     685           0 : }
     686             : 
     687           0 : inline void ColorMask::GetColorFor16BitMSB( BitmapColor& rColor, ConstHPBYTE pPixel ) const
     688             : {
     689           0 :     const sal_uInt32 nVal = pPixel[ 1 ] | ( (sal_uInt32) pPixel[ 0 ] << 8UL );
     690             : 
     691           0 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     692           0 : }
     693             : 
     694           0 : inline void ColorMask::SetColorFor16BitMSB( const BitmapColor& rColor, HPBYTE pPixel ) const
     695             : {
     696           0 :     const sal_uInt16 nVal = (sal_uInt16)COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, mnAlphaChannel );
     697             : 
     698           0 :     pPixel[ 0 ] = (sal_uInt8)(nVal >> 8U);
     699           0 :     pPixel[ 1 ] = (sal_uInt8) nVal;
     700           0 : }
     701             : 
     702     1502224 : inline void ColorMask::GetColorFor16BitLSB( BitmapColor& rColor, ConstHPBYTE pPixel ) const
     703             : {
     704     1502224 :     const sal_uInt32 nVal = pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL );
     705             : 
     706     1502224 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     707     1502224 : }
     708             : 
     709       50208 : inline void ColorMask::SetColorFor16BitLSB( const BitmapColor& rColor, HPBYTE pPixel ) const
     710             : {
     711       50208 :     const sal_uInt16 nVal = (sal_uInt16)COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, mnAlphaChannel );
     712             : 
     713       50208 :     pPixel[ 0 ] = (sal_uInt8) nVal;
     714       50208 :     pPixel[ 1 ] = (sal_uInt8)(nVal >> 8U);
     715       50208 : }
     716             : 
     717           0 : inline void ColorMask::GetColorFor24Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const
     718             : {
     719           0 :     const sal_uInt32 nVal = pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL ) | ( (sal_uInt32) pPixel[ 2 ] << 16UL );
     720           0 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     721           0 : }
     722             : 
     723           0 : inline void ColorMask::SetColorFor24Bit( const BitmapColor& rColor, HPBYTE pPixel ) const
     724             : {
     725           0 :     const sal_uInt32 nVal = COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, mnAlphaChannel );
     726           0 :     pPixel[ 0 ] = (sal_uInt8) nVal; pPixel[ 1 ] = (sal_uInt8) ( nVal >> 8UL ); pPixel[ 2 ] = (sal_uInt8) ( nVal >> 16UL );
     727           0 : }
     728             : 
     729  1404984508 : inline void ColorMask::GetColorFor32Bit( BitmapColor& rColor, ConstHPBYTE pPixel ) const
     730             : {
     731  2809969016 :     const sal_uInt32 nVal = (sal_uInt32) pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL ) |
     732  2809969016 :                         ( (sal_uInt32) pPixel[ 2 ] << 16UL ) | ( (sal_uInt32) pPixel[ 3 ] << 24UL );
     733             : 
     734  1404984508 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     735  1404984508 : }
     736             : 
     737           0 : inline void ColorMask::GetColorAndAlphaFor32Bit( BitmapColor& rColor, sal_uInt8& rAlpha, ConstHPBYTE pPixel ) const
     738             : {
     739           0 :     const sal_uInt32 nVal = (sal_uInt32) pPixel[ 0 ] | ( (sal_uInt32) pPixel[ 1 ] << 8UL ) |
     740           0 :                         ( (sal_uInt32) pPixel[ 2 ] << 16UL ) | ( (sal_uInt32) pPixel[ 3 ] << 24UL );
     741           0 :     rAlpha = (sal_uInt8)(nVal >> 24);
     742             : 
     743           0 :     MASK_TO_COLOR( nVal, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, rColor );
     744           0 : }
     745             : 
     746   585503196 : inline void ColorMask::SetColorFor32Bit( const BitmapColor& rColor, HPBYTE pPixel ) const
     747             : {
     748   585503196 :     const sal_uInt32 nVal = COLOR_TO_MASK( rColor, mnRMask, mnGMask, mnBMask, mnRShift, mnGShift, mnBShift, mnAlphaChannel );
     749   585503196 :     pPixel[ 0 ] = (sal_uInt8) nVal; pPixel[ 1 ] = (sal_uInt8) ( nVal >> 8UL );
     750   585503196 :     pPixel[ 2 ] = (sal_uInt8) ( nVal >> 16UL ); pPixel[ 3 ] = (sal_uInt8) ( nVal >> 24UL );
     751   585503196 : }
     752             : 
     753             : #endif // INCLUDED_VCL_SALBTYPE_HXX
     754             : 
     755             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11