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

Generated by: LCOV version 1.10