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