home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 8 / 8_3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.7 KB  |  87 lines

  1. /* Listing 8-3 */
  2.  
  3. #define    UP        -1
  4. #define    DOWN        1
  5.  
  6.  
  7. LineAdjFill( SeedX, SeedY, D, PrevXL, PrevXR )
  8. int    SeedX,SeedY;        /* seed for current row of pixels */
  9. int    D;            /* direction searched to find current row */
  10. int    PrevXL,PrevXR;        /* endpoints of previous row of pixels */
  11. {
  12.     int    x,y;
  13.     int    xl,xr;
  14.     int    v;
  15.  
  16.     y = SeedY;        /* initialize to seed coordinates */
  17.     xl = SeedX;
  18.     xr = SeedX;
  19.  
  20.     ScanLeft( &xl, &y );    /* determine endpoints of seed line segment */
  21.     ScanRight( &xr, &y );
  22.  
  23.     Line( xl, y, xr, y, FillValue );    /* fill line with FillValue */
  24.  
  25.  
  26. /* find and fill adjacent line segments in same direction */
  27.  
  28.     for (x=xl; x<=xr; x++)        /* inspect adjacent rows of pixels */
  29.     {
  30.       v = ReadPixel( x, y+D );
  31.       if ( (v!=BorderValue) && (v!=FillValue) )
  32.         x = LineAdjFill( x, y+D, D, xl, xr );
  33.     }
  34.  
  35. /* find and fill adjacent line segments in opposite direction */
  36.  
  37.     for (x=xl; x<PrevXL; x++)
  38.     {
  39.       v = ReadPixel( x, y-D );
  40.       if ( (v!=BorderValue) && (v!=FillValue) )
  41.         x = LineAdjFill( x, y-D, -D, xl, xr );
  42.     }
  43.  
  44.     for (x=PrevXR; x<xr; x++)
  45.     {
  46.       v = ReadPixel( x, y-D );
  47.       if ( (v!=BorderValue) && (v!=FillValue) )
  48.         x = LineAdjFill( x, y-D, -D, xl, xr );
  49.     }
  50.  
  51.     return( xr );
  52. }
  53.  
  54.  
  55. ScanLeft( x, y )
  56. int    *x,*y;
  57. {
  58.     int    v;
  59.  
  60.  
  61.     do
  62.     {
  63.       --(*x);            /* move left one pixel */
  64.       v = ReadPixel( *x, *y );    /* determine its value */
  65.     }
  66.     while ( (v!=BorderValue) && (v!=FillValue) );
  67.  
  68.     ++(*x);        /* x-coordinate of leftmost pixel in row */
  69. }
  70.  
  71.  
  72. ScanRight( x, y )
  73. int    *x,*y;
  74. {
  75.     int    v;
  76.  
  77.  
  78.     do
  79.     {
  80.       ++(*x);            /* move right one pixel */
  81.       v = ReadPixel( *x, *y );    /* determine its value */
  82.     }
  83.     while ( (v!=BorderValue) && (v!=FillValue) );
  84.  
  85.     --(*x);        /* x-coordinate of rightmost pixel in row */
  86. }
  87.