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