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 / emulStip.c < prev    next >
C/C++ Source or Header  |  1989-11-07  |  5KB  |  149 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. /* ppc Stipple
  24.  *
  25.  * Uses private monoFill a bunch of times
  26.  */
  27.  
  28. #include "X.h"
  29. #include "pixmapstr.h"
  30. #include "pixmap.h"
  31. #include "scrnintstr.h"
  32.  
  33. #include "ppc.h"
  34. #include "ibmTrace.h"
  35.  
  36. extern PixmapPtr ppcCopyPixmap() ;
  37.  
  38. void
  39. ppcStipple( pStipple, fg, merge, planes, x, y, w, h, xSrc, ySrc )
  40. PixmapPtr pStipple ;
  41. unsigned long int fg ;
  42. int merge ;
  43. unsigned long int planes ;
  44. int x, y, w, h ;
  45. int xSrc, ySrc ;
  46. {
  47. register void    (*fnp)() ;
  48. register char     *data ;
  49. register int     htarget, vtarget, tlx, tly ;
  50. PixmapPtr     pUseStipple, pTmpStipple ;
  51. int         savehcount, savevcount, hcount, vcount,
  52.         xfits, xrot, yrot, Rtlx, Btly ;
  53.  
  54.     TRACE( ( "ppcStipple(pStipple = x%x, merge= x%x, planes=x%02x, x=%d, y=%d, w=%d, h=%d, xSrc=%d, ySrc=%d\n",
  55.         pStipple, merge, planes, x, y, w, h, xSrc, ySrc ) ) ;
  56.  
  57.     pUseStipple = pStipple ;
  58.  
  59.     if ( xrot = ( ( x - xSrc ) % ( tlx = pStipple->drawable.width ) ) ) {
  60.     if ( !( pTmpStipple = ppcCopyPixmap( pStipple ) ) ) {
  61.         ErrorF("Fail ppcCopyPixmap \"pTmpStipple\" in ppcStipple\n" ) ;
  62.         return ;
  63.     }
  64.     ppcRotBitmapRight( pTmpStipple, tlx - xrot ) ;
  65.     pUseStipple = pTmpStipple ;
  66.     }
  67.  
  68.     if ( yrot = ( ( y - ySrc ) % ( tly = pStipple->drawable.height ) ) ) {
  69.     if ( !( pTmpStipple = ppcCopyPixmap( pUseStipple ) ) ) {
  70.         ErrorF( "Fail ppcCopyPixmap 2 \"pTmpStipple\" in ppcStipple\n");
  71.         return ;
  72.     }
  73.     ppcRotBitmapDown( pTmpStipple, tly - yrot ) ;
  74.     if (xrot)
  75.         mfbDestroyPixmap( pUseStipple ) ;
  76.  
  77.     pUseStipple = pTmpStipple ;
  78.     }
  79.  
  80. /* By here, pUseStipple points to the (possibly rotated) tile. If it is rotated,
  81.    then it is the only newly created PIxmap, which we must destroy at the end.*/
  82.  
  83.     savehcount = w / tlx ;
  84.     savevcount = h / tly ;
  85.  
  86.     fnp = ((ppcScrnPriv *)(pStipple->drawable.pScreen->devPrivate) )->monoFill ;
  87. /* FIRST DO COMPLETELY VISIBLE PORTIONS */
  88.     data = (char *) pUseStipple->devPrivate.ptr ;
  89.     for ( vcount = savevcount, vtarget = y ;
  90.       vcount-- ;
  91.       vtarget += tly )
  92.     for ( htarget = x, hcount = savehcount ;
  93.           hcount-- ;
  94.           htarget += tlx )
  95.         (*fnp)( data, htarget, vtarget, tlx, tly, fg, merge, planes ) ;
  96.  
  97. /* NOW DO RIGHT HAND SIDE */
  98.     if ( Rtlx = w % tlx ) {
  99.     /* htarget is already set to ( x + ( savehcount * tlx ) ) from above */
  100.     xfits = ( ( ( ( Rtlx + 31 ) & ~31 ) == ( ( tlx + 31 ) & ~31 ) )
  101.         ? -1 : 0 ) ;
  102.     if (xfits)
  103.         for ( vcount = savevcount, vtarget = y ;
  104.                   vcount-- ;
  105.                   vtarget += tly )
  106.                 (*fnp)( data, htarget, vtarget, 
  107.                     Rtlx, tly, fg, merge, planes ) ;
  108.        else
  109.         for ( vcount = savevcount, vtarget = y ;
  110.                   vcount-- ;
  111.                   vtarget += tly ) {
  112.             int th = tly ;
  113.             int tvtarget = vtarget ;
  114.             unsigned char *tdata = data ;
  115.             while ( th-- ) {
  116.                 (*fnp)( tdata, htarget, tvtarget++, 
  117.                     Rtlx, 1, fg, merge, planes ) ;
  118.                 tdata += pStipple->devKind ;
  119.             }
  120.         }
  121.     }
  122.  
  123. /* NOW DO BOTTOM */
  124.     if ( Btly = h % tly )
  125.     /* vtarget is already set to ( x + ( savevcount * tly ) ) from above */
  126.     for ( hcount = savehcount, htarget = x ;
  127.               hcount-- ;
  128.               htarget += tlx )
  129.         (*fnp)( data, htarget, vtarget, tlx, Btly, fg, merge, planes ) ;
  130.  
  131. /* NOW DO BOTTOM RIGHT CORNER */
  132.     if ( Btly && Rtlx )
  133.     /* htarget is already set to ( x + ( savehcount * tlx ) ) from above */
  134.     /* vtarget is already set to ( x + ( savevcount * tly ) ) from above */
  135.     if (xfits)
  136.         (*fnp)( data, htarget, vtarget, Rtlx, Btly, fg, merge, planes) ;
  137.     else
  138.         while ( Btly-- ) {
  139.             (*fnp)( data, htarget, vtarget++, 
  140.                 Rtlx, 1, fg, merge, planes ) ;
  141.             data += pStipple->devKind ;
  142.         }
  143.  
  144.     if ( xrot || yrot )
  145.     mfbDestroyPixmap( pUseStipple ) ;
  146.  
  147.     return ;
  148. }
  149.