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