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/basebmpdllapi.h>
27 #include <boost/scoped_ptr.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/shared_array.hpp>
30 #include <boost/enable_shared_from_this.hpp>
31 #include <boost/noncopyable.hpp>
47 // Temporary. Use like the tools color object
49 typedef boost::shared_ptr
< class BitmapDevice
> BitmapDeviceSharedPtr
;
50 typedef boost::shared_ptr
< struct IBitmapDeviceDamageTracker
> IBitmapDeviceDamageTrackerSharedPtr
;
51 typedef boost::shared_array
< sal_uInt8
> RawMemorySharedArray
;
52 typedef boost::shared_ptr
< const std::vector
<Color
> > PaletteMemorySharedVector
;
54 struct ImplBitmapDevice
;
56 /// Interface for getting damage tracking events
57 struct IBitmapDeviceDamageTracker
59 /// gets called when said region is clobbered
60 virtual void damaged(const basegfx::B2IBox
& rDamageRect
) const = 0;
63 ~IBitmapDeviceDamageTracker() {}
66 /** Definition of BitmapDevice interface
68 Use the createBitmapDevice() function to create instances.
70 Implementation note: the clip mask and bitmap parameter instances
71 of BitmapDevice that are passed to individual BitmapDevice
72 instances work best with 1 bit grey masks for the clip and a
73 format matching that of the target BitmapDevice for the other
74 parameters. The alpha mask passed to the drawMaskedColor() methods
75 works best when given as an eight bit grey bitmap. Everything else
76 is accepted, but potentially slow.
78 class BASEBMP_DLLPUBLIC BitmapDevice
: public boost::enable_shared_from_this
<BitmapDevice
>,
79 private boost::noncopyable
82 /** Query size of device in pixel columns (X) and rows (Y, "scanlines")
84 basegfx::B2IVector
getSize() const;
86 /** Query whether buffer starts with 0th scanline
88 @return true, if the buffer memory starts with the 0th
89 scanline, and false if it starts with the last one. The latter
90 is e.g. the typical scan line ordering for the Windows BMP
93 bool isTopDown() const;
95 /** Query the size of the whole frame buffer
97 @ return the size of the whole frame buffer, the same as
98 getSize() unless this is a "subset" device.
100 basegfx::B2IVector
getBufferSize() const;
102 /** Query type of scanline memory format
104 sal_Int32
getScanlineFormat() const;
106 /** Query byte offset to get from scanline n to scanline n+1
108 @return the scanline stride in bytes.
110 sal_Int32
getScanlineStride() const;
112 /** Get pointer to frame buffer
114 @return a shared ptr to the bitmap buffer memory. As this is a
115 shared ptr, you can freely store and use the pointer, even
116 after this object has been deleted.
118 RawMemorySharedArray
getBuffer() const;
120 /// Query current damage tracking object (if any)
121 IBitmapDeviceDamageTrackerSharedPtr
getDamageTracker() const;
123 /** Set new damage tracking object
126 Object implementing the IBitmapDeviceDamageTracker interface -
127 everytime some area of the surface gets clobbered, that object
130 void setDamageTracker( const IBitmapDeviceDamageTrackerSharedPtr
& rDamage
);
132 /** Get pointer to palette
134 The returned pointer is const on purpose, since the
135 BitmapDevice might internally cache lookup information. Don't
136 modify the returned data, unless you want to enter the realm
137 of completely undefined behaviour.
139 @return shared pointer to vector of Color entries.
141 PaletteMemorySharedVector
getPalette() const;
143 /** Clear whole device with given color
145 This method works like a fill with the given color value,
146 resulting in a bitmap uniformly colored in fillColor.
148 void clear( Color fillColor
);
150 /** Set given pixel to specified color
156 Color value to set the pixel to
159 Draw mode to use when changing the pixel value
161 void setPixel( const basegfx::B2IPoint
& rPt
,
165 /** Set given pixel to specified color
171 Color value to set the pixel to
174 Draw mode to use when changing the pixel value
177 Clip mask to use. If the clip mask is 1 at the given pixel
178 position, no change will take place.
180 void setPixel( const basegfx::B2IPoint
& rPt
,
183 const BitmapDeviceSharedPtr
& rClip
);
185 /** Get color value at given pixel
187 Color
getPixel( const basegfx::B2IPoint
& rPt
);
189 /** Get underlying pixel data value at given position
191 This method returns the raw pixel data. In the case of
192 paletted bitmaps, this is the palette index, not the final
195 sal_uInt32
getPixelData( const basegfx::B2IPoint
& rPt
);
200 Start point of the line
203 End point of the line. If the analytical line from rP1 to rPt2
204 (with the actual pixel positions assumed to be the center of
205 the pixel) is exactly in the middle between two pixel, this
206 method always selects the pixel closer to rPt1.
209 Color value to draw the line with
212 Draw mode to use when changing the pixel value
214 void drawLine( const basegfx::B2IPoint
& rPt1
,
215 const basegfx::B2IPoint
& rPt2
,
222 Start point of the line
225 End point of the line. If the analytical line from rP1 to rPt2
226 (with the actual pixel positions assumed to be the center of
227 the pixel) is exactly in the middle between two pixel, this
228 method always selects the pixel closer to rPt1.
231 Color value to draw the line with
234 Draw mode to use when changing the pixel value
237 Clip mask to use. Pixel where the corresponding clip mask
238 pixel is 1 will not be modified.
240 void drawLine( const basegfx::B2IPoint
& rPt1
,
241 const basegfx::B2IPoint
& rPt2
,
244 const BitmapDeviceSharedPtr
& rClip
);
249 Polygon to draw. Depending on the value returned by rPoly's
250 isClosed() method, the resulting line polygon will be drawn
254 Color value to draw the polygon with
257 Draw mode to use when changing pixel values
259 void drawPolygon( const basegfx::B2DPolygon
& rPoly
,
266 Polygon to draw. Depending on the value returned by rPoly's
267 isClosed() method, the resulting line polygon will be drawn
271 Color value to draw the polygon with
274 Draw mode to use when changing pixel values
277 Clip mask to use. Pixel where the corresponding clip mask
278 pixel is 1 will not be modified.
280 void drawPolygon( const basegfx::B2DPolygon
& rPoly
,
283 const BitmapDeviceSharedPtr
& rClip
);
285 /** Fill a poly-polygon
288 Poly-polygon to fill. Regardless of the value returned by
289 rPoly's isClosed() method, the resulting filled poly-polygon
290 is always considered closed. As usual, when filling a shape,
291 the rightmost and bottommost pixel are not filled, compared to
292 the drawPolygon() method. For example, the rectangle
293 (0,0),(1,1) will have four pixel set, when drawn via
294 drawPolygon(), and only one pixel, when filled via
298 Color value to fill the poly-polygon with
301 Draw mode to use when changing pixel values
303 void fillPolyPolygon( const basegfx::B2DPolyPolygon
& rPoly
,
307 /** Fill a poly-polygon
310 Poly-polygon to fill. Regardless of the value returned by
311 rPoly's isClosed() method, the resulting filled poly-polygon
312 is always considered closed. As usual, when filling a shape,
313 the rightmost and bottommost pixel are not filled, compared to
314 the drawPolygon() method. For example, the rectangle
315 (0,0),(1,1) will have four pixel set, when drawn via
316 drawPolygon(), and only one pixel, when filled via
320 Color value to fill the poly-polygon with
323 Draw mode to use when changing pixel values
326 Clip mask to use. Pixel where the corresponding clip mask
327 pixel is 1 will not be modified.
329 void fillPolyPolygon( const basegfx::B2DPolyPolygon
& rPoly
,
332 const BitmapDeviceSharedPtr
& rClip
);
334 /** Draw another bitmap into this device
337 Bitmap to render into this one. It is permitted that source
338 and destination bitmap are the same.
341 Rectangle within the source bitmap to take the pixel from.
344 Rectangle in the destination bitmap to put the pixel
345 into. Source and destination rectangle are permitted to have
346 differing sizes; this method will scale the source pixel
347 accordingly. Please note that both source and destination
348 rectangle are interpreted excluding the rightmost pixel column
349 and the bottommost pixel row, this is much like polygon
350 filling. As a result, filling a given rectangle with
351 fillPolyPolygon(), and using the same rectangle as the
352 destination rectangle of this method, will affect exactly the
356 Draw mode to use when changing pixel values
358 void drawBitmap( const BitmapDeviceSharedPtr
& rSrcBitmap
,
359 const basegfx::B2IBox
& rSrcRect
,
360 const basegfx::B2IBox
& rDstRect
,
363 /** Draw another bitmap into this device
366 Bitmap to render into this one. It is permitted that source
367 and destination bitmap are the same.
370 Rectangle within the source bitmap to take the pixel from.
373 Rectangle in the destination bitmap to put the pixel
374 into. Source and destination rectangle are permitted to have
375 differing sizes; this method will scale the source pixel
376 accordingly. Please note that both source and destination
377 rectangle are interpreted excluding the rightmost pixel column
378 and the bottommost pixel row, this is much like polygon
379 filling. As a result, filling a given rectangle with
380 fillPolyPolygon(), and using the same rectangle as the
381 destination rectangle of this method, will affect exactly the
385 Draw mode to use when changing pixel values
388 Clip mask to use. Pixel where the corresponding clip mask
389 pixel is 1 will not be modified.
391 void drawBitmap( const BitmapDeviceSharedPtr
& rSrcBitmap
,
392 const basegfx::B2IBox
& rSrcRect
,
393 const basegfx::B2IBox
& rDstRect
,
395 const BitmapDeviceSharedPtr
& rClip
);
397 /** Draw a color with an alpha-modulation bitmap into this device
399 This method takes a fixed color value, and an alpha mask. For
400 each pixel in the alpha mask, the given color value is blended
401 with the corresponding alpha value against the content of this
405 Color value to use for blending
408 Alpha mask to use for blending. It is permitted that alpha
409 mask and this bitmap are the same object.
412 Rectangle within the alpha mask to take the pixel from.
413 Please note that the destination rectangle is interpreted
414 excluding the rightmost pixel column and the bottommost pixel
415 row, this is much like polygon filling. As a result, filling a
416 given rectangle with fillPolyPolygon(), and using the same
417 rectangle as the source rectangle of this method, will affect
418 exactly the same set of pixel.
421 Destination point, where to start placing the pixel from the
424 void drawMaskedColor( Color aSrcColor
,
425 const BitmapDeviceSharedPtr
& rAlphaMask
,
426 const basegfx::B2IBox
& rSrcRect
,
427 const basegfx::B2IPoint
& rDstPoint
);
429 /** Draw a color with an alpha-modulation bitmap into this device
431 This method takes a fixed color value, and an alpha mask. For
432 each pixel in the alpha mask, the given color value is blended
433 with the corresponding alpha value against the content of this
437 Color value to use for blending
440 Alpha mask to use for blending. It is permitted that alpha
441 mask and this bitmap are the same object.
444 Rectangle within the alpha mask to take the pixel from.
445 Please note that the destination rectangle is interpreted
446 excluding the rightmost pixel column and the bottommost pixel
447 row, this is much like polygon filling. As a result, filling a
448 given rectangle with fillPolyPolygon(), and using the same
449 rectangle as the source rectangle of this method, will affect
450 exactly the same set of pixel.
453 Destination point, where to start placing the pixel from the
457 Clip mask to use. Pixel where the corresponding clip mask
458 pixel is 1 will not be modified.
460 void drawMaskedColor( Color aSrcColor
,
461 const BitmapDeviceSharedPtr
& rAlphaMask
,
462 const basegfx::B2IBox
& rSrcRect
,
463 const basegfx::B2IPoint
& rDstPoint
,
464 const BitmapDeviceSharedPtr
& rClip
);
466 /** Draw another bitmap through a mask into this device
468 This method renders a source bitmap into this device, much
469 like the drawBitmap() method. The only difference is the
470 additional mask parameter, which operates much like an
471 additional clip mask: pixel with value zero in this mask
472 result in destination pixel not being modified.
475 Bitmap to render into this one. It is permitted that source
476 and destination bitmap are the same.
479 Bitmap to use as a mask. Pixel with value != zero in this mask
480 will result in destination pixel not being affected by the
484 Rectangle within the source bitmap to take the pixel from.
487 Rectangle in the destination bitmap to put the pixel
488 into. Source and destination rectangle are permitted to have
489 differing sizes; this method will scale the source pixel
490 accordingly. Please note that both source and destination
491 rectangle are interpreted excluding the rightmost pixel column
492 and the bottommost pixel row, this is much like polygon
493 filling. As a result, filling a given rectangle with
494 fillPolyPolygon(), and using the same rectangle as the
495 destination rectangle of this method, will affect exactly the
499 Draw mode to use when changing pixel values
501 void drawMaskedBitmap( const BitmapDeviceSharedPtr
& rSrcBitmap
,
502 const BitmapDeviceSharedPtr
& rMask
,
503 const basegfx::B2IBox
& rSrcRect
,
504 const basegfx::B2IBox
& rDstRect
,
507 /** Draw another bitmap through a mask into this device
509 This method renders a source bitmap into this device, much
510 like the drawBitmap() method. The only difference is the
511 additional mask parameter, which operates much like an
512 additional clip mask: pixel with value != zero in this mask
513 result in destination pixel not being modified.
516 Bitmap to render into this one. It is permitted that source
517 and destination bitmap are the same.
520 Bitmap to use as a mask. Pixel with value != zero in this mask
521 will result in destination pixel not being affected by the
525 Rectangle within the source bitmap to take the pixel from.
528 Rectangle in the destination bitmap to put the pixel
529 into. Source and destination rectangle are permitted to have
530 differing sizes; this method will scale the source pixel
531 accordingly. Please note that both source and destination
532 rectangle are interpreted excluding the rightmost pixel column
533 and the bottommost pixel row, this is much like polygon
534 filling. As a result, filling a given rectangle with
535 fillPolyPolygon(), and using the same rectangle as the
536 destination rectangle of this method, will affect exactly the
540 Draw mode to use when changing pixel values
543 Clip mask to use. Pixel where the corresponding clip mask
544 pixel is 1 will not be modified.
546 void drawMaskedBitmap( const BitmapDeviceSharedPtr
& rSrcBitmap
,
547 const BitmapDeviceSharedPtr
& rMask
,
548 const basegfx::B2IBox
& rSrcRect
,
549 const basegfx::B2IBox
& rDstRect
,
551 const BitmapDeviceSharedPtr
& rClip
);
554 BASEBMP_DLLPRIVATE
BitmapDevice( const basegfx::B2IBox
& rBounds
,
555 const basegfx::B2IVector
& rBufferSize
,
556 sal_Int32 nScanlineFormat
,
557 sal_Int32 nScanlineStride
,
558 sal_uInt8
* pFirstScanline
,
559 const RawMemorySharedArray
& rMem
,
560 const PaletteMemorySharedVector
& rPalette
);
561 BASEBMP_DLLPRIVATE
virtual ~BitmapDevice();
564 BASEBMP_DLLPRIVATE
virtual bool isCompatibleBitmap( const BitmapDeviceSharedPtr
& bmp
) const = 0;
565 BASEBMP_DLLPRIVATE
virtual bool isCompatibleClipMask( const BitmapDeviceSharedPtr
& bmp
) const = 0;
566 BASEBMP_DLLPRIVATE
virtual bool isCompatibleAlphaMask( const BitmapDeviceSharedPtr
& bmp
) const = 0;
568 BASEBMP_DLLPRIVATE
virtual void clear_i( Color fillColor
,
569 const basegfx::B2IBox
& rBounds
) = 0;
571 BASEBMP_DLLPRIVATE
virtual void setPixel_i( const basegfx::B2IPoint
& rPt
,
573 DrawMode drawMode
) = 0;
574 BASEBMP_DLLPRIVATE
virtual void setPixel_i( const basegfx::B2IPoint
& rPt
,
577 const BitmapDeviceSharedPtr
& rClip
) = 0;
579 BASEBMP_DLLPRIVATE
virtual Color
getPixel_i( const basegfx::B2IPoint
& rPt
) = 0;
581 BASEBMP_DLLPRIVATE
virtual sal_uInt32
getPixelData_i( const basegfx::B2IPoint
& rPt
) = 0;
583 BASEBMP_DLLPRIVATE
virtual void drawLine_i( const basegfx::B2IPoint
& rPt1
,
584 const basegfx::B2IPoint
& rPt2
,
585 const basegfx::B2IBox
& rBounds
,
587 DrawMode drawMode
) = 0;
588 BASEBMP_DLLPRIVATE
virtual void drawLine_i( const basegfx::B2IPoint
& rPt1
,
589 const basegfx::B2IPoint
& rPt2
,
590 const basegfx::B2IBox
& rBounds
,
593 const BitmapDeviceSharedPtr
& rClip
) = 0;
595 BASEBMP_DLLPRIVATE
virtual void drawPolygon_i( const basegfx::B2DPolygon
& rPoly
,
596 const basegfx::B2IBox
& rBounds
,
598 DrawMode drawMode
) = 0;
599 BASEBMP_DLLPRIVATE
virtual void drawPolygon_i( const basegfx::B2DPolygon
& rPoly
,
600 const basegfx::B2IBox
& rBounds
,
603 const BitmapDeviceSharedPtr
& rClip
) = 0;
605 BASEBMP_DLLPRIVATE
virtual void fillPolyPolygon_i( const basegfx::B2DPolyPolygon
& rPoly
,
608 const basegfx::B2IBox
& rBounds
) = 0;
609 BASEBMP_DLLPRIVATE
virtual void fillPolyPolygon_i( const basegfx::B2DPolyPolygon
& rPoly
,
612 const basegfx::B2IBox
& rBounds
,
613 const BitmapDeviceSharedPtr
& rClip
) = 0;
615 // must work with *this == rSrcBitmap!
616 BASEBMP_DLLPRIVATE
virtual void drawBitmap_i( const BitmapDeviceSharedPtr
& rSrcBitmap
,
617 const basegfx::B2IBox
& rSrcRect
,
618 const basegfx::B2IBox
& rDstRect
,
619 DrawMode drawMode
) = 0;
620 BASEBMP_DLLPRIVATE
virtual void drawBitmap_i( const BitmapDeviceSharedPtr
& rSrcBitmap
,
621 const basegfx::B2IBox
& rSrcRect
,
622 const basegfx::B2IBox
& rDstRect
,
624 const BitmapDeviceSharedPtr
& rClip
) = 0;
626 // must work with *this == rSrcBitmap!
627 BASEBMP_DLLPRIVATE
virtual void drawMaskedColor_i( Color rSrcColor
,
628 const BitmapDeviceSharedPtr
& rAlphaMask
,
629 const basegfx::B2IBox
& rSrcRect
,
630 const basegfx::B2IPoint
& rDstPoint
) = 0;
631 BASEBMP_DLLPRIVATE
virtual void drawMaskedColor_i( Color rSrcColor
,
632 const BitmapDeviceSharedPtr
& rAlphaMask
,
633 const basegfx::B2IBox
& rSrcRect
,
634 const basegfx::B2IPoint
& rDstPoint
,
635 const BitmapDeviceSharedPtr
& rClip
) = 0;
637 // must work with *this == rSrcBitmap!
638 BASEBMP_DLLPRIVATE
virtual void drawMaskedBitmap_i( const BitmapDeviceSharedPtr
& rSrcBitmap
,
639 const BitmapDeviceSharedPtr
& rMask
,
640 const basegfx::B2IBox
& rSrcRect
,
641 const basegfx::B2IBox
& rDstRect
,
642 DrawMode drawMode
) = 0;
643 BASEBMP_DLLPRIVATE
virtual void drawMaskedBitmap_i( const BitmapDeviceSharedPtr
& rSrcBitmap
,
644 const BitmapDeviceSharedPtr
& rMask
,
645 const basegfx::B2IBox
& rSrcRect
,
646 const basegfx::B2IBox
& rDstRect
,
648 const BitmapDeviceSharedPtr
& rClip
) = 0;
650 BASEBMP_DLLPRIVATE
virtual IBitmapDeviceDamageTrackerSharedPtr
getDamageTracker_i() const = 0;
651 BASEBMP_DLLPRIVATE
virtual void setDamageTracker_i( const IBitmapDeviceDamageTrackerSharedPtr
& rDamage
) = 0;
653 BitmapDeviceSharedPtr
getGenericRenderer() const;
655 boost::scoped_ptr
< ImplBitmapDevice
> mpImpl
;
658 /** Function to create a BitmapDevice for given scanline format
660 BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC
createBitmapDevice( const basegfx::B2IVector
& rSize
,
662 sal_Int32 nScanlineFormat
);
664 /** Function to create a BitmapDevice for given scanline format
665 with the given palette
667 Note: the provided palette must have sufficient size, to satisfy
668 lookups for the whole range of pixel values from the specified
671 BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC
createBitmapDevice( const basegfx::B2IVector
& rSize
,
673 sal_Int32 nScanlineFormat
,
674 const PaletteMemorySharedVector
& rPalette
);
676 /** Function to create a BitmapDevice for given scanline format
677 from the given piece of raw memory and palette
679 Note: the provided memory must have sufficient size, to store the
680 image of the specified area and format.
682 BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC
createBitmapDevice( const basegfx::B2IVector
& rSize
,
684 sal_Int32 nScanlineFormat
,
685 const RawMemorySharedArray
& rMem
,
686 const PaletteMemorySharedVector
& rPalette
);
689 /** Function to retrieve a subsetted BitmapDevice to the same
692 Note that there is no coordinate system translation or offsetting
695 This method creates a second bitmap device instance, which renders
696 to the same memory as the original, with the same pixel coordinate
697 pairs refering to the same pixels in the memory buffer, but with
698 rendering clipped to a rectangular area. Useful to implement
699 rectangular clips (usually faster than setting up a 1bpp clip
703 BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC
subsetBitmapDevice( const BitmapDeviceSharedPtr
& rProto
,
704 const basegfx::B2IBox
& rSubset
);
706 /** Function to clone a BitmapDevice from a given prototype.
708 All attributes (like scanline format and top-down state) are
709 copied, only the size can be varied. Note that the prototype's
710 bitmap content is <em>not</em> copied, only a palette (if any).
712 BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC
cloneBitmapDevice( const basegfx::B2IVector
& rSize
,
713 const BitmapDeviceSharedPtr
& rProto
);
717 #endif /* INCLUDED_BASEBMP_BITMAPDEVICE_HXX */
719 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */