1 | /*
|
---|
2 | * $Id: renderedge.h,v 1.4 2005/08/24 11:18:33 daniels Exp $
|
---|
3 | *
|
---|
4 | * Copyright © 2004 Keith Packard
|
---|
5 | *
|
---|
6 | * Permission to use, copy, modify, distribute, and sell this software and its
|
---|
7 | * documentation for any purpose is hereby granted without fee, provided that
|
---|
8 | * the above copyright notice appear in all copies and that both that
|
---|
9 | * copyright notice and this permission notice appear in supporting
|
---|
10 | * documentation, and that the name of Keith Packard not be used in
|
---|
11 | * advertising or publicity pertaining to distribution of the software without
|
---|
12 | * specific, written prior permission. Keith Packard makes no
|
---|
13 | * representations about the suitability of this software for any purpose. It
|
---|
14 | * is provided "as is" without express or implied warranty.
|
---|
15 | *
|
---|
16 | * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
---|
17 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
---|
18 | * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
---|
19 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
---|
20 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
---|
21 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
---|
22 | * PERFORMANCE OF THIS SOFTWARE.
|
---|
23 | */
|
---|
24 |
|
---|
25 | #ifndef _RENDEREDGE_H_
|
---|
26 | #define _RENDEREDGE_H_
|
---|
27 |
|
---|
28 | #include "picturestr.h"
|
---|
29 |
|
---|
30 | #define MAX_ALPHA(n) ((1 << (n)) - 1)
|
---|
31 | #define N_Y_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
|
---|
32 | #define N_X_FRAC(n) ((1 << ((n)/2)) + 1)
|
---|
33 |
|
---|
34 | #define STEP_Y_SMALL(n) (xFixed1 / N_Y_FRAC(n))
|
---|
35 | #define STEP_Y_BIG(n) (xFixed1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
|
---|
36 |
|
---|
37 | #define Y_FRAC_FIRST(n) (STEP_Y_SMALL(n) / 2)
|
---|
38 | #define Y_FRAC_LAST(n) (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
|
---|
39 |
|
---|
40 | #define STEP_X_SMALL(n) (xFixed1 / N_X_FRAC(n))
|
---|
41 | #define STEP_X_BIG(n) (xFixed1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
|
---|
42 |
|
---|
43 | #define X_FRAC_FIRST(n) (STEP_X_SMALL(n) / 2)
|
---|
44 | #define X_FRAC_LAST(n) (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
|
---|
45 |
|
---|
46 | #define RenderSamplesX(x,n) ((n) == 1 ? 0 : (xFixedFrac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
|
---|
47 |
|
---|
48 | /*
|
---|
49 | * An edge structure. This represents a single polygon edge
|
---|
50 | * and can be quickly stepped across small or large gaps in the
|
---|
51 | * sample grid
|
---|
52 | */
|
---|
53 |
|
---|
54 | typedef struct {
|
---|
55 | xFixed x;
|
---|
56 | xFixed e;
|
---|
57 | xFixed stepx;
|
---|
58 | xFixed signdx;
|
---|
59 | xFixed dy;
|
---|
60 | xFixed dx;
|
---|
61 |
|
---|
62 | xFixed stepx_small;
|
---|
63 | xFixed stepx_big;
|
---|
64 | xFixed dx_small;
|
---|
65 | xFixed dx_big;
|
---|
66 | } RenderEdge;
|
---|
67 |
|
---|
68 | /*
|
---|
69 | * Step across a small sample grid gap
|
---|
70 | */
|
---|
71 | #define RenderEdgeStepSmall(edge) { \
|
---|
72 | edge->x += edge->stepx_small; \
|
---|
73 | edge->e += edge->dx_small; \
|
---|
74 | if (edge->e > 0) \
|
---|
75 | { \
|
---|
76 | edge->e -= edge->dy; \
|
---|
77 | edge->x += edge->signdx; \
|
---|
78 | } \
|
---|
79 | }
|
---|
80 |
|
---|
81 | /*
|
---|
82 | * Step across a large sample grid gap
|
---|
83 | */
|
---|
84 | #define RenderEdgeStepBig(edge) { \
|
---|
85 | edge->x += edge->stepx_big; \
|
---|
86 | edge->e += edge->dx_big; \
|
---|
87 | if (edge->e > 0) \
|
---|
88 | { \
|
---|
89 | edge->e -= edge->dy; \
|
---|
90 | edge->x += edge->signdx; \
|
---|
91 | } \
|
---|
92 | }
|
---|
93 |
|
---|
94 | xFixed
|
---|
95 | RenderSampleCeilY (xFixed y, int bpp);
|
---|
96 |
|
---|
97 | xFixed
|
---|
98 | RenderSampleFloorY (xFixed y, int bpp);
|
---|
99 |
|
---|
100 | void
|
---|
101 | RenderEdgeStep (RenderEdge *e, int n);
|
---|
102 |
|
---|
103 | void
|
---|
104 | RenderEdgeInit (RenderEdge *e,
|
---|
105 | int bpp,
|
---|
106 | xFixed y_start,
|
---|
107 | xFixed x_top,
|
---|
108 | xFixed y_top,
|
---|
109 | xFixed x_bot,
|
---|
110 | xFixed y_bot);
|
---|
111 |
|
---|
112 | void
|
---|
113 | RenderLineFixedEdgeInit (RenderEdge *e,
|
---|
114 | int bpp,
|
---|
115 | xFixed y,
|
---|
116 | xLineFixed *line,
|
---|
117 | int x_off,
|
---|
118 | int y_off);
|
---|
119 |
|
---|
120 | #endif /* _RENDEREDGE_H_ */
|
---|