vcl: 'horizontically'
[LibreOffice.git] / include / vcl / bitmapex.hxx
blob14bbee5354853a06286aceafe845e51f1df5d39f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 {
32 class XBitmapCanvas;
34 namespace com::sun::star::uno { template <class interface_type> class Reference; }
35 namespace basegfx { class BColorModifierStack; }
37 enum class TransparentType
39 NONE,
40 Color,
41 Bitmap
44 class SAL_WARN_UNUSED VCL_DLLPUBLIC BitmapEx
46 public:
48 BitmapEx();
49 explicit BitmapEx( const OUString& rIconName );
50 BitmapEx( const BitmapEx& rBitmapEx );
51 BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize );
52 BitmapEx( Size aSize, sal_uInt16 nBitCount );
53 explicit BitmapEx( const Bitmap& rBmp );
54 BitmapEx( const Bitmap& rBmp, const Bitmap& rMask );
55 BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask );
56 BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor );
58 BitmapEx& operator=( const BitmapEx& rBitmapEx );
59 BitmapEx& operator=( const Bitmap& rBitmap ) { return operator=(BitmapEx(rBitmap)); }
60 bool operator==( const BitmapEx& rBitmapEx ) const;
61 bool operator!=( const BitmapEx& rBitmapEx ) const { return !(*this==rBitmapEx); }
62 bool operator!() const { return !maBitmap; }
64 bool IsEmpty() const;
65 void SetEmpty();
66 void Clear();
68 void Draw( OutputDevice* pOutDev,
69 const Point& rDestPt ) const;
70 void Draw( OutputDevice* pOutDev,
71 const Point& rDestPt, const Size& rDestSize ) const;
73 bool IsTransparent() const;
74 TransparentType GetTransparentType() const { return meTransparent; }
76 Bitmap GetBitmap( Color aTransparentReplaceColor ) const;
77 /// Gives direct access to the contained bitmap.
78 const Bitmap& GetBitmap() const;
79 Bitmap GetMask() const;
81 bool IsAlpha() const;
82 AlphaMask GetAlpha() const;
84 const Size& GetSizePixel() const { return maBitmapSize; }
85 void SetSizePixel(const Size& rNewSize);
87 const Size& GetPrefSize() const { return maBitmap.GetPrefSize(); }
88 void SetPrefSize( const Size& rPrefSize ) { maBitmap.SetPrefSize( rPrefSize ); }
90 const MapMode& GetPrefMapMode() const { return maBitmap.GetPrefMapMode(); }
91 void SetPrefMapMode( const MapMode& rPrefMapMode ) { maBitmap.SetPrefMapMode( rPrefMapMode ); }
93 const Color& GetTransparentColor() const { return maTransparentColor; }
95 sal_uInt16 GetBitCount() const { return maBitmap.GetBitCount(); }
96 sal_uLong GetSizeBytes() const;
97 BitmapChecksum GetChecksum() const;
99 /** Convert bitmap format
101 @param eConversion
102 The format this bitmap should be converted to.
104 @return true, if the conversion was completed successfully.
106 bool Convert( BmpConversion eConversion );
108 /** Crop the bitmap
110 @param rRectPixel
111 A rectangle specifying the crop amounts on all four sides of
112 the bitmap. If the upper left corner of the bitmap is assigned
113 (0,0), then this method cuts out the given rectangle from the
114 bitmap. Note that the rectangle is clipped to the bitmap's
115 dimension, i.e. negative left,top rectangle coordinates or
116 exceeding width or height is ignored.
118 @return true, if cropping was performed successfully. If
119 nothing had to be cropped, because e.g. the crop rectangle
120 included the bitmap, false is returned, too!
122 bool Crop( const tools::Rectangle& rRectPixel );
124 /** Expand the bitmap by pixel padding
126 @param nDX
127 Number of pixel to pad at the right border of the bitmap
129 @param nDY
130 Number of scanlines to pad at the bottom border of the bitmap
132 @param bExpandTransparent
133 Whether to expand the transparency color or not.
135 void Expand(
136 sal_uLong nDX, sal_uLong nDY,
137 bool bExpandTransparent = false );
139 /** Copy a rectangular area from another bitmap
141 @param rRectDst
142 Destination rectangle in this bitmap. This is clipped to the
143 bitmap dimensions.
145 @param rRectSrc
146 Source rectangle in pBmpSrc. This is clipped to the source
147 bitmap dimensions. Note further that no scaling takes place
148 during this copy operation, i.e. only the minimum of source
149 and destination rectangle's width and height are used.
151 @param pBmpExSrc
152 The source bitmap to copy from. If this argument is NULL, or
153 equal to the object this method is called on, copying takes
154 place within the same bitmap.
156 @return true, if the operation completed successfully. false
157 is not only returned when the operation failed, but also if
158 nothing had to be done, e.g. because one of the rectangles are
159 empty.
161 bool CopyPixel(
162 const tools::Rectangle& rRectDst,
163 const tools::Rectangle& rRectSrc,
164 const BitmapEx* pBmpExSrc );
166 /** Fill the entire bitmap with the given color
168 @param rFillColor
169 Color value to use for filling. Set the transparency part of
170 the color to fill the mask.
172 @return true, if the operation was completed successfully.
174 bool Erase( const Color& rFillColor );
176 /** Perform the Invert operation on every pixel
178 @return true, if the operation was completed successfully.
180 bool Invert();
182 /** Mirror the bitmap
184 @param nMirrorFlags
185 About which axis (horizontal, vertical, or both) to mirror
187 @return true, if the operation was completed successfully.
189 bool Mirror( BmpMirrorFlags nMirrorFlags );
191 /** Scale the bitmap
193 @param rNewSize
194 The resulting size of the scaled bitmap
196 @param nScaleFlag
197 The algorithm to be used for scaling
199 @return true, if the operation was completed successfully.
201 bool Scale(
202 const Size& rNewSize,
203 BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
205 /** Scale the bitmap
207 @param rScaleX
208 The scale factor in x direction.
210 @param rScaleY
211 The scale factor in y direction.
213 @param nScaleFlag
214 The algorithm to be used for scaling
216 @return true, if the operation was completed successfully.
218 bool Scale(
219 const double& rScaleX,
220 const double& rScaleY,
221 BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
223 /** Rotate bitmap by the specified angle
225 @param nAngle10
226 The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
228 @param rFillColor
229 The color to use for filling blank areas. During rotation, the
230 bitmap is enlarged such that the whole rotation result fits
231 in. The empty spaces around that rotated original bitmap are
232 then filled with this color.
234 @return true, if the operation was completed successfully.
236 bool Rotate(
237 Degree10 nAngle10,
238 const Color& rFillColor );
240 /** Replace all pixel having the search color with the specified color
242 @param rSearchColor
243 Color specifying which pixel should be replaced
245 @param rReplaceColor
246 Color to be placed in all changed pixel
248 void Replace(
249 const Color& rSearchColor,
250 const Color& rReplaceColor );
252 /** Replace all pixel having the search color with the specified color
254 @param rSearchColor
255 Color specifying which pixel should be replaced
257 @param rReplaceColor
258 Color to be placed in all changed pixel
260 @param nTolerance
261 Tolerance value. Specifies the maximal difference between
262 rSearchColor and the individual pixel values, such that the
263 corresponding pixel is still regarded a match.
265 void Replace(
266 const Color& rSearchColor,
267 const Color& rReplaceColor,
268 sal_uInt8 nTolerance );
270 /** Replace all pixel having one the search colors with the corresponding replace color
272 @param pSearchColors
273 Array of colors specifying which pixel should be replaced
275 @param pReplaceColors
276 Array of colors to be placed in all changed pixel
278 @param nColorCount
279 Size of the aforementioned color arrays
281 @param pTols
282 Tolerance value. Specifies the maximal difference between
283 pSearchColor colors and the individual pixel values, such that
284 the corresponding pixel is still regarded a match.
286 void Replace(
287 const Color* pSearchColors,
288 const Color* pReplaceColors,
289 size_t nColorCount );
291 /** Replace all pixel having one the search colors with the corresponding replace color
293 @param pSearchColors
294 Array of colors specifying which pixel should be replaced
296 @param rReplaceColors
297 Array of colors to be placed in all changed pixel
299 @param nColorCount
300 Size of the aforementioned color arrays
302 @param pTols
303 Tolerance value. Specifies the maximal difference between
304 pSearchColor colors and the individual pixel values, such that
305 the corresponding pixel is still regarded a match.
307 @return true, if the operation was completed successfully.
309 void Replace(
310 const Color* pSearchColors,
311 const Color* pReplaceColors,
312 size_t nColorCount,
313 sal_uInt8 const * pTols );
315 /** Replace transparency with given color.
317 void ReplaceTransparency( const Color& rColor );
319 /** Get contours in image */
320 tools::Polygon GetContour( bool bContourEdgeDetect, const tools::Rectangle* pWorkRect );
322 /** Change various global color characteristics
324 @param nLuminancePercent
325 Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
327 @param nContrastPercent
328 Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
330 @param nChannelRPercent
331 Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
333 @param nChannelGPercent
334 Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
336 @param nChannelBPercent
337 Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
339 @param fGamma
340 Exponent of the gamma function applied to the bitmap. The
341 value 1.0 results in no change, the valid range is
342 (0.0,10.0]. Values outside this range are regarded as 1.0.
344 @param bInvert
345 If true, invert the channel values with the logical 'not' operator
347 @param msoBrightness
348 Use the same formula for brightness as used by MSOffice.
350 @return true, if the operation was completed successfully.
352 bool Adjust(
353 short nLuminancePercent,
354 short nContrastPercent,
355 short nChannelRPercent,
356 short nChannelGPercent,
357 short nChannelBPercent,
358 double fGamma = 1.0,
359 bool bInvert = false,
360 bool msoBrightness = false );
362 /** Get transparency at given position
364 @param nX
365 integer X-Position in Bitmap
367 @param nY
368 integer Y-Position in Bitmap
370 @return transparency value in the range of [0 .. 255] where
371 0 is not transparent, 255 is fully transparent
373 sal_uInt8 GetTransparency(
374 sal_Int32 nX,
375 sal_Int32 nY) const;
377 /** Get pixel color (including alpha) at given position
379 @param nX
380 integer X-Position in Bitmap
382 @param nY
383 integer Y-Position in Bitmap
385 ::Color GetPixelColor(
386 sal_Int32 nX,
387 sal_Int32 nY) const;
389 /** Create transformed Bitmap
391 @param fWidth
392 The target width in pixels
394 @param fHeight
395 The target height in pixels
397 @param rTransformation
398 The back transformation for each pixel in (0 .. fWidth),(0 .. fHeight) to
399 local pixel coordinates
401 [[nodiscard]]
402 BitmapEx TransformBitmapEx(
403 double fWidth,
404 double fHeight,
405 const basegfx::B2DHomMatrix& rTransformation) const;
407 /** Create transformed Bitmap
409 @param rTransformation
410 The transformation from unit coordinates to the unit range
412 @param rVisibleRange
413 The relative visible range in unit coordinates, relative to (0,0,1,1) which
414 defines the whole target area
416 @param fMaximumArea
417 A limitation for the maximum size of pixels to use for the result
419 The target size of the result bitmap is defined by transforming the given
420 rTargetRange with the given rTransformation; the area of the result is
421 linearly scaled to not exceed the given fMaximumArea
423 @return The transformed bitmap
425 [[nodiscard]]
426 BitmapEx getTransformed(
427 const basegfx::B2DHomMatrix& rTransformation,
428 const basegfx::B2DRange& rVisibleRange,
429 double fMaximumArea) const;
431 /** Create ColorStack-modified version of this BitmapEx
433 @param rBColorModifierStack
434 A ColrModifierStack which defines how each pixel has to be modified
436 [[nodiscard]]
437 BitmapEx ModifyBitmapEx( const basegfx::BColorModifierStack& rBColorModifierStack) const;
439 [[nodiscard]]
440 static BitmapEx AutoScaleBitmap( BitmapEx const & aBitmap, const tools::Long aStandardSize );
442 /// populate from a canvas implementation
443 bool Create(
444 const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
445 const Size &rSize );
447 void setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo );
449 void AdjustTransparency( sal_uInt8 cTrans );
451 void CombineMaskOr(Color maskColor, sal_uInt8 nTol);
454 * Retrieves the color model data we need for the XImageConsumer stuff.
456 void GetColorModel(css::uno::Sequence< sal_Int32 >& rRGBPalette,
457 sal_uInt32& rnRedMask, sal_uInt32& rnGreenMask, sal_uInt32& rnBlueMask, sal_uInt32& rnAlphaMask, sal_uInt32& rnTransparencyIndex,
458 sal_uInt32& rnWidth, sal_uInt32& rnHeight, sal_uInt8& rnBitCount);
460 SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetBitmapSalBitmap() const { return maBitmap.ImplGetSalBitmap(); }
461 SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetMaskSalBitmap() const { return maMask.ImplGetSalBitmap(); }
464 private:
465 friend class ImpGraphic;
466 friend class OutputDevice;
467 friend bool VCL_DLLPUBLIC WriteDIBBitmapEx(const BitmapEx& rSource, SvStream& rOStm);
468 friend bool VCL_DLLPUBLIC ReadRawDIB(BitmapEx& rTarget, const unsigned char* pBuf,
469 const ScanlineFormat nFormat,
470 const int nHeight,
471 const int nStride);
473 void loadFromIconTheme( const OUString& rIconName );
475 Bitmap maBitmap;
476 Bitmap maMask;
477 Size maBitmapSize;
478 Color maTransparentColor;
479 TransparentType meTransparent;
480 bool mbAlpha;
485 /** Create a blend frame as BitmapEx
487 @param nAlpha
488 The blend value defines how strong the frame will be blended with the
489 existing content, 255 == full coverage, 0 == no frame will be drawn
491 @param aColorTopLeft, aColorBottomRight
492 The colors defining the frame. These colors are linearly interpolated from
493 aColorTopLeft and aColorBottomRight using the width and height of the area
495 @param rSize
496 The size of the frame in pixels
498 BitmapEx VCL_DLLPUBLIC createBlendFrame(
499 const Size& rSize,
500 sal_uInt8 nAlpha,
501 Color aColorTopLeft,
502 Color aColorBottomRight);
505 /** Create a blend frame as BitmapEx
507 @param nAlpha
508 The blend value defines how strong the frame will be blended with the
509 existing content, 255 == full coverage, 0 == no frame will be drawn
511 @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft
512 The colors defining the frame.
514 @param rSize
515 The size of the frame in pixels
517 BitmapEx createBlendFrame(
518 const Size& rSize,
519 sal_uInt8 nAlpha,
520 Color aColorTopLeft,
521 Color aColorTopRight,
522 Color aColorBottomRight,
523 Color aColorBottomLeft);
525 #endif // INCLUDED_VCL_BITMAPEX_HXX
527 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */