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