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 INCLUDED_VCL_BITMAPEX_HXX
21 #define INCLUDED_VCL_BITMAPEX_HXX
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>
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <sal/types.h>
32 namespace com
{ namespace sun
{ namespace star
{ namespace rendering
{
43 class VCL_DLLPUBLIC BitmapEx
48 BitmapEx( const ResId
& rResId
);
49 BitmapEx( const OUString
& rIconName
);
50 BitmapEx( const BitmapEx
& rBitmapEx
);
51 BitmapEx( const BitmapEx
& rBitmapEx
, Point aSrc
, Size aSize
);
52 BitmapEx( const Bitmap
& rBmp
);
53 BitmapEx( const Bitmap
& rBmp
, const Bitmap
& rMask
);
54 BitmapEx( const Bitmap
& rBmp
, const AlphaMask
& rAlphaMask
);
55 BitmapEx( const Bitmap
& rBmp
, const Color
& rTransparentColor
);
58 BitmapEx
& operator=( const BitmapEx
& rBitmapEx
);
59 bool operator==( const BitmapEx
& rBitmapEx
) const;
60 bool operator!=( const BitmapEx
& rBitmapEx
) const { return !(*this==rBitmapEx
); }
61 bool operator!() const { return !aBitmap
; }
63 bool IsEqual( const BitmapEx
& rBmpEx
) const;
69 void Draw( OutputDevice
* pOutDev
,
70 const Point
& rDestPt
) const;
71 void Draw( OutputDevice
* pOutDev
,
72 const Point
& rDestPt
, const Size
& rDestSize
) const;
74 bool IsTransparent() const;
75 TransparentType
GetTransparentType() const { return eTransparent
; }
77 Bitmap
GetBitmap( const Color
* pTransReplaceColor
= NULL
) const;
78 Bitmap
GetMask() const;
80 BitmapEx
GetColorTransformedBitmapEx() const;
83 AlphaMask
GetAlpha() const;
85 const Size
& GetSizePixel() const { return aBitmapSize
; }
86 void SetSizePixel( const Size
& rNewSize
, BmpScaleFlag nScaleFlag
= BmpScaleFlag::Default
);
88 const Size
& GetPrefSize() const { return aBitmap
.GetPrefSize(); }
89 void SetPrefSize( const Size
& rPrefSize
) { aBitmap
.SetPrefSize( rPrefSize
); }
91 const MapMode
& GetPrefMapMode() const { return aBitmap
.GetPrefMapMode(); }
92 void SetPrefMapMode( const MapMode
& rPrefMapMode
) { aBitmap
.SetPrefMapMode( rPrefMapMode
); }
94 const Color
& GetTransparentColor() const { return aTransparentColor
; }
95 void SetTransparentColor( const Color
& rColor
) { aTransparentColor
= rColor
; }
97 sal_uInt16
GetBitCount() const { return aBitmap
.GetBitCount(); }
98 sal_uLong
GetSizeBytes() const;
99 BitmapChecksum
GetChecksum() const;
103 /** Convert bitmap format
106 The format this bitmap should be converted to.
108 @return true, if the conversion was completed successfully.
110 bool Convert( BmpConversion eConversion
);
112 /** Reduce number of colors for the bitmap
114 @param nNewColorCount
115 Maximal number of bitmap colors after the reduce operation
118 Algorithm to use for color reduction
120 @return true, if the color reduction operation was completed successfully.
123 sal_uInt16 nNewColorCount
,
124 BmpReduce eReduce
= BMP_REDUCE_SIMPLE
);
126 /** Apply a dither algorithm to the bitmap
128 This method dithers the bitmap inplace, i.e. a true color
129 bitmap is converted to a paletted bitmap, reducing the color
130 deviation by error diffusion.
133 The algorithm to be used for dithering
135 bool Dither( BmpDitherFlags nDitherFlags
= BmpDitherFlags::Matrix
);
140 A rectangle specifying the crop amounts on all four sides of
141 the bitmap. If the upper left corner of the bitmap is assigned
142 (0,0), then this method cuts out the given rectangle from the
143 bitmap. Note that the rectangle is clipped to the bitmap's
144 dimension, i.e. negative left,top rectangle coordinates or
145 exceeding width or height is ignored.
147 @return true, if cropping was performed successfully. If
148 nothing had to be cropped, because e.g. the crop rectangle
149 included the bitmap, false is returned, too!
151 bool Crop( const Rectangle
& rRectPixel
);
153 /** Expand the bitmap by pixel padding
156 Number of pixel to pad at the right border of the bitmap
159 Number of scanlines to pad at the bottom border of the bitmap
162 Color to use for padded pixel
164 @param bExpandTransparent
165 Whether to expand the transparency color or not.
167 @return true, if padding was performed successfully. false is
168 not only returned when the operation failed, but also if
169 nothing had to be done, e.g. because nDX and nDY were zero.
172 sal_uLong nDX
, sal_uLong nDY
,
173 const Color
* pInitColor
= NULL
,
174 bool bExpandTransparent
= false );
176 /** Copy a rectangular area from another bitmap
179 Destination rectangle in this bitmap. This is clipped to the
183 Source rectangle in pBmpSrc. This is clipped to the source
184 bitmap dimensions. Note further that no scaling takes place
185 during this copy operation, i.e. only the minimum of source
186 and destination rectangle's width and height are used.
189 The source bitmap to copy from. If this argument is NULL, or
190 equal to the object this method is called on, copying takes
191 place within the same bitmap.
193 @return true, if the operation completed successfully. false
194 is not only returned when the operation failed, but also if
195 nothing had to be done, e.g. because one of the rectangles are
199 const Rectangle
& rRectDst
,
200 const Rectangle
& rRectSrc
,
201 const BitmapEx
* pBmpExSrc
= NULL
);
203 /** Fill the entire bitmap with the given color
206 Color value to use for filling. Set the transparency part of
207 the color to fill the mask.
209 @return true, if the operation was completed successfully.
211 bool Erase( const Color
& rFillColor
);
213 /** Perform the Invert operation on every pixel
215 @return true, if the operation was completed successfully.
219 /** Mirror the bitmap
222 About which axis (horizontal, vertical, or both) to mirror
224 @return true, if the operation was completed successfully.
226 bool Mirror( BmpMirrorFlags nMirrorFlags
);
231 The resulting size of the scaled bitmap
234 The algorithm to be used for scaling
236 @return true, if the operation was completed successfully.
239 const Size
& rNewSize
,
240 BmpScaleFlag nScaleFlag
= BmpScaleFlag::Default
);
245 The scale factor in x direction.
248 The scale factor in y direction.
251 The algorithm to be used for scaling
253 @return true, if the operation was completed successfully.
256 const double& rScaleX
,
257 const double& rScaleY
,
258 BmpScaleFlag nScaleFlag
= BmpScaleFlag::Default
);
260 /** Rotate bitmap by the specified angle
263 The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
266 The color to use for filling blank areas. During rotation, the
267 bitmap is enlarged such that the whole rotation result fits
268 in. The empty spaces around that rotated original bitmap are
269 then filled with this color.
271 @return true, if the operation was completed successfully.
275 const Color
& rFillColor
);
277 /** Replace all pixel having the search color with the specified color
280 Color specifying which pixel should be replaced
283 Color to be placed in all changed pixel
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.
290 @return true, if the operation was completed successfully.
293 const Color
& rSearchColor
,
294 const Color
& rReplaceColor
,
295 sal_uLong nTol
= 0 );
297 /** Replace all pixel having one the search colors with the corresponding replace color
300 Array of colors specifying which pixel should be replaced
302 @param pReplaceColors
303 Array of colors to be placed in all changed pixel
306 Size of the aforementioned color arrays
309 Tolerance value. Specifies the maximal difference between
310 pSearchColor colors and the individual pixel values, such that
311 the corresponding pixel is still regarded a match.
313 @return true, if the operation was completed successfully.
316 const Color
* pSearchColors
,
317 const Color
* pReplaceColors
,
318 sal_uLong nColorCount
,
319 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 true, invert the channel values with the logical 'not' operator
347 Use the same formula for brightness as used by MSOffice.
349 @return true, if the operation was completed successfully.
352 short nLuminancePercent
= 0,
353 short nContrastPercent
= 0,
354 short nChannelRPercent
= 0,
355 short nChannelGPercent
= 0,
356 short nChannelBPercent
= 0,
358 bool bInvert
= false,
359 bool msoBrightness
= false );
361 /** Apply specified filter to the bitmap
364 The filter algorithm to apply
367 Various parameter for the different bitmap filter algorithms
370 A callback for showing the progress of the vectorization
372 @return true, if the operation was completed successfully.
376 const BmpFilterParam
* pFilterParam
= NULL
,
377 const Link
<>* pProgress
= NULL
);
379 /** Get transparency at given position
382 integer X-Position in Bitmap
385 integer Y-Position in Bitmap
387 @return transparency value in the range of [0 .. 255] where
388 0 is not transparent, 255 is fully transparent
390 sal_uInt8
GetTransparency(
394 /** Create transformed Bitmap
397 The target width in pixels
400 The target height in pixels
402 @param rTransformation
403 The back transformation for each pixel in (0 .. fWidth),(0 .. fHeight) to
404 local pixel coordiantes
407 Defines if pixel interpolation is to be used to create the result
409 BitmapEx
TransformBitmapEx(
412 const basegfx::B2DHomMatrix
& rTransformation
,
413 bool bSmooth
= true) const;
415 /** Create transformed Bitmap
417 @param rTransformation
418 The transformation from unit coordinates to the unit range
421 The relative visible range in unit coordinates, relative to (0,0,1,1) which
422 defines the whole target area
425 A limitation for the maximum size of pixels to use for the result
428 Defines if pixel interpolation is to be used to create the result
430 The traget size of the result bitmap is defined by transforming the given
431 rTargetRange with the given rTransformation; the area of the result is
432 linearly scaled to not exceed the given fMaximumArea
434 @return The transformed bitmap
436 BitmapEx
getTransformed(
437 const basegfx::B2DHomMatrix
& rTransformation
,
438 const basegfx::B2DRange
& rVisibleRange
,
439 double fMaximumArea
= 500000.0,
440 bool bSmooth
= true) const;
442 /** Create ColorStack-modified version of this BitmapEx
444 @param rBColorModifierStack
445 A ColrModifierStack which defines how each pixel has to be modified
447 BitmapEx
ModifyBitmapEx( const basegfx::BColorModifierStack
& rBColorModifierStack
) const;
449 static BitmapEx
AutoScaleBitmap( BitmapEx
& aBitmap
, const long aStandardSize
);
451 /// populate from a canvas implementation
453 const css::uno::Reference
< css::rendering::XBitmapCanvas
> &xBitmapCanvas
,
457 SAL_DLLPRIVATE ImpBitmap
* ImplGetBitmapImpBitmap() const { return aBitmap
.ImplGetImpBitmap(); }
458 SAL_DLLPRIVATE ImpBitmap
* ImplGetMaskImpBitmap() const { return aMask
.ImplGetImpBitmap(); }
462 friend class ImpGraphic
;
463 friend bool VCL_DLLPUBLIC
WriteDIBBitmapEx(const BitmapEx
& rSource
, SvStream
& rOStm
);
464 void loadFromIconTheme( const OUString
& rIconName
);
469 Color aTransparentColor
;
470 TransparentType eTransparent
;
476 /** Create a blend frame as BitmapEx
479 The blend value defines how strong the frame will be blended with the
480 existing content, 255 == full coverage, 0 == no frame will be drawn
482 @param aColorTopLeft, aColorBottomRight
483 The colors defining the frame. These colors are linearly interpolated from
484 aColorTopLeft and aColorBottomRight using the width and height of the area
487 The size of the frame in pixels
489 BitmapEx VCL_DLLPUBLIC
createBlendFrame(
493 Color aColorBottomRight
);
496 /** Create a blend frame as BitmapEx
499 The blend value defines how strong the frame will be blended with the
500 existing content, 255 == full coverage, 0 == no frame will be drawn
502 @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft
503 The colors defining the frame.
506 The size of the frame in pixels
508 BitmapEx VCL_DLLPUBLIC
createBlendFrame(
512 Color aColorTopRight
,
513 Color aColorBottomRight
,
514 Color aColorBottomLeft
);
516 #endif // INCLUDED_VCL_BITMAPEX_HXX
518 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */