Back to index

plt-scheme  4.2.1
CrIFrDat.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1989-95 GROUPE BULL
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to
00006  * deal in the Software without restriction, including without limitation the
00007  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00008  * sell copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00017  * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00018  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00019  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00020  *
00021  * Except as contained in this notice, the name of GROUPE BULL shall not be
00022  * used in advertising or otherwise to promote the sale, use or other dealings
00023  * in this Software without prior written authorization from GROUPE BULL.
00024  */
00025 
00026 /*****************************************************************************\
00027 *  CrIFrData.c:                                                               *
00028 *                                                                             *
00029 *  XPM library                                                                *
00030 *  Parse an Xpm array and create the image and possibly its mask              *
00031 *                                                                             *
00032 *  Developed by Arnaud Le Hors                                                *
00033 \*****************************************************************************/
00034 
00035 #include "xpmP.h"
00036 
00037 LFUNC(OpenArray, void, (char **data, xpmData *mdata));
00038 
00039 int
00040 XpmCreateImageFromData(display, data, image_return,
00041                      shapeimage_return, attributes)
00042     Display *display;
00043     char **data;
00044     XImage **image_return;
00045     XImage **shapeimage_return;
00046     XpmAttributes *attributes;
00047 {
00048     XpmImage image;
00049     XpmInfo info;
00050     int ErrorStatus;
00051 
00052     /* create an XpmImage from the file */
00053     if (attributes) {
00054        xpmInitAttributes(attributes);
00055        xpmSetInfoMask(&info, attributes);
00056        ErrorStatus = XpmCreateXpmImageFromData(data, &image, &info);
00057     } else
00058        ErrorStatus = XpmCreateXpmImageFromData(data, &image, NULL);
00059 
00060     if (ErrorStatus != XpmSuccess)
00061        return (ErrorStatus);
00062 
00063     /* create the related ximages */
00064     ErrorStatus = XpmCreateImageFromXpmImage(display, &image,
00065                                         image_return, shapeimage_return,
00066                                         attributes);
00067     if (attributes) {
00068        if (ErrorStatus >= 0)              /* no fatal error */
00069            xpmSetAttributes(attributes, &image, &info);
00070        XpmFreeXpmInfo(&info);
00071     }
00072     XpmFreeXpmImage(&image);
00073 
00074     return (ErrorStatus);
00075 }
00076 
00077 int
00078 XpmCreateXpmImageFromData(data, image, info)
00079     char **data;
00080     XpmImage *image;
00081     XpmInfo *info;
00082 {
00083     xpmData mdata;
00084     int ErrorStatus;
00085 
00086     /* init returned values */
00087     xpmInitXpmImage(image);
00088     xpmInitXpmInfo(info);
00089 
00090     /* open data */
00091     OpenArray(data, &mdata);
00092 
00093     /* create the XpmImage from the XpmData */
00094     ErrorStatus = xpmParseData(&mdata, image, info);
00095 
00096     return (ErrorStatus);
00097 }
00098 
00099 /*
00100  * open the given array to be read or written as an xpmData which is returned
00101  */
00102 static void
00103 OpenArray(data, mdata)
00104     char **data;
00105     xpmData *mdata;
00106 {
00107     mdata->type = XPMARRAY;
00108     mdata->stream.data = data;
00109     mdata->cptr = *data;
00110     mdata->line = 0;
00111     mdata->CommentLength = 0;
00112     mdata->Bcmt = mdata->Ecmt = NULL;
00113     mdata->Bos = mdata->Eos = '\0';
00114     mdata->format = 0;                    /* this can only be Xpm 2 or 3 */
00115 }