1 /* $NetBSD: rasops_bitops.h,v 1.8 2002/05/31 19:42:12 thorpej 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 * 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 int lmask, rmask, lclr, rclr, clr; 52 struct rasops_info *ri; 53 int32_t *dp, *rp; 54 int height, cnt; 55 56 ri = (struct rasops_info *)cookie; 57 58 #ifdef RASOPS_CLIPPING 59 if ((unsigned)row >= (unsigned)ri->ri_rows) 60 return; 61 62 if (col < 0) { 63 num += col; 64 col = 0; 65 } 66 67 if ((col + num) > ri->ri_cols) 68 num = ri->ri_cols - col; 69 70 if (num <= 0) 71 return; 72 #endif 73 col *= ri->ri_font->fontwidth << PIXEL_SHIFT; 74 num *= ri->ri_font->fontwidth << PIXEL_SHIFT; 75 height = ri->ri_font->fontheight; 76 clr = ri->ri_devcmap[(attr >> 16) & 0xf]; 77 rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3)); 78 79 if ((col & 31) + num <= 32) { 80 lmask = ~rasops_pmask[col & 31][num]; 81 lclr = clr & ~lmask; 82 83 while (height--) { 84 dp = rp; 85 DELTA(rp, ri->ri_stride, int32_t *); 86 87 *dp = (*dp & lmask) | lclr; 88 } 89 } else { 90 lmask = rasops_rmask[col & 31]; 91 rmask = rasops_lmask[(col + num) & 31]; 92 93 if (lmask) 94 num = (num - (32 - (col & 31))) >> 5; 95 else 96 num = num >> 5; 97 98 lclr = clr & ~lmask; 99 rclr = clr & ~rmask; 100 101 while (height--) { 102 dp = rp; 103 DELTA(rp, ri->ri_stride, int32_t *); 104 105 if (lmask) { 106 *dp = (*dp & lmask) | lclr; 107 dp++; 108 } 109 110 for (cnt = num; cnt > 0; cnt--) 111 *dp++ = clr; 112 113 if (rmask) 114 *dp = (*dp & rmask) | rclr; 115 } 116 } 117 } 118 119 /* 120 * Actually paint the cursor. 121 */ 122 static void 123 NAME(do_cursor)(ri) 124 struct rasops_info *ri; 125 { 126 int lmask, rmask, height, row, col, num; 127 int32_t *dp, *rp; 128 129 row = ri->ri_crow; 130 col = ri->ri_ccol * ri->ri_font->fontwidth << PIXEL_SHIFT; 131 height = ri->ri_font->fontheight; 132 num = ri->ri_font->fontwidth << PIXEL_SHIFT; 133 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3)); 134 135 if ((col & 31) + num <= 32) { 136 lmask = rasops_pmask[col & 31][num]; 137 138 while (height--) { 139 dp = rp; 140 DELTA(rp, ri->ri_stride, int32_t *); 141 *dp ^= lmask; 142 } 143 } else { 144 lmask = ~rasops_rmask[col & 31]; 145 rmask = ~rasops_lmask[(col + num) & 31]; 146 147 while (height--) { 148 dp = rp; 149 DELTA(rp, ri->ri_stride, int32_t *); 150 151 if (lmask != -1) 152 *dp++ ^= lmask; 153 154 if (rmask != -1) 155 *dp ^= rmask; 156 } 157 } 158 } 159 160 /* 161 * Copy columns. Ick! 162 */ 163 static void 164 NAME(copycols)(cookie, row, src, dst, num) 165 void *cookie; 166 int row, src, dst, num; 167 { 168 int tmp, lmask, rmask, height, lnum, rnum, sb, db, cnt, full; 169 int32_t *sp, *dp, *srp, *drp; 170 struct rasops_info *ri; 171 172 ri = (struct rasops_info *)cookie; 173 174 #ifdef RASOPS_CLIPPING 175 if (dst == src) 176 return; 177 178 /* Catches < 0 case too */ 179 if ((unsigned)row >= (unsigned)ri->ri_rows) 180 return; 181 182 if (src < 0) { 183 num += src; 184 src = 0; 185 } 186 187 if ((src + num) > ri->ri_cols) 188 num = ri->ri_cols - src; 189 190 if (dst < 0) { 191 num += dst; 192 dst = 0; 193 } 194 195 if ((dst + num) > ri->ri_cols) 196 num = ri->ri_cols - dst; 197 198 if (num <= 0) 199 return; 200 #endif 201 202 cnt = ri->ri_font->fontwidth << PIXEL_SHIFT; 203 src *= cnt; 204 dst *= cnt; 205 num *= cnt; 206 row *= ri->ri_yscale; 207 height = ri->ri_font->fontheight; 208 db = dst & 31; 209 210 if (db + num <= 32) { 211 /* Destination is contained within a single word */ 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 216 while (height--) { 217 GETBITS(srp, sb, num, tmp); 218 PUTBITS(tmp, db, num, drp); 219 DELTA(srp, ri->ri_stride, int32_t *); 220 DELTA(drp, ri->ri_stride, int32_t *); 221 } 222 223 return; 224 } 225 226 lmask = rasops_rmask[db]; 227 rmask = rasops_lmask[(dst + num) & 31]; 228 lnum = (32 - db) & 31; 229 rnum = (dst + num) & 31; 230 231 if (lmask) 232 full = (num - (32 - (dst & 31))) >> 5; 233 else 234 full = num >> 5; 235 236 if (src < dst && src + num > dst) { 237 /* Copy right-to-left */ 238 sb = src & 31; 239 src = src + num; 240 dst = dst + num; 241 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3)); 242 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3)); 243 244 src = src & 31; 245 rnum = 32 - lnum; 246 db = dst & 31; 247 248 if ((src -= db) < 0) { 249 sp--; 250 src += 32; 251 } 252 253 while (height--) { 254 sp = srp; 255 dp = drp; 256 DELTA(srp, ri->ri_stride, int32_t *); 257 DELTA(drp, ri->ri_stride, int32_t *); 258 259 if (db) { 260 GETBITS(sp, src, db, tmp); 261 PUTBITS(tmp, 0, db, dp); 262 dp--; 263 sp--; 264 } 265 266 /* Now aligned to 32-bits wrt dp */ 267 for (cnt = full; cnt; cnt--, sp--) { 268 GETBITS(sp, src, 32, tmp); 269 *dp-- = tmp; 270 } 271 272 if (lmask) { 273 #if 0 274 if (src > sb) 275 sp++; 276 #endif 277 GETBITS(sp, sb, lnum, tmp); 278 PUTBITS(tmp, rnum, lnum, dp); 279 } 280 } 281 } else { 282 /* Copy left-to-right */ 283 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3)); 284 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3)); 285 db = dst & 31; 286 287 while (height--) { 288 sb = src & 31; 289 sp = srp; 290 dp = drp; 291 DELTA(srp, ri->ri_stride, int32_t *); 292 DELTA(drp, ri->ri_stride, int32_t *); 293 294 if (lmask) { 295 GETBITS(sp, sb, lnum, tmp); 296 PUTBITS(tmp, db, lnum, dp); 297 dp++; 298 299 if ((sb += lnum) > 31) { 300 sp++; 301 sb -= 32; 302 } 303 } 304 305 /* Now aligned to 32-bits wrt dp */ 306 for (cnt = full; cnt; cnt--, sp++) { 307 GETBITS(sp, sb, 32, tmp); 308 *dp++ = tmp; 309 } 310 311 if (rmask) { 312 GETBITS(sp, sb, rnum, tmp); 313 PUTBITS(tmp, 0, rnum, dp); 314 } 315 } 316 } 317 } 318 319 #endif /* _RASOPS_BITOPS_H_ */ 320