home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ppc / ppcTile.c < prev    next >
C/C++ Source or Header  |  1989-11-07  |  7KB  |  248 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. #include "X.h"
  25. #include "pixmapstr.h"
  26. #include "pixmap.h"
  27. #include "scrnintstr.h"
  28. #include "colormap.h"
  29.  
  30. #include "ppc.h"
  31. #include "ppcProcs.h"
  32. #include "ibmTrace.h"
  33. #include "OScompiler.h"
  34.  
  35. extern void ErrorF( ) ;
  36. extern void mfbDestroyPixmap( ) ;
  37.  
  38. void ppcTileRect( pTile, alu, planes, x, y, w, h, xSrc, ySrc )
  39. register PixmapPtr pTile ;
  40. const int alu ;
  41. const unsigned long int planes ;
  42. register int x, y, w, h ;
  43. {
  44. register int        htarget, vtarget ;
  45. register int         tlx, tly ;
  46. register void        (*fnp)() ;
  47. register PixmapPtr     pTmpTile ;
  48. int            depth ;
  49. ScreenPtr        pScreen ;
  50. int            TileCopied ;
  51.  
  52. TRACE( ( "ppcTileRect(pTile = x%x, alu= x%x, planes=x%02x, x=%d, y=%d, w=%d, h=%d, xSrc=%d, ySrc=%d\n",
  53.         pTile, alu, planes, x, y, w, h, xSrc, ySrc ) ) ;
  54.  
  55. tlx = pTile->drawable.width ;
  56. tly = pTile->drawable.height ;
  57. pScreen = pTile->drawable.pScreen ;
  58. depth   = pTile->drawable.depth ;
  59.  
  60. switch ( alu ) {
  61.     case GXclear:        /* 0x0 Zero 0 */
  62.     case GXinvert:        /* 0xa NOT dst */
  63.     case GXset:        /* 0xf 1 */
  64.          (* ( ( (ppcScrnPriv *) (pScreen->devPrivate) )->solidFill) )
  65.              (0xFF, alu, planes, x, y, w, h ) ;
  66.     case GXnoop:        /* 0x5 dst */
  67.         return ;
  68.     default:
  69.         break ;
  70. }
  71.  
  72.  
  73. if ( ( x - xSrc ) % tlx ) {
  74.     if ( !( pTmpTile = ppcCreatePixmap( pScreen, tlx, tly, depth ) ) ) {
  75.         ErrorF( "Failed To Create Temporary Pixmap in ppcTileRect\n" ) ;
  76.         return ;
  77.     }
  78.     if (depth==1)
  79.            ppcRotBitmapLeft( pTile, pTmpTile, ( ( x - xSrc ) % tlx ) ) ;
  80.        else ppcRotZ8mapLeft( pTile, pTmpTile, ( ( x - xSrc ) % tlx ) ) ;
  81.  
  82.     if ( ( y - ySrc ) % tly ) {
  83.         if ( !( pTile = ppcCreatePixmap( pScreen, tlx, tly, depth ) ) ) {
  84.             ErrorF( "Failed To Create Pixmap \"pTile\" in ppcTileRect\n" ) ;
  85.             return ;
  86.         }
  87.         if (depth==1)
  88.             ppcRotBitmapUp( pTmpTile, pTile, ( (y-ySrc) % tly ) );
  89.            else ppcRotZ8mapUp( pTmpTile, pTile, ( (y-ySrc) % tly ) );
  90.         mfbDestroyPixmap( pTmpTile ) ;
  91.     }
  92.     else
  93.         pTile = pTmpTile ;
  94.     TileCopied = 1 ;
  95. }
  96. else if ( ( y - ySrc ) % tly ) {
  97.     if ( !( pTmpTile = ppcCreatePixmap( pScreen, tlx, tly, depth ) ) ) {
  98.         ErrorF( "Failed To Create Pixmap \"pTmpTile\" in ppcTileRect\n" ) ;
  99.         return ;
  100.     }
  101.     if (depth==1)
  102.         ppcRotBitmapUp( pTile, pTmpTile, ( ( y - ySrc ) % tly ) ) ;
  103.        else ppcRotZ8mapUp( pTile, pTmpTile, ( ( y - ySrc ) % tly ) ) ;
  104.     pTile = pTmpTile ;
  105.     TileCopied = 1 ;
  106. }
  107. else {
  108.     TileCopied = 0 ;
  109. }
  110.  
  111. fnp = ( (ppcScrnPriv *) (pScreen->devPrivate) )->imageFill ;
  112.  
  113. switch ( alu ) {
  114.     case GXcopyInverted:    /* 0xc NOT src */
  115.     case GXcopy:        /* 0x3 src */
  116.         /* Special Case Code */
  117.         vtarget = ( h > tly ) ? tly : h ;
  118.         if ( w >= tlx ) {
  119.             /* Note: Drawing with Height Less Than
  120.                The Actual Height Of The Image Will
  121.                Work Correctly */
  122.             (*fnp)( x, y,
  123.                 htarget = tlx,
  124.                 vtarget,
  125.                 pTile->devPrivate.ptr,pTile->devKind,
  126.                 alu, planes ) ;
  127.         }
  128.         else {
  129.             if ( !( pTmpTile = ppcCreatePixmap( pScreen,
  130.                                 htarget = w,
  131.                                    vtarget,
  132.                                 depth ) ) ) {
  133.                 ErrorF( "Failed To Create Short Pixmap in ppcTileRect\n" ) ;
  134.                 return ;
  135.             }
  136.             if (depth==1)
  137.                 ppcClipZ1Pixmap( pTile, pTmpTile ) ;
  138.                else ppcClipZ8Pixmap( pTile, pTmpTile ) ;
  139.  
  140.             (*fnp)( x, y,
  141.                 htarget,
  142.                 vtarget,
  143.                 pTmpTile->devPrivate.ptr,pTmpTile->devKind,
  144.                 alu, planes ) ;
  145.             mfbDestroyPixmap( pTmpTile ) ;
  146.         }
  147.         /* Here We Double The Size Of The BLIT Each Iteration */
  148.         ppcReplicateArea( x, y, planes, w, h,
  149.                   htarget, vtarget, pScreen ) ;
  150.         break ;
  151.     case GXnor:        /* 0x8 NOT src AND NOT dst */
  152.     case GXandReverse:    /* 0x2 src AND NOT dst */
  153.     case GXorReverse:    /* 0xb src OR NOT dst */
  154.     case GXnand:        /* 0xe NOT src OR NOT dst */
  155.     case GXandInverted:    /* 0x4 NOT src AND dst */
  156.     case GXand:        /* 0x1 src AND dst */
  157.     case GXequiv:        /* 0x9 NOT src XOR dst */
  158.     case GXxor:        /* 0x6 src XOR dst */
  159.     case GXorInverted:    /* 0xd NOT src OR dst */
  160.     case GXor:        /* 0x7 src OR dst */
  161.     default:
  162.         {
  163.         register int    hcount, vcount ;
  164.         register int    savevcount ;
  165.         register int    savehcount ;
  166.         char         *data ;
  167.         int        Rtlx, Btly ;
  168.     
  169.         savevcount = h / tly ;
  170.         savehcount = w / tlx ;
  171.     
  172.         /* FIRST DO COMPLETELY VISIBLE PORTIONS */
  173.         for ( data = (char *) pTile->devPrivate.ptr,
  174.               vcount = savevcount,
  175.               vtarget = y ;
  176.               vcount-- ;
  177.               vtarget += tly ) {
  178.             for ( hcount = savehcount,
  179.                   htarget = x ;
  180.                   hcount-- ;
  181.                   htarget += tlx ) {
  182.                 (*fnp)( htarget, vtarget,
  183.                     tlx, tly, data,pTile->devKind,
  184.                     alu, planes ) ;
  185.             }
  186.         }
  187.         
  188.         /* NOW DO RIGHT HAND SIDE */
  189.         if ( Rtlx = w % tlx ) {
  190.             if ( !( pTmpTile = ppcCreatePixmap( pScreen, Rtlx, tly, depth ) ) ) {
  191.                 ErrorF( "Failed To Create Right Pixmap in ppcTileRect\n" ) ;
  192.                 return ;
  193.             }
  194.             if (depth==1)
  195.                 ppcClipZ1Pixmap( pTile, pTmpTile ) ;
  196.                else ppcClipZ8Pixmap( pTile, pTmpTile ) ;
  197.         
  198.             for ( data = (char *) pTmpTile->devPrivate.ptr,
  199.                   vcount = savevcount,
  200.                   htarget = x + savehcount * tlx,
  201.                   vtarget = y ;
  202.                   vcount-- ;
  203.                   vtarget += tly ) {
  204.                 (*fnp)( htarget, vtarget,
  205.                     Rtlx, tly, data, pTmpTile->devKind,
  206.                     alu, planes ) ;
  207.             }
  208.             mfbDestroyPixmap( pTmpTile ) ;
  209.         }
  210.         
  211.         /* NOW DO BOTTOM */
  212.         if ( Btly = h % tly ) {
  213.             for ( data = (char *) pTile->devPrivate.ptr,
  214.                   hcount = savehcount,
  215.                   htarget = x,
  216.                   vtarget = y + savevcount * tly ;
  217.                   hcount-- ;
  218.                   htarget += tlx ) {
  219.                 (*fnp)( htarget, vtarget,
  220.                     tlx, Btly, data,pTile->devKind,
  221.                     alu, planes ) ;
  222.             }
  223.             if ( Rtlx ) {
  224.             /* NOW DO BOTTOM RIGHT CORNER */
  225.                 if ( !( pTmpTile = ppcCreatePixmap( pScreen, Rtlx, Btly, depth ) ) ) {
  226.                     ErrorF( "Failed To Create Corner Pixmap in ppcTileRect\n" ) ;
  227.                     return ;
  228.                 }
  229.                 if (depth==1)
  230.                     ppcClipZ1Pixmap( pTile, pTmpTile ) ;
  231.                    else ppcClipZ8Pixmap( pTile, pTmpTile ) ;
  232.                 (*fnp)( ( x + savehcount * tlx ),
  233.                     ( y + savevcount * tly ),
  234.                     Rtlx, Btly, pTmpTile->devPrivate.ptr,
  235.                     pTmpTile->devKind, alu, planes ) ;
  236.                 mfbDestroyPixmap( pTmpTile ) ;
  237.             }
  238.         }
  239.     }
  240.     break ;
  241. }
  242.  
  243. if ( TileCopied )
  244.     mfbDestroyPixmap( pTile ) ;
  245.  
  246. return ;
  247. }
  248.