v08i034: GIF viewers for SUN

Brandon S. Allbery - comp.sources.misc allbery at uunet.UU.NET
Sun Sep 10 04:03:06 AEST 1989


Posting-number: Volume 8, Issue 34
Submitted-by: marcel at duteca.tudelft.nl (Marcel Mol)
Archive-name: gif_sun

HEre are a few gif programs intended for the SUN.
One converts from GIF to rasterfiles, one must be used with sunview 
(or suntools), and the third just uses the console sceen (my experience
is that you will not see anything if you use that third program with sunview
running.)
There is also a program that just show some info of the gif file but does not 
display it.

-MArcel

=======================CUT=================================
#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	 gif2r.c 	   16510	bytes
#	 gif2ras.c 	   12405	bytes
#	 gif2sun.c 	   19279	bytes
#	 gifinfo.c 	   10471	bytes
# This archive created:  Fri Sep  8 00:22:34 MET 1989
# By:	 Marcel J.E. Mol
export PATH
echo shar: extracting gif2r.c
if test -f 'gif2r.c'
then
	echo shar: over-writing existing file "'gif2r.c'"
fi
sed -e 's/^-//' << \_E_O_F_ > gif2r.c
-/*********************************************
- *             GIF to SUN color screen       *
- *                                           *
- *      March 23 1989 By Marcel J.E. Mol     *
- *                                           *
- * I hereby place this program               *
- * in the public domain, i.e. there are no   *
- * copying restrictions of any kind.         *
- *********************************************/
-
-/* 
- * Usage:
- *        gif2r -s<num> -v -d <gif-file>
- * 
- * Compile:
- *          cc gif2r.c -o gif2r -lpixrect
- * 
- */ 
-
-
-#include <stdio.h>
-#include <sys/file.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <pixrect/pixrect_hs.h>
-
-
-#define FALSE 0
-#define TRUE 1
-#define COLSIZE 256
-#define PICSIZE 0;               /* Initila scaling factor: 0 = autoscale */
-
-
-
-int        main();
-void       convert();
-int        checksignature();
-void       readscreen();
-int        readimage();
-void       readextension();
-int        readraster();
-int        uncompress();
-void       initcolors();
-int        rasterize();
-void       usage();
-Pixrect  * find_screen();
-Pixrect  * my_pr_open();
-int        terminate();
-char     * malloc();
-int        strncmp();
-
-
-typedef int bool;
-
-/* 
- * sun screen data
- */
-unsigned char oldred[COLSIZE], oldgreen[COLSIZE], oldblue[COLSIZE];
-int oldplanes;
-Pixrect *disp_pr;
-#define MAXGROUPS 10
-char groups[MAXGROUPS];
-int pwidth, pheight;
-
-/*
- * LZW structures and variables
- */
-unsigned int prefix[4096];
-unsigned char suffix[4096];
-unsigned char stack[4096];
-int datasize,codesize,codemask;     /* Decoder working variables */
-int clear,eoi;                      /* Special code values */
-int avail;
-int oldcode;
-
-/*
- * GIF variables
- */
-FILE *infile;
-unsigned int screenwidth;           /* The dimensions of the screen */
-unsigned int screenheight;          /*   (not those of the image)   */
-bool global;                        /* Is there a global color map? */
-int globalbits;                     /* Number of bits of global colors */
-bool local;                         /* Is there a local color map? */
-int localbits;                      /* Number of bits of local colors */
-bool interleaved;                   /* gif data interleaved ? */
-unsigned char globalmap[COLSIZE][3];/* RGB values for global color map */
-unsigned char localmap[COLSIZE][3];
-char bgcolor;                       /* background color */
-unsigned char *raster;              /* Decoded image data */
-unsigned left,top,width,height;     /* image dimensions */
-
-/*
- * general variables
- */
-char *progname;                     /* program name */
-char *filename;                     /* current gif file name */
-int initsize = PICSIZE;             /* initial scale factor */
-int wait = 0;                       /* get input before display */
-int verbose = 0;                    /* display info on picture */
-int debug = 0;                      /* display more info, sets verbose */
-
-
-
-
-main(argc,argv)
-int argc;
-char *argv[];
-{
-    extern int optind;              /* getopt variables */
-    extern char *optarg;
-    int flag;
-
-    progname = *argv;
-
-    while ((flag = getopt(argc, argv, "ds:v")) != EOF) {
-        switch (flag) {
-            case 'd' : debug = 1;       /* fall in verbose */
-            case 'v' : verbose = 1;
-                       break;
-            case 's' : initsize = atoi(optarg);
-                       if (initsize < 0)
-                           initsize = - initsize;
-                       break;
-            default  : fprintf(stderr, "%s: ignoring unknown flag %c\n", 
-                                       progname, flag);
-                       usage();
-        }
-    }
-
-    disp_pr = find_screen();
-
-    /*
-     * Save old state.
-     */
-    pr_getcolormap(disp_pr, 0, 256, oldred, oldblue, oldgreen);
-    oldplanes = pr_get_plane_group(disp_pr);
-    signal(SIGHUP,  terminate);
-    signal(SIGINT,  terminate);
-    signal(SIGTERM, terminate);
-
-    pwidth  = disp_pr->pr_size.x;
-    pheight = disp_pr->pr_size.y;
-
-/*
-    (void) pr_available_plane_groups( disp_pr, MAXGROUPS, groups );
-    if ( ! groups[PIXPG_8BIT_COLOR] ) {
-	fprintf( stderr, "%s: display must implement 8-bit color\n", progname );
-	exit( 1 );
-    }
-    pr_set_plane_group( disp_pr, PIXPG_8BIT_COLOR );
- */
-
-
-    if (optind >= argc) {       /* stdin if no files given */
-        filename = "stdin";
-        infile = stdin;
-        convert();
-    }
-    else {                      /* walk over gif files */
-        while (optind < argc) {
-            filename = argv[optind++];
-            if ((infile = fopen(filename,"r")) == NULL) {
-                perror(filename);
-                continue;
-            }
-            convert();
-            fclose(infile);
-        }
-    }
-
-} /* main */
-
-
-
-void convert()
-{
-    char ch;
-
-    if (verbose)
-        fprintf(stderr, "%s:\n", filename); 
-    if (checksignature())
-        return;
-    readscreen();
-    while ((ch = getc(infile)) != ';' && ch != EOF) {
-        switch (ch) {
-            case '\0':  break;  /* this kludge for non-standard files */
-            case ',':   if (readimage())
-                           return;
-                        break;
-            case '!':   readextension();
-                        break;
-            default:    fprintf(stderr, "%s: illegal GIF block type in %s\n",
-                                        progname, filename);
-                        return;
-                        break;
-        }
-    }
-
-} /* convert */
-
-
-
-checksignature()
-{
-    char buf[6];
-
-    fread(buf,1,6,infile);
-    if (strncmp(buf,"GIF",3)) {
-        fprintf(stderr, "%s: %s is not a GIF file\n", progname, filename);
-        return 1;
-    }
-    if (strncmp(&buf[3],"87a",3)) {
-        fprintf(stderr, "%s: unknown GIF version number in %s\n",
-                        progname, filename);
-        return 1;
-    }
-    return 0;
-
-} /* checksignature */
-
-
-
-/*
- * Get information which is global to all the images stored in the file
- */
-
-void readscreen()
-{
-    unsigned char buf[7];
-
-    fread(buf,1,7,infile);
-    screenwidth = buf[0] + (buf[1] << 8);
-    screenheight = buf[2] + (buf[3] << 8);
-    global = buf[4] & 0x80;
-    if (global) {
-        globalbits = (buf[4] & 0x07) + 1;
-        fread(globalmap,3,1<<globalbits,infile);
-    }
-    bgcolor = buf[5];
-    if (verbose)
-        fprintf(stderr, "    global screen: %dx%dx%d\n",
-                        screenwidth, screenheight, 1<<globalbits);
-    if (debug)
-        fprintf(stderr, "    backgroundcolor: %d\n",
-                        bgcolor);
-
-} /* readscreen */
-
-
-
-
-readimage()
-{
-    unsigned char buf[9];
-
-    if (fread(buf, 1, 9, infile) == 0) {
-        perror(filename);
-        exit(1);
-    }
-    left = buf[0] + (buf[1] << 8);
-    top = buf[2] + (buf[3] << 8);
-    width = buf[4] + (buf[5] << 8);
-    height = buf[6] + (buf[7] << 8);
-    local = buf[8] & 0x80;
-    interleaved = buf[8] & 0x40;
-    if (verbose)
-        fprintf(stderr, "    image: %dx%d %s  org: %d,%d\n", width, height,
-                        interleaved ? "interleaved" : "", left, top);
-    if (local == 0 && global == 0) {
-        fprintf(stderr, "%s: no colormap present for image in %s\n",
-                        progname, filename);
-        return 1;
-    }
-    if ((raster = (unsigned char*) malloc(width*height)) == NULL) {
-        fprintf(stderr, "%s: not enough memory for image in %s\n",
-                        progname, filename);
-        return 1;
-    }
-    if (readraster(width, height))
-        return 1;
-
-    if (local) {
-        localbits = (buf[8] & 0x7) + 1;
-        if (verbose)
-            fprintf(stderr, "   local colors: %d\n", 1<<localbits);
-        fread(localmap, 3, 1<<localbits, infile);
-    }
-
-    rasterize(interleaved, raster);
-    free(raster);
-
-    return 0;
-
-} /* readimage */
-
-
-
-/*
- * Read a GIF extension block (and do nothing with it).
- */
-
-void readextension()
-{
-    unsigned char code;
-    int count;
-    char buf[255];
-
-    code = getc(infile);
-    if (verbose) 
-        fprintf(stderr, "    skipping extension: %d\n", code);
-    while (count = getc(infile))
-        fread(buf, 1, count, infile);
-
-} /* readextension */
-
-
-
-/*
- * Decode a raster image
- */
-
-readraster(width, height)
-unsigned width,height;
-{
-    unsigned char *fill = raster;
-    unsigned char buf[255];
-    register bits = 0;
-    register unsigned datum = 0;
-    register unsigned char *ch;
-    register int count, code;
-
-    datasize = getc(infile);
-    clear    = 1 << datasize;
-    eoi      = clear + 1;
-    avail    = clear + 2;
-    oldcode  = -1;
-    codesize = datasize + 1;
-    codemask = (1 << codesize) - 1;
-    for (code = 0; code < clear; code++) {
-        prefix[code] = 0;
-        suffix[code] = code;
-    }
-    for (count = getc(infile); count > 0; count = getc(infile)) {
-        fread(buf, 1, count, infile);
-        for (ch = buf; count-- > 0; ch++) {
-            datum += *ch << bits;
-            bits  += 8;
-            while (bits >= codesize) {
-                code  = datum & codemask;
-                datum >>= codesize;
-                bits  -= codesize;
-                if (code == eoi) {               /* This kludge put in */
-                    goto exitloop;               /* because some GIF files*/
-                }                                /* aren't standard */
-                if (uncompress(code, &fill)) {
-                    goto exitloop;
-                }
-            }
-        }
-        if (fill >= raster + width*height) {
-            fprintf(stderr, "%s: raster full before eoi code in %s\n",
-                            progname, filename);
-            goto exitloop;
-        }
-    }
-exitloop:
-    if (fill != raster + width*height)  {
-        fprintf(stderr, "%s: warning: %s has wrong rastersize: %ld bytes\n",
-                        progname, filename, (long) (fill-raster));
-        fprintf(stderr, "         instead of %ld bytes\n",
-                        (long) width*height);
-        return 0; /* can still draw a picture ... */
-    }
-
-    return 0;
-
-} /* readraster */
-
-
-
-
-/*
- * Process a compression code.  "clear" resets the code table.  Otherwise
- * make a new code table entry, and output the bytes associated with the
- * code.
- */
-
-uncompress(code, fill)
-register code;
-register unsigned char **fill;
-{
-    int incode;
-    static unsigned char firstchar;
-    register unsigned char *stackp;
-
-    stackp = stack;
-    if (code == clear) {
-        codesize = datasize + 1;
-        codemask = (1 << codesize) - 1;
-        avail    = clear + 2;
-        oldcode  = -1;
-        return 0;
-    }
-
-    if (oldcode == -1) {
-        *(*fill)++ = suffix[code];
-        firstchar = oldcode = code;
-        return 0;
-    }
-
-    if (code > avail) {
-        fprintf(stderr, "%s: code % d to large for %d in %s\n",
-                        progname, code, avail, filename);
-        return 1; 
-    }
-
-    incode = code;
-    if (code == avail) {      /* the first code is always < avail */
-        *stackp++ = firstchar;
-        code = oldcode;
-    }
-    while (code > clear) {
-        *stackp++ = suffix[code];
-        code = prefix[code];
-    }
-
-    *stackp++ = firstchar = suffix[code];
-    prefix[avail] = oldcode;
-    suffix[avail] = firstchar;
-    avail++;
-
-    if (((avail & codemask) == 0) && (avail < 4096)) {
-        codesize++;
-        codemask += avail;
-    }
-
-    oldcode = incode;
-    do {
-        *(*fill)++ = *--stackp;
-    } while (stackp > stack);
-
-    return 0;
-
-} /* process */
-
-
-
-
-/*
- * Convert a color map (local or global) to arrays with R, G and B
- * values. Pass colors to SUNVIEW and set the background color.
- */
-
-void initcolors(colormap, ncolors, bgcolor)
-unsigned char colormap[COLSIZE][3];
-int ncolors;
-int bgcolor;
-{
-    register i;
-    unsigned char red[COLSIZE];
-    unsigned char green[COLSIZE];
-    unsigned char blue[COLSIZE];
-
-    if (verbose)
-        fprintf(stderr, "            ");
-    for (i = 0; i < ncolors; i++) {
-        red[i]   = colormap[i][0];
-        green[i] = colormap[i][1];
-        blue[i]  = colormap[i][2];
-        if (debug) {
-            fprintf(stderr, "   %3u: %3u, %3u, %3u",
-                            i, red[i], green[i], blue[i]);
-            if (i%3 == 2)
-                fprintf(stderr, "\n            ");
-        }
-    }
-
-    if (debug)
-        fprintf(stderr, "\n      Background: %3u: %3u, %3u, %3u\n", bgcolor,
-                        red[bgcolor], green[bgcolor], blue[bgcolor]);
-
-    pr_putcolormap(disp_pr, 0, ncolors, red, green, blue);
-    pr_rop(disp_pr, 0, 0, pwidth, pheight, 
-                     PIX_SRC | PIX_COLOR(bgcolor), 0, 0, 0);
-  
-} /* initcolors */
-
-
-
-/*
- * Create a sun raster from the gif image
- */
-
-rasterize(interleaved, raster)
-int interleaved;
-register unsigned char *raster;
-{
-    register col;
-    register unsigned char *rr;
-    register i, j;
-    register row;
-    unsigned char * newras;
-    unsigned char * expras;
-    unsigned int off_x=0, off_y=0;
-    unsigned int picx, picy, rwidth;
-    Pixrect * picture;
-    int size;
-   
-    
-#define DRAWSEGMENT(offset, step)                       \
-        for (row = offset; row < height; row += step) { \
-            rr = newras + row*picx*size;                \
-            for (i=0; i<size; i++) {                    \
-                for (col=0; col < width; col++) {       \
-                    for (j=0; j<size; j++)              \
-                        *rr++ = *raster;                \
-                    raster++;                           \
-                }                                       \
-                raster -= width;                        \
-                rr + = rwidth%2;                        \
-            }                                           \
-            raster += width;                            \
-        }
-
-    size = initsize;
-    if (size == 0) {
-        size = 2;
-        while (size*width <= pwidth && size*height <= pheight)
-            size++;
-        size--;
-    }
-    rwidth = size * width;
-    picx = rwidth + rwidth%2; 
-    picy = size * height;
-
-    if ((newras = (unsigned char*) malloc(picx*picy)) == NULL) {
-        fprintf(stderr, "%s: not enough memory for raster in %s\n",
-                        progname, filename);
-        return 1;
-    }
-    if (interleaved) {
-        DRAWSEGMENT(0, 8);
-        DRAWSEGMENT(4, 8);
-        DRAWSEGMENT(2, 4);
-        DRAWSEGMENT(1, 2);
-    }
-    else 
-        DRAWSEGMENT(0, 1);
-
-    if (pwidth > picx)
-        off_x = (pwidth - picx)/2;
-    if (pheight > picy)
-        off_y = (pheight - picy)/2;
-
-    picture = mem_point(picx, picy, 8, newras);
-
-    if (wait) {
-       while (getchar() != '\n');
-    }
-    else
-        wait = 0;  /* does not work proerly */
-
-    if (local) 
-        initcolors(localmap,  1<<localbits,  bgcolor);
-    else
-        initcolors(globalmap, 1<<globalbits, bgcolor);
-    pr_rop(disp_pr, off_x, off_y, picx, picy,
-                       PIX_SRC ,picture ,0 ,0);
-
-    free(newras);
-
-
-} /* rasterize */
-
-
-
-void usage()
-{
-
-        fprintf(stderr, "usage: %s [-s<num> -dv] gif-files\n",
-                        progname);
-        fprintf(stderr, "       -s : scale factor (integer), 0 is autoscale\n");
-        fprintf(stderr, "       -v : prints picture information on stderr\n");
-        fprintf(stderr, "       -d : prints more information on stderr\n");
-
-} /* usage */
-
-
-
-Pixrect * find_screen()
-{
-    Pixrect *disp_pr;
-
-    if ( (disp_pr = my_pr_open( "/dev/cgfive0" )) == (Pixrect *) 0 )
-      if ( (disp_pr = my_pr_open( "/dev/cgthree0" )) == (Pixrect *) 0 )
-	if ( (disp_pr = my_pr_open( "/dev/gpone0a" )) == (Pixrect *) 0 )
-	  if ( (disp_pr = my_pr_open( "/dev/cgtwo0" )) == (Pixrect *) 0 )
-	    if ( (disp_pr = my_pr_open( "/dev/cgfour0" )) == (Pixrect *) 0 )
-	      if ( (disp_pr = my_pr_open( "/dev/cgone0" )) == (Pixrect *) 0 )
-	        if ( (disp_pr = my_pr_open( "/dev/fb" )) == (Pixrect *) 0 )
-	        {
-	        fprintf( stderr, "%s: error opening display\n", progname );
-	        exit( 1 );
-	        }
-    return disp_pr;
-
-} /* find_screen */
-
-
-
-Pixrect * my_pr_open( fb )
-char *fb;
-{
-    int fd;
-
-    /*
-     * Test with open first, to avoid stupid error messages from pr_open().
-     */
-    if ( (fd = open(fb, O_RDWR)) == -1 )
-	return (Pixrect *) 0;
-    close( fd );
-
-    return pr_open( fb );
-
-} /* my_pr_open */
-
-
-
-terminate( sig, code, scp )
-int sig, code;
-struct sigcontext *scp;
-{
-    pr_putcolormap( disp_pr, 0, 256, oldred, oldgreen, oldblue );
-    pr_set_plane_group( disp_pr, oldplanes );
-    pr_rop( disp_pr, 0, 0, disp_pr->pr_size.x, disp_pr->pr_size.y,
-	             PIX_CLR, 0, 0, 0 );
-    exit( 0 );
-
-} /* terminate */
-
_E_O_F_
if test 16510 -ne `wc -c < gif2r.c `; then
	echo shar: "'gif2r.c'" unpacked with wrong size!
