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/alpha.hxx>
25 #include <vcl/Scanline.hxx>
26 #include <tools/color.hxx>
27 #include <tools/degree.hxx>
29 #include <sal/types.h>
31 namespace com::sun::star::rendering
{
34 namespace com::sun::star::uno
{ template <class interface_type
> class Reference
; }
35 namespace basegfx
{ class BColorModifierStack
; }
37 class SAL_WARN_UNUSED VCL_DLLPUBLIC BitmapEx
42 explicit BitmapEx( const OUString
& rIconName
);
43 BitmapEx( const BitmapEx
& rBitmapEx
);
44 BitmapEx( const BitmapEx
& rBitmapEx
, Point aSrc
, Size aSize
);
45 BitmapEx(Size aSize
, vcl::PixelFormat ePixelFormat
);
46 explicit BitmapEx( const Bitmap
& rBmp
);
47 BitmapEx( const Bitmap
& rBmp
, const Bitmap
& rMask
);
48 BitmapEx( const Bitmap
& rBmp
, const AlphaMask
& rAlphaMask
);
49 BitmapEx( const Bitmap
& rBmp
, const Color
& rTransparentColor
);
51 BitmapEx
& operator=( const BitmapEx
& rBitmapEx
);
52 BitmapEx
& operator=( const Bitmap
& rBitmap
) { return operator=(BitmapEx(rBitmap
)); }
53 bool operator==( const BitmapEx
& rBitmapEx
) const;
54 bool operator!=( const BitmapEx
& rBitmapEx
) const { return !(*this==rBitmapEx
); }
61 void Draw( OutputDevice
* pOutDev
,
62 const Point
& rDestPt
) const;
63 void Draw( OutputDevice
* pOutDev
,
64 const Point
& rDestPt
, const Size
& rDestSize
) const;
66 Bitmap
GetBitmap( Color aTransparentReplaceColor
) const;
67 /// Gives direct access to the contained bitmap.
68 const Bitmap
& GetBitmap() const;
71 const AlphaMask
& GetAlphaMask() const { return maAlphaMask
; }
73 const Size
& GetSizePixel() const { return maBitmapSize
; }
74 void SetSizePixel(const Size
& rNewSize
);
76 const Size
& GetPrefSize() const { return maBitmap
.GetPrefSize(); }
77 void SetPrefSize( const Size
& rPrefSize
) { maBitmap
.SetPrefSize( rPrefSize
); }
79 const MapMode
& GetPrefMapMode() const { return maBitmap
.GetPrefMapMode(); }
80 void SetPrefMapMode( const MapMode
& rPrefMapMode
) { maBitmap
.SetPrefMapMode( rPrefMapMode
); }
82 vcl::PixelFormat
getPixelFormat() const
84 return maBitmap
.getPixelFormat();
87 sal_Int64
GetSizeBytes() const;
88 BitmapChecksum
GetChecksum() const;
90 /** Convert bitmap format
93 The format this bitmap should be converted to.
95 @return true, if the conversion was completed successfully.
97 bool Convert( BmpConversion eConversion
);
102 A rectangle specifying the crop amounts on all four sides of
103 the bitmap. If the upper left corner of the bitmap is assigned
104 (0,0), then this method cuts out the given rectangle from the
105 bitmap. Note that the rectangle is clipped to the bitmap's
106 dimension, i.e. negative left,top rectangle coordinates or
107 exceeding width or height is ignored.
109 @return true, if cropping was performed successfully. If
110 nothing had to be cropped, because e.g. the crop rectangle
111 included the bitmap, false is returned, too!
113 bool Crop( const tools::Rectangle
& rRectPixel
);
115 /** Expand the bitmap by pixel padding
118 Number of pixel to pad at the right border of the bitmap
121 Number of scanlines to pad at the bottom border of the bitmap
123 @param bExpandTransparent
124 Whether to expand the transparency color or not.
127 sal_Int32 nDX
, sal_Int32 nDY
,
128 bool bExpandTransparent
= false );
130 /** Copy a rectangular area from another bitmap
133 Destination rectangle in this bitmap. This is clipped to the
137 Source rectangle in pBmpSrc. This is clipped to the source
138 bitmap dimensions. Note further that no scaling takes place
139 during this copy operation, i.e. only the minimum of source
140 and destination rectangle's width and height are used.
143 The source bitmap to copy from.
145 @return true, if the operation completed successfully. false
146 is not only returned when the operation failed, but also if
147 nothing had to be done, e.g. because one of the rectangles are
151 const tools::Rectangle
& rRectDst
,
152 const tools::Rectangle
& rRectSrc
,
153 const BitmapEx
& rBmpExSrc
);
155 /** Copy a rectangular area from one part of the bitmap to another.
158 Destination rectangle in this bitmap. This is clipped to the
162 Source rectangle in this bitmap. This is clipped to the
163 bitmap dimensions. Note further that no scaling takes place
164 during this copy operation, i.e. only the minimum of source
165 and destination rectangle's width and height are used.
167 @return true, if the operation completed successfully. false
168 is not only returned when the operation failed, but also if
169 nothing had to be done, e.g. because one of the rectangles are
173 const tools::Rectangle
& rRectDst
,
174 const tools::Rectangle
& rRectSrc
);
176 /** Fill the entire bitmap with the given color
179 Color value to use for filling. Set the transparency part of
180 the color to fill the mask.
182 @return true, if the operation was completed successfully.
184 bool Erase( const Color
& rFillColor
);
186 /** Perform the Invert operation on every pixel
188 @return true, if the operation was completed successfully.
192 /** Mirror the bitmap
195 About which axis (horizontal, vertical, or both) to mirror
197 @return true, if the operation was completed successfully.
199 bool Mirror( BmpMirrorFlags nMirrorFlags
);
204 The resulting size of the scaled bitmap
207 The algorithm to be used for scaling
209 @return true, if the operation was completed successfully.
212 const Size
& rNewSize
,
213 BmpScaleFlag nScaleFlag
= BmpScaleFlag::Default
);
218 The scale factor in x direction.
221 The scale factor in y direction.
224 The algorithm to be used for scaling
226 @return true, if the operation was completed successfully.
229 const double& rScaleX
,
230 const double& rScaleY
,
231 BmpScaleFlag nScaleFlag
= BmpScaleFlag::Default
);
233 /** Rotate bitmap by the specified angle
236 The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
239 The color to use for filling blank areas. During rotation, the
240 bitmap is enlarged such that the whole rotation result fits
241 in. The empty spaces around that rotated original bitmap are
242 then filled with this color.
244 @return true, if the operation was completed successfully.
248 const Color
& rFillColor
);
250 /** Replace all pixel having the search color with the specified color
253 Color specifying which pixel should be replaced
256 Color to be placed in all changed pixel
259 const Color
& rSearchColor
,
260 const Color
& rReplaceColor
);
262 /** Replace all pixel having the search color with the specified color
265 Color specifying which pixel should be replaced
268 Color to be placed in all changed pixel
271 Tolerance value. Specifies the maximal difference between
272 rSearchColor and the individual pixel values, such that the
273 corresponding pixel is still regarded a match.
276 const Color
& rSearchColor
,
277 const Color
& rReplaceColor
,
278 sal_uInt8 nTolerance
);
280 /** Replace all pixel having one the search colors with the corresponding replace color
283 Array of colors specifying which pixel should be replaced
285 @param pReplaceColors
286 Array of colors to be placed in all changed pixel
289 Size of the aforementioned color arrays
292 Tolerance value. Specifies the maximal difference between
293 pSearchColor colors and the individual pixel values, such that
294 the corresponding pixel is still regarded a match.
297 const Color
* pSearchColors
,
298 const Color
* pReplaceColors
,
299 size_t nColorCount
);
301 /** Replace all pixel having one the search colors with the corresponding replace color
304 Array of colors specifying which pixel should be replaced
306 @param rReplaceColors
307 Array of colors to be placed in all changed pixel
310 Size of the aforementioned color arrays
313 Tolerance value. Specifies the maximal difference between
314 pSearchColor colors and the individual pixel values, such that
315 the corresponding pixel is still regarded a match.
317 @return true, if the operation was completed successfully.
320 const Color
* pSearchColors
,
321 const Color
* pReplaceColors
,
323 sal_uInt8
const * pTols
);
325 /** Replace transparency with given color.
327 void ReplaceTransparency( const Color
& rColor
);
329 /** Get contours in image */
330 tools::Polygon
GetContour( bool bContourEdgeDetect
, const tools::Rectangle
* pWorkRect
);
332 /** Change various global color characteristics
334 @param nLuminancePercent
335 Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
337 @param nContrastPercent
338 Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
340 @param nChannelRPercent
341 Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
343 @param nChannelGPercent
344 Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
346 @param nChannelBPercent
347 Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
350 Exponent of the gamma function applied to the bitmap. The
351 value 1.0 results in no change, the valid range is
352 (0.0,10.0]. Values outside this range are regarded as 1.0.
355 If true, invert the channel values with the logical 'not' operator
358 Use the same formula for brightness as used by MSOffice.
360 @return true, if the operation was completed successfully.
363 short nLuminancePercent
,
364 short nContrastPercent
,
365 short nChannelRPercent
,
366 short nChannelGPercent
,
367 short nChannelBPercent
,
369 bool bInvert
= false,
370 bool msoBrightness
= false );
372 /** Get alpha at given position
375 integer X-Position in Bitmap
378 integer Y-Position in Bitmap
380 @return alpha value in the range of [0 .. 255] where
381 0 is fully transparent, 255 is not transparent
387 /** Get pixel color (including alpha) at given position
390 integer X-Position in Bitmap
393 integer Y-Position in Bitmap
395 ::Color
GetPixelColor(
399 /** Create transformed Bitmap
402 The target width in pixels
405 The target height in pixels
407 @param rTransformation
408 The back transformation for each pixel in (0 .. fWidth),(0 .. fHeight) to
409 local pixel coordinates
412 BitmapEx
TransformBitmapEx(
415 const basegfx::B2DHomMatrix
& rTransformation
) const;
417 /** Create transformed Bitmap
419 @param rTransformation
420 The transformation from unit coordinates to the unit range
423 The relative visible range in unit coordinates, relative to (0,0,1,1) which
424 defines the whole target area
427 A limitation for the maximum size of pixels to use for the result
429 The target 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
433 @return The transformed bitmap
436 BitmapEx
getTransformed(
437 const basegfx::B2DHomMatrix
& rTransformation
,
438 const basegfx::B2DRange
& rVisibleRange
,
439 double fMaximumArea
) const;
441 /** Create ColorStack-modified version of this BitmapEx
443 @param rBColorModifierStack
444 A ColrModifierStack which defines how each pixel has to be modified
447 BitmapEx
ModifyBitmapEx( const basegfx::BColorModifierStack
& rBColorModifierStack
) const;
450 static BitmapEx
AutoScaleBitmap( BitmapEx
const & aBitmap
, const tools::Long aStandardSize
);
452 /// populate from a canvas implementation
454 const css::uno::Reference
< css::rendering::XBitmapCanvas
> &xBitmapCanvas
,
457 void ChangeColorAlpha( sal_uInt8 cIndexFrom
, sal_Int8 nAlphaTo
);
459 void AdjustTransparency( sal_uInt8 cTrans
);
461 void CombineMaskOr(Color maskColor
, sal_uInt8 nTol
);
464 * Retrieves the color model data we need for the XImageConsumer stuff.
466 void GetColorModel(css::uno::Sequence
< sal_Int32
>& rRGBPalette
,
467 sal_uInt32
& rnRedMask
, sal_uInt32
& rnGreenMask
, sal_uInt32
& rnBlueMask
, sal_uInt32
& rnAlphaMask
, sal_uInt32
& rnTransparencyIndex
,
468 sal_uInt32
& rnWidth
, sal_uInt32
& rnHeight
, sal_uInt8
& rnBitCount
);
470 SAL_DLLPRIVATE
std::shared_ptr
<SalBitmap
> const & ImplGetBitmapSalBitmap() const { return maBitmap
.ImplGetSalBitmap(); }
472 /// Dumps the pixels as PNG in bitmap.png.
473 void DumpAsPng(const char* pFileName
= nullptr) const;
476 friend class ImpGraphic
;
477 friend class OutputDevice
;
478 friend bool VCL_DLLPUBLIC
WriteDIBBitmapEx(const BitmapEx
& rSource
, SvStream
& rOStm
);
479 friend bool VCL_DLLPUBLIC
ReadRawDIB(BitmapEx
& rTarget
, const unsigned char* pBuf
,
480 const ScanlineFormat nFormat
,
484 void loadFromIconTheme( const OUString
& rIconName
);
487 AlphaMask maAlphaMask
;
492 /** Create a blend frame as BitmapEx
495 The blend value defines how strong the frame will be blended with the
496 existing content, 255 == full coverage, 0 == no frame will be drawn
498 @param aColorTopLeft, aColorBottomRight
499 The colors defining the frame. These colors are linearly interpolated from
500 aColorTopLeft and aColorBottomRight using the width and height of the area
503 The size of the frame in pixels
505 BitmapEx VCL_DLLPUBLIC
createBlendFrame(
509 Color aColorBottomRight
);
512 /** Create a blend frame as BitmapEx
515 The blend value defines how strong the frame will be blended with the
516 existing content, 255 == full coverage, 0 == no frame will be drawn
518 @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft
519 The colors defining the frame.
522 The size of the frame in pixels
524 BitmapEx
createBlendFrame(
528 Color aColorTopRight
,
529 Color aColorBottomRight
,
530 Color aColorBottomLeft
);
532 #endif // INCLUDED_VCL_BITMAPEX_HXX
534 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */