1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
/* imagetypes.c:
*
* this contains the ImageTypes array
*
* jim frost 09.27.89
*
* Copyright 1989, 1991 Jim Frost.
* See included file "copyright.h" for complete copyright information.
*/
#include "copyright.h"
#include "xli.h"
#include "imagetypes.h"
#include <errno.h>
extern int errno;
/* some of these are order-dependent */
static struct {
int (*identifier) (char *, char *);
Image *(*loader) (char *, ImageOptions *, boolean);
char *name;
} ImageTypes[] = {
{fbmIdent, fbmLoad, "FBM Image"},
{sunRasterIdent, sunRasterLoad, "Sun Rasterfile"},
{cmuwmIdent, cmuwmLoad, "CMU WM Raster"},
{pbmIdent, pbmLoad, "Portable Bit Map (PBM, PGM, PPM)"},
{facesIdent, facesLoad, "Faces Project"},
{pngIdent, pngLoad, "Portable Network Graphics (PNG)"},
{gifIdent, gifLoad, "GIF Image"},
{jpegIdent, jpegLoad, "JFIF style jpeg Image"},
{rleIdent, rleLoad, "Utah RLE Image"},
{bmpIdent, bmpLoad, "Windows, OS/2 RLE Image"},
{pcdIdent, pcdLoad, "Photograph on CD Image"},
{xwdIdent, xwdLoad, "X Window Dump"},
{tgaIdent, tgaLoad, "Targa Image"},
{mcidasIdent, mcidasLoad, "McIDAS areafile"},
{g3Ident, g3Load, "G3 FAX Image"},
{pcxIdent, pcxLoad, "PC Paintbrush Image"},
{imgIdent, imgLoad, "GEM Bit Image"},
{macIdent, macLoad, "MacPaint Image"},
{xpixmapIdent, xpixmapLoad, "X Pixmap"},
{xbitmapIdent, xbitmapLoad, "X Bitmap"},
{NULL, NULL, NULL}
};
/* load a named image */
Image *loadImage(ImageOptions * image_ops, boolean verbose)
{
char fullname[BUFSIZ];
Image *image;
int a;
if (findImage(image_ops->name, fullname) < 0) {
if (errno == ENOENT)
printf("%s: image not found\n", image_ops->name);
else if (errno == EISDIR)
printf("%s: directory\n", image_ops->name);
else
perror(fullname);
return (NULL);
}
image_ops->fullname = lmalloc(strlen(fullname) + 1);
strcpy(image_ops->fullname, fullname);
/* We've done this before !! */
if (image_ops->loader_idx != -1) {
image = ImageTypes[image_ops->loader_idx].loader(fullname,
image_ops, verbose);
if (image) {
zreset(NULL);
return (image);
}
} else {
for (a = 0; ImageTypes[a].loader; a++) {
image = ImageTypes[a].loader(fullname, image_ops,
verbose);
if (image) {
zreset(NULL);
return (image);
}
}
}
printf("%s: unknown or unsupported image type\n", fullname);
zreset(NULL);
return (NULL);
}
/* identify what kind of image a named image is */
void identifyImage(char *name)
{
char fullname[BUFSIZ];
int a;
if (findImage(name, fullname) < 0) {
if (errno == ENOENT)
printf("%s: image not found\n", name);
else if (errno == EISDIR)
printf("%s: directory\n", name);
else
perror(fullname);
return;
}
for (a = 0; ImageTypes[a].identifier; a++) {
if (ImageTypes[a].identifier(fullname, name)) {
zreset(NULL);
return;
}
}
zreset(NULL);
printf("%s: unknown or unsupported image type\n", fullname);
}
/* tell user what image types we support */
void supportedImageTypes(void)
{
int a;
printf("Image types supported:\n");
for (a = 0; ImageTypes[a].name; a++)
printf(" %s\n", ImageTypes[a].name);
}
|