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_BITMAPEX_HXX
30 : : #define _SV_BITMAPEX_HXX
31 : :
32 : : #include <vcl/dllapi.h>
33 : : #include <vcl/bitmap.hxx>
34 : : #include <vcl/alpha.hxx>
35 : : #include <tools/color.hxx>
36 : :
37 : : // -------------------
38 : : // - TransparentType -
39 : : // -------------------
40 : :
41 : : enum TransparentType
42 : : {
43 : : TRANSPARENT_NONE,
44 : : TRANSPARENT_COLOR,
45 : : TRANSPARENT_BITMAP
46 : : };
47 : :
48 : : // ------------
49 : : // - BitmapEx -
50 : : // ------------
51 : :
52 : : class VCL_DLLPUBLIC BitmapEx
53 : : {
54 : : friend class ImpGraphic;
55 : :
56 : : private:
57 : :
58 : : Bitmap aBitmap;
59 : : Bitmap aMask;
60 : : Size aBitmapSize;
61 : : Color aTransparentColor;
62 : : TransparentType eTransparent;
63 : : sal_Bool bAlpha;
64 : :
65 : : public:
66 : :
67 : :
68 : 3085 : SAL_DLLPRIVATE ImpBitmap* ImplGetBitmapImpBitmap() const { return aBitmap.ImplGetImpBitmap(); }
69 : 3085 : SAL_DLLPRIVATE ImpBitmap* ImplGetMaskImpBitmap() const { return aMask.ImplGetImpBitmap(); }
70 : :
71 : : public:
72 : :
73 : : BitmapEx();
74 : : BitmapEx( const ResId& rResId );
75 : : BitmapEx( const BitmapEx& rBitmapEx );
76 : : BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize );
77 : : BitmapEx( const Bitmap& rBmp );
78 : : BitmapEx( const Bitmap& rBmp, const Bitmap& rMask );
79 : : BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask );
80 : : BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor );
81 : : ~BitmapEx();
82 : :
83 : : BitmapEx& operator=( const BitmapEx& rBitmapEx );
84 : : sal_Bool operator==( const BitmapEx& rBitmapEx ) const;
85 : 0 : sal_Bool operator!=( const BitmapEx& rBitmapEx ) const { return !(*this==rBitmapEx); }
86 : 203037 : sal_Bool operator!() const { return !aBitmap; }
87 : :
88 : : sal_Bool IsEqual( const BitmapEx& rBmpEx ) const;
89 : :
90 : : sal_Bool IsEmpty() const;
91 : : void SetEmpty();
92 : : void Clear();
93 : :
94 : : void Draw( OutputDevice* pOutDev,
95 : : const Point& rDestPt ) const;
96 : : void Draw( OutputDevice* pOutDev,
97 : : const Point& rDestPt, const Size& rDestSize ) const;
98 : :
99 : : sal_Bool IsTransparent() const;
100 : 563707 : TransparentType GetTransparentType() const { return eTransparent; }
101 : :
102 : : Bitmap GetBitmap( const Color* pTransReplaceColor = NULL ) const;
103 : : Bitmap GetMask() const;
104 : :
105 : : BitmapEx GetColorTransformedBitmapEx() const;
106 : :
107 : : sal_Bool IsAlpha() const;
108 : : AlphaMask GetAlpha() const;
109 : :
110 : 667018 : const Size& GetSizePixel() const { return aBitmapSize; }
111 : : void SetSizePixel( const Size& rNewSize );
112 : :
113 : 51099 : const Size& GetPrefSize() const { return aBitmap.GetPrefSize(); }
114 : 5997 : void SetPrefSize( const Size& rPrefSize ) { aBitmap.SetPrefSize( rPrefSize ); }
115 : :
116 : 23463 : const MapMode& GetPrefMapMode() const { return aBitmap.GetPrefMapMode(); }
117 : 5997 : void SetPrefMapMode( const MapMode& rPrefMapMode ) { aBitmap.SetPrefMapMode( rPrefMapMode ); }
118 : :
119 : 0 : const Color& GetTransparentColor() const { return aTransparentColor; }
120 : : void SetTransparentColor( const Color& rColor ) { aTransparentColor = rColor; }
121 : :
122 : 0 : sal_uInt16 GetBitCount() const { return aBitmap.GetBitCount(); }
123 : : sal_uLong GetSizeBytes() const;
124 : : sal_uLong GetChecksum() const;
125 : :
126 : : public:
127 : :
128 : : /** Convert bitmap format
129 : :
130 : : @param eConversion
131 : : The format this bitmap should be converted to.
132 : :
133 : : @return sal_True, if the conversion was completed successfully.
134 : : */
135 : : sal_Bool Convert( BmpConversion eConversion );
136 : :
137 : : /** Reduce number of colors for the bitmap
138 : :
139 : : @param nNewColorCount
140 : : Maximal number of bitmap colors after the reduce operation
141 : :
142 : : @param eReduce
143 : : Algorithm to use for color reduction
144 : :
145 : : @return sal_True, if the color reduction operation was completed successfully.
146 : : */
147 : : sal_Bool ReduceColors( sal_uInt16 nNewColorCount,
148 : : BmpReduce eReduce = BMP_REDUCE_SIMPLE );
149 : :
150 : : /** Apply a dither algorithm to the bitmap
151 : :
152 : : This method dithers the bitmap inplace, i.e. a true color
153 : : bitmap is converted to a paletted bitmap, reducing the color
154 : : deviation by error diffusion.
155 : :
156 : : @param nDitherFlags
157 : : The algorithm to be used for dithering
158 : : */
159 : : sal_Bool Dither( sal_uLong nDitherFlags = BMP_DITHER_MATRIX );
160 : :
161 : : /** Crop the bitmap
162 : :
163 : : @param rRectPixel
164 : : A rectangle specifying the crop amounts on all four sides of
165 : : the bitmap. If the upper left corner of the bitmap is assigned
166 : : (0,0), then this method cuts out the given rectangle from the
167 : : bitmap. Note that the rectangle is clipped to the bitmap's
168 : : dimension, i.e. negative left,top rectangle coordinates or
169 : : exceeding width or height is ignored.
170 : :
171 : : @return sal_True, if cropping was performed successfully. If
172 : : nothing had to be cropped, because e.g. the crop rectangle
173 : : included the bitmap, sal_False is returned, too!
174 : : */
175 : : sal_Bool Crop( const Rectangle& rRectPixel );
176 : :
177 : : /** Expand the bitmap by pixel padding
178 : :
179 : : @param nDX
180 : : Number of pixel to pad at the right border of the bitmap
181 : :
182 : : @param nDY
183 : : Number of scanlines to pad at the bottom border of the bitmap
184 : :
185 : : @param pInitColor
186 : : Color to use for padded pixel
187 : :
188 : : @return sal_True, if padding was performed successfully. sal_False is
189 : : not only returned when the operation failed, but also if
190 : : nothing had to be done, e.g. because nDX and nDY were zero.
191 : : */
192 : : sal_Bool Expand( sal_uLong nDX, sal_uLong nDY,
193 : : const Color* pInitColor = NULL,
194 : : sal_Bool bExpandTransparent = sal_False );
195 : :
196 : : /** Copy a rectangular area from another bitmap
197 : :
198 : : @param rRectDst
199 : : Destination rectangle in this bitmap. This is clipped to the
200 : : bitmap dimensions.
201 : :
202 : : @param rRectSrc
203 : : Source rectangle in pBmpSrc. This is clipped to the source
204 : : bitmap dimensions. Note further that no scaling takes place
205 : : during this copy operation, i.e. only the minimum of source
206 : : and destination rectangle's width and height are used.
207 : :
208 : : @param pBmpSrc
209 : : The source bitmap to copy from. If this argument is NULL, or
210 : : equal to the object this method is called on, copying takes
211 : : place within the same bitmap.
212 : :
213 : : @return sal_True, if the operation completed successfully. sal_False
214 : : is not only returned when the operation failed, but also if
215 : : nothing had to be done, e.g. because one of the rectangles are
216 : : empty.
217 : : */
218 : : sal_Bool CopyPixel( const Rectangle& rRectDst,
219 : : const Rectangle& rRectSrc,
220 : : const BitmapEx* pBmpExSrc = NULL );
221 : :
222 : : /** Fill the entire bitmap with the given color
223 : :
224 : : @param rFillColor
225 : : Color value to use for filling. Set the transparency part of
226 : : the color to fill the mask.
227 : :
228 : : @return sal_True, if the operation was completed successfully.
229 : : */
230 : : sal_Bool Erase( const Color& rFillColor );
231 : :
232 : : /** Perform the Invert operation on every pixel
233 : :
234 : : @return sal_True, if the operation was completed successfully.
235 : : */
236 : : sal_Bool Invert();
237 : :
238 : : /** Mirror the bitmap
239 : :
240 : : @param nMirrorFlags
241 : : About which axis (horizontal, vertical, or both) to mirror
242 : :
243 : : @return sal_True, if the operation was completed successfully.
244 : : */
245 : : sal_Bool Mirror( sal_uLong nMirrorFlags );
246 : :
247 : : /** Scale the bitmap
248 : :
249 : : @param rNewSize
250 : : The resulting size of the scaled bitmap
251 : :
252 : : @param nScaleFlag
253 : : The algorithm to be used for scaling
254 : :
255 : : @return sal_True, if the operation was completed successfully.
256 : : */
257 : : sal_Bool Scale( const Size& rNewSize, sal_uLong nScaleFlag = BMP_SCALE_DEFAULT );
258 : :
259 : : /** Scale the bitmap
260 : :
261 : : @param rScaleX
262 : : The scale factor in x direction.
263 : :
264 : : @param rScaleY
265 : : The scale factor in y direction.
266 : :
267 : : @return sal_True, if the operation was completed successfully.
268 : : */
269 : : sal_Bool Scale( const double& rScaleX, const double& rScaleY, sal_uLong nScaleFlag = BMP_SCALE_DEFAULT );
270 : :
271 : : /** Scale, crop and rotate the bitmap */
272 : : sal_Bool ScaleCropRotate(
273 : : const double& rScaleX, const double& rScaleY, const Rectangle& rRectPixel, long nAngle10,
274 : : const Color& rFillColor, sal_uLong nScaleFlag = BMP_SCALE_DEFAULT );
275 : :
276 : : /** Rotate bitmap by the specified angle
277 : :
278 : : @param nAngle10
279 : : The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
280 : :
281 : : @param rFillColor
282 : : The color to use for filling blank areas. During rotation, the
283 : : bitmap is enlarged such that the whole rotation result fits
284 : : in. The empty spaces around that rotated original bitmap are
285 : : then filled with this color.
286 : :
287 : : @return sal_True, if the operation was completed successfully.
288 : : */
289 : : sal_Bool Rotate( long nAngle10, const Color& rFillColor );
290 : :
291 : : /** Replace all pixel having the search color with the specified color
292 : :
293 : : @param rSearchColor
294 : : Color specifying which pixel should be replaced
295 : :
296 : : @param rReplaceColor
297 : : Color to be placed in all changed pixel
298 : :
299 : : @param nTol
300 : : Tolerance value. Specifies the maximal difference between
301 : : rSearchColor and the individual pixel values, such that the
302 : : corresponding pixel is still regarded a match.
303 : :
304 : : @return sal_True, if the operation was completed successfully.
305 : : */
306 : : sal_Bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
307 : :
308 : : /** Replace all pixel having one the search colors with the corresponding replace color
309 : :
310 : : @param pSearchColor
311 : : Array of colors specifying which pixel should be replaced
312 : :
313 : : @param pReplaceColor
314 : : Array of colors to be placed in all changed pixel
315 : :
316 : : @param nColorCount
317 : : Size of the aforementioned color arrays
318 : :
319 : : @param nTol
320 : : Tolerance value. Specifies the maximal difference between
321 : : pSearchColor colors and the individual pixel values, such that
322 : : the corresponding pixel is still regarded a match.
323 : :
324 : : @return sal_True, if the operation was completed successfully.
325 : : */
326 : : sal_Bool Replace( const Color* pSearchColors, const Color* pReplaceColors,
327 : : sal_uLong nColorCount, const sal_uLong* pTols = NULL );
328 : :
329 : : /** Change various global color characteristics
330 : :
331 : : @param nLuminancePercent
332 : : Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
333 : :
334 : : @param nContrastPercent
335 : : Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
336 : :
337 : : @param nChannelRPercent
338 : : Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
339 : :
340 : : @param nChannelGPercent
341 : : Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
342 : :
343 : : @param nChannelBPercent
344 : : Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
345 : :
346 : : @param fGamma
347 : : Exponent of the gamma function applied to the bitmap. The
348 : : value 1.0 results in no change, the valid range is
349 : : (0.0,10.0]. Values outside this range are regarded as 1.0.
350 : :
351 : : @param bInvert
352 : : If sal_True, invert the channel values with the logical 'not' operator
353 : :
354 : : @return sal_True, if the operation was completed successfully.
355 : : */
356 : : sal_Bool Adjust( short nLuminancePercent = 0,
357 : : short nContrastPercent = 0,
358 : : short nChannelRPercent = 0,
359 : : short nChannelGPercent = 0,
360 : : short nChannelBPercent = 0,
361 : : double fGamma = 1.0,
362 : : sal_Bool bInvert = sal_False );
363 : :
364 : : /** Apply specified filter to the bitmap
365 : :
366 : : @param eFilter
367 : : The filter algorithm to apply
368 : :
369 : : @param pFilterParam
370 : : Various parameter for the different bitmap filter algorithms
371 : :
372 : : @param pProgress
373 : : A callback for showing the progress of the vectorization
374 : :
375 : : @return sal_True, if the operation was completed successfully.
376 : : */
377 : : sal_Bool Filter( BmpFilter eFilter,
378 : : const BmpFilterParam* pFilterParam = NULL,
379 : : const Link* pProgress = NULL );
380 : :
381 : : /** Get transparency at given position
382 : :
383 : : @param nX
384 : : integer X-Position in Bitmap
385 : :
386 : : @param nY
387 : : integer Y-Position in Bitmap
388 : :
389 : : @return transparency value in the range of [0 .. 255] where
390 : : 0 is not transparent, 255 is fully transparent
391 : : */
392 : : sal_uInt8 GetTransparency(sal_Int32 nX, sal_Int32 nY) const;
393 : :
394 : : public:
395 : :
396 : : friend VCL_DLLPUBLIC SvStream& operator<<( SvStream& rOStm, const BitmapEx& rBitmapEx );
397 : : friend VCL_DLLPUBLIC SvStream& operator>>( SvStream& rIStm, BitmapEx& rBitmapEx );
398 : : static BitmapEx AutoScaleBitmap(BitmapEx & aBitmap, const long aStandardSize);
399 : : };
400 : :
401 : : #endif // _SV_BITMAPEX_HXX
402 : :
403 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|