convert line ends
[canaan.git] / prj / tech / libsrc / g2 / grtm.c
blobf9a5deaf7b0ea70d239fe289a476d5cc11199fe0
1 // $Header: x:/prj/tech/libsrc/g2/RCS/grtm.c 1.1 1997/05/16 09:48:55 KEVIN Exp $
3 #include <g2d.h>
4 #include <grtm.h>
5 #include <grspoint.h>
6 #include <g2tm.h>
7 #include <buffer.h>
9 static void vpl_to_ppl(grs_bitmap *bm, int n, grs_vertex **vpl, g2s_point **ppl)
11 int i;
12 float inv_u_scale, inv_v_scale;
13 float inv_ltab_size = 1.0/grd_light_table_size;
14 grs_point *pl = (grs_point *)(ppl + n);
16 if (bm!=NULL) {
17 inv_u_scale = 1.0/bm->w;
18 inv_v_scale = 1.0/bm->h;
21 for (i=0; i<n; i++) {
22 ppl[i] = (g2s_point *)(&pl[i]);
23 pl[i].sx = vpl[i]->x;
24 pl[i].sy = vpl[i]->y;
25 pl[i].flags = 0;
26 pl[i].i = fix_float(vpl[i]->i) * inv_ltab_size;
27 if (bm!=NULL) {
28 pl[i].u = fix_float(vpl[i]->u) * inv_u_scale;
29 pl[i].v = fix_float(vpl[i]->v) * inv_v_scale;
30 pl[i].w = fix_float(vpl[i]->w);
35 typedef int (map_func)(int n, g2s_point **ppl);
36 static int do_map(grs_bitmap *bm, int n, grs_vertex **vpl, map_func *f)
38 g2s_point **ppl;
39 int code;
41 ppl = (g2s_point **)gr_alloc_temp(n * (4 + sizeof(grs_point)));
42 vpl_to_ppl (bm, n, vpl, ppl);
43 code = f (n, ppl);
44 gr_free_temp (ppl);
45 return code;
48 int gr_poly(int c, int n, grs_vertex **vpl)
50 gr_set_fcolor (c);
51 g2_poly_setup (NULL);
52 return do_map(NULL, n, vpl, g2_map);
55 int gr_spoly(int c, int n, grs_vertex **vpl)
57 gr_set_fcolor (c);
58 g2_spoly_setup (NULL);
59 return do_map(NULL, n, vpl, g2_map);
62 int gr_lin_map(grs_bitmap *bm, int n, grs_vertex **vpl)
64 g2_lin_map_setup (bm);
65 return do_map(bm, n, vpl, g2_map);
68 int gr_lit_lin_map(grs_bitmap *bm, int n, grs_vertex **vpl)
70 g2_lit_lin_map_setup (bm);
71 return do_map(bm, n, vpl, g2_map);
74 int gr_clut_lin_map(grs_bitmap *bm, int n, grs_vertex **vpl, uchar *clut)
76 int code;
78 if (gr_get_fill_type()==FILL_NORM) {
79 gr_set_fill_type(FILL_CLUT);
80 gr_set_fill_parm(clut);
81 code = gr_lin_map(bm, n, vpl);
82 gr_set_fill_type(FILL_NORM);
83 } else {
84 code = gr_lin_map(bm, n, vpl);
86 return code;
89 int gr_per_map(grs_bitmap *bm, int n, grs_vertex **vpl)
91 g2_per_map_setup(bm);
92 return do_map(bm, n, vpl, g2_per_map);
95 int gr_lit_per_map(grs_bitmap *bm, int n, grs_vertex **vpl)
97 g2_lit_per_map_setup(bm);
98 return do_map(bm, n, vpl, g2_per_map);
101 int gr_clut_per_map(grs_bitmap *bm, int n, grs_vertex **vpl, uchar *clut)
103 int code;
104 if (gr_get_fill_type()==FILL_NORM) {
105 gr_set_fill_type(FILL_CLUT);
106 gr_set_fill_parm(clut);
107 code = gr_per_map(bm, n, vpl);
108 gr_set_fill_type(FILL_NORM);
109 } else {
110 code = gr_per_map(bm, n, vpl);
112 return code;
115 void gr_upoly(int c, int n, grs_vertex **vpl)
117 gr_set_fcolor (c);
118 g2_upoly_setup (NULL);
119 do_map(NULL, n, vpl, g2_umap);
122 void gr_uspoly(int c, int n, grs_vertex **vpl)
124 gr_set_fcolor (c);
125 g2_uspoly_setup (NULL);
126 do_map(NULL, n, vpl, g2_umap);
129 void gr_lin_umap(grs_bitmap *bm, int n, grs_vertex **vpl)
131 g2_lin_umap_setup (bm);
132 do_map(bm, n, vpl, g2_umap);
135 void gr_lit_lin_umap(grs_bitmap *bm, int n, grs_vertex **vpl)
137 g2_lit_lin_umap_setup (bm);
138 do_map(bm, n, vpl, g2_umap);
141 void gr_clut_lin_umap(grs_bitmap *bm, int n, grs_vertex **vpl, uchar *clut)
143 if (gr_get_fill_type()==FILL_NORM) {
144 gr_set_fill_type(FILL_CLUT);
145 gr_set_fill_parm(clut);
146 gr_lin_umap(bm, n, vpl);
147 gr_set_fill_type(FILL_NORM);
148 } else {
149 gr_lin_umap(bm, n, vpl);
153 void gr_per_umap(grs_bitmap *bm, int n, grs_vertex **vpl)
155 g2_per_umap_setup (bm);
156 do_map(bm, n, vpl, g2_per_umap);
159 void gr_lit_per_umap(grs_bitmap *bm, int n, grs_vertex **vpl)
161 g2_lit_per_umap_setup (bm);
162 do_map(bm, n, vpl, g2_per_umap);
165 void gr_clut_per_umap(grs_bitmap *bm, int n, grs_vertex **vpl, uchar *clut)
167 if (gr_get_fill_type()==FILL_NORM) {
168 gr_set_fill_type(FILL_CLUT);
169 gr_set_fill_parm(clut);
170 gr_per_map(bm, n, vpl);
171 gr_set_fill_type(FILL_NORM);
172 } else {
173 gr_per_map(bm, n, vpl);