bump product version to 4.2.0.1
[LibreOffice.git] / include / vcl / bitmap.hxx
blobadf6b63785a81859adb117307bc07e941f31d6f6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_BITMAP_HXX
21 #define INCLUDED_VCL_BITMAP_HXX
23 #include <boost/math/special_functions/sinc.hpp>
24 #include <tools/color.hxx>
25 #include <tools/link.hxx>
26 #include <tools/solar.h>
27 #include <vcl/dllapi.h>
28 #include <vcl/mapmod.hxx>
29 #include <vcl/region.hxx>
30 #include <vcl/scopedbitmapaccess.hxx>
32 #define BMP_MIRROR_NONE 0x00000000UL
33 #define BMP_MIRROR_HORZ 0x00000001UL
34 #define BMP_MIRROR_VERT 0x00000002UL
37 #define BMP_SCALE_NONE 0x00000000UL
38 #define BMP_SCALE_FAST 0x00000001UL
39 #define BMP_SCALE_INTERPOLATE 0x00000002UL
40 #define BMP_SCALE_SUPER 0x00000003UL
41 #define BMP_SCALE_LANCZOS 0x00000004UL
42 #define BMP_SCALE_BICUBIC 0x00000005UL
43 #define BMP_SCALE_BILINEAR 0x00000006UL
44 #define BMP_SCALE_BOX 0x00000007UL
46 // Aliases, try to use these two (or BMP_SCALE_FAST/BMP_SCALE_NONE),
47 // use a specific algorithm only if you really need to.
48 #define BMP_SCALE_BESTQUALITY BMP_SCALE_LANCZOS
49 #define BMP_SCALE_DEFAULT BMP_SCALE_SUPER
52 #define BMP_DITHER_NONE 0x00000000UL
53 #define BMP_DITHER_MATRIX 0x00000001UL
54 #define BMP_DITHER_FLOYD 0x00000002UL
55 #define BMP_DITHER_FLOYD_16 0x00000004UL
57 #define BMP_VECTORIZE_NONE BMP_VECTORIZE_OUTER
58 #define BMP_VECTORIZE_INNER 0x00000001UL
59 #define BMP_VECTORIZE_OUTER 0x00000002UL
60 #define BMP_VECTORIZE_BOUND_ONLY 0x00000004UL
61 #define BMP_VECTORIZE_REDUCE_EDGES 0x00000008UL
63 #define BMP_COL_TRANS Color( 252, 3, 251 )
65 enum BmpConversion
67 BMP_CONVERSION_NONE = 0,
68 BMP_CONVERSION_1BIT_THRESHOLD = 1,
69 BMP_CONVERSION_1BIT_MATRIX = 2,
70 BMP_CONVERSION_4BIT_GREYS = 3,
71 BMP_CONVERSION_4BIT_COLORS = 4,
72 BMP_CONVERSION_8BIT_GREYS = 5,
73 BMP_CONVERSION_8BIT_COLORS = 6,
74 BMP_CONVERSION_24BIT = 7,
75 BMP_CONVERSION_4BIT_TRANS = 8,
76 BMP_CONVERSION_8BIT_TRANS = 9,
77 BMP_CONVERSION_GHOSTED = 10
80 enum BmpCombine
82 BMP_COMBINE_COPY = 0,
83 BMP_COMBINE_INVERT = 1,
84 BMP_COMBINE_AND = 2,
85 BMP_COMBINE_NAND = 3,
86 BMP_COMBINE_OR = 4,
87 BMP_COMBINE_NOR = 5,
88 BMP_COMBINE_XOR = 6,
89 BMP_COMBINE_NXOR = 7
92 enum BmpReduce
94 BMP_REDUCE_SIMPLE = 0,
95 BMP_REDUCE_POPULAR = 1,
96 BMP_REDUCE_MEDIAN = 2
99 enum BmpEmboss
101 BMP_EMBOSS_TOPLEFT = 0,
102 BMP_EMBOSS_TOP = 1,
103 BMP_EMBOSS_TOPRIGHT = 2,
104 BMP_EMBOSS_LEFT = 3,
105 BMP_EMBOSS_MIDDLE = 4,
106 BMP_EMBOSS_RIGHT = 5,
107 BMP_EMBOSS_BOTTOMLEFT = 6,
108 BMP_EMBOSS_BOTTOM = 7,
109 BMP_EMBOSS_BOTTOMRIGHT = 8
112 enum BmpFilter
114 BMP_FILTER_SMOOTH = 0,
115 BMP_FILTER_SHARPEN = 1,
116 BMP_FILTER_REMOVENOISE = 2,
117 BMP_FILTER_SOBEL_GREY = 3,
118 BMP_FILTER_EMBOSS_GREY = 4,
119 BMP_FILTER_SOLARIZE = 5,
120 BMP_FILTER_SEPIA = 6,
121 BMP_FILTER_MOSAIC = 7,
122 BMP_FILTER_POPART = 8,
123 BMP_FILTER_DUOTONE = 9,
125 BMP_FILTER_UNKNOWN = 65535
128 class VCL_DLLPUBLIC BmpFilterParam
130 friend class Bitmap;
131 friend class BitmapEx;
132 friend class Animation;
134 private:
135 BmpFilter meFilter;
136 sal_uLong mnProgressStart;
137 sal_uLong mnProgressEnd;
139 public:
140 struct MosaicTileSize
142 sal_uLong mnTileWidth;
143 sal_uLong mnTileHeight;
146 struct EmbossAngles
148 sal_uInt16 mnAzimuthAngle100;
149 sal_uInt16 mnElevationAngle100;
152 private:
153 union
155 sal_uInt16 mnSepiaPercent;
156 sal_uInt8 mcSolarGreyThreshold;
157 double mnRadius;
159 MosaicTileSize maMosaicTileSize;
160 EmbossAngles maEmbossAngles;
163 public:
165 BmpFilterParam( sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
166 meFilter( BMP_FILTER_UNKNOWN ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ) {}
168 BmpFilterParam( sal_uInt8 cSolarGreyThreshold, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
169 meFilter( BMP_FILTER_SOLARIZE ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
170 mcSolarGreyThreshold( cSolarGreyThreshold ) {}
172 BmpFilterParam( double nRadius, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
173 meFilter( BMP_FILTER_SMOOTH ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
174 mnRadius( nRadius ) {}
176 BmpFilterParam( sal_uInt16 nSepiaPercent, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
177 meFilter( BMP_FILTER_SEPIA ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
178 mnSepiaPercent( nSepiaPercent ) {}
180 BmpFilterParam( const Size& rMosaicTileSize, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
181 meFilter( BMP_FILTER_MOSAIC ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
183 maMosaicTileSize.mnTileWidth = rMosaicTileSize.Width();
184 maMosaicTileSize.mnTileHeight= rMosaicTileSize.Height();
186 BmpFilterParam( sal_uInt16 nEmbossAzimuthAngle100, sal_uInt16 nEmbossElevationAngle100,
187 sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
188 meFilter( BMP_FILTER_EMBOSS_GREY ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
190 maEmbossAngles.mnAzimuthAngle100 = nEmbossAzimuthAngle100;
191 maEmbossAngles.mnElevationAngle100 = nEmbossElevationAngle100;
195 // --------------------
196 // Resample kernels
197 // --------------------
199 class Kernel
202 public:
203 Kernel () {}
204 virtual ~Kernel() {}
206 virtual double GetWidth() const = 0;
207 virtual double Calculate( double x ) const = 0;
210 class Lanczos3Kernel : public Kernel
212 typedef boost::math::policies::policy<
213 boost::math::policies::promote_double<false> > SincPolicy;
214 public:
215 Lanczos3Kernel() : Kernel () {}
216 virtual double GetWidth() const { return 3.0; }
217 virtual double Calculate (double x) const
219 return (-3.0 <= x && x < 3.0) ? SincFilter(x) * SincFilter( x / 3.0 ) : 0.0;
222 inline double SincFilter(double x) const
224 if (x == 0.0)
226 return 1.0;
228 x = x * M_PI;
229 return boost::math::sinc_pi(x, SincPolicy());
233 class BicubicKernel : public Kernel {
234 public:
235 BicubicKernel() : Kernel () {}
236 private:
237 virtual double GetWidth() const { return 2.0; }
238 virtual double Calculate (double x) const
240 if (x < 0.0)
242 x = -x;
245 if (x <= 1.0)
247 return (1.5 * x - 2.5) * x * x + 1.0;
249 else if (x < 2.0)
251 return ((-0.5 * x + 2.5) * x - 4) * x + 2;
253 return 0.0;
257 class BilinearKernel : public Kernel {
258 public:
259 BilinearKernel() : Kernel () {}
260 private:
261 virtual double GetWidth() const { return 1.0; }
262 virtual double Calculate (double x) const
264 if (x < 0.0)
266 x = -x;
268 if (x < 1.0)
270 return 1.0-x;
272 return 0.0;
276 class BoxKernel : public Kernel {
277 public:
278 BoxKernel() : Kernel () {}
279 private:
280 virtual double GetWidth() const { return 0.5; }
281 virtual double Calculate (double x) const
283 if (-0.5 <= x && x < 0.5)
284 return 1.0;
285 return 0.0;
289 class BitmapReadAccess;
290 class BitmapWriteAccess;
291 class BitmapPalette;
292 class ImpBitmap;
293 class Color;
294 class ResId;
295 class GDIMetaFile;
296 class AlphaMask;
297 class OutputDevice;
298 class SalBitmap;
300 struct BitmapSystemData
302 #if defined( WNT )
303 void* pDIB; // device independent byte buffer
304 void* pDDB; // if not NULL then this is actually an HBITMAP
305 #elif defined( MACOSX ) || defined( IOS )
306 void* rImageContext; //Image context (CGContextRef)
307 #else
308 void* aPixmap;
309 #endif
310 int mnWidth;
311 int mnHeight;
314 class VCL_DLLPUBLIC Bitmap
316 private:
318 ImpBitmap* mpImpBmp;
319 MapMode maPrefMapMode;
320 Size maPrefSize;
322 public:
324 SAL_DLLPRIVATE void ImplReleaseRef();
325 SAL_DLLPRIVATE void ImplMakeUnique();
326 ImpBitmap* ImplGetImpBitmap() const;
327 SAL_DLLPRIVATE void ImplSetImpBitmap( ImpBitmap* pImpBmp );
328 SAL_DLLPRIVATE void ImplAssignWithSize( const Bitmap& rBitmap );
330 SAL_DLLPRIVATE void ImplAdaptBitCount(Bitmap& rNew) const;
331 SAL_DLLPRIVATE sal_Bool ImplScaleFast( const double& rScaleX, const double& rScaleY );
332 SAL_DLLPRIVATE sal_Bool ImplScaleInterpolate( const double& rScaleX, const double& rScaleY );
333 SAL_DLLPRIVATE sal_Bool ImplScaleSuper( const double& rScaleX, const double& rScaleY );
334 SAL_DLLPRIVATE sal_Bool ImplScaleConvolution( const double& rScaleX, const double& rScaleY, const Kernel& aKernel);
336 SAL_DLLPRIVATE bool ImplConvolutionPass( Bitmap& aNewBitmap, const int nNewSize, BitmapReadAccess* pReadAcc,
337 int aNumberOfContributions, double* pWeights, int* pPixels, int* pCount );
339 SAL_DLLPRIVATE sal_Bool ImplMakeMono( sal_uInt8 cThreshold );
340 SAL_DLLPRIVATE sal_Bool ImplMakeMonoDither();
341 SAL_DLLPRIVATE sal_Bool ImplMakeGreyscales( sal_uInt16 nGreyscales );
342 SAL_DLLPRIVATE sal_Bool ImplConvertUp( sal_uInt16 nBitCount, Color* pExtColor = NULL );
343 SAL_DLLPRIVATE sal_Bool ImplConvertDown( sal_uInt16 nBitCount, Color* pExtColor = NULL );
344 SAL_DLLPRIVATE sal_Bool ImplConvertGhosted();
345 SAL_DLLPRIVATE sal_Bool ImplDitherMatrix();
346 SAL_DLLPRIVATE sal_Bool ImplDitherFloyd();
347 SAL_DLLPRIVATE sal_Bool ImplDitherFloyd16();
348 SAL_DLLPRIVATE sal_Bool ImplReduceSimple( sal_uInt16 nColorCount );
349 SAL_DLLPRIVATE sal_Bool ImplReducePopular( sal_uInt16 nColorCount );
350 SAL_DLLPRIVATE sal_Bool ImplReduceMedian( sal_uInt16 nColorCount );
351 SAL_DLLPRIVATE void ImplMedianCut( sal_uLong* pColBuf, BitmapPalette& rPal,
352 long nR1, long nR2, long nG1, long nG2, long nB1, long nB2,
353 long nColors, long nPixels, long& rIndex );
354 SAL_DLLPRIVATE sal_Bool ImplConvolute3( const long* pMatrix, long nDivisor,
355 const BmpFilterParam* pFilterParam, const Link* pProgress );
356 SAL_DLLPRIVATE sal_Bool ImplMedianFilter( const BmpFilterParam* pFilterParam, const Link* pProgress );
357 SAL_DLLPRIVATE sal_Bool ImplSobelGrey( const BmpFilterParam* pFilterParam, const Link* pProgress );
358 SAL_DLLPRIVATE sal_Bool ImplEmbossGrey( const BmpFilterParam* pFilterParam, const Link* pProgress );
359 SAL_DLLPRIVATE sal_Bool ImplSolarize( const BmpFilterParam* pFilterParam, const Link* pProgress );
360 SAL_DLLPRIVATE sal_Bool ImplSepia( const BmpFilterParam* pFilterParam, const Link* pProgress );
361 SAL_DLLPRIVATE sal_Bool ImplMosaic( const BmpFilterParam* pFilterParam, const Link* pProgress );
362 SAL_DLLPRIVATE sal_Bool ImplPopArt( const BmpFilterParam* pFilterParam, const Link* pProgress );
364 SAL_DLLPRIVATE bool ImplSeparableBlurFilter( const double aRadius = 0.7 );
365 SAL_DLLPRIVATE bool ImplSeparableUnsharpenFilter( const double aRadius = 0.7 );
366 SAL_DLLPRIVATE bool ImplDuotoneFilter( const sal_uLong nColorOne, sal_uLong nColorTwo );
367 SAL_DLLPRIVATE void ImplBlurContributions( const int aSize, const int aNumberOfContributions,
368 double* pBlurVector, double*& pWeights, int*& pPixels, int*& pCount );
369 public:
371 Bitmap();
372 Bitmap( const Bitmap& rBitmap );
373 Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal = NULL );
374 Bitmap( const ResId& rResId );
375 Bitmap( SalBitmap* pSalBitmap );
376 virtual ~Bitmap();
378 Bitmap& operator=( const Bitmap& rBitmap );
379 inline sal_Bool operator!() const;
380 inline sal_Bool operator==( const Bitmap& rBitmap ) const;
381 inline sal_Bool operator!=( const Bitmap& rBitmap ) const;
383 inline sal_Bool IsSameInstance( const Bitmap& rBmp ) const;
384 sal_Bool IsEqual( const Bitmap& rBmp ) const;
386 inline sal_Bool IsEmpty() const;
387 void SetEmpty();
389 inline const MapMode& GetPrefMapMode() const;
390 inline void SetPrefMapMode( const MapMode& rMapMode );
392 inline const Size& GetPrefSize() const;
393 inline void SetPrefSize( const Size& rSize );
395 Size GetSizePixel() const;
397 sal_uInt16 GetBitCount() const;
398 inline sal_uLong GetColorCount() const;
399 inline sal_uLong GetSizeBytes() const;
400 sal_Bool HasGreyPalette() const;
401 /** get system dependent bitmap data
403 @param rData
404 The system dependent BitmapSystemData structure to be filled
406 @return sal_True if the bitmap has a valid system object (e.g. not empty)
408 bool GetSystemData( BitmapSystemData& rData ) const;
410 sal_uLong GetChecksum() const;
412 Bitmap CreateDisplayBitmap( OutputDevice* pDisplay );
413 Bitmap GetColorTransformedBitmap() const;
415 static const BitmapPalette& GetGreyPalette( int nEntries );
417 public:
419 sal_Bool MakeMono( sal_uInt8 cThreshold );
422 /** Convert bitmap format
424 @param eConversion
425 The format this bitmap should be converted to.
427 @return sal_True, if the conversion was completed successfully.
429 sal_Bool Convert( BmpConversion eConversion );
431 /** Reduce number of colors for the bitmap
433 @param nNewColorCount
434 Maximal number of bitmap colors after the reduce operation
436 @param eReduce
437 Algorithm to use for color reduction
439 @return sal_True, if the color reduction operation was completed successfully.
441 sal_Bool ReduceColors( sal_uInt16 nNewColorCount,
442 BmpReduce eReduce = BMP_REDUCE_SIMPLE );
444 /** Apply a dither algorithm to the bitmap
446 This method dithers the bitmap inplace, i.e. a true color
447 bitmap is converted to a paletted bitmap, reducing the color
448 deviation by error diffusion.
450 @param nDitherFlags
451 The algorithm to be used for dithering
453 @param pDitherPal
454 A custom palette to be used when dithering (not yet implemented, leave NULL)
456 sal_Bool Dither( sal_uLong nDitherFlags = BMP_DITHER_MATRIX );
458 /** Crop the bitmap
460 @param rRectPixel
461 A rectangle specifying the crop amounts on all four sides of
462 the bitmap. If the upper left corner of the bitmap is assigned
463 (0,0), then this method cuts out the given rectangle from the
464 bitmap. Note that the rectangle is clipped to the bitmap's
465 dimension, i.e. negative left,top rectangle coordinates or
466 exceeding width or height is ignored.
468 @return sal_True, if cropping was performed successfully. If
469 nothing had to be cropped, because e.g. the crop rectangle
470 included the bitmap, sal_False is returned, too!
472 sal_Bool Crop( const Rectangle& rRectPixel );
474 /** Expand the bitmap by pixel padding
476 @param nDX
477 Number of pixel to pad at the right border of the bitmap
479 @param nDY
480 Number of scanlines to pad at the bottom border of the bitmap
482 @param pInitColor
483 Color to use for padded pixel
485 @return sal_True, if padding was performed successfully. sal_False is
486 not only returned when the operation failed, but also if
487 nothing had to be done, e.g. because nDX and nDY were zero.
489 sal_Bool Expand( sal_uLong nDX, sal_uLong nDY,
490 const Color* pInitColor = NULL );
492 /** Copy a rectangular area from another bitmap
494 @param rRectDst
495 Destination rectangle in this bitmap. This is clipped to the
496 bitmap dimensions.
498 @param rRectSrc
499 Source rectangle in pBmpSrc. This is clipped to the source
500 bitmap dimensions. Note further that no scaling takes place
501 during this copy operation, i.e. only the minimum of source
502 and destination rectangle's width and height are used.
504 @param pBmpSrc
505 The source bitmap to copy from. If this argument is NULL, or
506 equal to the object this method is called on, copying takes
507 place within the same bitmap.
509 @return sal_True, if the operation completed successfully. sal_False
510 is not only returned when the operation failed, but also if
511 nothing had to be done, e.g. because one of the rectangles are
512 empty.
514 sal_Bool CopyPixel( const Rectangle& rRectDst,
515 const Rectangle& rRectSrc,
516 const Bitmap* pBmpSrc = NULL );
518 /** Perform boolean operations with another bitmap
520 @param rMask
521 The mask bitmap in the selected combine operation
523 @param eCombine
524 The combine operation to perform on the bitmap
526 @return sal_True, if the operation was completed successfully.
528 sal_Bool CombineSimple( const Bitmap& rMask,
529 BmpCombine eCombine );
531 /** Alpha-blend the given bitmap against a specified uniform
532 background color.
534 @attention This method might convert paletted bitmaps to
535 truecolor, to be able to represent every necessary color. Note
536 that during alpha blending, lots of colors not originally
537 included in the bitmap can be generated.
539 @param rAlpha
540 Alpha mask to blend with
542 @param rBackgroundColor
543 Background color to use for every pixel during alpha blending
545 @return sal_True, if blending was successful, sal_False otherwise
547 sal_Bool Blend( const AlphaMask& rAlpha,
548 const Color& rBackgroundColor );
550 /** Fill the entire bitmap with the given color
552 @param rFillColor
553 Color value to use for filling
555 @return sal_True, if the operation was completed successfully.
557 sal_Bool Erase( const Color& rFillColor );
559 /** Perform the Invert operation on every pixel
561 @return sal_True, if the operation was completed successfully.
563 sal_Bool Invert();
565 /** Mirror the bitmap
567 @param nMirrorFlags
568 About which axis (horizontal, vertical, or both) to mirror
570 @return sal_True, if the operation was completed successfully.
572 sal_Bool Mirror( sal_uLong nMirrorFlags );
574 /** Scale the bitmap
576 @param rNewSize
577 The resulting size of the scaled bitmap
579 @param nScaleFlag
580 The algorithm to be used for scaling
582 @return sal_True, if the operation was completed successfully.
584 sal_Bool Scale( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
586 /** Scale the bitmap
588 @param rScaleX
589 The scale factor in x direction.
591 @param rScaleY
592 The scale factor in y direction.
594 @return sal_True, if the operation was completed successfully.
596 sal_Bool Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
598 // Adapt the BitCount of rNew to BitCount of lolal, including grey or color paltette
599 // Can be used to create alpha/mask bitmaps after their processing in 24bit
600 void AdaptBitCount(Bitmap& rNew) const;
602 /** Rotate bitmap by the specified angle
604 @param nAngle10
605 The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
607 @param rFillColor
608 The color to use for filling blank areas. During rotation, the
609 bitmap is enlarged such that the whole rotation result fits
610 in. The empty spaces around that rotated original bitmap are
611 then filled with this color.
613 @return sal_True, if the operation was completed successfully.
615 sal_Bool Rotate( long nAngle10, const Color& rFillColor );
617 /** Create on-off mask from bitmap
619 This method creates a bitmask from the bitmap, where every
620 pixel that equals rTransColor is set transparent, the rest
621 opaque.
623 @param rTransColor
624 Color value where the bitmask should be transparent
626 @param nTol
627 Tolerance value. Specifies the maximal difference between
628 rTransColor and the individual pixel values, such that the
629 corresponding pixel is still regarded transparent.
631 @return the resulting bitmask.
633 Bitmap CreateMask( const Color& rTransColor, sal_uLong nTol = 0UL ) const;
635 /** Create region of similar colors in a given rectangle
637 @param rColor
638 All pixel which have this color are included in the calculated region
640 @param rRect
641 The rectangle within which matching pixel are looked for. This
642 rectangle is always clipped to the bitmap dimensions.
644 @return the generated region.
646 Region CreateRegion( const Color& rColor, const Rectangle& rRect ) const;
648 /** Replace all pixel where the given mask is on with the specified color
650 @param rMask
651 Mask specifying which pixel should be replaced
653 @param rReplaceColor
654 Color to be placed in all changed pixel
656 @return sal_True, if the operation was completed successfully.
658 sal_Bool Replace( const Bitmap& rMask, const Color& rReplaceColor );
660 /** Merge bitmap with given background color according to specified alpha mask
662 @param rAlpha
663 Alpha mask specifying the amount of background color to merge in
665 @param rMergeColor
666 Background color to be used for merging
668 @return sal_True, if the operation was completed successfully.
670 sal_Bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
672 /** Replace all pixel having the search color with the specified color
674 @param rSearchColor
675 Color specifying which pixel should be replaced
677 @param rReplaceColor
678 Color to be placed in all changed pixel
680 @param nTol
681 Tolerance value. Specifies the maximal difference between
682 rSearchColor and the individual pixel values, such that the
683 corresponding pixel is still regarded a match.
685 @return sal_True, if the operation was completed successfully.
687 sal_Bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
689 /** Replace all pixel having one the search colors with the corresponding replace color
691 @param pSearchColor
692 Array of colors specifying which pixel should be replaced
694 @param pReplaceColor
695 Array of colors to be placed in all changed pixel
697 @param nColorCount
698 Size of the aforementioned color arrays
700 @param nTol
701 Tolerance value. Specifies the maximal difference between
702 pSearchColor colors and the individual pixel values, such that
703 the corresponding pixel is still regarded a match.
705 @return sal_True, if the operation was completed successfully.
707 sal_Bool Replace( const Color* pSearchColors, const Color* rReplaceColors,
708 sal_uLong nColorCount, sal_uLong* pTols = NULL );
710 /** Convert the bitmap to a PolyPolygon
712 This works by putting continuous areas of the same color into
713 a polygon, by tracing its bounding line.
715 @param rPolyPoly
716 The resulting PolyPolygon
718 @param nFlags
719 Whether the inline or the outline of the color areas should be
720 represented by the polygon
722 @param pProgress
723 A callback for showing the progress of the vectorization
725 @return sal_True, if the operation was completed successfully.
727 sal_Bool Vectorize( PolyPolygon& rPolyPoly,
728 sal_uLong nFlags = BMP_VECTORIZE_OUTER,
729 const Link* pProgress = NULL );
731 /** Convert the bitmap to a meta file
733 This works by putting continuous areas of the same color into
734 polygons painted in this color, by tracing the area's bounding
735 line.
737 @param rMtf
738 The resulting meta file
740 @param cReduce
741 If non-null, minimal size of bound rects for individual polygons. Smaller ones are ignored.
743 @param nFlags
744 Whether the inline or the outline of the color areas should be
745 represented by the polygon
747 @param pProgress
748 A callback for showing the progress of the vectorization
750 @return sal_True, if the operation was completed successfully.
752 sal_Bool Vectorize( GDIMetaFile& rMtf, sal_uInt8 cReduce = 0,
753 sal_uLong nFlags = BMP_VECTORIZE_INNER,
754 const Link* pProgress = NULL );
756 /** Change various global color characteristics
758 @param nLuminancePercent
759 Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
761 @param nContrastPercent
762 Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
764 @param nChannelRPercent
765 Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
767 @param nChannelGPercent
768 Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
770 @param nChannelBPercent
771 Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
773 @param fGamma
774 Exponent of the gamma function applied to the bitmap. The
775 value 1.0 results in no change, the valid range is
776 (0.0,10.0]. Values outside this range are regarded as 1.0.
778 @param bInvert
779 If sal_True, invert the channel values with the logical 'not' operator
781 @return sal_True, if the operation was completed successfully.
783 sal_Bool Adjust( short nLuminancePercent = 0,
784 short nContrastPercent = 0,
785 short nChannelRPercent = 0,
786 short nChannelGPercent = 0,
787 short nChannelBPercent = 0,
788 double fGamma = 1.0,
789 sal_Bool bInvert = sal_False );
791 /** Apply specified filter to the bitmap
793 @param eFilter
794 The filter algorithm to apply
796 @param pFilterParam
797 Various parameter for the different bitmap filter algorithms
799 @param pProgress
800 A callback for showing the progress of the vectorization
802 @return sal_True, if the operation was completed successfully.
804 sal_Bool Filter( BmpFilter eFilter,
805 const BmpFilterParam* pFilterParam = NULL,
806 const Link* pProgress = NULL );
808 public:
810 BitmapReadAccess* AcquireReadAccess();
811 BitmapWriteAccess* AcquireWriteAccess();
812 void ReleaseAccess( BitmapReadAccess* pAccess );
814 typedef vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap, &Bitmap::AcquireReadAccess >
815 ScopedReadAccess;
816 typedef vcl::ScopedBitmapAccess< BitmapWriteAccess, Bitmap, &Bitmap::AcquireWriteAccess >
817 ScopedWriteAccess;
820 inline sal_Bool Bitmap::operator!() const
822 return( mpImpBmp == NULL );
825 inline sal_Bool Bitmap::operator==( const Bitmap& rBitmap ) const
827 return( rBitmap.mpImpBmp == mpImpBmp );
830 inline sal_Bool Bitmap::operator!=( const Bitmap& rBitmap ) const
832 return( rBitmap.mpImpBmp != mpImpBmp );
835 inline sal_Bool Bitmap::IsSameInstance( const Bitmap& rBitmap ) const
837 return( rBitmap.mpImpBmp == mpImpBmp );
840 inline sal_Bool Bitmap::IsEmpty() const
842 return( mpImpBmp == NULL );
845 inline const MapMode& Bitmap::GetPrefMapMode() const
847 return maPrefMapMode;
850 inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
852 maPrefMapMode = rMapMode;
855 inline const Size& Bitmap::GetPrefSize() const
857 return maPrefSize;
860 inline void Bitmap::SetPrefSize( const Size& rSize )
862 maPrefSize = rSize;
865 inline sal_uLong Bitmap::GetColorCount() const
867 return( 1UL << (sal_uLong) GetBitCount() );
870 inline sal_uLong Bitmap::GetSizeBytes() const
872 const Size aSizePix( GetSizePixel() );
873 return( ( (sal_uLong) aSizePix.Width() * aSizePix.Height() * GetBitCount() ) >> 3UL );
876 #endif // INCLUDED_VCL_BITMAP_HXX
878 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */