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 /* $Source: n:/project/lib/src/2d/RCS/fl8mscl.c $
20 * $Revision: 1.1 $
21 * $Author: lmfeeney $
22 * $Date: 1994/04/09 00:18:42 $
23 */
24
25 #include "bit.h"
26 #include "bitmap.h"
27 #include "clpcon.h"
28 #include "cnvdat.h"
29
flat8_mono_scale_ubitmap(grs_bitmap * bm,short x,short y,short w,short h)30 void flat8_mono_scale_ubitmap(grs_bitmap *bm, short x, short y, short w, short h) {
31 fix x_scale; /* x scale factor */
32 fix y_scale; /* y scale factor */
33 fix x_src; /* fractional x in source bitmap */
34 fix y_src; /* y */
35 uchar *p_src; /* pointer into source bitmap */
36 uchar *p_dst; /* pointer into destination bitmap */
37 int index, bit; /* calculate indexes into char and bitmap */
38 int i;
39
40 /* if either width or height is to be 0, no problem. */
41 if (w == 0 || h == 0)
42 return;
43
44 x_scale = (bm->w << 16) / w;
45 y_scale = (bm->h << 16) / h;
46
47 y_src = y_scale >> 1;
48 p_dst = grd_bm.bits + y * grd_bm.row + x;
49
50 if (bm->flags & BMF_TRANS)
51 while (h-- > 0) {
52 p_src = bm->bits + fix_int(y_src) * bm->row;
53 x_src = (bm->align << 16) + (x_scale >> 1);
54
55 for (i = 0; i < w; i++) {
56 index = x_src >> (16 + 3);
57 bit = (x_src >> 16) & 0x0007;
58
59 if (p_src[index] & bitmask[bit])
60 *p_dst++ = grd_gc.fcolor;
61 else
62 p_dst++;
63
64 x_src += x_scale;
65 }
66 p_dst += grd_bm.row - w;
67 y_src += y_scale;
68 }
69 else
70 while (h-- > 0) {
71 p_src = bm->bits + fix_int(y_src) * bm->row;
72 x_src = (bm->align << 16) + (x_scale >> 4);
73
74 for (i = 0; i < w; i++) {
75 index = x_src >> (16 + 3);
76 bit = (x_src >> 16) & 0x0007;
77
78 if (p_src[index] & bitmask[bit])
79 *p_dst++ = grd_gc.fcolor;
80 else
81 *p_dst++ = grd_gc.bcolor;
82
83 x_src += x_scale;
84 }
85
86 p_dst += grd_bm.row - w;
87 y_src += y_scale;
88 }
89 }
90
flat8_mono_scale_bitmap(grs_bitmap * bm,short x,short y,short w,short h)91 int flat8_mono_scale_bitmap(grs_bitmap *bm, short x, short y, short w, short h) {
92 fix x_left;
93 fix x_scale; /* x scale factor */
94 fix y_scale; /* y scale factor */
95 fix x_src; /* fractional x in source bitmap */
96 fix y_src; /* y */
97 uchar *p_src; /* pointer into source bitmap */
98 uchar *p_dst;
99 int code;
100 int index = 0, bit = 0; /* char, bit in char in bitmask */
101 int i;
102
103 /* if either width or height is to be 0, no problem. */
104 if (w == 0 || h == 0)
105 return CLIP_ALL;
106
107 /* check for trivial reject clip. */
108 if (x > grd_clip.right || x + w <= grd_clip.left || y > grd_clip.bot || y + h <= grd_clip.top)
109 return CLIP_ALL;
110
111 x_scale = (bm->w << 16) / w;
112 y_scale = (bm->h << 16) / h;
113 x_left = y_src = 0;
114 code = CLIP_NONE;
115
116 if (x < grd_clip.left) {
117 x_left = x_scale * (grd_clip.left - x);
118 w -= grd_clip.left - x;
119 x = grd_clip.left;
120 code |= CLIP_LEFT;
121 }
122 if (x + w > grd_clip.right) {
123 w = grd_clip.right - x;
124 code |= CLIP_RIGHT;
125 }
126 if (y < grd_clip.top) {
127 y_src = y_scale * (grd_clip.top - y);
128 h -= grd_clip.top - y;
129 y = grd_clip.top;
130 code |= CLIP_TOP;
131 }
132 if (y + h > grd_clip.bot) {
133 h = grd_clip.bot - y;
134 code |= CLIP_BOT;
135 }
136
137 x_left += (bm->align << 16);
138 x_left += (x_scale >> 1);
139 y_src += y_scale >> 1;
140 p_dst = grd_bm.bits + y * grd_bm.row + x;
141
142 if (bm->flags & BMF_TRANS)
143 while (h-- > 0) {
144 p_src = bm->bits + fix_int(y_src) * bm->row;
145 x_src = x_left;
146
147 for (i = w; i > 0; i--) {
148 index = x_src >> (16 + 3);
149 bit = (x_src >> 16) & 0x0007;
150
151 if (p_src[index] & bitmask[bit])
152 *p_dst++ = grd_gc.fcolor;
153 else
154 p_dst++;
155
156 x_src += x_scale;
157 }
158
159 p_dst += grd_bm.row - w;
160 y_src += y_scale;
161 }
162 else
163
164 while (h-- > 0) {
165 p_src = bm->bits + fix_int(y_src) * bm->row;
166 x_src = x_left;
167
168 for (i = w; i > 0; i--) {
169
170 if (p_src[index] & bitmask[bit])
171 *p_dst++ = grd_gc.fcolor;
172 else
173 *p_dst++ = grd_gc.bcolor;
174
175 x_src += x_scale;
176 }
177
178 p_dst += grd_bm.row - w;
179 y_src += y_scale;
180 }
181
182 return code;
183 }
184