update credits
[LibreOffice.git] / include / vcl / bitmapex.hxx
blob00a3c4e83886bda2d5929e4ddf1875f2be5f6db4
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 _SV_BITMAPEX_HXX
21 #define _SV_BITMAPEX_HXX
23 #include <vcl/dllapi.h>
24 #include <vcl/bitmap.hxx>
25 #include <vcl/alpha.hxx>
26 #include <tools/color.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
30 namespace com { namespace sun { namespace star { namespace rendering {
31 class XBitmapCanvas;
32 } } } }
34 // -------------------
35 // - TransparentType -
36 // -------------------
38 enum TransparentType
40 TRANSPARENT_NONE,
41 TRANSPARENT_COLOR,
42 TRANSPARENT_BITMAP
45 // ------------
46 // - BitmapEx -
47 // ------------
49 class VCL_DLLPUBLIC BitmapEx
51 friend class ImpGraphic;
53 private:
55 Bitmap aBitmap;
56 Bitmap aMask;
57 Size aBitmapSize;
58 Color aTransparentColor;
59 TransparentType eTransparent;
60 sal_Bool bAlpha;
62 public:
65 SAL_DLLPRIVATE ImpBitmap* ImplGetBitmapImpBitmap() const { return aBitmap.ImplGetImpBitmap(); }
66 SAL_DLLPRIVATE ImpBitmap* ImplGetMaskImpBitmap() const { return aMask.ImplGetImpBitmap(); }
68 public:
70 BitmapEx();
71 BitmapEx( const ResId& rResId );
72 BitmapEx( const BitmapEx& rBitmapEx );
73 BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize );
74 BitmapEx( const Bitmap& rBmp );
75 BitmapEx( const Bitmap& rBmp, const Bitmap& rMask );
76 BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask );
77 BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor );
78 ~BitmapEx();
80 BitmapEx& operator=( const BitmapEx& rBitmapEx );
81 sal_Bool operator==( const BitmapEx& rBitmapEx ) const;
82 sal_Bool operator!=( const BitmapEx& rBitmapEx ) const { return !(*this==rBitmapEx); }
83 sal_Bool operator!() const { return !aBitmap; }
85 sal_Bool IsEqual( const BitmapEx& rBmpEx ) const;
87 sal_Bool IsEmpty() const;
88 void SetEmpty();
89 void Clear();
91 void Draw( OutputDevice* pOutDev,
92 const Point& rDestPt ) const;
93 void Draw( OutputDevice* pOutDev,
94 const Point& rDestPt, const Size& rDestSize ) const;
96 sal_Bool IsTransparent() const;
97 TransparentType GetTransparentType() const { return eTransparent; }
99 Bitmap GetBitmap( const Color* pTransReplaceColor = NULL ) const;
100 Bitmap GetMask() const;
102 BitmapEx GetColorTransformedBitmapEx() const;
104 sal_Bool IsAlpha() const;
105 AlphaMask GetAlpha() const;
107 const Size& GetSizePixel() const { return aBitmapSize; }
108 void SetSizePixel( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
110 const Size& GetPrefSize() const { return aBitmap.GetPrefSize(); }
111 void SetPrefSize( const Size& rPrefSize ) { aBitmap.SetPrefSize( rPrefSize ); }
113 const MapMode& GetPrefMapMode() const { return aBitmap.GetPrefMapMode(); }
114 void SetPrefMapMode( const MapMode& rPrefMapMode ) { aBitmap.SetPrefMapMode( rPrefMapMode ); }
116 const Color& GetTransparentColor() const { return aTransparentColor; }
117 void SetTransparentColor( const Color& rColor ) { aTransparentColor = rColor; }
119 sal_uInt16 GetBitCount() const { return aBitmap.GetBitCount(); }
120 sal_uLong GetSizeBytes() const;
121 sal_uLong GetChecksum() const;
123 public:
125 /** Convert bitmap format
127 @param eConversion
128 The format this bitmap should be converted to.
130 @return sal_True, if the conversion was completed successfully.
132 sal_Bool Convert( BmpConversion eConversion );
134 /** Reduce number of colors for the bitmap
136 @param nNewColorCount
137 Maximal number of bitmap colors after the reduce operation
139 @param eReduce
140 Algorithm to use for color reduction
142 @return sal_True, if the color reduction operation was completed successfully.
144 sal_Bool ReduceColors( sal_uInt16 nNewColorCount,
145 BmpReduce eReduce = BMP_REDUCE_SIMPLE );
147 /** Apply a dither algorithm to the bitmap
149 This method dithers the bitmap inplace, i.e. a true color
150 bitmap is converted to a paletted bitmap, reducing the color
151 deviation by error diffusion.
153 @param nDitherFlags
154 The algorithm to be used for dithering
156 sal_Bool Dither( sal_uLong nDitherFlags = BMP_DITHER_MATRIX );
158 /** Crop the bitmap
160 @param rRectPixel
161 A rectangle specifying the crop amounts on all four sides of
162 the bitmap. If the upper left corner of the bitmap is assigned
163 (0,0), then this method cuts out the given rectangle from the
164 bitmap. Note that the rectangle is clipped to the bitmap's
165 dimension, i.e. negative left,top rectangle coordinates or
166 exceeding width or height is ignored.
168 @return sal_True, if cropping was performed successfully. If
169 nothing had to be cropped, because e.g. the crop rectangle
170 included the bitmap, sal_False is returned, too!
172 sal_Bool Crop( const Rectangle& rRectPixel );
174 /** Expand the bitmap by pixel padding
176 @param nDX
177 Number of pixel to pad at the right border of the bitmap
179 @param nDY
180 Number of scanlines to pad at the bottom border of the bitmap
182 @param pInitColor
183 Color to use for padded pixel
185 @return sal_True, if padding was performed successfully. sal_False is
186 not only returned when the operation failed, but also if
187 nothing had to be done, e.g. because nDX and nDY were zero.
189 sal_Bool Expand( sal_uLong nDX, sal_uLong nDY,
190 const Color* pInitColor = NULL,
191 sal_Bool bExpandTransparent = sal_False );
193 /** Copy a rectangular area from another bitmap
195 @param rRectDst
196 Destination rectangle in this bitmap. This is clipped to the
197 bitmap dimensions.
199 @param rRectSrc
200 Source rectangle in pBmpSrc. This is clipped to the source
201 bitmap dimensions. Note further that no scaling takes place
202 during this copy operation, i.e. only the minimum of source
203 and destination rectangle's width and height are used.
205 @param pBmpSrc
206 The source bitmap to copy from. If this argument is NULL, or
207 equal to the object this method is called on, copying takes
208 place within the same bitmap.
210 @return sal_True, if the operation completed successfully. sal_False
211 is not only returned when the operation failed, but also if
212 nothing had to be done, e.g. because one of the rectangles are
213 empty.
215 sal_Bool CopyPixel( const Rectangle& rRectDst,
216 const Rectangle& rRectSrc,
217 const BitmapEx* pBmpExSrc = NULL );
219 /** Fill the entire bitmap with the given color
221 @param rFillColor
222 Color value to use for filling. Set the transparency part of
223 the color to fill the mask.
225 @return sal_True, if the operation was completed successfully.
227 sal_Bool Erase( const Color& rFillColor );
229 /** Perform the Invert operation on every pixel
231 @return sal_True, if the operation was completed successfully.
233 sal_Bool Invert();
235 /** Mirror the bitmap
237 @param nMirrorFlags
238 About which axis (horizontal, vertical, or both) to mirror
240 @return sal_True, if the operation was completed successfully.
242 sal_Bool Mirror( sal_uLong nMirrorFlags );
244 /** Scale the bitmap
246 @param rNewSize
247 The resulting size of the scaled bitmap
249 @param nScaleFlag
250 The algorithm to be used for scaling
252 @return sal_True, if the operation was completed successfully.
254 sal_Bool Scale( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
256 /** Scale the bitmap
258 @param rScaleX
259 The scale factor in x direction.
261 @param rScaleY
262 The scale factor in y direction.
264 @return sal_True, if the operation was completed successfully.
266 sal_Bool Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
268 /** Rotate bitmap by the specified angle
270 @param nAngle10
271 The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
273 @param rFillColor
274 The color to use for filling blank areas. During rotation, the
275 bitmap is enlarged such that the whole rotation result fits
276 in. The empty spaces around that rotated original bitmap are
277 then filled with this color.
279 @return sal_True, if the operation was completed successfully.
281 sal_Bool Rotate( long nAngle10, const Color& rFillColor );
283 /** Replace all pixel having the search color with the specified color
285 @param rSearchColor
286 Color specifying which pixel should be replaced
288 @param rReplaceColor
289 Color to be placed in all changed pixel
291 @param nTol
292 Tolerance value. Specifies the maximal difference between
293 rSearchColor and the individual pixel values, such that the
294 corresponding pixel is still regarded a match.
296 @return sal_True, if the operation was completed successfully.
298 sal_Bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
300 /** Replace all pixel having one the search colors with the corresponding replace color
302 @param pSearchColor
303 Array of colors specifying which pixel should be replaced
305 @param pReplaceColor
306 Array of colors to be placed in all changed pixel
308 @param nColorCount
309 Size of the aforementioned color arrays
311 @param nTol
312 Tolerance value. Specifies the maximal difference between
313 pSearchColor colors and the individual pixel values, such that
314 the corresponding pixel is still regarded a match.
316 @return sal_True, if the operation was completed successfully.
318 sal_Bool Replace( const Color* pSearchColors, const Color* pReplaceColors,
319 sal_uLong nColorCount, const sal_uLong* pTols = NULL );
321 /** Change various global color characteristics
323 @param nLuminancePercent
324 Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
326 @param nContrastPercent
327 Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
329 @param nChannelRPercent
330 Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
332 @param nChannelGPercent
333 Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
335 @param nChannelBPercent
336 Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
338 @param fGamma
339 Exponent of the gamma function applied to the bitmap. The
340 value 1.0 results in no change, the valid range is
341 (0.0,10.0]. Values outside this range are regarded as 1.0.
343 @param bInvert
344 If sal_True, invert the channel values with the logical 'not' operator
346 @return sal_True, if the operation was completed successfully.
348 sal_Bool Adjust( short nLuminancePercent = 0,
349 short nContrastPercent = 0,
350 short nChannelRPercent = 0,
351 short nChannelGPercent = 0,
352 short nChannelBPercent = 0,
353 double fGamma = 1.0,
354 sal_Bool bInvert = sal_False );
356 /** Apply specified filter to the bitmap
358 @param eFilter
359 The filter algorithm to apply
361 @param pFilterParam
362 Various parameter for the different bitmap filter algorithms
364 @param pProgress
365 A callback for showing the progress of the vectorization
367 @return sal_True, if the operation was completed successfully.
369 sal_Bool Filter( BmpFilter eFilter,
370 const BmpFilterParam* pFilterParam = NULL,
371 const Link* pProgress = NULL );
373 /** Get transparency at given position
375 @param nX
376 integer X-Position in Bitmap
378 @param nY
379 integer Y-Position in Bitmap
381 @return transparency value in the range of [0 .. 255] where
382 0 is not transparent, 255 is fully transparent
384 sal_uInt8 GetTransparency(sal_Int32 nX, sal_Int32 nY) const;
386 public:
388 friend VCL_DLLPUBLIC SvStream& operator<<( SvStream& rOStm, const BitmapEx& rBitmapEx );
389 friend VCL_DLLPUBLIC SvStream& operator>>( SvStream& rIStm, BitmapEx& rBitmapEx );
390 static BitmapEx AutoScaleBitmap(BitmapEx & aBitmap, const long aStandardSize);
392 /// populate from a canvas implementation
393 bool Create( const ::com::sun::star::uno::Reference<
394 ::com::sun::star::rendering::XBitmapCanvas > &xBitmapCanvas,
395 const Size &rSize );
398 // ------------------------------------------------------------------
399 /** Create a blend frame as BitmapEx
401 @param nAlpha
402 The blend value defines how strong the frame will be blended with the
403 existing content, 255 == full coverage, 0 == no frame will be drawn
405 @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft
406 The colors defining the frame. If the version without aColorTopRight and
407 aColorBottomLeft is used, these colors are linearly interpolated from
408 aColorTopLeft and aColorBottomRight using the width and height of the area
410 @param rSize
411 The size of the frame in pixels
414 BitmapEx VCL_DLLPUBLIC createBlendFrame(
415 const Size& rSize,
416 sal_uInt8 nAlpha,
417 Color aColorTopLeft,
418 Color aColorBottomRight);
420 BitmapEx VCL_DLLPUBLIC createBlendFrame(
421 const Size& rSize,
422 sal_uInt8 nAlpha,
423 Color aColorTopLeft,
424 Color aColorTopRight,
425 Color aColorBottomRight,
426 Color aColorBottomLeft);
428 // ------------------------------------------------------------------
430 #endif // _SV_BITMAPEX_HXX
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */