home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / mpel / mpelImg.c < prev    next >
C/C++ Source or Header  |  1992-03-24  |  7KB  |  249 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23.  
  24. /* $Header: /afs/athena.mit.edu/astaff/project/x11r5/src/athena/ibm/mpel/RCS/mpelImg.c,v 5.1 1992/02/12 00:40:46 jfc Exp $ */
  25. /* $Source: /afs/athena.mit.edu/astaff/project/x11r5/src/athena/ibm/mpel/RCS/mpelImg.c,v $ */
  26.  
  27. #ifndef lint
  28. static char *rcsid = "$Id: mpelImg.c,v 5.1 1992/02/12 00:40:46 jfc Exp $";
  29. #endif
  30.  
  31. #include "X.h"
  32.  
  33. #include "OScompiler.h"
  34.  
  35. #include "mpel.h"
  36. #include "mpelHdwr.h"
  37. #include "mpelFifo.h"
  38.  
  39. #include "ibmTrace.h"
  40.  
  41. /* Cursor Stuff */
  42. extern int mpelcursorSemaphore;
  43. extern int mpelCheckCursor();
  44. extern void mpelReplaceCursor();
  45.  
  46. /***==================================================================***/
  47.  
  48. /*
  49.  * mpelDrawColorImage(x,y,w,h,data,alu,planes)
  50.  */
  51.  
  52. void
  53. mpelDrawColorImage( x, y, w, h, data, RowIncrement, alu, mask )
  54.     int    x;
  55.     int    y;
  56.     int w;
  57.     register int h;
  58.     register unsigned char *data;
  59.     int    RowIncrement;
  60.     int    alu;
  61.     unsigned long int mask;
  62. {
  63.     int maxrows;
  64.     mpelSrcBLTVPM blt;
  65.     int cursor_saved;
  66.  
  67.     TRACE(("mpelDrawColorImage(%d,%d,%d,%d,0x%x,%d,0x%x,0x%x)\n",
  68.        x, y, w, h, data, RowIncrement, alu, mask));
  69.  
  70.     if ( w <= 0 || h <= 0 || alu == GXnoop )
  71.     return;
  72.  
  73.     /* If Cursor Is In The Way Remove It */
  74.     cursor_saved = !mpelcursorSemaphore && mpelCheckCursor( x, y, w, h );
  75.  
  76.     mpelSetPlaneMask( mask );
  77.     /* So we KNOW the stage is NOT in use when we wait later */
  78.  
  79.     blt.srcaddr =    mpelAddr( MPEL_BLIT_STAGE );
  80.     blt.dest.lleft.x =    x;
  81.     blt.dest.uright.x =    x + w - 1;
  82.     blt.bpixel =    0x0008;
  83.     blt.alu =        alu + 1;
  84.  
  85.     if ( h <= ( maxrows = MPEL_BLIT_STAGE_SIZE / w ) ) {
  86.     blt.dest.lleft.y =    MPEL_HEIGHT - ( y + h );
  87.     blt.dest.uright.y =    MPEL_HEIGHT - 1 - y;
  88.  
  89.     /* copy image TO adapter buffer area */
  90.     MPELWaitFifo();
  91.     if ( RowIncrement != w ) {
  92.         register volatile unsigned char *daptr =
  93.             (volatile unsigned char *) MPEL_BLIT_STAGE;
  94.         while ( h-- ) {
  95.             MOVE( data, daptr, w );
  96.             daptr += w;
  97.         data += RowIncrement;
  98.         }
  99.     }
  100.     else
  101.         MOVE( data, (volatile unsigned char *) MPEL_BLIT_STAGE, w * h );
  102.  
  103.     MPELSrcBLTVPM( &blt );
  104.     } 
  105.     else { /* do multiple blits */
  106.     register int nh;
  107.  
  108.     while ( h ) {
  109.         /* update values */
  110.         blt.dest.uright.y =    MPEL_HEIGHT - 1 - y;
  111.         nh = MIN( h, maxrows );
  112.         blt.dest.lleft.y =    MPEL_HEIGHT - ( y += nh );
  113.         h -= nh;
  114.  
  115.         /* copy image TO adapter buffer area */
  116.         MPELWaitFifo();
  117.         if ( RowIncrement != w ) {
  118.             register volatile unsigned char *daptr =
  119.             (volatile unsigned char *) MPEL_BLIT_STAGE;
  120.             while ( nh-- ) {
  121.                 MOVE( data, daptr, w );
  122.             daptr += w;
  123.                 data += RowIncrement;
  124.             }    
  125.         }
  126.         else
  127.         {
  128.             MOVE( data, (volatile unsigned char *) MPEL_BLIT_STAGE, w*nh);
  129.         data += nh*RowIncrement;
  130.         }
  131.  
  132.         MPELSrcBLTVPM(&blt);
  133.         MPELNoOp(2, &MPELNoOpData);
  134.     } /* end while */
  135.     } /* end else */
  136.  
  137.     if ( cursor_saved )
  138.     mpelReplaceCursor();
  139.  
  140.     return;
  141. }
  142.  
  143. /*
  144.  * mpelReadColorImage(x,y,lx,ly,data)
  145.  * 
  146.  * BUG: the first 32-bit word is broken !!!
  147.  */
  148.  
  149. void
  150. mpelReadColorImage( x, y, w, h, data, RowIncrement )
  151.     int        x;
  152.     int        y;
  153.     int        w;
  154.     register int h;
  155.     register unsigned char *data;
  156.     int    RowIncrement;
  157. {
  158.     int maxrows;
  159.     mpelVPMBLTDestination blt;
  160.     int cursor_saved;
  161.  
  162.     TRACE( ( "mpelReadColorImage(%d,%d,%d,%d,0x%x,%d)\n",
  163.        x, y, w, h, data, RowIncrement ) );
  164.  
  165.     if (w <= 0 || h <= 0)
  166.     return;
  167.  
  168.     /* The megapel adapter hangs on a copy of a 1x1 region, so there
  169.        is some code in this function to special case w == 1. */
  170.  
  171.     cursor_saved = !mpelcursorSemaphore && mpelCheckCursor( x, y, w, h );
  172.  
  173.     blt.destaddr =        mpelAddr(MPEL_BLIT_STAGE);
  174.     blt.source.lleft.x =    x;
  175.     blt.source.uright.x =    x + w - 1 + (w == 1);
  176.     blt.comp =            0x0001;    /* no color compression */
  177.  
  178.     /* copy image TO adapter buffer area */
  179.     if (h <= (maxrows = MPEL_BLIT_STAGE_SIZE / w)) {
  180.     blt.source.lleft.y =    MPEL_HEIGHT - (y + h);
  181.     blt.source.uright.y =    MPEL_HEIGHT - 1 - y;
  182.     /* do a DestBlt VPM */
  183.     MPELVPMBLTDest(&blt);
  184.     /* Make Sure The Transfer is complete */
  185.     MPELNoOp(2, &MPELNoOpData);
  186.     MPELWaitFifo();
  187.     /* NOW, read the data from the Stage */
  188.     if (w == 1) {
  189.         register volatile unsigned char *ptr =
  190.         (volatile unsigned char *) MPEL_BLIT_STAGE;
  191.         while(h--) {
  192.         *ptr = *data;
  193.         ptr += 2;
  194.         data += RowIncrement;
  195.         }
  196.     } else if (RowIncrement != w) {
  197.         register volatile unsigned char *ptr =
  198.         (volatile unsigned char *) MPEL_BLIT_STAGE;
  199.         while ( h-- ) {
  200.             MOVE(ptr, data, w);
  201.             ptr += w;
  202.             data += RowIncrement;
  203.         }    
  204.     } else {
  205.         MOVE((volatile unsigned char *) MPEL_BLIT_STAGE, data, w * h);
  206.     }
  207.     } 
  208.     else { /* do multiple blits */
  209.     register int nh;
  210.  
  211.     while ( h ) {
  212.         nh = MIN(h, maxrows);
  213.  
  214.         /* update values */
  215.         blt.source.uright.y =    MPEL_HEIGHT - 1 - y;
  216.         blt.source.lleft.y =    MPEL_HEIGHT - ( y += nh );
  217.  
  218.         /* do a DestBlt VPM */
  219.         MPELVPMBLTDest(&blt);
  220.         /* Make Sure The Transfer is complete */
  221.         MPELNoOp( 2, &MPELNoOpData );
  222.  
  223.         h -= nh;
  224.  
  225.         MPELWaitFifo();
  226.         /* NOW, read the data from the Stage */
  227.         if ( RowIncrement != w ) {
  228.             register volatile unsigned char *ptr =
  229.             (volatile unsigned char *) MPEL_BLIT_STAGE;
  230.             while ( nh-- ) {
  231.             MOVE( ptr, data, w );
  232.             ptr += w;
  233.             data += RowIncrement;
  234.             }
  235.         }
  236.         else
  237.         {
  238.         MOVE( (volatile unsigned char *) MPEL_BLIT_STAGE, data, w*nh );
  239.         data += nh*RowIncrement;
  240.         }
  241.     }
  242.     } /* end ELSE */
  243.  
  244.     if ( cursor_saved )
  245.     mpelReplaceCursor();
  246.  
  247.     return;
  248. }
  249.