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