bump product version to 4.2.0.1
[LibreOffice.git] / include / vcl / bitmapex.hxx
blobda23547dfdd82ccb9027e79b68cb2105eb4ae332
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_BITMAPEX_HXX
21 #define INCLUDED_VCL_BITMAPEX_HXX
23 #include <vcl/dllapi.h>
24 #include <vcl/bitmap.hxx>
25 #include <vcl/alpha.hxx>
26 #include <tools/color.hxx>
27 #include <basegfx/color/bcolormodifier.hxx>
29 #include <com/sun/star/uno/Reference.hxx>
31 namespace com { namespace sun { namespace star { namespace rendering {
32 class XBitmapCanvas;
33 } } } }
35 // -------------------
36 // - TransparentType -
37 // -------------------
39 enum TransparentType
41 TRANSPARENT_NONE,
42 TRANSPARENT_COLOR,
43 TRANSPARENT_BITMAP
46 // ------------
47 // - BitmapEx -
48 // ------------
50 class VCL_DLLPUBLIC BitmapEx
52 private:
53 friend class ImpGraphic;
54 friend bool VCL_DLLPUBLIC WriteDIBBitmapEx(const BitmapEx& rSource, SvStream& rOStm);
56 Bitmap aBitmap;
57 Bitmap aMask;
58 Size aBitmapSize;
59 Color aTransparentColor;
60 TransparentType eTransparent;
61 sal_Bool bAlpha;
63 public:
66 SAL_DLLPRIVATE ImpBitmap* ImplGetBitmapImpBitmap() const { return aBitmap.ImplGetImpBitmap(); }
67 SAL_DLLPRIVATE ImpBitmap* ImplGetMaskImpBitmap() const { return aMask.ImplGetImpBitmap(); }
69 BitmapEx();
70 BitmapEx( const ResId& rResId );
71 BitmapEx( const BitmapEx& rBitmapEx );
72 BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize );
73 BitmapEx( const Bitmap& rBmp );
74 BitmapEx( const Bitmap& rBmp, const Bitmap& rMask );
75 BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask );
76 BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor );
77 ~BitmapEx();
79 BitmapEx& operator=( const BitmapEx& rBitmapEx );
80 sal_Bool operator==( const BitmapEx& rBitmapEx ) const;
81 sal_Bool operator!=( const BitmapEx& rBitmapEx ) const { return !(*this==rBitmapEx); }
82 sal_Bool operator!() const { return !aBitmap; }
84 sal_Bool IsEqual( const BitmapEx& rBmpEx ) const;
86 sal_Bool IsEmpty() const;
87 void SetEmpty();
88 void Clear();
90 void Draw( OutputDevice* pOutDev,
91 const Point& rDestPt ) const;
92 void Draw( OutputDevice* pOutDev,
93 const Point& rDestPt, const Size& rDestSize ) const;
95 sal_Bool IsTransparent() const;
96 TransparentType GetTransparentType() const { return eTransparent; }
98 Bitmap GetBitmap( const Color* pTransReplaceColor = NULL ) const;
99 Bitmap GetMask() const;
101 BitmapEx GetColorTransformedBitmapEx() const;
103 sal_Bool IsAlpha() const;
104 AlphaMask GetAlpha() const;
106 const Size& GetSizePixel() const { return aBitmapSize; }
107 void SetSizePixel( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
109 const Size& GetPrefSize() const { return aBitmap.GetPrefSize(); }
110 void SetPrefSize( const Size& rPrefSize ) { aBitmap.SetPrefSize( rPrefSize ); }
112 const MapMode& GetPrefMapMode() const { return aBitmap.GetPrefMapMode(); }
113 void SetPrefMapMode( const MapMode& rPrefMapMode ) { aBitmap.SetPrefMapMode( rPrefMapMode ); }
115 const Color& GetTransparentColor() const { return aTransparentColor; }
116 void SetTransparentColor( const Color& rColor ) { aTransparentColor = rColor; }
118 sal_uInt16 GetBitCount() const { return aBitmap.GetBitCount(); }
119 sal_uLong GetSizeBytes() const;
120 sal_uLong GetChecksum() const;
122 public:
124 /** Convert bitmap format
126 @param eConversion
127 The format this bitmap should be converted to.
129 @return sal_True, if the conversion was completed successfully.
131 sal_Bool Convert( BmpConversion eConversion );
133 /** Reduce number of colors for the bitmap
135 @param nNewColorCount
136 Maximal number of bitmap colors after the reduce operation
138 @param eReduce
139 Algorithm to use for color reduction
141 @return sal_True, if the color reduction operation was completed successfully.
143 sal_Bool ReduceColors( sal_uInt16 nNewColorCount,
144 BmpReduce eReduce = BMP_REDUCE_SIMPLE );
146 /** Apply a dither algorithm to the bitmap
148 This method dithers the bitmap inplace, i.e. a true color
149 bitmap is converted to a paletted bitmap, reducing the color
150 deviation by error diffusion.
152 @param nDitherFlags
153 The algorithm to be used for dithering
155 sal_Bool Dither( sal_uLong nDitherFlags = BMP_DITHER_MATRIX );
157 /** Crop the bitmap
159 @param rRectPixel
160 A rectangle specifying the crop amounts on all four sides of
161 the bitmap. If the upper left corner of the bitmap is assigned
162 (0,0), then this method cuts out the given rectangle from the
163 bitmap. Note that the rectangle is clipped to the bitmap's
164 dimension, i.e. negative left,top rectangle coordinates or
165 exceeding width or height is ignored.
167 @return sal_True, if cropping was performed successfully. If
168 nothing had to be cropped, because e.g. the crop rectangle
169 included the bitmap, sal_False is returned, too!
171 sal_Bool Crop( const Rectangle& rRectPixel );
173 /** Expand the bitmap by pixel padding
175 @param nDX
176 Number of pixel to pad at the right border of the bitmap
178 @param nDY
179 Number of scanlines to pad at the bottom border of the bitmap
181 @param pInitColor
182 Color to use for padded pixel
184 @return sal_True, if padding was performed successfully. sal_False is
185 not only returned when the operation failed, but also if
186 nothing had to be done, e.g. because nDX and nDY were zero.
188 sal_Bool Expand( sal_uLong nDX, sal_uLong nDY,
189 const Color* pInitColor = NULL,
190 sal_Bool bExpandTransparent = sal_False );
192 /** Copy a rectangular area from another bitmap
194 @param rRectDst
195 Destination rectangle in this bitmap. This is clipped to the
196 bitmap dimensions.
198 @param rRectSrc
199 Source rectangle in pBmpSrc. This is clipped to the source
200 bitmap dimensions. Note further that no scaling takes place
201 during this copy operation, i.e. only the minimum of source
202 and destination rectangle's width and height are used.
204 @param pBmpSrc
205 The source bitmap to copy from. If this argument is NULL, or
206 equal to the object this method is called on, copying takes
207 place within the same bitmap.
209 @return sal_True, if the operation completed successfully. sal_False
210 is not only returned when the operation failed, but also if
211 nothing had to be done, e.g. because one of the rectangles are
212 empty.
214 sal_Bool CopyPixel( const Rectangle& rRectDst,
215 const Rectangle& rRectSrc,
216 const BitmapEx* pBmpExSrc = NULL );
218 /** Fill the entire bitmap with the given color
220 @param rFillColor
221 Color value to use for filling. Set the transparency part of
222 the color to fill the mask.
224 @return sal_True, if the operation was completed successfully.
226 sal_Bool Erase( const Color& rFillColor );
228 /** Perform the Invert operation on every pixel
230 @return sal_True, if the operation was completed successfully.
232 sal_Bool Invert();
234 /** Mirror the bitmap
236 @param nMirrorFlags
237 About which axis (horizontal, vertical, or both) to mirror
239 @return sal_True, if the operation was completed successfully.
241 sal_Bool Mirror( sal_uLong nMirrorFlags );
243 /** Scale the bitmap
245 @param rNewSize
246 The resulting size of the scaled bitmap
248 @param nScaleFlag
249 The algorithm to be used for scaling
251 @return sal_True, if the operation was completed successfully.
253 sal_Bool Scale( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
255 /** Scale the bitmap
257 @param rScaleX
258 The scale factor in x direction.
260 @param rScaleY
261 The scale factor in y direction.
263 @return sal_True, if the operation was completed successfully.
265 sal_Bool Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
267 /** Rotate bitmap by the specified angle
269 @param nAngle10
270 The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
272 @param rFillColor
273 The color to use for filling blank areas. During rotation, the
274 bitmap is enlarged such that the whole rotation result fits
275 in. The empty spaces around that rotated original bitmap are
276 then filled with this color.
278 @return sal_True, if the operation was completed successfully.
280 sal_Bool Rotate( long nAngle10, const Color& rFillColor );
282 /** Replace all pixel having the search color with the specified color
284 @param rSearchColor
285 Color specifying which pixel should be replaced
287 @param rReplaceColor
288 Color to be placed in all changed pixel
290 @param nTol
291 Tolerance value. Specifies the maximal difference between
292 rSearchColor and the individual pixel values, such that the
293 corresponding pixel is still regarded a match.
295 @return sal_True, if the operation was completed successfully.
297 sal_Bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
299 /** Replace all pixel having one the search colors with the corresponding replace color
301 @param pSearchColor
302 Array of colors specifying which pixel should be replaced
304 @param pReplaceColor
305 Array of colors to be placed in all changed pixel
307 @param nColorCount
308 Size of the aforementioned color arrays
310 @param nTol
311 Tolerance value. Specifies the maximal difference between
312 pSearchColor colors and the individual pixel values, such that
313 the corresponding pixel is still regarded a match.
315 @return sal_True, if the operation was completed successfully.
317 sal_Bool Replace( const Color* pSearchColors, const Color* pReplaceColors,
318 sal_uLong nColorCount, const sal_uLong* pTols = NULL );
320 /** Change various global color characteristics
322 @param nLuminancePercent
323 Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
325 @param nContrastPercent
326 Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
328 @param nChannelRPercent
329 Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
331 @param nChannelGPercent
332 Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
334 @param nChannelBPercent
335 Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
337 @param fGamma
338 Exponent of the gamma function applied to the bitmap. The
339 value 1.0 results in no change, the valid range is
340 (0.0,10.0]. Values outside this range are regarded as 1.0.
342 @param bInvert
343 If sal_True, invert the channel values with the logical 'not' operator
345 @return sal_True, if the operation was completed successfully.
347 sal_Bool Adjust( short nLuminancePercent = 0,
348 short nContrastPercent = 0,
349 short nChannelRPercent = 0,
350 short nChannelGPercent = 0,
351 short nChannelBPercent = 0,
352 double fGamma = 1.0,
353 sal_Bool bInvert = sal_False );
355 /** Apply specified filter to the bitmap
357 @param eFilter
358 The filter algorithm to apply
360 @param pFilterParam
361 Various parameter for the different bitmap filter algorithms
363 @param pProgress
364 A callback for showing the progress of the vectorization
366 @return sal_True, if the operation was completed successfully.
368 sal_Bool Filter( BmpFilter eFilter,
369 const BmpFilterParam* pFilterParam = NULL,
370 const Link* pProgress = NULL );
372 /** Get transparency at given position
374 @param nX
375 integer X-Position in Bitmap
377 @param nY
378 integer Y-Position in Bitmap
380 @return transparency value in the range of [0 .. 255] where
381 0 is not transparent, 255 is fully transparent
383 sal_uInt8 GetTransparency(sal_Int32 nX, sal_Int32 nY) const;
385 /** Create transformed Bitmap
387 @param fWidth
388 The target width in pixels
390 @param fHeight
391 The target height in pixels
393 @param rTransformation
394 The back transformation for each pixel in (0 .. fWidth),(0 .. fHeight) to
395 local pixel coordiantes
397 @param bSmooth
398 Defines if pixel interpolation is to be used to create the result
400 BitmapEx TransformBitmapEx(
401 double fWidth,
402 double fHeight,
403 const basegfx::B2DHomMatrix& rTransformation,
404 bool bSmooth = true) const;
406 /** Create transformed Bitmap
408 @param rTransformation
409 The transformation from unit coordinates to the unit range
411 @param rVisibleRange
412 The relative visible range in unit coordinates, relative to (0,0,1,1) which
413 defines the whole target area
415 @param fMaximumArea
416 A limitation for the maximum size of pixels to use for the result
418 @param bSmooth
419 Defines if pixel interpolation is to be used to create the result
421 The traget size of the result bitmap is defined by transforming the given
422 rTargetRange with the given rTransformation; the area of the result is
423 linearly scaled to not exceed the given fMaximumArea
425 @return The transformed bitmap
427 BitmapEx getTransformed(
428 const basegfx::B2DHomMatrix& rTransformation,
429 const basegfx::B2DRange& rVisibleRange,
430 double fMaximumArea = 500000.0,
431 bool bSmooth = true) const;
433 /** Create ColorStack-modified version of this BitmapEx
435 @param rBColorModifierStack
436 A ColrModifierStack which defines how each pixel has to be modified
438 BitmapEx ModifyBitmapEx(const basegfx::BColorModifierStack& rBColorModifierStack) const;
440 public:
442 static BitmapEx AutoScaleBitmap(BitmapEx & aBitmap, const long aStandardSize);
444 /// populate from a canvas implementation
445 bool Create( const ::com::sun::star::uno::Reference<
446 ::com::sun::star::rendering::XBitmapCanvas > &xBitmapCanvas,
447 const Size &rSize );
450 // ------------------------------------------------------------------
451 /** Create a blend frame as BitmapEx
453 @param nAlpha
454 The blend value defines how strong the frame will be blended with the
455 existing content, 255 == full coverage, 0 == no frame will be drawn
457 @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft
458 The colors defining the frame. If the version without aColorTopRight and
459 aColorBottomLeft is used, these colors are linearly interpolated from
460 aColorTopLeft and aColorBottomRight using the width and height of the area
462 @param rSize
463 The size of the frame in pixels
466 BitmapEx VCL_DLLPUBLIC createBlendFrame(
467 const Size& rSize,
468 sal_uInt8 nAlpha,
469 Color aColorTopLeft,
470 Color aColorBottomRight);
472 BitmapEx VCL_DLLPUBLIC createBlendFrame(
473 const Size& rSize,
474 sal_uInt8 nAlpha,
475 Color aColorTopLeft,
476 Color aColorTopRight,
477 Color aColorBottomRight,
478 Color aColorBottomLeft);
480 // ------------------------------------------------------------------
482 #endif // INCLUDED_VCL_BITMAPEX_HXX
484 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */