1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/* Libart_LGPL - library of basic graphic primitives
* Copyright (C) 1998 Raph Levien
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* Render a sorted vector path into a graymap. */
#include "config.h"
#include "art_gray_svp.h"
#include <string.h> /* for memset */
#include "art_misc.h"
#include "art_svp.h"
#include "art_svp_render_aa.h"
typedef struct _ArtGraySVPData ArtGraySVPData;
struct _ArtGraySVPData {
art_u8 *buf;
int rowstride;
int x0, x1;
};
static void
art_gray_svp_callback (void *callback_data, int y,
int start, ArtSVPRenderAAStep *steps, int n_steps)
{
ArtGraySVPData *data = (ArtGraySVPData *)callback_data;
art_u8 *linebuf;
int run_x0, run_x1;
int running_sum = start;
int x0, x1;
int k;
#if 0
printf ("start = %d", start);
running_sum = start;
for (k = 0; k < n_steps; k++)
{
running_sum += steps[k].delta;
printf (" %d:%d", steps[k].x, running_sum >> 16);
}
printf ("\n");
#endif
linebuf = data->buf;
x0 = data->x0;
x1 = data->x1;
if (n_steps > 0)
{
run_x1 = steps[0].x;
if (run_x1 > x0)
memset (linebuf, running_sum >> 16, run_x1 - x0);
for (k = 0; k < n_steps - 1; k++)
{
running_sum += steps[k].delta;
run_x0 = run_x1;
run_x1 = steps[k + 1].x;
if (run_x1 > run_x0)
memset (linebuf + run_x0 - x0, running_sum >> 16, run_x1 - run_x0);
}
running_sum += steps[k].delta;
if (x1 > run_x1)
memset (linebuf + run_x1 - x0, running_sum >> 16, x1 - run_x1);
}
else
{
memset (linebuf, running_sum >> 16, x1 - x0);
}
data->buf += data->rowstride;
}
/**
* art_gray_svp_aa: Render the vector path into the bytemap.
* @svp: The SVP to render.
* @x0: The view window's left coord.
* @y0: The view window's top coord.
* @x1: The view window's right coord.
* @y1: The view window's bottom coord.
* @buf: The buffer where the bytemap is stored.
* @rowstride: the rowstride for @buf.
*
* Each pixel gets a value proportional to the area within the pixel
* overlapping the (filled) SVP. Pixel (x, y) is stored at:
*
* @buf[(y - * @y0) * @rowstride + (x - @x0)]
*
* All pixels @x0 <= x < @x1, @y0 <= y < @y1 are generated. A
* stored value of zero is no coverage, and a value of 255 is full
* coverage. The area within the pixel (x, y) is the region covered
* by [x..x+1] and [y..y+1].
**/
void
art_gray_svp_aa (const ArtSVP *svp,
int x0, int y0, int x1, int y1,
art_u8 *buf, int rowstride)
{
ArtGraySVPData data;
data.buf = buf;
data.rowstride = rowstride;
data.x0 = x0;
data.x1 = x1;
art_svp_render_aa (svp, x0, y0, x1, y1, art_gray_svp_callback, &data);
}
|