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

Generated by: LCOV version 1.11