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 / ppcCReduce.c < prev    next >
C/C++ Source or Header  |  1989-11-14  |  7KB  |  259 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: /andrew/X11/R3src/tape/server/ddx/ibm/ppc/RCS/ppcCReduce.c,v 9.1 88/10/24 03:59:37 paul Exp $ */
  25. /* $Source: /andrew/X11/R3src/tape/server/ddx/ibm/ppc/RCS/ppcCReduce.c,v $ */
  26.  
  27. #ifndef lint
  28. static char *rcsid = "$Header: /andrew/X11/R3src/tape/server/ddx/ibm/ppc/RCS/ppcCReduce.c,v 9.1 88/10/24 03:59:37 paul Exp $";
  29. #endif
  30.  
  31. #include "X.h"
  32. #include "misc.h"
  33. #include "gcstruct.h"
  34. #include "pixmapstr.h"
  35. #include "colormapst.h"
  36. #include "ppc.h"
  37.  
  38. /* ppcGetReducedColorRrop( pGC, drawableDepth, returnLoc )
  39.  * An attempt to do "strength reduction" on color raster-ops
  40.  * P. Shupak 1/88
  41.  */
  42.  
  43. void 
  44. ppcReduceGeneral( alu, pm, fg, bg, fillStyle, drawableDepth, returnLoc )
  45. register int        alu ;
  46. register unsigned long    pm ;
  47. register unsigned long    fg ;
  48. register unsigned long    bg ;
  49. register int        fillStyle ;
  50. int            drawableDepth ;
  51. ppcReducedRrop        *returnLoc ;
  52. {
  53.  
  54. if ( ( alu == GXnoop )
  55.   || !( pm &= ( ( 1 << drawableDepth ) - 1 ) ) ) {
  56.     returnLoc->alu = GXnoop ;
  57.     return ;
  58. }
  59.  
  60. switch ( fillStyle ) {
  61.     case FillTiled:
  62.         switch ( alu ) {
  63.             case GXclear:        /* 0x0 Zero 0 */
  64.             case GXinvert:        /* 0xa NOT dst */
  65.             case GXset:        /* 0xf 1 */
  66.                 fillStyle = FillSolid ;
  67.             default: /* We Can't Do Much Here */
  68.                 break ;
  69.         }
  70.         break ;
  71.     case FillOpaqueStippled:
  72.         if ( ( fg & pm ) != ( bg & pm ) ) { /* else FillSolid */
  73.             switch ( alu ) {
  74.                 case GXclear:    /* 0x0 Zero 0 */
  75.                 case GXset:    /* 0xf 1 */
  76.                 case GXinvert:    /* 0xa NOT dst */
  77.                     fillStyle = FillSolid ;
  78.                     break ;
  79.                 case GXnor:    /* 0x8 NOT src AND NOT dst */
  80.                 case GXnand:    /* 0xe NOT src OR NOT dst */
  81.                 case GXcopy:    /* 0x3 src */
  82.                     break ;
  83.                 case GXandReverse: /* 0x2 src AND NOT dst */
  84.                     fg = ~fg ;
  85.                     bg = ~bg ;
  86.                     alu = GXnor ;
  87.                     break ;
  88.                 case GXandInverted: /* 0x4 NOT src AND dst */
  89.                     fg = ~fg ;
  90.                     bg = ~bg ;
  91.                     alu = GXand ; /* Fall Through */
  92.                 case GXand:    /* 0x1 src AND dst */
  93.                     pm &= ~( fg & bg ) ;
  94.                     if ( ( bg & pm ) == pm ) {
  95.                         fillStyle = FillStippled ;
  96.                         alu = GXclear ;
  97.                     }
  98.                     break ;
  99.                 case GXequiv:    /* 0x9 NOT src XOR dst */
  100.                     fg = ~fg ;
  101.                     bg = ~bg ;
  102.                     alu = GXxor ; /* Fall Through */
  103.                 case GXxor:    /* 0x6 src XOR dst */
  104.                     pm &= ( fg | bg ) ;
  105.                     if ( !( bg & pm ) ) {
  106.                         fillStyle = FillStippled ;
  107.                         alu = GXinvert ;
  108.                     }
  109.                     break ;
  110.                 case GXorReverse:    /* 0xb src OR NOT dst */
  111.                     fg = ~fg ;
  112.                     bg = ~bg ;
  113.                     alu = GXnand ;
  114.                     break ;
  115.                 case GXcopyInverted:    /* 0xc NOT src */
  116.                     fg = ~fg ;
  117.                     bg = ~bg ;
  118.                     alu = GXcopy ;
  119.                     break ;
  120.                 case GXorInverted:    /* 0xd NOT src OR dst */
  121.                     fg = ~fg ;
  122.                     bg = ~bg ;
  123.                     alu = GXor ; /* Fall Through */
  124.                 case GXor:    /* 0x7 src OR dst */
  125.                     pm &= ( fg | bg ) ;
  126.                     if ( !( bg & pm ) ) {
  127.                         fillStyle = FillStippled ;
  128.                         alu = GXset ;
  129.                     }
  130.                     break ;
  131.                 default:
  132.                     ErrorF(
  133.              "ppcGetReducedColorRrop: Unknown Alu Raster-Op" ) ;
  134.                     break ;
  135.             }
  136.             break ; /* Don't Fall Through */
  137.         }
  138.         else
  139.             fillStyle = FillSolid ;
  140.             /* Fall Through */
  141.     case FillStippled:
  142.     case FillSolid:
  143.         switch ( alu ) {
  144.             case GXclear:        /* 0x0 Zero 0 */
  145.             case GXset:        /* 0xf 1 */
  146.             case GXinvert:        /* 0xa NOT dst */
  147.                 break ;
  148.             case GXand:        /* 0x1 src AND dst */
  149.                 pm &= ~fg ;
  150.                 alu = GXclear ;
  151.                 break ;
  152.             case GXandReverse:    /* 0x2 src AND NOT dst */
  153.                 fg = ~fg ;
  154.                 alu = GXnor ; /* Fall Through */
  155.             case GXnor:        /* 0x8 NOT src AND NOT dst */
  156.                 if ( !( fg & pm ) )
  157.                     alu = GXclear ;
  158.                 else if ( ( fg & pm ) == pm )
  159.                     alu = GXinvert ;
  160.                 break ;
  161.             case GXandInverted:    /* 0x4 NOT src AND dst */
  162.                 pm &= fg ;
  163.                 alu = GXclear ;
  164.                 break ;
  165.             case GXxor:        /* 0x6 src XOR dst */
  166.                 pm &= fg ;
  167.                 alu = GXinvert ;
  168.                 break ;
  169.             case GXor:        /* 0x7 src OR dst */
  170.                 pm &= fg ;
  171.                 alu = GXset ;
  172.                 break ;
  173.             case GXequiv:        /* 0x9 NOT src XOR dst */
  174.                 pm &= ~fg ;
  175.                 alu = GXinvert ;
  176.                 break ;
  177.             case GXorReverse:    /* 0xb src OR NOT dst */
  178.                 fg = ~fg ;
  179.                 alu = GXnand ; /* Fall Through */
  180.             case GXnand:        /* 0xe NOT src OR NOT dst */
  181.                 if ( !( fg & pm ) )
  182.                     alu = GXset ;
  183.                 else if ( ( fg & pm ) == pm )
  184.                     alu = GXinvert ;
  185.                 break ;
  186.             case GXcopyInverted:    /* 0xc NOT src */
  187.                 fg = ~fg ;
  188.                 alu = GXcopy ; /* Fall Through */
  189.             case GXcopy:        /* 0x3 src */
  190.                 if ( !( fg & pm ) )
  191.                     alu = GXclear ;
  192.                 else if ( ( fg & pm ) == pm )
  193.                     alu = GXset ;
  194.                 break ;
  195.             case GXorInverted:    /* 0xd NOT src OR dst */
  196.                 pm &= ~fg ;
  197.                 alu = GXset ;
  198.                 break ;
  199.             default:
  200.                 ErrorF(
  201.              "ppcGetReducedColorRrop: Unknown Alu Raster-Op" ) ;
  202.                 break ;
  203.         }
  204.         break;
  205.     default:
  206.         ErrorF("ppcGetReducedColorRrop: Bad Fillstyle\n");
  207.         break;
  208. }
  209.  
  210. /* Final Test On Restricted Plane Mask */
  211. if ( !pm )
  212.     alu = GXnoop ;
  213.  
  214. /* Set Actual Returned Values */
  215. returnLoc->planemask = pm ;
  216. returnLoc->fgPixel   = fg ;
  217. returnLoc->bgPixel   = bg ;
  218. returnLoc->alu       = alu ;
  219. returnLoc->fillStyle = fillStyle ;
  220.  
  221. return ;
  222. }
  223.  
  224. void 
  225. ppcReduceColorRrop( initialLoc, drawableDepth, returnLoc )
  226. ppcReducedRrop    *initialLoc ;
  227. int        drawableDepth ;
  228. ppcReducedRrop    *returnLoc ;
  229. {
  230.  
  231. ppcReduceGeneral( initialLoc->alu,
  232.           initialLoc->planemask,
  233.           initialLoc->fgPixel,
  234.           initialLoc->bgPixel,
  235.            initialLoc->fillStyle,
  236.           drawableDepth,
  237.           returnLoc ) ;
  238.  
  239. return ;
  240. }
  241.  
  242. void 
  243. ppcGetReducedColorRrop( pGC, drawableDepth, returnLoc )
  244. GC        *pGC ;
  245. int        drawableDepth ;
  246. ppcReducedRrop    *returnLoc ;
  247. {
  248.  
  249. ppcReduceGeneral( pGC->alu,
  250.           pGC->planemask,
  251.           pGC->fgPixel,
  252.           pGC->bgPixel,
  253.            pGC->fillStyle,
  254.           drawableDepth,
  255.           returnLoc ) ;
  256.  
  257. return ;
  258. }
  259.