Home | History | Annotate | Line # | Download | only in rasops
rasops_bitops.h revision 1.2
      1 /* 	$NetBSD: rasops_bitops.h,v 1.2 1999/04/29 03:38:39 ad Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1999 Andy Doran <ad (at) NetBSD.org>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  *
     28  */
     29 
     30 #ifndef _RASOPS_BITOPS_H_
     31 #define _RASOPS_BITOPS_H_ 1
     32 
     33 /*
     34  * Erase columns.
     35  */
     36 static void
     37 NAME(erasecols)(cookie, row, col, num, attr)
     38 	void *cookie;
     39 	int row, col, num;
     40 	long attr;
     41 {
     42 	int32_t *dp, *rp, lmask, rmask, lclr, rclr, clr;
     43 	struct rasops_info *ri;
     44 	int height, cnt;
     45 
     46 	ri = (struct rasops_info *)cookie;
     47 
     48 #ifdef RASOPS_CLIPPING
     49 	if ((unsigned)row >= (unsigned)ri->ri_rows)
     50 		return;
     51 
     52 	if (col < 0) {
     53 		num += col;
     54 		col = 0;
     55 	}
     56 
     57 	if ((col + num) > ri->ri_cols)
     58 		num = ri->ri_cols - col;
     59 
     60 	if (num <= 0)
     61 		return;
     62 #endif
     63 	col *= ri->ri_font->fontwidth << PIXEL_SHIFT;
     64 	num *= ri->ri_font->fontwidth << PIXEL_SHIFT;
     65 	height = ri->ri_font->fontheight;
     66 	clr = ri->ri_devcmap[(attr >> 16) & 15];
     67 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3));
     68 
     69 	if ((col & 31) + num <= 32) {
     70 		lmask = ~rasops_pmask[col & 31][num];
     71 		lclr = clr & ~lmask;
     72 
     73 		while (height--) {
     74 			dp = rp;
     75 			DELTA(rp, ri->ri_stride, int32_t *);
     76 
     77 			*dp = (*dp & lmask) | lclr;
     78 		}
     79 	} else {
     80 		lmask = rasops_rmask[col & 31];
     81 		rmask = rasops_lmask[(col + num) & 31];
     82 
     83 		if (lmask)
     84 			num = (num - (32 - (col & 31))) >> 5;
     85 		else
     86 			num = num >> 5;
     87 
     88 		lclr = clr & ~lmask;
     89 		rclr = clr & ~rmask;
     90 
     91 		while (height--) {
     92 			dp = rp;
     93 			DELTA(rp, ri->ri_stride, int32_t *);
     94 
     95 			if (lmask)
     96 				*dp++ = (*dp & lmask) | lclr;
     97 
     98 			for (cnt = num; cnt > 0; cnt--)
     99 				*dp++ = clr;
    100 
    101 			if (rmask)
    102 				*dp = (*dp & rmask) | rclr;
    103 		}
    104 	}
    105 }
    106 
    107 
    108 /*
    109  * Actually paint the cursor.
    110  */
    111 static void
    112 NAME(do_cursor)(ri)
    113 	struct rasops_info *ri;
    114 {
    115 	int32_t *dp, *rp, lmask, rmask;
    116 	int height, row, col, num;
    117 
    118 	row = ri->ri_crow;
    119 	col = ri->ri_ccol * ri->ri_font->fontwidth << PIXEL_SHIFT;
    120 	height = ri->ri_font->fontheight;
    121 	num = ri->ri_font->fontwidth << PIXEL_SHIFT;
    122 	rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
    123 
    124 	if ((col & 31) + num <= 32) {
    125 		lmask = rasops_pmask[col & 31][num];
    126 
    127 		while (height--) {
    128 			dp = rp;
    129 			DELTA(rp, ri->ri_stride, int32_t *);
    130 			*dp ^= lmask;
    131 		}
    132 	} else {
    133 		lmask = ~rasops_rmask[col & 31];
    134 		rmask = ~rasops_lmask[(col + num) & 31];
    135 
    136 		while (height--) {
    137 			dp = rp;
    138 			DELTA(rp, ri->ri_stride, int32_t *);
    139 
    140 			if (lmask != -1)
    141 				*dp++ ^= lmask;
    142 
    143 			if (rmask != -1)
    144 				*dp ^= rmask;
    145 		}
    146 	}
    147 }
    148 
    149 
    150 /*
    151  * Copy columns. This is slow. Ick!
    152  */
    153 static void
    154 NAME(copycols)(cookie, row, src, dst, num)
    155 	void *cookie;
    156 	int row, src, dst, num;
    157 {
    158 	int32_t *sp, *dp, *srp, *drp, tmp, lmask, rmask;
    159 	int height, lnum, rnum, sb, db, cnt, full;
    160 	struct rasops_info *ri;
    161 
    162 	ri = (struct rasops_info *)cookie;
    163 
    164 #ifdef RASOPS_CLIPPING
    165 	if (dst == src)
    166 		return;
    167 
    168 	/* Catches < 0 case too */
    169 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    170 		return;
    171 
    172 	if (src < 0) {
    173 		num += src;
    174 		src = 0;
    175 	}
    176 
    177 	if ((src + num) > ri->ri_cols)
    178 		num = ri->ri_cols - src;
    179 
    180 	if (dst < 0) {
    181 		num += dst;
    182 		dst = 0;
    183 	}
    184 
    185 	if ((dst + num) > ri->ri_cols)
    186 		num = ri->ri_cols - dst;
    187 
    188 	if (num <= 0)
    189 		return;
    190 #endif
    191 
    192 	/* XXX pacify gcc until this is fixed XXX */
    193 	db = 0;
    194 
    195 	cnt = ri->ri_font->fontwidth << PIXEL_SHIFT;
    196 	src *= cnt;
    197 	dst *= cnt;
    198 	num *= cnt;
    199 	row *= ri->ri_yscale;
    200 	height = ri->ri_font->fontheight;
    201 
    202 	if (db + num <= 32) {
    203 		srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
    204 		drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
    205 		sb = src & 31;
    206 		db = dst & 31;
    207 
    208 		while (height--) {
    209 			GETBITS(srp, sb, num, tmp);
    210 			PUTBITS(tmp, db, num, drp);
    211 			DELTA(srp, ri->ri_stride, int32_t *);
    212 			DELTA(drp, ri->ri_stride, int32_t *);
    213 		}
    214 
    215 		return;
    216 	}
    217 
    218 	lmask = rasops_rmask[dst & 31];
    219 	rmask = rasops_lmask[(dst + num) & 31];
    220 
    221 	lnum = (lmask ? 32 - db : 0);
    222 	rnum = (rmask ? (dst + num) & 31 : 0);
    223 	sb = src < dst && src + num > dst;
    224 
    225 	if (lmask)
    226 		full = (num - (32 - (dst & 31))) >> 5;
    227 	else
    228 		full = num >> 5;
    229 
    230 	if (sb) {
    231 		/* Go backwards */
    232 		/* XXX this is broken! */
    233 		src = src + num;
    234 		dst = dst + num;
    235 		srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
    236 		drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
    237 
    238 		src = src & 31;
    239 		db = dst & 31;
    240 
    241 		while (height--) {
    242 			sb = src;
    243 			sp = srp;
    244 			dp = drp;
    245 			DELTA(srp, ri->ri_stride, int32_t *);
    246 			DELTA(drp, ri->ri_stride, int32_t *);
    247 
    248 			if (db) {
    249 				GETBITS(sp, sb, db, tmp);
    250 				PUTBITS(tmp, db, db, dp);
    251 				dp--;
    252 				if ((sb -= rnum) < 0) {
    253 					sp--;
    254 					sb += 32;
    255 				}
    256 			}
    257 
    258 			/* Now we're aligned to 32-bits with dp :) */
    259 			for (cnt = full; cnt; cnt--, sp--) {
    260 				GETBITS(sp, sb, 32, tmp);
    261 				*dp-- = tmp;
    262 			}
    263 
    264 			if (lmask) {
    265 				GETBITS(sp, sb, rnum, tmp);
    266 				PUTBITS(tmp, 0, rnum, dp);
    267  			}
    268  		}
    269 	} else {
    270 		srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
    271 		drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
    272 		db = dst & 31;
    273 
    274 		while (height--) {
    275 			sb = src & 31;
    276 			sp = srp;
    277 			dp = drp;
    278 			DELTA(srp, ri->ri_stride, int32_t *);
    279 			DELTA(drp, ri->ri_stride, int32_t *);
    280 
    281 			if (lmask) {
    282 				GETBITS(sp, sb, lnum, tmp);
    283 				PUTBITS(tmp, db, lnum, dp);
    284 				dp++;
    285 
    286 				if ((sb += lnum) > 31) {
    287 					sp++;
    288 					sb -= 32;
    289 				}
    290 			}
    291 
    292 			/* Now we're aligned to 32-bits with dp :) */
    293 			for (cnt = full; cnt; cnt--) {
    294 				GETBITS(sp, sb, 32, tmp);
    295 				*dp++ = tmp;
    296 				sp++;
    297 			}
    298 
    299 			if (rmask) {
    300 				GETBITS(sp, sb, rnum, tmp);
    301 				PUTBITS(tmp, 0, rnum, dp);
    302  			}
    303  		}
    304  	}
    305 }
    306 
    307 #endif /* _RASOPS_BITOPS_H_ */
    308