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/fl8fltr2.c $
21  * $Revision: 1.3 $
22  * $Author: kaboom $
23  * $Date: 1993/10/19 09:52:36 $
24  *
25  * Routine for scaling down by 2 with filtering onto a flat8 canvas
26  *
27  * This file is part of the 2d library.
28  *
29  * $Log: fl8fltr2.c $
30  * Revision 1.3  1993/10/19  09:52:36  kaboom
31  * Replaced #include <grd.h" with new headers split from grd.h.
32  *
33  * Revision 1.2  1993/10/08  01:15:14  kaboom
34  * Changed quotes in #include lines to angle brackets for Watcom.
35  *
36  * Revision 1.1  1993/08/05  20:06:53  jaemz
37  * Initial revision
38  */
39 
40 #include "bitmap.h"
41 #include "cnvdat.h"
42 #include "scrdat.h"
43 
44 /* Assumes bm is flat, assumes canvas is big enough to
45    hold it, as it is, unclipped */
flat8_filter2_ubitmap(grs_bitmap * bm)46 void flat8_filter2_ubitmap(grs_bitmap *bm) {
47     grs_rgb a;
48     int i, j;
49     uchar *src, *dst;
50     uchar *c;
51     int ds;
52     int dd;
53 
54     dst = grd_bm.bits;
55     src = bm->bits;
56 
57     ds = 2 * bm->row - bm->w;
58     dd = grd_bm.row - grd_bm.w;
59 
60     /* variables
61        a,src,dst,bm->row,grd_ipal,grd_bpal */
62 
63     /* Cycle through rows and do horizontal strips */
64     for (j = bm->h; j > 0; j -= 2) {
65         for (i = bm->w; i > 0; i -= 2) {
66             a = (grd_bpal[*src] >> 2) & 0x3fc7f8ff;
67             src++;
68             a += (grd_bpal[*src] >> 2) & 0x3fc7f8ff;
69             src += bm->row;
70             a += (grd_bpal[*src] >> 2) & 0x3fc7f8ff;
71             src--;
72             a += (grd_bpal[*src] >> 2) & 0x3fc7f8ff;
73             src -= bm->row;
74             src += 2;
75 
76             c = grd_ipal;
77             a = a >> 5;
78             c += a & 0x1f;
79             a = a >> 6;
80             c += a & 0x3e0;
81             a = a >> 6;
82             c += a & 0x7c00;
83 
84             *dst = *c;
85             dst++;
86         }
87         src += ds;
88         dst += dd;
89     }
90 }
91