~ubuntu-branches/ubuntu/maverick/gcompris/maverick

« back to all changes in this revision

Viewing changes to src/libart_lgpl/art_gray_svp.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Gariepy, Marc Gariepy, Stephane Graber
  • Date: 2010-01-04 17:42:49 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20100104174249-7bupatd9dtxyhvs4
Tags: 9.0-0ubuntu1
[Marc Gariepy]
* New upstream release (9.0).
* Remove cache.c from POTFILES to avoid FTBFS
* Remove unneeded rm in debian/rules (file no longer exists upstream)

[Stephane Graber]
* Bump Debian standards to 3.8.3
* Add patch system (dpatch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 3 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, see <http://www.gnu.org/licenses/>.
16
 
 * Boston, MA 02111-1307, USA.
17
 
 */
18
 
 
19
 
/* Render a sorted vector path into a graymap. */
20
 
 
21
 
#include "config.h"
22
 
#include "art_gray_svp.h"
23
 
 
24
 
#include <string.h>     /* for memset */
25
 
#include "art_misc.h"
26
 
 
27
 
#include "art_svp.h"
28
 
#include "art_svp_render_aa.h"
29
 
 
30
 
typedef struct _ArtGraySVPData ArtGraySVPData;
31
 
 
32
 
struct _ArtGraySVPData {
33
 
  art_u8 *buf;
34
 
  int rowstride;
35
 
  int x0, x1;
36
 
};
37
 
 
38
 
static void
39
 
art_gray_svp_callback (void *callback_data, int y,
40
 
                       int start, ArtSVPRenderAAStep *steps, int n_steps)
41
 
{
42
 
  ArtGraySVPData *data = (ArtGraySVPData *)callback_data;
43
 
  art_u8 *linebuf;
44
 
  int run_x0, run_x1;
45
 
  int running_sum = start;
46
 
  int x0, x1;
47
 
  int k;
48
 
 
49
 
#if 0
50
 
  printf ("start = %d", start);
51
 
  running_sum = start;
52
 
  for (k = 0; k < n_steps; k++)
53
 
    {
54
 
      running_sum += steps[k].delta;
55
 
      printf (" %d:%d", steps[k].x, running_sum >> 16);
56
 
    }
57
 
  printf ("\n");
58
 
#endif
59
 
 
60
 
  linebuf = data->buf;
61
 
  x0 = data->x0;
62
 
  x1 = data->x1;
63
 
 
64
 
  if (n_steps > 0)
65
 
    {
66
 
      run_x1 = steps[0].x;
67
 
      if (run_x1 > x0)
68
 
        memset (linebuf, running_sum >> 16, run_x1 - x0);
69
 
 
70
 
      for (k = 0; k < n_steps - 1; k++)
71
 
        {
72
 
          running_sum += steps[k].delta;
73
 
          run_x0 = run_x1;
74
 
          run_x1 = steps[k + 1].x;
75
 
          if (run_x1 > run_x0)
76
 
            memset (linebuf + run_x0 - x0, running_sum >> 16, run_x1 - run_x0);
77
 
        }
78
 
      running_sum += steps[k].delta;
79
 
      if (x1 > run_x1)
80
 
        memset (linebuf + run_x1 - x0, running_sum >> 16, x1 - run_x1);
81
 
    }
82
 
  else
83
 
    {
84
 
      memset (linebuf, running_sum >> 16, x1 - x0);
85
 
    }
86
 
 
87
 
  data->buf += data->rowstride;
88
 
}
89
 
 
90
 
/**
91
 
 * art_gray_svp_aa: Render the vector path into the bytemap.
92
 
 * @svp: The SVP to render.
93
 
 * @x0: The view window's left coord.
94
 
 * @y0: The view window's top coord.
95
 
 * @x1: The view window's right coord.
96
 
 * @y1: The view window's bottom coord.
97
 
 * @buf: The buffer where the bytemap is stored.
98
 
 * @rowstride: the rowstride for @buf.
99
 
 *
100
 
 * Each pixel gets a value proportional to the area within the pixel
101
 
 * overlapping the (filled) SVP. Pixel (x, y) is stored at:
102
 
 *
103
 
 *    @buf[(y - * @y0) * @rowstride + (x - @x0)]
104
 
 *
105
 
 * All pixels @x0 <= x < @x1, @y0 <= y < @y1 are generated. A
106
 
 * stored value of zero is no coverage, and a value of 255 is full
107
 
 * coverage. The area within the pixel (x, y) is the region covered
108
 
 * by [x..x+1] and [y..y+1].
109
 
 **/
110
 
void
111
 
art_gray_svp_aa (const ArtSVP *svp,
112
 
                 int x0, int y0, int x1, int y1,
113
 
                 art_u8 *buf, int rowstride)
114
 
{
115
 
  ArtGraySVPData data;
116
 
 
117
 
  data.buf = buf;
118
 
  data.rowstride = rowstride;
119
 
  data.x0 = x0;
120
 
  data.x1 = x1;
121
 
  art_svp_render_aa (svp, x0, y0, x1, y1, art_gray_svp_callback, &data);
122
 
}