|
|
1.1 ! root 1: /* $Header: spixline.h,v 10.1 86/11/19 10:46:29 jg Exp $ */ ! 2: /* spixline.h - macros used by the single pixel wide line drawing routine ! 3: * SinglePixelLine() ! 4: * ! 5: * Author: ! 6: * Scott Bates ! 7: * Brown University ! 8: * IRIS, Box 1946 ! 9: * Providence, RI 02912 ! 10: * ! 11: * ! 12: * Copyright (c) 1986 Brown University ! 13: * ! 14: * Permission to use, copy, modify and distribute this software and its ! 15: * documentation for any purpose and without fee is hereby granted, provided ! 16: * that the above copyright notice appear in all copies, and that both ! 17: * that copyright notice and this permission notice appear in supporting ! 18: * documentation, and that the name of Brown University not be used in ! 19: * advertising or publicity pertaining to distribution of the software ! 20: * without specific, written prior permission. Brown University makes no ! 21: * representations about the suitability of this software for any purpose. ! 22: * It is provided "as-is" without express or implied warranty. ! 23: */ ! 24: ! 25: #if (defined(APA8) || defined(APA8C)) ! 26: /* ! 27: * Macro for incrementing destination address ! 28: */ ! 29: ! 30: #define DESTINATION \ ! 31: Destination = (u_short *) ((long)Destination + DestinationIncrement) ! 32: #else ! 33: #define DESTINATION Destination++ ! 34: #endif (APA8 || APA8C) ! 35: ! 36: /* ! 37: * Macro used to advanced to the next scan line or row of the ! 38: * destination bitmap ! 39: */ ! 40: ! 41: #define NEXT_ROW \ ! 42: Destination = (u_short *) ((long)Destination + NumberOfBytes) ! 43: ! 44: /* ! 45: * Macro that draws horizontal solid, dashed and patterned lines ! 46: */ ! 47: ! 48: #define HORIZONTAL_LINE(Rule1, Rule2) { \ ! 49: switch (Mode) { \ ! 50: case (DrawSolidLine): \ ! 51: while (BitsLeftToDraw--) { \ ! 52: Rule1 \ ! 53: if ((MaskBit >>= 1) == 0) { \ ! 54: MaskBit = 0x8000; \ ! 55: DESTINATION; \ ! 56: } \ ! 57: if ((Sentinel -= DeltaY) < 0) { \ ! 58: NEXT_ROW; \ ! 59: Sentinel += DeltaX; \ ! 60: } \ ! 61: } \ ! 62: Rule1 \ ! 63: break; \ ! 64: case (DrawDashedLine): \ ! 65: while (BitsLeftToDraw--) { \ ! 66: if(Pattern & PatternBit) \ ! 67: Rule1 \ ! 68: if(--RepeatCount == 0) { \ ! 69: RepeatCount = PatternMultiplier; \ ! 70: if((PatternBit >>= 1) == 0) \ ! 71: PatternBit = PatternFirstBit; \ ! 72: } \ ! 73: if ((MaskBit >>= 1) == 0) { \ ! 74: MaskBit = 0x8000; \ ! 75: DESTINATION; \ ! 76: } \ ! 77: if ((Sentinel -= DeltaY) < 0) { \ ! 78: NEXT_ROW; \ ! 79: Sentinel += DeltaX; \ ! 80: } \ ! 81: } \ ! 82: if(Pattern & PatternBit) \ ! 83: Rule1 \ ! 84: break; \ ! 85: case (DrawPatternedLine): \ ! 86: while (BitsLeftToDraw--) { \ ! 87: if(Pattern & PatternBit) \ ! 88: Rule1 \ ! 89: else \ ! 90: Rule2 \ ! 91: if(--RepeatCount == 0) { \ ! 92: RepeatCount = PatternMultiplier; \ ! 93: if((PatternBit >>= 1) == 0) \ ! 94: PatternBit = PatternFirstBit; \ ! 95: } \ ! 96: if ((MaskBit >>= 1) == 0) { \ ! 97: MaskBit = 0x8000; \ ! 98: DESTINATION; \ ! 99: } \ ! 100: if ((Sentinel -= DeltaY) < 0) { \ ! 101: NEXT_ROW; \ ! 102: Sentinel += DeltaX; \ ! 103: } \ ! 104: } \ ! 105: if(Pattern & PatternBit) \ ! 106: Rule1 \ ! 107: else \ ! 108: Rule2 \ ! 109: } \ ! 110: } ! 111: ! 112: /* ! 113: * Macro that draws vertical solid, dashed and patterned lines ! 114: */ ! 115: ! 116: #define VERTICAL_LINE(Rule1, Rule2) { \ ! 117: switch (Mode) { \ ! 118: case (DrawSolidLine): \ ! 119: while (BitsLeftToDraw--) { \ ! 120: Rule1 \ ! 121: NEXT_ROW; \ ! 122: if ((Sentinel -= DeltaX) < 0) { \ ! 123: if ((MaskBit >>= 1) == 0) { \ ! 124: MaskBit = 0x8000; \ ! 125: DESTINATION; \ ! 126: } \ ! 127: Sentinel += DeltaY; \ ! 128: } \ ! 129: } \ ! 130: Rule1 \ ! 131: break; \ ! 132: case (DrawDashedLine): \ ! 133: while (BitsLeftToDraw--) { \ ! 134: if(Pattern & PatternBit) \ ! 135: Rule1 \ ! 136: if(--RepeatCount == 0) { \ ! 137: RepeatCount = PatternMultiplier; \ ! 138: if((PatternBit >>= 1) == 0) \ ! 139: PatternBit = PatternFirstBit; \ ! 140: } \ ! 141: NEXT_ROW; \ ! 142: if ((Sentinel -= DeltaX) < 0) { \ ! 143: if ((MaskBit >>= 1) == 0) { \ ! 144: MaskBit = 0x8000; \ ! 145: DESTINATION; \ ! 146: } \ ! 147: Sentinel += DeltaY; \ ! 148: } \ ! 149: } \ ! 150: if(Pattern & PatternBit) \ ! 151: Rule1 \ ! 152: break; \ ! 153: case (DrawPatternedLine): \ ! 154: while (BitsLeftToDraw--) { \ ! 155: if(Pattern & PatternBit) \ ! 156: Rule1 \ ! 157: else \ ! 158: Rule2 \ ! 159: if(--RepeatCount == 0) { \ ! 160: RepeatCount = PatternMultiplier; \ ! 161: if((PatternBit >>= 1) == 0) \ ! 162: PatternBit = PatternFirstBit; \ ! 163: } \ ! 164: NEXT_ROW; \ ! 165: if ((Sentinel -= DeltaX) < 0) { \ ! 166: if ((MaskBit >>= 1) == 0) { \ ! 167: MaskBit = 0x8000; \ ! 168: DESTINATION; \ ! 169: } \ ! 170: Sentinel += DeltaY; \ ! 171: } \ ! 172: } \ ! 173: if(Pattern & PatternBit) \ ! 174: Rule1 \ ! 175: else \ ! 176: Rule2 \ ! 177: } \ ! 178: } ! 179: ! 180: /* ! 181: * Cohen-Sutherland clipping algorithm ! 182: * ! 183: * See: Fundamentals of Interactive Computer Graphics ! 184: * J. D. Foley & A. Van Dam ! 185: * Pages 146 - 149 ! 186: */ ! 187: ! 188: #define OUTCODE_TOP 0x08 ! 189: #define OUTCODE_BOTTOM 0x04 ! 190: #define OUTCODE_RIGHT 0x02 ! 191: #define OUTCODE_LEFT 0x01 ! 192: ! 193: ! 194: #define OUTCODES(x, y, clip) \ ! 195: (((x) < clip->left ? OUTCODE_LEFT : \ ! 196: (x) >= clip->left + clip->width ? OUTCODE_RIGHT : 0) \ ! 197: +((y) < clip->top ? OUTCODE_TOP : \ ! 198: (y) >= clip->top + clip->height ? OUTCODE_BOTTOM : 0)) ! 199: ! 200: #define ClipLine(x0, y0, x1, y1, clip) { \ ! 201: \ ! 202: if (clip) { \ ! 203: int OutCode0 = OUTCODES(x0, y0, clip); \ ! 204: int OutCode1 = OUTCODES(x1, y1, clip); \ ! 205: \ ! 206: while (OutCode0 | OutCode1) { /* trivially accepted ? */ \ ! 207: if (OutCode0 & OutCode1) /* trivially rejected ? */ \ ! 208: return; \ ! 209: if (OutCode0) { \ ! 210: if (OutCode0 & (OUTCODE_LEFT | OUTCODE_RIGHT)) { \ ! 211: int Clip_X = (OutCode0 & OUTCODE_LEFT) ? clip->left : \ ! 212: clip->left + clip->width - 1; \ ! 213: \ ! 214: y0 = y0 + (y1 - y0) * (Clip_X - x0) / (x1 - x0); \ ! 215: x0 = Clip_X; \ ! 216: } else if (OutCode0 & (OUTCODE_TOP | OUTCODE_BOTTOM)) { \ ! 217: int Clip_Y = (OutCode0 & OUTCODE_TOP) ? clip->top : \ ! 218: clip->top + clip->height - 1; \ ! 219: \ ! 220: x0 = x0 + (x1 - x0) * (Clip_Y - y0) / (y1 - y0); \ ! 221: y0 = Clip_Y; \ ! 222: } \ ! 223: OutCode0 = OUTCODES(x0, y0, clip); \ ! 224: } else if (OutCode1) { \ ! 225: if (OutCode1 & (OUTCODE_LEFT | OUTCODE_RIGHT)) { \ ! 226: int Clip_X = (OutCode1 & OUTCODE_LEFT) ? clip->left : \ ! 227: clip->left + clip->width - 1; \ ! 228: \ ! 229: y1 = y0 + (y1 - y0) * (Clip_X - x0) / (x1 - x0); \ ! 230: x1 = Clip_X; \ ! 231: } else if (OutCode1 & (OUTCODE_TOP | OUTCODE_BOTTOM)) { \ ! 232: int Clip_Y = (OutCode1 & OUTCODE_TOP) ? clip->top : \ ! 233: clip->top + clip->height - 1; \ ! 234: \ ! 235: x1 = x0 + (x1 - x0) * (Clip_Y - y0) / (y1 - y0); \ ! 236: y1 = Clip_Y; \ ! 237: } \ ! 238: OutCode1 = OUTCODES(x1, y1, clip); \ ! 239: } \ ! 240: } \ ! 241: } \ ! 242: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.