home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gems / gemsiii / pir.c < prev    next >
Text File  |  1992-03-16  |  2KB  |  64 lines

  1. /***********************************************************************
  2. The following function displays an image using progressive refinement
  3. via gridded sampling.  It assumes the existence of two functions:
  4.  
  5.     SetColor (x, y)
  6.         Sets the current color to the color at image location x,y.
  7.  
  8.     Rectangle (x, y, width, height)
  9.         Draws a rectangular region filled with the current color.  The
  10.         rectangle ranges from x to (x+width-1), and from y to
  11.         (y+height-1).
  12.  
  13. The parameters given are the subdivision start level (a power of two),
  14. and the X and Y dimensions of the entire image.
  15. ***********************************************************************/
  16.  
  17. void  PIR_Display  (start_level, Xdim, Ydim)
  18.     int  start_level;      /* Starting Subdivision Level */
  19.     int  Xdim, Ydim;       /* Image Dimensions */
  20. {
  21.     auto int size, size2;  /* Current Region Size & size/2 */
  22.     auto int Ix, Iy;       /* Image Space Indices */
  23.  
  24.  
  25.     /* Initialization loop:  display the initial coarse image tiling. */
  26.  
  27.     size = 1 << start_level;
  28.  
  29.     for (Iy=0;  Iy <= Ydim;  Iy += size)
  30.     {   for (Ix=0;  Ix <= Xdim;  Ix += size)
  31.         {   SetColor  (Ix, Iy);
  32.             Rectangle (Ix, Iy, size, size);
  33.         }
  34.     }
  35.  
  36.     /* Sampling and Gridding Loop */
  37.  
  38.     size2 = size / 2;
  39.  
  40.     while (size > 1)       /* Subdivide down to the pixel level. */
  41.     {
  42.         for (Iy=0;  Iy <= Ydim;  Iy += size)
  43.         {   for (Ix=0;  Ix <= Xdim;  Ix += size)
  44.             {
  45.                 /* Draw the three new subpixel regions. */
  46.  
  47.                 SetColor  (Ix, Iy + size2);
  48.                 Rectangle (Ix, Iy + size2, size2, size2);
  49.  
  50.                 SetColor  (Ix + size2, Iy + size2);
  51.                 Rectangle (Ix + size2, Iy + size2, size2, size2);
  52.  
  53.                 SetColor  (Ix + size2, Iy);
  54.                 Rectangle (Ix + size2, Iy, size2, size2);
  55.             }
  56.         }
  57.  
  58.         /* The new region edge length is half the old edge length. */
  59.  
  60.         size  = size2;
  61.         size2 = size2 / 2;
  62.     }
  63. }
  64.