home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfbimage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-14  |  5.1 KB  |  161 lines

  1. /***********************************************************
  2. Copyright 1987 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. /* $XConsortium: mfbimage.c,v 5.3 89/09/14 16:26:42 rws Exp $ */
  25.  
  26. #include "X.h"
  27.  
  28. #include "windowstr.h"
  29. #include "pixmapstr.h"
  30. #include "scrnintstr.h"
  31. #include "gcstruct.h"
  32.  
  33. #include "mfb.h"
  34. #include "mi.h"
  35. #include "Xmd.h"
  36.  
  37. #include "maskbits.h"
  38.  
  39. #include "servermd.h"
  40.  
  41. /* Put and Get images on a monochrome frame buffer
  42.  *
  43.  *   we do this by creating a temporary pixmap and making its
  44.  * pointer to bits point to the buffer read in from the client.
  45.  * this works because of the padding rules specified at startup
  46.  *
  47.  * Note that CopyArea must know how to copy a bitmap into the server-format
  48.  * temporary pixmap.
  49.  *
  50.  * For speed, mfbPutImage should allocate the temporary pixmap on the stack.
  51.  *
  52.  *     even though an XYBitmap and an XYPixmap have the same
  53.  * format (for this device), PutImage has different semantics for the
  54.  * two.  XYPixmap just does the copy; XYBitmap takes gc.fgPixel for
  55.  * a 1 bit, gc.bgPixel for a 0 bit, which we notice is exactly
  56.  * like CopyPlane.
  57.  *
  58.  *   written by drewry, september 1986
  59.  */
  60.  
  61.  
  62. /*ARGSUSED*/
  63. void
  64. mfbPutImage(dst, pGC, depth, x, y, w, h, leftPad, format, pImage)
  65.     DrawablePtr dst;
  66.     GCPtr    pGC;
  67.     int        depth, x, y, w, h;
  68.     int leftPad;
  69.     unsigned int format;
  70.     int     *pImage;
  71. {
  72.     PixmapRec    FakePixmap;
  73.  
  74.     if (!(pGC->planemask & 1))
  75.     return;
  76.  
  77.     /* 0 may confuse CreatePixmap, and will sometimes be
  78.        passed by the mi text code
  79.     */
  80.     if ((w == 0) || (h == 0))
  81.     return;
  82.  
  83.     FakePixmap.drawable.type = DRAWABLE_PIXMAP;
  84.     FakePixmap.drawable.class = 0;
  85.     FakePixmap.drawable.pScreen = dst->pScreen;
  86.     FakePixmap.drawable.depth = 1;
  87.     FakePixmap.drawable.bitsPerPixel = 1;
  88.     FakePixmap.drawable.id = 0;
  89.     FakePixmap.drawable.serialNumber = NEXT_SERIAL_NUMBER;
  90.     FakePixmap.drawable.x = 0;
  91.     FakePixmap.drawable.y = 0;
  92.     FakePixmap.drawable.width = w+leftPad;
  93.     FakePixmap.drawable.height = h;
  94.     FakePixmap.devKind = PixmapBytePad(FakePixmap.drawable.width, 1);
  95.     FakePixmap.refcnt = 1;
  96.     FakePixmap.devPrivate.ptr = (pointer)pImage;
  97.     ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->fExpose = FALSE;
  98.     if (format != XYBitmap)
  99.     (*pGC->ops->CopyArea)(&FakePixmap, dst, pGC, leftPad, 0, w, h, x, y);
  100.     else
  101.     (*pGC->ops->CopyPlane)(&FakePixmap, dst, pGC, leftPad, 0, w, h, x, y, 1);
  102.     ((mfbPrivGC*)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->fExpose = TRUE;
  103. }
  104.  
  105.  
  106. /*
  107.  * pdstLine points to space allocated by caller, which he can do since
  108.  * he knows dimensions of the pixmap
  109.  * we can call mfbDoBitblt because the dispatcher has promised not to send us
  110.  * anything that would require going over the edge of the screen.
  111.  *
  112.  *    XYPixmap and ZPixmap are the same for mfb.
  113.  *    For any planemask with bit 0 == 0, just fill the dst with 0.
  114.  */
  115. /*ARGSUSED*/
  116. void
  117. mfbGetImage( pDrawable, sx, sy, w, h, format, planeMask, pdstLine)
  118.     DrawablePtr pDrawable;
  119.     int        sx, sy, w, h;
  120.     unsigned int format;
  121.     unsigned long planeMask;
  122.     pointer    pdstLine;
  123. {
  124.     PixmapRec FakePixmap;
  125.     BoxRec box;
  126.     DDXPointRec ptSrc;
  127.     RegionRec rgnDst;
  128.  
  129.     if (planeMask & 0x1)
  130.     {
  131.     FakePixmap.drawable.type = DRAWABLE_PIXMAP;
  132.     FakePixmap.drawable.class = 0;
  133.     FakePixmap.drawable.pScreen = pDrawable->pScreen;
  134.     FakePixmap.drawable.depth = 1;
  135.     FakePixmap.drawable.bitsPerPixel = 1;
  136.     FakePixmap.drawable.id = 0;
  137.     FakePixmap.drawable.serialNumber = NEXT_SERIAL_NUMBER;
  138.     FakePixmap.drawable.x = 0;
  139.     FakePixmap.drawable.y = 0;
  140.     FakePixmap.drawable.width = w;
  141.     FakePixmap.drawable.height = h;
  142.     FakePixmap.devKind = PixmapBytePad(w, 1);
  143.     FakePixmap.refcnt = 1;
  144.     FakePixmap.devPrivate.ptr = pdstLine;
  145.         ptSrc.x = sx + pDrawable->x;
  146.         ptSrc.y = sy + pDrawable->y;
  147.         box.x1 = 0;
  148.         box.y1 = 0;
  149.         box.x2 = w;
  150.         box.y2 = h;
  151.         (*pDrawable->pScreen->RegionInit)(&rgnDst, &box, 1);
  152.         mfbDoBitblt(pDrawable, (DrawablePtr)&FakePixmap,
  153.             GXcopy, &rgnDst, &ptSrc);
  154.         (*pDrawable->pScreen->RegionUninit)(&rgnDst);
  155.     }
  156.     else
  157.     {
  158.     bzero((char *)pdstLine, PixmapBytePad(w, 1) * h);
  159.     }
  160. }
  161.