LCOV - code coverage report
Current view: top level - include/vcl - bitmap.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 82 0.0 %
Date: 2014-04-14 Functions: 0 41 0.0 %
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_BITMAP_HXX
      21             : #define INCLUDED_VCL_BITMAP_HXX
      22             : 
      23             : #include <boost/math/special_functions/sinc.hpp>
      24             : #include <tools/color.hxx>
      25             : #include <tools/link.hxx>
      26             : #include <tools/solar.h>
      27             : #include <vcl/dllapi.h>
      28             : #include <vcl/mapmod.hxx>
      29             : #include <vcl/region.hxx>
      30             : #include <vcl/scopedbitmapaccess.hxx>
      31             : 
      32             : #define BMP_MIRROR_NONE             0x00000000UL
      33             : #define BMP_MIRROR_HORZ             0x00000001UL
      34             : #define BMP_MIRROR_VERT             0x00000002UL
      35             : 
      36             : 
      37             : #define BMP_SCALE_NONE              0x00000000UL
      38             : #define BMP_SCALE_FAST              0x00000001UL
      39             : #define BMP_SCALE_INTERPOLATE       0x00000002UL
      40             : #define BMP_SCALE_SUPER             0x00000003UL
      41             : #define BMP_SCALE_LANCZOS           0x00000004UL
      42             : #define BMP_SCALE_BICUBIC           0x00000005UL
      43             : #define BMP_SCALE_BILINEAR          0x00000006UL
      44             : #define BMP_SCALE_BOX               0x00000007UL
      45             : 
      46             : // Aliases, try to use these two (or BMP_SCALE_FAST/BMP_SCALE_NONE),
      47             : // use a specific algorithm only if you really need to.
      48             : #define BMP_SCALE_BESTQUALITY       BMP_SCALE_LANCZOS
      49             : #define BMP_SCALE_DEFAULT           BMP_SCALE_SUPER
      50             : 
      51             : 
      52             : #define BMP_DITHER_NONE             0x00000000UL
      53             : #define BMP_DITHER_MATRIX           0x00000001UL
      54             : #define BMP_DITHER_FLOYD            0x00000002UL
      55             : #define BMP_DITHER_FLOYD_16         0x00000004UL
      56             : 
      57             : #define BMP_VECTORIZE_NONE          BMP_VECTORIZE_OUTER
      58             : #define BMP_VECTORIZE_INNER         0x00000001UL
      59             : #define BMP_VECTORIZE_OUTER         0x00000002UL
      60             : #define BMP_VECTORIZE_BOUND_ONLY    0x00000004UL
      61             : #define BMP_VECTORIZE_REDUCE_EDGES  0x00000008UL
      62             : 
      63             : #define BMP_COL_TRANS                   Color( 252, 3, 251 )
      64             : 
      65             : enum BmpConversion
      66             : {
      67             :     BMP_CONVERSION_NONE = 0,
      68             :     BMP_CONVERSION_1BIT_THRESHOLD = 1,
      69             :     BMP_CONVERSION_1BIT_MATRIX = 2,
      70             :     BMP_CONVERSION_4BIT_GREYS = 3,
      71             :     BMP_CONVERSION_4BIT_COLORS = 4,
      72             :     BMP_CONVERSION_8BIT_GREYS = 5,
      73             :     BMP_CONVERSION_8BIT_COLORS = 6,
      74             :     BMP_CONVERSION_24BIT = 7,
      75             :     BMP_CONVERSION_4BIT_TRANS = 8,
      76             :     BMP_CONVERSION_8BIT_TRANS = 9,
      77             :     BMP_CONVERSION_GHOSTED = 10
      78             : };
      79             : 
      80             : enum BmpCombine
      81             : {
      82             :     BMP_COMBINE_COPY = 0,
      83             :     BMP_COMBINE_INVERT = 1,
      84             :     BMP_COMBINE_AND = 2,
      85             :     BMP_COMBINE_NAND = 3,
      86             :     BMP_COMBINE_OR = 4,
      87             :     BMP_COMBINE_NOR = 5,
      88             :     BMP_COMBINE_XOR = 6,
      89             :     BMP_COMBINE_NXOR = 7
      90             : };
      91             : 
      92             : enum BmpReduce
      93             : {
      94             :     BMP_REDUCE_SIMPLE = 0,
      95             :     BMP_REDUCE_POPULAR = 1,
      96             :     BMP_REDUCE_MEDIAN = 2
      97             : };
      98             : 
      99             : enum BmpEmboss
     100             : {
     101             :     BMP_EMBOSS_TOPLEFT = 0,
     102             :     BMP_EMBOSS_TOP = 1,
     103             :     BMP_EMBOSS_TOPRIGHT = 2,
     104             :     BMP_EMBOSS_LEFT = 3,
     105             :     BMP_EMBOSS_MIDDLE = 4,
     106             :     BMP_EMBOSS_RIGHT = 5,
     107             :     BMP_EMBOSS_BOTTOMLEFT = 6,
     108             :     BMP_EMBOSS_BOTTOM = 7,
     109             :     BMP_EMBOSS_BOTTOMRIGHT = 8
     110             : };
     111             : 
     112             : enum BmpFilter
     113             : {
     114             :     BMP_FILTER_SMOOTH = 0,
     115             :     BMP_FILTER_SHARPEN = 1,
     116             :     BMP_FILTER_REMOVENOISE = 2,
     117             :     BMP_FILTER_SOBEL_GREY = 3,
     118             :     BMP_FILTER_EMBOSS_GREY = 4,
     119             :     BMP_FILTER_SOLARIZE = 5,
     120             :     BMP_FILTER_SEPIA = 6,
     121             :     BMP_FILTER_MOSAIC = 7,
     122             :     BMP_FILTER_POPART = 8,
     123             :     BMP_FILTER_DUOTONE = 9,
     124             : 
     125             :     BMP_FILTER_UNKNOWN = 65535
     126             : };
     127             : 
     128             : class VCL_DLLPUBLIC BmpFilterParam
     129             : {
     130             :     friend class Bitmap;
     131             :     friend class BitmapEx;
     132             :     friend class Animation;
     133             : 
     134             : private:
     135             :     BmpFilter       meFilter;
     136             :     sal_uLong       mnProgressStart;
     137             :     sal_uLong       mnProgressEnd;
     138             : 
     139             : public:
     140             :     struct MosaicTileSize
     141             :     {
     142             :         sal_uLong mnTileWidth;
     143             :         sal_uLong mnTileHeight;
     144             :     };
     145             : 
     146             :     struct EmbossAngles
     147             :     {
     148             :         sal_uInt16 mnAzimuthAngle100;
     149             :         sal_uInt16 mnElevationAngle100;
     150             :     };
     151             : 
     152             : private:
     153             :     union
     154             :     {
     155             :         sal_uInt16  mnSepiaPercent;
     156             :         sal_uInt8   mcSolarGreyThreshold;
     157             :         double      mnRadius;
     158             : 
     159             :         MosaicTileSize maMosaicTileSize;
     160             :         EmbossAngles maEmbossAngles;
     161             :     };
     162             : 
     163             : public:
     164             : 
     165           0 :     BmpFilterParam( sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
     166           0 :         meFilter( BMP_FILTER_UNKNOWN ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ) {}
     167             : 
     168           0 :     BmpFilterParam( sal_uInt8 cSolarGreyThreshold, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
     169             :         meFilter( BMP_FILTER_SOLARIZE ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
     170           0 :         mcSolarGreyThreshold( cSolarGreyThreshold ) {}
     171             : 
     172           0 :     BmpFilterParam( double nRadius, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
     173             :         meFilter( BMP_FILTER_SMOOTH ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
     174           0 :         mnRadius( nRadius ) {}
     175             : 
     176           0 :     BmpFilterParam( sal_uInt16 nSepiaPercent, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
     177             :         meFilter( BMP_FILTER_SEPIA ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
     178           0 :         mnSepiaPercent( nSepiaPercent ) {}
     179             : 
     180           0 :     BmpFilterParam( const Size& rMosaicTileSize, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
     181           0 :         meFilter( BMP_FILTER_MOSAIC ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
     182             :         {
     183           0 :             maMosaicTileSize.mnTileWidth = rMosaicTileSize.Width();
     184           0 :             maMosaicTileSize.mnTileHeight= rMosaicTileSize.Height();
     185           0 :         }
     186           0 :     BmpFilterParam( sal_uInt16 nEmbossAzimuthAngle100, sal_uInt16 nEmbossElevationAngle100,
     187             :                     sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
     188           0 :         meFilter( BMP_FILTER_EMBOSS_GREY ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
     189             :         {
     190           0 :             maEmbossAngles.mnAzimuthAngle100 = nEmbossAzimuthAngle100;
     191           0 :             maEmbossAngles.mnElevationAngle100 = nEmbossElevationAngle100;
     192           0 :         }
     193             : };
     194             : 
     195             : 
     196             : // Resample kernels
     197             : 
     198             : 
     199             : class Kernel
     200             : {
     201             : 
     202             : public:
     203           0 :     Kernel () {}
     204           0 :     virtual ~Kernel() {}
     205             : 
     206             :     virtual double GetWidth() const = 0;
     207             :     virtual double Calculate( double x ) const = 0;
     208             : };
     209             : 
     210           0 : class Lanczos3Kernel : public Kernel
     211             : {
     212             :     typedef boost::math::policies::policy<
     213             :         boost::math::policies::promote_double<false> > SincPolicy;
     214             : public:
     215           0 :     Lanczos3Kernel() : Kernel () {}
     216           0 :     virtual double GetWidth() const SAL_OVERRIDE { return 3.0; }
     217           0 :     virtual double Calculate (double x) const SAL_OVERRIDE
     218             :     {
     219           0 :         return (-3.0 <= x && x < 3.0) ? SincFilter(x) * SincFilter( x / 3.0 ) : 0.0;
     220             :     }
     221             : 
     222           0 :     inline double SincFilter(double x) const
     223             :     {
     224           0 :         if (x == 0.0)
     225             :         {
     226           0 :             return 1.0;
     227             :         }
     228           0 :         x = x * M_PI;
     229           0 :         return boost::math::sinc_pi(x, SincPolicy());
     230             :     }
     231             : };
     232             : 
     233           0 : class BicubicKernel : public Kernel {
     234             : public:
     235           0 :     BicubicKernel() : Kernel () {}
     236             : private:
     237           0 :     virtual double GetWidth() const SAL_OVERRIDE { return 2.0; }
     238           0 :     virtual double Calculate (double x) const SAL_OVERRIDE
     239             :     {
     240           0 :         if (x < 0.0)
     241             :         {
     242           0 :             x = -x;
     243             :         }
     244             : 
     245           0 :         if (x <= 1.0)
     246             :         {
     247           0 :             return (1.5 * x - 2.5) * x * x + 1.0;
     248             :         }
     249           0 :         else if (x < 2.0)
     250             :         {
     251           0 :             return ((-0.5 * x + 2.5) * x - 4) * x + 2;
     252             :         }
     253           0 :         return 0.0;
     254             :     }
     255             : };
     256             : 
     257           0 : class BilinearKernel : public Kernel {
     258             : public:
     259           0 :     BilinearKernel() : Kernel () {}
     260             : private:
     261           0 :     virtual double GetWidth() const SAL_OVERRIDE { return 1.0; }
     262           0 :     virtual double Calculate (double x) const SAL_OVERRIDE
     263             :     {
     264           0 :         if (x < 0.0)
     265             :         {
     266           0 :             x = -x;
     267             :         }
     268           0 :         if (x < 1.0)
     269             :         {
     270           0 :             return 1.0-x;
     271             :         }
     272           0 :         return 0.0;
     273             :     }
     274             : };
     275             : 
     276           0 : class BoxKernel : public Kernel {
     277             : public:
     278           0 :     BoxKernel() : Kernel () {}
     279             : private:
     280           0 :     virtual double GetWidth() const SAL_OVERRIDE { return 0.5; }
     281           0 :     virtual double Calculate (double x) const SAL_OVERRIDE
     282             :     {
     283           0 :         if (-0.5 <= x && x < 0.5)
     284           0 :             return 1.0;
     285           0 :         return 0.0;
     286             :     }
     287             : };
     288             : 
     289             : class   BitmapReadAccess;
     290             : class   BitmapWriteAccess;
     291             : class   BitmapPalette;
     292             : class   ImpBitmap;
     293             : class   Color;
     294             : class   ResId;
     295             : class   GDIMetaFile;
     296             : class   AlphaMask;
     297             : class   OutputDevice;
     298             : class   SalBitmap;
     299             : 
     300             : struct BitmapSystemData
     301             : {
     302             :     #if defined( WNT )
     303             :     void* pDIB; // device independent byte buffer
     304             :     void* pDDB; // if not NULL then this is actually an HBITMAP
     305             :     #elif defined( MACOSX ) || defined( IOS )
     306             :     void* rImageContext;     //Image context (CGContextRef)
     307             :     #else
     308             :     void* aPixmap;
     309             :     #endif
     310             :     int mnWidth;
     311             :     int mnHeight;
     312             : };
     313             : 
     314             : class VCL_DLLPUBLIC Bitmap
     315             : {
     316             : private:
     317             : 
     318             :     ImpBitmap*          mpImpBmp;
     319             :     MapMode             maPrefMapMode;
     320             :     Size                maPrefSize;
     321             : 
     322             : public:
     323             : 
     324             :     SAL_DLLPRIVATE void                 ImplReleaseRef();
     325             :     SAL_DLLPRIVATE void                 ImplMakeUnique();
     326             :                    ImpBitmap*           ImplGetImpBitmap() const;
     327             :     SAL_DLLPRIVATE void                 ImplSetImpBitmap( ImpBitmap* pImpBmp );
     328             :     SAL_DLLPRIVATE void                 ImplAssignWithSize( const Bitmap& rBitmap );
     329             : 
     330             :     SAL_DLLPRIVATE void                 ImplAdaptBitCount(Bitmap& rNew) const;
     331             :     SAL_DLLPRIVATE bool             ImplScaleFast( const double& rScaleX, const double& rScaleY );
     332             :     SAL_DLLPRIVATE bool             ImplScaleInterpolate( const double& rScaleX, const double& rScaleY );
     333             :     SAL_DLLPRIVATE bool             ImplScaleSuper( const double& rScaleX, const double& rScaleY );
     334             :     SAL_DLLPRIVATE bool             ImplScaleConvolution( const double& rScaleX, const double& rScaleY, const Kernel& aKernel);
     335             : 
     336             :     SAL_DLLPRIVATE bool                 ImplConvolutionPass( Bitmap& aNewBitmap, const int nNewSize, BitmapReadAccess* pReadAcc,
     337             :                                                 int aNumberOfContributions, double* pWeights, int* pPixels, int* pCount );
     338             : 
     339             :     SAL_DLLPRIVATE bool             ImplMakeMono( sal_uInt8 cThreshold );
     340             :     SAL_DLLPRIVATE bool             ImplMakeMonoDither();
     341             :     SAL_DLLPRIVATE bool             ImplMakeGreyscales( sal_uInt16 nGreyscales );
     342             :     SAL_DLLPRIVATE bool             ImplConvertUp( sal_uInt16 nBitCount, Color* pExtColor = NULL );
     343             :     SAL_DLLPRIVATE bool             ImplConvertDown( sal_uInt16 nBitCount, Color* pExtColor = NULL );
     344             :     SAL_DLLPRIVATE bool             ImplConvertGhosted();
     345             :     SAL_DLLPRIVATE bool             ImplDitherMatrix();
     346             :     SAL_DLLPRIVATE bool             ImplDitherFloyd();
     347             :     SAL_DLLPRIVATE bool             ImplDitherFloyd16();
     348             :     SAL_DLLPRIVATE bool             ImplReduceSimple( sal_uInt16 nColorCount );
     349             :     SAL_DLLPRIVATE bool             ImplReducePopular( sal_uInt16 nColorCount );
     350             :     SAL_DLLPRIVATE bool             ImplReduceMedian( sal_uInt16 nColorCount );
     351             :     SAL_DLLPRIVATE void                 ImplMedianCut( sal_uLong* pColBuf, BitmapPalette& rPal,
     352             :                                                 long nR1, long nR2, long nG1, long nG2, long nB1, long nB2,
     353             :                                                 long nColors, long nPixels, long& rIndex );
     354             :     SAL_DLLPRIVATE bool             ImplConvolute3( const long* pMatrix, long nDivisor,
     355             :                                                             const BmpFilterParam* pFilterParam, const Link* pProgress );
     356             :     SAL_DLLPRIVATE bool             ImplMedianFilter( const BmpFilterParam* pFilterParam, const Link* pProgress );
     357             :     SAL_DLLPRIVATE bool             ImplSobelGrey( const BmpFilterParam* pFilterParam, const Link* pProgress );
     358             :     SAL_DLLPRIVATE bool             ImplEmbossGrey( const BmpFilterParam* pFilterParam, const Link* pProgress );
     359             :     SAL_DLLPRIVATE bool             ImplSolarize( const BmpFilterParam* pFilterParam, const Link* pProgress );
     360             :     SAL_DLLPRIVATE bool             ImplSepia( const BmpFilterParam* pFilterParam, const Link* pProgress );
     361             :     SAL_DLLPRIVATE bool             ImplMosaic( const BmpFilterParam* pFilterParam, const Link* pProgress );
     362             :     SAL_DLLPRIVATE bool             ImplPopArt( const BmpFilterParam* pFilterParam, const Link* pProgress );
     363             : 
     364             :     SAL_DLLPRIVATE bool                 ImplSeparableBlurFilter( const double aRadius = 0.7 );
     365             :     SAL_DLLPRIVATE bool                 ImplSeparableUnsharpenFilter( const double aRadius = 0.7 );
     366             :     SAL_DLLPRIVATE bool                 ImplDuotoneFilter( const sal_uLong nColorOne,  sal_uLong nColorTwo );
     367             :     SAL_DLLPRIVATE void                 ImplBlurContributions( const int aSize, const int aNumberOfContributions,
     368             :                                                 double* pBlurVector, double*& pWeights, int*& pPixels, int*& pCount );
     369             : public:
     370             : 
     371             :     Bitmap();
     372             :     Bitmap( const Bitmap& rBitmap );
     373             :     Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal = NULL );
     374             :     Bitmap( const ResId& rResId );
     375             :     Bitmap( SalBitmap* pSalBitmap );
     376             :     virtual ~Bitmap();
     377             : 
     378             :     Bitmap&                 operator=( const Bitmap& rBitmap );
     379             :     inline bool             operator!() const;
     380             :     inline bool             operator==( const Bitmap& rBitmap ) const;
     381             :     inline bool             operator!=( const Bitmap& rBitmap ) const;
     382             : 
     383             :     inline bool             IsSameInstance( const Bitmap& rBmp ) const;
     384             :     bool                    IsEqual( const Bitmap& rBmp ) const;
     385             : 
     386             :     inline bool             IsEmpty() const;
     387             :     void                    SetEmpty();
     388             : 
     389             :     inline const MapMode&   GetPrefMapMode() const;
     390             :     inline void             SetPrefMapMode( const MapMode& rMapMode );
     391             : 
     392             :     inline const Size&      GetPrefSize() const;
     393             :     inline void             SetPrefSize( const Size& rSize );
     394             : 
     395             :     Size                    GetSizePixel() const;
     396             : 
     397             :     sal_uInt16                  GetBitCount() const;
     398             :     inline sal_uLong            GetColorCount() const;
     399             :     inline sal_uLong            GetSizeBytes() const;
     400             :     bool                    HasGreyPalette() const;
     401             :     /** get system dependent bitmap data
     402             : 
     403             :         @param rData
     404             :         The system dependent BitmapSystemData structure to be filled
     405             : 
     406             :         @return true if the bitmap has a valid system object (e.g. not empty)
     407             :     */
     408             :     bool                    GetSystemData( BitmapSystemData& rData ) const;
     409             : 
     410             :     sal_uLong                   GetChecksum() const;
     411             : 
     412             :     Bitmap                  CreateDisplayBitmap( OutputDevice* pDisplay );
     413             :     Bitmap                  GetColorTransformedBitmap() const;
     414             : 
     415             :     static const BitmapPalette& GetGreyPalette( int nEntries );
     416             : 
     417             : public:
     418             : 
     419             :     bool MakeMono( sal_uInt8 cThreshold );
     420             : 
     421             : 
     422             :     /** Convert bitmap format
     423             : 
     424             :         @param eConversion
     425             :         The format this bitmap should be converted to.
     426             : 
     427             :         @return true, if the conversion was completed successfully.
     428             :      */
     429             :     bool                    Convert( BmpConversion eConversion );
     430             : 
     431             :     /** Reduce number of colors for the bitmap
     432             : 
     433             :         @param nNewColorCount
     434             :         Maximal number of bitmap colors after the reduce operation
     435             : 
     436             :         @param eReduce
     437             :         Algorithm to use for color reduction
     438             : 
     439             :         @return true, if the color reduction operation was completed successfully.
     440             :      */
     441             :     bool                    ReduceColors( sal_uInt16 nNewColorCount,
     442             :                                           BmpReduce eReduce = BMP_REDUCE_SIMPLE );
     443             : 
     444             :     /** Apply a dither algorithm to the bitmap
     445             : 
     446             :         This method dithers the bitmap inplace, i.e. a true color
     447             :         bitmap is converted to a paletted bitmap, reducing the color
     448             :         deviation by error diffusion.
     449             : 
     450             :         @param nDitherFlags
     451             :         The algorithm to be used for dithering
     452             :      */
     453             :     bool                    Dither( sal_uLong nDitherFlags = BMP_DITHER_MATRIX );
     454             : 
     455             :     /** Crop the bitmap
     456             : 
     457             :         @param rRectPixel
     458             :         A rectangle specifying the crop amounts on all four sides of
     459             :         the bitmap. If the upper left corner of the bitmap is assigned
     460             :         (0,0), then this method cuts out the given rectangle from the
     461             :         bitmap. Note that the rectangle is clipped to the bitmap's
     462             :         dimension, i.e. negative left,top rectangle coordinates or
     463             :         exceeding width or height is ignored.
     464             : 
     465             :         @return true, if cropping was performed successfully. If
     466             :         nothing had to be cropped, because e.g. the crop rectangle
     467             :         included the bitmap, false is returned, too!
     468             :      */
     469             :     bool                    Crop( const Rectangle& rRectPixel );
     470             : 
     471             :     /** Expand the bitmap by pixel padding
     472             : 
     473             :         @param nDX
     474             :         Number of pixel to pad at the right border of the bitmap
     475             : 
     476             :         @param nDY
     477             :         Number of scanlines to pad at the bottom border of the bitmap
     478             : 
     479             :         @param pInitColor
     480             :         Color to use for padded pixel
     481             : 
     482             :         @return true, if padding was performed successfully. false is
     483             :         not only returned when the operation failed, but also if
     484             :         nothing had to be done, e.g. because nDX and nDY were zero.
     485             :      */
     486             :     bool                    Expand( sal_uLong nDX, sal_uLong nDY,
     487             :                                     const Color* pInitColor = NULL );
     488             : 
     489             :     /** Copy a rectangular area from another bitmap
     490             : 
     491             :         @param rRectDst
     492             :         Destination rectangle in this bitmap. This is clipped to the
     493             :         bitmap dimensions.
     494             : 
     495             :         @param rRectSrc
     496             :         Source rectangle in pBmpSrc. This is clipped to the source
     497             :         bitmap dimensions. Note further that no scaling takes place
     498             :         during this copy operation, i.e. only the minimum of source
     499             :         and destination rectangle's width and height are used.
     500             : 
     501             :         @param pBmpSrc
     502             :         The source bitmap to copy from. If this argument is NULL, or
     503             :         equal to the object this method is called on, copying takes
     504             :         place within the same bitmap.
     505             : 
     506             :         @return true, if the operation completed successfully. false
     507             :         is not only returned when the operation failed, but also if
     508             :         nothing had to be done, e.g. because one of the rectangles are
     509             :         empty.
     510             :      */
     511             :     bool                    CopyPixel( const Rectangle& rRectDst,
     512             :                                        const Rectangle& rRectSrc,
     513             :                                        const Bitmap* pBmpSrc = NULL );
     514             : 
     515             :     /** Perform boolean operations with another bitmap
     516             : 
     517             :         @param rMask
     518             :         The mask bitmap in the selected combine operation
     519             : 
     520             :         @param eCombine
     521             :         The combine operation to perform on the bitmap
     522             : 
     523             :         @return true, if the operation was completed successfully.
     524             :      */
     525             :     bool                    CombineSimple( const Bitmap& rMask,
     526             :                                            BmpCombine eCombine );
     527             : 
     528             :     /** Alpha-blend the given bitmap against a specified uniform
     529             :           background color.
     530             : 
     531             :         @attention This method might convert paletted bitmaps to
     532             :         truecolor, to be able to represent every necessary color. Note
     533             :         that during alpha blending, lots of colors not originally
     534             :         included in the bitmap can be generated.
     535             : 
     536             :         @param rAlpha
     537             :         Alpha mask to blend with
     538             : 
     539             :         @param rBackgroundColor
     540             :         Background color to use for every pixel during alpha blending
     541             : 
     542             :         @return true, if blending was successful, false otherwise
     543             :      */
     544             :     bool                    Blend( const AlphaMask& rAlpha,
     545             :                                    const Color&     rBackgroundColor );
     546             : 
     547             :     /** Fill the entire bitmap with the given color
     548             : 
     549             :         @param rFillColor
     550             :         Color value to use for filling
     551             : 
     552             :         @return true, if the operation was completed successfully.
     553             :      */
     554             :     bool                    Erase( const Color& rFillColor );
     555             : 
     556             :     /** Perform the Invert operation on every pixel
     557             : 
     558             :         @return true, if the operation was completed successfully.
     559             :      */
     560             :     bool                    Invert();
     561             : 
     562             :     /** Mirror the bitmap
     563             : 
     564             :         @param nMirrorFlags
     565             :         About which axis (horizontal, vertical, or both) to mirror
     566             : 
     567             :         @return true, if the operation was completed successfully.
     568             :      */
     569             :     bool                    Mirror( sal_uLong nMirrorFlags );
     570             : 
     571             :     /** Scale the bitmap
     572             : 
     573             :         @param rNewSize
     574             :         The resulting size of the scaled bitmap
     575             : 
     576             :         @param nScaleFlag
     577             :         The algorithm to be used for scaling
     578             : 
     579             :         @return true, if the operation was completed successfully.
     580             :      */
     581             :     bool                    Scale( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
     582             : 
     583             :     /** Scale the bitmap
     584             : 
     585             :         @param rScaleX
     586             :         The scale factor in x direction.
     587             : 
     588             :         @param rScaleY
     589             :         The scale factor in y direction.
     590             : 
     591             :         @param nScaleFlag
     592             :         Method of scaling - it is recommended that either BMP_SCALE_DEFAULT or BMP_SCALE_BESTQUALITY be used.
     593             : 
     594             :         @return true, if the operation was completed successfully.
     595             :      */
     596             :     bool                    Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
     597             : 
     598             :     // Adapt the BitCount of rNew to BitCount of lolal, including grey or color paltette
     599             :     // Can be used to create alpha/mask bitmaps after their processing in 24bit
     600             :     void AdaptBitCount(Bitmap& rNew) const;
     601             : 
     602             :     /** Rotate bitmap by the specified angle
     603             : 
     604             :         @param nAngle10
     605             :         The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
     606             : 
     607             :         @param rFillColor
     608             :         The color to use for filling blank areas. During rotation, the
     609             :         bitmap is enlarged such that the whole rotation result fits
     610             :         in. The empty spaces around that rotated original bitmap are
     611             :         then filled with this color.
     612             : 
     613             :         @return true, if the operation was completed successfully.
     614             :      */
     615             :     bool                    Rotate( long nAngle10, const Color& rFillColor );
     616             : 
     617             :     /** Create on-off mask from bitmap
     618             : 
     619             :         This method creates a bitmask from the bitmap, where every
     620             :         pixel that equals rTransColor is set transparent, the rest
     621             :         opaque.
     622             : 
     623             :         @param rTransColor
     624             :         Color value where the bitmask should be transparent
     625             : 
     626             :         @param nTol
     627             :         Tolerance value. Specifies the maximal difference between
     628             :         rTransColor and the individual pixel values, such that the
     629             :         corresponding pixel is still regarded transparent.
     630             : 
     631             :         @return the resulting bitmask.
     632             :      */
     633             :     Bitmap                  CreateMask( const Color& rTransColor, sal_uLong nTol = 0UL ) const;
     634             : 
     635             :     /** Create region of similar colors in a given rectangle
     636             : 
     637             :         @param rColor
     638             :         All pixel which have this color are included in the calculated region
     639             : 
     640             :         @param rRect
     641             :         The rectangle within which matching pixel are looked for. This
     642             :         rectangle is always clipped to the bitmap dimensions.
     643             : 
     644             :         @return the generated region.
     645             :      */
     646             :     Region                  CreateRegion( const Color& rColor, const Rectangle& rRect ) const;
     647             : 
     648             :     /** Replace all pixel where the given mask is on with the specified color
     649             : 
     650             :         @param rMask
     651             :         Mask specifying which pixel should be replaced
     652             : 
     653             :         @param rReplaceColor
     654             :         Color to be placed in all changed pixel
     655             : 
     656             :         @return true, if the operation was completed successfully.
     657             :      */
     658             :     bool                    Replace( const Bitmap& rMask, const Color& rReplaceColor );
     659             : 
     660             :     /** Merge bitmap with given background color according to specified alpha mask
     661             : 
     662             :         @param rAlpha
     663             :         Alpha mask specifying the amount of background color to merge in
     664             : 
     665             :         @param rMergeColor
     666             :         Background color to be used for merging
     667             : 
     668             :         @return true, if the operation was completed successfully.
     669             :      */
     670             :     bool                    Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
     671             : 
     672             :     /** Replace all pixel having the search color with the specified color
     673             : 
     674             :         @param rSearchColor
     675             :         Color specifying which pixel should be replaced
     676             : 
     677             :         @param rReplaceColor
     678             :         Color to be placed in all changed pixel
     679             : 
     680             :         @param nTol
     681             :         Tolerance value. Specifies the maximal difference between
     682             :         rSearchColor and the individual pixel values, such that the
     683             :         corresponding pixel is still regarded a match.
     684             : 
     685             :         @return true, if the operation was completed successfully.
     686             :      */
     687             :     bool                    Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
     688             : 
     689             :     /** Replace all pixel having one the search colors with the corresponding replace color
     690             : 
     691             :         @param pSearchColors
     692             :         Array of colors specifying which pixel should be replaced
     693             : 
     694             :         @param rReplaceColors
     695             :         Array of colors to be placed in all changed pixel
     696             : 
     697             :         @param nColorCount
     698             :         Size of the aforementioned color arrays
     699             : 
     700             :         @param pTols
     701             :         Tolerance value. Specifies the maximal difference between
     702             :         pSearchColor colors and the individual pixel values, such that
     703             :         the corresponding pixel is still regarded a match.
     704             : 
     705             :         @return true, if the operation was completed successfully.
     706             :      */
     707             :     bool                    Replace( const Color* pSearchColors, const Color* rReplaceColors,
     708             :                                      sal_uLong nColorCount, sal_uLong* pTols = NULL );
     709             : 
     710             :     /** Convert the bitmap to a PolyPolygon
     711             : 
     712             :         This works by putting continuous areas of the same color into
     713             :         a polygon, by tracing its bounding line.
     714             : 
     715             :         @param rPolyPoly
     716             :         The resulting PolyPolygon
     717             : 
     718             :         @param nFlags
     719             :         Whether the inline or the outline of the color areas should be
     720             :         represented by the polygon
     721             : 
     722             :         @param pProgress
     723             :         A callback for showing the progress of the vectorization
     724             : 
     725             :         @return true, if the operation was completed successfully.
     726             :      */
     727             :     bool                    Vectorize( PolyPolygon& rPolyPoly,
     728             :                                        sal_uLong nFlags = BMP_VECTORIZE_OUTER,
     729             :                                        const Link* pProgress = NULL );
     730             : 
     731             :     /** Convert the bitmap to a meta file
     732             : 
     733             :         This works by putting continuous areas of the same color into
     734             :         polygons painted in this color, by tracing the area's bounding
     735             :         line.
     736             : 
     737             :         @param rMtf
     738             :         The resulting meta file
     739             : 
     740             :         @param cReduce
     741             :         If non-null, minimal size of bound rects for individual polygons. Smaller ones are ignored.
     742             : 
     743             :         @param nFlags
     744             :         Whether the inline or the outline of the color areas should be
     745             :         represented by the polygon
     746             : 
     747             :         @param pProgress
     748             :         A callback for showing the progress of the vectorization
     749             : 
     750             :         @return true, if the operation was completed successfully.
     751             :      */
     752             :     bool                    Vectorize( GDIMetaFile& rMtf, sal_uInt8 cReduce = 0,
     753             :                                        sal_uLong nFlags = BMP_VECTORIZE_INNER,
     754             :                                        const Link* pProgress = NULL );
     755             : 
     756             :     /** Change various global color characteristics
     757             : 
     758             :         @param nLuminancePercent
     759             :         Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     760             : 
     761             :         @param nContrastPercent
     762             :         Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     763             : 
     764             :         @param nChannelRPercent
     765             :         Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     766             : 
     767             :         @param nChannelGPercent
     768             :         Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     769             : 
     770             :         @param nChannelBPercent
     771             :         Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     772             : 
     773             :         @param fGamma
     774             :         Exponent of the gamma function applied to the bitmap. The
     775             :         value 1.0 results in no change, the valid range is
     776             :         (0.0,10.0]. Values outside this range are regarded as 1.0.
     777             : 
     778             :         @param bInvert
     779             :         If true, invert the channel values with the logical 'not' operator
     780             : 
     781             :         @return true, if the operation was completed successfully.
     782             :      */
     783             :     bool                    Adjust( short nLuminancePercent = 0,
     784             :                                     short nContrastPercent = 0,
     785             :                                     short nChannelRPercent = 0,
     786             :                                     short nChannelGPercent = 0,
     787             :                                     short nChannelBPercent = 0,
     788             :                                     double fGamma = 1.0,
     789             :                                     bool bInvert = false );
     790             : 
     791             :     /** Apply specified filter to the bitmap
     792             : 
     793             :         @param eFilter
     794             :         The filter algorithm to apply
     795             : 
     796             :         @param pFilterParam
     797             :         Various parameter for the different bitmap filter algorithms
     798             : 
     799             :         @param pProgress
     800             :         A callback for showing the progress of the vectorization
     801             : 
     802             :         @return true, if the operation was completed successfully.
     803             :      */
     804             :     bool                    Filter( BmpFilter eFilter,
     805             :                                     const BmpFilterParam* pFilterParam = NULL,
     806             :                                     const Link* pProgress = NULL );
     807             : 
     808             : public:
     809             : 
     810             :     BitmapReadAccess*       AcquireReadAccess();
     811             :     BitmapWriteAccess*      AcquireWriteAccess();
     812             :     void                    ReleaseAccess( BitmapReadAccess* pAccess );
     813             : 
     814             :     typedef vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap, &Bitmap::AcquireReadAccess >
     815             :         ScopedReadAccess;
     816             :     typedef vcl::ScopedBitmapAccess< BitmapWriteAccess, Bitmap, &Bitmap::AcquireWriteAccess >
     817             :         ScopedWriteAccess;
     818             : };
     819             : 
     820           0 : inline bool Bitmap::operator!() const
     821             : {
     822           0 :     return( mpImpBmp == NULL );
     823             : }
     824             : 
     825           0 : inline bool Bitmap::operator==( const Bitmap& rBitmap ) const
     826             : {
     827           0 :     return( rBitmap.mpImpBmp == mpImpBmp );
     828             : }
     829             : 
     830           0 : inline bool Bitmap::operator!=( const Bitmap& rBitmap ) const
     831             : {
     832           0 :     return( rBitmap.mpImpBmp != mpImpBmp );
     833             : }
     834             : 
     835           0 : inline bool Bitmap::IsSameInstance( const Bitmap& rBitmap ) const
     836             : {
     837           0 :     return( rBitmap.mpImpBmp == mpImpBmp );
     838             : }
     839             : 
     840           0 : inline bool Bitmap::IsEmpty() const
     841             : {
     842           0 :     return( mpImpBmp == NULL );
     843             : }
     844             : 
     845           0 : inline const MapMode& Bitmap::GetPrefMapMode() const
     846             : {
     847           0 :     return maPrefMapMode;
     848             : }
     849             : 
     850           0 : inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
     851             : {
     852           0 :     maPrefMapMode = rMapMode;
     853           0 : }
     854             : 
     855           0 : inline const Size& Bitmap::GetPrefSize() const
     856             : {
     857           0 :     return maPrefSize;
     858             : }
     859             : 
     860           0 : inline void Bitmap::SetPrefSize( const Size& rSize )
     861             : {
     862           0 :     maPrefSize = rSize;
     863           0 : }
     864             : 
     865           0 : inline sal_uLong Bitmap::GetColorCount() const
     866             : {
     867           0 :     return( 1UL << (sal_uLong) GetBitCount() );
     868             : }
     869             : 
     870           0 : inline sal_uLong Bitmap::GetSizeBytes() const
     871             : {
     872           0 :     const Size aSizePix( GetSizePixel() );
     873           0 :     return( ( (sal_uLong) aSizePix.Width() * aSizePix.Height() * GetBitCount() ) >> 3UL );
     874             : }
     875             : 
     876             : #endif // INCLUDED_VCL_BITMAP_HXX
     877             : 
     878             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10