fi
echo shar: extracting gif2ras.c
if test -f 'gif2ras.c'
then
	echo shar: over-writing existing file "'gif2ras.c'"
fi
sed -e 's/^-//' << \_E_O_F_ > gif2ras.c
-/*********************************************
- *             GIF to SUN rasterfile         *
- *                                           *
- *      March 23 1989 By Marcel J.E. Mol     *
- *                                           *
- * I hereby place this program               *
- * in the public domain, i.e. there are no   *
- * copying restrictions of any kind.         *
- *********************************************/
-
-/* 
- * Usage:
- *        gif2ras <gif-file>
- * 
- * Compile:
- *          cc gif2ras.c -o gif2ras -lpixrect
- * 
- */ 
-
-
-#include <stdio.h>
-#include	<rasterfile.h>
-
-char *malloc();
-int strncmp();
-
-#define FALSE 0
-#define TRUE 1
-#define COLSIZE 256
-#define PICSIZE 2;
-#define SHOWCOUNT 10;
-
-
-/*
- * Rasterfile variables 
- */
-struct rasterfile	header;
-
-/*
- * LZW structures and variables
- */
-typedef int bool;
-unsigned char *stackp;
-unsigned int prefix[4096];
-unsigned char suffix[4096];
-unsigned char stack[4096];
-int datasize,codesize,codemask;     /* Decoder working variables */
-int clear,eoi;                      /* Special code values */
-int avail;
-int oldcode;
-
-/*
- * GIF variables
- */
-FILE *infile;
-unsigned int screenwidth;           /* The dimensions of the screen */
-unsigned int screenheight;          /*   (not those of the image)   */
-unsigned int rscreenwidth;          /* The dimensions of the raster */
-bool global;                        /* Is there a global color map? */
-int globalbits;                     /* Number of bits of global colors */
-unsigned char globalmap[COLSIZE][3];/* RGB values for global color map */
-char bgcolor;                       /* background color */
-unsigned char *raster;              /* Decoded image data */
-unsigned left,top,width,height,rwidth;
-
-char *progname;
-char *filename;
-
-void convert();
-int  checksignature();
-void readscreen();
-int  readimage();
-void readextension();
-int  readraster();
-int  process();
-void outcode();
-void initraster();
-void initcolors();
-int  rasterize();
-void usage();
-
-
-
-
-main(argc,argv)
-int argc;
-char *argv[];
-{
-    extern int optind;
-    extern char *optarg;
-    int flag;
-
-    progname = *argv;
-
-    while ((flag = getopt(argc, argv, "")) != EOF) {
-        switch (flag) {
-            default  : fprintf(stderr, "ignoring unknown flag %c\n", flag);
-                       usage();
-        }
-    }
-
-    if (optind >= argc) {
-        filename = "stdin";
-        convert();
-    }
-    else {
-        filename = argv[1];
-        if ((infile = fopen(filename,"r")) == NULL) {
-            perror(filename);
-            exit(1);
-        }
-        convert();
-        fclose(infile);
-    }
-        
-#if defined(ARGS)
-   else
-        while (optind < argc) {
-            filename = argv[optind];
-            optind++;
-            if ((infile = fopen(filename,"r")) == NULL) {
-                perror(filename);
-                continue;
-            }
-            convert();
-            fclose(infile);
-        }
-#endif
-
-} /* main */
-
-
-
-void convert()
-{
-    char ch;
-
-/*    fprintf(stderr, "%s:\n", filename); */
-    if (checksignature())
-        return;
-    readscreen();
-    while ((ch = getc(infile)) != ';' && ch != EOF) {
-        switch (ch) {
-            case '\0':  break;  /* this kludge for non-standard files */
-            case ',':   if (readimage())
-                           return;
-                        break;
-            case '!':   readextension();
-                        break;
-            default:    fprintf(stderr, "illegal GIF block type\n");
-                        return;
-                        break;
-        }
-    }
-
-} /* convert */
-
-
-
-checksignature()
-{
-    char buf[6];
-
-    fread(buf,1,6,infile);
-    if (strncmp(buf,"GIF",3)) {
-        fprintf(stderr, "file is not a GIF file\n");
-        return 1;
-    }
-    if (strncmp(&buf[3],"87a",3)) {
-        fprintf(stderr, "unknown GIF version number\n");
-        return 1;
-    }
-    return 0;
-
-} /* checksignature */
-
-
-
-/*
- * Get information which is global to all the images stored in the file
- */
-
-void readscreen()
-{
-    unsigned char buf[7];
-
-    fread(buf,1,7,infile);
-    screenwidth = buf[0] + (buf[1] << 8);
-    rscreenwidth = screenwidth + screenwidth%2; /* compensate odd widths */
-    screenheight = buf[2] + (buf[3] << 8);
-    global = buf[4] & 0x80;
-    if (global) {
-        globalbits = (buf[4] & 0x07) + 1;
-        fread(globalmap,3,1<<globalbits,infile);
-    }
-    bgcolor = buf[5];
-/*
-    fprintf(stderr, "    global screen: %dx%dx%d, backgroundcolor: %d\n",
-                screenwidth, screenheight, 1<<globalbits, bgcolor);
-*/
-
-} /* readscreen */
-
-
-
-
-readimage()
-{
-    unsigned char buf[9];
-    bool local, interleaved;
-    char localmap[256][3];
-    int localbits;
-    register row;
-    register i;
-
-    if (fread(buf, 1, 9, infile) == 0) {
-        perror(filename);
-        exit(1);
-    }
-    left = buf[0] + (buf[1] << 8);
-    top = buf[2] + (buf[3] << 8);
-    width = buf[4] + (buf[5] << 8);
-    rwidth = width + width%2; /* compensate odd widths */
-    height = buf[6] + (buf[7] << 8);
-    local = buf[8] & 0x80;
-    interleaved = buf[8] & 0x40;
-/*
-    fprintf(stderr, "    image: %dx%d %s  org: %d,%d\n", width, height,
-              interleaved ? "interleaved" : "", left, top);
-*/
-    if (local == 0 && global == 0) {
-        fprintf(stderr, "no colormap present for image\n");
-        return 1;
-    }
-    if ((raster = (unsigned char*) malloc(rwidth*height)) == NULL) {
-        fprintf(stderr, "not enough memory for image\n");
-        return 1;
-    }
-    if (readraster(width, height))
-        return 1;
-
-    if (local) {
-        localbits = (buf[8] & 0x7) + 1;
-/*
-        fprintf(stderr, "   local colors: %d\n", 1<<localbits);
-*/
-        fread(localmap, 3, 1<<localbits, infile);
-        initraster(1<<localbits);
-        initcolors(localmap, 1<<localbits, bgcolor);
-    } else if (global) {
-        initraster(1<<globalbits);
-        initcolors(globalmap, 1<<globalbits, bgcolor);
-    }
-
-    rasterize(interleaved, raster);
-    free(raster);
-
-    return 0;
-
-} /* readimage */
-
-
-
-/*
- * Read a GIF extension block (and do nothing with it).
- */
-
-void readextension()
-{
-    unsigned char code;
-    int count;
-    char buf[255];
-
-    code = getc(infile);
-    while (count = getc(infile))
-        fread(buf, 1, count, infile);
-
-} /* readextension */
-
-
-
-/*
- * Decode a raster image
- */
-
-readraster(width, height)
-unsigned width,height;
-{
-        unsigned char *fill = raster;
-        unsigned char buf[255];
-        register bits=0;
-        register unsigned datum=0;
-        register unsigned char *ch;
-        register int count, code;
-
-        datasize = getc(infile);
-        clear = 1 << datasize;
-        eoi = clear + 1;
-        avail = clear + 2;
-        oldcode = -1;
-        codesize = datasize + 1;
-        codemask = (1 << codesize) - 1;
-        for (code = 0; code < clear; code++) {
-            prefix[code] = 0;
-            suffix[code] = code;
-        }
-        stackp = stack;
-        for (count = getc(infile); count > 0; count = getc(infile)) {
-            fread(buf,1,count,infile);
-            for (ch=buf; count-- > 0; ch++) {
-                datum += *ch << bits;
-                bits += 8;
-                while (bits >= codesize) {
-                    code = datum & codemask;
-                    datum >>= codesize;
-                    bits -= codesize;
-                    if (code == eoi) {               /* This kludge put in */
-/*
-                        fprintf(stderr, "found eoi code\n");
-*/
-                        goto exitloop;               /* because some GIF files*/
-                    }                                /* aren't standard */
-                    if (process(code, &fill)) {
-                        goto exitloop;
-                    }
-                }
-            }
-            if (fill >= raster + width*height) {
-                fprintf(stderr, "raster full before eoi code\n");
-                goto exitloop;
-            }
-        }
-exitloop:
-        if (fill != raster + width*height)  {
-            fprintf(stderr, "warning: wrong rastersize: %ld bytes\n",
-                      (long) (fill-raster));
-            fprintf(stderr, "         instead of %ld bytes\n",
-                      (long) width*height);
-            return 0; /* can still draw a picture ... */
-        }
-
-        return 0;
-
-} /* readraster */
-
-
-
-
-/*
- * Process a compression code.  "clear" resets the code table.  Otherwise
- * make a new code table entry, and output the bytes associated with the
- * code.
- */
-
-process(code, fill)
-register code;
-unsigned char **fill;
-{
-        int incode;
-        static unsigned char firstchar;
-
-        if (code == clear) {
-            codesize = datasize + 1;
-            codemask = (1 << codesize) - 1;
-            avail = clear + 2;
-            oldcode = -1;
-            return 0;
-        }
-
-        if (oldcode == -1) {
-            *(*fill)++ = suffix[code];
-            firstchar = oldcode = code;
-            return 0;
-        }
-
-        if (code > avail) {
-            fprintf(stderr, "code % d to large for %d\n", code, avail);
-            return 1; 
-        }
-
-        incode = code;
-        if (code == avail) {      /* the first code is always < avail */
-            *stackp++ = firstchar;
-            code = oldcode;
-        }
-        while (code > clear) {
-            *stackp++ = suffix[code];
-            code = prefix[code];
-        }
-
-        *stackp++ = firstchar = suffix[code];
-        prefix[avail] = oldcode;
-        suffix[avail] = firstchar;
-        avail++;
-
-        if (((avail & codemask) == 0) && (avail < 4096)) {
-            codesize++;
-            codemask += avail;
-        }
-
-        oldcode = incode;
-        do {
-            *(*fill)++ = *--stackp;
-        } while (stackp > stack);
-
-        return 0;
-
-} /* process */
-
-
-
-void initraster(numcols)
-int numcols;
-{
-
-  header.ras_magic= 0x59a66a95;
-  header.ras_width= rwidth;
-  header.ras_height= height;
-  header.ras_depth= 8;
-  header.ras_length= rwidth * height;
-  header.ras_type= RT_STANDARD;
-  header.ras_maptype= RMT_EQUAL_RGB;
-  header.ras_maplength= 3*numcols;
-
-  if (fwrite(&header, sizeof(header), 1, stdout) == 0) {
-	perror(progname);
-	exit(1);
-  }
-
-
-} /* initraster */
-
-
-
-/*
- * Convert a color map (local or global) to arrays with R, G and B
- * values. Pass colors to SUNVIEW and set the background color.
- */
-
-void initcolors(colormap, ncolors, bgcolor)
-unsigned char colormap[COLSIZE][3];
-int ncolors;
-int bgcolor;
-{
-    register i;
-    unsigned char red[COLSIZE];
-    unsigned char green[COLSIZE];
-    unsigned char blue[COLSIZE];
-
-/*
-fprintf(stderr, "            ");
-*/
-    for (i = 0; i < ncolors; i++) {
-        red[i]   = colormap[i][0];
-        green[i] = colormap[i][1];
-        blue[i]  = colormap[i][2];
-/*
-fprintf(stderr, "   %3u: %3u, %3u, %3u", i, red[i], green[i], blue[i]);
-if (i%3 == 2) fprintf(stderr, "\n            ");
-*/
-    }
-
-/*
-fprintf(stderr, "\n      Background: %3u: %3u, %3u, %3u\n", bgcolor,
-                          red[bgcolor], green[bgcolor], blue[bgcolor]);
-*/
-
-  if (fwrite(red, 1, ncolors, stdout) == 0) {
-	perror(progname);
-	exit(1);
-  }
-  if (fwrite(green, 1, ncolors, stdout) == 0) {
-	perror(progname);
-	exit(1);
-  }
-  if (fwrite(blue, 1, ncolors, stdout) == 0) {
-	perror(progname);
-	exit(1);
-  }
-  
-} /* initcolors */
-
-
-
-/*
- * Read a row out of the raster image and write it to the screen
- */
-
-rasterize(interleaved, raster)
-int interleaved;
-register unsigned char *raster;
-{
-    register row, col;
-    register unsigned char *rr;
-    unsigned char * newras;
-    
-   
-    
-#define DRAWSEGMENT(offset, step)                       \
-        for (row = offset; row < height; row += step) { \
-            rr = newras + row*rwidth;                   \
-            bcopy(raster, rr, width);                   \
-            raster += width;                            \
-        }
-
-
-    if ((newras = (unsigned char*) malloc(rwidth*height)) == NULL) {
-        fprintf(stderr, "not enough memory for image\n");
-        return 1;
-    }
-    rr = newras;
-    if (interleaved) {
-        DRAWSEGMENT(0, 8);
-        DRAWSEGMENT(4, 8);
-        DRAWSEGMENT(2, 4);
-        DRAWSEGMENT(1, 2);
-    }
-    else 
-        DRAWSEGMENT(0, 1);
-
-    if (!fwrite(newras, 1, rwidth*height, stdout)) {
-        perror(progname);
-        exit(1);
-    }
-
-    free(newras);
-
-
-} /* rasterize */
-
-
-
-void usage()
-{
-
-        fprintf(stderr, "usage: %s [-l<num] [-s<num>] [-b] gif-files\n",
-                        progname);
-
-} /* usage */
-
_E_O_F_
if test 12405 -ne `wc -c < gif2ras.c `; then
	echo shar: "'gif2ras.c'" unpacked with wrong size!
