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: n:/project/lib/src/2d/RCS/fl8ntrp2.c $
21 * $Revision: 1.4 $
22 * $Author: kaboom $
23 * $Date: 1993/10/19 09:54:21 $
24 *
25 * Routine for scaling up by 2 with interpolation onto a gen canvas
26 *
27 * This file is part of the 2d library.
28 *
29 * $Log: fl8ntrp2.c $
30 * Revision 1.4 1993/10/19 09:54:21 kaboom
31 * Replaced #include <grd.h" with new headers split from grd.h.
32 *
33 * Revision 1.3 1993/10/08 01:15:24 kaboom
34 * Changed quotes in #include liness to angle brackets for Watcom problem.
35 *
36 * Revision 1.2 1993/10/02 00:37:56 kaboom
37 * Fixed bug---wasn't drawing the last line.
38 *
39 * Revision 1.1 1993/08/05 20:06:42 jaemz
40 * Initial revision
41 */
42
43 #include "bitmap.h"
44 #include "cnvdat.h"
45 #include "scrdat.h"
46
47 /* Assumes bm is flat, assumes canvas is big enough to
48 hold it, as it is, unclipped */
flat8_interp2_ubitmap(grs_bitmap * bm)49 void flat8_interp2_ubitmap(grs_bitmap *bm) {
50 grs_rgb a, b;
51 int i, j;
52 uchar *c;
53 uchar *src, *dst;
54 int dd, ds;
55
56 /* Cycle through rows and do horizontal strips */
57 dd = 2 * grd_bm.row - grd_bm.w;
58 ds = bm->row - bm->w;
59
60 dst = grd_bm.bits;
61 src = bm->bits;
62
63 for (j = bm->h; j > 0; j--) {
64 for (i = bm->w; i > 0; i--) {
65
66 a = *src;
67 src++;
68 b = *src;
69
70 *dst = a;
71 dst++;
72
73 /* load them with the rgb values */
74 a = grd_bpal[a];
75 b = grd_bpal[b];
76 a = (a >> 1) + (b >> 1);
77 c = grd_ipal;
78 a = a >> 5;
79 c += a & 0x1f;
80 a = a >> 6;
81 c += a & 0x3e0;
82 a = a >> 6;
83 c += a & 0x7c00;
84
85 *dst = *c;
86 dst++;
87 }
88 dst += dd;
89 src += ds;
90 }
91
92 /* Cycle through rows and fill in missing strips */
93 src = grd_bm.bits;
94 for (i = (bm->w) * 2 - 1; i >= 0; i--) {
95 src = grd_bm.bits + i;
96 for (j = bm->h; j > 1; j--) {
97 a = *src;
98 src += 2 * grd_bm.row;
99 b = *src;
100 src -= grd_bm.row;
101
102 a = grd_bpal[a];
103 b = grd_bpal[b];
104 a = (a >> 1) + (b >> 1);
105 c = grd_ipal;
106 a = a >> 5;
107 c += a & 0x1f;
108 a = a >> 6;
109 c += a & 0x3e0;
110 a = a >> 6;
111 c += a & 0x7c00;
112 *src = *c;
113 src += grd_bm.row;
114 }
115 src += grd_bm.row;
116 *src = 0;
117 }
118 }
119