home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / dec / qdss / qdimage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-19  |  9.0 KB  |  337 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 "X.h"
  26.  
  27. #include "Xmd.h"
  28. #include "servermd.h"
  29. #include "misc.h"
  30. #include "gcstruct.h"
  31. #include "pixmapstr.h"
  32. #include "windowstr.h"
  33. #include "scrnintstr.h"
  34.  
  35. #include "qd.h"
  36. #include "qdgc.h"
  37. #include "qdprocs.h"
  38.  
  39. static void bitmapToScr(), bitmapToPixmap(), imageToPixmap();
  40.  
  41. #if NPLANES==24
  42. #define DOPIXEL(psrc, dst, pGC, delta) qddopixel(psrc, dst, pGC, delta)
  43. #else
  44. #define DOPIXEL(psrc, dst, pGC, delta) qddopixel(psrc, dst, pGC)
  45. #endif
  46.  
  47. void
  48. qdGetImage( pDraw, x, y, w, h, format, planemask, pImage)
  49.     DrawablePtr        pDraw;
  50.     int            x, y, w, h;
  51.     unsigned int    format;
  52.     unsigned long    planemask;
  53.     unsigned char    *pImage;
  54. {
  55.     switch( format)
  56.     {
  57.       case XYPixmap:
  58.     if ((pDraw->type == DRAWABLE_WINDOW /*&& no clipping*/)
  59.      || QDPIX_Y((QDPixPtr)pDraw) != NOTOFFSCREEN) {
  60.         int plane;
  61.         int bytesPerW = PixmapBytePad(w, 1);
  62.         int xAbs = x + pDraw->x, yAbs = y + pDraw->y;
  63.         for (plane = pDraw->depth; --plane >= 0; ) {
  64.         if ((1 << plane) & planemask) {
  65.             CopyFromOffscreen1(xAbs, yAbs, w, h,
  66.                        bytesPerW,
  67.                        pDraw->depth > 1
  68.                          ? 1 << plane
  69.                          : ((QDPixPtr)pDraw)->planes,
  70.                        pImage);
  71.             pImage += bytesPerW * h;
  72.         }
  73.         }
  74.     }
  75.     else
  76.         miGetImage( pDraw, x, y, w, h, format, planemask, pImage);
  77.     break;
  78.       case ZPixmap:
  79.     if ( pDraw->type == DRAWABLE_WINDOW)
  80.         tlgetimage(pDraw,
  81.                x + QDWIN_X((WindowPtr)pDraw),
  82.                y + QDWIN_Y((WindowPtr)pDraw),
  83.                w, h, planemask, pImage);
  84.     else
  85. /*#ifdef X11R4 This looks bad, folks! */
  86.         tlCancelPixmap(pDraw), 
  87.  
  88.         miGetImage( pDraw, x, y, w, h, format, planemask, pImage);
  89.     break;
  90.     }
  91. }
  92.  
  93. void
  94. qdPixPutImage( pDraw, pGC, depth, x, y, w, h, leftPad, format, pImage)
  95.     DrawablePtr        pDraw;
  96.     GCPtr        pGC;
  97.     int            depth, x, y, w, h, leftPad;
  98.     unsigned int    format;
  99.     unsigned char    *pImage;
  100. {
  101.     CHECK_MOVED(pGC, pDraw);
  102.     if (depth == 1 && format != XYBitmap) {
  103.     if (QD_PIX_DATA((PixmapPtr)pDraw) == NULL) {
  104.         SETUP_PIXMAP_AS_WINDOW(pDraw, pGC);
  105.         /* ignore {fg,bg}Pixel if gotten here via doBitmap */
  106.         pGC->fgPixel = Allplanes;
  107.         pGC->bgPixel = 0;
  108.         bitmapToScr(pGC, x, y, w, h, leftPad, pImage);
  109.         CLEANUP_PIXMAP_AS_WINDOW(pGC);
  110.         return;
  111.     }
  112.     else
  113.         goto doBitmap;
  114.     }
  115.     switch( format)
  116.     {
  117.       case XYBitmap:
  118.     if (QD_PIX_DATA((PixmapPtr)pDraw) == NULL) {
  119.         SETUP_PIXMAP_AS_WINDOW(pDraw, pGC);
  120.         bitmapToScr(pGC, x, y, w, h, leftPad, pImage);
  121.         CLEANUP_PIXMAP_AS_WINDOW(pGC);
  122.         break;
  123.     }
  124.       doBitmap:
  125.     if ( pDraw->depth > 1) {
  126.         bitmapToPixmap( (PixmapPtr)pDraw, pGC, x, y, w, h,
  127.                             leftPad, pImage);
  128.         break;
  129.     }
  130.     /* otherwise, fall through */
  131.       case XYPixmap:
  132.     miPutImage( pDraw, pGC, depth, x, y, w, h, leftPad, format, pImage);
  133.     break;
  134.       case ZPixmap:
  135.     if (QD_PIX_DATA((PixmapPtr)pDraw) == NULL)
  136.         tlputimage( pDraw, pGC, x, y, w, h, pImage);
  137.     else
  138.         imageToPixmap( pDraw, pGC, x, y, w, h, pImage );
  139.     break;
  140.     }
  141. }
  142.  
  143. void
  144. qdWinPutImage( pDraw, pGC, depth, x, y, w, h, leftPad, format, pImage)
  145.     WindowPtr        pDraw;
  146.     GCPtr        pGC;
  147.     int            depth, x, y, w, h, leftPad;
  148.     unsigned int    format;
  149.     unsigned char    *pImage;
  150. {
  151.     switch( format)
  152.     {
  153.       case XYBitmap:
  154.     bitmapToScr(pGC, x, y, w, h, leftPad, pImage);
  155.     break;
  156.       case XYPixmap:
  157.     {
  158.         int fgSave = pGC->fgPixel, bgSave = pGC->bgPixel;
  159.         int planemaskSave = pGC->planemask;
  160.         int i;
  161.         int bytesPerPlane = h * PixmapBytePad(w, 1);
  162.         pGC->fgPixel = -1; pGC->bgPixel = 0;
  163.         for (i = 1 << (pDraw->drawable.depth-1); i != 0; i >>= 1) {
  164.         if (i & planemaskSave) {
  165.             pGC->planemask = i;
  166.             bitmapToScr(pGC, x, y, w, h, leftPad, pImage);
  167.         }
  168.         pImage += bytesPerPlane;
  169.         }
  170.         pGC->fgPixel = fgSave; pGC->bgPixel = bgSave;
  171.         pGC->planemask = planemaskSave;
  172.     }
  173.     break;
  174.       case ZPixmap:
  175.     tlputimage( pDraw, pGC, x, y, w, h, pImage );
  176.     break;
  177.     }
  178. }
  179.  
  180. /*
  181.  * use the bitmap to select back or fore color from GC
  182.  */
  183. static void
  184. bitmapToScr(pGC, x, y, w, h, leftPad, pImage)
  185.     GCPtr               pGC;
  186.     int                 x, y, w, h, leftPad;
  187.     unsigned char       *pImage;
  188. {
  189.     PixmapRec    tempBMap[1];
  190.     int         ic;     /* clip rect index */
  191.     int    numRects = REGION_NUM_RECTS(QDGC_COMPOSITE_CLIP(pGC));
  192.     register BoxPtr rects = REGION_RECTS(QDGC_COMPOSITE_CLIP(pGC));
  193.     BoxPtr newRects;
  194.  
  195.  
  196.     x += pGC->lastWinOrg.x;
  197.     y += pGC->lastWinOrg.y;
  198.  
  199.     /*
  200.      * create a temporary bitmap and transplant pImage into it
  201.      */
  202.     QDPIX_WIDTH(tempBMap) = w+leftPad;
  203.     QDPIX_HEIGHT(tempBMap) = h;
  204.     tempBMap->devKind = PixmapBytePad(QDPIX_WIDTH(tempBMap), 1);
  205.     QD_PIX_DATA(tempBMap) = pImage;
  206.  
  207.     for ( ic=0; ic < numRects; ic++, rects++) {
  208.     int save_x1 = rects->x1;
  209. #if 1
  210.     if (x > rects->x1) rects->x1 = x;
  211. #endif
  212.     tlBitmapBichrome( pGC, tempBMap, pGC->fgPixel, pGC->bgPixel,
  213.         x - leftPad, y, rects);
  214.     rects->x1 = save_x1;
  215.     }
  216. }
  217.  
  218. /*
  219.  * use the bitmap to select back or fore color from GC
  220.  */
  221. static void
  222. bitmapToPixmap( pPix, pGC, x, y, w, h, leftPad, pImage)
  223.     PixmapPtr   pPix;
  224.     GCPtr       pGC;
  225.     int         x, y, w, h, leftPad;
  226.     unsigned char *pImage;
  227. {
  228.     int        ic;    /* clip rect index */
  229.     BoxPtr    pc = REGION_RECTS(QDGC_COMPOSITE_CLIP(pGC));
  230.  
  231.     int        br;    /* bitmap row */
  232.     register int bc;    /* bitmap column */
  233.     register unsigned *    pbr;    /* pointer to bitmap row */
  234.     int        bwlongs = PixmapWidthInPadUnits( w, 1); /* bitmap width
  235.                                 in longs */
  236.  
  237.     DDXPointRec    mp;    /* pixmap point */
  238.  
  239.     /*
  240.      * for each clipping rectangle
  241.      */
  242.     for (ic = REGION_NUM_RECTS(QDGC_COMPOSITE_CLIP(pGC)); --ic >= 0; pc++)
  243.     {
  244.     int    brlast = min( h, pc->y2-y);  /* last bitmap row to paint */
  245.       
  246.     /*
  247.      * for each row in the intersection of bitmap source and dest clip
  248.      */
  249.     for ( br = max( 0, pc->y1-y), mp.y = y + br,
  250.         pbr = (unsigned *) &pImage[ br*(bwlongs<<2) ];
  251.           br < brlast;
  252.           br++, mp.y++, pbr+=bwlongs
  253.         )
  254.     {
  255.         int    bclast = leftPad + min( w, pc->x2-x);
  256.  
  257.         /*
  258.          * for each column in the intersection
  259.          */
  260.         for ( bc = leftPad + max( 0, pc->x1-x), mp.x = x + (bc-leftPad);
  261.           bc < bclast;
  262.           bc++, mp.x++)
  263.         {
  264.         /*
  265.                  * examine each bit.
  266.                  */
  267.         /* XXX - now uses qddopixel below
  268.         unsigned char    pixel;
  269.                 pixel = ( pbr[ bc>>5] & (1 << (bc&0x1f)))
  270.                 ? pGC->fgPixel
  271.                 : pGC->bgPixel;
  272.         */
  273.         DOPIXEL((pbr[ bc>>5] & (1 << (bc&0x1f)))?
  274.             (unsigned char *) &pGC->fgPixel:
  275.             (unsigned char *) &pGC->bgPixel,
  276.             QD_PIX_DATA(pPix) + mp.x + mp.y * QDPIX_WIDTH(pPix),
  277.             pGC, QDPIX_WIDTH(pPix) * QDPIX_HEIGHT(pPix));
  278.         }
  279.     }
  280.     }
  281. }
  282.  
  283. /*
  284.  * transfer an image into a pixmap
  285.  */
  286. static void
  287. imageToPixmap( pPix, pGC, x, y, w, h, pImage)
  288.     PixmapPtr           pPix;
  289.     GCPtr               pGC;
  290.     int                 x, y, w, h;
  291.     unsigned char       *pImage;
  292. {
  293.     extern unsigned int Allplanes;
  294.     register unsigned char    *pcolor;    /* current z-val */
  295.     register int        minx, miny, maxy, width;
  296.     RegionPtr    pSaveGCclip = QDGC_COMPOSITE_CLIP(pGC);
  297.     register BoxPtr    pclip = REGION_RECTS(pSaveGCclip);
  298.     register int    nclip = REGION_NUM_RECTS(pSaveGCclip);
  299.     DDXPointRec        mp;    /* pixmap point */
  300.     int fast = pGC->alu == GXcopy && (pGC->planemask & Allplanes) == Allplanes;
  301.  
  302.     /*
  303.      * for each clipping rectangle
  304.      */
  305.     for ( ; nclip > 0; nclip--, pclip++)
  306.     {
  307.     minx = max(x,    pclip->x1);
  308.     width= min(x+w,    pclip->x2) - minx;
  309.     miny = max(y,    pclip->y1);
  310.     maxy = min(y+h,    pclip->y2);
  311.  
  312.         if (width <= 0) return;
  313.  
  314.     for (mp.y = miny; mp.y < maxy; mp.y++)
  315.     {
  316.         int i;
  317.         unsigned char *pdst =
  318.         QD_PIX_DATA(pPix) + minx + mp.y * QDPIX_WIDTH(pPix);
  319.         pcolor =
  320.         pImage + (NPLANES/8)*((mp.y-y) * QDPIX_WIDTH(pPix) + (minx-x));
  321.  
  322. #if NPLANES<24
  323.             if (fast)
  324.         bcopy(pcolor, pdst, width);
  325.         else
  326. #endif
  327.         for (i = width; --i >= 0; pdst++)
  328.         {
  329.         DOPIXEL(pcolor, pdst, pGC,
  330.             QDPIX_WIDTH(pPix) * QDPIX_HEIGHT(pPix));
  331.         pcolor += (NPLANES/8);
  332.         }
  333.     }
  334.     }
  335. }
  336.  
  337.