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