source: trunk/third/mozilla/other-licenses/libart_lgpl/art_gray_svp.c @ 22325

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