1 /* $XConsortium: XpmCrIFrBuf.c /main/2 1996/09/20 08:03:23 pascale $ */
2 /*
3  * Copyright (C) 1989-95 GROUPE BULL
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to
7  * deal in the Software without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  * sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Except as contained in this notice, the name of GROUPE BULL shall not be
23  * used in advertising or otherwise to promote the sale, use or other dealings
24  * in this Software without prior written authorization from GROUPE BULL.
25  */
26 
27 /*****************************************************************************\
28 *  CrIFrBuf.c:                                                                *
29 *                                                                             *
30 *  XPM library                                                                *
31 *  Parse an Xpm buffer (file in memory) and create the image and possibly its *
32 *  mask                                                                       *
33 *  Developed by Arnaud Le Hors                                                *
34 \*****************************************************************************/
35 
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39 
40 
41 #include "XpmI.h"
42 
43 LFUNC(OpenBuffer, void, (char *buffer, xpmData *mdata));
44 
45 int
XpmCreateImageFromBuffer(display,buffer,image_return,shapeimage_return,attributes)46 XpmCreateImageFromBuffer(display, buffer, image_return,
47 			 shapeimage_return, attributes)
48     Display *display;
49     char *buffer;
50     XImage **image_return;
51     XImage **shapeimage_return;
52     XpmAttributes *attributes;
53 {
54     XpmImage image;
55     XpmInfo info;
56     int ErrorStatus;
57     xpmData mdata;
58 
59     xpmInitXpmImage(&image);
60     xpmInitXpmInfo(&info);
61 
62     /* open buffer to read */
63     OpenBuffer(buffer, &mdata);
64 
65     /* create the XImage from the XpmData */
66     if (attributes) {
67 	xpmInitAttributes(attributes);
68 	xpmSetInfoMask(&info, attributes);
69 	ErrorStatus = xpmParseDataAndCreate(display, &mdata,
70 					    image_return, shapeimage_return,
71 					    &image, &info, attributes);
72     } else
73 	ErrorStatus = xpmParseDataAndCreate(display, &mdata,
74 					    image_return, shapeimage_return,
75 					    &image, NULL, attributes);
76     if (attributes) {
77 	if (ErrorStatus >= 0)		/* no fatal error */
78 	    xpmSetAttributes(attributes, &image, &info);
79 	XpmFreeXpmInfo(&info);
80     }
81 
82     /* free the XpmImage */
83     XpmFreeXpmImage(&image);
84 
85     return (ErrorStatus);
86 }
87 
88 int
XpmCreateXpmImageFromBuffer(buffer,image,info)89 XpmCreateXpmImageFromBuffer(buffer, image, info)
90     char *buffer;
91     XpmImage *image;
92     XpmInfo *info;
93 {
94     xpmData mdata;
95     int ErrorStatus;
96 
97     /* init returned values */
98     xpmInitXpmImage(image);
99     xpmInitXpmInfo(info);
100 
101     /* open buffer to read */
102     OpenBuffer(buffer, &mdata);
103 
104     /* create the XpmImage from the XpmData */
105     ErrorStatus = xpmParseData(&mdata, image, info);
106 
107     return (ErrorStatus);
108 }
109 
110 /*
111  * open the given buffer to be read or written as an xpmData which is returned
112  */
113 static void
OpenBuffer(buffer,mdata)114 OpenBuffer(buffer, mdata)
115     char *buffer;
116     xpmData *mdata;
117 {
118     mdata->type = XPMBUFFER;
119     mdata->cptr = buffer;
120     mdata->CommentLength = 0;
121 }
122