1 | /* |
---|
2 | * art_render.h: Modular rendering architecture. |
---|
3 | * |
---|
4 | * Libart_LGPL - library of basic graphic primitives |
---|
5 | * Copyright (C) 2000 Raph Levien |
---|
6 | * |
---|
7 | * This library is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU Library General Public |
---|
9 | * License as published by the Free Software Foundation; either |
---|
10 | * version 2 of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This library is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
15 | * Library General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU Library General Public |
---|
18 | * License along with this library; if not, write to the |
---|
19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
20 | * Boston, MA 02111-1307, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef __ART_RENDER_H__ |
---|
24 | #define __ART_RENDER_H__ |
---|
25 | |
---|
26 | #ifdef LIBART_COMPILATION |
---|
27 | #include "art_alphagamma.h" |
---|
28 | #else |
---|
29 | #include <libart_lgpl/art_alphagamma.h> |
---|
30 | #endif |
---|
31 | |
---|
32 | #ifdef __cplusplus |
---|
33 | extern "C" { |
---|
34 | #endif /* __cplusplus */ |
---|
35 | |
---|
36 | /* Render object */ |
---|
37 | |
---|
38 | #ifndef ART_MAX_DEPTH |
---|
39 | #define ART_MAX_DEPTH 16 |
---|
40 | #endif |
---|
41 | |
---|
42 | #if ART_MAX_DEPTH == 16 |
---|
43 | typedef art_u16 ArtPixMaxDepth; |
---|
44 | #define ART_PIX_MAX_FROM_8(x) ((x) | ((x) << 8)) |
---|
45 | #define ART_PIX_8_FROM_MAX(x) (((x) + 0x80 - (((x) + 0x80) >> 8)) >> 8) |
---|
46 | #else |
---|
47 | #if ART_MAX_DEPTH == 8 |
---|
48 | typedef art_u8 ArtPixMaxDepth; |
---|
49 | #define ART_PIX_MAX_FROM_8(x) (x) |
---|
50 | #define ART_PIX_8_FROM_MAX(x) (x) |
---|
51 | #else |
---|
52 | #error ART_MAX_DEPTH must be either 8 or 16 |
---|
53 | #endif |
---|
54 | #endif |
---|
55 | |
---|
56 | #define ART_MAX_CHAN 16 |
---|
57 | |
---|
58 | typedef struct _ArtRender ArtRender; |
---|
59 | typedef struct _ArtRenderCallback ArtRenderCallback; |
---|
60 | typedef struct _ArtRenderMaskRun ArtRenderMaskRun; |
---|
61 | typedef struct _ArtImageSource ArtImageSource; |
---|
62 | typedef struct _ArtMaskSource ArtMaskSource; |
---|
63 | |
---|
64 | typedef enum { |
---|
65 | ART_ALPHA_NONE = 0, |
---|
66 | ART_ALPHA_SEPARATE = 1, |
---|
67 | ART_ALPHA_PREMUL = 2 |
---|
68 | } ArtAlphaType; |
---|
69 | |
---|
70 | typedef enum { |
---|
71 | ART_COMPOSITE_NORMAL, |
---|
72 | ART_COMPOSITE_MULTIPLY, |
---|
73 | /* todo: more */ |
---|
74 | ART_COMPOSITE_CUSTOM |
---|
75 | } ArtCompositingMode; |
---|
76 | |
---|
77 | typedef enum { |
---|
78 | ART_IMAGE_SOURCE_CAN_CLEAR = 1, |
---|
79 | ART_IMAGE_SOURCE_CAN_COMPOSITE = 2 |
---|
80 | } ArtImageSourceFlags; |
---|
81 | |
---|
82 | struct _ArtRenderMaskRun { |
---|
83 | int x; |
---|
84 | int alpha; |
---|
85 | }; |
---|
86 | |
---|
87 | struct _ArtRenderCallback { |
---|
88 | void (*render) (ArtRenderCallback *self, ArtRender *render, |
---|
89 | art_u8 *dest, int y); |
---|
90 | void (*done) (ArtRenderCallback *self, ArtRender *render); |
---|
91 | }; |
---|
92 | |
---|
93 | struct _ArtImageSource { |
---|
94 | ArtRenderCallback super; |
---|
95 | void (*negotiate) (ArtImageSource *self, ArtRender *render, |
---|
96 | ArtImageSourceFlags *p_flags, |
---|
97 | int *p_buf_depth, ArtAlphaType *p_alpha_type); |
---|
98 | }; |
---|
99 | |
---|
100 | struct _ArtMaskSource { |
---|
101 | ArtRenderCallback super; |
---|
102 | int (*can_drive) (ArtMaskSource *self, ArtRender *render); |
---|
103 | /* For each mask source, ::prepare() is invoked if it is not |
---|
104 | a driver, or ::invoke_driver() if it is. */ |
---|
105 | void (*invoke_driver) (ArtMaskSource *self, ArtRender *render); |
---|
106 | void (*prepare) (ArtMaskSource *self, ArtRender *render, art_boolean first); |
---|
107 | }; |
---|
108 | |
---|
109 | struct _ArtRender { |
---|
110 | /* parameters of destination image */ |
---|
111 | int x0, y0; |
---|
112 | int x1, y1; |
---|
113 | art_u8 *pixels; |
---|
114 | int rowstride; |
---|
115 | int n_chan; |
---|
116 | int depth; |
---|
117 | ArtAlphaType alpha_type; |
---|
118 | |
---|
119 | art_boolean clear; |
---|
120 | ArtPixMaxDepth clear_color[ART_MAX_CHAN + 1]; |
---|
121 | art_u32 opacity; /* [0..0x10000] */ |
---|
122 | |
---|
123 | ArtCompositingMode compositing_mode; |
---|
124 | |
---|
125 | ArtAlphaGamma *alphagamma; |
---|
126 | |
---|
127 | art_u8 *alpha_buf; |
---|
128 | |
---|
129 | /* parameters of intermediate buffer */ |
---|
130 | int buf_depth; |
---|
131 | ArtAlphaType buf_alpha; |
---|
132 | art_u8 *image_buf; |
---|
133 | |
---|
134 | /* driving alpha scanline data */ |
---|
135 | /* A "run" is a contiguous sequence of x values with the same alpha value. */ |
---|
136 | int n_run; |
---|
137 | ArtRenderMaskRun *run; |
---|
138 | |
---|
139 | /* A "span" is a contiguous sequence of x values with non-zero alpha. */ |
---|
140 | int n_span; |
---|
141 | int *span_x; |
---|
142 | |
---|
143 | art_boolean need_span; |
---|
144 | }; |
---|
145 | |
---|
146 | ArtRender * |
---|
147 | art_render_new (int x0, int y0, int x1, int y1, |
---|
148 | art_u8 *pixels, int rowstride, |
---|
149 | int n_chan, int depth, ArtAlphaType alpha_type, |
---|
150 | ArtAlphaGamma *alphagamma); |
---|
151 | |
---|
152 | void |
---|
153 | art_render_invoke (ArtRender *render); |
---|
154 | |
---|
155 | void |
---|
156 | art_render_clear (ArtRender *render, const ArtPixMaxDepth *clear_color); |
---|
157 | |
---|
158 | void |
---|
159 | art_render_clear_rgb (ArtRender *render, art_u32 clear_rgb); |
---|
160 | |
---|
161 | void |
---|
162 | art_render_mask_solid (ArtRender *render, int opacity); |
---|
163 | |
---|
164 | void |
---|
165 | art_render_image_solid (ArtRender *render, ArtPixMaxDepth *color); |
---|
166 | |
---|
167 | /* The next two functions are for custom mask sources only. */ |
---|
168 | void |
---|
169 | art_render_add_mask_source (ArtRender *render, ArtMaskSource *mask_source); |
---|
170 | |
---|
171 | void |
---|
172 | art_render_invoke_callbacks (ArtRender *render, art_u8 *dest, int y); |
---|
173 | |
---|
174 | /* The following function is for custom image sources only. */ |
---|
175 | void |
---|
176 | art_render_add_image_source (ArtRender *render, ArtImageSource *image_source); |
---|
177 | |
---|
178 | #ifdef __cplusplus |
---|
179 | } |
---|
180 | #endif /* __cplusplus */ |
---|
181 | |
---|
182 | #endif /* __ART_RENDER_H__ */ |
---|
183 | |
---|