home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_CrPixmap.c < prev    next >
C/C++ Source or Header  |  2001-06-08  |  4KB  |  127 lines

  1. /* $XConsortium: CrPixmap.c,v 11.8 94/04/17 20:19:01 rws Exp $ */
  2. /*
  3.  
  4. Copyright (c) 1986  X Consortium
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  19. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.  
  23. Except as contained in this notice, the name of the X Consortium shall not be
  24. used in advertising or otherwise to promote the sale, use or other dealings
  25. in this Software without prior written authorization from the X Consortium.
  26.  
  27. */
  28.  
  29. #include "Xlib_private.h"
  30.  
  31. void Xlib_InitPixmap(HPS hps, int width, int height, int depth)
  32. {
  33.     DBUG_ENTER("Xlib_InitPixmap")
  34.     struct {
  35.         BITMAPINFO2 bmi;
  36.         RGB2 palette[256];
  37.     } inf;
  38.     
  39.     memset(&inf, 0, sizeof(inf));    
  40.     inf.bmi.cbFix = sizeof(BITMAPINFO2);
  41.     inf.bmi.cx = width; inf.bmi.cy = height;
  42.     inf.bmi.cPlanes = 1; inf.bmi.cBitCount = depth;
  43.     inf.bmi.cbImage = ((width * depth + 7)>>3)*height;
  44.     inf.bmi.ulColorEncoding = BCE_RGB;
  45.     inf.bmi.argbColor[0].bBlue = 0xff;
  46.     inf.bmi.argbColor[0].bGreen = 0xff;
  47.     inf.bmi.argbColor[0].bRed = 0xff;
  48.     if (depth <= 8)
  49.         inf.bmi.cclrUsed = inf.bmi.cclrImportant = 1<<depth;
  50.     else
  51.         inf.bmi.ulColorEncoding = 0;
  52.     GpiSetBitmapBits(hps, 0, 0, NULL, &inf.bmi);
  53.     DBUG_VOID_RETURN;
  54. }
  55.  
  56. Pixmap XCreatePixmap (dpy, d, width, height, depth)
  57.     Display *dpy;
  58.     Drawable d;
  59.     unsigned int width, height, depth;
  60. {
  61.     DBUG_ENTER("XCreatePixmap")
  62.     DEVOPENSTRUC dop = { 0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L };
  63.     BITMAPINFOHEADER2 bmih;
  64.     SIZEL sizl = {0, 0};
  65.     Xlib_Pixmap *pixmap;
  66.  
  67.     if (!(pixmap = calloc(1,sizeof(Xlib_Pixmap)))) DBUG_RETURN((Pixmap)0);
  68.     if (!depth) depth = 24;
  69.  
  70.     pixmap->width = width; pixmap->height = height;
  71.     pixmap->hdc = DevOpenDC(mainhab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
  72.  
  73.     pixmap->hps = GpiCreatePS(mainhab, pixmap->hdc, &sizl, PU_PELS | GPIT_MICRO | GPIA_ASSOC );
  74.  
  75.     memset(&bmih, 0, sizeof(BITMAPINFOHEADER2));
  76.     bmih.cbFix = sizeof(BITMAPINFOHEADER2);
  77.     bmih.cx = width; bmih.cy = height;
  78.     bmih.cPlanes = bmih.cBitCount = depth;
  79.     bmih.cbImage = (width * height * depth + 7)>>3;
  80.     
  81.     pixmap->hbm = GpiCreateBitmap(pixmap->hps, &bmih, 0L, NULL, NULL);
  82.  
  83.     pixmap->colormap = None;
  84.  
  85.     GpiSetBitmap(pixmap->hps, pixmap->hbm);
  86.  
  87.     if (depth>8)
  88.     GpiCreateLogColorTable(pixmap->hps, LCOL_PURECOLOR, LCOLF_RGB, 0, 0, NULL );
  89.  
  90.     Xlib_InitPixmap(pixmap->hps, width, height, depth);
  91.  
  92. #ifdef DEBUG_VERBOSE
  93.     fprintf(stderr,"XCreatePixmap: width=%d, height=%d, depth=%d, pixmap=%p,\n",width,height,depth,pixmap);
  94. #endif
  95.  
  96.     DBUG_RETURN((Pixmap)pixmap);
  97. }
  98.  
  99. void _XPurgeGC(Display* display, GC gc);
  100.  
  101. int XFreePixmap(Display* display, Pixmap _pixmap)
  102. {
  103.     DBUG_ENTER("XFreePixmap")
  104.     Xlib_Pixmap *pixmap = (Xlib_Pixmap *)_pixmap;
  105.     Xlib_GC *xgc;
  106.     int i;
  107.     if (!pixmap) DBUG_RETURN(False);
  108.     _XPurgeGC(display, pixmap->currentGC);
  109.     if (pixmap->currentGC  && (xgc=(Xlib_GC *)pixmap->currentGC)->pixmap == pixmap) {
  110.         xgc->pixmap = (Pixmap)0L;
  111.         (HPS)xgc->gid = WinGetScreenPS(hwndDesktop);
  112.     }
  113.     pixmap->currentGC = (GC)0L;
  114.     Xlib_FreePixmapAtom(pixmap);
  115.     Xlib_FreeAllAtoms(pixmap);
  116.     Xlib_InvalidateResource((XID)_pixmap);
  117.     /* We must disassociate the bitmap from the presentation space
  118.      * before deleting it.
  119.      */
  120.     GpiSetBitmap(pixmap->hps, NULLHANDLE);
  121.     GpiDeleteBitmap(pixmap->hbm);
  122.     GpiDestroyPS(pixmap->hps);
  123.     DevCloseDC(pixmap->hdc);
  124.     free(pixmap);
  125.     DBUG_RETURN(True);
  126. }
  127.