convert line ends
[canaan.git] / prj / tech / libsrc / g2 / shadhack.c
blob2d124fcc5b80d3498fe26470c0ff1a61cc0d968b
1 // $Header: x:/prj/tech/libsrc/g2/RCS/shadhack.c 1.6 1998/04/28 14:29:32 KEVIN Exp $
3 #include <g2d.h>
4 #include <trirast.h>
5 #include <plyshell.h>
6 #include <tmapd.h>
7 #include <dev2d.h>
8 #include <genrast.h>
10 static void golf_shadow_hack_il(g2s_raster *r, g2s_poly_params *tp)
12 uint offset_max;
13 fix u,v,du,dv;
14 int row, left, right, x, x_last;
15 ushort *dst;
16 uchar *src;
18 if (r->n <= 0)
19 return;
21 if ((r->y < grd_clip.top) || (r->y >= grd_clip.bot))
22 return;
24 src = tp->bm->bits;
25 row = tp->bm->row;
26 offset_max = (uint )(row * tp->bm->h);
27 left = grd_clip.left;
28 right = grd_clip.right;
29 dst = (ushort *)(grd_bm.bits + r->y * grd_bm.row);
31 x = r->x;
32 u = r->u;
33 v = r->v;
34 du = tp->dux;
35 dv = tp->dvx;
36 x_last = x + r->n - 1;
37 goto loop_start;
38 do {
39 uint offset;
40 uchar c;
41 ushort c16;
42 ushort *clut;
44 u += du;
45 v += dv;
46 x++;
47 loop_start:
48 if ((x < left) || (x >= right))
49 continue;
51 offset = (uint )(fix_int(u) + fix_int(v)*row);
52 if (offset >= offset_max)
53 offset = 0;
54 c = src[offset];
55 if (c==0)
56 continue;
58 clut = (ushort *)(tluc8tab[c]);
59 c16 = dst[x];
60 dst[x] = clut[c16&0xff] + clut[256 + (c16>>8)];
61 } while (x<x_last);
64 void golf_shadow_hack(grs_bitmap *bm, int n, g2s_point **vpl)
66 g2s_poly_params tp;
68 tp.flags = PPF_UV;
69 tp.dy = 1;
71 tp.bm = bm;
72 tp.u_scale = bm->w;
73 tp.v_scale = bm->h;
74 tp.inner_loop = golf_shadow_hack_il;
75 tp.raster_func = gen_raster_loop;
76 tp.right_edge_func = gen_right_edge;
77 tp.left_edge_func = gen_left_edge;
78 tp.grad_func = gen_triangle_gradients;
80 g2_trifan(&tp, n, vpl);