Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef _SV_BITMAP_HXX
21 : #define _SV_BITMAP_HXX
22 :
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>
31 :
32 : #define BMP_MIRROR_NONE 0x00000000UL
33 : #define BMP_MIRROR_HORZ 0x00000001UL
34 : #define BMP_MIRROR_VERT 0x00000002UL
35 :
36 :
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
45 :
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
50 :
51 :
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
56 :
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
62 :
63 : #define BMP_COL_TRANS Color( 252, 3, 251 )
64 :
65 : enum BmpConversion
66 : {
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
78 : };
79 :
80 : enum BmpCombine
81 : {
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
90 : };
91 :
92 : enum BmpReduce
93 : {
94 : BMP_REDUCE_SIMPLE = 0,
95 : BMP_REDUCE_POPULAR = 1,
96 : BMP_REDUCE_MEDIAN = 2
97 : };
98 :
99 : enum BmpEmboss
100 : {
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
110 : };
111 :
112 : enum BmpFilter
113 : {
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 :
124 : BMP_FILTER_UNKNOWN = 65535
125 : };
126 :
127 : class VCL_DLLPUBLIC BmpFilterParam
128 : {
129 : friend class Bitmap;
130 : friend class BitmapEx;
131 : friend class Animation;
132 :
133 : private:
134 : BmpFilter meFilter;
135 : sal_uLong mnProgressStart;
136 : sal_uLong mnProgressEnd;
137 :
138 : public:
139 : struct MosaicTileSize
140 : {
141 : sal_uLong mnTileWidth;
142 : sal_uLong mnTileHeight;
143 : };
144 :
145 : struct EmbossAngles
146 : {
147 : sal_uInt16 mnAzimuthAngle100;
148 : sal_uInt16 mnElevationAngle100;
149 : };
150 :
151 : private:
152 : union
153 : {
154 : sal_uInt16 mnSepiaPercent;
155 : sal_uInt8 mcSolarGreyThreshold;
156 : double mnRadius;
157 :
158 : MosaicTileSize maMosaicTileSize;
159 : EmbossAngles maEmbossAngles;
160 : };
161 :
162 : public:
163 :
164 : BmpFilterParam( sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
165 : meFilter( BMP_FILTER_UNKNOWN ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ) {}
166 :
167 0 : BmpFilterParam( sal_uInt8 cSolarGreyThreshold, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
168 : meFilter( BMP_FILTER_SOLARIZE ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
169 0 : mcSolarGreyThreshold( cSolarGreyThreshold ) {}
170 :
171 0 : BmpFilterParam( double nRadius, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
172 : meFilter( BMP_FILTER_SMOOTH ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
173 0 : mnRadius( nRadius ) {}
174 :
175 0 : BmpFilterParam( sal_uInt16 nSepiaPercent, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
176 : meFilter( BMP_FILTER_SEPIA ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd ),
177 0 : mnSepiaPercent( nSepiaPercent ) {}
178 :
179 0 : BmpFilterParam( const Size& rMosaicTileSize, sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
180 0 : meFilter( BMP_FILTER_MOSAIC ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
181 : {
182 0 : maMosaicTileSize.mnTileWidth = rMosaicTileSize.Width();
183 0 : maMosaicTileSize.mnTileHeight= rMosaicTileSize.Height();
184 0 : }
185 0 : BmpFilterParam( sal_uInt16 nEmbossAzimuthAngle100, sal_uInt16 nEmbossElevationAngle100,
186 : sal_uLong nProgressStart = 0, sal_uLong nProgressEnd = 0 ) :
187 0 : meFilter( BMP_FILTER_EMBOSS_GREY ), mnProgressStart( nProgressStart ), mnProgressEnd( nProgressEnd )
188 : {
189 0 : maEmbossAngles.mnAzimuthAngle100 = nEmbossAzimuthAngle100;
190 0 : maEmbossAngles.mnElevationAngle100 = nEmbossElevationAngle100;
191 0 : }
192 : };
193 :
194 : // --------------------
195 : // Resample kernels
196 : // --------------------
197 :
198 : class Kernel
199 : {
200 :
201 : public:
202 1155 : Kernel () {}
203 1155 : virtual ~Kernel() {}
204 :
205 : virtual double GetWidth() const = 0;
206 : virtual double Calculate( double x ) const = 0;
207 : };
208 :
209 1152 : class Lanczos3Kernel : public Kernel
210 : {
211 : typedef boost::math::policies::policy<
212 : boost::math::policies::promote_double<false> > SincPolicy;
213 : public:
214 1152 : Lanczos3Kernel() : Kernel () {}
215 2198 : virtual double GetWidth() const { return 3.0; }
216 4258779 : virtual double Calculate (double x) const
217 : {
218 4258779 : return (-3.0 <= x && x < 3.0) ? SincFilter(x) * SincFilter( x / 3.0 ) : 0.0;
219 : }
220 :
221 7808030 : inline double SincFilter(double x) const
222 : {
223 7808030 : if (x == 0.0)
224 : {
225 112010 : return 1.0;
226 : }
227 7696020 : x = x * M_PI;
228 7696020 : return boost::math::sinc_pi(x, SincPolicy());
229 : }
230 : };
231 :
232 1 : class BicubicKernel : public Kernel {
233 : public:
234 1 : BicubicKernel() : Kernel () {}
235 : private:
236 2 : virtual double GetWidth() const { return 2.0; }
237 3604 : virtual double Calculate (double x) const
238 : {
239 3604 : if (x < 0.0)
240 : {
241 1801 : x = -x;
242 : }
243 :
244 3604 : if (x <= 1.0)
245 : {
246 1645 : return (1.5 * x - 2.5) * x * x + 1.0;
247 : }
248 1959 : else if (x < 2.0)
249 : {
250 1643 : return ((-0.5 * x + 2.5) * x - 4) * x + 2;
251 : }
252 316 : return 0.0;
253 : }
254 : };
255 :
256 1 : class BilinearKernel : public Kernel {
257 : public:
258 1 : BilinearKernel() : Kernel () {}
259 : private:
260 2 : virtual double GetWidth() const { return 1.0; }
261 1961 : virtual double Calculate (double x) const
262 : {
263 1961 : if (x < 0.0)
264 : {
265 980 : x = -x;
266 : }
267 1961 : if (x < 1.0)
268 : {
269 1643 : return 1.0-x;
270 : }
271 318 : return 0.0;
272 : }
273 : };
274 :
275 1 : class BoxKernel : public Kernel {
276 : public:
277 1 : BoxKernel() : Kernel () {}
278 : private:
279 2 : virtual double GetWidth() const { return 0.5; }
280 1140 : virtual double Calculate (double x) const
281 : {
282 1140 : if (-0.5 <= x && x < 0.5)
283 822 : return 1.0;
284 318 : return 0.0;
285 : }
286 : };
287 :
288 : class BitmapReadAccess;
289 : class BitmapWriteAccess;
290 : class BitmapPalette;
291 : class ImpBitmap;
292 : class Color;
293 : class ResId;
294 : class GDIMetaFile;
295 : class AlphaMask;
296 : class OutputDevice;
297 : class SalBitmap;
298 :
299 : struct BitmapSystemData
300 : {
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;
311 : };
312 :
313 : class VCL_DLLPUBLIC Bitmap
314 : {
315 : private:
316 :
317 : ImpBitmap* mpImpBmp;
318 : MapMode maPrefMapMode;
319 : Size maPrefSize;
320 :
321 : public:
322 :
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 );
328 :
329 : SAL_DLLPRIVATE void ImplAdaptBitCount(Bitmap& rNew) const;
330 : SAL_DLLPRIVATE sal_Bool ImplScaleFast( const double& rScaleX, const double& rScaleY );
331 : SAL_DLLPRIVATE sal_Bool ImplScaleInterpolate( const double& rScaleX, const double& rScaleY );
332 : SAL_DLLPRIVATE sal_Bool ImplScaleSuper( const double& rScaleX, const double& rScaleY );
333 : SAL_DLLPRIVATE sal_Bool ImplScaleConvolution( const double& rScaleX, const double& rScaleY, const Kernel& aKernel);
334 :
335 : SAL_DLLPRIVATE bool ImplConvolutionPass( Bitmap& aNewBitmap, const int nNewSize, BitmapReadAccess* pReadAcc,
336 : int aNumberOfContributions, double* pWeights, int* pPixels, int* pCount );
337 :
338 : SAL_DLLPRIVATE sal_Bool ImplMakeMono( sal_uInt8 cThreshold );
339 : SAL_DLLPRIVATE sal_Bool ImplMakeMonoDither();
340 : SAL_DLLPRIVATE sal_Bool ImplMakeGreyscales( sal_uInt16 nGreyscales );
341 : SAL_DLLPRIVATE sal_Bool ImplConvertUp( sal_uInt16 nBitCount, Color* pExtColor = NULL );
342 : SAL_DLLPRIVATE sal_Bool ImplConvertDown( sal_uInt16 nBitCount, Color* pExtColor = NULL );
343 : SAL_DLLPRIVATE sal_Bool ImplConvertGhosted();
344 : SAL_DLLPRIVATE sal_Bool ImplDitherMatrix();
345 : SAL_DLLPRIVATE sal_Bool ImplDitherFloyd();
346 : SAL_DLLPRIVATE sal_Bool ImplDitherFloyd16();
347 : SAL_DLLPRIVATE sal_Bool ImplReduceSimple( sal_uInt16 nColorCount );
348 : SAL_DLLPRIVATE sal_Bool ImplReducePopular( sal_uInt16 nColorCount );
349 : SAL_DLLPRIVATE sal_Bool ImplReduceMedian( sal_uInt16 nColorCount );
350 : SAL_DLLPRIVATE void ImplMedianCut( sal_uLong* pColBuf, BitmapPalette& rPal,
351 : long nR1, long nR2, long nG1, long nG2, long nB1, long nB2,
352 : long nColors, long nPixels, long& rIndex );
353 : SAL_DLLPRIVATE sal_Bool ImplConvolute3( const long* pMatrix, long nDivisor,
354 : const BmpFilterParam* pFilterParam, const Link* pProgress );
355 : SAL_DLLPRIVATE sal_Bool ImplMedianFilter( const BmpFilterParam* pFilterParam, const Link* pProgress );
356 : SAL_DLLPRIVATE sal_Bool ImplSobelGrey( const BmpFilterParam* pFilterParam, const Link* pProgress );
357 : SAL_DLLPRIVATE sal_Bool ImplEmbossGrey( const BmpFilterParam* pFilterParam, const Link* pProgress );
358 : SAL_DLLPRIVATE sal_Bool ImplSolarize( const BmpFilterParam* pFilterParam, const Link* pProgress );
359 : SAL_DLLPRIVATE sal_Bool ImplSepia( const BmpFilterParam* pFilterParam, const Link* pProgress );
360 : SAL_DLLPRIVATE sal_Bool ImplMosaic( const BmpFilterParam* pFilterParam, const Link* pProgress );
361 : SAL_DLLPRIVATE sal_Bool ImplPopArt( const BmpFilterParam* pFilterParam, const Link* pProgress );
362 :
363 : SAL_DLLPRIVATE bool ImplSeparableBlurFilter( const double aRadius = 0.7 );
364 : SAL_DLLPRIVATE bool ImplSeparableUnsharpenFilter( const double aRadius = 0.7 );
365 : SAL_DLLPRIVATE void ImplBlurContributions( const int aSize, const int aNumberOfContributions,
366 : double* pBlurVector, double*& pWeights, int*& pPixels, int*& pCount );
367 : public:
368 :
369 : Bitmap();
370 : Bitmap( const Bitmap& rBitmap );
371 : Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal = NULL );
372 : Bitmap( const ResId& rResId );
373 : Bitmap( SalBitmap* pSalBitmap );
374 : virtual ~Bitmap();
375 :
376 : Bitmap& operator=( const Bitmap& rBitmap );
377 : inline sal_Bool operator!() const;
378 : inline sal_Bool operator==( const Bitmap& rBitmap ) const;
379 : inline sal_Bool operator!=( const Bitmap& rBitmap ) const;
380 :
381 : inline sal_Bool IsSameInstance( const Bitmap& rBmp ) const;
382 : sal_Bool IsEqual( const Bitmap& rBmp ) const;
383 :
384 : inline sal_Bool IsEmpty() const;
385 : void SetEmpty();
386 :
387 : inline const MapMode& GetPrefMapMode() const;
388 : inline void SetPrefMapMode( const MapMode& rMapMode );
389 :
390 : inline const Size& GetPrefSize() const;
391 : inline void SetPrefSize( const Size& rSize );
392 :
393 : Size GetSizePixel() const;
394 :
395 : /**
396 : * The pixel size of a bitmap's source (e.g. an image file)
397 : * and the pixel size of its resulting bitmap can differ,
398 : * e.g. when the image reader has its preview mode enabled.
399 : */
400 : void SetSourceSizePixel( const Size& );
401 :
402 : sal_uInt16 GetBitCount() const;
403 : inline sal_uLong GetColorCount() const;
404 : inline sal_uLong GetSizeBytes() const;
405 : sal_Bool HasGreyPalette() const;
406 : /** get system dependent bitmap data
407 :
408 : @param rData
409 : The system dependent BitmapSystemData structure to be filled
410 :
411 : @return sal_True if the bitmap has a valid system object (e.g. not empty)
412 : */
413 : bool GetSystemData( BitmapSystemData& rData ) const;
414 :
415 : sal_uLong GetChecksum() const;
416 :
417 : Bitmap CreateDisplayBitmap( OutputDevice* pDisplay );
418 : Bitmap GetColorTransformedBitmap() const;
419 :
420 : static const BitmapPalette& GetGreyPalette( int nEntries );
421 :
422 : public:
423 :
424 : sal_Bool MakeMono( sal_uInt8 cThreshold );
425 :
426 :
427 : /** Convert bitmap format
428 :
429 : @param eConversion
430 : The format this bitmap should be converted to.
431 :
432 : @return sal_True, if the conversion was completed successfully.
433 : */
434 : sal_Bool Convert( BmpConversion eConversion );
435 :
436 : /** Reduce number of colors for the bitmap
437 :
438 : @param nNewColorCount
439 : Maximal number of bitmap colors after the reduce operation
440 :
441 : @param eReduce
442 : Algorithm to use for color reduction
443 :
444 : @return sal_True, if the color reduction operation was completed successfully.
445 : */
446 : sal_Bool ReduceColors( sal_uInt16 nNewColorCount,
447 : BmpReduce eReduce = BMP_REDUCE_SIMPLE );
448 :
449 : /** Apply a dither algorithm to the bitmap
450 :
451 : This method dithers the bitmap inplace, i.e. a true color
452 : bitmap is converted to a paletted bitmap, reducing the color
453 : deviation by error diffusion.
454 :
455 : @param nDitherFlags
456 : The algorithm to be used for dithering
457 :
458 : @param pDitherPal
459 : A custom palette to be used when dithering (not yet implemented, leave NULL)
460 : */
461 : sal_Bool Dither( sal_uLong nDitherFlags = BMP_DITHER_MATRIX );
462 :
463 : /** Crop the bitmap
464 :
465 : @param rRectPixel
466 : A rectangle specifying the crop amounts on all four sides of
467 : the bitmap. If the upper left corner of the bitmap is assigned
468 : (0,0), then this method cuts out the given rectangle from the
469 : bitmap. Note that the rectangle is clipped to the bitmap's
470 : dimension, i.e. negative left,top rectangle coordinates or
471 : exceeding width or height is ignored.
472 :
473 : @return sal_True, if cropping was performed successfully. If
474 : nothing had to be cropped, because e.g. the crop rectangle
475 : included the bitmap, sal_False is returned, too!
476 : */
477 : sal_Bool Crop( const Rectangle& rRectPixel );
478 :
479 : /** Expand the bitmap by pixel padding
480 :
481 : @param nDX
482 : Number of pixel to pad at the right border of the bitmap
483 :
484 : @param nDY
485 : Number of scanlines to pad at the bottom border of the bitmap
486 :
487 : @param pInitColor
488 : Color to use for padded pixel
489 :
490 : @return sal_True, if padding was performed successfully. sal_False is
491 : not only returned when the operation failed, but also if
492 : nothing had to be done, e.g. because nDX and nDY were zero.
493 : */
494 : sal_Bool Expand( sal_uLong nDX, sal_uLong nDY,
495 : const Color* pInitColor = NULL );
496 :
497 : /** Copy a rectangular area from another bitmap
498 :
499 : @param rRectDst
500 : Destination rectangle in this bitmap. This is clipped to the
501 : bitmap dimensions.
502 :
503 : @param rRectSrc
504 : Source rectangle in pBmpSrc. This is clipped to the source
505 : bitmap dimensions. Note further that no scaling takes place
506 : during this copy operation, i.e. only the minimum of source
507 : and destination rectangle's width and height are used.
508 :
509 : @param pBmpSrc
510 : The source bitmap to copy from. If this argument is NULL, or
511 : equal to the object this method is called on, copying takes
512 : place within the same bitmap.
513 :
514 : @return sal_True, if the operation completed successfully. sal_False
515 : is not only returned when the operation failed, but also if
516 : nothing had to be done, e.g. because one of the rectangles are
517 : empty.
518 : */
519 : sal_Bool CopyPixel( const Rectangle& rRectDst,
520 : const Rectangle& rRectSrc,
521 : const Bitmap* pBmpSrc = NULL );
522 :
523 : /** Perform boolean operations with another bitmap
524 :
525 : @param rMask
526 : The mask bitmap in the selected combine operation
527 :
528 : @param eCombine
529 : The combine operation to perform on the bitmap
530 :
531 : @return sal_True, if the operation was completed successfully.
532 : */
533 : sal_Bool CombineSimple( const Bitmap& rMask,
534 : BmpCombine eCombine );
535 :
536 : /** Alpha-blend the given bitmap against a specified uniform
537 : background color.
538 :
539 : @attention This method might convert paletted bitmaps to
540 : truecolor, to be able to represent every necessary color. Note
541 : that during alpha blending, lots of colors not originally
542 : included in the bitmap can be generated.
543 :
544 : @param rAlpha
545 : Alpha mask to blend with
546 :
547 : @param rBackgroundColor
548 : Background color to use for every pixel during alpha blending
549 :
550 : @return sal_True, if blending was successful, sal_False otherwise
551 : */
552 : sal_Bool Blend( const AlphaMask& rAlpha,
553 : const Color& rBackgroundColor );
554 :
555 : /** Fill the entire bitmap with the given color
556 :
557 : @param rFillColor
558 : Color value to use for filling
559 :
560 : @return sal_True, if the operation was completed successfully.
561 : */
562 : sal_Bool Erase( const Color& rFillColor );
563 :
564 : /** Perform the Invert operation on every pixel
565 :
566 : @return sal_True, if the operation was completed successfully.
567 : */
568 : sal_Bool Invert();
569 :
570 : /** Mirror the bitmap
571 :
572 : @param nMirrorFlags
573 : About which axis (horizontal, vertical, or both) to mirror
574 :
575 : @return sal_True, if the operation was completed successfully.
576 : */
577 : sal_Bool Mirror( sal_uLong nMirrorFlags );
578 :
579 : /** Scale the bitmap
580 :
581 : @param rNewSize
582 : The resulting size of the scaled bitmap
583 :
584 : @param nScaleFlag
585 : The algorithm to be used for scaling
586 :
587 : @return sal_True, if the operation was completed successfully.
588 : */
589 : sal_Bool Scale( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
590 :
591 : /** Scale the bitmap
592 :
593 : @param rScaleX
594 : The scale factor in x direction.
595 :
596 : @param rScaleY
597 : The scale factor in y direction.
598 :
599 : @return sal_True, if the operation was completed successfully.
600 : */
601 : sal_Bool Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
602 :
603 : // Adapt the BitCount of rNew to BitCount of lolal, including grey or color paltette
604 : // Can be used to create alpha/mask bitmaps after their processing in 24bit
605 : void AdaptBitCount(Bitmap& rNew) const;
606 :
607 : /** Rotate bitmap by the specified angle
608 :
609 : @param nAngle10
610 : The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
611 :
612 : @param rFillColor
613 : The color to use for filling blank areas. During rotation, the
614 : bitmap is enlarged such that the whole rotation result fits
615 : in. The empty spaces around that rotated original bitmap are
616 : then filled with this color.
617 :
618 : @return sal_True, if the operation was completed successfully.
619 : */
620 : sal_Bool Rotate( long nAngle10, const Color& rFillColor );
621 :
622 : /** Create on-off mask from bitmap
623 :
624 : This method creates a bitmask from the bitmap, where every
625 : pixel that equals rTransColor is set transparent, the rest
626 : opaque.
627 :
628 : @param rTransColor
629 : Color value where the bitmask should be transparent
630 :
631 : @param nTol
632 : Tolerance value. Specifies the maximal difference between
633 : rTransColor and the individual pixel values, such that the
634 : corresponding pixel is still regarded transparent.
635 :
636 : @return the resulting bitmask.
637 : */
638 : Bitmap CreateMask( const Color& rTransColor, sal_uLong nTol = 0UL ) const;
639 :
640 : /** Create region of similar colors in a given rectangle
641 :
642 : @param rColor
643 : All pixel which have this color are included in the calculated region
644 :
645 : @param rRect
646 : The rectangle within which matching pixel are looked for. This
647 : rectangle is always clipped to the bitmap dimensions.
648 :
649 : @return the generated region.
650 : */
651 : Region CreateRegion( const Color& rColor, const Rectangle& rRect ) const;
652 :
653 : /** Replace all pixel where the given mask is on with the specified color
654 :
655 : @param rMask
656 : Mask specifying which pixel should be replaced
657 :
658 : @param rReplaceColor
659 : Color to be placed in all changed pixel
660 :
661 : @return sal_True, if the operation was completed successfully.
662 : */
663 : sal_Bool Replace( const Bitmap& rMask, const Color& rReplaceColor );
664 :
665 : /** Merge bitmap with given background color according to specified alpha mask
666 :
667 : @param rAlpha
668 : Alpha mask specifying the amount of background color to merge in
669 :
670 : @param rMergeColor
671 : Background color to be used for merging
672 :
673 : @return sal_True, if the operation was completed successfully.
674 : */
675 : sal_Bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
676 :
677 : /** Replace all pixel having the search color with the specified color
678 :
679 : @param rSearchColor
680 : Color specifying which pixel should be replaced
681 :
682 : @param rReplaceColor
683 : Color to be placed in all changed pixel
684 :
685 : @param nTol
686 : Tolerance value. Specifies the maximal difference between
687 : rSearchColor and the individual pixel values, such that the
688 : corresponding pixel is still regarded a match.
689 :
690 : @return sal_True, if the operation was completed successfully.
691 : */
692 : sal_Bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
693 :
694 : /** Replace all pixel having one the search colors with the corresponding replace color
695 :
696 : @param pSearchColor
697 : Array of colors specifying which pixel should be replaced
698 :
699 : @param pReplaceColor
700 : Array of colors to be placed in all changed pixel
701 :
702 : @param nColorCount
703 : Size of the aforementioned color arrays
704 :
705 : @param nTol
706 : Tolerance value. Specifies the maximal difference between
707 : pSearchColor colors and the individual pixel values, such that
708 : the corresponding pixel is still regarded a match.
709 :
710 : @return sal_True, if the operation was completed successfully.
711 : */
712 : sal_Bool Replace( const Color* pSearchColors, const Color* rReplaceColors,
713 : sal_uLong nColorCount, sal_uLong* pTols = NULL );
714 :
715 : /** Convert the bitmap to a PolyPolygon
716 :
717 : This works by putting continuous areas of the same color into
718 : a polygon, by tracing its bounding line.
719 :
720 : @param rPolyPoly
721 : The resulting PolyPolygon
722 :
723 : @param nFlags
724 : Whether the inline or the outline of the color areas should be
725 : represented by the polygon
726 :
727 : @param pProgress
728 : A callback for showing the progress of the vectorization
729 :
730 : @return sal_True, if the operation was completed successfully.
731 : */
732 : sal_Bool Vectorize( PolyPolygon& rPolyPoly,
733 : sal_uLong nFlags = BMP_VECTORIZE_OUTER,
734 : const Link* pProgress = NULL );
735 :
736 : /** Convert the bitmap to a meta file
737 :
738 : This works by putting continuous areas of the same color into
739 : polygons painted in this color, by tracing the area's bounding
740 : line.
741 :
742 : @param rMtf
743 : The resulting meta file
744 :
745 : @param cReduce
746 : If non-null, minimal size of bound rects for individual polygons. Smaller ones are ignored.
747 :
748 : @param nFlags
749 : Whether the inline or the outline of the color areas should be
750 : represented by the polygon
751 :
752 : @param pProgress
753 : A callback for showing the progress of the vectorization
754 :
755 : @return sal_True, if the operation was completed successfully.
756 : */
757 : sal_Bool Vectorize( GDIMetaFile& rMtf, sal_uInt8 cReduce = 0,
758 : sal_uLong nFlags = BMP_VECTORIZE_INNER,
759 : const Link* pProgress = NULL );
760 :
761 : /** Change various global color characteristics
762 :
763 : @param nLuminancePercent
764 : Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
765 :
766 : @param nContrastPercent
767 : Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
768 :
769 : @param nChannelRPercent
770 : Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
771 :
772 : @param nChannelGPercent
773 : Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
774 :
775 : @param nChannelBPercent
776 : Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
777 :
778 : @param fGamma
779 : Exponent of the gamma function applied to the bitmap. The
780 : value 1.0 results in no change, the valid range is
781 : (0.0,10.0]. Values outside this range are regarded as 1.0.
782 :
783 : @param bInvert
784 : If sal_True, invert the channel values with the logical 'not' operator
785 :
786 : @return sal_True, if the operation was completed successfully.
787 : */
788 : sal_Bool Adjust( short nLuminancePercent = 0,
789 : short nContrastPercent = 0,
790 : short nChannelRPercent = 0,
791 : short nChannelGPercent = 0,
792 : short nChannelBPercent = 0,
793 : double fGamma = 1.0,
794 : sal_Bool bInvert = sal_False );
795 :
796 : /** Apply specified filter to the bitmap
797 :
798 : @param eFilter
799 : The filter algorithm to apply
800 :
801 : @param pFilterParam
802 : Various parameter for the different bitmap filter algorithms
803 :
804 : @param pProgress
805 : A callback for showing the progress of the vectorization
806 :
807 : @return sal_True, if the operation was completed successfully.
808 : */
809 : sal_Bool Filter( BmpFilter eFilter,
810 : const BmpFilterParam* pFilterParam = NULL,
811 : const Link* pProgress = NULL );
812 :
813 : public:
814 :
815 : BitmapReadAccess* AcquireReadAccess();
816 : BitmapWriteAccess* AcquireWriteAccess();
817 : void ReleaseAccess( BitmapReadAccess* pAccess );
818 :
819 : typedef vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap, &Bitmap::AcquireReadAccess >
820 : ScopedReadAccess;
821 : typedef vcl::ScopedBitmapAccess< BitmapWriteAccess, Bitmap, &Bitmap::AcquireWriteAccess >
822 : ScopedWriteAccess;
823 : };
824 :
825 315716 : inline sal_Bool Bitmap::operator!() const
826 : {
827 315716 : return( mpImpBmp == NULL );
828 : }
829 :
830 1580 : inline sal_Bool Bitmap::operator==( const Bitmap& rBitmap ) const
831 : {
832 1580 : return( rBitmap.mpImpBmp == mpImpBmp );
833 : }
834 :
835 10104 : inline sal_Bool Bitmap::operator!=( const Bitmap& rBitmap ) const
836 : {
837 10104 : return( rBitmap.mpImpBmp != mpImpBmp );
838 : }
839 :
840 0 : inline sal_Bool Bitmap::IsSameInstance( const Bitmap& rBitmap ) const
841 : {
842 0 : return( rBitmap.mpImpBmp == mpImpBmp );
843 : }
844 :
845 761924 : inline sal_Bool Bitmap::IsEmpty() const
846 : {
847 761924 : return( mpImpBmp == NULL );
848 : }
849 :
850 2696 : inline const MapMode& Bitmap::GetPrefMapMode() const
851 : {
852 2696 : return maPrefMapMode;
853 : }
854 :
855 2510 : inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
856 : {
857 2510 : maPrefMapMode = rMapMode;
858 2510 : }
859 :
860 8546 : inline const Size& Bitmap::GetPrefSize() const
861 : {
862 8546 : return maPrefSize;
863 : }
864 :
865 2753 : inline void Bitmap::SetPrefSize( const Size& rSize )
866 : {
867 2753 : maPrefSize = rSize;
868 2753 : }
869 :
870 0 : inline sal_uLong Bitmap::GetColorCount() const
871 : {
872 0 : return( 1UL << (sal_uLong) GetBitCount() );
873 : }
874 :
875 3516 : inline sal_uLong Bitmap::GetSizeBytes() const
876 : {
877 3516 : const Size aSizePix( GetSizePixel() );
878 3516 : return( ( (sal_uLong) aSizePix.Width() * aSizePix.Height() * GetBitCount() ) >> 3UL );
879 : }
880 :
881 : #endif // _SV_BITMAP_HXX
882 :
883 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|