home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-ASM_VI.ARJ / PROGC.ZIP / PROGC091.C < prev    next >
Text File  |  1988-04-10  |  4KB  |  83 lines

  1.  
  2. /************************************************************************/
  3. /* Transfer source block of dimension DX x DY from XS,YS                */
  4. /* to XD, YD                                                            */
  5. /************************************************************************/
  6.  
  7. slow_bitblt(xs, ys, xd, yd, dx, dy, fn)
  8. int     xs, ys;                         /* Source upper left corner     */
  9. int     xd, yd;                         /* Destination upper left       */
  10. int     dx, dy;                         /* Dimensions of the block      */
  11. int     fn;                             /* Logical operation            */
  12.         {
  13.         #define COPY    0
  14.         #define CLEAR   1
  15.         #define OR      2
  16.         #define XOR     3
  17.         #define AND     4
  18.         int     x_incr, y_incr, x_max, y_max, x, y, i, j, value;
  19.  
  20.         /****************************************************************/
  21.         /* Compute starting points and directions of transfer           */
  22.         /****************************************************************/
  23.  
  24.         x = 0;                          /* Assume no overlap or ++      */
  25.         y = 0;                          /* i.e. xs > xd && ys > yd      */
  26.         x_incr = 1;
  27.         y_incr = 1;
  28.  
  29.         if (xs <= xd && xs + dx >= xd)  /* Reverse x direction if source*/
  30.                 {                       /* overlaps left half of dest.  */
  31.                 x = dx - 1;
  32.                 x_incr = -1;
  33.                 }
  34.  
  35.         if (ys > yd && ys <= yd + dy)   /* Revers y direction if source */
  36.                 {                       /* overlaps bottom half of dest */
  37.                 y = dy - 1;
  38.                 y_incr = -1;
  39.                 }
  40.  
  41.         /****************************************************************/
  42.         /* Transfer the block                                           */
  43.         /****************************************************************/
  44.  
  45.         for (j = 0; j < dy; j++)                /* Loop over rasters    */
  46.                 {
  47.                 for (i = 0; i < dx; i++)        /* Loop over pixels     */
  48.                         {
  49.                         switch (fn)             /* Select logical op    */
  50.                                 {
  51.                                 case COPY:
  52.                                         value = pixel_read(xs+x,ys+y);
  53.                                         pixel_write(xd+x,yd+y,value);
  54.                                         break;
  55.                                 case CLEAR:
  56.                                         value = 0;
  57.                                         pixel_write(xd+x,yd+y,value);
  58.                                         break;
  59.                                 case OR:
  60.                                         value = pixel_read(xs+x,ys+y) |
  61.                                                 pixel_read(xd+x,yd+x);
  62.                                         pixel_write(xd+x,yd+y,value);
  63.                                         break;
  64.                                 case XOR:
  65.                                         value = pixel_read(xs+x,ys+y) ^
  66.                                                 pixel_read(xd+x,yd+x);
  67.                                         pixel_write(xd+x,yd+y,value);
  68.                                         break;
  69.                                 case AND:
  70.                                         value = pixel_read(xs+x,ys+y) &
  71.                                                 pixel_read(xd+x,yd+x);
  72.                                         pixel_write(xd+x,yd+y,value);
  73.                                         break;
  74.                                 default:
  75.                                         break;
  76.                                 }
  77.                         x += x_incr;            /* Update pixel pointer */
  78.                         }
  79.                 y += y_incr;                    /* Update raster pointer*/
  80.                 x -= dx * x_incr;               /* Reset pixel pointer  */
  81.                 }
  82.         }
  83.