2 * GPAC - Multimedia Framework C SDK
\r
4 * Copyright (c) Jean Le Feuvre 2000-2005
\r
5 * All rights reserved
\r
7 * This file is part of GPAC / modules interfaces
\r
9 * GPAC is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation; either version 2, or (at your option)
\r
12 * any later version.
\r
14 * GPAC is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public
\r
20 * License along with this library; see the file COPYING. If not, write to
\r
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
\r
26 #ifndef _GF_MODULE_RASTER2D_H_
\r
27 #define _GF_MODULE_RASTER2D_H_
\r
33 #include <gpac/path2d.h>
\r
34 #include <gpac/module.h>
\r
35 #include <gpac/color.h>
\r
41 /*solid color stencil*/
\r
42 GF_STENCIL_SOLID = 0,
\r
43 /*linear color gradient stencil*/
\r
44 GF_STENCIL_LINEAR_GRADIENT,
\r
45 /*radial color gradient stencil*/
\r
46 GF_STENCIL_RADIAL_GRADIENT,
\r
48 GF_STENCIL_VERTEX_GRADIENT,
\r
54 /*gradient filling modes*/
\r
57 /*edge colors are repeated until path is filled*/
\r
58 GF_GRADIENT_MODE_PAD,
\r
59 /*pattern is inversed each time it's repeated*/
\r
60 GF_GRADIENT_MODE_SPREAD,
\r
61 /*pattern is repeated to fill path*/
\r
62 GF_GRADIENT_MODE_REPEAT
\r
66 /*texture tiling flags*/
\r
69 /*texture is repeated in its horizontal direction*/
\r
70 GF_TEXTURE_REPEAT_S = (1<<1),
\r
71 /*texture is repeated in its horizontal direction*/
\r
72 GF_TEXTURE_REPEAT_T = (1<<2),
\r
73 /*texture is fliped vertically*/
\r
74 GF_TEXTURE_FLIP = (1<<3),
\r
77 /*filter levels for texturing - up to the graphics engine but the following levels are used by
\r
81 /*high speed mapping (ex, no filtering applied)*/
\r
82 GF_TEXTURE_FILTER_HIGH_SPEED,
\r
83 /*compromise between speed and quality (ex, filter to nearest pixel)*/
\r
84 GF_TEXTURE_FILTER_MID,
\r
85 /*high quality mapping (ex, bi-linear/bi-cubic interpolation)*/
\r
86 GF_TEXTURE_FILTER_HIGH_QUALITY
\r
89 /* rasterizer antialiasing depending on the graphics engine*/
\r
92 /*raster should use fastest mode possible (eg, no antialiasing)*/
\r
93 GF_RASTER_HIGH_SPEED,
\r
94 /*raster should use fast mode and good quality if possible*/
\r
96 /*raster should use antialiasing*/
\r
97 GF_RASTER_HIGH_QUALITY
\r
101 /*user routines for raserizer. common syntaxes:
\r
102 @cbk: user defined callback
\r
103 @x, y: first pixel position of the run, in device memory (top-left) coordinates
\r
104 @run_h_len: number of pixels to fill on line
\r
105 @color: color to fill pixel with. USER MUST IGNORE THE ALPHA COMPONENT OF THIS COLOR, the final
\r
106 alpha is computed by the lib
\r
107 @alpha: blending amount (0->0xFF) for the pixels
\r
112 /*fills line pixels without any blending operation*/
\r
113 void (*fill_run_no_alpha)(void *cbk, u32 x, u32 y, u32 run_h_len, GF_Color color);
\r
114 /*fills line pixels without blending operation - alpha combines both fill color and anti-aliasing blending*/
\r
115 void (*fill_run_alpha)(void *cbk, u32 x, u32 y, u32 run_h_len, GF_Color color, u32 alpha);
\r
116 } GF_RasterCallback;
\r
120 /*opaque handler for all stencils*/
\r
121 typedef void *GF_STENCIL;
\r
123 /*visual surface handler*/
\r
124 typedef void *GF_SURFACE;
\r
126 /*interface name and version for raster2D*/
\r
127 #define GF_RASTER_2D_INTERFACE GF_4CC('G','R','2', 0x02)
\r
129 /*graphics driver*/
\r
130 typedef struct _raster2d_interface
\r
132 /* interface declaration*/
\r
133 GF_DECL_MODULE_INTERFACE
\r
135 GF_STENCIL (*stencil_new) (struct _raster2d_interface *, GF_StencilType type);
\r
136 /*common destructor for all stencils*/
\r
137 void (*stencil_delete) (GF_STENCIL _this);
\r
138 /*set stencil transformation matrix*/
\r
139 GF_Err (*stencil_set_matrix) (GF_STENCIL _this, GF_Matrix2D *mat);
\r
140 /*solid brush - set brush color*/
\r
141 GF_Err (*stencil_set_brush_color) (GF_STENCIL _this, GF_Color c);
\r
142 /*gradient brushes*/
\r
143 /*sets gradient repeat mode - return GF_NOT_SUPPORTED if driver doesn't support this to let the app compute repeat patterns
\r
144 this may be called before the gradient is setup*/
\r
145 GF_Err (*stencil_set_gradient_mode) (GF_STENCIL _this, GF_GradientMode mode);
\r
146 /*set linear gradient. line is defined by start and end, and you can give interpolation colors at specified positions*/
\r
147 GF_Err (*stencil_set_linear_gradient) (GF_STENCIL _this, Fixed start_x, Fixed start_y, Fixed end_x, Fixed end_y);
\r
148 /*radial gradient brush center point, focal point and radius - colors can only be set through set_interpolation */
\r
149 GF_Err (*stencil_set_radial_gradient) (GF_STENCIL _this, Fixed cx, Fixed cy, Fixed fx, Fixed fy, Fixed x_radius, Fixed y_radius);
\r
150 /*radial and linear gradient (not used with vertex) - set color interpolation at given points,
\r
151 @pos[i]: distance from (center for radial, start for linear) expressed between 0 and 1 (1 being the gradient bounds)
\r
152 @col[i]: associated color
\r
153 NOTE 1: the colors at 0 and 1.0 MUST be provided
\r
154 NOTE 2: colors shall be fed in order from 0 to 1
\r
155 NOTE 3: this overrides the colors provided for linear gradient
\r
157 GF_Err (*stencil_set_gradient_interpolation) (GF_STENCIL _this, Fixed *pos, GF_Color *col, u32 count);
\r
159 /*vertex gradient : set limit path */
\r
160 GF_Err (*stencil_set_vertex_path) (GF_STENCIL _this, GF_Path *path);
\r
161 /*set the center of the gradient*/
\r
162 GF_Err (*stencil_set_vertex_center) (GF_STENCIL _this, Fixed cx, Fixed cy, u32 color);
\r
163 /*set the center of the gradient*/
\r
164 GF_Err (*stencil_set_vertex_colors) (GF_STENCIL _this, u32 *colors, u32 nbCol);
\r
166 /*sets global alpha blending level for stencil (texture and gradients)
\r
167 the alpha channel shall be combined with the color matrix if any*/
\r
168 GF_Err (*stencil_set_alpha) (GF_STENCIL _this, u8 alpha);
\r
170 /*set stencil texture
\r
171 @pixels: texture data, from top to bottom
\r
172 @width, @height: texture size
\r
173 @stride: texture horizontal pitch (bytes to skip to get to next row)
\r
174 @pixelFormat: texture pixel format as defined in file constants.h
\r
175 @destination_format_hint: this is the current pixel format of the destination surface, and is given
\r
176 as a hint in case the texture needs to be converted by the stencil
\r
177 @no_copy: if set, specifies the texture data shall not be cached by the module (eg it must be able
\r
178 to directly modify the given memory
\r
179 NOTE: this stencil acts as a data wrapper, the pixel data is not required to be locally copied
\r
180 data is not required to be available for texturing until the stencil is used in a draw operation
\r
182 GF_Err (*stencil_set_texture) (GF_STENCIL _this, char *pixels, u32 width, u32 height, u32 stride, GF_PixelFormat pixelFormat, GF_PixelFormat destination_format_hint, Bool no_copy);
\r
183 /*creates internal texture - pixel data is owned by texture brush - set to NULL if not supported - this is used to
\r
184 cope with engines that don't support random strides (ex: Gdiplus needs stride to be a multiple of 4)
\r
185 if not set the compositor will create its own mem texture and pass it through set_texture - pixel format shall
\r
186 be respected as far as Alpha is concerned (eg alpha info shall be kept and used in blit) */
\r
187 GF_Err (*stencil_create_texture) (GF_STENCIL _this, u32 width, u32 height, GF_PixelFormat pixelFormat);
\r
188 /*signals the texture has been modified (internal texture only)*/
\r
189 void (*stencil_texture_modified) (GF_STENCIL _this);
\r
191 /*sets texture tile mode*/
\r
192 GF_Err (*stencil_set_tiling) (GF_STENCIL _this, GF_TextureTiling mode);
\r
193 /*sets texture filtering mode*/
\r
194 GF_Err (*stencil_set_filter) (GF_STENCIL _this, GF_TextureFilter filter_mode);
\r
195 /*set stencil color matrix - texture stencils only. If matrix is NULL, resets current color matrix*/
\r
196 GF_Err (*stencil_set_color_matrix) (GF_STENCIL _this, GF_ColorMatrix *cmat);
\r
198 /*creates surface object*/
\r
199 /* @center_coords: true indicates mathematical-like coord system,
\r
200 false indicates computer-like coord system */
\r
201 GF_SURFACE (*surface_new) (struct _raster2d_interface *, Bool center_coords);
\r
202 /* delete surface object */
\r
203 void (*surface_delete) (GF_SURFACE _this);
\r
205 /* attach surface object to device object (Win32: HDC) width and height are target surface size*/
\r
206 GF_Err (*surface_attach_to_device) (GF_SURFACE _this, void *os_handle, u32 width, u32 height);
\r
207 /* attach surface object to stencil object*/
\r
208 GF_Err (*surface_attach_to_texture) (GF_SURFACE _this, GF_STENCIL sten);
\r
209 /* attach surface object to memory buffer if supported
\r
210 @pixels: texture data
\r
211 @width, @height: texture size
\r
212 @stride: texture horizontal pitch (bytes to skip to get to next row)
\r
213 @pixelFormat: texture pixel format
\r
215 GF_Err (*surface_attach_to_buffer) (GF_SURFACE _this, char *pixels, u32 width, u32 height, u32 stride, GF_PixelFormat pixelFormat);
\r
217 GF_Err (*surface_attach_to_callbacks) (GF_SURFACE _this, GF_RasterCallback *callbacks, u32 width, u32 height);
\r
219 /* detach surface object */
\r
220 void (*surface_detach) (GF_SURFACE _this);
\r
222 /*sets rasterizer precision */
\r
223 GF_Err (*surface_set_raster_level) (GF_SURFACE _this, GF_RasterLevel RasterSetting);
\r
224 /* set the given matrix as the current transformations for all drawn paths
\r
225 if NULL reset the current transformation */
\r
226 GF_Err (*surface_set_matrix) (GF_SURFACE _this, GF_Matrix2D *mat);
\r
227 /* set the given rectangle as a clipper - nothing will be drawn outside this clipper
\r
228 if the clipper is NULL then no clipper is set
\r
229 NB: the clipper is not affected by the surface matrix and is given in pixels
\r
230 CF ABOVE NOTE ON CLIPPERS*/
\r
231 GF_Err (*surface_set_clipper) (GF_SURFACE _this, GF_IRect *rc);
\r
233 /*sets the given path as the current one for drawing - the surface transform is NEVER changed between
\r
234 setting the path and filling, only the clipper may change*/
\r
235 GF_Err (*surface_set_path) (GF_SURFACE _this, GF_Path *path);
\r
236 /*fills the current path using the given stencil - can be called several times with the same current path*/
\r
237 GF_Err (*surface_fill) (GF_SURFACE _this, GF_STENCIL stencil);
\r
239 /*flushes to surface*/
\r
240 GF_Err (*surface_flush) (GF_SURFACE _this);
\r
242 /*clears given pixel rect on the surface with the given color - REQUIRED
\r
243 the given rect is formatted as a clipper - CF ABOVE NOTE ON CLIPPERS*/
\r
244 GF_Err (*surface_clear)(GF_SURFACE _this, GF_IRect *rc, GF_Color col);
\r
257 #endif /*_GF_MODULE_RASTER2D_H_*/
\r