LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/vcl - bitmapex.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 12 75.0 %
Date: 2012-12-27 Functions: 9 12 75.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 _SV_BITMAPEX_HXX
      21             : #define _SV_BITMAPEX_HXX
      22             : 
      23             : #include <vcl/dllapi.h>
      24             : #include <vcl/bitmap.hxx>
      25             : #include <vcl/alpha.hxx>
      26             : #include <tools/color.hxx>
      27             : 
      28             : // -------------------
      29             : // - TransparentType -
      30             : // -------------------
      31             : 
      32             : enum TransparentType
      33             : {
      34             :     TRANSPARENT_NONE,
      35             :     TRANSPARENT_COLOR,
      36             :     TRANSPARENT_BITMAP
      37             : };
      38             : 
      39             : // ------------
      40             : // - BitmapEx -
      41             : // ------------
      42             : 
      43             : class VCL_DLLPUBLIC BitmapEx
      44             : {
      45             :     friend class ImpGraphic;
      46             : 
      47             : private:
      48             : 
      49             :     Bitmap              aBitmap;
      50             :     Bitmap              aMask;
      51             :     Size                aBitmapSize;
      52             :     Color               aTransparentColor;
      53             :     TransparentType     eTransparent;
      54             :     sal_Bool            bAlpha;
      55             : 
      56             : public:
      57             : 
      58             : 
      59           4 :     SAL_DLLPRIVATE  ImpBitmap*  ImplGetBitmapImpBitmap() const { return aBitmap.ImplGetImpBitmap(); }
      60           4 :     SAL_DLLPRIVATE  ImpBitmap*  ImplGetMaskImpBitmap() const { return aMask.ImplGetImpBitmap(); }
      61             : 
      62             : public:
      63             : 
      64             :                         BitmapEx();
      65             :                         BitmapEx( const ResId& rResId );
      66             :                         BitmapEx( const BitmapEx& rBitmapEx );
      67             :                         BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize );
      68             :                         BitmapEx( const Bitmap& rBmp );
      69             :                         BitmapEx( const Bitmap& rBmp, const Bitmap& rMask );
      70             :                         BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask );
      71             :                         BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor );
      72             :                         ~BitmapEx();
      73             : 
      74             :     BitmapEx&           operator=( const BitmapEx& rBitmapEx );
      75             :     sal_Bool                operator==( const BitmapEx& rBitmapEx ) const;
      76           0 :     sal_Bool                operator!=( const BitmapEx& rBitmapEx ) const { return !(*this==rBitmapEx); }
      77        2803 :     sal_Bool                operator!() const { return !aBitmap; }
      78             : 
      79             :     sal_Bool                IsEqual( const BitmapEx& rBmpEx ) const;
      80             : 
      81             :     sal_Bool                IsEmpty() const;
      82             :     void                SetEmpty();
      83             :     void                Clear();
      84             : 
      85             :     void                Draw( OutputDevice* pOutDev,
      86             :                               const Point& rDestPt ) const;
      87             :     void                Draw( OutputDevice* pOutDev,
      88             :                               const Point& rDestPt, const Size& rDestSize ) const;
      89             : 
      90             :     sal_Bool                IsTransparent() const;
      91        2266 :     TransparentType     GetTransparentType() const { return eTransparent; }
      92             : 
      93             :     Bitmap              GetBitmap( const Color* pTransReplaceColor = NULL ) const;
      94             :     Bitmap              GetMask() const;
      95             : 
      96             :     BitmapEx            GetColorTransformedBitmapEx() const;
      97             : 
      98             :     sal_Bool                IsAlpha() const;
      99             :     AlphaMask           GetAlpha() const;
     100             : 
     101        2432 :     const Size&         GetSizePixel() const { return aBitmapSize; }
     102             :     void                SetSizePixel( const Size& rNewSize );
     103             : 
     104        1528 :     const Size&         GetPrefSize() const { return aBitmap.GetPrefSize(); }
     105         278 :     void                SetPrefSize( const Size& rPrefSize ) { aBitmap.SetPrefSize( rPrefSize ); }
     106             : 
     107         616 :     const MapMode&      GetPrefMapMode() const { return aBitmap.GetPrefMapMode(); }
     108         278 :     void                SetPrefMapMode( const MapMode& rPrefMapMode ) { aBitmap.SetPrefMapMode( rPrefMapMode ); }
     109             : 
     110           0 :     const Color&        GetTransparentColor() const { return aTransparentColor; }
     111             :     void                SetTransparentColor( const Color& rColor ) { aTransparentColor = rColor; }
     112             : 
     113           0 :     sal_uInt16              GetBitCount() const { return aBitmap.GetBitCount(); }
     114             :     sal_uLong               GetSizeBytes() const;
     115             :     sal_uLong               GetChecksum() const;
     116             : 
     117             : public:
     118             : 
     119             :     /** Convert bitmap format
     120             : 
     121             :         @param eConversion
     122             :         The format this bitmap should be converted to.
     123             : 
     124             :         @return sal_True, if the conversion was completed successfully.
     125             :      */
     126             :     sal_Bool                Convert( BmpConversion eConversion );
     127             : 
     128             :     /** Reduce number of colors for the bitmap
     129             : 
     130             :         @param nNewColorCount
     131             :         Maximal number of bitmap colors after the reduce operation
     132             : 
     133             :         @param eReduce
     134             :         Algorithm to use for color reduction
     135             : 
     136             :         @return sal_True, if the color reduction operation was completed successfully.
     137             :      */
     138             :     sal_Bool                ReduceColors( sal_uInt16 nNewColorCount,
     139             :                                       BmpReduce eReduce = BMP_REDUCE_SIMPLE );
     140             : 
     141             :     /** Apply a dither algorithm to the bitmap
     142             : 
     143             :         This method dithers the bitmap inplace, i.e. a true color
     144             :         bitmap is converted to a paletted bitmap, reducing the color
     145             :         deviation by error diffusion.
     146             : 
     147             :         @param nDitherFlags
     148             :         The algorithm to be used for dithering
     149             :      */
     150             :     sal_Bool                Dither( sal_uLong nDitherFlags = BMP_DITHER_MATRIX );
     151             : 
     152             :     /** Crop the bitmap
     153             : 
     154             :         @param rRectPixel
     155             :         A rectangle specifying the crop amounts on all four sides of
     156             :         the bitmap. If the upper left corner of the bitmap is assigned
     157             :         (0,0), then this method cuts out the given rectangle from the
     158             :         bitmap. Note that the rectangle is clipped to the bitmap's
     159             :         dimension, i.e. negative left,top rectangle coordinates or
     160             :         exceeding width or height is ignored.
     161             : 
     162             :         @return sal_True, if cropping was performed successfully. If
     163             :         nothing had to be cropped, because e.g. the crop rectangle
     164             :         included the bitmap, sal_False is returned, too!
     165             :      */
     166             :     sal_Bool                Crop( const Rectangle& rRectPixel );
     167             : 
     168             :     /** Expand the bitmap by pixel padding
     169             : 
     170             :         @param nDX
     171             :         Number of pixel to pad at the right border of the bitmap
     172             : 
     173             :         @param nDY
     174             :         Number of scanlines to pad at the bottom border of the bitmap
     175             : 
     176             :         @param pInitColor
     177             :         Color to use for padded pixel
     178             : 
     179             :         @return sal_True, if padding was performed successfully. sal_False is
     180             :         not only returned when the operation failed, but also if
     181             :         nothing had to be done, e.g. because nDX and nDY were zero.
     182             :      */
     183             :     sal_Bool                Expand( sal_uLong nDX, sal_uLong nDY,
     184             :                                 const Color* pInitColor = NULL,
     185             :                                 sal_Bool bExpandTransparent = sal_False );
     186             : 
     187             :     /** Copy a rectangular area from another bitmap
     188             : 
     189             :         @param rRectDst
     190             :         Destination rectangle in this bitmap. This is clipped to the
     191             :         bitmap dimensions.
     192             : 
     193             :         @param rRectSrc
     194             :         Source rectangle in pBmpSrc. This is clipped to the source
     195             :         bitmap dimensions. Note further that no scaling takes place
     196             :         during this copy operation, i.e. only the minimum of source
     197             :         and destination rectangle's width and height are used.
     198             : 
     199             :         @param pBmpSrc
     200             :         The source bitmap to copy from. If this argument is NULL, or
     201             :         equal to the object this method is called on, copying takes
     202             :         place within the same bitmap.
     203             : 
     204             :         @return sal_True, if the operation completed successfully. sal_False
     205             :         is not only returned when the operation failed, but also if
     206             :         nothing had to be done, e.g. because one of the rectangles are
     207             :         empty.
     208             :      */
     209             :     sal_Bool                CopyPixel( const Rectangle& rRectDst,
     210             :                                    const Rectangle& rRectSrc,
     211             :                                    const BitmapEx* pBmpExSrc = NULL );
     212             : 
     213             :     /** Fill the entire bitmap with the given color
     214             : 
     215             :         @param rFillColor
     216             :         Color value to use for filling. Set the transparency part of
     217             :         the color to fill the mask.
     218             : 
     219             :         @return sal_True, if the operation was completed successfully.
     220             :      */
     221             :     sal_Bool                Erase( const Color& rFillColor );
     222             : 
     223             :     /** Perform the Invert operation on every pixel
     224             : 
     225             :         @return sal_True, if the operation was completed successfully.
     226             :      */
     227             :     sal_Bool                Invert();
     228             : 
     229             :     /** Mirror the bitmap
     230             : 
     231             :         @param nMirrorFlags
     232             :         About which axis (horizontal, vertical, or both) to mirror
     233             : 
     234             :         @return sal_True, if the operation was completed successfully.
     235             :      */
     236             :     sal_Bool                Mirror( sal_uLong nMirrorFlags );
     237             : 
     238             :     /** Scale the bitmap
     239             : 
     240             :         @param rNewSize
     241             :         The resulting size of the scaled bitmap
     242             : 
     243             :         @param nScaleFlag
     244             :         The algorithm to be used for scaling
     245             : 
     246             :         @return sal_True, if the operation was completed successfully.
     247             :      */
     248             :     sal_Bool                Scale( const Size& rNewSize, sal_uLong nScaleFlag = BMP_SCALE_DEFAULT );
     249             : 
     250             :     /** Scale the bitmap
     251             : 
     252             :         @param rScaleX
     253             :         The scale factor in x direction.
     254             : 
     255             :         @param rScaleY
     256             :         The scale factor in y direction.
     257             : 
     258             :         @return sal_True, if the operation was completed successfully.
     259             :      */
     260             :     sal_Bool                Scale( const double& rScaleX, const double& rScaleY, sal_uLong nScaleFlag = BMP_SCALE_DEFAULT );
     261             : 
     262             :     /** Rotate bitmap by the specified angle
     263             : 
     264             :         @param nAngle10
     265             :         The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
     266             : 
     267             :         @param rFillColor
     268             :         The color to use for filling blank areas. During rotation, the
     269             :         bitmap is enlarged such that the whole rotation result fits
     270             :         in. The empty spaces around that rotated original bitmap are
     271             :         then filled with this color.
     272             : 
     273             :         @return sal_True, if the operation was completed successfully.
     274             :      */
     275             :     sal_Bool                Rotate( long nAngle10, 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 sal_True, if the operation was completed successfully.
     291             :      */
     292             :     sal_Bool                Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
     293             : 
     294             :     /** Replace all pixel having one the search colors with the corresponding replace color
     295             : 
     296             :         @param pSearchColor
     297             :         Array of colors specifying which pixel should be replaced
     298             : 
     299             :         @param pReplaceColor
     300             :         Array of colors to be placed in all changed pixel
     301             : 
     302             :         @param nColorCount
     303             :         Size of the aforementioned color arrays
     304             : 
     305             :         @param nTol
     306             :         Tolerance value. Specifies the maximal difference between
     307             :         pSearchColor colors and the individual pixel values, such that
     308             :         the corresponding pixel is still regarded a match.
     309             : 
     310             :         @return sal_True, if the operation was completed successfully.
     311             :      */
     312             :     sal_Bool                Replace( const Color* pSearchColors, const Color* pReplaceColors,
     313             :                                  sal_uLong nColorCount, const sal_uLong* pTols = NULL );
     314             : 
     315             :     /** Change various global color characteristics
     316             : 
     317             :         @param nLuminancePercent
     318             :         Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     319             : 
     320             :         @param nContrastPercent
     321             :         Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     322             : 
     323             :         @param nChannelRPercent
     324             :         Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     325             : 
     326             :         @param nChannelGPercent
     327             :         Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     328             : 
     329             :         @param nChannelBPercent
     330             :         Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
     331             : 
     332             :         @param fGamma
     333             :         Exponent of the gamma function applied to the bitmap. The
     334             :         value 1.0 results in no change, the valid range is
     335             :         (0.0,10.0]. Values outside this range are regarded as 1.0.
     336             : 
     337             :         @param bInvert
     338             :         If sal_True, invert the channel values with the logical 'not' operator
     339             : 
     340             :         @return sal_True, if the operation was completed successfully.
     341             :      */
     342             :     sal_Bool                Adjust( short nLuminancePercent = 0,
     343             :                                 short nContrastPercent = 0,
     344             :                                 short nChannelRPercent = 0,
     345             :                                 short nChannelGPercent = 0,
     346             :                                 short nChannelBPercent = 0,
     347             :                                 double fGamma = 1.0,
     348             :                                 sal_Bool bInvert = sal_False );
     349             : 
     350             :     /** Apply specified filter to the bitmap
     351             : 
     352             :         @param eFilter
     353             :         The filter algorithm to apply
     354             : 
     355             :         @param pFilterParam
     356             :         Various parameter for the different bitmap filter algorithms
     357             : 
     358             :         @param pProgress
     359             :         A callback for showing the progress of the vectorization
     360             : 
     361             :         @return sal_True, if the operation was completed successfully.
     362             :      */
     363             :     sal_Bool                Filter( BmpFilter eFilter,
     364             :                                 const BmpFilterParam* pFilterParam = NULL,
     365             :                                 const Link* pProgress = NULL );
     366             : 
     367             :     /** Get transparency at given position
     368             : 
     369             :         @param nX
     370             :         integer X-Position in Bitmap
     371             : 
     372             :         @param nY
     373             :         integer Y-Position in Bitmap
     374             : 
     375             :         @return transparency value in the range of [0 .. 255] where
     376             :                 0 is not transparent, 255 is fully transparent
     377             :      */
     378             :     sal_uInt8 GetTransparency(sal_Int32 nX, sal_Int32 nY) const;
     379             : 
     380             : public:
     381             : 
     382             :     friend VCL_DLLPUBLIC SvStream&  operator<<( SvStream& rOStm, const BitmapEx& rBitmapEx );
     383             :     friend VCL_DLLPUBLIC SvStream&  operator>>( SvStream& rIStm, BitmapEx& rBitmapEx );
     384             :     static BitmapEx AutoScaleBitmap(BitmapEx & aBitmap, const long aStandardSize);
     385             : };
     386             : 
     387             : #endif // _SV_BITMAPEX_HXX
     388             : 
     389             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10