home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapterg / lg-6.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-18  |  2.3 KB  |  56 lines

  1. /* Draws pixels from the list of horizontal lines passed in, to a 32-bpp 
  2. buffer; drawing takes place only for scan lines between ScanBandStart and 
  3. ScanBandEnd, inclusive; drawing goes to ScanLineBuffer, with the scan line at 
  4. ScanBandStart mapping to the first scan line in ScanLineBuffer. Note that 
  5. Color here points to an RGB structure that maps directly to the buffer's pixel 
  6. format, rather than containing a 16-bit integer.
  7.   Tested with Borland C++ 4.02 in small model by Jim Mischel 12/16/94.
  8. */
  9. #include "polygon.h"
  10.  
  11. extern struct RGB *ScanLineBuffer;  /* drawing goes here */
  12. extern int ScanBandStart, ScanBandEnd; /* limits of band to draw */
  13. extern int ScanBandWidth;  /* # of subpixels across scan band */
  14.    
  15. void DrawBandedList(struct HLineList * HLineListPtr,
  16.    struct RGB *Color)
  17. {
  18.    struct HLine *HLinePtr;
  19.    int Length, Width, YStart = HLineListPtr->YStart, i;
  20.    struct RGB *BufferPtr, *WorkingBufferPtr;
  21.  
  22.    /* Done if fully off the bottom or top of the band */
  23.    if (YStart > ScanBandEnd) return;
  24.    Length = HLineListPtr->Length;
  25.    if ((YStart + Length) <= ScanBandStart) return;
  26.  
  27.    /* Point to XStart/XEnd descriptor for the first (top) horizontal line */
  28.    HLinePtr = HLineListPtr->HLinePtr;
  29.  
  30.    /* Confine drawing to the specified band */
  31.    if (YStart < ScanBandStart) {
  32.       /* Skip ahead to the start of the band */
  33.       Length -= ScanBandStart - YStart;
  34.       HLinePtr += ScanBandStart - YStart;
  35.       YStart = ScanBandStart;
  36.    }
  37.    if (Length > (ScanBandEnd - YStart + 1))
  38.       Length = ScanBandEnd - YStart + 1;
  39.  
  40.    /* Point to the start of the first scan line on which to draw */
  41.    BufferPtr = ScanLineBuffer + (YStart-ScanBandStart)*ScanBandWidth;
  42.  
  43.    /* Draw each horizontal line within the band in turn, starting with
  44.       the top one and advancing one line each time */
  45.    while (Length-- > 0) {
  46.       /* Fill whole horiz line with Color if it has positive width */
  47.       if ((Width = HLinePtr->XEnd - HLinePtr->XStart + 1) > 0) {
  48.          WorkingBufferPtr = BufferPtr + HLinePtr->XStart;
  49.          for (i = 0; i < Width; i++) *WorkingBufferPtr++ = *Color;
  50.       }
  51.       HLinePtr++;                /* point to next scan line X info */
  52.       BufferPtr += ScanBandWidth; /* point to start of next line */
  53.    }
  54. }
  55.  
  56.