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