1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_CANVAS_BITMAP_HXX
25 #define INCLUDED_CANVAS_BITMAP_HXX
26 
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/rendering/XCanvas.hpp>
29 #include <com/sun/star/rendering/IntegerBitmapLayout.hpp>
30 #include <com/sun/star/geometry/IntegerRectangle2D.hpp>
31 #include <com/sun/star/geometry/IntegerPoint2D.hpp>
32 #include <canvas/rendering/icolorbuffer.hxx>
33 #include <canvas/rendering/icachedprimitive.hxx>
34 #include <canvas/rendering/isurfaceproxymanager.hxx>
35 
36 #include <boost/shared_ptr.hpp>
37 #include <boost/scoped_ptr.hpp>
38 #include <vector>
39 
40 namespace basegfx
41 {
42     class B2IVector;
43     class B2DPoint;
44     class B2DHomMatrix;
45     class B2DPolyPolygon;
46 }
47 
48 namespace canvas
49 {
50     class ImplBitmap;
51 
52     /** Bitmap class, with XCanvas-like render interface.
53 
54         This class provides a bitmap, that can be rendered into,
55         with an interface compatible to XCanvas. Furthermore, the
56         bitmaps held here can optionally be backed by (possibly
57         hw-accelerated) textures.
58     */
59 	class Bitmap
60     {
61     public:
62         /** Create bitmap with given size
63 
64             @param rSize
65             Size of the bitmap, in pixel
66 
67             @param rMgr
68             SurfaceProxyManager, to use for HW acceleration
69 
70             @param bWithAlpha
71             When true, the created bitmap will have an alpha channel,
72             false otherwise
73          */
74         Bitmap( const ::basegfx::B2IVector&          rSize,
75                 const ISurfaceProxyManagerSharedPtr& rMgr,
76                 bool                                 bWithAlpha );
77         ~Bitmap();
78 
79         /// Query whether this bitmap contains alpha channel information
80         bool hasAlpha() const;
81 
82         /// Query size of the bitmap in pixel
83         ::basegfx::B2IVector getSize() const;
84 
85 		::com::sun::star::uno::Sequence< sal_Int8 > getData(
86 			::com::sun::star::rendering::IntegerBitmapLayout&		bitmapLayout,
87 			const ::com::sun::star::geometry::IntegerRectangle2D&	rect );
88 
89 		void setData(
90 			const ::com::sun::star::uno::Sequence< sal_Int8 >&		data,
91 			const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
92 			const ::com::sun::star::geometry::IntegerRectangle2D&	rect );
93 
94 		void setPixel(
95 			const ::com::sun::star::uno::Sequence< sal_Int8 >&		color,
96 			const ::com::sun::star::rendering::IntegerBitmapLayout& bitmapLayout,
97 			const ::com::sun::star::geometry::IntegerPoint2D&		pos );
98 
99 		::com::sun::star::uno::Sequence< sal_Int8 > getPixel(
100 			::com::sun::star::rendering::IntegerBitmapLayout&		bitmapLayout,
101             const ::com::sun::star::geometry::IntegerPoint2D&		pos );
102 
103         /** Render the bitmap content to associated
104             SurfaceProxyManager's screen.
105 
106             @param fAlpha
107             Overall alpha for content
108 
109             @param rPos
110             Output position
111 
112             @param rTransform
113             Output transformation (does not affect output position)
114          */
115         bool draw( double                         fAlpha,
116                    const ::basegfx::B2DPoint&     rPos,
117                    const ::basegfx::B2DHomMatrix& rTransform );
118 
119         /** Render the bitmap content to associated
120             SurfaceProxyManager's screen.
121 
122             @param fAlpha
123             Overall alpha for content
124 
125             @param rPos
126             Output position
127 
128             @param rArea
129             Subset of the surface to render. Coordinate system are
130             surface area pixel, given area will be clipped to the
131             surface bounds.
132 
133             @param rTransform
134             Output transformation (does not affect output position)
135          */
136         bool draw( double                         fAlpha,
137                    const ::basegfx::B2DPoint&     rPos,
138                    const ::basegfx::B2DRange&     rArea,
139                    const ::basegfx::B2DHomMatrix& rTransform );
140 
141         /** Render the bitmap content to associated
142             SurfaceProxyManager's screen.
143 
144             @param fAlpha
145             Overall alpha for content
146 
147             @param rPos
148             Output position
149 
150             @param rClipPoly
151             Clip polygon for the surface. The clip polygon is also
152             subject to the output transformation.
153 
154             @param rTransform
155             Output transformation (does not affect output position)
156          */
157         bool draw( double                           fAlpha,
158                    const ::basegfx::B2DPoint&       rPos,
159                    const ::basegfx::B2DPolyPolygon& rClipPoly,
160                    const ::basegfx::B2DHomMatrix&   rTransform );
161 
162         /** Clear whole bitmap with given color.
163 
164             This method sets every single pixel of the bitmap to the
165             specified color value.
166          */
167         void clear( const ::com::sun::star::uno::Sequence< double >& color );
168 
169         void fillB2DPolyPolygon(
170             const ::basegfx::B2DPolyPolygon&                    rPolyPolygon,
171             const ::com::sun::star::rendering::ViewState& 		viewState,
172             const ::com::sun::star::rendering::RenderState& 	renderState );
173 
174 
175         // High-level drawing operations (from the XCanvas interface)
176         // ==========================================================
177 
178         /// See XCanvas interface
179         void drawPoint( const ::com::sun::star::geometry::RealPoint2D& 		aPoint,
180                         const ::com::sun::star::rendering::ViewState& 		viewState,
181                         const ::com::sun::star::rendering::RenderState& 	renderState );
182         /// See XCanvas interface
183         void drawLine( const ::com::sun::star::geometry::RealPoint2D& 	aStartPoint,
184                        const ::com::sun::star::geometry::RealPoint2D& 	aEndPoint,
185                        const ::com::sun::star::rendering::ViewState& 	viewState,
186                        const ::com::sun::star::rendering::RenderState& 	renderState	);
187         /// See XCanvas interface
188         void drawBezier( const ::com::sun::star::geometry::RealBezierSegment2D&	aBezierSegment,
189                          const ::com::sun::star::geometry::RealPoint2D& 		aEndPoint,
190                          const ::com::sun::star::rendering::ViewState& 			viewState,
191                          const ::com::sun::star::rendering::RenderState& 		renderState );
192         /// See XCanvas interface
193         ICachedPrimitiveSharedPtr drawPolyPolygon(
194             const ::com::sun::star::uno::Reference<
195                   ::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
196             const ::com::sun::star::rendering::ViewState&           viewState,
197             const ::com::sun::star::rendering::RenderState&         renderState );
198 
199         /// See XCanvas interface
200         ICachedPrimitiveSharedPtr strokePolyPolygon(
201             const ::com::sun::star::uno::Reference<
202                   ::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
203             const ::com::sun::star::rendering::ViewState&           viewState,
204             const ::com::sun::star::rendering::RenderState& 		renderState,
205             const ::com::sun::star::rendering::StrokeAttributes&    strokeAttributes );
206         /** See XCanvas interface
207 
208             @param textureAnnotations
209             Vector of shared pointers to bitmap textures,
210             <em>corresponding</em> in indices to the textures
211             sequence. This is to decouple this interface from the
212             client's XBitmap-implementation class.
213          */
214         ICachedPrimitiveSharedPtr strokeTexturedPolyPolygon(
215             const ::com::sun::star::uno::Reference<
216                   ::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
217             const ::com::sun::star::rendering::ViewState&           viewState,
218             const ::com::sun::star::rendering::RenderState& 		renderState,
219             const ::com::sun::star::uno::Sequence<
220                   ::com::sun::star::rendering::Texture >&           textures,
221             const ::std::vector< ::boost::shared_ptr<Bitmap> >&     textureAnnotations,
222             const ::com::sun::star::rendering::StrokeAttributes&    strokeAttributes );
223         /** See XCanvas interface
224 
225             @param textureAnnotations
226             Vector of shared pointers to bitmap textures,
227             <em>corresponding</em> in indices to the textures
228             sequence. This is to decouple this interface from the
229             client's XBitmap-implementation class.
230          */
231         ICachedPrimitiveSharedPtr strokeTextureMappedPolyPolygon(
232             const ::com::sun::star::uno::Reference<
233                   ::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
234             const ::com::sun::star::rendering::ViewState& 			viewState,
235             const ::com::sun::star::rendering::RenderState& 		renderState,
236             const ::com::sun::star::uno::Sequence<
237                   ::com::sun::star::rendering::Texture >&           textures,
238             const ::std::vector< ::boost::shared_ptr<Bitmap> >&     textureAnnotations,
239             const ::com::sun::star::uno::Reference<
240                   ::com::sun::star::geometry::XMapping2D >& 		xMapping,
241             const ::com::sun::star::rendering::StrokeAttributes& 	strokeAttributes );
242         /// See XCanvas interface
243         ICachedPrimitiveSharedPtr fillPolyPolygon(
244             const ::com::sun::star::uno::Reference<
245                   ::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
246             const ::com::sun::star::rendering::ViewState& 			viewState,
247             const ::com::sun::star::rendering::RenderState& 		renderState );
248         /** See XCanvas interface
249 
250             @param textureAnnotations
251             Vector of shared pointers to bitmap textures,
252             <em>corresponding</em> in indices to the textures
253             sequence. This is to decouple this interface from the
254             client's XBitmap-implementation class.
255          */
256         ICachedPrimitiveSharedPtr fillTexturedPolyPolygon(
257             const ::com::sun::star::uno::Reference<
258                   ::com::sun::star::rendering::XPolyPolygon2D >&	xPolyPolygon,
259             const ::com::sun::star::rendering::ViewState& 			viewState,
260             const ::com::sun::star::rendering::RenderState& 		renderState,
261             const ::com::sun::star::uno::Sequence<
262                   ::com::sun::star::rendering::Texture >&           textures,
263             const ::std::vector< ::boost::shared_ptr<Bitmap> >&     textureAnnotations );
264         /** See XCanvas interface
265 
266             @param textureAnnotations
267             Vector of shared pointers to bitmap textures,
268             <em>corresponding</em> in indices to the textures
269             sequence. This is to decouple this interface from the
270             client's XBitmap-implementation class.
271          */
272         ICachedPrimitiveSharedPtr fillTextureMappedPolyPolygon(
273             const ::com::sun::star::uno::Reference<
274                   ::com::sun::star::rendering::XPolyPolygon2D >& 	xPolyPolygon,
275             const ::com::sun::star::rendering::ViewState&           viewState,
276             const ::com::sun::star::rendering::RenderState& 		renderState,
277             const ::com::sun::star::uno::Sequence<
278                   ::com::sun::star::rendering::Texture >&           textures,
279             const ::std::vector< ::boost::shared_ptr<Bitmap> >&     textureAnnotations,
280             const ::com::sun::star::uno::Reference<
281                   ::com::sun::star::geometry::XMapping2D >& 		xMapping );
282 
283         /// See XCanvas interface
284         ICachedPrimitiveSharedPtr drawBitmap(
285             const ::com::sun::star::uno::Reference<
286                   ::com::sun::star::rendering::XBitmap >&   xBitmap,
287             const ::com::sun::star::rendering::ViewState& 	viewState,
288             const ::com::sun::star::rendering::RenderState& renderState );
289         /// See XCanvas interface
290         ICachedPrimitiveSharedPtr drawBitmap(
291             const ::boost::shared_ptr<Bitmap>&              rImage,
292             const ::com::sun::star::rendering::ViewState& 	viewState,
293             const ::com::sun::star::rendering::RenderState& renderState );
294 
295         /// See XCanvas interface
296         ICachedPrimitiveSharedPtr drawBitmapModulated(
297             const ::com::sun::star::uno::Reference<
298                   ::com::sun::star::rendering::XBitmap >&		xBitmap,
299             const ::com::sun::star::rendering::ViewState& 		viewState,
300             const ::com::sun::star::rendering::RenderState&     renderState );
301         /// See XCanvas interface
302         ICachedPrimitiveSharedPtr drawBitmapModulated(
303             const ::boost::shared_ptr<Bitmap>&                  rImage,
304             const ::com::sun::star::rendering::ViewState& 		viewState,
305             const ::com::sun::star::rendering::RenderState&     renderState );
306 
307     private:
308         friend class ImplBitmap;
309 
310         const ::boost::scoped_ptr< ImplBitmap > mpImpl;
311 	};
312 
313     typedef ::boost::shared_ptr< Bitmap > BitmapSharedPtr;
314 }
315 
316 #endif /* INCLUDED_CANVAS_BITMAP_HXX */
317