1 /*
2
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 */
19 /*
20 * $Source: r:/prj/lib/src/2d/RCS/fl8ns.c $
21 * $Revision: 1.1 $
22 * $Author: kevin $
23 * $Date: 1994/08/16 13:13:12 $
24 *
25 * Routines to scale a flat8 bitmap to a generic canvas.
26 *
27 * This file is part of the 2d library.
28 *
29 */
30
31 #include "cnvdat.h"
32 #include "fl8tf.h"
33 #include "gente.h"
34 #include "grnull.h"
35 #include "poly.h"
36 #include "tlucdat.h"
37 #include "tmapint.h"
38
39 // prototypes
40 int gri_tluc8_scale_umap_loop(grs_tmap_loop_info *tli);
41
gri_tluc8_scale_umap_loop(grs_tmap_loop_info * tli)42 int gri_tluc8_scale_umap_loop(grs_tmap_loop_info *tli) {
43 fix u, ul, du;
44 uchar *pl, *pr;
45
46 pl = tli->d + fix_cint(tli->left.x);
47 pr = tli->d + fix_cint(tli->right.x);
48 if (pr <= pl)
49 return TRUE;
50 ul = tli->left.u;
51 du = fix_div(tli->right.u - ul, tli->right.x - tli->left.x);
52 ul += fix_mul(du, fix_ceil(tli->left.x) - tli->left.x);
53 do {
54 uchar *p_dst, k;
55 uchar *p_src = tli->bm.bits + tli->bm.row * fix_int(tli->left.v);
56 switch (tli->bm.hlog) {
57 case GRL_OPAQUE:
58 for (p_dst = pl, u = ul; p_dst < pr; p_dst++) {
59 k = p_src[fix_fint(u)];
60 if (tluc8tab[k] != NULL)
61 *p_dst = tluc8tab[k][*p_dst];
62 else
63 *p_dst = k;
64 u += du;
65 }
66 break;
67 case GRL_TRANS:
68 for (p_dst = pl, u = ul; p_dst < pr; p_dst++) {
69 k = p_src[fix_fint(u)];
70 if (k != 0) {
71 if (tluc8tab[k] != NULL)
72 *p_dst = tluc8tab[k][*p_dst];
73 else
74 *p_dst = k;
75 }
76 u += du;
77 }
78 break;
79 case GRL_OPAQUE | GRL_CLUT:
80 for (p_dst = pl, u = ul; p_dst < pr; p_dst++) {
81 k = p_src[fix_fint(u)];
82 if (tluc8tab[k] != NULL)
83 *p_dst = tli->clut[tluc8tab[k][*p_dst]];
84 else
85 *p_dst = tli->clut[k];
86 u += du;
87 }
88 break;
89 case GRL_TRANS | GRL_CLUT:
90 for (p_dst = pl, u = ul; p_dst < pr; p_dst++) {
91 k = p_src[fix_fint(u)];
92 if (k != 0) {
93 if (tluc8tab[k] != NULL)
94 *p_dst = tli->clut[tluc8tab[k][*p_dst]];
95 else
96 *p_dst = tli->clut[k];
97 }
98 u += du;
99 }
100 break;
101 }
102 tli->left.v += tli->left.dv;
103 pl += grd_bm.row;
104 pr += grd_bm.row;
105 } while (--(tli->n) > 0);
106 return FALSE; /* tmap OK */
107 }
108
gri_tluc8_trans_scale_umap_init(grs_tmap_loop_info * tli)109 void gri_tluc8_trans_scale_umap_init(grs_tmap_loop_info *tli) {
110 tli->bm.hlog = GRL_TRANS;
111 tli->d = grd_bm.bits + grd_bm.row * tli->y;
112 tli->loop_func = (void (*)())gri_tluc8_scale_umap_loop;
113 tli->right_edge_func = gr_null;
114 tli->left_edge_func = (void (*)())gri_scale_edge;
115 }
116
gri_tluc8_opaque_scale_umap_init(grs_tmap_loop_info * tli)117 void gri_tluc8_opaque_scale_umap_init(grs_tmap_loop_info *tli) {
118 tli->bm.hlog = GRL_OPAQUE;
119 tli->d = grd_bm.bits + grd_bm.row * tli->y;
120 tli->loop_func = (void (*)())gri_tluc8_scale_umap_loop;
121 tli->right_edge_func = gr_null;
122 tli->left_edge_func = (void (*)())gri_scale_edge;
123 }
124
gri_tluc8_trans_clut_scale_umap_init(grs_tmap_loop_info * tli)125 void gri_tluc8_trans_clut_scale_umap_init(grs_tmap_loop_info *tli) {
126 tli->bm.hlog = GRL_TRANS | GRL_CLUT;
127 tli->d = grd_bm.bits + grd_bm.row * tli->y;
128 tli->loop_func = (void (*)())gri_tluc8_scale_umap_loop;
129 tli->right_edge_func = gr_null;
130 tli->left_edge_func = (void (*)())gri_scale_edge;
131 }
132
gri_tluc8_opaque_clut_scale_umap_init(grs_tmap_loop_info * tli)133 void gri_tluc8_opaque_clut_scale_umap_init(grs_tmap_loop_info *tli) {
134 tli->bm.hlog = GRL_OPAQUE | GRL_CLUT;
135 tli->d = grd_bm.bits + grd_bm.row * tli->y;
136 tli->loop_func = (void (*)())gri_tluc8_scale_umap_loop;
137 tli->right_edge_func = gr_null;
138 tli->left_edge_func = (void (*)())gri_scale_edge;
139 }
140