home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / dec / qdss / qddopixel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-19  |  8.1 KB  |  307 lines

  1. /***********************************************************
  2. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #include <sys/types.h>
  26. #include <stdio.h>    /* debug */
  27.  
  28. #include "X.h"
  29. #include "windowstr.h"
  30. #include "regionstr.h"
  31. #include "pixmap.h"
  32. #include "gcstruct.h"
  33. #include "dixstruct.h"
  34.  
  35. #include "Xproto.h"
  36. #include "Xprotostr.h"
  37. #include "mi.h"
  38. #include "Xmd.h"
  39.  
  40. /*
  41.  * driver headers
  42.  */
  43. #include "Ultrix2.0inc.h"
  44. #include <vaxuba/qduser.h>
  45. #include <vaxuba/qdioctl.h>
  46. #include <vaxuba/qdreg.h>
  47.  
  48. #include "qd.h"
  49. #include "qdgc.h"
  50.  
  51. #include "scrnintstr.h"
  52.  
  53. /* qddopixel(psrc, pdst, pGC)
  54.  *    does output to a (full-depth) pixel pointed to by pdst
  55.  *      dst byte from pPoint in pPixmap
  56.  *        alu (with dst pixel), planemask, {fg, bg} on fillStyle
  57.  *   NOT: tiling, stippling, opaquestippling, clipping
  58.  */
  59.  
  60.  
  61. unsigned char
  62. qdlogic(src, dst, alu, planebyte)
  63.     unsigned char    src, dst;
  64.     int            alu;
  65.     unsigned char    planebyte;
  66. {
  67.     unsigned char    aluout;
  68.  
  69.     switch (alu)
  70.     {
  71.       case GXclear:
  72.     aluout = 0;
  73.     break;
  74.       case GXand:
  75.     aluout = src & dst;
  76.     break;
  77.       case GXandReverse:
  78.     aluout = src & ~dst;
  79.     break;
  80.       case GXcopy:
  81.     aluout = src;
  82.     break;
  83.       case GXandInverted:
  84.     aluout = ~src & dst;
  85.     break;
  86.       case GXnoop:
  87.     aluout = dst;
  88.     break;
  89.       case GXxor:
  90.     aluout = src ^ dst;
  91.     break;
  92.       case GXor:
  93.     aluout = src | dst;
  94.     break;
  95.       case GXnor:
  96.     aluout = ~(src | dst);
  97.     break;
  98.       case GXequiv:
  99.     aluout = ~src ^ dst;
  100.     break;
  101.       case GXinvert:
  102.     aluout = ~dst;
  103.     break;
  104.       case GXorReverse:
  105.     aluout = src | ~dst;
  106.     break;
  107.       case GXcopyInverted:
  108.     aluout = ~src;
  109.     break;
  110.       case GXorInverted:
  111.     aluout = ~src | dst;
  112.     break;
  113.       case GXnand:
  114.     aluout = ~(src & dst);
  115.     break;
  116.       case GXset:
  117.     aluout = ~0;
  118.     break;
  119.     }
  120.     dst = (aluout & planebyte) | (dst & ~planebyte);
  121.     return(dst);
  122. }
  123.  
  124. extern    int    Nentries;
  125. extern    int    Nplanes;
  126. extern unsigned int Allplanes;
  127. #if NPLANES==24
  128. extern    int    Nchannels;
  129. #define FOR_EACH_CHANNEL for (icolor = 0; icolor < Nchannels; icolor++)
  130. #else
  131. #define Nchannels 1
  132. #define FOR_EACH_CHANNEL /* no loop */
  133. #define icolor 0
  134. #endif
  135.  
  136. void
  137. #if NPLANES==24
  138. qddopixel(psrc, pdst, pGC, igreen)
  139. #else
  140. qddopixel(psrc, pdst, pGC)
  141. #endif
  142.     unsigned char *    psrc;
  143.     register unsigned char *    pdst;
  144. #if 0
  145.     PixmapPtr        pPixmap;
  146.     DDXPointPtr        pPoint;
  147. #endif
  148.     GCPtr        pGC;
  149. {
  150.     QDPrivGCPtr        pPriv;
  151.     register unsigned char *    ptable;
  152. #if NPLANES==24
  153.     int            igreen = QDPIX_WIDTH(pPixmap) * QDPIX_HEIGHT(pPixmap);
  154.     int            icolor;
  155. #endif
  156. #if 0
  157.     register unsigned char *    pdst;
  158.     pdst = QD_PIX_DATA(pPixmap) + pPoint->x + pPoint->y * QDPIX_WIDTH(pPixmap);
  159. #endif
  160.     pPriv = (QDPrivGCPtr) (pGC->devPrivates[qdGCPrivateIndex].ptr);
  161.     ptable = pPriv->ptresult;
  162. #ifdef DEBUGDOPIXEL
  163.     if (!pPriv)
  164.         FatalError("GC devprivate == NULL in qddopixel\n");
  165.     if (*psrc > 1 && pGC->fillStyle & (FillStippled|FillOpaqueStippled))
  166.         FatalError("src byte > 1 for stippling case in qddopixel\n");
  167. #endif
  168.     if (pPriv->mask & QD_NEWLOGIC)
  169.     {
  170.     int    idst;
  171.  
  172.     switch (pGC->alu)
  173.     {
  174.       case GXclear:
  175.       case GXset:
  176.         pPriv->mask = QD_LOOKUP|QD_DSTBYTE;
  177.         if (pPriv->ptresult)
  178.         Xfree(pPriv->ptresult);
  179.         pPriv->igreen = 256;
  180.         pPriv->ptresult = (unsigned char *)
  181.         Xalloc(NPLANES*32*sizeof(unsigned char));
  182.         ptable = pPriv->ptresult;
  183.         FOR_EACH_CHANNEL {
  184.             for (idst = 0; idst < 256; idst++, ptable++)
  185.                 *ptable = qdlogic(0, (unsigned char) idst, pGC->alu,
  186.             *((unsigned char *)&(pGC->planemask) + icolor));
  187.         }
  188.         break;
  189.       case GXnoop:
  190.       case GXinvert:
  191.         pPriv->mask = QD_LOOKUP|QD_DSTBYTE;
  192.         if (pPriv->ptresult)
  193.         Xfree(pPriv->ptresult);
  194.         pPriv->igreen = 256;
  195.         pPriv->ptresult = (unsigned char *)
  196.         Xalloc(NPLANES*32*sizeof(unsigned char));
  197.         ptable = pPriv->ptresult;
  198.         FOR_EACH_CHANNEL {
  199.             for (idst = 0; idst < 256; idst++, ptable++)
  200.                 *ptable = qdlogic(0, (unsigned char) idst, pGC->alu,
  201.             *((unsigned char *)&(pGC->planemask) + icolor));
  202.         }
  203.         break;
  204.       case GXcopy:
  205.       case GXcopyInverted:
  206.         if ((pGC->planemask & Allplanes) == Allplanes)
  207.         {
  208.             pPriv->mask = QD_LOOKUP;
  209.             if (pPriv->ptresult)
  210.             Xfree(pPriv->ptresult);
  211.             pPriv->igreen = 256;
  212.             pPriv->ptresult = (unsigned char *)
  213.             Xalloc(NPLANES*32*sizeof(unsigned char));
  214.             ptable = pPriv->ptresult;
  215.         FOR_EACH_CHANNEL {
  216.                 for (idst = 0; idst < 256; idst++, ptable++)
  217.                     *ptable = qdlogic((unsigned char) idst, 0,
  218.                 pGC->alu, 255);
  219.             }
  220.         break;
  221.         }
  222.       default:
  223. #ifndef FASTSTIP
  224.         pPriv->mask = 0;
  225.         if (pPriv->ptresult)
  226.         Xfree(pPriv->ptresult);
  227.         pPriv->ptresult = (unsigned char *) NULL;
  228. #else
  229.             switch (pGC->fillStyle)
  230.         {
  231.               case FillSolid:
  232.           case FillTiled:
  233.             pPriv->mask = 0;
  234.             if (pPriv->ptresult)
  235.                Xfree(pPriv->ptresult);
  236.          pPriv->ptresult = (unsigned char *) NULL;
  237.             break;
  238.           case FillOpaqueStippled:
  239.             pPriv->mask = QD_LOOKUP|QD_SRCBIT|QD_DSTBYTE;
  240.             if (pPriv->ptresult)
  241.             Xfree(pPriv->ptresult);
  242.             pPriv->igreen = 512;
  243.             pPriv->ptresult = (unsigned char *)
  244.             Xalloc(NPLANES*64*sizeof(unsigned char));
  245.             ptable = pPriv->ptresult;
  246.         FOR_EACH_CHANNEL {
  247.                 for (idst = 0; idst < 256; idst++, ptable++)
  248.                     *ptable = qdlogic((unsigned char *) &pGC->bgPixel,
  249.                 (unsigned char) idst, pGC->alu, 255);
  250.                 for (idst = 0; idst < 256; idst++, ptable++)
  251.                     *ptable = qdlogic((unsigned char *) &pGC->fgPixel,
  252.                 (unsigned char) idst, pGC->alu, 255);
  253.             }
  254.             break;
  255.           case FillStippled:
  256.             pPriv->mask = QD_LOOKUP|QD_SRCBIT|QD_DSTBYTE;
  257.             if (pPriv->ptresult)
  258.              Xfree(pPriv->ptresult);
  259.             pPriv->igreen = 512;
  260.             pPriv->ptresult = (unsigned char *)
  261.             Xalloc(NPLANES*64*sizeof(unsigned char));
  262.             ptable = pPriv->ptresult;
  263.             FOR_EACH_CHANNEL {
  264.                 for (idst = 0; idst < 256; idst++, ptable++)
  265.                     *ptable = qdlogic(0, (unsigned char) idst, GXnoop, 255);
  266.                 for (idst = 0; idst < 256; idst++, ptable++)
  267.                     *ptable = qdlogic((unsigned char *) &pGC->fgPixel,
  268.                 (unsigned char) idst, pGC->alu, 255);
  269.             }
  270.             break;
  271.         }
  272. #endif
  273.         break;
  274.     }
  275.     ptable = pPriv->ptresult;
  276.     }
  277. #if NPLANES == 24
  278.     for (icolor = 0; icolor < Nchannels; icolor++, pdst += igreen, psrc++,
  279.     ptable += pPriv->igreen)
  280. #endif
  281.     {
  282.         switch (pPriv->mask)
  283.     {
  284.           case QD_LOOKUP:
  285.           case QD_LOOKUP|QD_SRCBIT:
  286.         *pdst = *(ptable + *psrc);
  287.         break;
  288.           case QD_LOOKUP|QD_DSTBYTE:
  289.         *pdst = *(ptable + *pdst);
  290.         break;
  291.     /*    case QD_LOOKUP|QD_SRCBIT|QD_DSTBYTE:
  292.      *        *pdst = *(ptable + *pdst + (*psrc << 8));
  293.      *        break;
  294.      */
  295.           case 0:
  296.             *pdst = qdlogic(*psrc, *pdst, pGC->alu,
  297.                 *((unsigned char *)&(pGC->planemask) + icolor));
  298.         break;
  299. #ifdef DEBUGDOPIXEL
  300.           default:
  301.         FatalError("illegal lookup type in GC private structure\n");
  302.         break;
  303. #endif
  304.         }
  305.     }
  306. }
  307.