rasops1_putchar_width.h revision 1.4 1 /* $NetBSD: rasops1_putchar_width.h,v 1.4 2019/08/07 12:27:49 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 hp 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, *hp, tmp;
69
70 hp = 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 hp = (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 if (ri->ri_hwbits) {
98 *hp = bg;
99 DELTA(hp, rs, COPY_UNIT *);
100 }
101 }
102 } else {
103 fr = FONT_GLYPH(uc, font, ri);
104 fs = font->stride;
105
106 while (height--) {
107 GET_GLYPH;
108 if (bg)
109 tmp = ~tmp;
110 *rp = tmp;
111 DELTA(rp, rs, COPY_UNIT *);
112 if (ri->ri_hwbits) {
113 *hp = tmp;
114 DELTA(hp, rs, COPY_UNIT *);
115 }
116 fr += fs;
117 }
118 }
119
120 /* Do underline */
121 if ((attr & WSATTR_UNDERLINE) != 0) {
122 DELTA(rp, - ri->ri_stride * ri->ri_ul.off, COPY_UNIT *);
123 if (ri->ri_hwbits)
124 DELTA(hp, - ri->ri_stride * ri->ri_ul.off, COPY_UNIT *);
125 for (height = ri->ri_ul.height; height; height--) {
126 DELTA(rp, - ri->ri_stride, COPY_UNIT *);
127 *rp = fg;
128 if (ri->ri_hwbits) {
129 DELTA(hp, - ri->ri_stride, COPY_UNIT *);
130 *hp = fg;
131 }
132 }
133 }
134 }
135
136 #undef PUTCHAR_WIDTH1
137 #undef PUTCHAR_WIDTH
138
139 #undef COPY_UNIT
140 #undef GET_GLYPH
141