Home | History | Annotate | Line # | Download | only in rasops
rasops1_putchar_width.h revision 1.2
      1  1.2  rin /* $NetBSD: rasops1_putchar_width.h,v 1.2 2019/07/29 17:22:19 rin Exp $ */
      2  1.1  rin 
      3  1.1  rin /* NetBSD: rasops1.c,v 1.28 2019/07/25 03:02:44 rin Exp */
      4  1.1  rin /*-
      5  1.1  rin  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      6  1.1  rin  * All rights reserved.
      7  1.1  rin  *
      8  1.1  rin  * This code is derived from software contributed to The NetBSD Foundation
      9  1.1  rin  * by Andrew Doran.
     10  1.1  rin  *
     11  1.1  rin  * Redistribution and use in source and binary forms, with or without
     12  1.1  rin  * modification, are permitted provided that the following conditions
     13  1.1  rin  * are met:
     14  1.1  rin  * 1. Redistributions of source code must retain the above copyright
     15  1.1  rin  *    notice, this list of conditions and the following disclaimer.
     16  1.1  rin  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  rin  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  rin  *    documentation and/or other materials provided with the distribution.
     19  1.1  rin  *
     20  1.1  rin  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  1.1  rin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.1  rin  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  1.1  rin  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  1.1  rin  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.1  rin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.1  rin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.1  rin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1  rin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1  rin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1  rin  * POSSIBILITY OF SUCH DAMAGE.
     31  1.1  rin  */
     32  1.1  rin 
     33  1.1  rin #if RASOPS_WIDTH != 8 && RASOPS_WIDTH != 16
     34  1.1  rin #error "Width not supported"
     35  1.1  rin #endif
     36  1.1  rin 
     37  1.1  rin #define	PUTCHAR_WIDTH1(width)	rasops1_putchar ## width
     38  1.1  rin #define	PUTCHAR_WIDTH(width)	PUTCHAR_WIDTH1(width)
     39  1.1  rin 
     40  1.1  rin #if RASOPS_WIDTH == 8
     41  1.1  rin #define	COPY_UNIT	uint8_t
     42  1.1  rin #define	GET_GLYPH	tmp = fr[0]
     43  1.1  rin #endif
     44  1.1  rin 
     45  1.1  rin #if RASOPS_WIDTH == 16
     46  1.1  rin /*
     47  1.1  rin  * rp and hrp are always half-word aligned, whereas
     48  1.1  rin  * fr may not be aligned in half-word boundary.
     49  1.1  rin  */
     50  1.1  rin #define	COPY_UNIT	uint16_t
     51  1.1  rin #  if BYTE_ORDER == BIG_ENDIAN
     52  1.1  rin #define	GET_GLYPH	tmp = (fr[0] << 8) | fr[1]
     53  1.1  rin #  else
     54  1.1  rin #define	GET_GLYPH	tmp = fr[0] | (fr[1] << 8)
     55  1.1  rin #  endif
     56  1.1  rin #endif /* RASOPS_WIDTH == 16 */
     57  1.1  rin 
     58  1.1  rin /*
     59  1.1  rin  * Width-optimized putchar function.
     60  1.1  rin  */
     61  1.1  rin static void
     62  1.1  rin PUTCHAR_WIDTH(RASOPS_WIDTH)(void *cookie, int row, int col, u_int uc, long attr)
     63  1.1  rin {
     64  1.1  rin 	struct rasops_info *ri = (struct rasops_info *)cookie;
     65  1.1  rin 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
     66  1.1  rin 	int height, fs, rs, bg, fg;
     67  1.1  rin 	uint8_t *fr;
     68  1.1  rin 	COPY_UNIT *rp, *hrp, tmp;
     69  1.1  rin 
     70  1.1  rin 	hrp = NULL;	/* XXX GCC */
     71  1.1  rin 
     72  1.1  rin #ifdef RASOPS_CLIPPING
     73  1.1  rin 	/* Catches 'row < 0' case too */
     74  1.1  rin 	if ((unsigned)row >= (unsigned)ri->ri_rows)
     75  1.1  rin 		return;
     76  1.1  rin 
     77  1.1  rin 	if ((unsigned)col >= (unsigned)ri->ri_cols)
     78  1.1  rin 		return;
     79  1.1  rin #endif
     80  1.1  rin 
     81  1.1  rin 	rp = (COPY_UNIT *)(ri->ri_bits + row * ri->ri_yscale +
     82  1.1  rin 	    col * sizeof(COPY_UNIT));
     83  1.1  rin 	if (ri->ri_hwbits)
     84  1.1  rin 		hrp = (COPY_UNIT *)(ri->ri_hwbits + row * ri->ri_yscale +
     85  1.1  rin 		    col * sizeof(COPY_UNIT));
     86  1.1  rin 	height = font->fontheight;
     87  1.1  rin 	rs = ri->ri_stride;
     88  1.1  rin 
     89  1.1  rin 	bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
     90  1.1  rin 	fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
     91  1.1  rin 
     92  1.1  rin 	/* If fg and bg match this becomes a space character */
     93  1.1  rin 	if (uc == ' ' || fg == bg) {
     94  1.1  rin 		while (height--) {
     95  1.1  rin 			*rp = bg;
     96  1.1  rin 			DELTA(rp, rs, COPY_UNIT *);
     97  1.2  rin 			if (ri->ri_hwbits) {
     98  1.1  rin 				*hrp = bg;
     99  1.1  rin 				DELTA(hrp, rs, COPY_UNIT *);
    100  1.1  rin 			}
    101  1.1  rin 		}
    102  1.1  rin 	} else {
    103  1.1  rin 		fr = FONT_GLYPH(uc, font, ri);
    104  1.1  rin 		fs = font->stride;
    105  1.1  rin 
    106  1.1  rin 		while (height--) {
    107  1.1  rin 			GET_GLYPH;
    108  1.1  rin 			if (bg)
    109  1.1  rin 				tmp = ~tmp;
    110  1.1  rin 			*rp = tmp;
    111  1.1  rin 			DELTA(rp, rs, COPY_UNIT *);
    112  1.1  rin 			if (ri->ri_hwbits) {
    113  1.1  rin 				*hrp = tmp;
    114  1.1  rin 				DELTA(hrp, rs, COPY_UNIT *);
    115  1.1  rin 			}
    116  1.1  rin 			fr += fs;
    117  1.1  rin 		}
    118  1.1  rin 	}
    119  1.1  rin 
    120  1.1  rin 	/* Do underline */
    121  1.1  rin 	if ((attr & WSATTR_UNDERLINE) != 0) {
    122  1.1  rin 		DELTA(rp, -(ri->ri_stride << 1), COPY_UNIT *);
    123  1.1  rin 		*rp = fg;
    124  1.1  rin 		if (ri->ri_hwbits) {
    125  1.1  rin 			DELTA(hrp, -(ri->ri_stride << 1), COPY_UNIT *);
    126  1.1  rin 			*hrp = fg;
    127  1.1  rin 		}
    128  1.1  rin 	}
    129  1.1  rin }
    130  1.1  rin 
    131  1.1  rin #undef	PUTCHAR_WIDTH1
    132  1.1  rin #undef	PUTCHAR_WIDTH
    133  1.1  rin 
    134  1.1  rin #undef	COPY_UNIT
    135  1.1  rin #undef	GET_GLYPH
    136