CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / canvas / source / tools / image.hxx
blob1c62c7d6276baeeae9e14a4694350cea2fa8beb6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef INCLUDED_CANVAS_IMAGE_HXX
29 #define INCLUDED_CANVAS_IMAGE_HXX
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/rendering/XCanvas.hpp>
33 #include <canvas/rendering/icolorbuffer.hxx>
34 #include <canvas/parametricpolypolygon.hxx>
35 #include "imagecachedprimitive.hxx"
37 #include <canvas/elapsedtime.hxx>
39 #include "image_sysprereq.h"
41 struct BitmapSystemData;
42 class BitmapEx;
44 namespace canvas
46 class Image : public IColorBuffer
48 public:
49 /// The description of the image
50 struct Description
52 IColorBuffer::Format eFormat;
53 sal_uInt32 nWidth;
54 sal_uInt32 nHeight;
55 sal_uInt32 nStride;
56 sal_uInt8* pBuffer;
59 /** Create a new image with the attributes passed as argument.
61 explicit Image( const Description& desc );
63 /** Create a new image from the XBitmap passed as argument
65 explicit Image( const ::com::sun::star::uno::Reference<
66 ::com::sun::star::rendering::XBitmap >& xBitmap );
69 virtual ~Image();
71 /** Retrieve desciption of image layout
73 const Description& getDescription() const { return maDesc; }
75 /** Clear image with uniform color
77 void clear( sal_uInt8 a,
78 sal_uInt8 r,
79 sal_uInt8 g,
80 sal_uInt8 b );
82 void fillB2DPolyPolygon(
83 const ::basegfx::B2DPolyPolygon& rPolyPolygon,
84 const ::com::sun::star::rendering::ViewState& viewState,
85 const ::com::sun::star::rendering::RenderState& renderState );
88 // IColorBuffer interface implementation
89 // =====================================
91 virtual sal_uInt8* lock() const;
92 virtual void unlock() const;
93 virtual sal_uInt32 getWidth() const;
94 virtual sal_uInt32 getHeight() const;
95 virtual sal_uInt32 getStride() const;
96 virtual Format getFormat() const;
99 // High-level drawing operations (from the XCanvas interface)
100 // ==========================================================
102 void drawPoint( const ::com::sun::star::geometry::RealPoint2D& aPoint,
103 const ::com::sun::star::rendering::ViewState& viewState,
104 const ::com::sun::star::rendering::RenderState& renderState );
105 void drawLine( const ::com::sun::star::geometry::RealPoint2D& aStartPoint,
106 const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
107 const ::com::sun::star::rendering::ViewState& viewState,
108 const ::com::sun::star::rendering::RenderState& renderState );
109 void drawBezier( const ::com::sun::star::geometry::RealBezierSegment2D& aBezierSegment,
110 const ::com::sun::star::geometry::RealPoint2D& aEndPoint,
111 const ::com::sun::star::rendering::ViewState& viewState,
112 const ::com::sun::star::rendering::RenderState& renderState );
113 ImageCachedPrimitiveSharedPtr drawPolyPolygon(
114 const ::com::sun::star::uno::Reference<
115 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
116 const ::com::sun::star::rendering::ViewState& viewState,
117 const ::com::sun::star::rendering::RenderState& renderState );
119 ImageCachedPrimitiveSharedPtr strokePolyPolygon(
120 const ::com::sun::star::uno::Reference<
121 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
122 const ::com::sun::star::rendering::ViewState& viewState,
123 const ::com::sun::star::rendering::RenderState& renderState,
124 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
125 ImageCachedPrimitiveSharedPtr strokeTexturedPolyPolygon(
126 const ::com::sun::star::uno::Reference<
127 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
128 const ::com::sun::star::rendering::ViewState& viewState,
129 const ::com::sun::star::rendering::RenderState& renderState,
130 const ::com::sun::star::uno::Sequence<
131 ::com::sun::star::rendering::Texture >& textures,
132 const ::std::vector< ::boost::shared_ptr<Image> >& textureAnnotations,
133 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
134 ImageCachedPrimitiveSharedPtr strokeTextureMappedPolyPolygon(
135 const ::com::sun::star::uno::Reference<
136 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
137 const ::com::sun::star::rendering::ViewState& viewState,
138 const ::com::sun::star::rendering::RenderState& renderState,
139 const ::com::sun::star::uno::Sequence<
140 ::com::sun::star::rendering::Texture >& textures,
141 const ::std::vector< ::boost::shared_ptr<Image> >& textureAnnotations,
142 const ::com::sun::star::uno::Reference<
143 ::com::sun::star::geometry::XMapping2D >& xMapping,
144 const ::com::sun::star::rendering::StrokeAttributes& strokeAttributes );
145 ImageCachedPrimitiveSharedPtr fillPolyPolygon(
146 const ::com::sun::star::uno::Reference<
147 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
148 const ::com::sun::star::rendering::ViewState& viewState,
149 const ::com::sun::star::rendering::RenderState& renderState );
150 ImageCachedPrimitiveSharedPtr fillTexturedPolyPolygon(
151 const ::com::sun::star::uno::Reference<
152 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
153 const ::com::sun::star::rendering::ViewState& viewState,
154 const ::com::sun::star::rendering::RenderState& renderState,
155 const ::com::sun::star::uno::Sequence<
156 ::com::sun::star::rendering::Texture >& textures,
157 const ::std::vector< ::boost::shared_ptr<Image> >& textureAnnotations );
158 ImageCachedPrimitiveSharedPtr fillTextureMappedPolyPolygon(
159 const ::com::sun::star::uno::Reference<
160 ::com::sun::star::rendering::XPolyPolygon2D >& xPolyPolygon,
161 const ::com::sun::star::rendering::ViewState& viewState,
162 const ::com::sun::star::rendering::RenderState& renderState,
163 const ::com::sun::star::uno::Sequence<
164 ::com::sun::star::rendering::Texture >& textures,
165 const ::std::vector< ::boost::shared_ptr<Image> >& textureAnnotations,
166 const ::com::sun::star::uno::Reference<
167 ::com::sun::star::geometry::XMapping2D >& xMapping );
169 ImageCachedPrimitiveSharedPtr drawBitmap(
170 const ::com::sun::star::uno::Reference<
171 ::com::sun::star::rendering::XBitmap >& xBitmap,
172 const ::com::sun::star::rendering::ViewState& viewState,
173 const ::com::sun::star::rendering::RenderState& renderState );
174 ImageCachedPrimitiveSharedPtr drawBitmap(
175 const ::boost::shared_ptr<Image>& rImage,
176 const ::com::sun::star::rendering::ViewState& viewState,
177 const ::com::sun::star::rendering::RenderState& renderState );
179 ImageCachedPrimitiveSharedPtr drawBitmapModulated(
180 const ::com::sun::star::uno::Reference<
181 ::com::sun::star::rendering::XBitmap >& xBitmap,
182 const ::com::sun::star::rendering::ViewState& viewState,
183 const ::com::sun::star::rendering::RenderState& renderState );
184 ImageCachedPrimitiveSharedPtr drawBitmapModulated(
185 const ::boost::shared_ptr<Image>& rImage,
186 const ::com::sun::star::rendering::ViewState& viewState,
187 const ::com::sun::star::rendering::RenderState& renderState );
189 private:
190 void drawLinePolyPolygon( const ::basegfx::B2DPolyPolygon& rPoly,
191 double fStrokeWidth,
192 const ::com::sun::star::rendering::ViewState& viewState,
193 const ::com::sun::star::rendering::RenderState& renderState );
195 ImageCachedPrimitiveSharedPtr implDrawBitmap(
196 const Image& rBitmap,
197 const ::com::sun::star::rendering::ViewState& viewState,
198 const ::com::sun::star::rendering::RenderState& renderState );
200 ImageCachedPrimitiveSharedPtr fillTexturedPolyPolygon(
201 const Image& rTexture,
202 const ::basegfx::B2DPolyPolygon& rPolyPolygon,
203 const ::basegfx::B2DHomMatrix& rOverallTransform,
204 const ::basegfx::B2DHomMatrix& rViewTransform,
205 const ::com::sun::star::rendering::Texture& texture );
207 void fillGradient( const ParametricPolyPolygon::Values& rValues,
208 const ::com::sun::star::uno::Sequence< double >& rColor1,
209 const ::com::sun::star::uno::Sequence< double >& rColor2,
210 const ::basegfx::B2DPolyPolygon& rPolyPolygon,
211 const ::basegfx::B2DHomMatrix& rOverallTransform,
212 const ::com::sun::star::rendering::Texture& texture );
213 bool fromVCLBitmap( ::BitmapEx& rBmpEx );
215 template<class pixel_format>
216 void drawLinePolyPolygonImpl( const ::basegfx::B2DPolyPolygon& rPoly,
217 double fStrokeWidth,
218 const ::com::sun::star::rendering::ViewState& viewState,
219 const ::com::sun::star::rendering::RenderState& renderState );
221 template<class pixel_format,class span_gen_type>
222 ImageCachedPrimitiveSharedPtr fillTexturedPolyPolygonImpl(
223 const Image& rTexture,
224 const ::basegfx::B2DPolyPolygon& rPolyPolygon,
225 const ::basegfx::B2DHomMatrix& rOverallTransform,
226 const ::basegfx::B2DHomMatrix& rViewTransform,
227 const ::com::sun::star::rendering::Texture& texture );
229 template<class pixel_format>
230 void fillGradientImpl( const ParametricPolyPolygon::Values& rValues,
231 const ::com::sun::star::uno::Sequence< double >& rUnoColor1,
232 const ::com::sun::star::uno::Sequence< double >& rUnoColor2,
233 const ::basegfx::B2DPolyPolygon& rPolyPolygon,
234 const ::basegfx::B2DHomMatrix& rOverallTransform,
235 const ::com::sun::star::rendering::Texture& texture );
237 template<class pixel_format>
238 ImageCachedPrimitiveSharedPtr fillPolyPolygonImpl(
239 const ::basegfx::B2DPolyPolygon& rPolyPolygon,
240 const ::com::sun::star::rendering::ViewState& viewState,
241 const ::com::sun::star::rendering::RenderState& renderState );
243 template<class pixel_format> void clearImpl( sal_uInt8 a,
244 sal_uInt8 r,
245 sal_uInt8 g,
246 sal_uInt8 b );
248 /** Image description
250 Description maDesc;
252 /** the graphics buffer is a simple array
253 where each element points to the start
254 of a scanline in consecutive order.
256 agg::rendering_buffer maRenderingBuffer;
258 /// Whether maRenderingBuffer is owned by the client of this object
259 bool mbBufferHasUserOwnership;
261 #if defined(PROFILER)
263 enum constant
265 TIMER_FILLTEXTUREDPOLYPOLYGON,
266 TIMER_FILLB2DPOLYPOLYGON,
267 TIMER_DRAWPOLYPOLYGON,
268 TIMER_FILLPOLYPOLYGON,
269 TIMER_DRAWBITMAP,
270 TIMER_MAX
273 double maElapsedTime[TIMER_MAX];
275 struct ScopeTimer
277 ScopeTimer( constant aConstant, Image *pImage ) :
278 maConstant(aConstant),mpImage(pImage)
281 ~ScopeTimer()
283 mpImage->maElapsedTime[maConstant] += maTimer.getElapsedTime();
286 constant maConstant;
287 Image* mpImage;
288 ::canvas::tools::ElapsedTime maTimer;
291 #endif
294 typedef ::boost::shared_ptr< Image > ImageSharedPtr;
298 #endif /* INCLUDED_CANVAS_IMAGE_HXX */