rasops_putchar.h revision 1.5 1 /* $NetBSD: rasops_putchar.h,v 1.5 2019/07/30 15:29:40 rin Exp $ */
2
3 /* NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp */
4 /*-
5 * Copyright (c) 1999 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Andrew Doran.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #if RASOPS_DEPTH != 8 && RASOPS_DEPTH != 15 && RASOPS_DEPTH != 24 && \
34 RASOPS_DEPTH != 32
35 #error "Depth not supported"
36 #endif
37
38 #define PUTCHAR(depth) PUTCHAR1(depth)
39 #define PUTCHAR1(depth) rasops ## depth ## _putchar
40
41 #if RASOPS_DEPTH == 8
42 #define COLOR_TYPE uint8_t
43 #elif RASOPS_DEPTH == 15
44 #define COLOR_TYPE uint16_t
45 #else
46 #define COLOR_TYPE uint32_t
47 #endif
48
49 #if RASOPS_DEPTH != 24
50 #define PIXEL_BYTES sizeof(COLOR_TYPE)
51 #define SET_PIXEL(p, index) \
52 do { \
53 *(COLOR_TYPE *)(p) = clr[index]; \
54 (p) += sizeof(COLOR_TYPE); \
55 } while (0 /* CONSTCOND */)
56 #endif
57
58 #if RASOPS_DEPTH == 24
59 #define PIXEL_BYTES 3
60 #define SET_PIXEL(p, index) \
61 do { \
62 COLOR_TYPE c = clr[index]; \
63 *(p)++ = c >> 16; \
64 *(p)++ = c >> 8; \
65 *(p)++ = c; \
66 } while (0 /* CONSTCOND */)
67 #endif
68
69 /*
70 * Put a single character.
71 */
72 static void
73 PUTCHAR(RASOPS_DEPTH)(void *cookie, int row, int col, u_int uc, long attr)
74 {
75 struct rasops_info *ri = (struct rasops_info *)cookie;
76 struct wsdisplay_font *font = PICK_FONT(ri, uc);
77 int width, height, cnt, fs;
78 uint32_t fb;
79 uint8_t *dp, *rp, *hp, *fr;
80 COLOR_TYPE clr[2];
81
82 hp = NULL; /* XXX GCC */
83
84 if (!CHAR_IN_FONT(uc, font))
85 return;
86
87 #ifdef RASOPS_CLIPPING
88 /* Catches 'row < 0' case too */
89 if ((unsigned)row >= (unsigned)ri->ri_rows)
90 return;
91
92 if ((unsigned)col >= (unsigned)ri->ri_cols)
93 return;
94 #endif
95
96 rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
97 if (ri->ri_hwbits)
98 hp = ri->ri_hwbits + row * ri->ri_yscale + col * ri->ri_xscale;
99
100 height = font->fontheight;
101 width = font->fontwidth;
102
103 clr[0] = (COLOR_TYPE)ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
104 clr[1] = (COLOR_TYPE)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
105
106 if (uc == ' ') {
107 while (height--) {
108 dp = rp;
109 for (cnt = width; cnt; cnt--)
110 SET_PIXEL(dp, 0);
111 if (ri->ri_hwbits) {
112 uint16_t bytes = width * PIXEL_BYTES;
113 /* XXX GCC */
114 memcpy(hp, rp, bytes);
115 hp += ri->ri_stride;
116 }
117 rp += ri->ri_stride;
118 }
119 } else {
120 fr = FONT_GLYPH(uc, font, ri);
121 fs = font->stride;
122
123 while (height--) {
124 dp = rp;
125 fb = be32uatoh(fr);
126 fr += fs;
127 for (cnt = width; cnt; cnt--) {
128 SET_PIXEL(dp, (fb >> 31) & 1);
129 fb <<= 1;
130 }
131 if (ri->ri_hwbits) {
132 uint16_t bytes = width * PIXEL_BYTES;
133 /* XXX GCC */
134 memcpy(hp, rp, bytes);
135 hp += ri->ri_stride;
136 }
137 rp += ri->ri_stride;
138 }
139 }
140
141 /* Do underline */
142 if ((attr & WSATTR_UNDERLINE) != 0) {
143 rp -= (ri->ri_stride << 1);
144 dp = rp;
145 while (width--)
146 SET_PIXEL(dp, 1);
147 if (ri->ri_hwbits) {
148 hp -= (ri->ri_stride << 1);
149 uint16_t bytes = width * PIXEL_BYTES; /* XXX GCC */
150 memcpy(hp, rp, bytes);
151 }
152 }
153 }
154
155 #undef PUTCHAR
156 #undef COLOR_TYPE
157 #undef PIXEL_BYTES
158 #undef SET_PIXEL
159