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