1 /* $OpenBSD: rasops_bitops.h,v 1.5 2009/09/05 14:09:35 miod 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 int 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 0; 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 0; 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 return 0; 113 } 114 115 /* 116 * Actually paint the cursor. 117 */ 118 int 119 NAME(do_cursor)(ri) 120 struct rasops_info *ri; 121 { 122 int lmask, rmask, height, row, col, num; 123 int32_t *dp, *rp; 124 125 row = ri->ri_crow; 126 col = ri->ri_ccol * ri->ri_font->fontwidth << PIXEL_SHIFT; 127 height = ri->ri_font->fontheight; 128 num = ri->ri_font->fontwidth << PIXEL_SHIFT; 129 rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3)); 130 131 if ((col & 31) + num <= 32) { 132 lmask = rasops_pmask[col & 31][num]; 133 134 while (height--) { 135 dp = rp; 136 DELTA(rp, ri->ri_stride, int32_t *); 137 *dp ^= lmask; 138 } 139 } else { 140 lmask = ~rasops_rmask[col & 31]; 141 rmask = ~rasops_lmask[(col + num) & 31]; 142 143 while (height--) { 144 dp = rp; 145 DELTA(rp, ri->ri_stride, int32_t *); 146 147 if (lmask != -1) 148 *dp++ ^= lmask; 149 150 if (rmask != -1) 151 *dp ^= rmask; 152 } 153 } 154 155 return 0; 156 } 157 158 /* 159 * Copy columns. Ick! 160 */ 161 int 162 NAME(copycols)(cookie, row, src, dst, num) 163 void *cookie; 164 int row, src, dst, num; 165 { 166 int tmp, lmask, rmask, height, lnum, rnum, sb, db, cnt, full; 167 int32_t *sp, *dp, *srp, *drp; 168 struct rasops_info *ri; 169 170 ri = (struct rasops_info *)cookie; 171 172 #ifdef RASOPS_CLIPPING 173 if (dst == src) 174 return 0; 175 176 /* Catches < 0 case too */ 177 if ((unsigned)row >= (unsigned)ri->ri_rows) 178 return 0; 179 180 if (src < 0) { 181 num += src; 182 src = 0; 183 } 184 185 if ((src + num) > ri->ri_cols) 186 num = ri->ri_cols - src; 187 188 if (dst < 0) { 189 num += dst; 190 dst = 0; 191 } 192 193 if ((dst + num) > ri->ri_cols) 194 num = ri->ri_cols - dst; 195 196 if (num <= 0) 197 return 0; 198 #endif 199 200 cnt = ri->ri_font->fontwidth << PIXEL_SHIFT; 201 src *= cnt; 202 dst *= cnt; 203 num *= cnt; 204 row *= ri->ri_yscale; 205 height = ri->ri_font->fontheight; 206 db = dst & 31; 207 208 if (db + num <= 32) { 209 /* Destination is contained within a single word */ 210 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3)); 211 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3)); 212 sb = src & 31; 213 214 while (height--) { 215 GETBITS(srp, sb, num, tmp); 216 PUTBITS(tmp, db, num, drp); 217 DELTA(srp, ri->ri_stride, int32_t *); 218 DELTA(drp, ri->ri_stride, int32_t *); 219 } 220 221 return 0; 222 } 223 224 lmask = rasops_rmask[db]; 225 rmask = rasops_lmask[(dst + num) & 31]; 226 lnum = (32 - db) & 31; 227 rnum = (dst + num) & 31; 228 229 if (lmask) 230 full = (num - (32 - (dst & 31))) >> 5; 231 else 232 full = num >> 5; 233 234 if (src < dst && src + num > dst) { 235 /* Copy right-to-left */ 236 sb = src & 31; 237 src = src + num; 238 dst = dst + num; 239 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3)); 240 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3)); 241 242 src = src & 31; 243 rnum = 32 - lnum; 244 db = dst & 31; 245 246 if ((src -= db) < 0) { 247 sp--; 248 src += 32; 249 } 250 251 while (height--) { 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, src, db, tmp); 259 PUTBITS(tmp, 0, db, dp); 260 dp--; 261 sp--; 262 } 263 264 /* Now aligned to 32-bits wrt dp */ 265 for (cnt = full; cnt; cnt--, sp--) { 266 GETBITS(sp, src, 32, tmp); 267 *dp-- = tmp; 268 } 269 270 if (lmask) { 271 #if 0 272 if (src > sb) 273 sp++; 274 #endif 275 GETBITS(sp, sb, lnum, tmp); 276 PUTBITS(tmp, rnum, lnum, dp); 277 } 278 } 279 } else { 280 /* Copy left-to-right */ 281 srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3)); 282 drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3)); 283 db = dst & 31; 284 285 while (height--) { 286 sb = src & 31; 287 sp = srp; 288 dp = drp; 289 DELTA(srp, ri->ri_stride, int32_t *); 290 DELTA(drp, ri->ri_stride, int32_t *); 291 292 if (lmask) { 293 GETBITS(sp, sb, lnum, tmp); 294 PUTBITS(tmp, db, lnum, dp); 295 dp++; 296 297 if ((sb += lnum) > 31) { 298 sp++; 299 sb -= 32; 300 } 301 } 302 303 /* Now aligned to 32-bits wrt dp */ 304 for (cnt = full; cnt; cnt--, sp++) { 305 GETBITS(sp, sb, 32, tmp); 306 *dp++ = tmp; 307 } 308 309 if (rmask) { 310 GETBITS(sp, sb, rnum, tmp); 311 PUTBITS(tmp, 0, rnum, dp); 312 } 313 } 314 } 315 316 return 0; 317 } 318 319 #endif /* _RASOPS_BITOPS_H_ */ 320