1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: image.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_CANVAS_IMAGE_HXX
32 #define INCLUDED_CANVAS_IMAGE_HXX
34 #include <com/sun/star/uno/Reference.hxx>
35 #include <com/sun/star/rendering/XCanvas.hpp>
36 #include <canvas/rendering/icolorbuffer.hxx>
37 #include <canvas/parametricpolypolygon.hxx>
38 #include "imagecachedprimitive.hxx"
40 #include <canvas/elapsedtime.hxx>
42 #include "image_sysprereq.h"
44 struct BitmapSystemData
;
49 class Image
: public IColorBuffer
52 /// The description of the image
55 IColorBuffer::Format eFormat
;
62 /** Create a new image with the attributes passed as argument.
64 explicit Image( const Description
& desc
);
66 /** Create a new image from the XBitmap passed as argument
68 explicit Image( const ::com::sun::star::uno::Reference
<
69 ::com::sun::star::rendering::XBitmap
>& xBitmap
);
74 /** Retrieve desciption of image layout
76 const Description
& getDescription() const { return maDesc
; }
78 /** Clear image with uniform color
80 void clear( sal_uInt8 a
,
85 void fillB2DPolyPolygon(
86 const ::basegfx::B2DPolyPolygon
& rPolyPolygon
,
87 const ::com::sun::star::rendering::ViewState
& viewState
,
88 const ::com::sun::star::rendering::RenderState
& renderState
);
91 // IColorBuffer interface implementation
92 // =====================================
94 virtual sal_uInt8
* lock() const;
95 virtual void unlock() const;
96 virtual sal_uInt32
getWidth() const;
97 virtual sal_uInt32
getHeight() const;
98 virtual sal_uInt32
getStride() const;
99 virtual Format
getFormat() const;
102 // High-level drawing operations (from the XCanvas interface)
103 // ==========================================================
105 void drawPoint( const ::com::sun::star::geometry::RealPoint2D
& aPoint
,
106 const ::com::sun::star::rendering::ViewState
& viewState
,
107 const ::com::sun::star::rendering::RenderState
& renderState
);
108 void drawLine( const ::com::sun::star::geometry::RealPoint2D
& aStartPoint
,
109 const ::com::sun::star::geometry::RealPoint2D
& aEndPoint
,
110 const ::com::sun::star::rendering::ViewState
& viewState
,
111 const ::com::sun::star::rendering::RenderState
& renderState
);
112 void drawBezier( const ::com::sun::star::geometry::RealBezierSegment2D
& aBezierSegment
,
113 const ::com::sun::star::geometry::RealPoint2D
& aEndPoint
,
114 const ::com::sun::star::rendering::ViewState
& viewState
,
115 const ::com::sun::star::rendering::RenderState
& renderState
);
116 ImageCachedPrimitiveSharedPtr
drawPolyPolygon(
117 const ::com::sun::star::uno::Reference
<
118 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
119 const ::com::sun::star::rendering::ViewState
& viewState
,
120 const ::com::sun::star::rendering::RenderState
& renderState
);
122 ImageCachedPrimitiveSharedPtr
strokePolyPolygon(
123 const ::com::sun::star::uno::Reference
<
124 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
125 const ::com::sun::star::rendering::ViewState
& viewState
,
126 const ::com::sun::star::rendering::RenderState
& renderState
,
127 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
128 ImageCachedPrimitiveSharedPtr
strokeTexturedPolyPolygon(
129 const ::com::sun::star::uno::Reference
<
130 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
131 const ::com::sun::star::rendering::ViewState
& viewState
,
132 const ::com::sun::star::rendering::RenderState
& renderState
,
133 const ::com::sun::star::uno::Sequence
<
134 ::com::sun::star::rendering::Texture
>& textures
,
135 const ::std::vector
< ::boost::shared_ptr
<Image
> >& textureAnnotations
,
136 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
137 ImageCachedPrimitiveSharedPtr
strokeTextureMappedPolyPolygon(
138 const ::com::sun::star::uno::Reference
<
139 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
140 const ::com::sun::star::rendering::ViewState
& viewState
,
141 const ::com::sun::star::rendering::RenderState
& renderState
,
142 const ::com::sun::star::uno::Sequence
<
143 ::com::sun::star::rendering::Texture
>& textures
,
144 const ::std::vector
< ::boost::shared_ptr
<Image
> >& textureAnnotations
,
145 const ::com::sun::star::uno::Reference
<
146 ::com::sun::star::geometry::XMapping2D
>& xMapping
,
147 const ::com::sun::star::rendering::StrokeAttributes
& strokeAttributes
);
148 ImageCachedPrimitiveSharedPtr
fillPolyPolygon(
149 const ::com::sun::star::uno::Reference
<
150 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
151 const ::com::sun::star::rendering::ViewState
& viewState
,
152 const ::com::sun::star::rendering::RenderState
& renderState
);
153 ImageCachedPrimitiveSharedPtr
fillTexturedPolyPolygon(
154 const ::com::sun::star::uno::Reference
<
155 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
156 const ::com::sun::star::rendering::ViewState
& viewState
,
157 const ::com::sun::star::rendering::RenderState
& renderState
,
158 const ::com::sun::star::uno::Sequence
<
159 ::com::sun::star::rendering::Texture
>& textures
,
160 const ::std::vector
< ::boost::shared_ptr
<Image
> >& textureAnnotations
);
161 ImageCachedPrimitiveSharedPtr
fillTextureMappedPolyPolygon(
162 const ::com::sun::star::uno::Reference
<
163 ::com::sun::star::rendering::XPolyPolygon2D
>& xPolyPolygon
,
164 const ::com::sun::star::rendering::ViewState
& viewState
,
165 const ::com::sun::star::rendering::RenderState
& renderState
,
166 const ::com::sun::star::uno::Sequence
<
167 ::com::sun::star::rendering::Texture
>& textures
,
168 const ::std::vector
< ::boost::shared_ptr
<Image
> >& textureAnnotations
,
169 const ::com::sun::star::uno::Reference
<
170 ::com::sun::star::geometry::XMapping2D
>& xMapping
);
172 ImageCachedPrimitiveSharedPtr
drawBitmap(
173 const ::com::sun::star::uno::Reference
<
174 ::com::sun::star::rendering::XBitmap
>& xBitmap
,
175 const ::com::sun::star::rendering::ViewState
& viewState
,
176 const ::com::sun::star::rendering::RenderState
& renderState
);
177 ImageCachedPrimitiveSharedPtr
drawBitmap(
178 const ::boost::shared_ptr
<Image
>& rImage
,
179 const ::com::sun::star::rendering::ViewState
& viewState
,
180 const ::com::sun::star::rendering::RenderState
& renderState
);
182 ImageCachedPrimitiveSharedPtr
drawBitmapModulated(
183 const ::com::sun::star::uno::Reference
<
184 ::com::sun::star::rendering::XBitmap
>& xBitmap
,
185 const ::com::sun::star::rendering::ViewState
& viewState
,
186 const ::com::sun::star::rendering::RenderState
& renderState
);
187 ImageCachedPrimitiveSharedPtr
drawBitmapModulated(
188 const ::boost::shared_ptr
<Image
>& rImage
,
189 const ::com::sun::star::rendering::ViewState
& viewState
,
190 const ::com::sun::star::rendering::RenderState
& renderState
);
193 void drawLinePolyPolygon( const ::basegfx::B2DPolyPolygon
& rPoly
,
195 const ::com::sun::star::rendering::ViewState
& viewState
,
196 const ::com::sun::star::rendering::RenderState
& renderState
);
198 ImageCachedPrimitiveSharedPtr
implDrawBitmap(
199 const Image
& rBitmap
,
200 const ::com::sun::star::rendering::ViewState
& viewState
,
201 const ::com::sun::star::rendering::RenderState
& renderState
);
203 ImageCachedPrimitiveSharedPtr
fillTexturedPolyPolygon(
204 const Image
& rTexture
,
205 const ::basegfx::B2DPolyPolygon
& rPolyPolygon
,
206 const ::basegfx::B2DHomMatrix
& rOverallTransform
,
207 const ::basegfx::B2DHomMatrix
& rViewTransform
,
208 const ::com::sun::star::rendering::Texture
& texture
);
210 void fillGradient( const ParametricPolyPolygon::Values
& rValues
,
211 const ::com::sun::star::uno::Sequence
< double >& rColor1
,
212 const ::com::sun::star::uno::Sequence
< double >& rColor2
,
213 const ::basegfx::B2DPolyPolygon
& rPolyPolygon
,
214 const ::basegfx::B2DHomMatrix
& rOverallTransform
,
215 const ::com::sun::star::rendering::Texture
& texture
);
216 bool fromVCLBitmap( ::BitmapEx
& rBmpEx
);
218 template<class pixel_format
>
219 void drawLinePolyPolygonImpl( const ::basegfx::B2DPolyPolygon
& rPoly
,
221 const ::com::sun::star::rendering::ViewState
& viewState
,
222 const ::com::sun::star::rendering::RenderState
& renderState
);
224 template<class pixel_format
,class span_gen_type
>
225 ImageCachedPrimitiveSharedPtr
fillTexturedPolyPolygonImpl(
226 const Image
& rTexture
,
227 const ::basegfx::B2DPolyPolygon
& rPolyPolygon
,
228 const ::basegfx::B2DHomMatrix
& rOverallTransform
,
229 const ::basegfx::B2DHomMatrix
& rViewTransform
,
230 const ::com::sun::star::rendering::Texture
& texture
);
232 template<class pixel_format
>
233 void fillGradientImpl( const ParametricPolyPolygon::Values
& rValues
,
234 const ::com::sun::star::uno::Sequence
< double >& rUnoColor1
,
235 const ::com::sun::star::uno::Sequence
< double >& rUnoColor2
,
236 const ::basegfx::B2DPolyPolygon
& rPolyPolygon
,
237 const ::basegfx::B2DHomMatrix
& rOverallTransform
,
238 const ::com::sun::star::rendering::Texture
& texture
);
240 template<class pixel_format
>
241 ImageCachedPrimitiveSharedPtr
fillPolyPolygonImpl(
242 const ::basegfx::B2DPolyPolygon
& rPolyPolygon
,
243 const ::com::sun::star::rendering::ViewState
& viewState
,
244 const ::com::sun::star::rendering::RenderState
& renderState
);
246 template<class pixel_format
> void clearImpl( sal_uInt8 a
,
251 /** Image description
255 /** the graphics buffer is a simple array
256 where each element points to the start
257 of a scanline in consecutive order.
259 agg::rendering_buffer maRenderingBuffer
;
261 /// Whether maRenderingBuffer is owned by the client of this object
262 bool mbBufferHasUserOwnership
;
264 #if defined(PROFILER)
268 TIMER_FILLTEXTUREDPOLYPOLYGON
,
269 TIMER_FILLB2DPOLYPOLYGON
,
270 TIMER_DRAWPOLYPOLYGON
,
271 TIMER_FILLPOLYPOLYGON
,
276 double maElapsedTime
[TIMER_MAX
];
280 ScopeTimer( constant aConstant
, Image
*pImage
) :
281 maConstant(aConstant
),mpImage(pImage
)
286 mpImage
->maElapsedTime
[maConstant
] += maTimer
.getElapsedTime();
291 ::canvas::tools::ElapsedTime maTimer
;
297 typedef ::boost::shared_ptr
< Image
> ImageSharedPtr
;
301 #endif /* INCLUDED_CANVAS_IMAGE_HXX */