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