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_BITMAPEX_HXX
21 : #define _SV_BITMAPEX_HXX
22 :
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>
28 :
29 : #include <com/sun/star/uno/Reference.hxx>
30 :
31 : namespace com { namespace sun { namespace star { namespace rendering {
32 : class XBitmapCanvas;
33 : } } } }
34 :
35 : // -------------------
36 : // - TransparentType -
37 : // -------------------
38 :
39 : enum TransparentType
40 : {
41 : TRANSPARENT_NONE,
42 : TRANSPARENT_COLOR,
43 : TRANSPARENT_BITMAP
44 : };
45 :
46 : // ------------
47 : // - BitmapEx -
48 : // ------------
49 :
50 : class VCL_DLLPUBLIC BitmapEx
51 : {
52 : private:
53 : friend class ImpGraphic;
54 : friend bool VCL_DLLPUBLIC WriteDIBBitmapEx(const BitmapEx& rSource, SvStream& rOStm);
55 :
56 : Bitmap aBitmap;
57 : Bitmap aMask;
58 : Size aBitmapSize;
59 : Color aTransparentColor;
60 : TransparentType eTransparent;
61 : sal_Bool bAlpha;
62 :
63 : public:
64 :
65 :
66 5180 : SAL_DLLPRIVATE ImpBitmap* ImplGetBitmapImpBitmap() const { return aBitmap.ImplGetImpBitmap(); }
67 5180 : SAL_DLLPRIVATE ImpBitmap* ImplGetMaskImpBitmap() const { return aMask.ImplGetImpBitmap(); }
68 :
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();
78 :
79 : BitmapEx& operator=( const BitmapEx& rBitmapEx );
80 : sal_Bool operator==( const BitmapEx& rBitmapEx ) const;
81 0 : sal_Bool operator!=( const BitmapEx& rBitmapEx ) const { return !(*this==rBitmapEx); }
82 122255 : sal_Bool operator!() const { return !aBitmap; }
83 :
84 : sal_Bool IsEqual( const BitmapEx& rBmpEx ) const;
85 :
86 : sal_Bool IsEmpty() const;
87 : void SetEmpty();
88 : void Clear();
89 :
90 : void Draw( OutputDevice* pOutDev,
91 : const Point& rDestPt ) const;
92 : void Draw( OutputDevice* pOutDev,
93 : const Point& rDestPt, const Size& rDestSize ) const;
94 :
95 : sal_Bool IsTransparent() const;
96 280875 : TransparentType GetTransparentType() const { return eTransparent; }
97 :
98 : Bitmap GetBitmap( const Color* pTransReplaceColor = NULL ) const;
99 : Bitmap GetMask() const;
100 :
101 : BitmapEx GetColorTransformedBitmapEx() const;
102 :
103 : sal_Bool IsAlpha() const;
104 : AlphaMask GetAlpha() const;
105 :
106 319168 : const Size& GetSizePixel() const { return aBitmapSize; }
107 : void SetSizePixel( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
108 :
109 7524 : const Size& GetPrefSize() const { return aBitmap.GetPrefSize(); }
110 2709 : void SetPrefSize( const Size& rPrefSize ) { aBitmap.SetPrefSize( rPrefSize ); }
111 :
112 2664 : const MapMode& GetPrefMapMode() const { return aBitmap.GetPrefMapMode(); }
113 2466 : void SetPrefMapMode( const MapMode& rPrefMapMode ) { aBitmap.SetPrefMapMode( rPrefMapMode ); }
114 :
115 0 : const Color& GetTransparentColor() const { return aTransparentColor; }
116 : void SetTransparentColor( const Color& rColor ) { aTransparentColor = rColor; }
117 :
118 0 : sal_uInt16 GetBitCount() const { return aBitmap.GetBitCount(); }
119 : sal_uLong GetSizeBytes() const;
120 : sal_uLong GetChecksum() const;
121 :
122 : public:
123 :
124 : /** Convert bitmap format
125 :
126 : @param eConversion
127 : The format this bitmap should be converted to.
128 :
129 : @return sal_True, if the conversion was completed successfully.
130 : */
131 : sal_Bool Convert( BmpConversion eConversion );
132 :
133 : /** Reduce number of colors for the bitmap
134 :
135 : @param nNewColorCount
136 : Maximal number of bitmap colors after the reduce operation
137 :
138 : @param eReduce
139 : Algorithm to use for color reduction
140 :
141 : @return sal_True, if the color reduction operation was completed successfully.
142 : */
143 : sal_Bool ReduceColors( sal_uInt16 nNewColorCount,
144 : BmpReduce eReduce = BMP_REDUCE_SIMPLE );
145 :
146 : /** Apply a dither algorithm to the bitmap
147 :
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.
151 :
152 : @param nDitherFlags
153 : The algorithm to be used for dithering
154 : */
155 : sal_Bool Dither( sal_uLong nDitherFlags = BMP_DITHER_MATRIX );
156 :
157 : /** Crop the bitmap
158 :
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.
166 :
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!
170 : */
171 : sal_Bool Crop( const Rectangle& rRectPixel );
172 :
173 : /** Expand the bitmap by pixel padding
174 :
175 : @param nDX
176 : Number of pixel to pad at the right border of the bitmap
177 :
178 : @param nDY
179 : Number of scanlines to pad at the bottom border of the bitmap
180 :
181 : @param pInitColor
182 : Color to use for padded pixel
183 :
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.
187 : */
188 : sal_Bool Expand( sal_uLong nDX, sal_uLong nDY,
189 : const Color* pInitColor = NULL,
190 : sal_Bool bExpandTransparent = sal_False );
191 :
192 : /** Copy a rectangular area from another bitmap
193 :
194 : @param rRectDst
195 : Destination rectangle in this bitmap. This is clipped to the
196 : bitmap dimensions.
197 :
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.
203 :
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.
208 :
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.
213 : */
214 : sal_Bool CopyPixel( const Rectangle& rRectDst,
215 : const Rectangle& rRectSrc,
216 : const BitmapEx* pBmpExSrc = NULL );
217 :
218 : /** Fill the entire bitmap with the given color
219 :
220 : @param rFillColor
221 : Color value to use for filling. Set the transparency part of
222 : the color to fill the mask.
223 :
224 : @return sal_True, if the operation was completed successfully.
225 : */
226 : sal_Bool Erase( const Color& rFillColor );
227 :
228 : /** Perform the Invert operation on every pixel
229 :
230 : @return sal_True, if the operation was completed successfully.
231 : */
232 : sal_Bool Invert();
233 :
234 : /** Mirror the bitmap
235 :
236 : @param nMirrorFlags
237 : About which axis (horizontal, vertical, or both) to mirror
238 :
239 : @return sal_True, if the operation was completed successfully.
240 : */
241 : sal_Bool Mirror( sal_uLong nMirrorFlags );
242 :
243 : /** Scale the bitmap
244 :
245 : @param rNewSize
246 : The resulting size of the scaled bitmap
247 :
248 : @param nScaleFlag
249 : The algorithm to be used for scaling
250 :
251 : @return sal_True, if the operation was completed successfully.
252 : */
253 : sal_Bool Scale( const Size& rNewSize, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
254 :
255 : /** Scale the bitmap
256 :
257 : @param rScaleX
258 : The scale factor in x direction.
259 :
260 : @param rScaleY
261 : The scale factor in y direction.
262 :
263 : @return sal_True, if the operation was completed successfully.
264 : */
265 : sal_Bool Scale( const double& rScaleX, const double& rScaleY, sal_uInt32 nScaleFlag = BMP_SCALE_DEFAULT );
266 :
267 : /** Rotate bitmap by the specified angle
268 :
269 : @param nAngle10
270 : The rotation angle in tenth of a degree. The bitmap is always rotated around its center.
271 :
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.
277 :
278 : @return sal_True, if the operation was completed successfully.
279 : */
280 : sal_Bool Rotate( long nAngle10, const Color& rFillColor );
281 :
282 : /** Replace all pixel having the search color with the specified color
283 :
284 : @param rSearchColor
285 : Color specifying which pixel should be replaced
286 :
287 : @param rReplaceColor
288 : Color to be placed in all changed pixel
289 :
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.
294 :
295 : @return sal_True, if the operation was completed successfully.
296 : */
297 : sal_Bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uLong nTol = 0 );
298 :
299 : /** Replace all pixel having one the search colors with the corresponding replace color
300 :
301 : @param pSearchColor
302 : Array of colors specifying which pixel should be replaced
303 :
304 : @param pReplaceColor
305 : Array of colors to be placed in all changed pixel
306 :
307 : @param nColorCount
308 : Size of the aforementioned color arrays
309 :
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.
314 :
315 : @return sal_True, if the operation was completed successfully.
316 : */
317 : sal_Bool Replace( const Color* pSearchColors, const Color* pReplaceColors,
318 : sal_uLong nColorCount, const sal_uLong* pTols = NULL );
319 :
320 : /** Change various global color characteristics
321 :
322 : @param nLuminancePercent
323 : Percent of luminance change, valid range [-100,100]. Values outside this range are clipped to the valid range.
324 :
325 : @param nContrastPercent
326 : Percent of contrast change, valid range [-100,100]. Values outside this range are clipped to the valid range.
327 :
328 : @param nChannelRPercent
329 : Percent of red channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
330 :
331 : @param nChannelGPercent
332 : Percent of green channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
333 :
334 : @param nChannelBPercent
335 : Percent of blue channel change, valid range [-100,100]. Values outside this range are clipped to the valid range.
336 :
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.
341 :
342 : @param bInvert
343 : If sal_True, invert the channel values with the logical 'not' operator
344 :
345 : @return sal_True, if the operation was completed successfully.
346 : */
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 );
354 :
355 : /** Apply specified filter to the bitmap
356 :
357 : @param eFilter
358 : The filter algorithm to apply
359 :
360 : @param pFilterParam
361 : Various parameter for the different bitmap filter algorithms
362 :
363 : @param pProgress
364 : A callback for showing the progress of the vectorization
365 :
366 : @return sal_True, if the operation was completed successfully.
367 : */
368 : sal_Bool Filter( BmpFilter eFilter,
369 : const BmpFilterParam* pFilterParam = NULL,
370 : const Link* pProgress = NULL );
371 :
372 : /** Get transparency at given position
373 :
374 : @param nX
375 : integer X-Position in Bitmap
376 :
377 : @param nY
378 : integer Y-Position in Bitmap
379 :
380 : @return transparency value in the range of [0 .. 255] where
381 : 0 is not transparent, 255 is fully transparent
382 : */
383 : sal_uInt8 GetTransparency(sal_Int32 nX, sal_Int32 nY) const;
384 :
385 : /** Create transformed Bitmap
386 :
387 : @param fWidth
388 : The target width in pixels
389 :
390 : @param fHeight
391 : The target height in pixels
392 :
393 : @param rTransformation
394 : The back transformation for each pixel in (0 .. fWidth),(0 .. fHeight) to
395 : local pixel coordiantes
396 : */
397 : BitmapEx TransformBitmapEx(
398 : double fWidth,
399 : double fHeight,
400 : const basegfx::B2DHomMatrix& rTransformation) const;
401 :
402 : /** Create transformed Bitmap
403 :
404 : @param rTransformation
405 : The transformation from unit coordinates to target
406 :
407 : @param fMaximumArea
408 : A limitation for the maximum size of pixels to use for the result
409 :
410 : @return The transformed bitmap
411 : */
412 : BitmapEx getTransformed(
413 : const basegfx::B2DHomMatrix& rTransformation,
414 : double fMaximumArea = 500000.0) const;
415 :
416 : /** Create ColorStack-modified version of this BitmapEx
417 :
418 : @param rBColorModifierStack
419 : A ColrModifierStack which defines how each pixel has to be modified
420 : */
421 : BitmapEx ModifyBitmapEx(const basegfx::BColorModifierStack& rBColorModifierStack) const;
422 :
423 : public:
424 :
425 : static BitmapEx AutoScaleBitmap(BitmapEx & aBitmap, const long aStandardSize);
426 :
427 : /// populate from a canvas implementation
428 : bool Create( const ::com::sun::star::uno::Reference<
429 : ::com::sun::star::rendering::XBitmapCanvas > &xBitmapCanvas,
430 : const Size &rSize );
431 : };
432 :
433 : // ------------------------------------------------------------------
434 : /** Create a blend frame as BitmapEx
435 :
436 : @param nAlpha
437 : The blend value defines how strong the frame will be blended with the
438 : existing content, 255 == full coverage, 0 == no frame will be drawn
439 :
440 : @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft
441 : The colors defining the frame. If the version without aColorTopRight and
442 : aColorBottomLeft is used, these colors are linearly interpolated from
443 : aColorTopLeft and aColorBottomRight using the width and height of the area
444 :
445 : @param rSize
446 : The size of the frame in pixels
447 : */
448 :
449 : BitmapEx VCL_DLLPUBLIC createBlendFrame(
450 : const Size& rSize,
451 : sal_uInt8 nAlpha,
452 : Color aColorTopLeft,
453 : Color aColorBottomRight);
454 :
455 : BitmapEx VCL_DLLPUBLIC createBlendFrame(
456 : const Size& rSize,
457 : sal_uInt8 nAlpha,
458 : Color aColorTopLeft,
459 : Color aColorTopRight,
460 : Color aColorBottomRight,
461 : Color aColorBottomLeft);
462 :
463 : // ------------------------------------------------------------------
464 :
465 : #endif // _SV_BITMAPEX_HXX
466 :
467 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|