CrBFData.c revision 1ab64890
1/* $Xorg: CrBFData.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/* $XFree86$ */ 28 29#ifdef HAVE_CONFIG_H 30#include <config.h> 31#endif 32#include "Xlib.h" 33 34/* 35 * XCreateBitmapFromData: Routine to make a pixmap of depth 1 from user 36 * supplied data. 37 * D is any drawable on the same screen that the pixmap will be used in. 38 * Data is a pointer to the bit data, and 39 * width & height give the size in bits of the pixmap. 40 * 41 * The following format is assumed for data: 42 * 43 * format=XYPixmap 44 * bit_order=LSBFirst 45 * byte_order=LSBFirst 46 * padding=8 47 * bitmap_unit=8 48 * xoffset=0 49 * no extra bytes per line 50 */ 51Pixmap XCreateBitmapFromData( 52 Display *display, 53 Drawable d, 54 _Xconst char *data, 55 unsigned int width, 56 unsigned int height) 57{ 58 XImage ximage; 59 GC gc; 60 Pixmap pix; 61 62 pix = XCreatePixmap(display, d, width, height, 1); 63 if (! (gc = XCreateGC(display, pix, (unsigned long) 0, (XGCValues *) 0))) 64 return (Pixmap) None; 65 ximage.height = height; 66 ximage.width = width; 67 ximage.depth = 1; 68 ximage.bits_per_pixel = 1; 69 ximage.xoffset = 0; 70 ximage.format = XYPixmap; 71 ximage.data = (char *)data; 72 ximage.byte_order = LSBFirst; 73 ximage.bitmap_unit = 8; 74 ximage.bitmap_bit_order = LSBFirst; 75 ximage.bitmap_pad = 8; 76 ximage.bytes_per_line = (width+7)/8; 77 78 XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height); 79 XFreeGC(display, gc); 80 return(pix); 81} 82