fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / vcl / bitmap.hxx
blobb6c00c2aa58b1add95de6744ba0f7e62956aaef8
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 _SV_BITMAP_HXX
21 #define _SV_BITMAP_HXX
23 #include <tools/color.hxx>
24 #include <tools/link.hxx>
25 #include <tools/solar.h>
26 #include <vcl/dllapi.h>
27 #include <vcl/mapmod.hxx>
28 #include <vcl/region.hxx>
29 #include <vcl/scopedbitmapaccess.hxx>
31 #define BMP_MIRROR_NONE 0x00000000UL
32 #define BMP_MIRROR_HORZ 0x00000001UL
33 #define BMP_MIRROR_VERT 0x00000002UL
36 #define BMP_SCALE_NONE 0x00000000UL
37 #define BMP_SCALE_FAST 0x00000001UL
38 #define BMP_SCALE_INTERPOLATE 0x00000002UL
39 #define BMP_SCALE_SUPER 0x00000003UL
40 #define BMP_SCALE_LANCZOS 0x00000004UL
41 #define BMP_SCALE_BICUBIC 0x00000005UL
42 #define BMP_SCALE_BILINEAR 0x00000006UL
43 #define BMP_SCALE_BOX 0x00000007UL
45 // Aliases, try to use these two (or BMP_SCALE_FAST/BMP_SCALE_NONE),
46 // use a specific algorithm only if you really need to.
47 #define BMP_SCALE_BESTQUALITY BMP_SCALE_LANCZOS
48 #define BMP_SCALE_DEFAULT BMP_SCALE_SUPER
51 #define BMP_DITHER_NONE 0x00000000UL
52 #define BMP_DITHER_MATRIX 0x00000001UL
53 #define BMP_DITHER_FLOYD 0x00000002UL
54 #define BMP_DITHER_FLOYD_16 0x00000004UL
56 #define BMP_VECTORIZE_NONE BMP_VECTORIZE_OUTER
57 #define BMP_VECTORIZE_INNER 0x00000001UL
58 #define BMP_VECTORIZE_OUTER 0x00000002UL
59 #define BMP_VECTORIZE_BOUND_ONLY 0x00000004UL
60 #define BMP_VECTORIZE_REDUCE_EDGES 0x00000008UL
62 #define BMP_COL_TRANS Color( 252, 3, 251 )
64 enum BmpConversion
66 BMP_CONVERSION_NONE = 0,
67 BMP_CONVERSION_1BIT_THRESHOLD = 1,
68 BMP_CONVERSION_1BIT_MATRIX = 2,
69 BMP_CONVERSION_4BIT_GREYS = 3,
70 BMP_CONVERSION_4BIT_COLORS = 4,
71 BMP_CONVERSION_8BIT_GREYS = 5,
72 BMP_CONVERSION_8BIT_COLORS = 6,
73 BMP_CONVERSION_24BIT = 7,
74 BMP_CONVERSION_4BIT_TRANS = 8,
75 BMP_CONVERSION_8BIT_TRANS = 9,
76 BMP_CONVERSION_GHOSTED = 10
79 enum BmpCombine
81 BMP_COMBINE_COPY = 0,
82 BMP_COMBINE_INVERT = 1,
83 BMP_COMBINE_AND = 2,
84 BMP_COMBINE_NAND = 3,
85 BMP_COMBINE_OR = 4,
86 BMP_COMBINE_NOR = 5,
87 BMP_COMBINE_XOR = 6,
88 BMP_COMBINE_NXOR = 7
91 enum BmpReduce
93 BMP_REDUCE_SIMPLE = 0,
94 BMP_REDUCE_POPULAR = 1,
95 BMP_REDUCE_MEDIAN = 2
98 enum BmpEmboss
100 BMP_EMBOSS_TOPLEFT = 0,
101 BMP_EMBOSS_TOP = 1,
102 BMP_EMBOSS_TOPRIGHT = 2,
103 BMP_EMBOSS_LEFT = 3,
104 BMP_EMBOSS_MIDDLE = 4,
105 BMP_EMBOSS_RIGHT = 5,
106 BMP_EMBOSS_BOTTOMLEFT = 6,
107 BMP_EMBOSS_BOTTOM = 7,
108 BMP_EMBOSS_BOTTOMRIGHT = 8
111 enum BmpFilter
113 BMP_FILTER_SMOOTH = 0,
114 BMP_FILTER_SHARPEN = 1,
115 BMP_FILTER_REMOVENOISE = 2,
116 BMP_FILTER_SOBEL_GREY = 3,
117 BMP_FILTER_EMBOSS_GREY = 4,
118 BMP_FILTER_SOLARIZE = 5,
119 BMP_FILTER_SEPIA = 6,
120 BMP_FILTER_MOSAIC = 7,
121 BMP_FILTER_POPART = 8,
123 BMP_FILTER_UNKNOWN = 65535
126 class VCL_DLLPUBLIC BmpFilterParam
128 friend class Bitmap;
129 friend class BitmapEx;
130 friend class Animation;
132 private:
133 BmpFilter meFilter;
134 sal_uLong mnProgressStart;
135 sal_uLong mnProgressEnd;
137 public:
138 struct MosaicTileSize
140 sal_uLong mnTileWidth;
141 sal_uLong mnTileHeight;
144 struct EmbossAngles
146 sal_uInt16 mnAzimuthAngle100;
147 sal_uInt16 mnElevationAngle100;
150 private:
151 union
153 sal_uInt16 mnSepiaPercent;
154 sal_uInt8 mcSolarGreyThreshold;
155 double mnRadius;
157 MosaicTileSize maMosaicTileSize;
158 EmbossAngles maEmbossAngles;
161 public:
163 BmpFilterParam( sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
164 meFilter( BMP_FILTER_UNKNOWN ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ) {}
166 BmpFilterParam( sal_uInt8 cSolarGreyThreshold, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
167 meFilter( BMP_FILTER_SOLARIZE ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
168 mcSolarGreyThreshold( cSolarGreyThreshold ) {}
170 BmpFilterParam( double nRadius, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
171 meFilter( BMP_FILTER_SMOOTH ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
172 mnRadius( nRadius ) {}
174 BmpFilterParam( sal_uInt16 nSepiaPercent, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
175 meFilter( BMP_FILTER_SEPIA ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
176 mnSepiaPercent( nSepiaPercent ) {}
178 BmpFilterParam( const Size& rMosaicTileSize, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
179 meFilter( BMP_FILTER_MOSAIC ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
181 maMosaicTileSize.mnTileWidth = rMosaicTileSize.Width();
182 maMosaicTileSize.mnTileHeight= rMosaicTileSize.Height();
184 BmpFilterParam( sal_uInt16 nEmbossAzimuthAngle100, sal_uInt16 nEmbossElevationAngle100,
185 sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
186 meFilter( BMP_FILTER_EMBOSS_GREY ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
188 maEmbossAngles.mnAzimuthAngle100 = nEmbossAzimuthAngle100;
189 maEmbossAngles.mnElevationAngle100 = nEmbossElevationAngle100;
193 // --------------------
194 // Resample kernels
195 // --------------------
197 class Kernel
200 public:
201 Kernel () {}
202 virtual ~Kernel() {}
204 virtual double GetWidth() const = 0;
205 virtual double Calculate( double x ) const = 0;
208 class Lanczos3Kernel : public Kernel
211 public:
212 Lanczos3Kernel() : Kernel () {}
213 virtual double GetWidth() const { return 3.0; }
214 virtual double Calculate (double x) const
216 return (-3.0 <= x && x < 3.0) ? SincFilter(x) * SincFilter( x / 3.0 ) : 0.0;
219 inline double SincFilter(double x) const
221 if (x == 0.0)
223 return 1.0;
225 x = x * M_PI;
226 return sin(x) / x;
230 class BicubicKernel : public Kernel {
231 public:
232 BicubicKernel() : Kernel () {}
233 private:
234 virtual double GetWidth() const { return 2.0; }
235 virtual double Calculate (double x) const
237 if (x < 0.0)
239 x = -x;
242 if (x <= 1.0)
244 return (1.5 * x - 2.5) * x * x + 1.0;
246 else if (x < 2.0)
248 return ((-0.5 * x + 2.5) * x - 4) * x + 2;
250 return 0.0;
254 class BilinearKernel : public Kernel {
255 public:
256 BilinearKernel() : Kernel () {}
257 private:
258 virtual double GetWidth() const { return 1.0; }
259 virtual double Calculate (double x) const
261 if (x < 0.0)
263 x = -x;
265 if (x < 1.0)
267 return 1.0-x;
269 return 0.0;
273 class BoxKernel : public Kernel {
274 public:
275 BoxKernel() : Kernel () {}
276 private:
277 virtual double GetWidth() const { return 0.5; }
278 virtual double Calculate (double x) const
280 if (-0.5 <= x && x < 0.5)
281 return 1.0;
282 return 0.0;
286 class BitmapReadAccess;
287 class BitmapWriteAccess;
288 class BitmapPalette;
289 class ImpBitmap;
290 class Color;
291 class SvStream;
292 struct DIBInfoHeader;
293 class ResId;
294 class GDIMetaFile;
295 class AlphaMask;
296 class OutputDevice;
297 class SalBitmap;
299 struct BitmapSystemData
301 #if defined( WNT )
302 void* pDIB; // device independent byte buffer
303 void* pDDB; // if not NULL then this is actually an HBITMAP
304 #elif defined( MACOSX ) || defined( IOS )
305 void* rImageContext; //Image context (CGContextRef)
306 #else
307 void* aPixmap;
308 #endif
309 int mnWidth;
310 int mnHeight;
313 class VCL_DLLPUBLIC Bitmap
315 private:
317 ImpBitmap* mpImpBmp;
318 MapMode maPrefMapMode;
319 Size maPrefSize;
321 public:
323 SAL_DLLPRIVATE void ImplReleaseRef();
324 SAL_DLLPRIVATE void ImplMakeUnique();
325 ImpBitmap* ImplGetImpBitmap() const;
326 SAL_DLLPRIVATE void ImplSetImpBitmap( ImpBitmap* pImpBmp );
327 SAL_DLLPRIVATE void ImplAssignWithSize( const Bitmap& rBitmap );
329 SAL_DLLPRIVATE static sal_Bool ImplReadDIB( SvStream& rIStm, Bitmap& rBmp, sal_uLong nOffset, sal_Bool bMSOFormat = sal_False );
330 SAL_DLLPRIVATE static sal_Bool ImplReadDIBFileHeader( SvStream& rIStm, sal_uLong& rOffset );
331 SAL_DLLPRIVATE static sal_Bool ImplReadDIBInfoHeader( SvStream& rIStm, DIBInfoHeader& rHeader, sal_Bool& bTopDown, sal_Bool bMSOFormat = sal_False );
332 SAL_DLLPRIVATE static sal_Bool ImplReadDIBPalette( SvStream& rIStm, BitmapWriteAccess& rAcc, sal_Bool bQuad );
333 SAL_DLLPRIVATE static sal_Bool ImplReadDIBBits( SvStream& rIStm, DIBInfoHeader& rHeader, BitmapWriteAccess& rAcc, sal_Bool bTopDown );
334 SAL_DLLPRIVATE sal_Bool ImplWriteDIB( SvStream& rOStm, BitmapReadAccess& rAcc, sal_Bool bCompressed ) const;
335 SAL_DLLPRIVATE static sal_Bool ImplWriteDIBFileHeader( SvStream& rOStm, BitmapReadAccess& rAcc );
336 SAL_DLLPRIVATE static sal_Bool ImplWriteDIBPalette( SvStream& rOStm, BitmapReadAccess& rAcc );
337 SAL_DLLPRIVATE static sal_Bool ImplWriteDIBBits( SvStream& rOStm, BitmapReadAccess& rAcc,
338 sal_uLong nCompression, sal_uInt32& rImageSize );
339 SAL_DLLPRIVATE static void ImplDecodeRLE( sal_uInt8* pBuffer, DIBInfoHeader& rHeader,
340 BitmapWriteAccess& rAcc, sal_Bool bRLE4 );
341 SAL_DLLPRIVATE static sal_Bool ImplWriteRLE( SvStream& rOStm, BitmapReadAccess& rAcc, sal_Bool bRLE4 );
343 SAL_DLLPRIVATE void ImplAdaptBitCount(Bitmap& rNew);
344 SAL_DLLPRIVATE sal_Bool ImplScaleFast( const double& rScaleX, const double& rScaleY );
345 SAL_DLLPRIVATE sal_Bool ImplScaleInterpolate( const double& rScaleX, const double& rScaleY );
346 SAL_DLLPRIVATE sal_Bool ImplScaleSuper( const double& rScaleX, const double& rScaleY );
347 SAL_DLLPRIVATE sal_Bool ImplScaleConvolution( const double& rScaleX, const double& rScaleY, const Kernel& aKernel);
349 SAL_DLLPRIVATE bool ImplConvolutionPass( Bitmap& aNewBitmap, const int nNewSize, BitmapReadAccess* pReadAcc,
350 int aNumberOfContributions, double* pWeights, int* pPixels, int* pCount );
352 SAL_DLLPRIVATE sal_Bool ImplMakeMono( sal_uInt8 cThreshold );
353 SAL_DLLPRIVATE sal_Bool ImplMakeMonoDither();
354 SAL_DLLPRIVATE sal_Bool ImplMakeGreyscales( sal_uInt16 nGreyscales );
355 SAL_DLLPRIVATE sal_Bool ImplConvertUp( sal_uInt16 nBitCount, Color* pExtColor = NULL );
356 SAL_DLLPRIVATE sal_Bool ImplConvertDown( sal_uInt16 nBitCount, Color* pExtColor = NULL );
357 SAL_DLLPRIVATE sal_Bool ImplConvertGhosted();
358 SAL_DLLPRIVATE sal_Bool ImplDitherMatrix();
359 SAL_DLLPRIVATE sal_Bool ImplDitherFloyd();
360 SAL_DLLPRIVATE sal_Bool ImplDitherFloyd16();
361 SAL_DLLPRIVATE sal_Bool ImplReduceSimple( sal_uInt16 nColorCount );
362 SAL_DLLPRIVATE sal_Bool ImplReducePopular( sal_uInt16 nColorCount );
363 SAL_DLLPRIVATE sal_Bool ImplReduceMedian( sal_uInt16 nColorCount );
364 SAL_DLLPRIVATE void ImplMedianCut( sal_uLong* pColBuf, BitmapPalette& rPal,
365 long nR1, long nR2, long nG1, long nG2, long nB1, long nB2,
366 long nColors, long nPixels, long& rIndex );
367 SAL_DLLPRIVATE sal_Bool ImplConvolute3( const long* pMatrix, long nDivisor,
368 const BmpFilterParam* pFilterParam, const Link* pProgress );
369 SAL_DLLPRIVATE sal_Bool ImplMedianFilter( const BmpFilterParam* pFilterParam, const Link* pProgress );
370 SAL_DLLPRIVATE sal_Bool ImplSobelGrey( const BmpFilterParam* pFilterParam, const Link* pProgress );
371 SAL_DLLPRIVATE sal_Bool ImplEmbossGrey( const BmpFilterParam* pFilterParam, const Link* pProgress );
372 SAL_DLLPRIVATE sal_Bool ImplSolarize( const BmpFilterParam* pFilterParam, const Link* pProgress );
373 SAL_DLLPRIVATE sal_Bool ImplSepia( const BmpFilterParam* pFilterParam, const Link* pProgress );
374 SAL_DLLPRIVATE sal_Bool ImplMosaic( const BmpFilterParam* pFilterParam, const Link* pProgress );
375 SAL_DLLPRIVATE sal_Bool ImplPopArt( const BmpFilterParam* pFilterParam, const Link* pProgress );
377 SAL_DLLPRIVATE bool ImplSeparableBlurFilter( const double aRadius = 0.7 );
378 SAL_DLLPRIVATE bool ImplSeparableUnsharpenFilter( const double aRadius = 0.7 );
379 SAL_DLLPRIVATE void ImplBlurContributions( const int aSize, const int aNumberOfContributions,
380 double* pBlurVector, double*& pWeights, int*& pPixels, int*& pCount );
381 public:
383 Bitmap();
384 Bitmap( const Bitmap& rBitmap );
385 Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal = NULL );
386 Bitmap( const ResId& rResId );
387 Bitmap( SalBitmap* pSalBitmap );
388 virtual ~Bitmap();
390 Bitmap& operator=( const Bitmap& rBitmap );
391 inline sal_Bool operator!() const;
392 inline sal_Bool operator==( const Bitmap& rBitmap ) const;
393 inline sal_Bool operator!=( const Bitmap& rBitmap ) const;
395 inline sal_Bool IsSameInstance( const Bitmap& rBmp ) const;
396 sal_Bool IsEqual( const Bitmap& rBmp ) const;
398 inline sal_Bool IsEmpty() const;
399 void SetEmpty();
401 inline const MapMode& GetPrefMapMode() const;
402 inline void SetPrefMapMode( const MapMode& rMapMode );
404 inline const Size& GetPrefSize() const;
405 inline void SetPrefSize( const Size& rSize );
407 Size GetSizePixel() const;
410 * The pixel size of a bitmap's source (e.g. an image file)
411 * and the pixel size of its resulting bitmap can differ,
412 * e.g. when the image reader has its preview mode enabled.
414 void SetSourceSizePixel( const Size& );
416 sal_uInt16 GetBitCount() const;
417 inline sal_uLong GetColorCount() const;
418 inline sal_uLong GetSizeBytes() const;
419 sal_Bool HasGreyPalette() const;
420 /** get system dependent bitmap data
422 @param rData
423 The system dependent BitmapSystemData structure to be filled
425 @return sal_True if the bitmap has a valid system object (e.g. not empty)
427 bool GetSystemData( BitmapSystemData& rData ) const;
429 sal_uLong GetChecksum() const;
431 Bitmap CreateDisplayBitmap( OutputDevice* pDisplay );
432 Bitmap GetColorTransformedBitmap() const;
434 static const BitmapPalette& GetGreyPalette( int nEntries );
436 public:
438 sal_Bool MakeMono( sal_uInt8 cThreshold );
441 /** Convert bitmap format
443 @param eConversion
444 The format this bitmap should be converted to.
446 @return sal_True, if the conversion was completed successfully.
448 sal_Bool Convert( BmpConversion eConversion );
450 /** Reduce number of colors for the bitmap
452 @param nNewColorCount
453 Maximal number of bitmap colors after the reduce operation
455 @param eReduce
456 Algorithm to use for color reduction
458 @return sal_True, if the color reduction operation was completed successfully.
460 sal_Bool ReduceColors( sal_uInt16 nNewColorCount,
461 BmpReduce eReduce = BMP_REDUCE_SIMPLE );
463 /** Apply a dither algorithm to the bitmap
465 This method dithers the bitmap inplace, i.e. a true color
466 bitmap is converted to a paletted bitmap, reducing the color
467 deviation by error diffusion.
469 @param nDitherFlags
470 The algorithm to be used for dithering
472 @param pDitherPal
473 A custom palette to be used when dithering (not yet implemented, leave NULL)
475 sal_Bool Dither( sal_uLong nDitherFlags = BMP_DITHER_MATRIX );
477 /** Crop the bitmap
479 @param rRectPixel
480 A rectangle specifying the crop amounts on all four sides of
481 the bitmap. If the upper left corner of the bitmap is assigned
482 (0,0), then this method cuts out the given rectangle from the
483 bitmap. Note that the rectangle is clipped to the bitmap's
484 dimension, i.e. negative left,top rectangle coordinates or
485 exceeding width or height is ignored.
487 @return sal_True, if cropping was performed successfully. If
488 nothing had to be cropped, because e.g. the crop rectangle
489 included the bitmap, sal_False is returned, too!
491 sal_Bool Crop( const Rectangle& rRectPixel );
493 /** Expand the bitmap by pixel padding
495 @param nDX
496 Number of pixel to pad at the right border of the bitmap
498 @param nDY
499 Number of scanlines to pad at the bottom border of the bitmap
501 @param pInitColor
502 Color to use for padded pixel
504 @return sal_True, if padding was performed successfully. sal_False is
505 not only returned when the operation failed, but also if
506 nothing had to be done, e.g. because nDX and nDY were zero.
508 sal_Bool Expand( sal_uLong nDX, sal_uLong nDY,
509 const Color* pInitColor = NULL );
511 /** Copy a rectangular area from another bitmap
513 @param rRectDst
514 Destination rectangle in this bitmap. This is clipped to the
515 bitmap dimensions.
517 @param rRectSrc
518 Source rectangle in pBmpSrc. This is clipped to the source
519 bitmap dimensions. Note further that no scaling takes place
520 during this copy operation, i.e. only the minimum of source
521 and destination rectangle's width and height are used.
523 @param pBmpSrc
524 The source bitmap to copy from. If this argument is NULL, or
525 equal to the object this method is called on, copying takes
526 place within the same bitmap.
528 @return sal_True, if the operation completed successfully. sal_False
529 is not only returned when the operation failed, but also if
530 nothing had to be done, e.g. because one of the rectangles are
531 empty.
533 sal_Bool CopyPixel( const Rectangle& rRectDst,
534 const Rectangle& rRectSrc,
535 const Bitmap* pBmpSrc = NULL );
537 /** Perform boolean operations with another bitmap
539 @param rMask
540 The mask bitmap in the selected combine operation
542 @param eCombine
543 The combine operation to perform on the bitmap
545 @return sal_True, if the operation was completed successfully.
547 sal_Bool CombineSimple( const Bitmap& rMask,
548 BmpCombine eCombine );
550 /** Alpha-blend the given bitmap against a specified uniform
551 background color.
553 @attention This method might convert paletted bitmaps to
554 truecolor, to be able to represent every necessary color. Note
555 that during alpha blending, lots of colors not originally
556 included in the bitmap can be generated.
558 @param rAlpha
559 Alpha mask to blend with
561 @param rBackgroundColor
562 Background color to use for every pixel during alpha blending
564 @return sal_True, if blending was successful, sal_False otherwise
566 sal_Bool Blend( const AlphaMask& rAlpha,
567 const Color& rBackgroundColor );
569 /** Fill the entire bitmap with the given color
571 @param rFillColor
572 Color value to use for filling
574 @return sal_True, if the operation was completed successfully.
576 sal_Bool Erase( const Color& rFillColor );
578 /** Perform the Invert operation on every pixel
580 @return sal_True, if the operation was completed successfully.
582 sal_Bool Invert();
584 /** Mirror the bitmap
586 @param nMirrorFlags
587 About which axis (horizontal, vertical, or both) to mirror
589 @return sal_True, if the operation was completed successfully.
591 sal_Bool Mirror( sal_uLong nMirrorFlags );
593 /** Scale the bitmap
595 @param rNewSize
596 The resulting size of the scaled bitmap
598 @param nScaleFlag
599 The algorithm to be used for scaling
601 @return sal_True, if the operation was completed successfully.
603 sal_Bool Scale( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
605 /** Scale the bitmap
607 @param rScaleX
608 The scale factor in x direction.
610 @param rScaleY
611 The scale factor in y direction.
613 @return sal_True, if the operation was completed successfully.
615 sal_Bool Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
617 /** Rotate bitmap by the specified angle
619 @param nAngle10
620 The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
622 @param rFillColor
623 The color to use for filling blank areas. During rotation, the
624 bitmap is enlarged such that the whole rotation result fits
625 in. The empty spaces around that rotated original bitmap are
626 then filled with this color.
628 @return sal_True, if the operation was completed successfully.
630 sal_Bool Rotate( long nAngle10, const Color& rFillColor );
632 /** Create on-off mask from bitmap
634 This method creates a bitmask from the bitmap, where every
635 pixel that equals rTransColor is set transparent, the rest
636 opaque.
638 @param rTransColor
639 Color value where the bitmask should be transparent
641 @param nTol
642 Tolerance value. Specifies the maximal difference between
643 rTransColor and the individual pixel values, such that the
644 corresponding pixel is still regarded transparent.
646 @return the resulting bitmask.
648 Bitmap CreateMask( const Color& rTransColor, sal_uLong nTol = 0UL ) const;
650 /** Create region of similar colors in a given rectangle
652 @param rColor
653 All pixel which have this color are included in the calculated region
655 @param rRect
656 The rectangle within which matching pixel are looked for. This
657 rectangle is always clipped to the bitmap dimensions.
659 @return the generated region.
661 Region CreateRegion( const Color& rColor, const Rectangle& rRect ) const;
663 /** Replace all pixel where the given mask is on with the specified color
665 @param rMask
666 Mask specifying which pixel should be replaced
668 @param rReplaceColor
669 Color to be placed in all changed pixel
671 @return sal_True, if the operation was completed successfully.
673 sal_Bool Replace( const Bitmap& rMask, const Color& rReplaceColor );
675 /** Merge bitmap with given background color according to specified alpha mask
677 @param rAlpha
678 Alpha mask specifying the amount of background color to merge in
680 @param rMergeColor
681 Background color to be used for merging
683 @return sal_True, if the operation was completed successfully.
685 sal_Bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
687 /** Replace all pixel having the search color with the specified color
689 @param rSearchColor
690 Color specifying which pixel should be replaced
692 @param rReplaceColor
693 Color to be placed in all changed pixel
695 @param nTol
696 Tolerance value. Specifies the maximal difference between
697 rSearchColor and the individual pixel values, such that the
698 corresponding pixel is still regarded a match.
700 @return sal_True, if the operation was completed successfully.
702 sal_Bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
704 /** Replace all pixel having one the search colors with the corresponding replace color
706 @param pSearchColor
707 Array of colors specifying which pixel should be replaced
709 @param pReplaceColor
710 Array of colors to be placed in all changed pixel
712 @param nColorCount
713 Size of the aforementioned color arrays
715 @param nTol
716 Tolerance value. Specifies the maximal difference between
717 pSearchColor colors and the individual pixel values, such that
718 the corresponding pixel is still regarded a match.
720 @return sal_True, if the operation was completed successfully.
722 sal_Bool Replace( const Color* pSearchColors, const Color* rReplaceColors,
723 sal_uLong nColorCount, sal_uLong* pTols = NULL );
725 /** Convert the bitmap to a PolyPolygon
727 This works by putting continuous areas of the same color into
728 a polygon, by tracing its bounding line.
730 @param rPolyPoly
731 The resulting PolyPolygon
733 @param nFlags
734 Whether the inline or the outline of the color areas should be
735 represented by the polygon
737 @param pProgress
738 A callback for showing the progress of the vectorization
740 @return sal_True, if the operation was completed successfully.
742 sal_Bool Vectorize( PolyPolygon& rPolyPoly,
743 sal_uLong nFlags = BMP_VECTORIZE_OUTER,
744 const Link* pProgress = NULL );
746 /** Convert the bitmap to a meta file
748 This works by putting continuous areas of the same color into
749 polygons painted in this color, by tracing the area's bounding
750 line.
752 @param rMtf
753 The resulting meta file
755 @param cReduce
756 If non-null, minimal size of bound rects for individual polygons. Smaller ones are ignored.
758 @param nFlags
759 Whether the inline or the outline of the color areas should be
760 represented by the polygon
762 @param pProgress
763 A callback for showing the progress of the vectorization
765 @return sal_True, if the operation was completed successfully.
767 sal_Bool Vectorize( GDIMetaFile& rMtf, sal_uInt8 cReduce = 0,
768 sal_uLong nFlags = BMP_VECTORIZE_INNER,
769 const Link* pProgress = NULL );
771 /** Change various global color characteristics
773 @param nLuminancePercent
774 Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
776 @param nContrastPercent
777 Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
779 @param nChannelRPercent
780 Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
782 @param nChannelGPercent
783 Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
785 @param nChannelBPercent
786 Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
788 @param fGamma
789 Exponent of the gamma function applied to the bitmap. The
790 value 1.0 results in no change, the valid range is
791 (0.0,10.0]. Values outside this range are regarded as 1.0.
793 @param bInvert
794 If sal_True, invert the channel values with the logical 'not' operator
796 @return sal_True, if the operation was completed successfully.
798 sal_Bool Adjust( short nLuminancePercent = 0,
799 short nContrastPercent = 0,
800 short nChannelRPercent = 0,
801 short nChannelGPercent = 0,
802 short nChannelBPercent = 0,
803 double fGamma = 1.0,
804 sal_Bool bInvert = sal_False );
806 /** Apply specified filter to the bitmap
808 @param eFilter
809 The filter algorithm to apply
811 @param pFilterParam
812 Various parameter for the different bitmap filter algorithms
814 @param pProgress
815 A callback for showing the progress of the vectorization
817 @return sal_True, if the operation was completed successfully.
819 sal_Bool Filter( BmpFilter eFilter,
820 const BmpFilterParam* pFilterParam = NULL,
821 const Link* pProgress = NULL );
823 public:
825 BitmapReadAccess* AcquireReadAccess();
826 BitmapWriteAccess* AcquireWriteAccess();
827 void ReleaseAccess( BitmapReadAccess* pAccess );
829 typedef vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap, &Bitmap::AcquireReadAccess >
830 ScopedReadAccess;
831 typedef vcl::ScopedBitmapAccess< BitmapWriteAccess, Bitmap, &Bitmap::AcquireWriteAccess >
832 ScopedWriteAccess;
834 public:
836 sal_Bool Read( SvStream& rIStm, sal_Bool bFileHeader = sal_True, sal_Bool bMSOFormat = sal_False );
837 sal_Bool Write( SvStream& rOStm, sal_Bool bCompressed = sal_True, sal_Bool bFileHeader = sal_True ) const;
839 friend VCL_DLLPUBLIC SvStream& operator>>( SvStream& rIStm, Bitmap& rBitmap );
840 friend VCL_DLLPUBLIC SvStream& operator<<( SvStream& rOStm, const Bitmap& rBitmap );
843 inline sal_Bool Bitmap::operator!() const
845 return( mpImpBmp == NULL );
848 inline sal_Bool Bitmap::operator==( const Bitmap& rBitmap ) const
850 return( rBitmap.mpImpBmp == mpImpBmp );
853 inline sal_Bool Bitmap::operator!=( const Bitmap& rBitmap ) const
855 return( rBitmap.mpImpBmp != mpImpBmp );
858 inline sal_Bool Bitmap::IsSameInstance( const Bitmap& rBitmap ) const
860 return( rBitmap.mpImpBmp == mpImpBmp );
863 inline sal_Bool Bitmap::IsEmpty() const
865 return( mpImpBmp == NULL );
868 inline const MapMode& Bitmap::GetPrefMapMode() const
870 return maPrefMapMode;
873 inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
875 maPrefMapMode = rMapMode;
878 inline const Size& Bitmap::GetPrefSize() const
880 return maPrefSize;
883 inline void Bitmap::SetPrefSize( const Size& rSize )
885 maPrefSize = rSize;
888 inline sal_uLong Bitmap::GetColorCount() const
890 return( 1UL << (sal_uLong) GetBitCount() );
893 inline sal_uLong Bitmap::GetSizeBytes() const
895 const Size aSizePix( GetSizePixel() );
896 return( ( (sal_uLong) aSizePix.Width() * aSizePix.Height() * GetBitCount() ) >> 3UL );
899 #endif // _SV_BITMAP_HXX
901 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */