rasops32.c revision 1.22
1/* $NetBSD: rasops32.c,v 1.22 2011/12/27 06:24:40 macallan Exp $ */ 2 3/*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Andrew Doran. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33__KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.22 2011/12/27 06:24:40 macallan Exp $"); 34 35#include "opt_rasops.h" 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/time.h> 40 41#include <dev/wscons/wsdisplayvar.h> 42#include <dev/wscons/wsconsio.h> 43#include <dev/rasops/rasops.h> 44 45static void rasops32_putchar(void *, int, int, u_int, long attr); 46 47/* 48 * Initialize a 'rasops_info' descriptor for this depth. 49 */ 50void 51rasops32_init(struct rasops_info *ri) 52{ 53 54 if (ri->ri_rnum == 0) { 55 ri->ri_rnum = 8; 56 ri->ri_rpos = 0; 57 ri->ri_gnum = 8; 58 ri->ri_gpos = 8; 59 ri->ri_bnum = 8; 60 ri->ri_bpos = 16; 61 } 62 63 ri->ri_ops.putchar = rasops32_putchar; 64} 65 66/* 67 * Paint a single character. 68 */ 69static void 70rasops32_putchar(void *cookie, int row, int col, u_int uc, long attr) 71{ 72 int width, height, cnt, fs, fb, clr[2]; 73 struct rasops_info *ri = (struct rasops_info *)cookie; 74 struct wsdisplay_font *font = PICK_FONT(ri, uc); 75 int32_t *dp, *rp, *hp, *hrp; 76 u_char *fr; 77 78 hp = hrp = NULL; 79 80#ifdef RASOPS_CLIPPING 81 /* Catches 'row < 0' case too */ 82 if ((unsigned)row >= (unsigned)ri->ri_rows) 83 return; 84 85 if ((unsigned)col >= (unsigned)ri->ri_cols) 86 return; 87#endif 88 89 /* check if character fits into font limits */ 90 if (uc < font->firstchar || 91 (uc - font->firstchar) >= font->numchars) 92 return; 93 94 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale); 95 if (ri->ri_hwbits) 96 hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale + 97 col*ri->ri_xscale); 98 99 height = font->fontheight; 100 width = font->fontwidth; 101 102 clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf]; 103 clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf]; 104 105 if (uc == ' ') { 106 while (height--) { 107 dp = rp; 108 DELTA(rp, ri->ri_stride, int32_t *); 109 if (ri->ri_hwbits) { 110 hp = hrp; 111 DELTA(hrp, ri->ri_stride, int32_t *); 112 } 113 114 for (cnt = width; cnt; cnt--) { 115 *dp++ = clr[0]; 116 if (ri->ri_hwbits) 117 *hp++ = clr[0]; 118 } 119 } 120 } else { 121 uc -= font->firstchar; 122 fr = (u_char *)font->data + uc * ri->ri_fontscale; 123 fs = font->stride; 124 125 if (font->stride < width) { 126 /* this is a mono font */ 127 while (height--) { 128 dp = rp; 129 fb = fr[3] | (fr[2] << 8) | (fr[1] << 16) | 130 (fr[0] << 24); 131 fr += fs; 132 DELTA(rp, ri->ri_stride, int32_t *); 133 if (ri->ri_hwbits) { 134 hp = hrp; 135 DELTA(hrp, ri->ri_stride, int32_t *); 136 } 137 138 for (cnt = width; cnt; cnt--) { 139 *dp++ = clr[(fb >> 31) & 1]; 140 if (ri->ri_hwbits) 141 *hp++ = clr[(fb >> 31) & 1]; 142 fb <<= 1; 143 } 144 } 145 } else { 146 /* this is an alpha map */ 147 int x, y, r, g, b, aval; 148 int r1, g1, b1, r0, g0, b0; 149 150 r0 = (clr[0] >> 16) & 0xff; 151 r1 = (clr[1] >> 16) & 0xff; 152 g0 = (clr[0] >> 8) & 0xff; 153 g1 = (clr[1] >> 8) & 0xff; 154 b0 = clr[0] & 0xff; 155 b1 = clr[1] & 0xff; 156 157 for (y = 0; y < height; y++) { 158 dp = rp + ri->ri_width * y; 159 for (x = 0; x < width; x++) { 160 aval = *fr; 161 if (aval == 0) { 162 *dp = clr[0]; 163 } else if (aval == 255) { 164 *dp = clr[1]; 165 } else { 166 r = aval * r1 + 167 (255 - aval) * r0; 168 g = aval * g1 + 169 (255 - aval) * g0; 170 b = aval * b1 + 171 (255 - aval) * b0; 172 *dp = (r & 0xff00) << 8 | 173 (g & 0xff00) | 174 (b & 0xff00) >> 8; 175 } 176 dp++; 177 fr++; 178 } 179 } 180 } 181 } 182 183 /* Do underline */ 184 if ((attr & 1) != 0) { 185 DELTA(rp, -(ri->ri_stride << 1), int32_t *); 186 if (ri->ri_hwbits) 187 DELTA(hrp, -(ri->ri_stride << 1), int32_t *); 188 189 while (width--) { 190 *rp++ = clr[1]; 191 if (ri->ri_hwbits) 192 *hrp++ = clr[1]; 193 } 194 } 195} 196