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 / mpelMono.c < prev    next >
C/C++ Source or Header  |  1991-07-06  |  10KB  |  331 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.         Copyright IBM Corporation 1987,1988
  25.  
  26.                       All Rights Reserved
  27.  
  28. Permission to use, copy, modify, and distribute this software and its 
  29. documentation for any purpose and without fee is hereby granted, 
  30. provided that the above copyright notice appear in all copies and that
  31. both that copyright notice and this permission notice appear in 
  32. supporting documentation, and that the name of IBM not be
  33. used in advertising or publicity pertaining to distribution of the
  34. software without specific, written prior permission.  
  35.  
  36. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  37. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  38. IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  39. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  40. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  41. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  42. SOFTWARE.
  43.  
  44. ******************************************************************/
  45.  
  46. /* $Header: /afs/rel-eng.athena.mit.edu/project/x11r4/src/mit/server/ddx/ibm/mpel/RCS/mpelMono.c,v 1.2 90/09/02 12:19:57 jfc Exp $ */
  47. /* $Source: /afs/rel-eng.athena.mit.edu/project/x11r4/src/mit/server/ddx/ibm/mpel/RCS/mpelMono.c,v $ */
  48.  
  49. #ifndef lint
  50. static char *rcsid = "$Id: mpelMono.c,v 1.2 90/09/02 12:19:57 jfc Exp $" ;
  51. #endif
  52.  
  53. /*
  54.  * Megapel bitmap fill with solid foreground and transparent background
  55.  *
  56.  * Paquin 10/87
  57.  *
  58.  */
  59.  
  60. #include "X.h"
  61. #include "Xmd.h"
  62. #include "servermd.h"
  63. #include "font.h"
  64. #include "OScompiler.h"
  65.  
  66. #include "ibmTrace.h"
  67.  
  68. #include "mpel.h"
  69. #include "mpelHdwr.h"
  70. #include "mpelFifo.h"
  71.  
  72. /* Cursor Stuff */
  73. extern int mpelcursorSemaphore ;
  74. extern int mpelCheckCursor() ;
  75. extern void mpelReplaceCursor() ;
  76.  
  77. /***==================================================================***/
  78.  
  79. void
  80. mpelDrawMonoByteImage( data, x, y, w, h, fg, alu, planes )
  81.     register unsigned char *data ;
  82.     int            x ;
  83.     int            y ;
  84.     int            w ;
  85.     register int    h ;
  86.     unsigned long int    fg ;
  87.     int            alu ;
  88.     unsigned long int    planes ;
  89. {
  90.     register volatile unsigned char *dstPtr ;
  91.     int            i ;
  92.     int            cleanBytes, widthBytes ;
  93.     unsigned char    lastbyteMask ;
  94.     int            PaddedWidthInBits ;
  95.     int cursor_saved ;
  96.     mpelSrcBLTVPMWColorExpansion block ;
  97. #if (GLYPHPADBYTES != 1)
  98.     int         extrabytesPerScanline ;
  99. #endif
  100.  
  101.     void mpelUnnaturalMonoByteImage() ; /* Defined Below !! */
  102.  
  103.     TRACE(("mpelDrawMonoByteImage(0x%x,%d,%d,%d,%d,%d,%d,0x%x)\n",
  104.         data,x,y,w,h,fg,alu,planes)) ;
  105.  
  106.     if ( w <= 0 || h <= 0 || alu == GXnoop )
  107.     return ;
  108.  
  109.     widthBytes = ( w + 7 ) / 8 ; /* width of image, not data */
  110.     if ( ( widthBytes * h ) > MPEL_BLIT_STAGE_SIZE ) {
  111.     mpelUnnaturalMonoByteImage(data, x,y,w,h, fg, alu, planes ) ;
  112.     return ;
  113.     }
  114.  
  115.     /* If Cursor Is In The Way Remove It */
  116.     cursor_saved = !mpelcursorSemaphore && mpelCheckCursor( x, y, w, h ) ;
  117.  
  118.     mpelSetPlaneMask( planes ) ;
  119.  
  120.     if ( i = ( w % 8 ) ) {
  121.     lastbyteMask = ( ( ~0 ) << ( 8 - i ) ) ;
  122.     PaddedWidthInBits = ( w & ~7 ) + 8 ;
  123.     }
  124.     else {
  125.     lastbyteMask = ~0 ;
  126.     PaddedWidthInBits = w ;
  127.     }
  128.  
  129.     cleanBytes = widthBytes - 1 ;
  130.  
  131. #if (GLYPHPADBYTES != 1)
  132.     extrabytesPerScanline = PADGLYPHWIDTHBYTES( w ) - widthBytes ;
  133. #endif
  134.  
  135.     /* copy image TO adapter buffer area */
  136.     block.color        = fg ;
  137.     block.srcaddr         = mpelAddr(MPEL_BLIT_STAGE) ;
  138.     block.dest.lleft.x    = x ;
  139.     block.dest.lleft.y    = MPEL_HEIGHT - ( y + h ) ;
  140.     block.dest.uright.x    = x + PaddedWidthInBits - 1 ;
  141.     block.dest.uright.y    = MPEL_HEIGHT - 1 - y ;
  142.     block.alu        = alu + 1 ;
  143.  
  144.     /* If the 'SetPlaneMask' has been swallowed we can continue */
  145.     MPELWaitFifo() ;
  146.  
  147.     
  148.     for ( dstPtr = (volatile unsigned char *) MPEL_BLIT_STAGE ; h-- ; ) {
  149.         if ( cleanBytes ) {
  150.         MOVE( data, dstPtr, cleanBytes) ;
  151.         data += cleanBytes ;
  152.         dstPtr += cleanBytes ;
  153.         }
  154.         /* mask last byte */
  155.         *dstPtr++ = *data++ & lastbyteMask ; 
  156. #if (GLYPHPADBYTES != 1)
  157.         data += extrabytesPerScanline ;
  158. #endif
  159.     }
  160.  
  161.     MPELSrcBLTVPMWColorExpansionROP( &block ) ;
  162.  
  163.     if ( cursor_saved )
  164.     mpelReplaceCursor() ;
  165.  
  166.     return ;
  167. }
  168.  
  169. /***==================================================================***/
  170.  
  171. void
  172. mpelUnnaturalMonoByteImage( data, x, y, w, h, fg, alu, planes )
  173.     unsigned char    *data ;
  174.     int            x, y, w, h ;
  175.     unsigned long int    fg ;
  176.     int            alu ;
  177.     unsigned long int    planes ;
  178. {
  179.     int     totwidthBytes ;
  180.     int        linesPerBlock ;
  181.     int        bytes ;
  182.     int        bytesPerBlock ;
  183.  
  184.     TRACE(("mpelUnnaturalMonoByteImage(0x%x,%d,%d,%d,%d,%d,%d,0x%x)\n",
  185.         data, x, y, w, h, fg, alu, planes ) ) ;
  186.  
  187.     totwidthBytes = ( ( w + 7 ) / 8 ) ;
  188.     linesPerBlock = MPEL_BLIT_STAGE_SIZE / totwidthBytes ;
  189.  
  190.     /* the following *should* be impossible */
  191.     if ( ( linesPerBlock * totwidthBytes ) > MPEL_BLIT_STAGE_SIZE ) {
  192.         ErrorF( "Fatal MonoByte: too big (internal)\n" ) ;
  193.         return ;
  194.     }
  195.  
  196.     bytes = totwidthBytes * h ;
  197.     bytesPerBlock = totwidthBytes * linesPerBlock ;
  198.  
  199.     while ( bytes > 0 ) {
  200.     if (bytes < bytesPerBlock)
  201.         mpelDrawMonoByteImage(data, x, y, w, bytes / totwidthBytes, fg, alu, planes);
  202.     else
  203.         mpelDrawMonoByteImage(data, x, y, w, linesPerBlock, fg, alu, planes);
  204.     y += linesPerBlock ;
  205.     data += bytesPerBlock ;
  206.     bytes -= bytesPerBlock ;
  207.     }
  208.     return ;
  209. }
  210.  
  211. /***==================================================================***/
  212.  
  213. void
  214. mpelDrawMonoImage( data, x, y, w, h, fg, alu, planes )
  215.     unsigned char    *data ;
  216.     int            x, y, w, h ;
  217.     unsigned long int    fg ;
  218.     int            alu ;
  219.     unsigned long int    planes ;
  220. {
  221.     register volatile unsigned char    *dstPtr ;
  222.     int                 i ;
  223.     int                 cleanBytes, PadBytes ;
  224.     int                 totwidthBytes, realwidthBytes ;
  225.     int                 lastbyteMask ;
  226.     int                 PaddedWidthInBits ;
  227.     int                    cursor_saved ;
  228.     mpelSrcBLTVPMWColorExpansion     block ;
  229.  
  230.     void mpelUnnaturalMonoImage() ; /* Defined Below !! */
  231.  
  232.     TRACE(("mpelDrawMonoImage(0x%x,%d,%d,%d,%d,%d,%d,0x%x)\n",
  233.     data,x,y,w,h,fg,alu,planes)) ;
  234.  
  235.     if ( w <= 0 || h <= 0 || alu == GXnoop )
  236.     return ;
  237.  
  238.     totwidthBytes = ( ( w + 31 ) / 32 ) << 2 ;
  239.     realwidthBytes = ( w + 7 ) / 8 ;
  240.     if ( ( realwidthBytes * h ) > MPEL_BLIT_STAGE_SIZE ) {
  241.     mpelUnnaturalMonoImage( data, x, y, w, h, fg, alu, planes ) ;
  242.     return ;
  243.     }
  244.  
  245.     /* If Cursor Is In The Way Remove It */
  246.     cursor_saved = !mpelcursorSemaphore && mpelCheckCursor( x, y, w, h ) ;
  247.  
  248.     mpelSetPlaneMask( planes ) ;
  249.     PadBytes = totwidthBytes - realwidthBytes ;
  250.  
  251.     if ( i = ( w % 8 ) ) {
  252.     lastbyteMask = ( ( ~0 ) << ( 8 - i ) ) ;
  253.     PaddedWidthInBits = ( w & ~7 ) + 8 ;
  254.     }
  255.     else {
  256.     lastbyteMask = ~0 ;
  257.     PaddedWidthInBits = w ;
  258.     }
  259.  
  260.     block.color        = fg ;
  261.     block.srcaddr         = mpelAddr(MPEL_BLIT_STAGE) ;
  262.     block.dest.lleft.x    = x ;
  263.     block.dest.lleft.y    = MPEL_HEIGHT - ( y + h ) ;
  264.     block.dest.uright.x    = x + PaddedWidthInBits - 1 ;
  265.     block.dest.uright.y    = MPEL_HEIGHT - 1 - y ;
  266.     block.alu        = alu + 1 ;
  267.  
  268.     cleanBytes = realwidthBytes - 1 ;
  269.  
  270.     /* copy image TO adapter buffer area */
  271.     /* If the 'SetPlaneMask' has been swallowed we can continue */
  272.     MPELWaitFifo() ;
  273.     for ( dstPtr = (volatile unsigned char *) MPEL_BLIT_STAGE ; h-- ; ) {
  274.         if ( cleanBytes ) {
  275.         MOVE( data, dstPtr, cleanBytes) ;
  276.         data += cleanBytes ;
  277.         dstPtr += cleanBytes ;
  278.         }
  279.         /* mask last byte */
  280.         *dstPtr++ = *data++ & lastbyteMask ; 
  281.  
  282.         data += PadBytes ;
  283.     }
  284.  
  285.     MPELSrcBLTVPMWColorExpansionROP( &block ) ;
  286.  
  287.     if ( cursor_saved )
  288.     mpelReplaceCursor() ;
  289.  
  290.     return ;
  291. }
  292.  
  293. /***==================================================================***/
  294.  
  295. void
  296. mpelUnnaturalMonoImage( data, x, y, w, h, fg, alu, planes )
  297.     unsigned char    *data ;
  298.     int            x, y, w, h ;
  299.     unsigned long int    fg ;
  300.     int            alu ;
  301.     unsigned long int    planes ;
  302. {
  303.     int totwidthBytes, linesPerBlock, bytes, bytesPerBlock ;
  304.  
  305.     TRACE( ( "mpelUnnaturalMonoImage(0x%x,%d,%d,%d,%d,%d,%d,0x%x)\n",
  306.        data, x, y, w, h, fg, alu, planes ) ) ;
  307.  
  308.     totwidthBytes = ( ( w + 31 ) / 32 ) << 2 ;
  309.     linesPerBlock = MPEL_BLIT_STAGE_SIZE / totwidthBytes ;
  310.  
  311.     /* the following *should* be impossible */
  312.     if ( ( linesPerBlock * totwidthBytes ) > MPEL_BLIT_STAGE_SIZE ) {
  313.     ErrorF( "Fatal Mono: too big (internal)\n" ) ;
  314.     return ;
  315.     }
  316.  
  317.     bytes = totwidthBytes * h ;
  318.     bytesPerBlock = totwidthBytes * linesPerBlock ;
  319.  
  320.     while ( bytes > 0 ) {
  321.     if (bytes < bytesPerBlock)
  322.         mpelDrawMonoByteImage(data, x, y, w, bytes / totwidthBytes, fg, alu, planes);
  323.     else
  324.         mpelDrawMonoByteImage(data, x, y, w, linesPerBlock, fg, alu, planes);
  325.     y += linesPerBlock ;
  326.     data += bytesPerBlock ;
  327.     bytes -= bytesPerBlock ;
  328.     }
  329.     return ;
  330. }
  331.