home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / x11 / lib / XCopyImg.c < prev   
Encoding:
C/C++ Source or Header  |  1991-05-31  |  4.6 KB  |  221 lines

  1. /*
  2. * This software is copyrighted as noted below.  It may be freely copied,
  3. * modified, and redistributed, provided that the copyright notices are
  4. * preserved on all copies.
  5. *
  6. * There is no warranty or other guarantee of fitness for this software,
  7. * it is provided solely "as is".  Bug reports or fixes may be sent
  8. * to the author, who may or may not act on them as he desires.
  9. *
  10. * You may not include this software in a program or other software product
  11. * without supplying the source, or without informing the end-user that the
  12. * source is available for no extra charge.
  13. *
  14. * If you modify this software, you should include a notice giving the
  15. * name of the person performing the modification, the date of modification,
  16. * and the reason for such modification.
  17. */
  18.  
  19. /*
  20. * Author:    Martin R. Friedmann
  21. *         Dept of Electrical Engineering and Computer Science
  22. *        University of Michigan
  23. * Date:    Tue, Nov 14, 1989
  24. * Copyright (c) 1989, University of Michigan
  25. */
  26.  
  27. #include "X11/Xlib.h"
  28. #include "panel.h"
  29.  
  30. /* this function provides a client side, block move within a single image
  31.  * structure for panning around in the magnified image.  bcopy is probubly
  32.  * faster on most machines...
  33.  */
  34.  
  35. int
  36. XCopyImage ( image, src_x, src_y, width, height, dst_x, dst_y )
  37. XImage *image;
  38. int src_x, src_y, width, height, dst_x, dst_y;
  39. {
  40.     int line_width = image->bytes_per_line;
  41.  
  42.     if ( width == 0 )
  43.     return;
  44.     
  45.     switch ( image->bits_per_pixel )
  46.     {
  47.     case 1:
  48.     return False;
  49.  
  50.     case 8:
  51.     do {
  52.         char *srcline, *dstline;
  53.         register char *src, *dst;
  54.         register int counter;
  55.     
  56.         if ( src_y < dst_y )
  57.         {
  58.         srcline = image->data + line_width * (src_y+height-1) +
  59.             src_x;
  60.         dstline = image->data + line_width * (dst_y+height-1) +
  61.             dst_x;
  62.         
  63.         if ( src_x < dst_x ) {
  64.             dstline += width - 1;
  65.             while ( --height >= 0 ) {
  66.             src = srcline + width - 1;
  67.             dst = dstline;
  68.             counter = width;
  69.  
  70.             duff8( counter, *dst-- = *src-- );
  71.             
  72.             srcline -= line_width;
  73.             dstline -= line_width;
  74.             }
  75.         }
  76.         else {
  77.             srcline += width - 1;
  78.             while ( --height >= 0 ) {
  79.             src = srcline - width + 1;
  80.             dst = dstline;
  81.             counter = width;
  82.             
  83.             duff8( counter, *dst++ = *src++ );
  84.             
  85.             srcline -= line_width;
  86.             dstline -= line_width;
  87.             }
  88.         }    
  89.         }
  90.         else
  91.         {
  92.         srcline = image->data + line_width * src_y + src_x;
  93.         dstline = image->data + line_width * dst_y + dst_x;
  94.         
  95.         if ( src_x < dst_x ) {
  96.             
  97.             dstline += width - 1;
  98.             while ( --height >= 0 ) {
  99.             src = srcline + width - 1;
  100.             dst = dstline;
  101.             counter = width;
  102.             
  103.             duff8( counter, *dst-- = *src-- );
  104.             
  105.             srcline += line_width;
  106.             dstline += line_width;
  107.             }
  108.         }
  109.         else {
  110.             srcline += width - 1;
  111.             while ( --height >= 0 ) {
  112.             src = srcline - width + 1;
  113.             dst = dstline;
  114.             counter = width;
  115.             
  116.             duff8( counter, *dst++ = *src++ );
  117.             
  118.             srcline += line_width;
  119.             dstline += line_width;
  120.             }
  121.         }    
  122.         }
  123.     } while (0);
  124.     return True;
  125.         
  126.     case 32:
  127.     do {
  128.         register long *srcline, *dstline;
  129.         register long *src, *dst;
  130.     
  131.         if ( src_y < dst_y )
  132.         {
  133.         srcline = (long *) ((char *)image->data +
  134.                     line_width * (src_y+height-1) +
  135.                     src_x * sizeof(long));
  136.         dstline = (long *) ((char *)image->data +
  137.                     line_width * (dst_y+height-1) +
  138.                     dst_x * sizeof(long));
  139.         
  140.         if ( src_x < dst_x ) {
  141.             
  142.             dstline += width - 1;
  143.             while ( --height >= 0 ) {
  144.             src = srcline + width - 1;
  145.             dst = dstline;
  146.             
  147.             while ( src >= srcline )
  148.                 *dst-- = *src--;
  149.             
  150.             srcline -= line_width/sizeof(long);
  151.             dstline -= line_width/sizeof(long);
  152.             }
  153.         }
  154.         else {
  155.             srcline += width - 1;
  156.             while ( --height >= 0 ) {
  157.             src = srcline - width + 1;
  158.             dst = dstline;
  159.             
  160.             while ( src <= srcline )
  161.                 *dst++ = *src++;
  162.             
  163.             srcline -= line_width/sizeof(long);
  164.             dstline -= line_width/sizeof(long);
  165.             }
  166.         }    
  167.         }
  168.         else
  169.         {
  170.         srcline = (long *) ((char *)image->data + line_width * src_y +
  171.                     src_x * sizeof(long));
  172.         dstline = (long *) ((char *)image->data + line_width * dst_y +
  173.                     dst_x * sizeof(long));
  174.         
  175.         if ( src_x < dst_x ) {
  176.             
  177.             dstline += width - 1;
  178.             while ( --height >= 0 ) {
  179.             src = srcline + width - 1;
  180.             dst = dstline;
  181.             
  182.             while ( src >= srcline )
  183.                 *dst-- = *src--;
  184.             
  185.             srcline += line_width/sizeof(long);
  186.             dstline += line_width/sizeof(long);
  187.             }
  188.         }
  189.         else {
  190.             srcline += width - 1;
  191.             while ( --height >= 0 ) {
  192.             src = srcline - width + 1;
  193.             dst = dstline;
  194.             
  195.             while ( src <= srcline )
  196.                 *dst++ = *src++;
  197.             
  198.             srcline += line_width/sizeof(long);
  199.             dstline += line_width/sizeof(long);
  200.             }
  201.         }    
  202.         }
  203.     } while (0);
  204.     return True;
  205.     }    
  206.     return False;
  207. }
  208.     
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.