LCOV - code coverage report
Current view: top level - include/vcl - bitmapex.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 10 12 83.3 %
Date: 2015-06-13 12:38:46 Functions: 10 12 83.3 %
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_BITMAPEX_HXX
      21             : #define INCLUDED_VCL_BITMAPEX_HXX
      22             : 
      23             : #include <vcl/dllapi.h>
      24             : #include <vcl/bitmap.hxx>
      25             : #include <vcl/alpha.hxx>
      26             : #include <tools/color.hxx>
      27             : #include <basegfx/color/bcolormodifier.hxx>
      28             : 
      29             : #include <com/sun/star/uno/Reference.hxx>
      30             : #include <sal/types.h>
      31             : 
      32             : namespace com { namespace sun { namespace star { namespace rendering {
      33             :     class XBitmapCanvas;
      34             : } } } }
      35             : 
      36             : enum TransparentType
      37             : {
      38             :     TRANSPARENT_NONE,
      39             :     TRANSPARENT_COLOR,
      40             :     TRANSPARENT_BITMAP
      41             : };
      42             : 
      43             : class VCL_DLLPUBLIC BitmapEx
      44             : {
      45             : public:
      46             : 
      47             :                         BitmapEx();
      48             :                         BitmapEx( const ResId& rResId );
      49             :                         BitmapEx( const OUString& rIconName );
      50             :                         BitmapEx( const BitmapEx& rBitmapEx );
      51             :                         BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize );
      52             :                         BitmapEx( const Bitmap& rBmp );
      53             :                         BitmapEx( const Bitmap& rBmp, const Bitmap& rMask );
      54             :                         BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask );
      55             :                         BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor );
      56             :                         ~BitmapEx();
      57             : 
      58             :     BitmapEx&           operator=( const BitmapEx& rBitmapEx );
      59             :     bool                operator==( const BitmapEx& rBitmapEx ) const;
      60           0 :     bool                operator!=( const BitmapEx& rBitmapEx ) const { return !(*this==rBitmapEx); }
      61       12363 :     bool                operator!() const { return !aBitmap; }
      62             : 
      63             :     bool                IsEqual( const BitmapEx& rBmpEx ) const;
      64             : 
      65             :     bool                IsEmpty() const;
      66             :     void                SetEmpty();
      67             :     void                Clear();
      68             : 
      69             :     void                Draw( OutputDevice* pOutDev,
      70             :                               const Point& rDestPt ) const;
      71             :     void                Draw( OutputDevice* pOutDev,
      72             :                               const Point& rDestPt, const Size& rDestSize ) const;
      73             : 
      74             :     bool                IsTransparent() const;
      75      530004 :     TransparentType     GetTransparentType() const { return eTransparent; }
      76             : 
      77             :     Bitmap              GetBitmap( const Color* pTransReplaceColor = NULL ) const;
      78             :     Bitmap              GetMask() const;
      79             : 
      80             :     BitmapEx            GetColorTransformedBitmapEx() const;
      81             : 
      82             :     bool                IsAlpha() const;
      83             :     AlphaMask           GetAlpha() const;
      84             : 
      85      609102 :     const Size&         GetSizePixel() const { return aBitmapSize; }
      86             :     void                SetSizePixel( const Size& rNewSize, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
      87             : 
      88       34600 :     const Size&         GetPrefSize() const { return aBitmap.GetPrefSize(); }
      89        6605 :     void                SetPrefSize( const Size& rPrefSize ) { aBitmap.SetPrefSize( rPrefSize ); }
      90             : 
      91       11700 :     const MapMode&      GetPrefMapMode() const { return aBitmap.GetPrefMapMode(); }
      92        6602 :     void                SetPrefMapMode( const MapMode& rPrefMapMode ) { aBitmap.SetPrefMapMode( rPrefMapMode ); }
      93             : 
      94           0 :     const Color&        GetTransparentColor() const { return aTransparentColor; }
      95             :     void                SetTransparentColor( const Color& rColor ) { aTransparentColor = rColor; }
      96             : 
      97         296 :     sal_uInt16          GetBitCount() const { return aBitmap.GetBitCount(); }
      98             :     sal_uLong           GetSizeBytes() const;
      99             :     sal_uLong           GetChecksum() const;
     100             : 
     101             : public:
     102             : 
     103             :     /** Convert bitmap format
     104             : 
     105             :         @param eConversion
     106             :         The format this bitmap should be converted to.
     107             : 
     108             :         @return true, if the conversion was completed successfully.
     109             :      */
     110             :     bool                Convert( BmpConversion eConversion );
     111             : 
     112             :     /** Reduce number of colors for the bitmap
     113             : 
     114             :         @param nNewColorCount
     115             :         Maximal number of bitmap colors after the reduce operation
     116             : 
     117             :         @param eReduce
     118             :         Algorithm to use for color reduction
     119             : 
     120             :         @return true, if the color reduction operation was completed successfully.
     121             :      */
     122             :     bool                ReduceColors(
     123             :                             sal_uInt16 nNewColorCount,
     124             :                             BmpReduce eReduce = BMP_REDUCE_SIMPLE );
     125             : 
     126             :     /** Apply a dither algorithm to the bitmap
     127             : 
     128             :         This method dithers the bitmap inplace, i.e. a true color
     129             :         bitmap is converted to a paletted bitmap, reducing the color
     130             :         deviation by error diffusion.
     131             : 
     132             :         @param nDitherFlags
     133             :         The algorithm to be used for dithering
     134             :      */
     135             :     bool                Dither( BmpDitherFlags nDitherFlags = BmpDitherFlags::Matrix );
     136             : 
     137             :     /** Crop the bitmap
     138             : 
     139             :         @param rRectPixel
     140             :         A rectangle specifying the crop amounts on all four sides of
     141             :         the bitmap. If the upper left corner of the bitmap is assigned
     142             :         (0,0), then this method cuts out the given rectangle from the
     143             :         bitmap. Note that the rectangle is clipped to the bitmap's
     144             :         dimension, i.e. negative left,top rectangle coordinates or
     145             :         exceeding width or height is ignored.
     146             : 
     147             :         @return true, if cropping was performed successfully. If
     148             :         nothing had to be cropped, because e.g. the crop rectangle
     149             :         included the bitmap, false is returned, too!
     150             :      */
     151             :     bool                Crop( const Rectangle& rRectPixel );
     152             : 
     153             :     /** Expand the bitmap by pixel padding
     154             : 
     155             :         @param nDX
     156             :         Number of pixel to pad at the right border of the bitmap
     157             : 
     158             :         @param nDY
     159             :         Number of scanlines to pad at the bottom border of the bitmap
     160             : 
     161             :         @param pInitColor
     162             :         Color to use for padded pixel
     163             : 
     164             :         @param bExpandTransparent
     165             :         Whether to expand the transparency color or not.
     166             : 
     167             :         @return true, if padding was performed successfully. false is
     168             :         not only returned when the operation failed, but also if
     169             :         nothing had to be done, e.g. because nDX and nDY were zero.
     170             :      */
     171             :     bool                Expand(
     172             :                             sal_uLong nDX, sal_uLong nDY,
     173             :                             const Color* pInitColor = NULL,
     174             :                             bool bExpandTransparent = false );
     175             : 
     176             :     /** Copy a rectangular area from another bitmap
     177             : 
     178             :         @param rRectDst
     179             :         Destination rectangle in this bitmap. This is clipped to the
     180             :         bitmap dimensions.
     181             : 
     182             :         @param rRectSrc
     183             :         Source rectangle in pBmpSrc. This is clipped to the source
     184             :         bitmap dimensions. Note further that no scaling takes place
     185             :         during this copy operation, i.e. only the minimum of source
     186             :         and destination rectangle's width and height are used.
     187             : 
     188             :         @param pBmpExSrc
     189             :         The source bitmap to copy from. If this argument is NULL, or
     190             :         equal to the object this method is called on, copying takes
     191             :         place within the same bitmap.
     192             : 
     193             :         @return true, if the operation completed successfully. false
     194             :         is not only returned when the operation failed, but also if
     195             :         nothing had to be done, e.g. because one of the rectangles are
     196             :         empty.
     197             :      */
     198             :     bool                CopyPixel(
     199             :                             const Rectangle& rRectDst,
     200             :                             const Rectangle& rRectSrc,
     201             :                             const BitmapEx* pBmpExSrc = NULL );
     202             : 
     203             :     /** Fill the entire bitmap with the given color
     204             : 
     205             :         @param rFillColor
     206             :         Color value to use for filling. Set the transparency part of
     207             :         the color to fill the mask.
     208             : 
     209             :         @return true, if the operation was completed successfully.
     210             :      */
     211             :     bool                Erase( const Color& rFillColor );
     212             : 
     213             :     /** Perform the Invert operation on every pixel
     214             : 
     215             :         @return true, if the operation was completed successfully.
     216             :      */
     217             :     bool                Invert();
     218             : 
     219             :     /** Mirror the bitmap
     220             : 
     221             :         @param nMirrorFlags
     222             :         About which axis (horizontal, vertical, or both) to mirror
     223             : 
     224             :         @return true, if the operation was completed successfully.
     225             :      */
     226             :     bool                Mirror( BmpMirrorFlags nMirrorFlags );
     227             : 
     228             :     /** Scale the bitmap
     229             : 
     230             :         @param rNewSize
     231             :         The resulting size of the scaled bitmap
     232             : 
     233             :         @param nScaleFlag
     234             :         The algorithm to be used for scaling
     235             : 
     236             :         @return true, if the operation was completed successfully.
     237             :      */
     238             :     bool                Scale(
     239             :                             const Size& rNewSize,
     240             :                             BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
     241             : 
     242             :     /** Scale the bitmap
     243             : 
     244             :         @param rScaleX
     245             :         The scale factor in x direction.
     246             : 
     247             :         @param rScaleY
     248             :         The scale factor in y direction.
     249             : 
     250             :         @param nScaleFlag
     251             :         The algorithm to be used for scaling
     252             : 
     253             :         @return true, if the operation was completed successfully.
     254             :      */
     255             :     bool                Scale(
     256             :                             const double& rScaleX,
     257             :                             const double& rScaleY,
     258             :                             BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
     259             : 
     260             :     /** Rotate bitmap by the specified angle
     261             : 
     262             :         @param nAngle10
     263             :         The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
     264             : 
     265             :         @param rFillColor
     266             :         The color to use for filling blank areas. During rotation, the
     267             :         bitmap is enlarged such that the whole rotation result fits
     268             :         in. The empty spaces around that rotated original bitmap are
     269             :         then filled with this color.
     270             : 
     271             :         @return true, if the operation was completed successfully.
     272             :      */
     273             :     bool                Rotate(
     274             :                             long nAngle10,
     275             :                             const Color& rFillColor );
     276             : 
     277             :     /** Replace all pixel having the search color with the specified color
     278             : 
     279             :         @param rSearchColor
     280             :         Color specifying which pixel should be replaced
     281             : 
     282             :         @param rReplaceColor
     283             :         Color to be placed in all changed pixel
     284             : 
     285             :         @param nTol
     286             :         Tolerance value. Specifies the maximal difference between
     287             :         rSearchColor and the individual pixel values, such that the
     288             :         corresponding pixel is still regarded a match.
     289             : 
     290             :         @return true, if the operation was completed successfully.
     291             :      */
     292             :     bool                Replace(
     293             :                             const Color& rSearchColor,
     294             :                             const Color& rReplaceColor,
     295             :                             sal_uLong nTol = 0 );
     296             : 
     297             :     /** Replace all pixel having one the search colors with the corresponding replace color
     298             : 
     299             :         @param pSearchColors
     300             :         Array of colors specifying which pixel should be replaced
     301             : 
     302             :         @param pReplaceColors
     303             :         Array of colors to be placed in all changed pixel
     304             : 
     305             :         @param nColorCount
     306             :         Size of the aforementioned color arrays
     307             : 
     308             :         @param pTols
     309             :         Tolerance value. Specifies the maximal difference between
     310             :         pSearchColor colors and the individual pixel values, such that
     311             :         the corresponding pixel is still regarded a match.
     312             : 
     313             :         @return true, if the operation was completed successfully.
     314             :      */
     315             :     bool                Replace(
     316             :                             const Color* pSearchColors,
     317             :                             const Color* pReplaceColors,
     318             :                             sal_uLong nColorCount,
     319             :                             const sal_uLong* pTols = NULL );
     320             : 
     321             :     /** Change various global color characteristics
     322             : 
     323             :         @param nLuminancePercent
     324             :         Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     325             : 
     326             :         @param nContrastPercent
     327             :         Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     328             : 
     329             :         @param nChannelRPercent
     330             :         Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     331             : 
     332             :         @param nChannelGPercent
     333             :         Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     334             : 
     335             :         @param nChannelBPercent
     336             :         Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     337             : 
     338             :         @param fGamma
     339             :         Exponent of the gamma function applied to the bitmap. The
     340             :         value 1.0 results in no change, the valid range is
     341             :         (0.0,10.0]. Values outside this range are regarded as 1.0.
     342             : 
     343             :         @param bInvert
     344             :         If true, invert the channel values with the logical 'not' operator
     345             : 
     346             :         @param msoFormula
     347             :         Use the same formula for brightness as used by MSOffice.
     348             : 
     349             :         @return true, if the operation was completed successfully.
     350             :      */
     351             :     bool                Adjust(
     352             :                             short nLuminancePercent = 0,
     353             :                             short nContrastPercent = 0,
     354             :                             short nChannelRPercent = 0,
     355             :                             short nChannelGPercent = 0,
     356             :                             short nChannelBPercent = 0,
     357             :                             double fGamma = 1.0,
     358             :                             bool bInvert = false,
     359             :                             bool msoBrightness = false );
     360             : 
     361             :     /** Apply specified filter to the bitmap
     362             : 
     363             :         @param eFilter
     364             :         The filter algorithm to apply
     365             : 
     366             :         @param pFilterParam
     367             :         Various parameter for the different bitmap filter algorithms
     368             : 
     369             :         @param pProgress
     370             :         A callback for showing the progress of the vectorization
     371             : 
     372             :         @return true, if the operation was completed successfully.
     373             :      */
     374             :     bool                Filter(
     375             :                             BmpFilter eFilter,
     376             :                             const BmpFilterParam* pFilterParam = NULL,
     377             :                             const Link<>* pProgress = NULL );
     378             : 
     379             :     /** Get transparency at given position
     380             : 
     381             :         @param nX
     382             :         integer X-Position in Bitmap
     383             : 
     384             :         @param nY
     385             :         integer Y-Position in Bitmap
     386             : 
     387             :         @return transparency value in the range of [0 .. 255] where
     388             :                 0 is not transparent, 255 is fully transparent
     389             :      */
     390             :     sal_uInt8           GetTransparency(
     391             :                             sal_Int32 nX,
     392             :                             sal_Int32 nY) const;
     393             : 
     394             :     /** Create transformed Bitmap
     395             : 
     396             :         @param fWidth
     397             :         The target width in pixels
     398             : 
     399             :         @param fHeight
     400             :         The target height in pixels
     401             : 
     402             :         @param rTransformation
     403             :         The back transformation for each pixel in (0 .. fWidth),(0 .. fHeight) to
     404             :         local pixel coordiantes
     405             : 
     406             :         @param bSmooth
     407             :         Defines if pixel interpolation is to be used to create the result
     408             :     */
     409             :     BitmapEx            TransformBitmapEx(
     410             :                             double fWidth,
     411             :                             double fHeight,
     412             :                             const basegfx::B2DHomMatrix& rTransformation,
     413             :                             bool bSmooth = true) const;
     414             : 
     415             :     /** Create transformed Bitmap
     416             : 
     417             :         @param rTransformation
     418             :         The transformation from unit coordinates to the unit range
     419             : 
     420             :         @param rVisibleRange
     421             :         The relative visible range in unit coordinates, relative to (0,0,1,1) which
     422             :         defines the whole target area
     423             : 
     424             :         @param fMaximumArea
     425             :         A limitation for the maximum size of pixels to use for the result
     426             : 
     427             :         @param bSmooth
     428             :         Defines if pixel interpolation is to be used to create the result
     429             : 
     430             :         The traget size of the result bitmap is defined by transforming the given
     431             :         rTargetRange with the given rTransformation; the area of the result is
     432             :         linearly scaled to not exceed the given fMaximumArea
     433             : 
     434             :         @return The transformed bitmap
     435             :     */
     436             :     BitmapEx            getTransformed(
     437             :                             const basegfx::B2DHomMatrix& rTransformation,
     438             :                             const basegfx::B2DRange& rVisibleRange,
     439             :                             double fMaximumArea = 500000.0,
     440             :                             bool bSmooth = true) const;
     441             : 
     442             :     /** Create ColorStack-modified version of this BitmapEx
     443             : 
     444             :         @param rBColorModifierStack
     445             :         A ColrModifierStack which defines how each pixel has to be modified
     446             :     */
     447             :     BitmapEx            ModifyBitmapEx( const basegfx::BColorModifierStack& rBColorModifierStack) const;
     448             : 
     449             :     static BitmapEx     AutoScaleBitmap( BitmapEx & aBitmap, const long aStandardSize );
     450             : 
     451             :     /// populate from a canvas implementation
     452             :     bool                Create(
     453             :                             const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
     454             :                             const Size &rSize );
     455             : public:
     456             : 
     457       12405 :     SAL_DLLPRIVATE  ImpBitmap*  ImplGetBitmapImpBitmap() const { return aBitmap.ImplGetImpBitmap(); }
     458       12405 :     SAL_DLLPRIVATE  ImpBitmap*  ImplGetMaskImpBitmap() const { return aMask.ImplGetImpBitmap(); }
     459             : 
     460             : 
     461             : private:
     462             :     friend class ImpGraphic;
     463             :     friend bool VCL_DLLPUBLIC WriteDIBBitmapEx(const BitmapEx& rSource, SvStream& rOStm);
     464             :     void  loadFromIconTheme( const OUString& rIconName );
     465             : 
     466             :     Bitmap              aBitmap;
     467             :     Bitmap              aMask;
     468             :     Size                aBitmapSize;
     469             :     Color               aTransparentColor;
     470             :     TransparentType     eTransparent;
     471             :     bool                bAlpha;
     472             : 
     473             : };
     474             : 
     475             : 
     476             : /** Create a blend frame as BitmapEx
     477             : 
     478             :     @param nAlpha
     479             :     The blend value defines how strong the frame will be blended with the
     480             :     existing content, 255 == full coverage, 0 == no frame will be drawn
     481             : 
     482             :     @param aColorTopLeft, aColorBottomRight
     483             :     The colors defining the frame. These colors are linearly interpolated from
     484             :     aColorTopLeft and aColorBottomRight using the width and height of the area
     485             : 
     486             :     @param rSize
     487             :     The size of the frame in pixels
     488             :     */
     489             : BitmapEx VCL_DLLPUBLIC createBlendFrame(
     490             :     const Size& rSize,
     491             :     sal_uInt8 nAlpha,
     492             :     Color aColorTopLeft,
     493             :     Color aColorBottomRight);
     494             : 
     495             : 
     496             : /** Create a blend frame as BitmapEx
     497             : 
     498             :     @param nAlpha
     499             :     The blend value defines how strong the frame will be blended with the
     500             :     existing content, 255 == full coverage, 0 == no frame will be drawn
     501             : 
     502             :     @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft
     503             :     The colors defining the frame.
     504             : 
     505             :     @param rSize
     506             :     The size of the frame in pixels
     507             :     */
     508             : BitmapEx VCL_DLLPUBLIC createBlendFrame(
     509             :     const Size& rSize,
     510             :     sal_uInt8 nAlpha,
     511             :     Color aColorTopLeft,
     512             :     Color aColorTopRight,
     513             :     Color aColorBottomRight,
     514             :     Color aColorBottomLeft);
     515             : 
     516             : #endif // INCLUDED_VCL_BITMAPEX_HXX
     517             : 
     518             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11