1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * art_rgba_svp.c: A slightly modified version of art_rgb_svp to render into rgba buffer
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public License
7 * as published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * Raph Levien <raph@acm.org>
21 * Lauris Kaplinski <lauris@ariman.ee>
23 * Copyright (C) 1998 Raph Levien
27 #define SP_ART_RGBA_SVP_C
29 /* Render a sorted vector path into an RGBA buffer. */
31 #include <libart_lgpl/art_misc.h>
32 #include <libart_lgpl/art_svp.h>
33 #include <libart_lgpl/art_svp_render_aa.h>
34 #include <libart_lgpl/art_rgb.h>
36 #include "art_rgba_svp.h"
39 static void art_rgba_fill_run(
45 static void art_rgba_run_alpha(
53 typedef struct _ArtRgbaSVPAlphaData ArtRgbaSVPAlphaData;
55 struct _ArtRgbaSVPAlphaData {
57 art_u8 r, g, b, alpha;
60 int libart_x0, libart_x1;
63 static void art_rgba_svp_alpha_callback(
67 ArtSVPRenderAAStep * steps,
70 ArtRgbaSVPAlphaData *data = callback_data;
73 art_u32 running_sum = start;
74 int libart_x0, libart_x1;
81 libart_x0 = data->libart_x0;
82 libart_x1 = data->libart_x1;
87 alphatab = data->alphatab;
91 if (run_x1 > libart_x0) {
92 alpha = (running_sum >> 16) & 0xff;
94 art_rgba_run_alpha(linebuf,
95 r, g, b, alphatab[alpha],
99 /* render the steps into tmpbuf */
100 for (k = 0; k < n_steps - 1; k++) {
101 running_sum += steps[k].delta;
103 run_x1 = steps[k + 1].x;
104 if (run_x1 > run_x0) {
105 alpha = (running_sum >> 16) & 0xff;
107 art_rgba_run_alpha(linebuf + (run_x0 - libart_x0) * 4,
108 r, g, b, alphatab[alpha],
112 running_sum += steps[k].delta;
113 if (libart_x1 > run_x1) {
114 alpha = (running_sum >> 16) & 0xff;
116 art_rgba_run_alpha(linebuf + (run_x1 - libart_x0) * 4,
117 r, g, b, alphatab[alpha],
121 alpha = (running_sum >> 16) & 0xff;
123 art_rgba_run_alpha(linebuf,
124 r, g, b, alphatab[alpha],
125 libart_x1 - libart_x0);
128 data->buf += data->rowstride;
131 static void art_rgba_svp_alpha_opaque_callback(
135 ArtSVPRenderAAStep * steps,
138 ArtRgbaSVPAlphaData *data = callback_data;
141 art_u32 running_sum = start;
142 int libart_x0, libart_x1;
149 libart_x0 = data->libart_x0;
150 libart_x1 = data->libart_x1;
155 alphatab = data->alphatab;
159 if (run_x1 > libart_x0) {
160 alpha = running_sum >> 16;
163 art_rgba_fill_run(linebuf, r, g, b, run_x1 - libart_x0);
165 art_rgba_run_alpha(linebuf,
166 r, g, b, alphatab[alpha],
171 /* render the steps into tmpbuf */
172 for (k = 0; k < n_steps - 1; k++) {
173 running_sum += steps[k].delta;
175 run_x1 = steps[k + 1].x;
176 if (run_x1 > run_x0) {
177 alpha = running_sum >> 16;
180 art_rgba_fill_run(linebuf + (run_x0 - libart_x0) * 4,
181 r, g, b, run_x1 - run_x0);
183 art_rgba_run_alpha(linebuf + (run_x0 - libart_x0) * 4,
184 r, g, b, alphatab[alpha],
189 running_sum += steps[k].delta;
190 if (libart_x1 > run_x1) {
191 alpha = running_sum >> 16;
194 art_rgba_fill_run(linebuf + (run_x1 - libart_x0) * 4,
195 r, g, b, libart_x1 - run_x1);
197 art_rgba_run_alpha(linebuf + (run_x1 - libart_x0) * 4,
198 r, g, b, alphatab[alpha],
203 alpha = running_sum >> 16;
206 art_rgba_fill_run(linebuf, r, g, b, libart_x1 - libart_x0);
208 art_rgba_run_alpha(linebuf,
209 r, g, b, alphatab[alpha],
210 libart_x1 - libart_x0);
214 data->buf += data->rowstride;
218 * gnome_print_art_rgba_svp_alpha: Alpha-composite sorted vector path over RGBA buffer.
219 * @svp: The source sorted vector path.
220 * @libart_x0: Left coordinate of destination rectangle.
221 * @libart_y0: Top coordinate of destination rectangle.
222 * @libart_x1: Right coordinate of destination rectangle.
223 * @libart_y1: Bottom coordinate of destination rectangle.
224 * @rgba: Color in 0xRRGGBBAA format.
225 * @buf: Destination RGB buffer.
226 * @rowstride: Rowstride of @buf buffer.
227 * @alphagamma: #ArtAlphaGamma for gamma-correcting the compositing.
229 * Renders the shape specified with @svp over the @buf RGB buffer.
230 * @libart_x1 - @x0 specifies the width, and @libart_y1 - @libart_y0 specifies the height,
231 * of the rectangle rendered. The new pixels are stored starting at
232 * the first byte of @buf. Thus, the @x0 and @libart_y0 parameters specify
233 * an offset within @svp, and may be tweaked as a way of doing
234 * integer-pixel translations without fiddling with @svp itself.
236 * The @rgba argument specifies the color for the rendering. Pixels of
237 * entirely 0 winding number are left untouched. Pixels of entirely
238 * 1 winding number have the color @rgba composited over them (ie,
239 * are replaced by the red, green, blue components of @rgba if the alpha
240 * component is 0xff). Pixels of intermediate coverage are interpolated
241 * according to the rule in @alphagamma, or default to linear if
242 * @alphagamma is NULL.
244 void gnome_print_art_rgba_svp_alpha(
253 ArtAlphaGamma UNUSED(*alphagamma))
255 ArtRgbaSVPAlphaData data;
261 g = (rgba >> 16) & 0xff;
262 b = (rgba >> 8) & 0xff;
271 da = (alpha * 66051 + 0x80) >> 8; /* 66051 equals 2 ^ 32 / (255 * 255) */
273 for (i = 0; i < 256; i++) {
274 data.alphatab[i] = a >> 16;
279 data.rowstride = rowstride;
280 data.libart_x0 = libart_x0;
281 data.libart_x1 = libart_x1;
283 art_svp_render_aa(svp, libart_x0, libart_y0, libart_x1, libart_y1,
284 art_rgba_svp_alpha_opaque_callback, &data);
286 art_svp_render_aa(svp, libart_x0, libart_y0, libart_x1, libart_y1,
287 art_rgba_svp_alpha_callback, &data);
290 static void art_rgba_fill_run(
299 for (i = 0; i < n; i++) {
309 static void art_rgba_run_alpha(
321 for (i = 0; i < n; i++) {
327 cr = (br * ba + 0x80) >> 8;
328 cg = (bg * ba + 0x80) >> 8;
329 cb = (bb * ba + 0x80) >> 8;
331 *buf++ = cr + (((r - cr) * alpha + 0x80) >> 8);
332 *buf++ = cg + (((g - cg) * alpha + 0x80) >> 8);
333 *buf++ = cb + (((b - cb) * alpha + 0x80) >> 8);
334 *buf++ = ba + (((255 - ba) * alpha + 0x80) >> 8);