home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / x / x11r6-ch / xpm-3.4 / xpm-3 / xpm-3.4c / lib / CrIFrDat.c < prev    next >
C/C++ Source or Header  |  1994-06-06  |  4KB  |  116 lines

  1. /*
  2.  * Copyright (C) 1989-94 GROUPE BULL
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  5.  * of this software and associated documentation files (the "Software"), to
  6.  * deal in the Software without restriction, including without limitation the
  7.  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8.  * sell copies of the Software, and to permit persons to whom the Software is
  9.  * furnished to do so, subject to the following conditions:
  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
  17.  * GROUPE BULL 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 GROUPE BULL 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 GROUPE BULL.
  24.  */
  25.  
  26. /*****************************************************************************\
  27. *  CrIFrData.c:                                                               *
  28. *                                                                             *
  29. *  XPM library                                                                *
  30. *  Parse an Xpm array and create the image and possibly its mask              *
  31. *                                                                             *
  32. *  Developed by Arnaud Le Hors                                                *
  33. \*****************************************************************************/
  34.  
  35. #include "xpmP.h"
  36.  
  37. LFUNC(OpenArray, void, (char **data, xpmData *mdata));
  38.  
  39. int
  40. XpmCreateImageFromData(display, data, image_return,
  41.                shapeimage_return, attributes)
  42.     Display *display;
  43.     char **data;
  44.     XImage **image_return;
  45.     XImage **shapeimage_return;
  46.     XpmAttributes *attributes;
  47. {
  48.     XpmImage image;
  49.     XpmInfo info;
  50.     int ErrorStatus;
  51.  
  52.     /* create an XpmImage from the file */
  53.     if (attributes) {
  54.     xpmInitAttributes(attributes);
  55.     xpmSetInfoMask(&info, attributes);
  56.     ErrorStatus = XpmCreateXpmImageFromData(data, &image, &info);
  57.     } else
  58.     ErrorStatus = XpmCreateXpmImageFromData(data, &image, NULL);
  59.  
  60.     if (ErrorStatus != XpmSuccess)
  61.     return (ErrorStatus);
  62.  
  63.     /* create the related ximages */
  64.     ErrorStatus = XpmCreateImageFromXpmImage(display, &image,
  65.                          image_return, shapeimage_return,
  66.                          attributes);
  67.     if (attributes) {
  68.     if (ErrorStatus >= 0)        /* no fatal error */
  69.         xpmSetAttributes(attributes, &image, &info);
  70.     XpmFreeXpmInfo(&info);
  71.     }
  72.     XpmFreeXpmImage(&image);
  73.  
  74.     return (ErrorStatus);
  75. }
  76.  
  77. int
  78. XpmCreateXpmImageFromData(data, image, info)
  79.     char **data;
  80.     XpmImage *image;
  81.     XpmInfo *info;
  82. {
  83.     xpmData mdata;
  84.     int ErrorStatus;
  85.  
  86.     /* init returned values */
  87.     xpmInitXpmImage(image);
  88.     xpmInitXpmInfo(info);
  89.  
  90.     /* open data */
  91.     OpenArray(data, &mdata);
  92.  
  93.     /* create the XpmImage from the XpmData */
  94.     ErrorStatus = xpmParseData(&mdata, image, info);
  95.  
  96.     return (ErrorStatus);
  97. }
  98.  
  99. /*
  100.  * open the given array to be read or written as an xpmData which is returned
  101.  */
  102. static void
  103. OpenArray(data, mdata)
  104.     char **data;
  105.     xpmData *mdata;
  106. {
  107.     mdata->type = XPMARRAY;
  108.     mdata->stream.data = data;
  109.     mdata->cptr = *data;
  110.     mdata->line = 0;
  111.     mdata->CommentLength = 0;
  112.     mdata->Bcmt = mdata->Ecmt = NULL;
  113.     mdata->Bos = mdata->Eos = '\0';
  114.     mdata->format = 0;            /* this can only be Xpm 2 or 3 */
  115. }
  116.