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/genmono.c $
21 * $Revision: 1.4 $
22 * $Author: kaboom $
23 * $Date: 1993/10/19 09:51:20 $
24 *
25 * Generic monochrome bitmap routines.
26 *
27 * $Log: genmono.c $
28 * Revision 1.4 1993/10/19 09:51:20 kaboom
29 * Replaced #include "grd.h" with new headers split from grd.h.
30 *
31 * Revision 1.3 1993/10/02 01:17:28 kaboom
32 * Changed include of clip.h to include of clpcon.h and/or clpfcn.h.
33 *
34 * Revision 1.2 1993/04/29 18:40:38 kaboom
35 * Changed include of gr.h to smaller more specific grxxx.h.
36 *
37 * Revision 1.1 1993/02/16 15:42:57 kaboom
38 * Initial revision
39 *
40 ********************************************************************
41 * Log from old general.c:
42 *
43 * Revision 1.7 1992/12/11 13:58:09 kaboom
44 * Changed all the calls from gr_set_pixel to gr_set_upixel in primitives
45 * that have analytic clipping. Changed chain in gen_mono_bitmap()
46 * from general to specific (e.g., gr_ubitmap->gr_mono_ubitmap).
47 */
48
49 #include "bit.h"
50 #include "bitmap.h"
51 #include "clpcon.h"
52 #include "clpfcn.h"
53 #include "cnvdat.h"
54 #include "grdbm.h"
55 #include "grpix.h"
56
57 /* draw a monochrome bitmap with calls to gr_set_pixel for maximum device
58 independence and slowness. draws 1's in the source bitmap as currently
59 set foreground, and 0's are bacground if opaque, or not drawn if trans-
60 parent. */
gen_mono_ubitmap(grs_bitmap * bm,short x,short y)61 void gen_mono_ubitmap (grs_bitmap *bm, short x, short y)
62 {
63 short w, h; /* working width and height */
64 short dst_x; /* destination x */
65 int bit; /* bit from 0-7 in source byte */
66 uchar *p_row; /* pointer to current row of bitmap */
67 uchar *p; /* pointer to source byte */
68
69 h = bm->h;
70 p_row = bm->bits;
71
72 if (bm->flags & BMF_TRANS)
73 {
74 /* transparent bitmap; draw 1's as fcolor, don't draw 0's. */
75 while (h-- > 0)
76 {
77 /* set up scanline. */
78 bit = bm->align;
79 dst_x = x;
80 p = p_row;
81 w = bm->w;
82
83 while (w-- > 0)
84 {
85 /* do current scanline. */
86 if (*p & bitmask[bit])
87 gr_set_pixel (grd_gc.fcolor, dst_x, y);
88 dst_x++;
89 if (++bit > 7)
90 {
91 bit = 0;
92 p++;
93 }
94 }
95
96 y++;
97 p_row += bm->row;
98 }
99 }
100 else
101 {
102 /* opaque bitmap; draw 1's as fcolor, 0's as bcolor. */
103 while (h-- > 0)
104 {
105 bit = bm->align;
106 dst_x = x;
107 p = p_row;
108 w = bm->w;
109
110 while (w-- > 0)
111 {
112 if (*p & bitmask[bit])
113 gr_set_upixel (grd_gc.fcolor, dst_x, y);
114 else
115 gr_set_upixel (grd_gc.bcolor, dst_x, y);
116 dst_x++;
117 if (++bit > 7)
118 {
119 bit = 0;
120 p++;
121 }
122 }
123
124 y++;
125 p_row += bm->row;
126 }
127 }
128 }
129
130 /* clip monochrome bitmap against cliprect and jump to unclipped drawer. */
gen_mono_bitmap(grs_bitmap * bm,short x,short y)131 int gen_mono_bitmap (grs_bitmap *bm, short x, short y)
132 {
133 short w,h;
134 uchar align;
135 uchar *p;
136 int code = CLIP_NONE;
137
138 /* save stuff that clipping changes. */
139 w = bm->w; h = bm->h; align = bm->align; p = bm->bits;
140
141 /* clip & draw that sucker. */
142 code = gr_clip_mono_bitmap (bm, &x, &y);
143 if (code != CLIP_ALL)
144 gr_mono_ubitmap (bm, x, y);
145
146 /* restore bitmap to normal. */
147 bm->w = w; bm->h = h; bm->align = align; bm->bits = p;
148 return code;
149 }
150