Home | History | Annotate | Line # | Download | only in rasops
      1  1.15  rin /* $NetBSD: rasops_putchar_width.h,v 1.15 2019/08/14 00:51:10 rin Exp $ */
      2   1.1  rin 
      3   1.1  rin /* NetBSD: rasops8.c,v 1.41 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.7  rin #if RASOPS_DEPTH !=  2 && RASOPS_DEPTH !=  4 && RASOPS_DEPTH !=  8 &&	\
     34   1.7  rin     RASOPS_DEPTH != 15 && RASOPS_DEPTH != 24 && RASOPS_DEPTH != 32
     35   1.1  rin #error "Depth not supported"
     36   1.1  rin #endif
     37   1.1  rin 
     38   1.1  rin #if RASOPS_WIDTH != 8 && RASOPS_WIDTH != 12 && RASOPS_WIDTH != 16
     39   1.1  rin #error "Width not supported"
     40   1.1  rin #endif
     41   1.1  rin 
     42   1.7  rin #if   RASOPS_DEPTH == 2
     43   1.7  rin #define	STAMP_TYPE	uint8_t
     44   1.7  rin #elif RASOPS_DEPTH == 4
     45   1.7  rin #define	STAMP_TYPE	uint16_t
     46   1.7  rin #else
     47   1.7  rin #define	STAMP_TYPE	uint32_t
     48   1.7  rin #endif
     49   1.7  rin 
     50   1.7  rin #if   RASOPS_DEPTH <= 8
     51   1.9  rin #define	SUBST_UNIT	1
     52   1.9  rin #elif RASOPS_DEPTH == 15
     53   1.9  rin #define	SUBST_UNIT	2
     54   1.9  rin #elif RASOPS_DEPTH == 24
     55   1.9  rin #define	SUBST_UNIT	3
     56   1.9  rin #elif RASOPS_DEPTH == 32
     57   1.9  rin #define	SUBST_UNIT	4
     58   1.9  rin #endif
     59   1.9  rin 
     60   1.9  rin #define	SUBST_BYTES	(SUBST_UNIT * (RASOPS_WIDTH / 4) * sizeof(STAMP_TYPE))
     61   1.9  rin 
     62   1.9  rin #if   RASOPS_DEPTH <= 8
     63   1.7  rin #define	FILLED_STAMP	15
     64   1.7  rin #elif RASOPS_DEPTH == 15
     65   1.7  rin #define	FILLED_STAMP	30
     66   1.7  rin #else
     67   1.7  rin #define	FILLED_STAMP	60
     68   1.7  rin #endif
     69   1.7  rin 
     70   1.1  rin /* ################################################################### */
     71   1.1  rin 
     72   1.7  rin #if RASOPS_DEPTH <= 8
     73   1.1  rin 
     74   1.9  rin #define	SUBST_STAMP1(off, base)						\
     75   1.9  rin 	rp[(off) * 1 + 0] = stamp[base]
     76   1.1  rin 
     77   1.1  rin #define	SUBST_GLYPH1(index, nibble, off)				\
     78   1.1  rin 	do {								\
     79   1.6  rin 		int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
     80   1.1  rin 		rp[(off) * 1 + 0] = STAMP_READ(so);			\
     81   1.5  rin 	} while (0 /* CONSTCOND */)
     82   1.1  rin 
     83   1.7  rin #endif /* RASOPS_DEPTH <= 8 */
     84   1.1  rin 
     85   1.1  rin /* ################################################################### */
     86   1.1  rin 
     87   1.1  rin #if RASOPS_DEPTH == 15
     88   1.1  rin 
     89   1.9  rin #define	SUBST_STAMP1(off, base)						\
     90   1.9  rin 	rp[(off) * 2 + 0] = rp[(off) * 2 + 1] = stamp[base]
     91   1.1  rin 
     92   1.1  rin #define	SUBST_GLYPH1(index, nibble, off)				\
     93   1.1  rin 	do {								\
     94   1.6  rin 		int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
     95   1.1  rin 		rp[(off) * 2 + 0] = STAMP_READ(so);			\
     96   1.1  rin 		rp[(off) * 2 + 1] = STAMP_READ(so +  4);		\
     97   1.5  rin 	} while (0 /* CONSTCOND */)
     98   1.1  rin 
     99   1.1  rin #endif /* RASOPS_DEPTH == 15 */
    100   1.1  rin 
    101   1.1  rin /* ################################################################### */
    102   1.1  rin 
    103   1.1  rin #if RASOPS_DEPTH == 24
    104   1.1  rin 
    105   1.9  rin #define	SUBST_STAMP1(off, base)						\
    106   1.4  rin 	do {								\
    107   1.9  rin 		rp[(off) * 3 + 0] = stamp[(base) + 0];			\
    108   1.9  rin 		rp[(off) * 3 + 1] = stamp[(base) + 1];			\
    109   1.9  rin 		rp[(off) * 3 + 2] = stamp[(base) + 2];			\
    110   1.5  rin 	} while (0 /* CONSTCOND */)
    111   1.1  rin 
    112   1.1  rin #define	SUBST_GLYPH1(index, nibble, off)				\
    113   1.1  rin 	do {								\
    114   1.6  rin 		int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
    115   1.1  rin 		rp[(off) * 3 + 0] = STAMP_READ(so);			\
    116   1.1  rin 		rp[(off) * 3 + 1] = STAMP_READ(so +  4);		\
    117   1.1  rin 		rp[(off) * 3 + 2] = STAMP_READ(so +  8);		\
    118   1.5  rin 	} while (0 /* CONSTCOND */)
    119   1.1  rin 
    120   1.1  rin #endif /* RASOPS_DEPTH == 24 */
    121   1.1  rin 
    122   1.1  rin /* ################################################################### */
    123   1.1  rin 
    124   1.1  rin #if RASOPS_DEPTH == 32
    125   1.1  rin 
    126   1.9  rin #define	SUBST_STAMP1(off, base)						\
    127   1.9  rin 	rp[(off) * 4 + 0] = rp[(off) * 4 + 1] =				\
    128   1.9  rin 	rp[(off) * 4 + 2] = rp[(off) * 4 + 3] = stamp[base]
    129   1.1  rin 
    130   1.1  rin #define	SUBST_GLYPH1(index, nibble, off)				\
    131   1.1  rin 	do {								\
    132   1.6  rin 		int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
    133   1.1  rin 		rp[(off) * 4 + 0] = STAMP_READ(so);			\
    134   1.1  rin 		rp[(off) * 4 + 1] = STAMP_READ(so +  4);		\
    135   1.1  rin 		rp[(off) * 4 + 2] = STAMP_READ(so +  8);		\
    136   1.1  rin 		rp[(off) * 4 + 3] = STAMP_READ(so + 12);		\
    137   1.5  rin 	} while (0 /* CONSTCOND */)
    138   1.1  rin 
    139   1.1  rin #endif /* RASOPS_DEPTH == 32 */
    140   1.1  rin 
    141   1.1  rin /* ################################################################### */
    142   1.1  rin 
    143   1.4  rin #if   RASOPS_WIDTH == 8
    144   1.9  rin #define	SUBST_STAMP(base) 			\
    145   1.5  rin 	do {					\
    146   1.9  rin 		SUBST_STAMP1(0, base);		\
    147   1.9  rin 		SUBST_STAMP1(1, base);		\
    148   1.5  rin 	} while (0 /* CONSTCOND */)
    149   1.4  rin #elif RASOPS_WIDTH == 12
    150   1.9  rin #define	SUBST_STAMP(base)			\
    151   1.5  rin 	do {					\
    152   1.9  rin 		SUBST_STAMP1(0, base);		\
    153   1.9  rin 		SUBST_STAMP1(1, base);		\
    154   1.9  rin 		SUBST_STAMP1(2, base);		\
    155   1.5  rin 	} while (0 /* CONSTCOND */)
    156   1.4  rin #elif RASOPS_WIDTH == 16
    157   1.9  rin #define	SUBST_STAMP(base)			\
    158   1.5  rin 	do {					\
    159   1.9  rin 		SUBST_STAMP1(0, base);		\
    160   1.9  rin 		SUBST_STAMP1(1, base);		\
    161   1.9  rin 		SUBST_STAMP1(2, base);		\
    162   1.9  rin 		SUBST_STAMP1(3, base);		\
    163   1.5  rin 	} while (0 /* CONSTCOND */)
    164   1.4  rin #endif
    165   1.1  rin 
    166  1.14  rin /* ################################################################### */
    167  1.14  rin 
    168   1.1  rin #if   RASOPS_WIDTH == 8
    169   1.5  rin #define	SUBST_GLYPH				\
    170   1.5  rin 	do {					\
    171   1.5  rin 		SUBST_GLYPH1(0, 1, 0);		\
    172   1.5  rin 		SUBST_GLYPH1(0, 0, 1);		\
    173   1.5  rin 	} while (0 /* CONSTCOND */)
    174   1.1  rin #elif RASOPS_WIDTH == 12
    175   1.5  rin #define	SUBST_GLYPH				\
    176   1.5  rin 	do {					\
    177   1.5  rin 		SUBST_GLYPH1(0, 1, 0);		\
    178   1.5  rin 		SUBST_GLYPH1(0, 0, 1);		\
    179   1.5  rin 		SUBST_GLYPH1(1, 1, 2);		\
    180   1.5  rin 	} while (0 /* CONSTCOND */)
    181   1.1  rin #elif RASOPS_WIDTH == 16
    182   1.5  rin #define	SUBST_GLYPH				\
    183   1.5  rin 	do {					\
    184   1.5  rin 		SUBST_GLYPH1(0, 1, 0);		\
    185   1.5  rin 		SUBST_GLYPH1(0, 0, 1);		\
    186   1.5  rin 		SUBST_GLYPH1(1, 1, 2);		\
    187   1.5  rin 		SUBST_GLYPH1(1, 0, 3);		\
    188   1.5  rin 	} while (0 /* CONSTCOND */)
    189   1.1  rin #endif
    190   1.1  rin 
    191  1.14  rin /* ################################################################### */
    192  1.14  rin 
    193  1.14  rin #define	NAME(depth, width)	NAME1(depth, width)
    194  1.14  rin #define	NAME1(depth, width)	rasops ## depth ## _putchar ## width
    195  1.14  rin 
    196  1.14  rin #define	PUTCHAR(depth)		PUTCHAR1(depth)
    197  1.14  rin #define	PUTCHAR1(depth)		rasops ## depth ## _putchar
    198  1.14  rin 
    199  1.14  rin #define	MAKESTAMP(depth)	MAKESTAMP1(depth)
    200  1.14  rin #define	MAKESTAMP1(depth)	rasops ## depth ## _makestamp
    201  1.14  rin 
    202   1.1  rin /*
    203   1.1  rin  * Width-optimized putchar function.
    204   1.1  rin  */
    205   1.1  rin static void
    206  1.14  rin NAME(RASOPS_DEPTH, RASOPS_WIDTH)(void *cookie, int row, int col, u_int uc,
    207  1.14  rin     long attr)
    208   1.1  rin {
    209   1.1  rin 	struct rasops_info *ri = (struct rasops_info *)cookie;
    210   1.1  rin 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    211  1.14  rin 	int height;
    212  1.10  rin 	uint8_t *fr;
    213  1.15  rin 	bool do_ul;
    214   1.9  rin 	STAMP_TYPE *rp, *hp;
    215   1.1  rin 
    216   1.9  rin 	hp = NULL; /* XXX GCC */
    217   1.1  rin 
    218  1.14  rin 	/* check if character fits into font limits */
    219  1.14  rin 	if (__predict_false(!CHAR_IN_FONT(uc, font)))
    220  1.14  rin 		return;
    221  1.14  rin 
    222   1.1  rin #ifdef RASOPS_CLIPPING
    223   1.1  rin 	/* Catches 'row < 0' case too */
    224   1.1  rin 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    225   1.1  rin 		return;
    226   1.1  rin 
    227   1.1  rin 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    228   1.1  rin 		return;
    229   1.1  rin #endif
    230   1.1  rin 
    231  1.15  rin 	/*
    232  1.15  rin 	 * We don't care attributions other than back/foreground
    233  1.15  rin 	 * colors when using stamp.
    234  1.15  rin 	 */
    235  1.15  rin 	do_ul = (attr & WSATTR_UNDERLINE) != 0;
    236  1.15  rin 	attr &= (ATTR_MASK_BG | ATTR_MASK_FG);
    237  1.15  rin 
    238   1.1  rin 	/* Recompute stamp? */
    239  1.11  rin 	if (attr != stamp_attr || __predict_false(ri != stamp_ri))
    240   1.1  rin 		MAKESTAMP(RASOPS_DEPTH)(ri, attr);
    241   1.1  rin 
    242  1.14  rin 	height = font->fontheight;
    243  1.14  rin 
    244  1.14  rin 	rp = (STAMP_TYPE *)(ri->ri_bits + FBOFFSET(ri, row, col));
    245   1.1  rin 	if (ri->ri_hwbits)
    246  1.14  rin 		hp = (STAMP_TYPE *)(ri->ri_hwbits + FBOFFSET(ri, row, col));
    247   1.1  rin 
    248   1.1  rin 	if (uc == ' ') {
    249   1.1  rin 		while (height--) {
    250   1.9  rin 			SUBST_STAMP(0);
    251   1.8  rin 			if (ri->ri_hwbits) {
    252   1.9  rin 				memcpy(hp, rp, SUBST_BYTES);
    253   1.9  rin 				DELTA(hp, ri->ri_stride, STAMP_TYPE *);
    254   1.1  rin 			}
    255   1.9  rin 			DELTA(rp, ri->ri_stride, STAMP_TYPE *);
    256   1.1  rin 		}
    257   1.4  rin 	} else {
    258   1.1  rin 		fr = FONT_GLYPH(uc, font, ri);
    259   1.1  rin 		while (height--) {
    260   1.4  rin 			SUBST_GLYPH;
    261  1.14  rin 			fr += font->stride;
    262   1.9  rin 			if (ri->ri_hwbits) {
    263   1.9  rin 				memcpy(hp, rp, SUBST_BYTES);
    264   1.9  rin 				DELTA(hp, ri->ri_stride, STAMP_TYPE *);
    265   1.9  rin 			}
    266   1.7  rin 			DELTA(rp, ri->ri_stride, STAMP_TYPE *);
    267   1.1  rin 		}
    268   1.1  rin 	}
    269   1.1  rin 
    270   1.1  rin 	/* Do underline */
    271  1.15  rin 	if (do_ul) {
    272  1.12  rin 		DELTA(rp, - ri->ri_stride * ri->ri_ul.off, STAMP_TYPE *);
    273  1.12  rin 		if (ri->ri_hwbits)
    274  1.12  rin 			DELTA(hp, - ri->ri_stride * ri->ri_ul.off,
    275  1.12  rin 			    STAMP_TYPE *);
    276  1.14  rin 
    277  1.12  rin 		for (height = ri->ri_ul.height; height; height--) {
    278  1.12  rin 			DELTA(rp, - ri->ri_stride, STAMP_TYPE *);
    279  1.12  rin 			SUBST_STAMP(FILLED_STAMP);
    280  1.12  rin 			if (ri->ri_hwbits) {
    281  1.12  rin 				DELTA(hp, - ri->ri_stride, STAMP_TYPE *);
    282  1.12  rin 				memcpy(hp, rp, SUBST_BYTES);
    283  1.12  rin 			}
    284   1.4  rin 		}
    285   1.1  rin 	}
    286   1.1  rin }
    287   1.1  rin 
    288   1.7  rin #undef	STAMP_TYPE
    289   1.7  rin 
    290   1.9  rin #undef	SUBST_UNIT
    291   1.9  rin #undef	SUBST_BYTES
    292   1.9  rin 
    293   1.1  rin #undef	FILLED_STAMP
    294   1.1  rin 
    295   1.1  rin #undef	SUBST_STAMP1
    296   1.1  rin #undef	SUBST_STAMP
    297   1.1  rin 
    298   1.1  rin #undef	SUBST_GLYPH1
    299   1.1  rin #undef	SUBST_GLYPH
    300  1.14  rin 
    301  1.14  rin #undef	NAME
    302  1.14  rin #undef	NAME1
    303  1.14  rin 
    304  1.14  rin #undef	PUTCHAR
    305  1.14  rin #undef	PUTCHAR1
    306  1.14  rin 
    307  1.14  rin #undef	MAKESTAMP
    308  1.14  rin #undef	MAKESTAMP1
    309