fi
echo shar: extracting gif2sun.c
if test -f 'gif2sun.c'
then
	echo shar: over-writing existing file "'gif2sun.c'"
fi
sed -e 's/^-//' << \_E_O_F_ > gif2sun.c
-/*********************************************
- *             GIF viewer on SUNVIEW         *
- *                                           *
- *      March 23 1989 By Marcel J.E. Mol     *
- *                                           *
- * I hereby place this program               *
- * in the public domain, i.e. there are no   *
- * copying restrictions of any kind.         *
- *********************************************/
-
-/* 
- * Here is a gif viewer for the SUN running suntools (or sunview).
- * It is intended for color monitors (8 planes) and I don't
- * know how it will react on a monochrome screen.
- * It is rather slow because it uses call to sunview for 
- * each pixel. Should be converted to use rasterfiles one day...
- * 
- * Little help:
- *     left button: exit a picture being drawn, and starts the following
- *                  picture, if any.
- *     right button: exit program immediately.
- *     middle button: when a picture is ready pressing the middle button
- *                    will start the following picture, if any.
- * 
- * Usage:
- *        gif2sun [-sn -ln -b] <gif-files>
- * 
- *       -sn : tries to expand a picture n times.
- *       -ln : number of lines to hold for sunview batch mode.
- *       -b  : disable optimization done by not drawing pixels in 
- *             the background color.
- * 
- * Compile:
- *          cc gif2sun.c -o gif2sun -lsuntool -lsunwindow -lpixrect
- * 
- */ 
-
-#define FAST
-
-#include <stdio.h>
-#include <suntool/sunview.h>
-#include <suntool/panel.h>
-#include <suntool/canvas.h>
-
-/* Change event_action to event_id(event) for pre 4.0 */
-#ifndef event_action
-#define event_action event_id
-#define oldSunOS
-#endif
-
-#ifndef oldSunOS
-#include <suntool/alert.h>	/* Only for SunOS 4 */
-#include <alloca.h>		/* Cannot find this on 3.5 */
-#endif
-
-char *malloc();
-int strncmp();
-
-#define FALSE 0
-#define TRUE 1
-#define COLSIZE 256
-#define PICSIZE 1;
-#define SHOWCOUNT 10;
-
-#define BUTTONFONT "/usr/lib/fonts/fixedwidthfonts/gallant.r.19"
-static char *default_font =
-       "DEFAULT_FONT=/usr/lib/fonts/fixedwidthfonts/screen.r.13";
-
-/*
- * Sunview variables 
- */
-static Frame fr;
-static Canvas cv;
-static Pixwin *pw;
-static Panel pn;
-static Pixfont *bf, *pf;
-
-/*
- * LZW structures and variables
- */
-typedef int bool;
-unsigned char *stackp;
-unsigned int prefix[4096];
-unsigned char suffix[4096];
-unsigned char stack[4096];
-int datasize,codesize,codemask;     /* Decoder working variables */
-int clear,eoi;                      /* Special code values */
-int avail;
-int oldcode;
-
-/*
- * GIF variables
- */
-FILE *infile;
-unsigned int screenwidth;           /* The dimensions of the screen */
-unsigned int screenheight;          /*   (not those of the image)   */
-bool global;                        /* Is there a global color map? */
-int globalbits;                     /* Number of bits of global colors */
-unsigned char globalmap[COLSIZE][3];/* RGB values for global color map */
-char bgcolor;                       /* background color */
-unsigned char *raster;              /* Decoded image data */
-unsigned left,top,width,height;
-
-char *progname;
-char *filename;
-unsigned int windowwidth = 0;
-unsigned int windowheight = 0;
-unsigned int size;                  /* scale factor */
-
-unsigned int initsize = PICSIZE;
-int endpicflag = FALSE;
-int drawflag;
-unsigned int showcount = SHOWCOUNT;
-int dobgflag = FALSE;
-
-void convert();
-int  checksignature();
-void readscreen();
-int  readimage();
-void readextension();
-int  readraster();
-int  process();
-void outcode();
-void initsunview();
-void setupsunview();
-void initcolors();
-int  rasterize();
-void waitevent();
-void handlevent();
-void usage();
-
-
-
-
-main(argc,argv)
-int argc;
-char *argv[];
-{
-    extern int optind;
-    extern char *optarg;
-    int flag;
-
-    progname = *argv;
-    while ((flag = getopt(argc, argv, "s:l:b")) != EOF) {
-        switch (flag) {
-            case 's' : if ((initsize = atoi(optarg)) <= 0) {
-                           initsize = PICSIZE;
-                           fprintf(stderr, "scale factor must more than 1\n");
-                       }
-                       break;
-            case 'l' : if ((showcount = atoi(optarg)) <= 0) {
-                           showcount = SHOWCOUNT;
-                           fprintf(stderr, "showcount must more than 1\n");
-                       }
-                       break;
-            case 'b' : dobgflag = TRUE;
-                       break;
-            default  : fprintf(stderr, "ignoring unknown flag %c\n", flag);
-                       usage();
-        }
-    }
-
-    initsunview();
-    if (optind >= argc) {
-        filename = "stdin";
-        convert();
-    }
-    else
-        while (optind < argc) {
-            filename = argv[optind];
-            optind++;
-            if ((infile = fopen(filename,"r")) == NULL) {
-                perror(filename);
-                continue;
-            }
-            convert();
-            fclose(infile);
-        }
-
-    if (drawflag)        /* wait for last picture if fully drawn */
-        waitevent();
-
-} /* main */
-
-
-
-void convert()
-{
-    char ch;
-
-    printf("%s:\n", filename);
-    if (checksignature())
-        return;
-    readscreen();
-    size = initsize;
-    while ((ch = getc(infile)) != ';' && ch != EOF) {
-        switch (ch) {
-            case '\0':  break;  /* this kludge for non-standard files */
-            case ',':   if (readimage())
-                           return;
-                        break;
-            case '!':   readextension();
-                        break;
-            default:    printf(stderr, "illegal GIF block type\n");
-                        return;
-                        break;
-        }
-    }
-
-} /* convert */
-
-
-
-checksignature()
-{
-    char buf[6];
-
-    fread(buf,1,6,infile);
-    if (strncmp(buf,"GIF",3)) {
-        fprintf(stderr, "file is not a GIF file\n");
-        return 1;
-    }
-    if (strncmp(&buf[3],"87a",3)) {
-        fprintf(stderr, "unknown GIF version number\n");
-        return 1;
-    }
-    return 0;
-
-} /* checksignature */
-
-
-
-/*
- * Get information which is global to all the images stored in the file
- */
-
-void readscreen()
-{
-    unsigned char buf[7];
-
-    fread(buf,1,7,infile);
-    screenwidth = buf[0] + (buf[1] << 8);
-    screenheight = buf[2] + (buf[3] << 8);
-    global = buf[4] & 0x80;
-    if (global) {
-        globalbits = (buf[4] & 0x07) + 1;
-        fread(globalmap,3,1<<globalbits,infile);
-    }
-    bgcolor = buf[5];
-    printf("    global screen: %dx%dx%d, backgroundcolor: %d\n",
-                screenwidth, screenheight, 1<<globalbits, bgcolor);
-
-} /* readscreen */
-
-
-
-
-readimage()
-{
-    unsigned char buf[9];
-    bool local, interleaved;
-    char localmap[256][3];
-    int localbits;
-    register row;
-    register i;
-    static int waitflag = FALSE;
-
-    fread(buf, 1, 9, infile);
-    left = buf[0] + (buf[1] << 8);
-    top = buf[2] + (buf[3] << 8);
-    width = buf[4] + (buf[5] << 8);
-    height = buf[6] + (buf[7] << 8);
-    local = buf[8] & 0x80;
-    interleaved = buf[8] & 0x40;
-    printf("    image: %dx%d %s  org: %d,%d\n", width, height,
-              interleaved ? "interleaved" : "", left, top);
-    if (local == 0 && global == 0) {
-        fprintf(stderr, "no colormap present for image\n");
-        return 1;
-    }
-    if ((raster = (unsigned char*) malloc(width*height)) == NULL) {
-        fprintf(stderr, "not enough memory for image\n");
-        return 1;
-    }
-    if (readraster(width, height))
-        return 1;
-
-    if (waitflag)         /* if first picture or previous picture is   */
-        waitevent();      /* interrupted, don't wait for a buttonpress */
-
-    setupsunview(screenwidth, screenheight);
-    if (local) {
-        localbits = (buf[8] & 0x7) + 1;
-        printf("   local colors: %d\n", 1<<localbits);
-        fread(localmap, 3, 1<<localbits, infile);
-        initcolors(localmap, 1<<localbits, bgcolor);
-    } else if (global)
-        initcolors(globalmap, 1<<globalbits, bgcolor);
-
-    waitflag = rasterize(interleaved, raster);
-    free(raster);
-
-    return 0;
-
-} /* readimage */
-
-
-
-/*
- * Read a GIF extension block (and do nothing with it).
- */
-
-void readextension()
-{
-    unsigned char code;
-    int count;
-    char buf[255];
-
-    code = getc(infile);
-    while (count = getc(infile)) fread(buf, 1, count, infile);
-
-} /* readextension */
-
-
-
-/*
- * Decode a raster image
- */
-
-readraster(width, height)
-unsigned width,height;
-{
-        unsigned char *fill = raster;
-        unsigned char buf[255];
-        register bits=0;
-        register unsigned datum=0;
-        register unsigned char *ch;
-        register int count, code;
-
-        datasize = getc(infile);
-        clear = 1 << datasize;
-        eoi = clear + 1;
-        avail = clear + 2;
-        oldcode = -1;
-        codesize = datasize + 1;
-        codemask = (1 << codesize) - 1;
-        for (code = 0; code < clear; code++) {
-            prefix[code] = 0;
-            suffix[code] = code;
-        }
-        stackp = stack;
-        for (count = getc(infile); count > 0; count = getc(infile)) {
-            fread(buf,1,count,infile);
-            for (ch=buf; count-- > 0; ch++) {
-                datum += *ch << bits;
-                bits += 8;
-                while (bits >= codesize) {
-                    code = datum & codemask;
-                    datum >>= codesize;
-                    bits -= codesize;
-                    if (code == eoi) {               /* This kludge put in */
-#if defined(DEBUG)
-                        printf("found eoi code\n");
-#endif
-                        goto exitloop;               /* because some GIF files */
-                    }                                /* aren't standard */
-                    if (process(code, &fill)) 
-                        goto exitloop;
-                }
-            }
-            if (fill >= raster + width*height) {
-                fprintf(stderr, "raster full before eoi code\n");
-                goto exitloop;
-            }
-        }
-exitloop:
-        if (fill != raster + width*height)  {
-            fprintf(stderr, "warning: wrong rastersize: %ld bytes\n",
-                      (long) (fill-raster));
-            fprintf(stderr, "         instead of %ld bytes\n",
-                      (long) width*height);
-            return 0;  /* but try to show picture ... */
-        }
-
-        return 0;
-
-} /* readraster */
-
-
-
-
-/*
- * Process a compression code.  "clear" resets the code table.  Otherwise
- * make a new code table entry, and output the bytes associated with the
- * code.
- */
-
-process(code, fill)
-register code;
-unsigned char **fill;
-{
-        int incode;
-        static unsigned char firstchar;
-
-        if (code == clear) {
-#if defined(DEBUG)
-            fprintf(stderr, "clear encountered\n");
-#endif
-            codesize = datasize + 1;
-            codemask = (1 << codesize) - 1;
-            avail = clear + 2;
-            oldcode = -1;
-            return 0;
-        }
-
-        if (code > avail) {
-            fprintf(stderr, "code %d to large for %d\n", code, avail);
-            code = avail;
-            return 1;  
-        }
-
-        if (oldcode == -1) {
-            *(*fill)++ = suffix[code];
-            firstchar = oldcode = code;
-            return 0;
-        }
-
-        incode = code;
-        if (code == avail) {      /* the first code is always < avail */
-            *stackp++ = firstchar;
-            code = oldcode;
-        }
-        while (code > clear) {
-            *stackp++ = suffix[code];
-            code = prefix[code];
-        }
-
-        *stackp++ = firstchar = suffix[code];
-        prefix[avail] = oldcode;
-        suffix[avail] = firstchar;
-if (avail < 4096)
-        avail++;
-
-        if (((avail & codemask) == 0) && (avail < 4096)) {
-            codesize++;
-            codemask += avail;
-        }
-#if defined(DEBUG)
-        if (avail >= 4096) {
-            fprintf(stderr, "tables full, avail = %d\n", avail);
-        }
-#endif
-
-        oldcode = incode;
-        do {
-            *(*fill)++ = *--stackp;
-        } while (stackp > stack);
-
-        return 0;
-
-} /* process */
-
-
-
-void initsunview()
-{
-
-   (void) putenv(default_font);
-    bf = pf_open(BUTTONFONT);
-    pf = pf_default();
-
-} /* initsunview */
-
-
-
-void setupsunview(width, height)
-unsigned width, height;
-{
-    static havewin = FALSE;
-    char title[128];
-    unsigned rwidth;
-
-    rwidth = width + width%2;    /* compensate for odd width */
-    while ((size*rwidth > 1000) && (size > 1))
-        size--;
-    rwidth *= size;
-    height *= size;
-    if ((windowwidth < rwidth) || (windowheight < height)) {
-        windowwidth = rwidth;
-        windowheight = height;
-/*        if (havewin)    DESTROYING WINDOWS RESULT IN SEGMENTATION FAULTS 
-            window_destroy(fr); */
-        fr = window_create(0, FRAME,
-             WIN_X, 5,
-             WIN_Y, 50,
-             WIN_SHOW, TRUE,
-             FRAME_LABEL, "Gif to Sun",
-             0);
-        havewin = TRUE;
-        pn = window_create(fr, PANEL, 0);
-        panel_create_item(pn, PANEL_MESSAGE,
-                           PANEL_ITEM_X, 5,
-                           PANEL_ITEM_Y, 5,
-                           PANEL_LABEL_STRING, "File:",
-                           0);
-        window_fit_height(pn);
-        cv = window_create(fr, CANVAS,
-		           WIN_WIDTH, windowwidth,
-		           WIN_HEIGHT, windowheight,
-		           WIN_CONSUME_PICK_EVENT, LOC_DRAG, 
-		           WIN_EVENT_PROC, handlevent, 
-		           0);
-
-        window_fit(fr);
-        pw = canvas_pixwin(cv);
-        notify_interpose_destroy_func(fr, handlevent);
-        pw_setcmsname(pw, "gif colors");
-    }
-
-    notify_dispatch();     /* show the correct window */
-    sprintf(title, "%-20s", filename);
-    panel_pw_text(pn, 50, 5+panel_fonthome(pf), PIX_SRC, pf, title);
-
-} /* setupsunview */
-
-
-
-/*
- * Convert a color map (local or global) to arrays with R, G and B
- * values. Pass colors to SUNVIEW and set the background color.
- */
-
-void initcolors(colormap, ncolors, bgcolor)
-unsigned char colormap[COLSIZE][3];
-int ncolors;
-int bgcolor;
-{
-    register i;
-    unsigned char red[COLSIZE];
-    unsigned char green[COLSIZE];
-    unsigned char blue[COLSIZE];
-
-#if defined(DEBUG)
-    printf("            ");
-#endif
-    for (i = 0; i < ncolors; i++) {
-        red[i]   = colormap[i][0];
-        green[i] = colormap[i][1];
-        blue[i]  = colormap[i][2];
-#if defined(DEBUG)
-        printf("   %3u: %3u, %3u, %3u", i, red[i], green[i], blue[i]);
-        if (i%3 == 2)
-            printf("\n            ");
-#endif
-    }
-    pw_putcolormap(pw, 0, COLSIZE, red, green, blue);
-
-#if defined(DEBUG)
-    printf("\n      Background: %3u: %3u, %3u, %3u\n", bgcolor,
-                          red[bgcolor], green[bgcolor], blue[bgcolor]);
-#endif
-    pw_writebackground(pw, 0, 0, windowwidth, windowheight,
-                           PIX_SET | PIX_COLOR(bgcolor));
-
-} /* initcolors */
-
-
-
-/*
- * Read a row out of the raster image and write it to the screen
- */
-#ifdef FAST
-rasterize(interleaved, raster)
-int interleaved;
-register unsigned char *raster;
-{
-    register row, col;
-    register unsigned char *rr;
-    unsigned char * newras;
-    Pixrect *picture;
-    int rwidth;
-    
-#define DRAWSEGMENT(offset, step)                             \
-        for (row = offset; row < height; row += step) {       \
-            rr = newras + row*rwidth;                          \
-            bcopy(raster, rr, rwidth);                         \
-            raster += width;                                  \
-        }
-
-
-    panel_pw_text(pn, 250, 5+panel_fonthome(pf), PIX_SRC, pf, "Drawing");
-    drawflag = TRUE;
-    rwidth = width + width%2;    /* compensate for odd width */
-        if ((newras = (unsigned char*) malloc(rwidth*height)) == NULL) {
-            fprintf(stderr, "not enough memory for image\n");
-            return 1;
-        }
-    if (interleaved) {
-        DRAWSEGMENT(0, 8);
-        DRAWSEGMENT(4, 8);
-        DRAWSEGMENT(2, 4);
-        DRAWSEGMENT(1, 2);
-    }
-    else 
-       DRAWSEGMENT(0, 1);
-/*        newras = raster; */
-
-    picture = mem_point(screenwidth, screenheight, 8, newras);
-    pw_rop(pw, left, top, width, height,
-                PIX_SRC, picture, 0, 0); 
-
-    /*if (interleaved) */
-        free(newras);
-    panel_pw_text(pn, 250, 5+panel_fonthome(pf), PIX_SET, pf, "       ");
-    return drawflag;
-
-} /* rasterize */
-
-#else
-
-rasterize(interleaved, raster)
-int interleaved;
-register unsigned char *raster;
-{
-    register row, col;
-    register c, lc;
-   
-fprintf(stderr, " you use the slow version\n");
-
-#define DRAWSEGMENT(offset, step)                                        \
-        for (row = top+offset; row < top+height; row += step) {          \
-            notify_dispatch();                                           \
-            if (!drawflag)                                               \
-                goto quitdraw;                                           \
-            for (col = left; col < left+width; col++)                    \
-              if ((c = *raster++) != bgcolor || dobgflag)                \
-                pw_rop(pw, size*col, size*row, size, size,               \
-                           PIX_SRC | PIX_COLOR(c), (Pixrect *) 0, 0, 0); \
-            if (lc++ == showcount) {                                     \
-                lc = 0;                                                  \
-                pw_show(pw);                                             \
-            }                                                            \
-        }
-
-
-    panel_pw_text(pn, 250, 5+panel_fonthome(pf), PIX_SRC, pf, "Drawing");
-    pw_batch_on(pw);
-    drawflag = TRUE;
-    lc = 0;
-    if (interleaved) {
-        DRAWSEGMENT(0, 8);
-        DRAWSEGMENT(4, 8);
-        DRAWSEGMENT(2, 4);
-        DRAWSEGMENT(1, 2);
-    }
-    else {
-        DRAWSEGMENT(0, 1);
-    }
-
-quitdraw:
-    pw_batch_off(pw);
-    panel_pw_text(pn, 250, 5+panel_fonthome(pf), PIX_SRC, pf, "       ");
-    return drawflag;
-
-} /* rasterize */
-
-#endif
-
-
-void waitevent()
-{
-
-    while(endpicflag == FALSE) {
-        notify_dispatch();
-        usleep(50000);
-    }
-    endpicflag = FALSE;
-
-} /* waitevent */
-
-
-
-void handlevent(canvas, event, arg)
-Canvas *canvas;
-Event *event;
-char *arg;
-{
-
-    switch (event_action(event)) {
-        case MS_RIGHT:
-                if (event_is_down(event))
-#ifdef oldSunOS
-                exit(0);	/* You won't miss the following fancy stuff.. */
-#else
-                    if (alert_prompt(fr, (Event *)0, ALERT_MESSAGE_STRINGS,
-		          "Please confirm:", "Do you know what you're doing??",
-		          0,
-		          ALERT_BUTTON_YES, "Of course, quit bugging me!",
-		          ALERT_BUTTON_NO, "Sorry, I hit the wrong button...",
-		          ALERT_MESSAGE_FONT, bf,
-		          ALERT_BUTTON_FONT, pf,
-		          0)
-                          == ALERT_YES) 
-                        exit(0);
-                    else
-                        notify_veto_destroy(fr);
-#endif
-                break;
-        case MS_LEFT:
-                if (event_is_down(event))
-                    drawflag = FALSE;
-                break;
-        case MS_MIDDLE:
-                if (event_is_down(event))
-                    endpicflag = TRUE;
-                break;
-    }
-
-} /* handlevent */
-
-
-
-void usage()
-{
-
-        fprintf(stderr, "usage: %s [-l<num] [-s<num>] [-b] gif-files\n",
-                        progname);
-
-} /* usage */
-
_E_O_F_
if test 19279 -ne `wc -c < gif2sun.c `; then
	echo shar: "'gif2sun.c'" unpacked with wrong size!
