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/fl8mono.c $
21  * $Revision: 1.3 $
22  * $Author: kaboom $
23  * $Date: 1993/10/19 09:50:39 $
24  *
25  * Routines for drawing monochrome bitmaps into a flat 8 canvas.
26  *
27  * This file is part of the 2d library.
28  *
29  * $Log: fl8mono.c $
30  * Revision 1.3  1993/10/19  09:50:39  kaboom
31  * Replaced #include <grd.h" with new headers split from grd.h.
32  *
33  * Revision 1.2  1993/10/08  01:15:23  kaboom
34  * Changed quotes in #include liness to angle brackets for Watcom problem.
35  *
36  * Revision 1.1  1993/02/16  14:15:56  kaboom
37  * Initial revision
38  *
39  ********************************************************************
40  * Log from old flat8.c:
41  *
42  * Revision 1.5  1992/12/11  13:13:33  kaboom
43  * Fixed bug in transparent case of flat8_mono_ubitmap -- destination
44  * pointer wasn't getting incremented on transparent pixels.
45  */
46 
47 #include "bit.h"
48 #include "bitmap.h"
49 #include "cnvdat.h"
50 
flat8_mono_ubitmap(grs_bitmap * bm,short x,short y)51 void flat8_mono_ubitmap(grs_bitmap *bm, short x, short y) {
52     short w, h;   /* working width and height */
53     int bit;      /* bit from 0-7 in source byte */
54     uchar *p_row; /* pointer to current row of bitmap */
55     uchar *p_src; /* pointer to source byte */
56     uchar *p_dst;
57 
58     h = bm->h;
59     p_row = bm->bits;
60     p_dst = grd_bm.bits + y * grd_bm.row + x;
61 
62     if (bm->flags & BMF_TRANS) {
63         /* transparent bitmap; draw 1's as fcolor, don't draw 0's. */
64         while (h-- > 0) {
65             /* set up scanline. */
66             bit = bm->align;
67             p_src = p_row;
68             w = bm->w;
69 
70             while (w-- > 0) {
71                 /* do current scanline. */
72                 if (*p_src & bitmask[bit])
73                     *p_dst++ = grd_gc.fcolor;
74                 else
75                     p_dst++;
76                 if (++bit > 7) {
77                     bit = 0;
78                     p_src++;
79                 }
80             }
81             p_dst += grd_bm.row - bm->w;
82             p_row += bm->row;
83         }
84     } else {
85         /* opaque bitmap; draw 1's as fcolor, 0's as bcolor. */
86         while (h-- > 0) {
87             bit = bm->align;
88             p_src = p_row;
89             w = bm->w;
90 
91             while (w-- > 0) {
92                 if (*p_src & bitmask[bit])
93                     *p_dst++ = grd_gc.fcolor;
94                 else
95                     *p_dst++ = grd_gc.bcolor;
96                 if (++bit > 7) {
97                     bit = 0;
98                     p_src++;
99                 }
100             }
101             p_dst += grd_bm.row - bm->w;
102             p_row += bm->row;
103         }
104     }
105 }
106