Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / bitmap.hxx
blobe9800a02b8649553844ac6dedc37e0dde44f6da5
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/checksum.hxx>
28 #include <vcl/dllapi.h>
29 #include <vcl/mapmod.hxx>
30 #include <vcl/region.hxx>
31 #include <vcl/scopedbitmapaccess.hxx>
32 #include <o3tl/typed_flags_set.hxx>
34 enum class BmpMirrorFlags
36 NONE = 0x00,
37 Horizontal = 0x01,
38 Vertical = 0x02,
40 namespace o3tl
42 template<> struct typed_flags<BmpMirrorFlags> : is_typed_flags<BmpMirrorFlags, 0x03> {};
46 enum class BmpScaleFlag
48 NONE = 0,
49 // Try to preferably use these.
50 Default = 1,
51 Fast = 2,
52 BestQuality = 3,
53 // Specific algorithms, use only if you really need to.
54 Interpolate = 4,
55 Super = 5,
56 Lanczos = 6,
57 BiCubic = 7,
58 BiLinear = 8,
59 Box = 9,
63 enum class BmpDitherFlags
65 NONE = 0x0000,
66 Matrix = 0x0001,
67 Floyd = 0x0002,
68 Floyd16 = 0x0004,
70 namespace o3tl
72 template<> struct typed_flags<BmpDitherFlags> : is_typed_flags<BmpDitherFlags, 0x07> {};
75 enum class BmpVectorizeFlags
77 Inner = 0x0001,
78 Outer = 0x0002,
79 BoundOnly = 0x0004,
80 ReduceEdges = 0x0008,
82 namespace o3tl
84 template<> struct typed_flags<BmpVectorizeFlags> : is_typed_flags<BmpVectorizeFlags, 0x0f> {};
87 #define BMP_COL_TRANS Color( 252, 3, 251 )
89 enum BmpConversion
91 BMP_CONVERSION_NONE = 0,
92 BMP_CONVERSION_1BIT_THRESHOLD = 1,
93 BMP_CONVERSION_1BIT_MATRIX = 2,
94 BMP_CONVERSION_4BIT_GREYS = 3,
95 BMP_CONVERSION_4BIT_COLORS = 4,
96 BMP_CONVERSION_8BIT_GREYS = 5,
97 BMP_CONVERSION_8BIT_COLORS = 6,
98 BMP_CONVERSION_24BIT = 7,
99 BMP_CONVERSION_4BIT_TRANS = 8,
100 BMP_CONVERSION_8BIT_TRANS = 9,
101 BMP_CONVERSION_GHOSTED = 10
104 enum BmpCombine
106 BMP_COMBINE_COPY = 0,
107 BMP_COMBINE_INVERT = 1,
108 BMP_COMBINE_AND = 2,
109 BMP_COMBINE_NAND = 3,
110 BMP_COMBINE_OR = 4,
111 BMP_COMBINE_NOR = 5,
112 BMP_COMBINE_XOR = 6,
113 BMP_COMBINE_NXOR = 7
116 enum BmpReduce
118 BMP_REDUCE_SIMPLE = 0,
119 BMP_REDUCE_POPULAR = 1,
120 BMP_REDUCE_MEDIAN = 2
123 enum BmpEmboss
125 BMP_EMBOSS_TOPLEFT = 0,
126 BMP_EMBOSS_TOP = 1,
127 BMP_EMBOSS_TOPRIGHT = 2,
128 BMP_EMBOSS_LEFT = 3,
129 BMP_EMBOSS_MIDDLE = 4,
130 BMP_EMBOSS_RIGHT = 5,
131 BMP_EMBOSS_BOTTOMLEFT = 6,
132 BMP_EMBOSS_BOTTOM = 7,
133 BMP_EMBOSS_BOTTOMRIGHT = 8
136 enum BmpFilter
138 BMP_FILTER_SMOOTH = 0,
139 BMP_FILTER_SHARPEN = 1,
140 BMP_FILTER_REMOVENOISE = 2,
141 BMP_FILTER_SOBEL_GREY = 3,
142 BMP_FILTER_EMBOSS_GREY = 4,
143 BMP_FILTER_SOLARIZE = 5,
144 BMP_FILTER_SEPIA = 6,
145 BMP_FILTER_MOSAIC = 7,
146 BMP_FILTER_POPART = 8,
147 BMP_FILTER_DUOTONE = 9,
149 BMP_FILTER_UNKNOWN = 65535
152 class VCL_DLLPUBLIC BmpFilterParam
154 public:
156 BmpFilterParam( sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
157 meFilter( BMP_FILTER_UNKNOWN ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ) {}
159 BmpFilterParam( sal_uInt8 cSolarGreyThreshold, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
160 meFilter( BMP_FILTER_SOLARIZE ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
161 mcSolarGreyThreshold( cSolarGreyThreshold ) {}
163 BmpFilterParam( double nRadius, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
164 meFilter( BMP_FILTER_SMOOTH ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
165 mnRadius( nRadius ) {}
167 BmpFilterParam( sal_uInt16 nSepiaPercent, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
168 meFilter( BMP_FILTER_SEPIA ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
169 mnSepiaPercent( nSepiaPercent ) {}
171 BmpFilterParam( const Size& rMosaicTileSize, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
172 meFilter( BMP_FILTER_MOSAIC ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
174 maMosaicTileSize.mnTileWidth = rMosaicTileSize.Width();
175 maMosaicTileSize.mnTileHeight= rMosaicTileSize.Height();
177 BmpFilterParam( sal_uInt16 nEmbossAzimuthAngle100, sal_uInt16 nEmbossElevationAngle100,
178 sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
179 meFilter( BMP_FILTER_EMBOSS_GREY ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
181 maEmbossAngles.mnAzimuthAngle100 = nEmbossAzimuthAngle100;
182 maEmbossAngles.mnElevationAngle100 = nEmbossElevationAngle100;
185 private:
186 friend class ::Bitmap;
187 friend class BitmapEx;
188 friend class Animation;
190 private:
191 BmpFilter meFilter;
192 sal_uLong mnProgressStart;
193 sal_uLong mnProgressEnd;
195 public:
196 struct MosaicTileSize
198 sal_uLong mnTileWidth;
199 sal_uLong mnTileHeight;
202 struct EmbossAngles
204 sal_uInt16 mnAzimuthAngle100;
205 sal_uInt16 mnElevationAngle100;
208 private:
209 union
211 sal_uInt16 mnSepiaPercent;
212 sal_uInt8 mcSolarGreyThreshold;
213 double mnRadius;
215 MosaicTileSize maMosaicTileSize;
216 EmbossAngles maEmbossAngles;
221 // Resample kernels
223 class Kernel
226 public:
227 Kernel () {}
228 virtual ~Kernel() {}
230 virtual double GetWidth() const = 0;
231 virtual double Calculate( double x ) const = 0;
234 class Lanczos3Kernel : public Kernel
236 public:
237 Lanczos3Kernel() : Kernel () {}
239 virtual double GetWidth() const SAL_OVERRIDE { return 3.0; }
240 virtual double Calculate (double x) const SAL_OVERRIDE
242 return (-3.0 <= x && x < 3.0) ? SincFilter(x) * SincFilter( x / 3.0 ) : 0.0;
245 static inline double SincFilter(double x)
247 if (x == 0.0)
249 return 1.0;
251 x = x * M_PI;
252 return boost::math::sinc_pi(x, SincPolicy());
255 private:
256 typedef boost::math::policies::policy<
257 boost::math::policies::promote_double<false> > SincPolicy;
260 class BicubicKernel : public Kernel
262 public:
263 BicubicKernel() : Kernel () {}
265 private:
266 virtual double GetWidth() const SAL_OVERRIDE { return 2.0; }
267 virtual double Calculate (double x) const SAL_OVERRIDE
269 if (x < 0.0)
271 x = -x;
274 if (x <= 1.0)
276 return (1.5 * x - 2.5) * x * x + 1.0;
278 else if (x < 2.0)
280 return ((-0.5 * x + 2.5) * x - 4) * x + 2;
282 return 0.0;
286 class BilinearKernel : public Kernel
288 public:
289 BilinearKernel() : Kernel () {}
290 private:
291 virtual double GetWidth() const SAL_OVERRIDE { return 1.0; }
292 virtual double Calculate (double x) const SAL_OVERRIDE
294 if (x < 0.0)
296 x = -x;
298 if (x < 1.0)
300 return 1.0-x;
302 return 0.0;
306 class BoxKernel : public Kernel
308 public:
309 BoxKernel() : Kernel () {}
311 private:
312 virtual double GetWidth() const SAL_OVERRIDE { return 0.5; }
313 virtual double Calculate (double x) const SAL_OVERRIDE
315 if (-0.5 <= x && x < 0.5)
316 return 1.0;
317 return 0.0;
321 class BitmapInfoAccess;
322 class BitmapReadAccess;
323 class BitmapWriteAccess;
324 class BitmapPalette;
325 class ImpBitmap;
326 class Color;
327 class ResId;
328 class GDIMetaFile;
329 class AlphaMask;
330 class OutputDevice;
331 class SalBitmap;
333 struct BitmapSystemData
335 #if defined( WNT )
336 void* pDIB; // device independent byte buffer
337 void* pDDB; // if not NULL then this is actually an HBITMAP
338 #elif defined( MACOSX ) || defined( IOS )
339 void* rImageContext; //Image context (CGContextRef)
340 #else
341 void* aPixmap;
342 #endif
343 int mnWidth;
344 int mnHeight;
347 class VCL_DLLPUBLIC Bitmap
349 public:
351 Bitmap();
352 Bitmap( const Bitmap& rBitmap );
353 Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal = NULL );
354 Bitmap( const ResId& rResId );
355 Bitmap( SalBitmap* pSalBitmap );
356 virtual ~Bitmap();
358 Bitmap& operator=( const Bitmap& rBitmap );
359 inline bool operator!() const;
360 inline bool operator==( const Bitmap& rBitmap ) const;
361 inline bool operator!=( const Bitmap& rBitmap ) const;
363 inline bool IsSameInstance( const Bitmap& rBmp ) const;
364 bool IsEqual( const Bitmap& rBmp ) const;
366 inline bool IsEmpty() const;
367 void SetEmpty();
369 inline const MapMode& GetPrefMapMode() const;
370 inline void SetPrefMapMode( const MapMode& rMapMode );
372 inline const Size& GetPrefSize() const;
373 inline void SetPrefSize( const Size& rSize );
375 Size GetSizePixel() const;
377 sal_uInt16 GetBitCount() const;
378 inline sal_uLong GetColorCount() const;
379 inline sal_uLong GetSizeBytes() const;
380 bool HasGreyPalette() const;
381 /** get system dependent bitmap data
383 @param rData
384 The system dependent BitmapSystemData structure to be filled
386 @return true if the bitmap has a valid system object (e.g. not empty)
388 bool GetSystemData( BitmapSystemData& rData ) const;
390 BitmapChecksum GetChecksum() const;
392 Bitmap CreateDisplayBitmap( OutputDevice* pDisplay );
393 Bitmap GetColorTransformedBitmap() const;
395 static const BitmapPalette&
396 GetGreyPalette( int nEntries );
398 public:
400 bool MakeMono( sal_uInt8 cThreshold );
403 /** Convert bitmap format
405 @param eConversion
406 The format this bitmap should be converted to.
408 @return true, if the conversion was completed successfully.
410 bool Convert( BmpConversion eConversion );
412 /** Reduce number of colors for the bitmap
414 @param nNewColorCount
415 Maximal number of bitmap colors after the reduce operation
417 @param eReduce
418 Algorithm to use for color reduction
420 @return true, if the color reduction operation was completed successfully.
422 bool ReduceColors(
423 sal_uInt16 nNewColorCount,
424 BmpReduce eReduce = BMP_REDUCE_SIMPLE );
426 /** Apply a dither algorithm to the bitmap
428 This method dithers the bitmap inplace, i.e. a true color
429 bitmap is converted to a paletted bitmap, reducing the color
430 deviation by error diffusion.
432 @param nDitherFlags
433 The algorithm to be used for dithering
435 bool Dither( BmpDitherFlags nDitherFlags = BmpDitherFlags::Matrix );
437 /** Crop the bitmap
439 @param rRectPixel
440 A rectangle specifying the crop amounts on all four sides of
441 the bitmap. If the upper left corner of the bitmap is assigned
442 (0,0), then this method cuts out the given rectangle from the
443 bitmap. Note that the rectangle is clipped to the bitmap's
444 dimension, i.e. negative left,top rectangle coordinates or
445 exceeding width or height is ignored.
447 @return true, if cropping was performed successfully. If
448 nothing had to be cropped, because e.g. the crop rectangle
449 included the bitmap, false is returned, too!
451 bool Crop( const Rectangle& rRectPixel );
453 /** Expand the bitmap by pixel padding
455 @param nDX
456 Number of pixel to pad at the right border of the bitmap
458 @param nDY
459 Number of scanlines to pad at the bottom border of the bitmap
461 @param pInitColor
462 Color to use for padded pixel
464 @return true, if padding was performed successfully. false is
465 not only returned when the operation failed, but also if
466 nothing had to be done, e.g. because nDX and nDY were zero.
468 bool Expand(
469 sal_uLong nDX, sal_uLong nDY,
470 const Color* pInitColor = NULL );
472 /** Copy a rectangular area from another bitmap
474 @param rRectDst
475 Destination rectangle in this bitmap. This is clipped to the
476 bitmap dimensions.
478 @param rRectSrc
479 Source rectangle in pBmpSrc. This is clipped to the source
480 bitmap dimensions. Note further that no scaling takes place
481 during this copy operation, i.e. only the minimum of source
482 and destination rectangle's width and height are used.
484 @param pBmpSrc
485 The source bitmap to copy from. If this argument is NULL, or
486 equal to the object this method is called on, copying takes
487 place within the same bitmap.
489 @return true, if the operation completed successfully. false
490 is not only returned when the operation failed, but also if
491 nothing had to be done, e.g. because one of the rectangles are
492 empty.
494 bool CopyPixel(
495 const Rectangle& rRectDst,
496 const Rectangle& rRectSrc,
497 const Bitmap* pBmpSrc = NULL );
499 bool CopyPixel_AlphaOptimized(
500 const Rectangle& rRectDst,
501 const Rectangle& rRectSrc,
502 const Bitmap* pBmpSrc = NULL );
504 /** Perform boolean operations with another bitmap
506 @param rMask
507 The mask bitmap in the selected combine operation
509 @param eCombine
510 The combine operation to perform on the bitmap
512 @return true, if the operation was completed successfully.
514 bool CombineSimple(
515 const Bitmap& rMask,
516 BmpCombine eCombine );
518 /** Alpha-blend the given bitmap against a specified uniform
519 background color.
521 @attention This method might convert paletted bitmaps to
522 truecolor, to be able to represent every necessary color. Note
523 that during alpha blending, lots of colors not originally
524 included in the bitmap can be generated.
526 @param rAlpha
527 Alpha mask to blend with
529 @param rBackgroundColor
530 Background color to use for every pixel during alpha blending
532 @return true, if blending was successful, false otherwise
534 bool Blend(
535 const AlphaMask& rAlpha,
536 const Color& rBackgroundColor );
538 /** Fill the entire bitmap with the given color
540 @param rFillColor
541 Color value to use for filling
543 @return true, if the operation was completed successfully.
545 bool Erase( const Color& rFillColor );
547 /** Perform the Invert operation on every pixel
549 @return true, if the operation was completed successfully.
551 bool Invert();
553 /** Mirror the bitmap
555 @param nMirrorFlags
556 About which axis (horizontal, vertical, or both) to mirror
558 @return true, if the operation was completed successfully.
560 bool Mirror( BmpMirrorFlags nMirrorFlags );
562 /** Scale the bitmap
564 @param rNewSize
565 The resulting size of the scaled bitmap
567 @param nScaleFlag
568 The algorithm to be used for scaling
570 @return true, if the operation was completed successfully.
572 bool Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
574 /** Scale the bitmap
576 @param rScaleX
577 The scale factor in x direction.
579 @param rScaleY
580 The scale factor in y direction.
582 @param nScaleFlag
583 Method of scaling - it is recommended that either BmpScaleFlag::Default or BmpScaleFlag::BestQuality be used.
585 @return true, if the operation was completed successfully.
587 bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
590 Returns true if bitmap scaling is considered to be fast.
592 Currently this returns true if OpenGL is used for scaling, otherwise false (CPU scaling is slower).
594 @since 4.5
596 static bool HasFastScale();
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 true, if the operation was completed successfully.
615 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 vcl::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 true, if the operation was completed successfully.
658 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 true, if the operation was completed successfully.
670 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 true, if the operation was completed successfully.
687 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 pSearchColors
692 Array of colors specifying which pixel should be replaced
694 @param rReplaceColors
695 Array of colors to be placed in all changed pixel
697 @param nColorCount
698 Size of the aforementioned color arrays
700 @param pTols
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 true, if the operation was completed successfully.
707 bool Replace(
708 const Color* pSearchColors,
709 const Color* rReplaceColors,
710 sal_uLong nColorCount,
711 sal_uLong* pTols = NULL );
713 /** Convert the bitmap to a PolyPolygon
715 This works by putting continuous areas of the same color into
716 a polygon, by tracing its bounding line.
718 @param rPolyPoly
719 The resulting PolyPolygon
721 @param nFlags
722 Whether the inline or the outline of the color areas should be
723 represented by the polygon
725 @param pProgress
726 A callback for showing the progress of the vectorization
728 @return true, if the operation was completed successfully.
730 bool Vectorize(
731 tools::PolyPolygon& rPolyPoly,
732 BmpVectorizeFlags nFlags = BmpVectorizeFlags::Outer,
733 const Link<>* pProgress = NULL );
735 /** Convert the bitmap to a meta file
737 This works by putting continuous areas of the same color into
738 polygons painted in this color, by tracing the area's bounding
739 line.
741 @param rMtf
742 The resulting meta file
744 @param cReduce
745 If non-null, minimal size of bound rects for individual polygons. Smaller ones are ignored.
747 @param nFlags
748 Whether the inline or the outline of the color areas should be
749 represented by the polygon
751 @param pProgress
752 A callback for showing the progress of the vectorization
754 @return true, if the operation was completed successfully.
756 bool Vectorize(
757 GDIMetaFile& rMtf,
758 sal_uInt8 cReduce = 0,
759 BmpVectorizeFlags nFlags = BmpVectorizeFlags::Inner,
760 const Link<>* pProgress = NULL );
762 /** Change various global color characteristics
764 @param nLuminancePercent
765 Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
767 @param nContrastPercent
768 Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
770 @param nChannelRPercent
771 Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
773 @param nChannelGPercent
774 Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
776 @param nChannelBPercent
777 Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
779 @param fGamma
780 Exponent of the gamma function applied to the bitmap. The
781 value 1.0 results in no change, the valid range is
782 (0.0,10.0]. Values outside this range are regarded as 1.0.
784 @param bInvert
785 If true, invert the channel values with the logical 'not' operator
787 @param msoBrightness
788 Use the same formula for brightness as used by MSOffice.
790 @return true, if the operation was completed successfully.
792 bool Adjust(
793 short nLuminancePercent = 0,
794 short nContrastPercent = 0,
795 short nChannelRPercent = 0,
796 short nChannelGPercent = 0,
797 short nChannelBPercent = 0,
798 double fGamma = 1.0,
799 bool bInvert = false,
800 bool msoBrightness = false );
802 /** Apply specified filter to the bitmap
804 @param eFilter
805 The filter algorithm to apply
807 @param pFilterParam
808 Various parameter for the different bitmap filter algorithms
810 @param pProgress
811 A callback for showing the progress of the vectorization
813 @return true, if the operation was completed successfully.
815 bool Filter(
816 BmpFilter eFilter,
817 const BmpFilterParam* pFilterParam = NULL,
818 const Link<>* pProgress = NULL );
820 public:
822 SAL_DLLPRIVATE void ImplReleaseRef();
823 SAL_DLLPRIVATE void ImplMakeUnique();
824 ImpBitmap* ImplGetImpBitmap() const { return mpImpBmp;}
825 SAL_DLLPRIVATE void ImplSetImpBitmap( ImpBitmap* pImpBmp );
826 SAL_DLLPRIVATE void ImplAssignWithSize( const Bitmap& rBitmap );
828 SAL_DLLPRIVATE void ImplAdaptBitCount(Bitmap& rNew) const;
829 SAL_DLLPRIVATE bool ImplScaleFast( const double& rScaleX, const double& rScaleY );
830 SAL_DLLPRIVATE bool ImplScaleInterpolate( const double& rScaleX, const double& rScaleY );
831 SAL_DLLPRIVATE bool ImplScaleSuper( const double& rScaleX, const double& rScaleY );
832 SAL_DLLPRIVATE bool ImplScaleConvolution( const double& rScaleX, const double& rScaleY, const Kernel& aKernel);
834 SAL_DLLPRIVATE bool ImplConvolutionPass(
835 Bitmap& aNewBitmap,
836 BitmapReadAccess* pReadAcc,
837 int aNumberOfContributions,
838 double* pWeights,
839 int* pPixels,
840 int* pCount );
842 SAL_DLLPRIVATE bool ImplMakeMono( sal_uInt8 cThreshold );
843 SAL_DLLPRIVATE bool ImplMakeMonoDither();
844 SAL_DLLPRIVATE bool ImplMakeGreyscales( sal_uInt16 nGreyscales );
845 SAL_DLLPRIVATE bool ImplConvertUp( sal_uInt16 nBitCount, Color* pExtColor = NULL );
846 SAL_DLLPRIVATE bool ImplConvertDown( sal_uInt16 nBitCount, Color* pExtColor = NULL );
847 SAL_DLLPRIVATE bool ImplConvertGhosted();
848 SAL_DLLPRIVATE bool ImplDitherMatrix();
849 SAL_DLLPRIVATE bool ImplDitherFloyd();
850 SAL_DLLPRIVATE bool ImplDitherFloyd16();
851 SAL_DLLPRIVATE bool ImplReduceSimple( sal_uInt16 nColorCount );
852 SAL_DLLPRIVATE bool ImplReducePopular( sal_uInt16 nColorCount );
853 SAL_DLLPRIVATE bool ImplReduceMedian( sal_uInt16 nColorCount );
854 SAL_DLLPRIVATE void ImplMedianCut(
855 sal_uLong* pColBuf,
856 BitmapPalette& rPal,
857 long nR1, long nR2, long nG1, long nG2, long nB1, long nB2,
858 long nColors, long nPixels, long& rIndex );
860 SAL_DLLPRIVATE bool ImplConvolute3(
861 const long* pMatrix, long nDivisor,
862 const BmpFilterParam* pFilterParam,
863 const Link<>* pProgress );
865 SAL_DLLPRIVATE bool ImplMedianFilter( const BmpFilterParam* pFilterParam, const Link<>* pProgress );
866 SAL_DLLPRIVATE bool ImplSobelGrey( const BmpFilterParam* pFilterParam, const Link<>* pProgress );
867 SAL_DLLPRIVATE bool ImplEmbossGrey( const BmpFilterParam* pFilterParam, const Link<>* pProgress );
868 SAL_DLLPRIVATE bool ImplSolarize( const BmpFilterParam* pFilterParam, const Link<>* pProgress );
869 SAL_DLLPRIVATE bool ImplSepia( const BmpFilterParam* pFilterParam, const Link<>* pProgress );
870 SAL_DLLPRIVATE bool ImplMosaic( const BmpFilterParam* pFilterParam, const Link<>* pProgress );
871 SAL_DLLPRIVATE bool ImplPopArt( const BmpFilterParam* pFilterParam, const Link<>* pProgress );
873 SAL_DLLPRIVATE bool ImplSeparableBlurFilter( const double aRadius = 0.7 );
874 SAL_DLLPRIVATE bool ImplSeparableUnsharpenFilter( const double aRadius = 0.7 );
875 SAL_DLLPRIVATE bool ImplDuotoneFilter( const sal_uLong nColorOne, sal_uLong nColorTwo );
876 SAL_DLLPRIVATE void ImplBlurContributions(
877 const int aSize,
878 const int aNumberOfContributions,
879 double* pBlurVector,
880 double*& pWeights,
881 int*& pPixels,
882 int*& pCount );
884 public:
886 BitmapInfoAccess* AcquireInfoAccess();
887 BitmapReadAccess* AcquireReadAccess();
888 BitmapWriteAccess* AcquireWriteAccess();
889 static void ReleaseAccess( BitmapInfoAccess* pAccess );
891 typedef vcl::ScopedBitmapAccess<BitmapReadAccess, Bitmap, &Bitmap::AcquireReadAccess> ScopedReadAccess;
892 typedef vcl::ScopedBitmapAccess<BitmapWriteAccess, Bitmap, &Bitmap::AcquireWriteAccess> ScopedWriteAccess;
893 typedef vcl::ScopedBitmapAccess<BitmapInfoAccess, Bitmap, &Bitmap::AcquireInfoAccess> ScopedInfoAccess;
895 private:
897 ImpBitmap* mpImpBmp;
898 MapMode maPrefMapMode;
899 Size maPrefSize;
903 inline bool Bitmap::operator!() const
905 return( mpImpBmp == NULL );
908 inline bool Bitmap::operator==( const Bitmap& rBitmap ) const
910 return( rBitmap.mpImpBmp == mpImpBmp );
913 inline bool Bitmap::operator!=( const Bitmap& rBitmap ) const
915 return( rBitmap.mpImpBmp != mpImpBmp );
918 inline bool Bitmap::IsSameInstance( const Bitmap& rBitmap ) const
920 return( rBitmap.mpImpBmp == mpImpBmp );
923 inline bool Bitmap::IsEmpty() const
925 return( mpImpBmp == NULL );
928 inline const MapMode& Bitmap::GetPrefMapMode() const
930 return maPrefMapMode;
933 inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
935 maPrefMapMode = rMapMode;
938 inline const Size& Bitmap::GetPrefSize() const
940 return maPrefSize;
943 inline void Bitmap::SetPrefSize( const Size& rSize )
945 maPrefSize = rSize;
948 inline sal_uLong Bitmap::GetColorCount() const
950 return( (sal_uLong)1 << (sal_uLong) GetBitCount() );
953 inline sal_uLong Bitmap::GetSizeBytes() const
955 const Size aSizePix( GetSizePixel() );
956 return( ( (sal_uLong) aSizePix.Width() * aSizePix.Height() * GetBitCount() ) >> 3UL );
959 #endif // INCLUDED_VCL_BITMAP_HXX
961 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */