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