rasops1_putchar_width.h revision 1.1 1 /* $NetBSD: rasops1_putchar_width.h,v 1.1 2019/07/29 02:57:41 rin Exp $ */
2
3 /* NetBSD: rasops1.c,v 1.28 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_WIDTH != 8 && RASOPS_WIDTH != 16
34 #error "Width not supported"
35 #endif
36
37 #define PUTCHAR_WIDTH1(width) rasops1_putchar ## width
38 #define PUTCHAR_WIDTH(width) PUTCHAR_WIDTH1(width)
39
40 #if RASOPS_WIDTH == 8
41 #define COPY_UNIT uint8_t
42 #define GET_GLYPH tmp = fr[0]
43 #endif
44
45 #if RASOPS_WIDTH == 16
46 /*
47 * rp and hrp are always half-word aligned, whereas
48 * fr may not be aligned in half-word boundary.
49 */
50 #define COPY_UNIT uint16_t
51 # if BYTE_ORDER == BIG_ENDIAN
52 #define GET_GLYPH tmp = (fr[0] << 8) | fr[1]
53 # else
54 #define GET_GLYPH tmp = fr[0] | (fr[1] << 8)
55 # endif
56 #endif /* RASOPS_WIDTH == 16 */
57
58 /*
59 * Width-optimized putchar function.
60 */
61 static void
62 PUTCHAR_WIDTH(RASOPS_WIDTH)(void *cookie, int row, int col, u_int uc, long attr)
63 {
64 struct rasops_info *ri = (struct rasops_info *)cookie;
65 struct wsdisplay_font *font = PICK_FONT(ri, uc);
66 int height, fs, rs, bg, fg;
67 uint8_t *fr;
68 COPY_UNIT *rp, *hrp, tmp;
69
70 hrp = NULL; /* XXX GCC */
71
72 #ifdef RASOPS_CLIPPING
73 /* Catches 'row < 0' case too */
74 if ((unsigned)row >= (unsigned)ri->ri_rows)
75 return;
76
77 if ((unsigned)col >= (unsigned)ri->ri_cols)
78 return;
79 #endif
80
81 rp = (COPY_UNIT *)(ri->ri_bits + row * ri->ri_yscale +
82 col * sizeof(COPY_UNIT));
83 if (ri->ri_hwbits)
84 hrp = (COPY_UNIT *)(ri->ri_hwbits + row * ri->ri_yscale +
85 col * sizeof(COPY_UNIT));
86 height = font->fontheight;
87 rs = ri->ri_stride;
88
89 bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
90 fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
91
92 /* If fg and bg match this becomes a space character */
93 if (uc == ' ' || fg == bg) {
94 while (height--) {
95 *rp = bg;
96 DELTA(rp, rs, COPY_UNIT *);
97 }
98 if (ri->ri_hwbits) {
99 while (height--) {
100 *hrp = bg;
101 DELTA(hrp, rs, COPY_UNIT *);
102 }
103 }
104 } else {
105 fr = FONT_GLYPH(uc, font, ri);
106 fs = font->stride;
107
108 while (height--) {
109 GET_GLYPH;
110 if (bg)
111 tmp = ~tmp;
112 *rp = tmp;
113 DELTA(rp, rs, COPY_UNIT *);
114 if (ri->ri_hwbits) {
115 *hrp = tmp;
116 DELTA(hrp, rs, COPY_UNIT *);
117 }
118 fr += fs;
119 }
120 }
121
122 /* Do underline */
123 if ((attr & WSATTR_UNDERLINE) != 0) {
124 DELTA(rp, -(ri->ri_stride << 1), COPY_UNIT *);
125 *rp = fg;
126 if (ri->ri_hwbits) {
127 DELTA(hrp, -(ri->ri_stride << 1), COPY_UNIT *);
128 *hrp = fg;
129 }
130 }
131 }
132
133 #undef PUTCHAR_WIDTH1
134 #undef PUTCHAR_WIDTH
135
136 #undef COPY_UNIT
137 #undef GET_GLYPH
138