/src/libreoffice/include/vcl/bitmap.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <sal/config.h> |
23 | | |
24 | | #include <basegfx/numeric/ftools.hxx> |
25 | | #include <rtl/ustring.hxx> |
26 | | #include <tools/degree.hxx> |
27 | | #include <tools/gen.hxx> |
28 | | #include <vcl/checksum.hxx> |
29 | | #include <vcl/dllapi.h> |
30 | | #include <vcl/mapmod.hxx> |
31 | | #include <vcl/bitmap/BitmapTypes.hxx> |
32 | | #include <config_vclplug.h> |
33 | | |
34 | | #include <o3tl/typed_flags_set.hxx> |
35 | | |
36 | | #include <memory> |
37 | | |
38 | | class AlphaMask; |
39 | | namespace basegfx { class BColorModifierStack; } |
40 | | namespace com::sun::star::rendering { |
41 | | class XBitmapCanvas; |
42 | | } |
43 | | namespace com::sun::star::uno { template <class interface_type> class Reference; } |
44 | | namespace com::sun::star::uno { template <typename> class Sequence; } |
45 | | namespace basegfx { class B2DHomMatrix; } |
46 | | namespace basegfx { class B2DRange; } |
47 | | namespace tools { class Polygon; } |
48 | | namespace vcl { class Region; } |
49 | | |
50 | | inline sal_uInt8 GAMMA(double _def_cVal, double _def_InvGamma) |
51 | 0 | { |
52 | 0 | return basegfx::fround<sal_uInt8>(pow(_def_cVal / 255.0, _def_InvGamma) * 255.0); |
53 | 0 | } |
54 | | |
55 | | class Color; |
56 | | |
57 | | enum class BmpMirrorFlags |
58 | | { |
59 | | NONE = 0x00, |
60 | | Horizontal = 0x01, |
61 | | Vertical = 0x02, |
62 | | }; |
63 | | |
64 | | namespace o3tl |
65 | | { |
66 | | template<> struct typed_flags<BmpMirrorFlags> : is_typed_flags<BmpMirrorFlags, 0x03> {}; |
67 | | } |
68 | | |
69 | | enum class BmpScaleFlag |
70 | | { |
71 | | // Try to preferably use these. |
72 | | Default, |
73 | | Fast, |
74 | | BestQuality, |
75 | | // Specific algorithms, use only if you really need to (mainly used for tests) |
76 | | NearestNeighbor, |
77 | | Interpolate, // fast, integer bilinear |
78 | | Lanczos, |
79 | | BiCubic, |
80 | | BiLinear |
81 | | }; |
82 | | |
83 | 0 | #define BMP_COL_TRANS Color( 252, 3, 251 ) |
84 | | |
85 | | enum class BmpConversion |
86 | | { |
87 | | NNONE, |
88 | | N1BitThreshold, |
89 | | N8BitGreys, |
90 | | N8BitColors, |
91 | | N24Bit, |
92 | | N32Bit, |
93 | | N8BitTrans, |
94 | | N8BitNoConversion // make 8bit without color conversion (e.g. take the red channel) |
95 | | }; |
96 | | |
97 | | class BitmapPalette; |
98 | | class AlphaMask; |
99 | | class OutputDevice; |
100 | | class SalBitmap; |
101 | | |
102 | | namespace basegfx { class SystemDependentDataHolder; } |
103 | | |
104 | | struct BitmapSystemData |
105 | | { |
106 | | #if defined(_WIN32) |
107 | | void* pDIB; // device independent byte buffer |
108 | | #elif defined( MACOSX ) || defined( IOS ) |
109 | | // Nothing needed, apparently |
110 | | #else |
111 | | void* aPixmap; |
112 | | #endif |
113 | | int mnWidth; |
114 | | int mnHeight; |
115 | | }; |
116 | | |
117 | | class SAL_WARN_UNUSED VCL_DLLPUBLIC Bitmap final |
118 | | { |
119 | | public: |
120 | | |
121 | | Bitmap(); |
122 | | explicit Bitmap( const OUString& rIconName ); |
123 | | Bitmap( const Bitmap& rBitmap ); |
124 | | Bitmap( const Bitmap& rBitmap, Point aSrc, Size aSize ); |
125 | | Bitmap( const Size& rSizePixel, vcl::PixelFormat ePixelFormat, const BitmapPalette* pPal = nullptr ); |
126 | | Bitmap( const Bitmap& rBmp, const Bitmap& rMask ); |
127 | | Bitmap( const Bitmap& rBmp, const AlphaMask& rAlphaMask ); |
128 | | Bitmap( const Bitmap& rBmp, const Color& rTransparentColor ); |
129 | | SAL_DLLPRIVATE explicit Bitmap( std::shared_ptr<SalBitmap> xSalBitmap ); |
130 | | ~Bitmap(); |
131 | | |
132 | | Bitmap& operator=( const Bitmap& rBitmap ); |
133 | | Bitmap& operator=( Bitmap&& rBitmap ) noexcept; |
134 | | bool operator==( const Bitmap& rBitmap ) const; |
135 | 0 | bool operator!=( const Bitmap& rBitmap ) const { return !operator==(rBitmap); } |
136 | | |
137 | | inline bool IsEmpty() const; |
138 | | void SetEmpty(); |
139 | | |
140 | | inline const MapMode& GetPrefMapMode() const; |
141 | | inline void SetPrefMapMode( const MapMode& rMapMode ); |
142 | | |
143 | | inline const Size& GetPrefSize() const; |
144 | | inline void SetPrefSize( const Size& rSize ); |
145 | | |
146 | | Size GetSizePixel() const; |
147 | | |
148 | | vcl::PixelFormat getPixelFormat() const; |
149 | | inline sal_Int64 GetSizeBytes() const; |
150 | | bool HasGreyPalette8Bit() const; |
151 | | bool HasGreyPaletteAny() const; |
152 | | // does this bitmap have alpha information? |
153 | | bool HasAlpha() const; |
154 | | |
155 | | /** return the alpha data, copied into an AlphaMask. Will assert if this Bitmap has no alpha. */ |
156 | | AlphaMask CreateAlphaMask() const; |
157 | | /** return the color data, copied into a new Bitmap. If this Bitmap does not have alpha, will return a copy of itself. */ |
158 | | Bitmap CreateColorBitmap() const; |
159 | | |
160 | | /** get system dependent bitmap data |
161 | | |
162 | | @param rData |
163 | | The system dependent BitmapSystemData structure to be filled |
164 | | |
165 | | @return true if the bitmap has a valid system object (e.g. not empty) |
166 | | */ |
167 | | bool GetSystemData( BitmapSystemData& rData ) const; |
168 | | |
169 | | BitmapChecksum GetChecksum() const; |
170 | | |
171 | | SAL_DLLPRIVATE Bitmap CreateDisplayBitmap( OutputDevice* pDisplay ) const; |
172 | | |
173 | | static const BitmapPalette& |
174 | | GetGreyPalette( int nEntries ); |
175 | | |
176 | | /** Get pixel color (including alpha) at given position |
177 | | |
178 | | @param nX |
179 | | integer X-Position in Bitmap |
180 | | |
181 | | @param nY |
182 | | integer Y-Position in Bitmap |
183 | | */ |
184 | | ::Color GetPixelColor( |
185 | | sal_Int32 nX, |
186 | | sal_Int32 nY) const; |
187 | | |
188 | | /** Create transformed Bitmap |
189 | | |
190 | | @param fWidth |
191 | | The target width in pixels |
192 | | |
193 | | @param fHeight |
194 | | The target height in pixels |
195 | | |
196 | | @param rTransformation |
197 | | The back transformation for each pixel in (0 .. fWidth),(0 .. fHeight) to |
198 | | local pixel coordinates |
199 | | */ |
200 | | [[nodiscard]] |
201 | | Bitmap TransformBitmap( |
202 | | double fWidth, |
203 | | double fHeight, |
204 | | const basegfx::B2DHomMatrix& rTransformation) const; |
205 | | |
206 | | /** Create transformed Bitmap |
207 | | |
208 | | @param rTransformation |
209 | | The transformation from unit coordinates to the unit range |
210 | | |
211 | | @param rVisibleRange |
212 | | The relative visible range in unit coordinates, relative to (0,0,1,1) which |
213 | | defines the whole target area |
214 | | |
215 | | @param fMaximumArea |
216 | | A limitation for the maximum size of pixels to use for the result |
217 | | |
218 | | The target size of the result bitmap is defined by transforming the given |
219 | | rTargetRange with the given rTransformation; the area of the result is |
220 | | linearly scaled to not exceed the given fMaximumArea |
221 | | |
222 | | @return The transformed bitmap |
223 | | */ |
224 | | [[nodiscard]] |
225 | | SAL_DLLPRIVATE Bitmap getTransformed( |
226 | | const basegfx::B2DHomMatrix& rTransformation, |
227 | | const basegfx::B2DRange& rVisibleRange, |
228 | | double fMaximumArea) const; |
229 | | |
230 | | /** Convert bitmap format |
231 | | |
232 | | @param eConversion |
233 | | The format this bitmap should be converted to. |
234 | | |
235 | | @return true the conversion was completed successfully. |
236 | | */ |
237 | | bool Convert( BmpConversion eConversion ); |
238 | | |
239 | | /** Apply a Floyd dither algorithm to the bitmap |
240 | | |
241 | | This method dithers the bitmap inplace, i.e. a true color |
242 | | bitmap is converted to a paletted bitmap, reducing the color |
243 | | deviation by error diffusion. |
244 | | |
245 | | */ |
246 | | bool Dither(); |
247 | | |
248 | | /** Crop the bitmap |
249 | | |
250 | | @param rRectPixel |
251 | | A rectangle specifying the crop amounts on all four sides of |
252 | | the bitmap. If the upper left corner of the bitmap is assigned |
253 | | (0,0), then this method cuts out the given rectangle from the |
254 | | bitmap. Note that the rectangle is clipped to the bitmap's |
255 | | dimension, i.e. negative left,top rectangle coordinates or |
256 | | exceeding width or height is ignored. |
257 | | |
258 | | @return true cropping was performed successfully. If |
259 | | nothing had to be cropped, because e.g. the crop rectangle |
260 | | included the bitmap, false is returned, too! |
261 | | */ |
262 | | bool Crop( const tools::Rectangle& rRectPixel ); |
263 | | |
264 | | /** Expand the bitmap by pixel padding |
265 | | |
266 | | @param nDX |
267 | | Number of pixel to pad at the right border of the bitmap |
268 | | |
269 | | @param nDY |
270 | | Number of scanlines to pad at the bottom border of the bitmap |
271 | | |
272 | | @param bExpandTransparent |
273 | | Whether to expand the transparency color or not. |
274 | | */ |
275 | | void Expand( sal_Int32 nDX, sal_Int32 nDY, bool bExpandTransparent = false ); |
276 | | |
277 | | /** Expand the bitmap by pixel padding |
278 | | |
279 | | @param nDX |
280 | | Number of pixel to pad at the right border of the bitmap |
281 | | |
282 | | @param nDY |
283 | | Number of scanlines to pad at the bottom border of the bitmap |
284 | | |
285 | | @param pInitColor |
286 | | Color to use for padded pixel |
287 | | |
288 | | @return true, if padding was performed successfully. false is |
289 | | not only returned when the operation failed, but also if |
290 | | nothing had to be done, e.g. because nDX and nDY were zero. |
291 | | */ |
292 | | bool Expand( sal_Int32 nDX, sal_Int32 nDY, const Color* pInitColor = nullptr ); |
293 | | |
294 | | /** Copy a rectangular area from another bitmap |
295 | | |
296 | | @param rRectDst |
297 | | Destination rectangle in this bitmap. This is clipped to the |
298 | | bitmap dimensions. |
299 | | |
300 | | @param rRectSrc |
301 | | Source rectangle in pBmpSrc. This is clipped to the source |
302 | | bitmap dimensions. Note further that no scaling takes place |
303 | | during this copy operation, i.e. only the minimum of source |
304 | | and destination rectangle's width and height are used. |
305 | | |
306 | | @param pBmpSrc |
307 | | The source bitmap to copy from. If this argument is NULL, or |
308 | | equal to the object this method is called on, copying takes |
309 | | place within the same bitmap. |
310 | | |
311 | | @return true, if the operation completed successfully. false |
312 | | is not only returned when the operation failed, but also if |
313 | | nothing had to be done, e.g. because one of the rectangles are |
314 | | empty. |
315 | | */ |
316 | | bool CopyPixel( const tools::Rectangle& rRectDst, |
317 | | const tools::Rectangle& rRectSrc, |
318 | | const Bitmap& rBmpSrc ); |
319 | | |
320 | | /** Copy a rectangular area inside this bitmap. |
321 | | |
322 | | @param rRectDst |
323 | | Destination rectangle in this bitmap. This is clipped to the |
324 | | bitmap dimensions. |
325 | | |
326 | | @param rRectSrc |
327 | | Source rectangle. This is clipped to the |
328 | | bitmap dimensions. Note further that no scaling takes place |
329 | | during this copy operation, i.e. only the minimum of source |
330 | | and destination rectangle's width and height are used. |
331 | | |
332 | | @return true, if the operation completed successfully. false |
333 | | is not only returned when the operation failed, but also if |
334 | | nothing had to be done, e.g. because one of the rectangles are |
335 | | empty. |
336 | | */ |
337 | | SAL_DLLPRIVATE bool CopyPixel( |
338 | | const tools::Rectangle& rRectDst, |
339 | | const tools::Rectangle& rRectSrc ); |
340 | | |
341 | | /** Alpha-blend the given bitmap against a specified uniform |
342 | | background color. |
343 | | |
344 | | @attention This method might convert paletted bitmaps to |
345 | | truecolor, to be able to represent every necessary color. Note |
346 | | that during alpha blending, lots of colors not originally |
347 | | included in the bitmap can be generated. |
348 | | |
349 | | @param rAlpha |
350 | | Alpha mask to blend with |
351 | | |
352 | | @param rBackgroundColor |
353 | | Background color to use for every pixel during alpha blending |
354 | | |
355 | | @return true, if blending was successful, false otherwise |
356 | | */ |
357 | | SAL_DLLPRIVATE bool Blend( |
358 | | const AlphaMask& rAlpha, |
359 | | const Color& rBackgroundColor ); |
360 | | |
361 | | /** Fill the entire bitmap with the given color |
362 | | |
363 | | @param rFillColor |
364 | | Color value to use for filling |
365 | | |
366 | | @return true, if the operation was completed successfully. |
367 | | */ |
368 | | bool Erase( const Color& rFillColor ); |
369 | | |
370 | | /** Perform the Invert operation on every pixel |
371 | | |
372 | | @return true, if the operation was completed successfully. |
373 | | */ |
374 | | bool Invert(); |
375 | | |
376 | | /** Mirror the bitmap |
377 | | |
378 | | @param nMirrorFlags |
379 | | About which axis (horizontal, vertical, or both) to mirror |
380 | | |
381 | | @return true, if the operation was completed successfully. |
382 | | */ |
383 | | bool Mirror( BmpMirrorFlags nMirrorFlags ); |
384 | | |
385 | | /** Scale the bitmap |
386 | | |
387 | | @param rNewSize |
388 | | The resulting size of the scaled bitmap |
389 | | |
390 | | @param nScaleFlag |
391 | | The algorithm to be used for scaling |
392 | | |
393 | | @return true, if the operation was completed successfully. |
394 | | */ |
395 | | bool Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default ); |
396 | | |
397 | | /** Scale the bitmap |
398 | | |
399 | | @param rScaleX |
400 | | The scale factor in x direction. |
401 | | |
402 | | @param rScaleY |
403 | | The scale factor in y direction. |
404 | | |
405 | | @param nScaleFlag |
406 | | Method of scaling - it is recommended that either BmpScaleFlag::Default or BmpScaleFlag::BestQuality be used. |
407 | | |
408 | | @return true, if the operation was completed successfully. |
409 | | */ |
410 | | bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default ); |
411 | | |
412 | | /** |
413 | | Returns true if bitmap scaling is considered to be fast. |
414 | | |
415 | | Currently this returns true if OpenGL is used for scaling, otherwise false (CPU scaling is slower). |
416 | | |
417 | | @since 4.5 |
418 | | */ |
419 | | static bool HasFastScale(); |
420 | | |
421 | | // Adapt the BitCount of rNew to BitCount of total, including grey or color palette |
422 | | // Can be used to create alpha/mask bitmaps after their processing in 24bit |
423 | | SAL_DLLPRIVATE void AdaptBitCount(Bitmap& rNew) const; |
424 | | |
425 | | /** Rotate bitmap by the specified angle |
426 | | |
427 | | @param nAngle10 |
428 | | The rotation angle in tenth of a degree. The bitmap is always rotated around its center. |
429 | | |
430 | | @param rFillColor |
431 | | The color to use for filling blank areas. During rotation, the |
432 | | bitmap is enlarged such that the whole rotation result fits |
433 | | in. The empty spaces around that rotated original bitmap are |
434 | | then filled with this color. |
435 | | |
436 | | @return true, if the operation was completed successfully. |
437 | | */ |
438 | | bool Rotate( Degree10 nAngle10, const Color& rFillColor ); |
439 | | |
440 | | /** Create on-off mask from bitmap |
441 | | |
442 | | This method creates a bitmask from the bitmap, where every |
443 | | pixel that equals rTransColor is set transparent, the rest |
444 | | opaque. |
445 | | |
446 | | @param rTransColor |
447 | | Color value where the bitmask should be transparent |
448 | | |
449 | | @return the resulting bitmask. |
450 | | */ |
451 | | Bitmap CreateMask( const Color& rTransColor ) const; |
452 | | |
453 | | /** Create on-off mask from bitmap |
454 | | |
455 | | This method creates a bitmask from the bitmap, where every |
456 | | pixel that equals rTransColor is set transparent, the rest |
457 | | opaque. |
458 | | |
459 | | @param rTransColor |
460 | | Color value where the bitmask should be transparent |
461 | | |
462 | | @param nTol |
463 | | Tolerance value. Specifies the maximal difference between |
464 | | rTransColor and the individual pixel values, such that the |
465 | | corresponding pixel is still regarded as transparent. |
466 | | |
467 | | @return the resulting bitmask. |
468 | | */ |
469 | | Bitmap CreateMask( const Color& rTransColor, sal_uInt8 nTol ) const; |
470 | | |
471 | | /** Create on-off alpha mask from bitmap |
472 | | |
473 | | This method creates a bitmask from the bitmap, where every |
474 | | pixel that equals rTransColor is set transparent, the rest |
475 | | opaque. |
476 | | |
477 | | @param rTransColor |
478 | | Color value where the bitmask should be transparent |
479 | | |
480 | | @return the resulting bitmask. |
481 | | */ |
482 | | AlphaMask CreateAlphaMask( const Color& rTransColor ) const; |
483 | | |
484 | | /** Create on-off alpha mask from bitmap |
485 | | |
486 | | This method creates a bitmask from the bitmap, where every |
487 | | pixel that equals rTransColor is set transparent, the rest |
488 | | opaque. |
489 | | |
490 | | @param rTransColor |
491 | | Color value where the bitmask should be transparent |
492 | | |
493 | | @param nTol |
494 | | Tolerance value. Specifies the maximal difference between |
495 | | rTransColor and the individual pixel values, such that the |
496 | | corresponding pixel is still regarded as transparent. |
497 | | |
498 | | @return the resulting bitmask. |
499 | | */ |
500 | | AlphaMask CreateAlphaMask( const Color& rTransColor, sal_uInt8 nTol ) const; |
501 | | |
502 | | /** Create region of similar colors in a given rectangle |
503 | | |
504 | | @param rColor |
505 | | All pixel which have this color are included in the calculated region |
506 | | |
507 | | @param rRect |
508 | | The rectangle within which matching pixel are looked for. This |
509 | | rectangle is always clipped to the bitmap dimensions. |
510 | | |
511 | | @return the generated region. |
512 | | */ |
513 | | SAL_DLLPRIVATE vcl::Region CreateRegion( const Color& rColor, const tools::Rectangle& rRect ) const; |
514 | | |
515 | | /** Merge bitmap with given background color according to specified alpha mask |
516 | | |
517 | | @param rAlpha |
518 | | Alpha mask specifying the amount of background color to merge in |
519 | | |
520 | | @param rMergeColor |
521 | | Background color to be used for merging |
522 | | |
523 | | @return true, if the operation was completed successfully. |
524 | | */ |
525 | | SAL_DLLPRIVATE bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor ); |
526 | | |
527 | | /** Replace all pixel where the given mask/alpha layer is on with the specified color |
528 | | |
529 | | @param rMask |
530 | | Mask specifying which pixel should be replaced |
531 | | |
532 | | @param rReplaceColor |
533 | | Color to be placed in all changed pixel |
534 | | |
535 | | @return true, if the operation was completed successfully. |
536 | | */ |
537 | | SAL_DLLPRIVATE bool ReplaceMask( const AlphaMask& rMask, const Color& rReplaceColor ); |
538 | | |
539 | | /** Replace all pixel having the search color with the specified color. |
540 | | Note that, if present, alpha data is not modified. |
541 | | |
542 | | @param rSearchColor |
543 | | Color specifying which pixel should be replaced |
544 | | |
545 | | @param rReplaceColor |
546 | | Color to be placed in all changed pixel |
547 | | |
548 | | @param nTol |
549 | | Tolerance value. Specifies the maximal difference between |
550 | | rSearchColor and the individual pixel values, such that the |
551 | | corresponding pixel is still regarded a match. |
552 | | |
553 | | @return true, if the operation was completed successfully. |
554 | | */ |
555 | | bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol = 0 ); |
556 | | |
557 | | /** Replace all pixel having one the search colors with the corresponding replace color. |
558 | | Note that, if present, alpha data is not modified. |
559 | | |
560 | | @param pSearchColors |
561 | | Array of colors specifying which pixel should be replaced |
562 | | |
563 | | @param rReplaceColors |
564 | | Array of colors to be placed in all changed pixel |
565 | | |
566 | | @param nColorCount |
567 | | Size of the aforementioned color arrays |
568 | | |
569 | | @param pTols |
570 | | Tolerance value. Specifies the maximal difference between |
571 | | pSearchColor colors and the individual pixel values, such that |
572 | | the corresponding pixel is still regarded a match. |
573 | | |
574 | | @return true, if the operation was completed successfully. |
575 | | */ |
576 | | bool Replace(const Color* pSearchColors, |
577 | | const Color* rReplaceColors, |
578 | | size_t nColorCount, |
579 | | sal_uInt8 const * pTols ); |
580 | | |
581 | | /** Replace transparency with given color. |
582 | | */ |
583 | | void ReplaceTransparency( const Color& rColor ); |
584 | | |
585 | | /** Get contours in image */ |
586 | | tools::Polygon GetContour( bool bContourEdgeDetect, const tools::Rectangle* pWorkRect ); |
587 | | |
588 | | /** Change various global color characteristics |
589 | | |
590 | | @param nLuminancePercent |
591 | | Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range. |
592 | | |
593 | | @param nContrastPercent |
594 | | Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range. |
595 | | |
596 | | @param nChannelRPercent |
597 | | Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range. |
598 | | |
599 | | @param nChannelGPercent |
600 | | Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range. |
601 | | |
602 | | @param nChannelBPercent |
603 | | Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range. |
604 | | |
605 | | @param fGamma |
606 | | Exponent of the gamma function applied to the bitmap. The |
607 | | value 1.0 results in no change, the valid range is |
608 | | (0.0,10.0]. Values outside this range are regarded as 1.0. |
609 | | |
610 | | @param bInvert |
611 | | If true, invert the channel values with the logical 'not' operator |
612 | | |
613 | | @param msoBrightness |
614 | | Use the same formula for brightness as used by MSOffice. |
615 | | |
616 | | @return true, if the operation was completed successfully. |
617 | | */ |
618 | | bool Adjust( |
619 | | short nLuminancePercent, |
620 | | short nContrastPercent = 0, |
621 | | short nChannelRPercent = 0, |
622 | | short nChannelGPercent = 0, |
623 | | short nChannelBPercent = 0, |
624 | | double fGamma = 1.0, |
625 | | bool bInvert = false, |
626 | | bool msoBrightness = false ); |
627 | | |
628 | | /// populate from a canvas implementation |
629 | | bool Create( |
630 | | const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas, |
631 | | const Size &rSize ); |
632 | | |
633 | | SAL_DLLPRIVATE void ChangeColorAlpha( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo ); |
634 | | |
635 | | /** |
636 | | * Adds a constant value to the alpha layer |
637 | | */ |
638 | | SAL_DLLPRIVATE void AdjustTransparency( sal_uInt8 cTrans ); |
639 | | |
640 | | /** |
641 | | * Blends, i.e. multiplies the alpha layer with the new alpha value. |
642 | | */ |
643 | | void BlendAlpha( sal_uInt8 nAlpha ); |
644 | | |
645 | | void CombineMaskOr(Color maskColor, sal_uInt8 nTol); |
646 | | |
647 | | /** |
648 | | * Retrieves the color model data we need for the XImageConsumer stuff. |
649 | | */ |
650 | | void GetColorModel(css::uno::Sequence< sal_Int32 >& rRGBPalette, |
651 | | sal_uInt32& rnRedMask, sal_uInt32& rnGreenMask, sal_uInt32& rnBlueMask, sal_uInt32& rnAlphaMask, sal_uInt32& rnTransparencyIndex, |
652 | | sal_uInt32& rnWidth, sal_uInt32& rnHeight, sal_uInt8& rnBitCount); |
653 | | |
654 | | /** Remove existing blending against COL_WHITE based on given AlphaMask |
655 | | |
656 | | Inside convertToBitmap the content gets rendered to RGB target (no 'A'), |
657 | | so it gets blended against the start condition of the target device which |
658 | | is blank (usually white background, but others may be used). |
659 | | Usually rendering to RGB is sufficient (e.g. EditViews), but for conversion |
660 | | to Bitmap the alpha channel is needed to e.g. allow export/conversion to |
661 | | pixel target formats which support Alpha, e.g. PNG. |
662 | | It is possible though to create the fully valid and correct AlphaChannel. |
663 | | If the content, the start condition and the alpha values are known it is |
664 | | possible to calculate back ("remove") the white blending from the result, |
665 | | and this is what this method does. |
666 | | |
667 | | @param rColor |
668 | | The Color we know this Bitmap is blended against (usually COL_WHITE) |
669 | | |
670 | | @param rAlphaMask |
671 | | The AlphaMask which was used to blend white against this |
672 | | */ |
673 | | void RemoveBlendedStartColor( |
674 | | const Color& rColor, |
675 | | const AlphaMask& rAlphaMask); |
676 | | |
677 | | // access to SystemDependentDataHolder, to support overload in derived class(es) |
678 | | const basegfx::SystemDependentDataHolder* accessSystemDependentDataHolder() const; |
679 | | |
680 | | |
681 | | /** |
682 | | Can only be called on 32-bit bitmaps. Returns data split into color bitmap and alpha bitmap. |
683 | | */ |
684 | | std::pair<Bitmap, AlphaMask> SplitIntoColorAndAlpha() const; |
685 | | |
686 | | /** Create ColorStack-modified version of this Bitmap |
687 | | |
688 | | @param rBColorModifierStack |
689 | | A ColrModifierStack which defines how each pixel has to be modified |
690 | | */ |
691 | | [[nodiscard]] |
692 | | Bitmap Modify( const basegfx::BColorModifierStack& rBColorModifierStack) const; |
693 | | |
694 | | /** Get the average color of the entire image. |
695 | | i.e. like scaling it down to a 1x1 pixel image. |
696 | | */ |
697 | | Color GetAverageColor() const; |
698 | | |
699 | | [[nodiscard]] |
700 | | static Bitmap AutoScaleBitmap( Bitmap const & rBitmap, const tools::Long aStandardSize ); |
701 | | |
702 | | SAL_DLLPRIVATE void Draw( OutputDevice* pOutDev, |
703 | | const Point& rDestPt ) const; |
704 | | void Draw( OutputDevice* pOutDev, |
705 | | const Point& rDestPt, const Size& rDestSize ) const; |
706 | | |
707 | | /** ReassignWithSize and recalculate bitmap. |
708 | | |
709 | | ReassignWithSizes the bitmap, and recalculates the bitmap size based on the new bitmap. |
710 | | |
711 | | @param rBitmap Bitmap to reassign and use for size calculation |
712 | | */ |
713 | | SAL_DLLPRIVATE void ReassignWithSize(const Bitmap& rBitmap); |
714 | | |
715 | | SAL_DLLPRIVATE void ImplMakeUnique(); |
716 | 2.57M | const std::shared_ptr<SalBitmap>& ImplGetSalBitmap() const { return mxSalBmp; } |
717 | | SAL_DLLPRIVATE void ImplSetSalBitmap( const std::shared_ptr<SalBitmap>& xImpBmp ); |
718 | | |
719 | | SAL_DLLPRIVATE bool ImplMakeGreyscales(); |
720 | | SAL_DLLPRIVATE bool ImplMake8BitNoConversion(); |
721 | | |
722 | | /// Dumps the pixels as PNG in bitmap.png. |
723 | | void DumpAsPng(const char* pFileName = nullptr) const; |
724 | | |
725 | | #if USE_HEADLESS_CODE |
726 | | void* tryToGetCairoSurface() const; |
727 | | #endif |
728 | | |
729 | | private: |
730 | | SAL_DLLPRIVATE bool ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const* pExtColor = nullptr); |
731 | | SAL_DLLPRIVATE bool ImplConvertDown8BPP(Color const* pExtColor = nullptr); |
732 | | SAL_DLLPRIVATE void loadFromIconTheme( const OUString& rIconName ); |
733 | | |
734 | | private: |
735 | | std::shared_ptr<SalBitmap> mxSalBmp; |
736 | | MapMode maPrefMapMode; |
737 | | Size maPrefSize; |
738 | | }; |
739 | | |
740 | | inline bool Bitmap::IsEmpty() const |
741 | 3.65M | { |
742 | 3.65M | return( mxSalBmp == nullptr ); |
743 | 3.65M | } |
744 | | |
745 | | inline const MapMode& Bitmap::GetPrefMapMode() const |
746 | 73.6k | { |
747 | 73.6k | return maPrefMapMode; |
748 | 73.6k | } |
749 | | |
750 | | inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode ) |
751 | 88.9k | { |
752 | 88.9k | maPrefMapMode = rMapMode; |
753 | 88.9k | } |
754 | | |
755 | | inline const Size& Bitmap::GetPrefSize() const |
756 | 135k | { |
757 | 135k | return maPrefSize; |
758 | 135k | } |
759 | | |
760 | | inline void Bitmap::SetPrefSize( const Size& rSize ) |
761 | 86.6k | { |
762 | 86.6k | maPrefSize = rSize; |
763 | 86.6k | } |
764 | | |
765 | | inline sal_Int64 Bitmap::GetSizeBytes() const |
766 | 109k | { |
767 | 109k | const auto aSizePixel = GetSizePixel(); |
768 | 109k | const sal_Int64 aBitCount = vcl::pixelFormatBitCount(getPixelFormat()); |
769 | 109k | sal_Int64 aSizeInBytes = (aSizePixel.Width() * aSizePixel.Height() * aBitCount) / 8; |
770 | 109k | return aSizeInBytes; |
771 | 109k | } |
772 | | |
773 | | /** Create a blend frame as Bitmap using an alpha value |
774 | | |
775 | | @param nAlpha |
776 | | The blend value defines how strong the frame will be blended with the |
777 | | existing content, 255 == full coverage, 0 == no frame will be drawn |
778 | | |
779 | | @param aColorTopLeft, aColorBottomRight |
780 | | The colors defining the frame. These colors are linearly interpolated from |
781 | | aColorTopLeft and aColorBottomRight using the width and height of the area |
782 | | |
783 | | @param rSize |
784 | | The size of the frame in pixels |
785 | | */ |
786 | | Bitmap VCL_DLLPUBLIC createAlphaBlendFrame( |
787 | | const Size& rSize, |
788 | | sal_uInt8 nAlpha, |
789 | | const Color& rColorTopLeft, |
790 | | const Color& rColorBottomRight); |
791 | | |
792 | | /** Create a blend frame as Bitmap using an alpha value |
793 | | |
794 | | @param nAlpha |
795 | | The blend value defines how strong the frame will be blended with the |
796 | | existing content, 255 == full coverage, 0 == no frame will be drawn |
797 | | |
798 | | @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft |
799 | | The colors defining the frame. |
800 | | |
801 | | @param rSize |
802 | | The size of the frame in pixels |
803 | | */ |
804 | | Bitmap createAlphaBlendFrame( |
805 | | const Size& rSize, |
806 | | sal_uInt8 nAlpha, |
807 | | const Color& rColorTopLeft, |
808 | | const Color& rColorTopRight, |
809 | | const Color& rColorBottomRight, |
810 | | const Color& rColorBottomLeft); |
811 | | |
812 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |