1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _SV_BITMAPEX_HXX
21 #define _SV_BITMAPEX_HXX
23 #include <vcl/dllapi.h>
24 #include <vcl/bitmap.hxx>
25 #include <vcl/alpha.hxx>
26 #include <tools/color.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
30 namespace com
{ namespace sun
{ namespace star
{ namespace rendering
{
34 // -------------------
35 // - TransparentType -
36 // -------------------
49 class VCL_DLLPUBLIC BitmapEx
51 friend class ImpGraphic
;
58 Color aTransparentColor
;
59 TransparentType eTransparent
;
65 SAL_DLLPRIVATE ImpBitmap
* ImplGetBitmapImpBitmap() const { return aBitmap
.ImplGetImpBitmap(); }
66 SAL_DLLPRIVATE ImpBitmap
* ImplGetMaskImpBitmap() const { return aMask
.ImplGetImpBitmap(); }
71 BitmapEx( const ResId
& rResId
);
72 BitmapEx( const BitmapEx
& rBitmapEx
);
73 BitmapEx( const BitmapEx
& rBitmapEx
, Point aSrc
, Size aSize
);
74 BitmapEx( const Bitmap
& rBmp
);
75 BitmapEx( const Bitmap
& rBmp
, const Bitmap
& rMask
);
76 BitmapEx( const Bitmap
& rBmp
, const AlphaMask
& rAlphaMask
);
77 BitmapEx( const Bitmap
& rBmp
, const Color
& rTransparentColor
);
80 BitmapEx
& operator=( const BitmapEx
& rBitmapEx
);
81 sal_Bool
operator==( const BitmapEx
& rBitmapEx
) const;
82 sal_Bool
operator!=( const BitmapEx
& rBitmapEx
) const { return !(*this==rBitmapEx
); }
83 sal_Bool
operator!() const { return !aBitmap
; }
85 sal_Bool
IsEqual( const BitmapEx
& rBmpEx
) const;
87 sal_Bool
IsEmpty() const;
91 void Draw( OutputDevice
* pOutDev
,
92 const Point
& rDestPt
) const;
93 void Draw( OutputDevice
* pOutDev
,
94 const Point
& rDestPt
, const Size
& rDestSize
) const;
96 sal_Bool
IsTransparent() const;
97 TransparentType
GetTransparentType() const { return eTransparent
; }
99 Bitmap
GetBitmap( const Color
* pTransReplaceColor
= NULL
) const;
100 Bitmap
GetMask() const;
102 BitmapEx
GetColorTransformedBitmapEx() const;
104 sal_Bool
IsAlpha() const;
105 AlphaMask
GetAlpha() const;
107 const Size
& GetSizePixel() const { return aBitmapSize
; }
108 void SetSizePixel( const Size
& rNewSize
, sal_uInt32 nScaleFlag
= BMP_SCALE_DEFAULT
);
110 const Size
& GetPrefSize() const { return aBitmap
.GetPrefSize(); }
111 void SetPrefSize( const Size
& rPrefSize
) { aBitmap
.SetPrefSize( rPrefSize
); }
113 const MapMode
& GetPrefMapMode() const { return aBitmap
.GetPrefMapMode(); }
114 void SetPrefMapMode( const MapMode
& rPrefMapMode
) { aBitmap
.SetPrefMapMode( rPrefMapMode
); }
116 const Color
& GetTransparentColor() const { return aTransparentColor
; }
117 void SetTransparentColor( const Color
& rColor
) { aTransparentColor
= rColor
; }
119 sal_uInt16
GetBitCount() const { return aBitmap
.GetBitCount(); }
120 sal_uLong
GetSizeBytes() const;
121 sal_uLong
GetChecksum() const;
125 /** Convert bitmap format
128 The format this bitmap should be converted to.
130 @return sal_True, if the conversion was completed successfully.
132 sal_Bool
Convert( BmpConversion eConversion
);
134 /** Reduce number of colors for the bitmap
136 @param nNewColorCount
137 Maximal number of bitmap colors after the reduce operation
140 Algorithm to use for color reduction
142 @return sal_True, if the color reduction operation was completed successfully.
144 sal_Bool
ReduceColors( sal_uInt16 nNewColorCount
,
145 BmpReduce eReduce
= BMP_REDUCE_SIMPLE
);
147 /** Apply a dither algorithm to the bitmap
149 This method dithers the bitmap inplace, i.e. a true color
150 bitmap is converted to a paletted bitmap, reducing the color
151 deviation by error diffusion.
154 The algorithm to be used for dithering
156 sal_Bool
Dither( sal_uLong nDitherFlags
= BMP_DITHER_MATRIX
);
161 A rectangle specifying the crop amounts on all four sides of
162 the bitmap. If the upper left corner of the bitmap is assigned
163 (0,0), then this method cuts out the given rectangle from the
164 bitmap. Note that the rectangle is clipped to the bitmap's
165 dimension, i.e. negative left,top rectangle coordinates or
166 exceeding width or height is ignored.
168 @return sal_True, if cropping was performed successfully. If
169 nothing had to be cropped, because e.g. the crop rectangle
170 included the bitmap, sal_False is returned, too!
172 sal_Bool
Crop( const Rectangle
& rRectPixel
);
174 /** Expand the bitmap by pixel padding
177 Number of pixel to pad at the right border of the bitmap
180 Number of scanlines to pad at the bottom border of the bitmap
183 Color to use for padded pixel
185 @return sal_True, if padding was performed successfully. sal_False is
186 not only returned when the operation failed, but also if
187 nothing had to be done, e.g. because nDX and nDY were zero.
189 sal_Bool
Expand( sal_uLong nDX
, sal_uLong nDY
,
190 const Color
* pInitColor
= NULL
,
191 sal_Bool bExpandTransparent
= sal_False
);
193 /** Copy a rectangular area from another bitmap
196 Destination rectangle in this bitmap. This is clipped to the
200 Source rectangle in pBmpSrc. This is clipped to the source
201 bitmap dimensions. Note further that no scaling takes place
202 during this copy operation, i.e. only the minimum of source
203 and destination rectangle's width and height are used.
206 The source bitmap to copy from. If this argument is NULL, or
207 equal to the object this method is called on, copying takes
208 place within the same bitmap.
210 @return sal_True, if the operation completed successfully. sal_False
211 is not only returned when the operation failed, but also if
212 nothing had to be done, e.g. because one of the rectangles are
215 sal_Bool
CopyPixel( const Rectangle
& rRectDst
,
216 const Rectangle
& rRectSrc
,
217 const BitmapEx
* pBmpExSrc
= NULL
);
219 /** Fill the entire bitmap with the given color
222 Color value to use for filling. Set the transparency part of
223 the color to fill the mask.
225 @return sal_True, if the operation was completed successfully.
227 sal_Bool
Erase( const Color
& rFillColor
);
229 /** Perform the Invert operation on every pixel
231 @return sal_True, if the operation was completed successfully.
235 /** Mirror the bitmap
238 About which axis (horizontal, vertical, or both) to mirror
240 @return sal_True, if the operation was completed successfully.
242 sal_Bool
Mirror( sal_uLong nMirrorFlags
);
247 The resulting size of the scaled bitmap
250 The algorithm to be used for scaling
252 @return sal_True, if the operation was completed successfully.
254 sal_Bool
Scale( const Size
& rNewSize
, sal_uInt32 nScaleFlag
= BMP_SCALE_DEFAULT
);
259 The scale factor in x direction.
262 The scale factor in y direction.
264 @return sal_True, if the operation was completed successfully.
266 sal_Bool
Scale( const double& rScaleX
, const double& rScaleY
, sal_uInt32 nScaleFlag
= BMP_SCALE_DEFAULT
);
268 /** Rotate bitmap by the specified angle
271 The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
274 The color to use for filling blank areas. During rotation, the
275 bitmap is enlarged such that the whole rotation result fits
276 in. The empty spaces around that rotated original bitmap are
277 then filled with this color.
279 @return sal_True, if the operation was completed successfully.
281 sal_Bool
Rotate( long nAngle10
, const Color
& rFillColor
);
283 /** Replace all pixel having the search color with the specified color
286 Color specifying which pixel should be replaced
289 Color to be placed in all changed pixel
292 Tolerance value. Specifies the maximal difference between
293 rSearchColor and the individual pixel values, such that the
294 corresponding pixel is still regarded a match.
296 @return sal_True, if the operation was completed successfully.
298 sal_Bool
Replace( const Color
& rSearchColor
, const Color
& rReplaceColor
, sal_uLong nTol
= 0 );
300 /** Replace all pixel having one the search colors with the corresponding replace color
303 Array of colors specifying which pixel should be replaced
306 Array of colors to be placed in all changed pixel
309 Size of the aforementioned color arrays
312 Tolerance value. Specifies the maximal difference between
313 pSearchColor colors and the individual pixel values, such that
314 the corresponding pixel is still regarded a match.
316 @return sal_True, if the operation was completed successfully.
318 sal_Bool
Replace( const Color
* pSearchColors
, const Color
* pReplaceColors
,
319 sal_uLong nColorCount
, const sal_uLong
* pTols
= NULL
);
321 /** Change various global color characteristics
323 @param nLuminancePercent
324 Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
326 @param nContrastPercent
327 Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
329 @param nChannelRPercent
330 Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
332 @param nChannelGPercent
333 Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
335 @param nChannelBPercent
336 Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
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.
344 If sal_True, invert the channel values with the logical 'not' operator
346 @return sal_True, if the operation was completed successfully.
348 sal_Bool
Adjust( short nLuminancePercent
= 0,
349 short nContrastPercent
= 0,
350 short nChannelRPercent
= 0,
351 short nChannelGPercent
= 0,
352 short nChannelBPercent
= 0,
354 sal_Bool bInvert
= sal_False
);
356 /** Apply specified filter to the bitmap
359 The filter algorithm to apply
362 Various parameter for the different bitmap filter algorithms
365 A callback for showing the progress of the vectorization
367 @return sal_True, if the operation was completed successfully.
369 sal_Bool
Filter( BmpFilter eFilter
,
370 const BmpFilterParam
* pFilterParam
= NULL
,
371 const Link
* pProgress
= NULL
);
373 /** Get transparency at given position
376 integer X-Position in Bitmap
379 integer Y-Position in Bitmap
381 @return transparency value in the range of [0 .. 255] where
382 0 is not transparent, 255 is fully transparent
384 sal_uInt8
GetTransparency(sal_Int32 nX
, sal_Int32 nY
) const;
388 friend VCL_DLLPUBLIC SvStream
& operator<<( SvStream
& rOStm
, const BitmapEx
& rBitmapEx
);
389 friend VCL_DLLPUBLIC SvStream
& operator>>( SvStream
& rIStm
, BitmapEx
& rBitmapEx
);
390 static BitmapEx
AutoScaleBitmap(BitmapEx
& aBitmap
, const long aStandardSize
);
392 /// populate from a canvas implementation
393 bool Create( const ::com::sun::star::uno::Reference
<
394 ::com::sun::star::rendering::XBitmapCanvas
> &xBitmapCanvas
,
398 // ------------------------------------------------------------------
399 /** Create a blend frame as BitmapEx
402 The blend value defines how strong the frame will be blended with the
403 existing content, 255 == full coverage, 0 == no frame will be drawn
405 @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft
406 The colors defining the frame. If the version without aColorTopRight and
407 aColorBottomLeft is used, these colors are linearly interpolated from
408 aColorTopLeft and aColorBottomRight using the width and height of the area
411 The size of the frame in pixels
414 BitmapEx VCL_DLLPUBLIC
createBlendFrame(
418 Color aColorBottomRight
);
420 BitmapEx VCL_DLLPUBLIC
createBlendFrame(
424 Color aColorTopRight
,
425 Color aColorBottomRight
,
426 Color aColorBottomLeft
);
428 // ------------------------------------------------------------------
430 #endif // _SV_BITMAPEX_HXX
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */