Back to index

plt-scheme  4.2.1
Functions
WrFFrI.c File Reference
#include "xpmP.h"
#include <strings.h>

Go to the source code of this file.

Functions

 LFUNC (WriteFile, int,(FILE *file, XpmImage *image, char *name, XpmInfo *info))
 LFUNC (WriteColors, void,(FILE *file, XpmColor *colors, unsigned int ncolors))
 LFUNC (WritePixels, int,(FILE *file, unsigned int width, unsigned int height, unsigned int cpp, unsigned int *pixels, XpmColor *colors))
 LFUNC (WriteExtensions, void,(FILE *file, XpmExtension *ext, unsigned int num))
 LFUNC (OpenWriteFile, int,(char *filename, xpmData *mdata))
 LFUNC (xpmDataClose, void,(xpmData *mdata))
int XpmWriteFileFromImage (Display *display, char *filename, XImage *image, XImage *shapeimage, XpmAttributes *attributes)
int XpmWriteFileFromXpmImage (char *filename, XpmImage *image, XpmInfo *info)
static int WriteFile (FILE *file, XpmImage *image, char *name, XpmInfo *info)
static void WriteColors (FILE *file, XpmColor *colors, unsigned int ncolors)
static int WritePixels (FILE *file, unsigned int width, unsigned int height, unsigned int cpp, unsigned int *pixels, XpmColor *colors)
static void WriteExtensions (FILE *file, XpmExtension *ext, unsigned int num)
static int OpenWriteFile (char *filename, xpmData *mdata)
static void xpmDataClose (xpmData *mdata)

Function Documentation

