LCOV - code coverage report
Current view: top level - include/vcl - bitmapex.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 12 0.0 %
Date: 2014-04-14 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10