fi
echo shar: extracting gifinfo.c
if test -f 'gifinfo.c'
then
	echo shar: over-writing existing file "'gifinfo.c'"
fi
sed -e 's/^-//' << \_E_O_F_ > gifinfo.c
-/*********************************************
- *             GIF viewer on SUNVIEW         *
- *                                           *
- *      March 23 1989 By Marcel J.E. Mol     *
- *                                           *
- * I hereby place this program               *
- * in the public domain, i.e. there are no   *
- * copying restrictions of any kind.         *
- *********************************************/
-
-#include <stdio.h>
-
-char *malloc();
-int strncmp();
-
-#define FALSE 0
-#define TRUE 1
-#define COLSIZE 256
-
-/*
- * LZW structures and variables
- */
-typedef int bool;
-unsigned char *stackp;
-unsigned int prefix[4096];
-unsigned char suffix[4096];
-unsigned char stack[4096];
-int datasize,codesize,codemask;     /* Decoder working variables */
-int clear,eoi;                      /* Special code values */
-int avail;
-int oldcode;
-
-/*
- * GIF variables
- */
-FILE *infile;
-unsigned int screenwidth;           /* The dimensions of the screen */
-unsigned int screenheight;          /*   (not those of the image)   */
-bool global;                        /* Is there a global color map? */
-int globalbits;                     /* Number of bits of global colors */
-unsigned char globalmap[COLSIZE][3];/* RGB values for global color map */
-char bgcolor;                       /* background color */
-unsigned char *raster;              /* Decoded image data */
-unsigned left,top,width,height;
-
-char *progname;
-char *filename;
-
-
-void convert();
-int  checksignature();
-void readscreen();
-int  readimage();
-void readextension();
-int  readraster();
-int  process();
-void outcode();
-void initcolors();
-void usage();
-
-
-
-
-main(argc,argv)
-int argc;
-char *argv[];
-{
-    extern int optind;
-    extern char *optarg;
-    int flag;
-
-    progname = *argv;
-    while ((flag = getopt(argc, argv, "")) != EOF) {
-        switch (flag) {
-            default  : fprintf(stderr, "ignoring unknown flag %c\n", flag);
-                       usage();
-        }
-    }
-
-    if (optind >= argc) {
-        filename = "stdin";
-        convert();
-    }
-    else
-        while (optind < argc) {
-            filename = argv[optind];
-            optind++;
-            if ((infile = fopen(filename,"r")) == NULL) {
-                perror(filename);
-                continue;
-            }
-            convert();
-            fclose(infile);
-        }
-
-} /* main */
-
-
-
-void convert()
-{
-    char ch;
-
-    printf("%s:\n", filename);
-    if (checksignature())
-        return;
-    readscreen();
-    while ((ch = getc(infile)) != ';' && ch != EOF) {
-        switch (ch) {
-            case '\0':  break;  /* this kludge for non-standard files */
-            case ',':   if (readimage())
-                           return;
-                        break;
-            case '!':   readextension();
-                        break;
-            default:    printf(stderr, "illegal GIF block type\n");
-                        return;
-                        break;
-        }
-    }
-
-} /* convert */
-
-
-
-checksignature()
-{
-    char buf[6];
-
-    fread(buf,1,6,infile);
-    if (strncmp(buf,"GIF",3)) {
-        fprintf(stderr, "file is not a GIF file\n");
-        return 1;
-    }
-    if (strncmp(&buf[3],"87a",3)) {
-        fprintf(stderr, "unknown GIF version number\n");
-        return 1;
-    }
-    return 0;
-
-} /* checksignature */
-
-
-
-/*
- * Get information which is global to all the images stored in the file
- */
-
-void readscreen()
-{
-    unsigned char buf[7];
-
-    fread(buf,1,7,infile);
-    screenwidth = buf[0] + (buf[1] << 8);
-    screenheight = buf[2] + (buf[3] << 8);
-    global = buf[4] & 0x80;
-    if (global) {
-        globalbits = (buf[4] & 0x07) + 1;
-        fread(globalmap,3,1<<globalbits,infile);
-    }
-    bgcolor = buf[5];
-    printf("    global screen: %dx%dx%d, backgroundcolor: %d\n",
-                screenwidth, screenheight, 1<<globalbits, bgcolor);
-
-} /* readscreen */
-
-
-
-
-readimage()
-{
-    unsigned char buf[9];
-    bool local, interleaved;
-    char localmap[256][3];
-    int localbits;
-    register row;
-    register i;
-    static int waitflag = FALSE;
-
-    fread(buf, 1, 9, infile);
-    left = buf[0] + (buf[1] << 8);
-    top = buf[2] + (buf[3] << 8);
-    width = buf[4] + (buf[5] << 8);
-    height = buf[6] + (buf[7] << 8);
-    local = buf[8] & 0x80;
-    interleaved = buf[8] & 0x40;
-    printf("    image: %dx%d %s  org: %d,%d\n", width, height,
-              interleaved ? "interleaved" : "", left, top);
-    if (local == 0 && global == 0) {
-        fprintf(stderr, "no colormap present for image\n");
-        return 1;
-    }
-    if ((raster = (unsigned char*) malloc(width*height)) == NULL) {
-        fprintf(stderr, "not enough memory for image\n");
-        return 1;
-    }
-    if (readraster(width, height))
-        return 1;
-
-    if (local) {
-        localbits = (buf[8] & 0x7) + 1;
-        printf("   local colors: %d\n", 1<<localbits);
-        fread(localmap, 3, 1<<localbits, infile);
-        initcolors(localmap, 1<<localbits, bgcolor);
-    } else if (global)
-        initcolors(globalmap, 1<<globalbits, bgcolor);
-
-    free(raster);
-
-    return 0;
-
-} /* readimage */
-
-
-
-/*
- * Read a GIF extension block (and do nothing with it).
- */
-
-void readextension()
-{
-    unsigned char code;
-    int count;
-    char buf[255];
-
-    code = getc(infile);
-    while (count = getc(infile))
-        fread(buf, 1, count, infile);
-
-} /* readextension */
-
-
-
-/*
- * Decode a raster image
- */
-
-readraster(width, height)
-unsigned width,height;
-{
-        unsigned char *fill = raster;
-        unsigned char buf[255];
-        register bits=0;
-        register unsigned datum=0;
-        register unsigned char *ch;
-        register int count, code;
-        int i, tcount;
-
-        datasize = getc(infile);
-        clear = 1 << datasize;
-        eoi = clear + 1;
-        avail = clear + 2;
-        oldcode = -1;
-        codesize = datasize + 1;
-        codemask = (1 << codesize) - 1;
-        for (code = 0; code < clear; code++) {
-            prefix[code] = 0;
-            suffix[code] = code;
-        }
-        stackp = stack;
-        for (count = getc(infile); count > 0; count = getc(infile)) {
-            tcount = count;
-printf("new buffer, %d bytes\n", tcount);
-            fread(buf,1,count,infile);
-            for (ch=buf; count-- > 0; ch++) {
-                datum += *ch << bits;
-                bits += 8;
-                while (bits >= codesize) {
-                    code = datum & codemask;
-                    datum >>= codesize;
-                    bits -= codesize;
-if (code > avail) {
-printf("\ncode to large, buffer has %d bytes, %d bytes processed\n",
-        tcount, tcount-count);
-printf("datum %0X, code %0X(%d), bits %d, codesize %d, avail %d, codemask %0X\n",
-      datum, code, code, bits, codesize, avail, codemask);
-for (i=0; i < tcount; i++) {
-   if (i%20 == 0) putchar('\n');
-   printf("%x ", buf[i]);
-}
-}
-                    if (code == eoi) {               /* This kludge put in */
-                        printf("found eoi code\n");
-                        goto exitloop;               /* because some GIF files */
-                    }                                /* aren't standard */
-                    if (process(code, &fill))
-                        goto exitloop;
-                }
-            }
-            if (fill >= raster + width*height) {
-                fprintf(stderr, "raster full before eoi code\n");
-                goto exitloop;
-            }
-        }
-exitloop:
-printf("last count %d\n", count);
-        if (fill != raster + width*height) {
-            fprintf(stderr, "warning: wrong rastersize: %ld bytes\n",
-                      (long) (fill-raster));
-            fprintf(stderr, "         instead of %ld bytes\n",
-                      (long) width*height);
-            return 0; /* still show info ... */
-        }
-
-        return 0;
-
-} /* readraster */
-
-
-
-
-/*
- * Process a compression code.  "clear" resets the code table.  Otherwise
- * make a new code table entry, and output the bytes associated with the
- * code.
- */
-
-process(code, fill)
-register code;
-unsigned char **fill;
-{
-        int incode;
-        static unsigned char firstchar;
-
-int cnt = 0;
-        if (code == clear) {
-/* printf("\nC0."); */
-printf("clear ");
-            codesize = datasize + 1;
-            codemask = (1 << codesize) - 1;
-            avail = clear + 2;
-            oldcode = -1;
-            return 0;
-        }
-
-        if (oldcode == -1) {
-/* printf("F1."); */
-            *(*fill)++ = suffix[code];
-            firstchar = oldcode = code;
-            return 0;
-        }
-
-        if (code > avail) {
-            fprintf(stderr, "code % d to large for %d\n", code, avail);
-        /*    return 1; */
-        }
-
-        incode = code;
-        if (code == avail) {      /* the first code is always < avail */
-/* putchar('#'); */
-cnt++;
-            *stackp++ = firstchar;
-            code = oldcode;
-        }
-        while (code > clear) {
-cnt++;
-            *stackp++ = suffix[code];
-            code = prefix[code];
-        }
-/* printf("%d.", ++cnt); */
-
-        *stackp++ = firstchar = suffix[code];
-        prefix[avail] = oldcode;
-        suffix[avail] = firstchar;
-        avail++;
-
-        if (((avail & codemask) == 0) && avail < 4096) {
-/* printf("A\n"); */
-printf(" sizeplus ");
-            codesize++;
-            codemask += avail;
-        }
-if (avail >4096)
-    printf("avail(%d)", avail);
-
-        oldcode = incode;
-        do {
-            *(*fill)++ = *--stackp;
-        } while (stackp > stack);
-
-        return 0;
-
-} /* process */
-
-
-
-/*
- * Convert a color map (local or global) to arrays with R, G and B
- * values. Pass colors to SUNVIEW and set the background color.
- */
-
-void initcolors(colormap, ncolors, bgcolor)
-unsigned char colormap[COLSIZE][3];
-int ncolors;
-int bgcolor;
-{
-    register i;
-    unsigned char red[COLSIZE];
-    unsigned char green[COLSIZE];
-    unsigned char blue[COLSIZE];
-
-#if defined(DEBUG)
-printf("            ");
-#endif
-    for (i = 0; i < ncolors; i++) {
-        red[i]   = colormap[i][0];
-        green[i] = colormap[i][1];
-        blue[i]  = colormap[i][2];
-#if defined(DEBUG)
-printf("   %3u: %3u, %3u, %3u", i, red[i], green[i], blue[i]);
-if (i%3 == 2) printf("\n            ");
-#endif
-    }
-
-#if defined(DEBUG)
-printf("\n      Background: %3u: %3u, %3u, %3u\n", bgcolor,
-                          red[bgcolor], green[bgcolor], blue[bgcolor]);
-#endif
-
-} /* initcolors */
-
-
-
-void usage()
-{
-
-        fprintf(stderr, "usage: %s [-l<num] [-s<num>] [-b] gif-files\n",
-                        progname);
-
-} /* usage */
-
_E_O_F_
if test 10471 -ne `wc -c < gifinfo.c `; then
	echo shar: "'gifinfo.c'" unpacked with wrong size!
fi
# end of shell archive
exit 0
-- 
#########################################
# Marcel J.E. Mol                       # They hate you if your're clever
# Delft, University of Technology       # And they despise the fool
# The Netherlands                       # Till you're so fucking crazy
# UUCP: marcel at duteca.tudelft.nl        # You can't follow the rules.
#       duteca!marcel                  	#
#########################################			 - Lennon



More information about the Comp.sources.misc mailing list