CrPFBData.c revision 1ab64890
1/* $Xorg: CrPFBData.c,v 1.4 2001/02/09 02:03:32 xorgcvs Exp $ */ 2/* 3 4Copyright 1987, 1998 The Open Group 5 6Permission to use, copy, modify, distribute, and sell this software and its 7documentation for any purpose is hereby granted without fee, provided that 8the above copyright notice appear in all copies and that both that 9copyright notice and this permission notice appear in supporting 10documentation. 11 12The above copyright notice and this permission notice shall be included in 13all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of The Open Group shall not be 23used in advertising or otherwise to promote the sale, use or other dealings 24in this Software without prior written authorization from The Open Group. 25 26*/ 27 28#ifdef HAVE_CONFIG_H 29#include <config.h> 30#endif 31#include "Xlib.h" 32#include <stdio.h> 33 34/* 35 * XCreatePixmapFromBitmapData: Routine to make a pixmap from user supplied bitmap data. 36 * D is any drawable on the same screen that the pixmap will be used in. 37 * Data is a pointer to the bit data, and 38 * width & height give the size in bits of the pixmap. 39 * Fg and Bg are the pixel values to use for the two colors. 40 * Depth is the depth of the pixmap to create. 41 * 42 * The following format is assumed for data: 43 * 44 * format=XYPixmap 45 * bit_order=LSBFirst 46 * byte_order=LSBFirst 47 * padding=8 48 * bitmap_unit=8 49 * xoffset=0 50 * no extra bytes per line 51 */ 52Pixmap XCreatePixmapFromBitmapData( 53 Display *display, 54 Drawable d, 55 char *data, 56 unsigned int width, 57 unsigned int height, 58 unsigned long fg, 59 unsigned long bg, 60 unsigned int depth) 61{ 62 XImage ximage; 63 GC gc; 64 XGCValues gcv; 65 Pixmap pix; 66 67 pix = XCreatePixmap(display, d, width, height, depth); 68 gcv.foreground = fg; 69 gcv.background = bg; 70 if (! (gc = XCreateGC(display, pix, GCForeground|GCBackground, &gcv))) 71 return (Pixmap) NULL; 72 ximage.height = height; 73 ximage.width = width; 74 ximage.depth = 1; 75 ximage.bits_per_pixel = 1; 76 ximage.xoffset = 0; 77 ximage.format = XYBitmap; 78 ximage.data = data; 79 ximage.byte_order = LSBFirst; 80 ximage.bitmap_unit = 8; 81 ximage.bitmap_bit_order = LSBFirst; 82 ximage.bitmap_pad = 8; 83 ximage.bytes_per_line = (width+7)/8; 84 85 XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height); 86 XFreeGC(display, gc); 87 return(pix); 88} 89