LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/vcl - bmpacc.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 62 71.0 %
Date: 2012-12-27 Functions: 20 27 74.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 _SV_BMPACC_HXX
      21             : #define _SV_BMPACC_HXX
      22             : 
      23             : #include <tools/solar.h>
      24             : #include <vcl/dllapi.h>
      25             : #include <vcl/salbtype.hxx>
      26             : #include <vcl/bitmap.hxx>
      27             : 
      28             : // --------------------
      29             : // - Access defines -
      30             : // --------------------
      31             : 
      32             : #define DECL_FORMAT_GETPIXEL( Format ) \
      33             : static BitmapColor GetPixelFor##Format( ConstScanline pScanline, long nX, const ColorMask& rMask );
      34             : 
      35             : #define DECL_FORMAT_SETPIXEL( Format ) \
      36             : static void SetPixelFor##Format( Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask );
      37             : 
      38             : #define DECL_FORMAT( Format )   \
      39             : DECL_FORMAT_GETPIXEL( Format )  \
      40             : DECL_FORMAT_SETPIXEL( Format )
      41             : 
      42             : #define IMPL_FORMAT_GETPIXEL( Format ) \
      43             : BitmapColor BitmapReadAccess::GetPixelFor##Format( ConstScanline pScanline, long nX, const ColorMask& rMask )
      44             : 
      45             : #define IMPL_FORMAT_GETPIXEL_NOMASK( Format ) \
      46             : BitmapColor BitmapReadAccess::GetPixelFor##Format( ConstScanline pScanline, long nX, const ColorMask& )
      47             : 
      48             : #define IMPL_FORMAT_SETPIXEL( Format ) \
      49             : void BitmapReadAccess::SetPixelFor##Format( Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask )
      50             : 
      51             : #define IMPL_FORMAT_SETPIXEL_NOMASK( Format ) \
      52             : void BitmapReadAccess::SetPixelFor##Format( Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& )
      53             : 
      54             : #define CASE_FORMAT( Format )           \
      55             : case( BMP_FORMAT##Format ):            \
      56             : {                                       \
      57             :     mFncGetPixel = GetPixelFor##Format;\
      58             :     mFncSetPixel = SetPixelFor##Format;\
      59             : }                                       \
      60             : break;
      61             : 
      62             : 
      63             : // --------------------
      64             : // - Access functions -
      65             : // --------------------
      66             : 
      67             : typedef BitmapColor (*FncGetPixel)( ConstScanline pScanline, long nX, const ColorMask& rMask );
      68             : typedef void (*FncSetPixel)( Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask );
      69             : 
      70             : // --------------------
      71             : // - BitmapReadAccess -
      72             : // --------------------
      73             : 
      74             : class VCL_DLLPUBLIC BitmapReadAccess
      75             : {
      76             :     friend class BitmapWriteAccess;
      77             : 
      78             : private:
      79             : 
      80             :                                 BitmapReadAccess() {}
      81             :                                 BitmapReadAccess( const BitmapReadAccess& ) {}
      82             :     BitmapReadAccess&           operator=( const BitmapReadAccess& ) { return *this; }
      83             : 
      84             : protected:
      85             :     Bitmap                      maBitmap;
      86             :     BitmapBuffer*               mpBuffer;
      87             :     Scanline*                   mpScanBuf;
      88             :     ColorMask                   maColorMask;
      89             :     FncGetPixel                 mFncGetPixel;
      90             :     FncSetPixel                 mFncSetPixel;
      91             :     sal_Bool                        mbModify;
      92             : 
      93             : 
      94             : SAL_DLLPRIVATE  void            ImplCreate( Bitmap& rBitmap );
      95             : SAL_DLLPRIVATE  void            ImplDestroy();
      96             : SAL_DLLPRIVATE  sal_Bool            ImplSetAccessPointers( sal_uLong nFormat );
      97             : 
      98             : public:
      99             : 
     100             : SAL_DLLPRIVATE  void            ImplZeroInitUnusedBits();
     101           0 : SAL_DLLPRIVATE  BitmapBuffer*   ImplGetBitmapBuffer() const { return mpBuffer; }
     102             : 
     103             :                                 DECL_FORMAT( _1BIT_MSB_PAL )
     104             :                                 DECL_FORMAT( _1BIT_LSB_PAL )
     105             :                                 DECL_FORMAT( _4BIT_MSN_PAL )
     106             :                                 DECL_FORMAT( _4BIT_LSN_PAL )
     107             :                                 DECL_FORMAT( _8BIT_PAL )
     108             :                                 DECL_FORMAT( _8BIT_TC_MASK )
     109             :                                 DECL_FORMAT( _16BIT_TC_MSB_MASK )
     110             :                                 DECL_FORMAT( _16BIT_TC_LSB_MASK )
     111             :                                 DECL_FORMAT( _24BIT_TC_BGR )
     112             :                                 DECL_FORMAT( _24BIT_TC_RGB )
     113             :                                 DECL_FORMAT( _24BIT_TC_MASK )
     114             :                                 DECL_FORMAT( _32BIT_TC_ABGR )
     115             :                                 DECL_FORMAT( _32BIT_TC_ARGB )
     116             :                                 DECL_FORMAT( _32BIT_TC_BGRA )
     117             :                                 DECL_FORMAT( _32BIT_TC_RGBA )
     118             :                                 DECL_FORMAT( _32BIT_TC_MASK )
     119             : protected:
     120             :                                 BitmapReadAccess( Bitmap& rBitmap, sal_Bool bModify );
     121             : 
     122             : public:
     123             :                                 BitmapReadAccess( Bitmap& rBitmap );
     124             :     virtual                     ~BitmapReadAccess();
     125             : 
     126             :     inline sal_Bool                 operator!() const;
     127             : 
     128             :     inline long                 Width() const;
     129             :     inline long                 Height() const;
     130             :     inline Point                TopLeft() const;
     131             :     inline Point                BottomRight() const;
     132             : 
     133             :     inline sal_Bool                 IsTopDown() const;
     134             :     inline sal_Bool                 IsBottomUp() const;
     135             : 
     136             :     inline sal_uLong                GetScanlineFormat() const;
     137             :     inline sal_uLong                GetScanlineSize() const;
     138             : 
     139             :     inline sal_uInt16               GetBitCount() const;
     140             :     inline BitmapColor          GetBestMatchingColor( const BitmapColor& rBitmapColor );
     141             : 
     142             :     inline Scanline             GetBuffer() const;
     143             :     inline Scanline             GetScanline( long nY ) const;
     144             : 
     145             :     inline sal_Bool                 HasPalette() const;
     146             :     inline const BitmapPalette& GetPalette() const;
     147             :     inline sal_uInt16               GetPaletteEntryCount() const;
     148             :     inline const BitmapColor&   GetPaletteColor( sal_uInt16 nColor ) const;
     149             :     inline const BitmapColor&   GetBestPaletteColor( const BitmapColor& rBitmapColor ) const;
     150             :     sal_uInt16                      GetBestPaletteIndex( const BitmapColor& rBitmapColor ) const;
     151             : 
     152             :     inline sal_Bool                 HasColorMask() const;
     153             :     inline ColorMask&           GetColorMask() const;
     154             : 
     155             :     inline BitmapColor          GetPixelFromData( const sal_uInt8* pData, long nX ) const;
     156             :     inline void                 SetPixelOnData( sal_uInt8* pData, long nX, const BitmapColor& rBitmapColor );
     157             :     inline BitmapColor          GetPixel( long nY, long nX ) const;
     158             :     inline BitmapColor          GetColor( long nY, long nX ) const;
     159             :     inline sal_uInt8                    GetLuminance( long nY, long nX ) const;
     160             : };
     161             : 
     162             : // ---------------------
     163             : // - BitmapWriteAccess -
     164             : // ---------------------
     165             : 
     166             : class VCL_DLLPUBLIC BitmapWriteAccess : public BitmapReadAccess
     167             : {
     168             : public:
     169             : 
     170             :                                 BitmapWriteAccess( Bitmap& rBitmap );
     171             :     virtual                     ~BitmapWriteAccess();
     172             : 
     173             :     void                        CopyScanline( long nY, const BitmapReadAccess& rReadAcc );
     174             :     void                        CopyScanline( long nY, ConstScanline aSrcScanline,
     175             :                                               sal_uLong nSrcScanlineFormat, sal_uLong nSrcScanlineSize );
     176             : 
     177             :     void                        CopyBuffer( const BitmapReadAccess& rReadAcc );
     178             : 
     179             :     inline void                 SetPalette( const BitmapPalette& rPalette );
     180             :     inline void                 SetPaletteEntryCount( sal_uInt16 nCount );
     181             :     inline void                 SetPaletteColor( sal_uInt16 nColor, const BitmapColor& rBitmapColor );
     182             : 
     183             :     inline void                 SetPixel( long nY, long nX, const BitmapColor& rBitmapColor );
     184             : 
     185             :     void                        SetLineColor( const Color& rColor );
     186             : 
     187             :     void                        SetFillColor( const Color& rColor );
     188             : 
     189             :     void                        Erase( const Color& rColor );
     190             : 
     191             :     void                        DrawLine( const Point& rStart, const Point& rEnd );
     192             : 
     193             :     void                        FillRect( const Rectangle& rRect );
     194             :     void                        DrawRect( const Rectangle& rRect );
     195             : 
     196             : private:
     197             : 
     198             :     BitmapColor*                mpLineColor;
     199             :     BitmapColor*                mpFillColor;
     200             : 
     201             :                                 BitmapWriteAccess() {}
     202             :                                 BitmapWriteAccess( const BitmapWriteAccess& ) : BitmapReadAccess() {}
     203             :     BitmapWriteAccess&          operator=( const BitmapWriteAccess& ) { return *this; }
     204             : };
     205             : 
     206             : // -----------
     207             : // - Inlines -
     208             : // -----------
     209             : 
     210         392 : inline sal_Bool BitmapReadAccess::operator!() const
     211             : {
     212         392 :     return( mpBuffer == NULL );
     213             : }
     214             : 
     215             : // ------------------------------------------------------------------
     216             : 
     217         250 : inline long BitmapReadAccess::Width() const
     218             : {
     219         250 :     return( mpBuffer ? mpBuffer->mnWidth : 0L );
     220             : }
     221             : 
     222             : // ------------------------------------------------------------------
     223             : 
     224         367 : inline long BitmapReadAccess::Height() const
     225             : {
     226         367 :     return( mpBuffer ? mpBuffer->mnHeight : 0L );
     227             : }
     228             : 
     229             : // ------------------------------------------------------------------
     230             : 
     231             : inline Point BitmapReadAccess::TopLeft() const
     232             : {
     233             :     return Point();
     234             : }
     235             : 
     236             : // ------------------------------------------------------------------
     237             : 
     238             : inline Point BitmapReadAccess::BottomRight() const
     239             : {
     240             :     return Point( Width() - 1L, Height() - 1L );
     241             : }
     242             : 
     243             : // ------------------------------------------------------------------
     244             : 
     245           6 : inline sal_Bool BitmapReadAccess::IsTopDown() const
     246             : {
     247             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     248           6 :     return( mpBuffer ? sal::static_int_cast<sal_Bool>( BMP_SCANLINE_ADJUSTMENT( mpBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN ) : sal_False );
     249             : }
     250             : 
     251             : // ------------------------------------------------------------------
     252             : 
     253           6 : inline sal_Bool BitmapReadAccess::IsBottomUp() const
     254             : {
     255           6 :     return !IsTopDown();
     256             : }
     257             : 
     258             : // ------------------------------------------------------------------
     259             : 
     260         583 : inline sal_uLong BitmapReadAccess::GetScanlineFormat() const
     261             : {
     262             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     263         583 :     return( mpBuffer ? BMP_SCANLINE_FORMAT( mpBuffer->mnFormat ) : 0UL );
     264             : }
     265             : 
     266             : // ------------------------------------------------------------------
     267             : 
     268         619 : inline sal_uLong BitmapReadAccess::GetScanlineSize() const
     269             : {
     270             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     271         619 :     return( mpBuffer ? mpBuffer->mnScanlineSize : 0UL );
     272             : }
     273             : 
     274             : // ------------------------------------------------------------------
     275             : 
     276        1413 : inline sal_uInt16  BitmapReadAccess::GetBitCount() const
     277             : {
     278             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     279        1413 :     return( mpBuffer ? mpBuffer->mnBitCount : 0 );
     280             : }
     281             : 
     282             : // ------------------------------------------------------------------
     283             : 
     284          38 : inline BitmapColor BitmapReadAccess::GetBestMatchingColor( const BitmapColor& rBitmapColor )
     285             : {
     286          38 :     if( HasPalette() )
     287          38 :         return BitmapColor( (sal_uInt8) GetBestPaletteIndex( rBitmapColor ) );
     288             :     else
     289           0 :         return rBitmapColor;
     290             : }
     291             : 
     292             : // ------------------------------------------------------------------
     293             : 
     294         179 : inline Scanline BitmapReadAccess::GetBuffer() const
     295             : {
     296             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     297         179 :     return( mpBuffer ? mpBuffer->mpBits : NULL );
     298             : }
     299             : 
     300             : // ------------------------------------------------------------------
     301             : 
     302         852 : inline Scanline BitmapReadAccess::GetScanline( long nY ) const
     303             : {
     304             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     305             :     DBG_ASSERT( nY < mpBuffer->mnHeight, "y-coordinate out of range!" );
     306         852 :     return( mpBuffer ? mpScanBuf[ nY ] : NULL );
     307             : }
     308             : 
     309             : // ------------------------------------------------------------------
     310             : 
     311        4146 : inline sal_Bool BitmapReadAccess::HasPalette() const
     312             : {
     313             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     314        4146 :     return( mpBuffer && !!mpBuffer->maPalette );
     315             : }
     316             : 
     317             : // ------------------------------------------------------------------
     318             : 
     319          35 : inline const BitmapPalette& BitmapReadAccess::GetPalette() const
     320             : {
     321             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     322          35 :     return mpBuffer->maPalette;
     323             : }
     324             : 
     325             : // ------------------------------------------------------------------
     326             : 
     327          42 : inline sal_uInt16 BitmapReadAccess::GetPaletteEntryCount() const
     328             : {
     329             :     DBG_ASSERT( HasPalette(), "Bitmap has no palette!" );
     330          42 :     return( HasPalette() ? mpBuffer->maPalette.GetEntryCount() : 0 );
     331             : }
     332             : 
     333             : // ------------------------------------------------------------------
     334             : 
     335      320785 : inline const BitmapColor& BitmapReadAccess::GetPaletteColor( sal_uInt16 nColor ) const
     336             : {
     337             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     338             :     DBG_ASSERT( HasPalette(), "Bitmap has no palette!" );
     339      320785 :     return mpBuffer->maPalette[ nColor ];
     340             : }
     341             : 
     342             : // ------------------------------------------------------------------
     343             : 
     344           0 : inline const BitmapColor& BitmapReadAccess::GetBestPaletteColor( const BitmapColor& rBitmapColor ) const
     345             : {
     346           0 :     return GetPaletteColor( GetBestPaletteIndex( rBitmapColor ) );
     347             : }
     348             : 
     349             : // ------------------------------------------------------------------
     350             : 
     351             : inline sal_Bool BitmapReadAccess::HasColorMask() const
     352             : {
     353             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     354             :     const sal_uLong nFormat = BMP_SCANLINE_FORMAT( mpBuffer->mnFormat );
     355             : 
     356             :     return( nFormat == BMP_FORMAT_8BIT_TC_MASK  ||
     357             :             nFormat == BMP_FORMAT_16BIT_TC_MSB_MASK ||
     358             :             nFormat == BMP_FORMAT_16BIT_TC_LSB_MASK ||
     359             :             nFormat == BMP_FORMAT_24BIT_TC_MASK ||
     360             :             nFormat == BMP_FORMAT_32BIT_TC_MASK );
     361             : }
     362             : 
     363             : // ------------------------------------------------------------------
     364             : 
     365         132 : inline ColorMask& BitmapReadAccess::GetColorMask() const
     366             : {
     367             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     368         132 :     return mpBuffer->maColorMask;
     369             : }
     370             : 
     371             : // ------------------------------------------------------------------
     372             : 
     373     2210979 : inline BitmapColor BitmapReadAccess::GetPixel( long nY, long nX ) const
     374             : {
     375             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     376             :     DBG_ASSERT( nX < mpBuffer->mnWidth, "x-coordinate out of range!" );
     377             :     DBG_ASSERT( nY < mpBuffer->mnHeight, "y-coordinate out of range!" );
     378     2210979 :     return mFncGetPixel( mpScanBuf[ nY ], nX, maColorMask );
     379             : }
     380             : 
     381             : // ------------------------------------------------------------------
     382             : 
     383           0 : inline BitmapColor BitmapReadAccess::GetPixelFromData( const sal_uInt8* pData, long nX ) const
     384             : {
     385             :     DBG_ASSERT( pData, "Access is not valid!" );
     386           0 :     return mFncGetPixel( pData, nX, maColorMask );
     387             : }
     388             : 
     389             : // ------------------------------------------------------------------
     390             : 
     391           0 : inline void BitmapReadAccess::SetPixelOnData( sal_uInt8* pData, long nX, const BitmapColor& rBitmapColor )
     392             : {
     393             :     DBG_ASSERT( pData, "Access is not valid!" );
     394           0 :     mFncSetPixel( pData, nX, rBitmapColor, maColorMask );
     395           0 : }
     396             : 
     397             : // ------------------------------------------------------------------
     398             : 
     399           0 : inline BitmapColor BitmapReadAccess::GetColor( long nY, long nX ) const
     400             : {
     401           0 :     if( !!mpBuffer->maPalette )
     402             :     {
     403             :         DBG_ASSERT( mpBuffer, "Access is not valid!" );
     404           0 :         return mpBuffer->maPalette[ GetPixel( nY, nX ).GetIndex() ];
     405             :     }
     406             :     else
     407           0 :         return GetPixel( nY, nX );
     408             : }
     409             : 
     410             : // ------------------------------------------------------------------
     411             : 
     412           0 : inline sal_uInt8 BitmapReadAccess::GetLuminance( long nY, long nX ) const
     413             : {
     414           0 :     return GetColor( nY, nX ).GetLuminance();
     415             : }
     416             : 
     417             : // ------------------------------------------------------------------
     418             : 
     419           0 : inline void BitmapWriteAccess::SetPalette( const BitmapPalette& rPalette )
     420             : {
     421             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     422           0 :     mpBuffer->maPalette = rPalette;
     423           0 : }
     424             : 
     425             : // ------------------------------------------------------------------
     426             : 
     427          11 : inline void BitmapWriteAccess::SetPaletteEntryCount( sal_uInt16 nCount )
     428             : {
     429             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     430          11 :     mpBuffer->maPalette.SetEntryCount( nCount );
     431          11 : }
     432             : 
     433             : // ------------------------------------------------------------------
     434             : 
     435       17482 : inline void BitmapWriteAccess::SetPaletteColor( sal_uInt16 nColor, const BitmapColor& rBitmapColor )
     436             : {
     437             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     438             :     DBG_ASSERT( HasPalette(), "Bitmap has no palette!" );
     439       17482 :     mpBuffer->maPalette[ nColor ] = rBitmapColor;
     440       17482 : }
     441             : 
     442             : // ------------------------------------------------------------------
     443             : 
     444     2589035 : inline void BitmapWriteAccess::SetPixel( long nY, long nX, const BitmapColor& rBitmapColor )
     445             : {
     446             :     DBG_ASSERT( mpBuffer, "Access is not valid!" );
     447             :     DBG_ASSERT( nX < mpBuffer->mnWidth, "x-coordinate out of range!" );
     448             :     DBG_ASSERT( nY < mpBuffer->mnHeight, "y-coordinate out of range!" );
     449     2589035 :     mFncSetPixel( mpScanBuf[ nY ], nX, rBitmapColor, maColorMask );
     450     2589035 : }
     451             : 
     452             : #endif // _SV_BMPACC_HXX
     453             : 
     454             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10