1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef _SV_BITMAP_HXX
25 #define _SV_BITMAP_HXX
26
27 #include <vcl/sv.h>
28 #include <vcl/dllapi.h>
29 #include <vcl/mapmod.hxx>
30 #include <tools/rc.hxx>
31 #include <vcl/region.hxx>
32 #include <tools/color.hxx>
33
34 #ifdef WNT
35 #define _STLP_HAS_NATIVE_FLOAT_ABS
36 #endif
37
38 #include <boost/math/special_functions/sinc.hpp>
39
40 using namespace boost::math::policies;
41 typedef policy<
42 promote_double<false>
43 > SincPolicy;
44
45 // -----------
46 // - Defines -
47 // -----------
48
49 #define BMP_MIRROR_NONE 0x00000000UL
50 #define BMP_MIRROR_HORZ 0x00000001UL
51 #define BMP_MIRROR_VERT 0x00000002UL
52
53 // -----------------------------------------------------------------------------
54
55 #define BMP_SCALE_NONE 0x00000000UL
56 #define BMP_SCALE_FAST 0x00000001UL
57 #define BMP_SCALE_INTERPOLATE 0x00000002UL
58 #define BMP_SCALE_SUPER 0x00000003UL
59 #define BMP_SCALE_LANCZOS 0x00000004UL
60 #define BMP_SCALE_BICUBIC 0x00000005UL
61 #define BMP_SCALE_BILINEAR 0x00000006UL
62 #define BMP_SCALE_BOX 0x00000007UL
63
64 // new default assigns for having slots for best quality and
65 // an alternative with a good compromize between speed and quality.
66 // Currently BMP_SCALE_BESTQUALITY maps to BMP_SCALE_LANCZOS and
67 // BMP_SCALE_FASTESTINTERPOLATE to BMP_SCALE_SUPER
68 #define BMP_SCALE_BESTQUALITY 0x000000feUL
69 #define BMP_SCALE_FASTESTINTERPOLATE 0x000000ffUL
70
71 // -----------------------------------------------------------------------------
72
73 #define BMP_DITHER_NONE 0x00000000UL
74 #define BMP_DITHER_MATRIX 0x00000001UL
75 #define BMP_DITHER_FLOYD 0x00000002UL
76 #define BMP_DITHER_FLOYD_16 0x00000004UL
77
78 // -----------------------------------------------------------------------------
79
80 #define BMP_VECTORIZE_NONE BMP_VECTORIZE_OUTER
81 #define BMP_VECTORIZE_INNER 0x00000001UL
82 #define BMP_VECTORIZE_OUTER 0x00000002UL
83 #define BMP_VECTORIZE_BOUND_ONLY 0x00000004UL
84 #define BMP_VECTORIZE_REDUCE_EDGES 0x00000008UL
85
86 // -----------------------------------------------------------------------------
87
88 #define BMP_COL_TRANS Color( 252, 3, 251 )
89 #define BMP_COLOR_MONOCHROME_THRESHOLD 128
90
91 // ---------
92 // - Enums -
93 // ---------
94
95 enum BmpConversion
96 {
97 BMP_CONVERSION_NONE = 0,
98 BMP_CONVERSION_1BIT_THRESHOLD = 1,
99 BMP_CONVERSION_1BIT_MATRIX = 2,
100 BMP_CONVERSION_4BIT_GREYS = 3,
101 BMP_CONVERSION_4BIT_COLORS = 4,
102 BMP_CONVERSION_8BIT_GREYS = 5,
103 BMP_CONVERSION_8BIT_COLORS = 6,
104 BMP_CONVERSION_24BIT = 7,
105 BMP_CONVERSION_4BIT_TRANS = 8,
106 BMP_CONVERSION_8BIT_TRANS = 9,
107 BMP_CONVERSION_GHOSTED = 10
108 };
109
110 // ------------------------------------------------------------------------
111
112 enum BmpCombine
113 {
114 BMP_COMBINE_COPY = 0,
115 BMP_COMBINE_INVERT = 1,
116 BMP_COMBINE_AND = 2,
117 BMP_COMBINE_NAND = 3,
118 BMP_COMBINE_OR = 4,
119 BMP_COMBINE_NOR = 5,
120 BMP_COMBINE_XOR = 6,
121 BMP_COMBINE_NXOR = 7
122 };
123
124 // ------------------------------------------------------------------------
125
126 enum BmpReduce
127 {
128 BMP_REDUCE_SIMPLE = 0,
129 BMP_REDUCE_POPULAR = 1,
130 BMP_REDUCE_MEDIAN = 2
131 };
132
133 // ------------------------------------------------------------------------
134
135 enum BmpEmboss
136 {
137 BMP_EMBOSS_TOPLEFT = 0,
138 BMP_EMBOSS_TOP = 1,
139 BMP_EMBOSS_TOPRIGHT = 2,
140 BMP_EMBOSS_LEFT = 3,
141 BMP_EMBOSS_MIDDLE = 4,
142 BMP_EMBOSS_RIGHT = 5,
143 BMP_EMBOSS_BOTTOMLEFT = 6,
144 BMP_EMBOSS_BOTTOM = 7,
145 BMP_EMBOSS_BOTTOMRIGHT = 8
146 };
147
148 // ------------------------------------------------------------------------
149
150 enum BmpFilter
151 {
152 BMP_FILTER_SMOOTH = 0,
153 BMP_FILTER_SHARPEN = 1,
154 BMP_FILTER_REMOVENOISE = 2,
155 BMP_FILTER_SOBEL_GREY = 3,
156 BMP_FILTER_EMBOSS_GREY = 4,
157 BMP_FILTER_SOLARIZE = 5,
158 BMP_FILTER_SEPIA = 6,
159 BMP_FILTER_MOSAIC = 7,
160 BMP_FILTER_POPART = 8,
161
162 BMP_FILTER_UNKNOWN = 65535
163 };
164
165 // ------------------------------------------------------------------------
166
167 enum BmpColorMode
168 {
169 BMP_COLOR_NORMAL = 0,
170 BMP_COLOR_HIGHCONTRAST = 1,
171 BMP_COLOR_MONOCHROME_BLACK = 2,
172 BMP_COLOR_MONOCHROME_WHITE = 3
173 };
174
175 // --------------------
176 // - FilterParameters -
177 // --------------------
178
179 class VCL_DLLPUBLIC BmpFilterParam
180 {
181 friend class Bitmap;
182 friend class BitmapEx;
183 friend class Animation;
184
185 private:
186 BmpFilter meFilter;
187 sal_uLong mnProgressStart;
188 sal_uLong mnProgressEnd;
189
190 public:
191 struct MosaicTileSize
192 {
193 sal_uLong mnTileWidth;
194 sal_uLong mnTileHeight;
195 };
196
197 struct EmbossAngles
198 {
199 sal_uInt16 mnAzimuthAngle100;
200 sal_uInt16 mnElevationAngle100;
201 };
202
203 private:
204 union
205 {
206 sal_uInt16 mnSepiaPercent;
207 sal_uInt8 mcSolarGreyThreshold;
208
209 MosaicTileSize maMosaicTileSize;
210 EmbossAngles maEmbossAngles;
211 };
212
213 public:
214
BmpFilterParam(sal_uLong nProgressStart=0,sal_uLong nProgressEnd=0)215 BmpFilterParam( sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
216 meFilter( BMP_FILTER_UNKNOWN ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ) {}
217
BmpFilterParam(sal_uInt8 cSolarGreyThreshold,sal_uLong nProgressStart=0,sal_uLong nProgressEnd=0)218 BmpFilterParam( sal_uInt8 cSolarGreyThreshold, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
219 meFilter( BMP_FILTER_SOLARIZE ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
220 mcSolarGreyThreshold( cSolarGreyThreshold ) {}
221
BmpFilterParam(sal_uInt16 nSepiaPercent,sal_uLong nProgressStart=0,sal_uLong nProgressEnd=0)222 BmpFilterParam( sal_uInt16 nSepiaPercent, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
223 meFilter( BMP_FILTER_SEPIA ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
224 mnSepiaPercent( nSepiaPercent ) {}
225
BmpFilterParam(const Size & rMosaicTileSize,sal_uLong nProgressStart=0,sal_uLong nProgressEnd=0)226 BmpFilterParam( const Size& rMosaicTileSize, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
227 meFilter( BMP_FILTER_MOSAIC ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
228 {
229 maMosaicTileSize.mnTileWidth = rMosaicTileSize.Width();
230 maMosaicTileSize.mnTileHeight= rMosaicTileSize.Height();
231 }
BmpFilterParam(sal_uInt16 nEmbossAzimuthAngle100,sal_uInt16 nEmbossElevationAngle100,sal_uLong nProgressStart=0,sal_uLong nProgressEnd=0)232 BmpFilterParam( sal_uInt16 nEmbossAzimuthAngle100, sal_uInt16 nEmbossElevationAngle100,
233 sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
234 meFilter( BMP_FILTER_EMBOSS_GREY ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
235 {
236 maEmbossAngles.mnAzimuthAngle100 = nEmbossAzimuthAngle100;
237 maEmbossAngles.mnElevationAngle100 = nEmbossElevationAngle100;
238 }
239 };
240
241 // --------------------
242 // Resample Kernels
243 // --------------------
244
245 class Kernel
246 {
247 public:
Kernel()248 Kernel() {}
~Kernel()249 virtual ~Kernel() {}
250
251 virtual double GetWidth() const = 0;
252 virtual double Calculate(double x) const = 0;
253 };
254
255 class Lanczos3Kernel : public Kernel
256 {
257 public:
Lanczos3Kernel(void)258 Lanczos3Kernel( void) {}
259
GetWidth() const260 virtual double GetWidth() const
261 {
262 return 3.0;
263 }
264
Calculate(double x) const265 virtual double Calculate(double x) const
266 {
267 return (-3.0 <= x && 3.0 > x) ? SincFilter(x) * SincFilter( x / 3.0 ) : 0.0;
268 }
269
SincFilter(double x) const270 inline double SincFilter(double x) const
271 {
272 if(0.0 == x)
273 {
274 return 1.0;
275 }
276
277 x *= M_PI;
278 return boost::math::sinc_pi(x, SincPolicy());
279 }
280 };
281
282 class BicubicKernel : public Kernel
283 {
284 public:
BicubicKernel(void)285 BicubicKernel( void) {}
286
GetWidth() const287 virtual double GetWidth() const
288 {
289 return 2.0;
290 }
291
Calculate(double x) const292 virtual double Calculate(double x) const
293 {
294 if(0.0 > x)
295 {
296 x = -x;
297 }
298
299 if(1.0 >= x)
300 {
301 return (1.5 * x - 2.5) * x * x + 1.0;
302 }
303 else if(2.0 > x)
304 {
305 return ((-0.5 * x + 2.5) * x - 4.0) * x + 2.0;
306 }
307
308 return 0.0;
309 }
310 };
311
312 class BilinearKernel : public Kernel
313 {
314 public:
BilinearKernel(void)315 BilinearKernel( void) {}
316
GetWidth() const317 virtual double GetWidth() const
318 {
319 return 1.0;
320 }
321
Calculate(double x) const322 virtual double Calculate(double x) const
323 {
324 if(0.0 > x)
325 {
326 x = -x;
327 }
328
329 if(1.0 > x)
330 {
331 return 1.0 - x;
332 }
333
334 return 0.0;
335 }
336 };
337
338 class BoxKernel : public Kernel
339 {
340 public:
BoxKernel(void)341 BoxKernel( void) {}
342
GetWidth() const343 virtual double GetWidth() const
344 {
345 return 0.5;
346 }
347
Calculate(double x) const348 virtual double Calculate(double x) const
349 {
350 if(-0.5 <= x && 0.5 > x)
351 {
352 return 1.0;
353 }
354
355 return 0.0;
356 }
357 };
358
359 // ----------
360 // - Bitmap -
361 // ----------
362
363 class BitmapReadAccess;
364 class BitmapWriteAccess;
365 class BitmapPalette;
366 class ImpBitmap;
367 class Color;
368 class ResId;
369 class GDIMetaFile;
370 class AlphaMask;
371 class OutputDevice;
372 class SalBitmap;
373
374 struct BitmapSystemData
375 {
376 #if defined( WNT ) || defined( OS2 )
377 void* pDIB; // device independent byte buffer
378 void* pDDB; // if not NULL then this is actually an HBITMAP
379 #elif defined( QUARTZ )
380 void* rImageContext; //Image context (CGContextRef)
381 #else
382 void* aPixmap;
383 #endif
384 int mnWidth;
385 int mnHeight;
386 };
387
388 class VCL_DLLPUBLIC Bitmap
389 {
390 private:
391
392 ImpBitmap* mpImpBmp;
393 MapMode maPrefMapMode;
394 Size maPrefSize;
395
396 //#if 0 // _SOLAR__PRIVATE
397
398 public:
399
400 SAL_DLLPRIVATE void ImplReleaseRef();
401 SAL_DLLPRIVATE void ImplMakeUnique();
402 ImpBitmap* ImplGetImpBitmap() const;
403 SAL_DLLPRIVATE void ImplSetImpBitmap( ImpBitmap* pImpBmp );
404 SAL_DLLPRIVATE void ImplAssignWithSize( const Bitmap& rBitmap );
405
406 SAL_DLLPRIVATE void ImplAdaptBitCount(Bitmap& rNew) const;
407 SAL_DLLPRIVATE sal_Bool ImplScaleFast( const double& rScaleX, const double& rScaleY );
408 SAL_DLLPRIVATE sal_Bool ImplScaleInterpolate( const double& rScaleX, const double& rScaleY );
409 SAL_DLLPRIVATE sal_Bool ImplScaleSuper( const double& rScaleX, const double& rScaleY );
410 SAL_DLLPRIVATE sal_Bool ImplScaleConvolution( const double& rScaleX, const double& rScaleY, const Kernel& aKernel);
411 SAL_DLLPRIVATE sal_Bool ImplMakeMono( sal_uInt8 cThreshold );
412 SAL_DLLPRIVATE sal_Bool ImplMakeMonoDither();
413 SAL_DLLPRIVATE sal_Bool ImplMakeGreyscales( sal_uInt16 nGreyscales );
414 SAL_DLLPRIVATE sal_Bool ImplConvertUp( sal_uInt16 nBitCount, Color* pExtColor = NULL );
415 SAL_DLLPRIVATE sal_Bool ImplConvertDown( sal_uInt16 nBitCount, Color* pExtColor = NULL );
416 SAL_DLLPRIVATE sal_Bool ImplConvertGhosted();
417 SAL_DLLPRIVATE sal_Bool ImplDitherMatrix();
418 SAL_DLLPRIVATE sal_Bool ImplDitherFloyd();
419 SAL_DLLPRIVATE sal_Bool ImplDitherFloyd16();
420 SAL_DLLPRIVATE sal_Bool ImplReduceSimple( sal_uInt16 nColorCount );
421 SAL_DLLPRIVATE sal_Bool ImplReducePopular( sal_uInt16 nColorCount );
422 SAL_DLLPRIVATE sal_Bool ImplReduceMedian( sal_uInt16 nColorCount );
423 SAL_DLLPRIVATE void ImplMedianCut( sal_uLong* pColBuf, BitmapPalette& rPal,
424 long nR1, long nR2, long nG1, long nG2, long nB1, long nB2,
425 long nColors, long nPixels, long& rIndex );
426 SAL_DLLPRIVATE sal_Bool ImplConvolute3( const long* pMatrix, long nDivisor,
427 const BmpFilterParam* pFilterParam, const Link* pProgress );
428 SAL_DLLPRIVATE sal_Bool ImplMedianFilter( const BmpFilterParam* pFilterParam, const Link* pProgress );
429 SAL_DLLPRIVATE sal_Bool ImplSobelGrey( const BmpFilterParam* pFilterParam, const Link* pProgress );
430 SAL_DLLPRIVATE sal_Bool ImplEmbossGrey( const BmpFilterParam* pFilterParam, const Link* pProgress );
431 SAL_DLLPRIVATE sal_Bool ImplSolarize( const BmpFilterParam* pFilterParam, const Link* pProgress );
432 SAL_DLLPRIVATE sal_Bool ImplSepia( const BmpFilterParam* pFilterParam, const Link* pProgress );
433 SAL_DLLPRIVATE sal_Bool ImplMosaic( const BmpFilterParam* pFilterParam, const Link* pProgress );
434 SAL_DLLPRIVATE sal_Bool ImplPopArt( const BmpFilterParam* pFilterParam, const Link* pProgress );
435
436 //#endif // PRIVATE
437
438 public:
439
440 Bitmap();
441 Bitmap( const Bitmap& rBitmap );
442 Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal = NULL );
443 Bitmap( const ResId& rResId );
444 Bitmap( SalBitmap* pSalBitmap );
445 virtual ~Bitmap();
446
447 Bitmap& operator=( const Bitmap& rBitmap );
448 inline sal_Bool operator!() const;
449 inline sal_Bool operator==( const Bitmap& rBitmap ) const;
450 inline sal_Bool operator!=( const Bitmap& rBitmap ) const;
451
452 inline sal_Bool IsSameInstance( const Bitmap& rBmp ) const;
453 sal_Bool IsEqual( const Bitmap& rBmp ) const;
454
455 inline sal_Bool IsEmpty() const;
456 void SetEmpty();
457
458 inline const MapMode& GetPrefMapMode() const;
459 inline void SetPrefMapMode( const MapMode& rMapMode );
460
461 inline const Size& GetPrefSize() const;
462 inline void SetPrefSize( const Size& rSize );
463
464 Size GetSizePixel() const;
465 void SetSizePixel( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_FASTESTINTERPOLATE );
466
467 /**
468 * The pixel size of a bitmap's source (e.g. an image file)
469 * and the pixel size of its resulting bitmap can differ,
470 * e.g. when the image reader has its preview mode enabled.
471 */
472 Size GetSourceSizePixel() const;
473 void SetSourceSizePixel( const Size& );
474
475
476 sal_uInt16 GetBitCount() const;
477 inline sal_uLong GetColorCount() const;
478 inline sal_uLong GetSizeBytes() const;
479 sal_Bool HasGreyPalette() const;
480 /** get system dependent bitmap data
481
482 @param rData
483 The system dependent BitmapSystemData structure to be filled
484
485 @return sal_True if the bitmap has a valid system object (e.g. not empty)
486 */
487 bool GetSystemData( BitmapSystemData& rData ) const;
488
489 sal_uLong GetChecksum() const;
490
491 Bitmap CreateDisplayBitmap( OutputDevice* pDisplay );
492 Bitmap GetColorTransformedBitmap( BmpColorMode eColorMode ) const;
493
494 static const BitmapPalette& GetGreyPalette( int nEntries );
495
496 public:
497
498 sal_Bool MakeMono( sal_uInt8 cThreshold );
499
500
501 /** Convert bitmap format
502
503 @param eConversion
504 The format this bitmap should be converted to.
505
506 @return sal_True, if the conversion was completed successfully.
507 */
508 sal_Bool Convert( BmpConversion eConversion );
509
510 /** Reduce number of colors for the bitmap
511
512 @param nNewColorCount
513 Maximal number of bitmap colors after the reduce operation
514
515 @param eReduce
516 Algorithm to use for color reduction
517
518 @return sal_True, if the color reduction operation was completed successfully.
519 */
520 sal_Bool ReduceColors( sal_uInt16 nNewColorCount,
521 BmpReduce eReduce = BMP_REDUCE_SIMPLE );
522
523 /** Apply a dither algorithm to the bitmap
524
525 This method dithers the bitmap inplace, i.e. a true color
526 bitmap is converted to a paletted bitmap, reducing the color
527 deviation by error diffusion.
528
529 @param nDitherFlags
530 The algorithm to be used for dithering
531
532 @param pDitherPal
533 A custom palette to be used when dithering (not yet implemented, leave NULL)
534 */
535 sal_Bool Dither( sal_uLong nDitherFlags = BMP_DITHER_MATRIX );
536
537 /** Crop the bitmap
538
539 @param rRectPixel
540 A rectangle specifying the crop amounts on all four sides of
541 the bitmap. If the upper left corner of the bitmap is assigned
542 (0,0), then this method cuts out the given rectangle from the
543 bitmap. Note that the rectangle is clipped to the bitmap's
544 dimension, i.e. negative left,top rectangle coordinates or
545 exceeding width or height is ignored.
546
547 @return sal_True, if cropping was performed successfully. If
548 nothing had to be cropped, because e.g. the crop rectangle
549 included the bitmap, sal_False is returned, too!
550 */
551 sal_Bool Crop( const Rectangle& rRectPixel );
552
553 /** Expand the bitmap by pixel padding
554
555 @param nDX
556 Number of pixel to pad at the right border of the bitmap
557
558 @param nDY
559 Number of scanlines to pad at the bottom border of the bitmap
560
561 @param pInitColor
562 Color to use for padded pixel
563
564 @return sal_True, if padding was performed successfully. sal_False is
565 not only returned when the operation failed, but also if
566 nothing had to be done, e.g. because nDX and nDY were zero.
567 */
568 sal_Bool Expand( sal_uLong nDX, sal_uLong nDY,
569 const Color* pInitColor = NULL );
570
571 /** Copy a rectangular area from another bitmap
572
573 @param rRectDst
574 Destination rectangle in this bitmap. This is clipped to the
575 bitmap dimensions.
576
577 @param rRectSrc
578 Source rectangle in pBmpSrc. This is clipped to the source
579 bitmap dimensions. Note further that no scaling takes place
580 during this copy operation, i.e. only the minimum of source
581 and destination rectangle's width and height are used.
582
583 @param pBmpSrc
584 The source bitmap to copy from. If this argument is NULL, or
585 equal to the object this method is called on, copying takes
586 place within the same bitmap.
587
588 @return sal_True, if the operation completed successfully. sal_False
589 is not only returned when the operation failed, but also if
590 nothing had to be done, e.g. because one of the rectangles are
591 empty.
592 */
593 sal_Bool CopyPixel( const Rectangle& rRectDst,
594 const Rectangle& rRectSrc,
595 const Bitmap* pBmpSrc = NULL );
596
597 /** Perform boolean operations with another bitmap
598
599 @param rMask
600 The mask bitmap in the selected combine operation
601
602 @param eCombine
603 The combine operation to perform on the bitmap
604
605 @return sal_True, if the operation was completed successfully.
606 */
607 sal_Bool CombineSimple( const Bitmap& rMask,
608 BmpCombine eCombine );
609
610 /** Alpha-blend the given bitmap against a specified uniform
611 background color.
612
613 @attention This method might convert paletted bitmaps to
614 truecolor, to be able to represent every necessary color. Note
615 that during alpha blending, lots of colors not originally
616 included in the bitmap can be generated.
617
618 @param rAlpha
619 Alpha mask to blend with
620
621 @param rBackgroundColor
622 Background color to use for every pixel during alpha blending
623
624 @return sal_True, if blending was successful, sal_False otherwise
625 */
626 sal_Bool Blend( const AlphaMask& rAlpha,
627 const Color& rBackgroundColor );
628
629 /** Fill the entire bitmap with the given color
630
631 @param rFillColor
632 Color value to use for filling
633
634 @return sal_True, if the operation was completed successfully.
635 */
636 sal_Bool Erase( const Color& rFillColor );
637
638 /** Perform the Invert operation on every pixel
639
640 @return sal_True, if the operation was completed successfully.
641 */
642 sal_Bool Invert();
643
644 /** Mirror the bitmap
645
646 @param nMirrorFlags
647 About which axis (horizontal, vertical, or both) to mirror
648
649 @return sal_True, if the operation was completed successfully.
650 */
651 sal_Bool Mirror( sal_uLong nMirrorFlags );
652
653 /** Scale the bitmap
654
655 @param rNewSize
656 The resulting size of the scaled bitmap
657
658 @param nScaleFlag
659 The algorithm to be used for scaling
660
661 @return sal_True, if the operation was completed successfully.
662 */
663 sal_Bool Scale( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_FASTESTINTERPOLATE );
664
665 /** Scale the bitmap
666
667 @param rScaleX
668 The scale factor in x direction.
669
670 @param rScaleY
671 The scale factor in y direction.
672
673 @return sal_True, if the operation was completed successfully.
674 */
675 sal_Bool Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nScaleFlag = BMP_SCALE_FASTESTINTERPOLATE );
676
677 // Adapt the BitCount of rNew to BitCount of lolal, including grey or color paltette
678 // Can be used to create alpha/mask bitmaps after their processing in 24bit
679 void AdaptBitCount(Bitmap& rNew) const;
680
681 /** Rotate bitmap by the specified angle
682
683 @param nAngle10
684 The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
685
686 @param rFillColor
687 The color to use for filling blank areas. During rotation, the
688 bitmap is enlarged such that the whole rotation result fits
689 in. The empty spaces around that rotated original bitmap are
690 then filled with this color.
691
692 @return sal_True, if the operation was completed successfully.
693 */
694 sal_Bool Rotate( long nAngle10, const Color& rFillColor );
695
696 /** Create on-off mask from bitmap
697
698 This method creates a bitmask from the bitmap, where every
699 pixel that equals rTransColor is set transparent, the rest
700 opaque.
701
702 @param rTransColor
703 Color value where the bitmask should be transparent
704
705 @param nTol
706 Tolerance value. Specifies the maximal difference between
707 rTransColor and the individual pixel values, such that the
708 corresponding pixel is still regarded transparent.
709
710 @return the resulting bitmask.
711 */
712 Bitmap CreateMask( const Color& rTransColor, sal_uLong nTol = 0UL ) const;
713
714 /** Create region of similar colors in a given rectangle
715
716 @param rColor
717 All pixel which have this color are included in the calculated region
718
719 @param rRect
720 The rectangle within which matching pixel are looked for. This
721 rectangle is always clipped to the bitmap dimensions.
722
723 @return the generated region.
724 */
725 Region CreateRegion( const Color& rColor, const Rectangle& rRect ) const;
726
727 /** Replace all pixel where the given mask is on with the specified color
728
729 @param rMask
730 Mask specifying which pixel should be replaced
731
732 @param rReplaceColor
733 Color to be placed in all changed pixel
734
735 @return sal_True, if the operation was completed successfully.
736 */
737 sal_Bool Replace( const Bitmap& rMask, const Color& rReplaceColor );
738
739 /** Merge bitmap with given background color according to specified alpha mask
740
741 @param rAlpha
742 Alpha mask specifying the amount of background color to merge in
743
744 @param rMergeColor
745 Background color to be used for merging
746
747 @return sal_True, if the operation was completed successfully.
748 */
749 sal_Bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
750
751 /** Replace all pixel having the search color with the specified color
752
753 @param rSearchColor
754 Color specifying which pixel should be replaced
755
756 @param rReplaceColor
757 Color to be placed in all changed pixel
758
759 @param nTol
760 Tolerance value. Specifies the maximal difference between
761 rSearchColor and the individual pixel values, such that the
762 corresponding pixel is still regarded a match.
763
764 @return sal_True, if the operation was completed successfully.
765 */
766 sal_Bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
767
768 /** Replace all pixel having one the search colors with the corresponding replace color
769
770 @param pSearchColor
771 Array of colors specifying which pixel should be replaced
772
773 @param pReplaceColor
774 Array of colors to be placed in all changed pixel
775
776 @param nColorCount
777 Size of the aforementioned color arrays
778
779 @param nTol
780 Tolerance value. Specifies the maximal difference between
781 pSearchColor colors and the individual pixel values, such that
782 the corresponding pixel is still regarded a match.
783
784 @return sal_True, if the operation was completed successfully.
785 */
786 sal_Bool Replace( const Color* pSearchColors, const Color* rReplaceColors,
787 sal_uLong nColorCount, sal_uLong* pTols = NULL );
788
789 /** Convert the bitmap to a PolyPolygon
790
791 This works by putting continuous areas of the same color into
792 a polygon, by tracing its bounding line.
793
794 @param rPolyPoly
795 The resulting PolyPolygon
796
797 @param nFlags
798 Whether the inline or the outline of the color areas should be
799 represented by the polygon
800
801 @param pProgress
802 A callback for showing the progress of the vectorization
803
804 @return sal_True, if the operation was completed successfully.
805 */
806 sal_Bool Vectorize( PolyPolygon& rPolyPoly,
807 sal_uLong nFlags = BMP_VECTORIZE_OUTER,
808 const Link* pProgress = NULL );
809
810 /** Convert the bitmap to a meta file
811
812 This works by putting continuous areas of the same color into
813 polygons painted in this color, by tracing the area's bounding
814 line.
815
816 @param rMtf
817 The resulting meta file
818
819 @param cReduce
820 If non-null, minimal size of bound rects for individual polygons. Smaller ones are ignored.
821
822 @param nFlags
823 Whether the inline or the outline of the color areas should be
824 represented by the polygon
825
826 @param pProgress
827 A callback for showing the progress of the vectorization
828
829 @return sal_True, if the operation was completed successfully.
830 */
831 sal_Bool Vectorize( GDIMetaFile& rMtf, sal_uInt8 cReduce = 0,
832 sal_uLong nFlags = BMP_VECTORIZE_INNER,
833 const Link* pProgress = NULL );
834
835 /** Change various global color characteristics
836
837 @param nLuminancePercent
838 Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
839
840 @param nContrastPercent
841 Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
842
843 @param nChannelRPercent
844 Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
845
846 @param nChannelGPercent
847 Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
848
849 @param nChannelBPercent
850 Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
851
852 @param fGamma
853 Exponent of the gamma function applied to the bitmap. The
854 value 1.0 results in no change, the valid range is
855 (0.0,10.0]. Values outside this range are regarded as 1.0.
856
857 @param bInvert
858 If sal_True, invert the channel values with the logical 'not' operator
859
860 @return sal_True, if the operation was completed successfully.
861 */
862 sal_Bool Adjust( short nLuminancePercent = 0,
863 short nContrastPercent = 0,
864 short nChannelRPercent = 0,
865 short nChannelGPercent = 0,
866 short nChannelBPercent = 0,
867 double fGamma = 1.0,
868 sal_Bool bInvert = sal_False );
869
870 /** Apply specified filter to the bitmap
871
872 @param eFilter
873 The filter algorithm to apply
874
875 @param pFilterParam
876 Various parameter for the different bitmap filter algorithms
877
878 @param pProgress
879 A callback for showing the progress of the vectorization
880
881 @return sal_True, if the operation was completed successfully.
882 */
883 sal_Bool Filter( BmpFilter eFilter,
884 const BmpFilterParam* pFilterParam = NULL,
885 const Link* pProgress = NULL );
886
887 BitmapReadAccess* AcquireReadAccess();
888 BitmapWriteAccess* AcquireWriteAccess();
889 void ReleaseAccess( BitmapReadAccess* pAccess );
890 };
891
892 // -----------
893 // - Inlines -
894 // -----------
895
operator !() const896 inline sal_Bool Bitmap::operator!() const
897 {
898 return( mpImpBmp == NULL );
899 }
900
901 // ------------------------------------------------------------------
902
operator ==(const Bitmap & rBitmap) const903 inline sal_Bool Bitmap::operator==( const Bitmap& rBitmap ) const
904 {
905 return( rBitmap.mpImpBmp == mpImpBmp );
906 }
907
908 // ------------------------------------------------------------------
909
operator !=(const Bitmap & rBitmap) const910 inline sal_Bool Bitmap::operator!=( const Bitmap& rBitmap ) const
911 {
912 return( rBitmap.mpImpBmp != mpImpBmp );
913 }
914
915 // ------------------------------------------------------------------
916
IsSameInstance(const Bitmap & rBitmap) const917 inline sal_Bool Bitmap::IsSameInstance( const Bitmap& rBitmap ) const
918 {
919 return( rBitmap.mpImpBmp == mpImpBmp );
920 }
921
922 // ------------------------------------------------------------------
923
IsEmpty() const924 inline sal_Bool Bitmap::IsEmpty() const
925 {
926 return( mpImpBmp == NULL );
927 }
928
929 // ------------------------------------------------------------------
930
GetPrefMapMode() const931 inline const MapMode& Bitmap::GetPrefMapMode() const
932 {
933 return maPrefMapMode;
934 }
935
936 // ------------------------------------------------------------------
937
SetPrefMapMode(const MapMode & rMapMode)938 inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
939 {
940 maPrefMapMode = rMapMode;
941 }
942
943 // ------------------------------------------------------------------
944
GetPrefSize() const945 inline const Size& Bitmap::GetPrefSize() const
946 {
947 return maPrefSize;
948 }
949
950 // ------------------------------------------------------------------
951
SetPrefSize(const Size & rSize)952 inline void Bitmap::SetPrefSize( const Size& rSize )
953 {
954 maPrefSize = rSize;
955 }
956
957 // ------------------------------------------------------------------
958
GetColorCount() const959 inline sal_uLong Bitmap::GetColorCount() const
960 {
961 return( 1UL << (sal_uLong) GetBitCount() );
962 }
963
964 // ------------------------------------------------------------------
965
GetSizeBytes() const966 inline sal_uLong Bitmap::GetSizeBytes() const
967 {
968 const Size aSizePix( GetSizePixel() );
969 return( ( (sal_uLong) aSizePix.Width() * aSizePix.Height() * GetBitCount() ) >> 3UL );
970 }
971
972 #endif // _SV_BITMAP_HXX
973