LFUNC ( WriteFile  ,
int  ,
(FILE *file, XpmImage *image, char *name, XpmInfo *info  
)
LFUNC ( WriteColors  ,
void  ,
(FILE *file, XpmColor *colors, unsigned int ncolors)   
)
LFUNC ( WritePixels  ,
int  ,
(FILE *file, unsigned int width, unsigned int height, unsigned int cpp, unsigned int *pixels, XpmColor *colors)   
)
LFUNC ( WriteExtensions  ,
void  ,
(FILE *file, XpmExtension *ext, unsigned int num  
)
LFUNC ( OpenWriteFile  ,
int  ,
(char *filename, xpmData *mdata)   
)
LFUNC ( xpmDataClose  ,
void  ,
(xpmData *mdata)   
)
static int OpenWriteFile ( char *  filename,
xpmData mdata 
) [static]

Definition at line 292 of file WrFFrI.c.

{
#ifdef ZPIPE
    char buf[BUFSIZ];

#endif

    if (!filename) {
       mdata->stream.file = (stdout);
       mdata->type = XPMFILE;
    } else {
#ifdef ZPIPE
       if ((int) strlen(filename) > 2
           && !strcmp(".Z", filename + (strlen(filename) - 2))) {
           sprintf(buf, "compress > \"%s\"", filename);
           if (!(mdata->stream.file = popen(buf, "w")))
              return (XpmOpenFailed);

           mdata->type = XPMPIPE;
       } else if ((int) strlen(filename) > 3
                 && !strcmp(".gz", filename + (strlen(filename) - 3))) {
           sprintf(buf, "gzip -q > \"%s\"", filename);
           if (!(mdata->stream.file = popen(buf, "w")))
              return (XpmOpenFailed);

           mdata->type = XPMPIPE;
       } else {
#endif
           if (!(mdata->stream.file = fopen(filename, "w")))
              return (XpmOpenFailed);

           mdata->type = XPMFILE;
#ifdef ZPIPE
       }
#endif
    }
    return (XpmSuccess);
}

Here is the caller graph for this function:

static void WriteColors ( FILE *  file,
XpmColor colors,
unsigned int  ncolors 
) [static]

Definition at line 205 of file WrFFrI.c.

{
    unsigned int a, key;
    char *s;
    char **defaults;

    for (a = 0; a < ncolors; a++, colors++) {

       defaults = (char **) colors;
       fprintf(file, "\"%s", *defaults++);

       for (key = 1; key <= NKEYS; key++, defaults++) {
           if (s = *defaults)
              fprintf(file, "\t%s %s", xpmColorKeys[key - 1], s);
       }
       fprintf(file, "\",\n");
    }
}

Here is the caller graph for this function:

static void WriteExtensions ( FILE *  file,
XpmExtension ext,
unsigned int  num 
) [static]

Definition at line 271 of file WrFFrI.c.

{
    unsigned int x, y, n;
    char **line;

    for (x = 0; x < num; x++, ext++) {
       fprintf(file, ",\n\"XPMEXT %s\"", ext->name);
       n = ext->nlines;
       for (y = 0, line = ext->lines; y < n; y++, line++)
           fprintf(file, ",\n\"%s\"", *line);
    }
    fprintf(file, ",\n\"XPMENDEXT\"");
}

Here is the caller graph for this function:

static int WriteFile ( FILE *  file,
XpmImage image,
char *  name,
XpmInfo info 
) [static]

Definition at line 147 of file WrFFrI.c.

{
    /* calculation variables */
    unsigned int cmts, extensions;
    int ErrorStatus;

    cmts = info && (info->valuemask & XpmComments);
    extensions = info && (info->valuemask & XpmExtensions)
       && info->nextensions;

    /* print the header line */
    fprintf(file, "/* XPM */\nstatic char * %s[] = {\n", name);

    /* print the hints line */
    if (cmts && info->hints_cmt)
       fprintf(file, "/*%s*/\n", info->hints_cmt);

    fprintf(file, "\"%d %d %d %d", image->width, image->height,
           image->ncolors, image->cpp);

    if (info && (info->valuemask & XpmHotspot))
       fprintf(file, " %d %d", info->x_hotspot, info->y_hotspot);

    if (extensions)
       fprintf(file, " XPMEXT");

    fprintf(file, "\",\n");

    /* print colors */
    if (cmts && info->colors_cmt)
       fprintf(file, "/*%s*/\n", info->colors_cmt);

    WriteColors(file, image->colorTable, image->ncolors);

    /* print pixels */
    if (cmts && info->pixels_cmt)
       fprintf(file, "/*%s*/\n", info->pixels_cmt);

    ErrorStatus = WritePixels(file, image->width, image->height, image->cpp,
                           image->data, image->colorTable);
    if (ErrorStatus != XpmSuccess)
       return (ErrorStatus);

    /* print extensions */
    if (extensions)
       WriteExtensions(file, info->extensions, info->nextensions);

    /* close the array */
    fprintf(file, "};\n");

    return (XpmSuccess);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int WritePixels ( FILE *  file,
unsigned int  width,
unsigned int  height,
unsigned int  cpp,
unsigned int pixels,
XpmColor colors 
) [static]

Definition at line 229 of file WrFFrI.c.

{
    char *s, *p, *buf;
    unsigned int x, y, h;

    h = height - 1;
    p = buf = (char *) XpmMalloc(width * cpp + 3);
    if (!buf)
       return (XpmNoMemory);
    *buf = '"';
    p++;
    for (y = 0; y < h; y++) {
       s = p;
       for (x = 0; x < width; x++, pixels++) {
           strncpy(s, colors[*pixels].string, cpp);
           s += cpp;
       }
       *s++ = '"';
       *s = '\0';
       fprintf(file, "%s,\n", buf);
    }
    /* duplicate some code to avoid a test in the loop */
    s = p;
    for (x = 0; x < width; x++, pixels++) {
       strncpy(s, colors[*pixels].string, cpp);
       s += cpp;
    }
    *s++ = '"';
    *s = '\0';
    fprintf(file, "%s", buf);

    XpmFree(buf);
    return (XpmSuccess);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xpmDataClose ( xpmData mdata) [static]

Definition at line 337 of file WrFFrI.c.

{
    switch (mdata->type) {
    case XPMFILE:
       if (mdata->stream.file != (stdout))
           fclose(mdata->stream.file);
       break;
#ifdef ZPIPE
    case XPMPIPE:
       pclose(mdata->stream.file);
       break;
#endif
    }
}

Here is the caller graph for this function:

int XpmWriteFileFromImage ( Display *  display,
char *  filename,
XImage *  image,
XImage *  shapeimage,
XpmAttributes attributes 
)

Definition at line 58 of file WrFFrI.c.

{
    XpmImage xpmimage;
    XpmInfo info;
    int ErrorStatus;

    /* create an XpmImage from the image */
    ErrorStatus = XpmCreateXpmImageFromImage(display, image, shapeimage,
                                        &xpmimage, attributes);
    if (ErrorStatus != XpmSuccess)
       return (ErrorStatus);

    /* write the file from the XpmImage */
    if (attributes) {
       xpmSetInfo(&info, attributes);
       ErrorStatus = XpmWriteFileFromXpmImage(filename, &xpmimage, &info);
    } else
       ErrorStatus = XpmWriteFileFromXpmImage(filename, &xpmimage, NULL);

    /* free the XpmImage */
    XpmFreeXpmImage(&xpmimage);

    return (ErrorStatus);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int XpmWriteFileFromXpmImage ( char *  filename,
XpmImage image,
XpmInfo info 
)

Definition at line 89 of file WrFFrI.c.

{
    xpmData mdata;
    char *name, *dot, *s, new_name[BUFSIZ];
    int ErrorStatus;

    /* open file to write */
    if ((ErrorStatus = OpenWriteFile(filename, &mdata)) != XpmSuccess)
       return (ErrorStatus);

    /* figure out a name */
    if (filename) {
#ifdef VMS
       name = filename;
#else
       if (!(name = rindex(filename, '/')))
           name = filename;
       else
           name++;
#endif
       /* let's try to make a valid C syntax name */
       if (dot = index(name, '.')) {
           strcpy(new_name, name);
           /* change '.' to '_' */
           name = s = new_name;
           while (dot = index(s, '.')) {
              *dot = '_';
              s = dot;
           }
       }
       if (dot = index(name, '-')) {
           if (name != new_name) {
              strcpy(new_name, name);
              name = new_name;
           }
           /* change '-' to '_' */
           s = name;
           while (dot = index(s, '-')) {
              *dot = '_';
              s = dot;
           }
       }
    } else
       name = "image_name";

    /* write the XpmData from the XpmImage */
    if (ErrorStatus == XpmSuccess)
       ErrorStatus = WriteFile(mdata.stream.file, image, name, info);

    xpmDataClose(&mdata);

    return (ErrorStatus);
}

Here is the call graph for this function:

Here is the caller graph for this function: