1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_BASEBMP_BITMAPDEVICE_HXX
21 #define INCLUDED_BASEBMP_BITMAPDEVICE_HXX
23 #include <sal/types.h>
24 #include <basebmp/drawmodes.hxx>
25 #include <basebmp/scanlineformats.hxx>
26 #include <basebmp/basebmpdllapi.h>
28 #include <boost/scoped_ptr.hpp>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/shared_array.hpp>
31 #include <boost/enable_shared_from_this.hpp>
32 #include <boost/noncopyable.hpp>
48 // Temporary. Use like the tools color object
50 typedef boost::shared_ptr
< class BitmapDevice
> BitmapDeviceSharedPtr
;
51 typedef boost::shared_ptr
< struct IBitmapDeviceDamageTracker
> IBitmapDeviceDamageTrackerSharedPtr
;
52 typedef boost::shared_array
< sal_uInt8
> RawMemorySharedArray
;
53 typedef boost::shared_ptr
< const std::vector
<Color
> > PaletteMemorySharedVector
;
55 struct ImplBitmapDevice
;
57 /// Interface for getting damage tracking events
58 struct IBitmapDeviceDamageTracker
60 /// gets called when said region is clobbered
61 virtual void damaged(const basegfx::B2IBox
& rDamageRect
) const = 0;
64 ~IBitmapDeviceDamageTracker() {}
67 /** Definition of BitmapDevice interface
69 Use the createBitmapDevice() function to create instances.
71 Implementation note: the clip mask and bitmap parameter instances
72 of BitmapDevice that are passed to individual BitmapDevice
73 instances work best with 1 bit grey masks for the clip and a
74 format matching that of the target BitmapDevice for the other
75 parameters. The alpha mask passed to the drawMaskedColor() methods
76 works best when given as an eight bit grey bitmap. Everything else
77 is accepted, but potentially slow.
79 class BASEBMP_DLLPUBLIC BitmapDevice
: public boost::enable_shared_from_this
<BitmapDevice
>,
80 private boost::noncopyable
83 /** Query size of device in pixel columns (X) and rows (Y, "scanlines")
85 basegfx::B2IVector
getSize() const;
87 /** Query whether buffer starts with 0th scanline
89 @return true, if the buffer memory starts with the 0th
90 scanline, and false if it starts with the last one. The latter
91 is e.g. the typical scan line ordering for the Windows BMP
94 bool isTopDown() const;
96 /** Query the size of the whole frame buffer
98 @ return the size of the whole frame buffer, the same as
99 getSize() unless this is a "subset" device.
101 basegfx::B2IVector
getBufferSize() const;
103 /** Query type of scanline memory format
105 Format
getScanlineFormat() const;
107 /** Query byte offset to get from scanline n to scanline n+1
109 @return the scanline stride in bytes.
111 sal_Int32
getScanlineStride() const;
113 /** Get pointer to frame buffer
115 @return a shared ptr to the bitmap buffer memory. As this is a
116 shared ptr, you can freely store and use the pointer, even
117 after this object has been deleted.
119 RawMemorySharedArray
getBuffer() const;
121 /// Query current damage tracking object (if any)
122 IBitmapDeviceDamageTrackerSharedPtr
getDamageTracker() const;
124 /** Set new damage tracking object
127 Object implementing the IBitmapDeviceDamageTracker interface -
128 everytime some area of the surface gets clobbered, that object
131 void setDamageTracker( const IBitmapDeviceDamageTrackerSharedPtr
& rDamage
);
133 /** Get pointer to palette
135 The returned pointer is const on purpose, since the
136 BitmapDevice might internally cache lookup information. Don't
137 modify the returned data, unless you want to enter the realm
138 of completely undefined behaviour.
140 @return shared pointer to vector of Color entries.
142 PaletteMemorySharedVector
getPalette() const;
144 /// Check if this and the other BitmapDevice share a buffer
145 bool isSharedBuffer( const BitmapDeviceSharedPtr
& rOther
) const;
147 /** Clear whole device with given color
149 This method works like a fill with the given color value,
150 resulting in a bitmap uniformly colored in fillColor.
152 void clear( Color fillColor
);
154 /** Set given pixel to specified color
160 Color value to set the pixel to
163 Draw mode to use when changing the pixel value
165 void setPixel( const basegfx::B2IPoint
& rPt
,
169 /** Set given pixel to specified color
175 Color value to set the pixel to
178 Draw mode to use when changing the pixel value
181 Clip mask to use. If the clip mask is 1 at the given pixel
182 position, no change will take place.
184 void setPixel( const basegfx::B2IPoint
& rPt
,
187 const BitmapDeviceSharedPtr
& rClip
);
189 /** Get color value at given pixel
191 Color
getPixel( const basegfx::B2IPoint
& rPt
);
193 /** Get underlying pixel data value at given position
195 This method returns the raw pixel data. In the case of
196 paletted bitmaps, this is the palette index, not the final
199 sal_uInt32
getPixelData( const basegfx::B2IPoint
& rPt
);
204 Start point of the line
207 End point of the line. If the analytical line from rP1 to rPt2
208 (with the actual pixel positions assumed to be the center of
209 the pixel) is exactly in the middle between two pixel, this
210 method always selects the pixel closer to rPt1.
213 Color value to draw the line with
216 Draw mode to use when changing the pixel value
218 void drawLine( const basegfx::B2IPoint
& rPt1
,
219 const basegfx::B2IPoint
& rPt2
,
226 Start point of the line
229 End point of the line. If the analytical line from rP1 to rPt2
230 (with the actual pixel positions assumed to be the center of
231 the pixel) is exactly in the middle between two pixel, this
232 method always selects the pixel closer to rPt1.
235 Color value to draw the line with
238 Draw mode to use when changing the pixel value
241 Clip mask to use. Pixel where the corresponding clip mask
242 pixel is 1 will not be modified.
244 void drawLine( const basegfx::B2IPoint
& rPt1
,
245 const basegfx::B2IPoint
& rPt2
,
248 const BitmapDeviceSharedPtr
& rClip
);
253 Polygon to draw. Depending on the value returned by rPoly's
254 isClosed() method, the resulting line polygon will be drawn
258 Color value to draw the polygon with
261 Draw mode to use when changing pixel values
263 void drawPolygon( const basegfx::B2DPolygon
& rPoly
,
270 Polygon to draw. Depending on the value returned by rPoly's
271 isClosed() method, the resulting line polygon will be drawn
275 Color value to draw the polygon with
278 Draw mode to use when changing pixel values
281 Clip mask to use. Pixel where the corresponding clip mask
282 pixel is 1 will not be modified.
284 void drawPolygon( const basegfx::B2DPolygon
& rPoly
,
287 const BitmapDeviceSharedPtr
& rClip
);
289 /** Fill a poly-polygon
292 Poly-polygon to fill. Regardless of the value returned by
293 rPoly's isClosed() method, the resulting filled poly-polygon
294 is always considered closed. As usual, when filling a shape,
295 the rightmost and bottommost pixel are not filled, compared to
296 the drawPolygon() method. For example, the rectangle
297 (0,0),(1,1) will have four pixel set, when drawn via
298 drawPolygon(), and only one pixel, when filled via
302 Color value to fill the poly-polygon with
305 Draw mode to use when changing pixel values
307 void fillPolyPolygon( const basegfx::B2DPolyPolygon
& rPoly
,
311 /** Fill a poly-polygon
314 Poly-polygon to fill. Regardless of the value returned by
315 rPoly's isClosed() method, the resulting filled poly-polygon
316 is always considered closed. As usual, when filling a shape,
317 the rightmost and bottommost pixel are not filled, compared to
318 the drawPolygon() method. For example, the rectangle
319 (0,0),(1,1) will have four pixel set, when drawn via
320 drawPolygon(), and only one pixel, when filled via
324 Color value to fill the poly-polygon with
327 Draw mode to use when changing pixel values
330 Clip mask to use. Pixel where the corresponding clip mask
331 pixel is 1 will not be modified.
333 void fillPolyPolygon( const basegfx::B2DPolyPolygon
& rPoly
,
336 const BitmapDeviceSharedPtr
& rClip
);
338 /** Draw another bitmap into this device
341 Bitmap to render into this one. It is permitted that source
342 and destination bitmap are the same.
345 Rectangle within the source bitmap to take the pixel from.
348 Rectangle in the destination bitmap to put the pixel
349 into. Source and destination rectangle are permitted to have
350 differing sizes; this method will scale the source pixel
351 accordingly. Please note that both source and destination
352 rectangle are interpreted excluding the rightmost pixel column
353 and the bottommost pixel row, this is much like polygon
354 filling. As a result, filling a given rectangle with
355 fillPolyPolygon(), and using the same rectangle as the
356 destination rectangle of this method, will affect exactly the
360 Draw mode to use when changing pixel values
362 void drawBitmap( const BitmapDeviceSharedPtr
& rSrcBitmap
,
363 const basegfx::B2IBox
& rSrcRect
,
364 const basegfx::B2IBox
& rDstRect
,
367 /** Draw another bitmap into this device
370 Bitmap to render into this one. It is permitted that source
371 and destination bitmap are the same.
374 Rectangle within the source bitmap to take the pixel from.
377 Rectangle in the destination bitmap to put the pixel
378 into. Source and destination rectangle are permitted to have
379 differing sizes; this method will scale the source pixel
380 accordingly. Please note that both source and destination
381 rectangle are interpreted excluding the rightmost pixel column
382 and the bottommost pixel row, this is much like polygon
383 filling. As a result, filling a given rectangle with
384 fillPolyPolygon(), and using the same rectangle as the
385 destination rectangle of this method, will affect exactly the
389 Draw mode to use when changing pixel values
392 Clip mask to use. Pixel where the corresponding clip mask
393 pixel is 1 will not be modified.
395 void drawBitmap( const BitmapDeviceSharedPtr
& rSrcBitmap
,
396 const basegfx::B2IBox
& rSrcRect
,
397 const basegfx::B2IBox
& rDstRect
,
399 const BitmapDeviceSharedPtr
& rClip
);
401 /** Draw a color with an alpha-modulation bitmap into this device
403 This method takes a fixed color value, and an alpha mask. For
404 each pixel in the alpha mask, the given color value is blended
405 with the corresponding alpha value against the content of this
409 Color value to use for blending
412 Alpha mask to use for blending. It is permitted that alpha
413 mask and this bitmap are the same object.
416 Rectangle within the alpha mask to take the pixel from.
417 Please note that the destination rectangle is interpreted
418 excluding the rightmost pixel column and the bottommost pixel
419 row, this is much like polygon filling. As a result, filling a
420 given rectangle with fillPolyPolygon(), and using the same
421 rectangle as the source rectangle of this method, will affect
422 exactly the same set of pixel.
425 Destination point, where to start placing the pixel from the
428 void drawMaskedColor( Color aSrcColor
,
429 const BitmapDeviceSharedPtr
& rAlphaMask
,
430 const basegfx::B2IBox
& rSrcRect
,
431 const basegfx::B2IPoint
& rDstPoint
);
433 /** Draw a color with an alpha-modulation bitmap into this device
435 This method takes a fixed color value, and an alpha mask. For
436 each pixel in the alpha mask, the given color value is blended
437 with the corresponding alpha value against the content of this
441 Color value to use for blending
444 Alpha mask to use for blending. It is permitted that alpha
445 mask and this bitmap are the same object.
448 Rectangle within the alpha mask to take the pixel from.
449 Please note that the destination rectangle is interpreted
450 excluding the rightmost pixel column and the bottommost pixel
451 row, this is much like polygon filling. As a result, filling a
452 given rectangle with fillPolyPolygon(), and using the same
453 rectangle as the source rectangle of this method, will affect
454 exactly the same set of pixel.
457 Destination point, where to start placing the pixel from the
461 Clip mask to use. Pixel where the corresponding clip mask
462 pixel is 1 will not be modified.
464 void drawMaskedColor( Color aSrcColor
,
465 const BitmapDeviceSharedPtr
& rAlphaMask
,
466 const basegfx::B2IBox
& rSrcRect
,
467 const basegfx::B2IPoint
& rDstPoint
,
468 const BitmapDeviceSharedPtr
& rClip
);
470 /** Draw another bitmap through a mask into this device
472 This method renders a source bitmap into this device, much
473 like the drawBitmap() method. The only difference is the
474 additional mask parameter, which operates much like an
475 additional clip mask: pixel with value zero in this mask
476 result in destination pixel not being modified.
479 Bitmap to render into this one. It is permitted that source
480 and destination bitmap are the same.
483 Bitmap to use as a mask. Pixel with value != zero in this mask
484 will result in destination pixel not being affected by the
488 Rectangle within the source bitmap to take the pixel from.
491 Rectangle in the destination bitmap to put the pixel
492 into. Source and destination rectangle are permitted to have
493 differing sizes; this method will scale the source pixel
494 accordingly. Please note that both source and destination
495 rectangle are interpreted excluding the rightmost pixel column
496 and the bottommost pixel row, this is much like polygon
497 filling. As a result, filling a given rectangle with
498 fillPolyPolygon(), and using the same rectangle as the
499 destination rectangle of this method, will affect exactly the
503 Draw mode to use when changing pixel values
505 void drawMaskedBitmap( const BitmapDeviceSharedPtr
& rSrcBitmap
,
506 const BitmapDeviceSharedPtr
& rMask
,
507 const basegfx::B2IBox
& rSrcRect
,
508 const basegfx::B2IBox
& rDstRect
,
511 /** Draw another bitmap through a mask into this device
513 This method renders a source bitmap into this device, much
514 like the drawBitmap() method. The only difference is the
515 additional mask parameter, which operates much like an
516 additional clip mask: pixel with value != zero in this mask
517 result in destination pixel not being modified.
520 Bitmap to render into this one. It is permitted that source
521 and destination bitmap are the same.
524 Bitmap to use as a mask. Pixel with value != zero in this mask
525 will result in destination pixel not being affected by the
529 Rectangle within the source bitmap to take the pixel from.
532 Rectangle in the destination bitmap to put the pixel
533 into. Source and destination rectangle are permitted to have
534 differing sizes; this method will scale the source pixel
535 accordingly. Please note that both source and destination
536 rectangle are interpreted excluding the rightmost pixel column
537 and the bottommost pixel row, this is much like polygon
538 filling. As a result, filling a given rectangle with
539 fillPolyPolygon(), and using the same rectangle as the
540 destination rectangle of this method, will affect exactly the
544 Draw mode to use when changing pixel values
547 Clip mask to use. Pixel where the corresponding clip mask
548 pixel is 1 will not be modified.
550 void drawMaskedBitmap( const BitmapDeviceSharedPtr
& rSrcBitmap
,
551 const BitmapDeviceSharedPtr
& rMask
,
552 const basegfx::B2IBox
& rSrcRect
,
553 const basegfx::B2IBox
& rDstRect
,
555 const BitmapDeviceSharedPtr
& rClip
);
558 BASEBMP_DLLPRIVATE
BitmapDevice( const basegfx::B2IBox
& rBounds
,
559 const basegfx::B2IVector
& rBufferSize
,
560 Format nScanlineFormat
,
561 sal_Int32 nScanlineStride
,
562 sal_uInt8
* pFirstScanline
,
563 const RawMemorySharedArray
& rMem
,
564 const PaletteMemorySharedVector
& rPalette
);
565 BASEBMP_DLLPRIVATE
virtual ~BitmapDevice();
568 BASEBMP_DLLPRIVATE
virtual bool isCompatibleBitmap( const BitmapDeviceSharedPtr
& bmp
) const = 0;
569 BASEBMP_DLLPRIVATE
virtual bool isCompatibleClipMask( const BitmapDeviceSharedPtr
& bmp
) const = 0;
570 BASEBMP_DLLPRIVATE
virtual bool isCompatibleAlphaMask( const BitmapDeviceSharedPtr
& bmp
) const = 0;
572 BASEBMP_DLLPRIVATE
virtual void clear_i( Color fillColor
,
573 const basegfx::B2IBox
& rBounds
) = 0;
575 BASEBMP_DLLPRIVATE
virtual void setPixel_i( const basegfx::B2IPoint
& rPt
,
577 DrawMode drawMode
) = 0;
578 BASEBMP_DLLPRIVATE
virtual void setPixel_i( const basegfx::B2IPoint
& rPt
,
581 const BitmapDeviceSharedPtr
& rClip
) = 0;
583 BASEBMP_DLLPRIVATE
virtual Color
getPixel_i( const basegfx::B2IPoint
& rPt
) = 0;
585 BASEBMP_DLLPRIVATE
virtual sal_uInt32
getPixelData_i( const basegfx::B2IPoint
& rPt
) = 0;
587 BASEBMP_DLLPRIVATE
virtual void drawLine_i( const basegfx::B2IPoint
& rPt1
,
588 const basegfx::B2IPoint
& rPt2
,
589 const basegfx::B2IBox
& rBounds
,
591 DrawMode drawMode
) = 0;
592 BASEBMP_DLLPRIVATE
virtual void drawLine_i( const basegfx::B2IPoint
& rPt1
,
593 const basegfx::B2IPoint
& rPt2
,
594 const basegfx::B2IBox
& rBounds
,
597 const BitmapDeviceSharedPtr
& rClip
) = 0;
599 BASEBMP_DLLPRIVATE
virtual void drawPolygon_i( const basegfx::B2DPolygon
& rPoly
,
600 const basegfx::B2IBox
& rBounds
,
602 DrawMode drawMode
) = 0;
603 BASEBMP_DLLPRIVATE
virtual void drawPolygon_i( const basegfx::B2DPolygon
& rPoly
,
604 const basegfx::B2IBox
& rBounds
,
607 const BitmapDeviceSharedPtr
& rClip
) = 0;
609 BASEBMP_DLLPRIVATE
virtual void fillPolyPolygon_i( const basegfx::B2DPolyPolygon
& rPoly
,
612 const basegfx::B2IBox
& rBounds
) = 0;
613 BASEBMP_DLLPRIVATE
virtual void fillPolyPolygon_i( const basegfx::B2DPolyPolygon
& rPoly
,
616 const basegfx::B2IBox
& rBounds
,
617 const BitmapDeviceSharedPtr
& rClip
) = 0;
619 // must work with *this == rSrcBitmap!
620 BASEBMP_DLLPRIVATE
virtual void drawBitmap_i( const BitmapDeviceSharedPtr
& rSrcBitmap
,
621 const basegfx::B2IBox
& rSrcRect
,
622 const basegfx::B2IBox
& rDstRect
,
623 DrawMode drawMode
) = 0;
624 BASEBMP_DLLPRIVATE
virtual void drawBitmap_i( const BitmapDeviceSharedPtr
& rSrcBitmap
,
625 const basegfx::B2IBox
& rSrcRect
,
626 const basegfx::B2IBox
& rDstRect
,
628 const BitmapDeviceSharedPtr
& rClip
) = 0;
630 // must work with *this == rSrcBitmap!
631 BASEBMP_DLLPRIVATE
virtual void drawMaskedColor_i( Color rSrcColor
,
632 const BitmapDeviceSharedPtr
& rAlphaMask
,
633 const basegfx::B2IBox
& rSrcRect
,
634 const basegfx::B2IPoint
& rDstPoint
) = 0;
635 BASEBMP_DLLPRIVATE
virtual void drawMaskedColor_i( Color rSrcColor
,
636 const BitmapDeviceSharedPtr
& rAlphaMask
,
637 const basegfx::B2IBox
& rSrcRect
,
638 const basegfx::B2IPoint
& rDstPoint
,
639 const BitmapDeviceSharedPtr
& rClip
) = 0;
641 // must work with *this == rSrcBitmap!
642 BASEBMP_DLLPRIVATE
virtual void drawMaskedBitmap_i( const BitmapDeviceSharedPtr
& rSrcBitmap
,
643 const BitmapDeviceSharedPtr
& rMask
,
644 const basegfx::B2IBox
& rSrcRect
,
645 const basegfx::B2IBox
& rDstRect
,
646 DrawMode drawMode
) = 0;
647 BASEBMP_DLLPRIVATE
virtual void drawMaskedBitmap_i( const BitmapDeviceSharedPtr
& rSrcBitmap
,
648 const BitmapDeviceSharedPtr
& rMask
,
649 const basegfx::B2IBox
& rSrcRect
,
650 const basegfx::B2IBox
& rDstRect
,
652 const BitmapDeviceSharedPtr
& rClip
) = 0;
654 BASEBMP_DLLPRIVATE
virtual IBitmapDeviceDamageTrackerSharedPtr
getDamageTracker_i() const = 0;
655 BASEBMP_DLLPRIVATE
virtual void setDamageTracker_i( const IBitmapDeviceDamageTrackerSharedPtr
& rDamage
) = 0;
657 BitmapDeviceSharedPtr
getGenericRenderer() const;
659 boost::scoped_ptr
< ImplBitmapDevice
> mpImpl
;
662 /** Function to create a BitmapDevice for given scanline format
664 BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC
createBitmapDevice( const basegfx::B2IVector
& rSize
,
666 Format nScanlineFormat
);
668 /** Function to create a BitmapDevice for given scanline format
669 with the given palette
671 Note: the provided palette must have sufficient size, to satisfy
672 lookups for the whole range of pixel values from the specified
675 BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC
createBitmapDevice( const basegfx::B2IVector
& rSize
,
677 Format nScanlineFormat
,
678 const PaletteMemorySharedVector
& rPalette
);
680 /** Function to create a BitmapDevice for given scanline format
681 from the given piece of raw memory and palette
683 Note: the provided memory must have sufficient size, to store the
684 image of the specified area and format.
686 BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC
createBitmapDevice( const basegfx::B2IVector
& rSize
,
688 Format nScanlineFormat
,
689 const RawMemorySharedArray
& rMem
,
690 const PaletteMemorySharedVector
& rPalette
);
693 /** Function to retrieve a subsetted BitmapDevice to the same
696 Note that there is no coordinate system translation or offsetting
699 This method creates a second bitmap device instance, which renders
700 to the same memory as the original, with the same pixel coordinate
701 pairs refering to the same pixels in the memory buffer, but with
702 rendering clipped to a rectangular area. Useful to implement
703 rectangular clips (usually faster than setting up a 1bpp clip
707 BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC
subsetBitmapDevice( const BitmapDeviceSharedPtr
& rProto
,
708 const basegfx::B2IBox
& rSubset
);
710 /** Function to clone a BitmapDevice from a given prototype.
712 All attributes (like scanline format and top-down state) are
713 copied, only the size can be varied. Note that the prototype's
714 bitmap content is <em>not</em> copied, only a palette (if any).
716 BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC
cloneBitmapDevice( const basegfx::B2IVector
& rSize
,
717 const BitmapDeviceSharedPtr
& rProto
);
721 #endif /* INCLUDED_BASEBMP_BITMAPDEVICE_HXX */
723 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */