home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume5 / xldimage / patch3.2-2 < prev    next >
Encoding:
Internet Message Format  |  1993-04-28  |  19.1 KB

  1. From: kent@ssbell.IMD.Sterling.COM (Kent Landfield)
  2. Newsgroups: comp.sources.x
  3. Subject: v05i073: Xloadimage, Patch03, Part02/02
  4. Message-ID: <655@ssbell.IMD.Sterling.COM>
  5. Date: 5 Feb 90 05:28:30 GMT
  6. Approved: kent@ssbell.IMD.Sterling.COM (Kent Landfield)
  7.  
  8. Submitted-by: Jim Frost <jimf@saber.com>
  9. Posting-number: Volume 5, Issue 73
  10. Archive-name: xldimage/patch3.2-2
  11. Patch-To: xldimage: Volume 5, Issue 27-28,30
  12.  
  13.  
  14. This is part 2 of a 2 part patch to xloadimage to bring it from
  15. patchlevel 02 to patchlevel 03.
  16.  
  17. There are many bug fixes and improvements in patchlevel 03, including
  18. a new loader for GIF images.  This version should work on most X
  19. servers, including those with depths of odd values such as 2 or 4 (eg
  20. 386/ix servers).  See the README file for more information.
  21.  
  22. Part 1 contains a patch file which should be applied to a virgin
  23. patchlevel 02 source directory.  Save it in the file "patch.03" and
  24. apply via "patch < patch.03".
  25.  
  26. Part 2, which follows, contains a shar file with the new GIF loader
  27. and associated header files.  Save it in the file "patch.03.shar" and
  28. unpack it via "sh patch.03.shar".
  29.  
  30. If you do not have xloadimage or do not have it updated to patchlevel
  31. 02, you can get the original source (distributed at patchlevel 01) and
  32. the 02 patch from the comp.sources.x archives, or you can get the full
  33. distribution from expo.lcs.mit.edu in /contrib/xloadimage.1.03.tar.Z
  34. via anonymous ftp.  The original source and 02 patch are also on expo
  35. but have been moved to /oldcontrib.
  36.  
  37. Feel free to email any questions or comments.
  38.  
  39. Enjoy,
  40.  
  41. jim frost
  42. saber software
  43. jimf@saber.com
  44.  
  45. -- patch.03.shar: cut here --
  46. # This is a shell archive.  Remove anything before this line, then
  47. # unpack it by saving it in a file and typing "sh file".  (Files
  48. # unpacked will be owned by you and have default permissions.)
  49. #
  50. # This archive contains:
  51. # gif.c gif.h kljcpyrght.h
  52.  
  53. echo x - gif.c
  54. cat > "gif.c" << '//E*O*F gif.c//'
  55. /* gif.c:
  56.  *
  57.  * adapted from code by kirk johnson (tuna@athena.mit.edu).  most of this
  58.  * code is unchanged. -- jim frost 12.31.89
  59.  *
  60.  * gifin.c
  61.  * kirk johnson
  62.  * november 1989
  63.  *
  64.  * routines for reading GIF files
  65.  *
  66.  * Copyright 1989 Kirk L. Johnson (see the included file
  67.  * "kljcpyrght.h" for complete copyright information)
  68.  */
  69.  
  70. #include "xloadimage.h"
  71. #include "gif.h"
  72. #include "kljcpyrght.h"
  73.  
  74. /****
  75.  **
  76.  ** local #defines
  77.  **
  78.  ****/
  79.  
  80. #define PUSH_PIXEL(p)                                       \
  81. {                                                           \
  82.   if (pstk_idx == PSTK_SIZE)                                \
  83.     gifin_fatal("pixel stack overflow in PUSH_PIXEL()");    \
  84.   else                                                      \
  85.     pstk[pstk_idx++] = (p);                                 \
  86. }
  87.  
  88.  
  89. /****
  90.  **
  91.  ** local variables
  92.  **
  93.  ****/
  94.  
  95. static int interlace_start[4]= { /* start line for interlacing */
  96.   0, 4, 2, 1
  97. };
  98.  
  99. static int interlace_rate[4]= { /* rate at which we accelerate vertically */
  100.   8, 8, 4, 2
  101. };
  102.  
  103. static BYTE file_open  = 0;     /* status flags */
  104. static BYTE image_open = 0;
  105.  
  106. static ZFILE *ins;              /* input stream */
  107.  
  108. static int  root_size;          /* root code size */
  109. static int  clr_code;           /* clear code */
  110. static int  eoi_code;           /* end of information code */
  111. static int  code_size;          /* current code size */
  112. static int  code_mask;          /* current code mask */
  113. static int  prev_code;          /* previous code */
  114.  
  115. /*
  116.  * NOTE: a long is assumed to be at least 32 bits wide
  117.  */
  118. static long work_data;          /* working bit buffer */
  119. static int  work_bits;          /* working bit count */
  120.  
  121. static BYTE buf[256];           /* byte buffer */
  122. static int  buf_cnt;            /* byte count */
  123. static int  buf_idx;            /* buffer index */
  124.  
  125. static int table_size;          /* string table size */
  126. static int prefix[STAB_SIZE];   /* string table : prefixes */
  127. static int extnsn[STAB_SIZE];   /* string table : extensions */
  128.  
  129. static BYTE pstk[PSTK_SIZE];    /* pixel stack */
  130. static int  pstk_idx;           /* pixel stack pointer */
  131.  
  132.  
  133. /****
  134.  **
  135.  ** global variables
  136.  **
  137.  ****/
  138.  
  139. static int  gifin_rast_width;          /* raster width */
  140. static int  gifin_rast_height;         /* raster height */
  141. static BYTE gifin_g_cmap_flag;         /* global colormap flag */
  142. static int  gifin_g_pixel_bits;        /* bits per pixel, global colormap */
  143. static int  gifin_g_ncolors;           /* number of colors, global colormap */
  144. static BYTE gifin_g_cmap[3][256];      /* global colormap */
  145. static int  gifin_bg_color;            /* background color index */
  146. static int  gifin_color_bits;          /* bits of color resolution */
  147.  
  148. static int  gifin_img_left;            /* image position on raster */
  149. static int  gifin_img_top;             /* image position on raster */
  150. static int  gifin_img_width;           /* image width */
  151. static int  gifin_img_height;          /* image height */
  152. static BYTE gifin_l_cmap_flag;         /* local colormap flag */
  153. static int  gifin_l_pixel_bits;        /* bits per pixel, local colormap */
  154. static int  gifin_l_ncolors;           /* number of colors, local colormap */
  155. static BYTE gifin_l_cmap[3][256];      /* local colormap */
  156. static BYTE gifin_interlace_flag;      /* interlace image format flag */
  157.  
  158. /*
  159.  * open a GIF file, using s as the input stream
  160.  */
  161.  
  162. static int gifin_open_file(s)
  163.      ZFILE *s;
  164. {
  165.   /* make sure there isn't already a file open */
  166.   if (file_open)
  167.     return GIFIN_ERR_FAO;
  168.  
  169.   /* remember that we've got this file open */
  170.   file_open = 1;
  171.   ins       = s;
  172.  
  173.   /* check GIF signature */
  174.   if (zread(ins, buf, GIF_SIG_LEN) != GIF_SIG_LEN)
  175.     return GIFIN_ERR_EOF;
  176.  
  177.   buf[GIF_SIG_LEN] = '\0';
  178.   if (strcmp((char *) buf, GIF_SIG) != 0)
  179.     return GIFIN_ERR_BAD_SIG;
  180.  
  181.   /* read screen descriptor */
  182.   if (zread(ins, buf, GIF_SD_SIZE) != GIF_SD_SIZE)
  183.     return GIFIN_ERR_EOF;
  184.  
  185.   /* decode screen descriptor */
  186.   gifin_rast_width   = (buf[1] << 8) + buf[0];
  187.   gifin_rast_height  = (buf[3] << 8) + buf[2];
  188.   gifin_g_cmap_flag  = (buf[4] & 0x80) ? 1 : 0;
  189.   gifin_color_bits   = ((buf[4] & 0x70) >> 4) + 1;
  190.   gifin_g_pixel_bits = (buf[4] & 0x07) + 1;
  191.   gifin_bg_color     = buf[5];
  192.  
  193.   if (buf[6] != 0)
  194.     return GIFIN_ERR_BAD_SD;
  195.  
  196.   /* load global colormap */
  197.   if (gifin_g_cmap_flag)
  198.   {
  199.     gifin_g_ncolors = (1 << gifin_g_pixel_bits);
  200.  
  201.     if (gifin_load_cmap(gifin_g_cmap, gifin_g_ncolors) != GIFIN_SUCCESS)
  202.       return GIFIN_ERR_EOF;
  203.   }
  204.   else
  205.   {
  206.     gifin_g_ncolors = 0;
  207.   }
  208.  
  209.   /* done! */
  210.   return GIFIN_SUCCESS;
  211. }
  212.  
  213.  
  214. /*
  215.  * open next GIF image in the input stream; returns GIFIN_SUCCESS if
  216.  * successful. if there are no more images, returns GIFIN_DONE. (might
  217.  * also return various GIFIN_ERR codes.)
  218.  */
  219.  
  220. static int gifin_open_image()
  221. {
  222.   int i;
  223.   int separator;
  224.  
  225.   /* make sure there's a file open */
  226.   if (!file_open)
  227.     return GIFIN_ERR_NFO;
  228.  
  229.   /* make sure there isn't already an image open */
  230.   if (image_open)
  231.     return GIFIN_ERR_IAO;
  232.  
  233.   /* remember that we've got this image open */
  234.   image_open = 1;
  235.  
  236.   /* skip over any extension blocks */
  237.   do
  238.   {
  239.     separator = zgetc(ins);
  240.     if (separator == GIF_EXTENSION)
  241.     {
  242.       if (gifin_skip_extension() != GIFIN_SUCCESS)
  243.         return GIFIN_ERR_EOF;
  244.     }
  245.   }
  246.   while (separator == GIF_EXTENSION);
  247.  
  248.   /* check for end of file marker */
  249.   if (separator == GIF_TERMINATOR)
  250.     return GIFIN_DONE;
  251.  
  252.   /* make sure we've got an image separator */
  253.   if (separator != GIF_SEPARATOR)
  254.     return GIFIN_ERR_BAD_SEP;
  255.  
  256.   /* read image descriptor */
  257.   if (zread(ins, buf, GIF_ID_SIZE) != GIF_ID_SIZE)
  258.     return GIFIN_ERR_EOF;
  259.  
  260.   /* decode image descriptor */
  261.   gifin_img_left       = (buf[1] << 8) + buf[0];
  262.   gifin_img_top        = (buf[3] << 8) + buf[2];
  263.   gifin_img_width      = (buf[5] << 8) + buf[4];
  264.   gifin_img_height     = (buf[7] << 8) + buf[6];
  265.   gifin_l_cmap_flag    = (buf[8] & 0x80) ? 1 : 0;
  266.   gifin_interlace_flag = (buf[8] & 0x40) ? 1 : 0;
  267.   gifin_l_pixel_bits   = (buf[8] & 0x07) + 1;
  268.  
  269.   /* load local colormap */
  270.   if (gifin_l_cmap_flag)
  271.   {
  272.     gifin_l_ncolors = (1 << gifin_l_pixel_bits);
  273.  
  274.     if (gifin_load_cmap(gifin_l_cmap, gifin_l_ncolors) != GIFIN_SUCCESS)
  275.       return GIFIN_ERR_EOF;
  276.   }
  277.   else
  278.   {
  279.     gifin_l_ncolors = 0;
  280.   }
  281.  
  282.   /* initialize raster data stream decoder */
  283.   root_size = zgetc(ins);
  284.   clr_code  = 1 << root_size;
  285.   eoi_code  = clr_code + 1;
  286.   code_size = root_size + 1;
  287.   code_mask = (1 << code_size) - 1;
  288.   work_bits = 0;
  289.   work_data = 0;
  290.   buf_cnt   = 0;
  291.   buf_idx   = 0;
  292.  
  293.   /* initialize string table */
  294.   for (i=0; i<STAB_SIZE; i++)
  295.   {
  296.     prefix[i] = NULL_CODE;
  297.     extnsn[i] = i;
  298.   }
  299.  
  300.   /* initialize pixel stack */
  301.   pstk_idx = 0;
  302.  
  303.   /* done! */
  304.   return GIFIN_SUCCESS;
  305. }
  306.  
  307. /*
  308.  * try to read next pixel from the raster, return result in *pel
  309.  */
  310.  
  311. static int gifin_get_pixel(pel)
  312.      int *pel;
  313. {
  314.   int  code;
  315.   int  first;
  316.   int  place;
  317.  
  318.   /* decode until there are some pixels on the pixel stack */
  319.   while (pstk_idx == 0)
  320.   {
  321.     /* load bytes until we have enough bits for another code */
  322.     while (work_bits < code_size)
  323.     {
  324.       if (buf_idx == buf_cnt)
  325.       {
  326.         /* read a new data block */
  327.         if (gifin_read_data_block() != GIFIN_SUCCESS)
  328.           return GIFIN_ERR_EOF;
  329.  
  330.         if (buf_cnt == 0)
  331.           return GIFIN_ERR_EOD;
  332.       }
  333.  
  334.       work_data |= ((long) buf[buf_idx++]) << work_bits;
  335.       work_bits += 8;
  336.     }
  337.  
  338.     /* get the next code */
  339.     code        = work_data & code_mask;
  340.     work_data >>= code_size;
  341.     work_bits  -= code_size;
  342.  
  343.     /* interpret the code */
  344.     if (code == clr_code)
  345.     {
  346.       /* reset decoder stream */
  347.       code_size  = root_size + 1;
  348.       code_mask  = (1 << code_size) - 1;
  349.       prev_code  = NULL_CODE;
  350.       table_size = eoi_code + 1;
  351.     }
  352.     else if (code == eoi_code)
  353.     {
  354.       /* Ooops! no more pixels */
  355.       return GIFIN_ERR_EOF;
  356.     }
  357.     else if (prev_code == NULL_CODE)
  358.     {
  359.       gifin_push_string(code);
  360.       prev_code = code;
  361.     }
  362.     else
  363.     {
  364.       if (code < table_size)
  365.       {
  366.         first = gifin_push_string(code);
  367.       }
  368.       else
  369.       {
  370.         place = pstk_idx;
  371.         PUSH_PIXEL(NULL_CODE);
  372.         first = gifin_push_string(prev_code);
  373.         pstk[place] = first;
  374.       }
  375.  
  376.       gifin_add_string(prev_code, first);
  377.       prev_code = code;
  378.     }
  379.   }
  380.  
  381.   /* pop a pixel off the pixel stack */
  382.   *pel = (int) pstk[--pstk_idx];
  383.  
  384.   /* done! */
  385.   return GIFIN_SUCCESS;
  386. }
  387.  
  388.  
  389. /*
  390.  * close an open GIF image
  391.  */
  392.  
  393. static int gifin_close_image()
  394. {
  395.   /* make sure there's an image open */
  396.   if (!image_open)
  397.     return GIFIN_ERR_NIO;
  398.  
  399.   /* skip any remaining raster data */
  400.   do
  401.   {
  402.     if (gifin_read_data_block() != GIFIN_SUCCESS)
  403.       return GIFIN_ERR_EOF;
  404.   }
  405.   while (buf_cnt > 0);
  406.  
  407.   /* mark image as closed */
  408.   image_open = 0;
  409.  
  410.   /* done! */
  411.   return GIFIN_SUCCESS;
  412. }
  413.  
  414.  
  415. /*
  416.  * close an open GIF file
  417.  */
  418.  
  419. static int gifin_close_file()
  420. {
  421.   /* make sure there's a file open */
  422.   if (!file_open)
  423.     return GIFIN_ERR_NFO;
  424.  
  425.   /* mark file (and image) as closed */
  426.   file_open  = 0;
  427.   image_open = 0;
  428.  
  429.   /* done! */
  430.   return GIFIN_SUCCESS;
  431. }
  432.  
  433. /*
  434.  * load a colormap from the input stream
  435.  */
  436.  
  437. static int gifin_load_cmap(cmap, ncolors)
  438.      BYTE cmap[3][256];
  439.      int  ncolors;
  440. {
  441.   int i;
  442.  
  443.   for (i=0; i<ncolors; i++)
  444.   {
  445.     if (zread(ins, buf, 3) != 3)
  446.       return GIFIN_ERR_EOF;
  447.     
  448.     cmap[GIF_RED][i] = buf[GIF_RED];
  449.     cmap[GIF_GRN][i] = buf[GIF_GRN];
  450.     cmap[GIF_BLU][i] = buf[GIF_BLU];
  451.   }
  452.  
  453.   /* done! */
  454.   return GIFIN_SUCCESS;
  455. }
  456.  
  457. /*
  458.  * skip an extension block in the input stream
  459.  */
  460.  
  461. static int gifin_skip_extension()
  462. {
  463.   int function;
  464.  
  465.   /* get the extension function byte */
  466.   function = zgetc(ins);
  467.  
  468.   /* skip any remaining raster data */
  469.   do
  470.   {
  471.     if (gifin_read_data_block() != GIFIN_SUCCESS)
  472.       return GIFIN_ERR_EOF;
  473.   }
  474.   while (buf_cnt > 0);
  475.  
  476.   /* done! */
  477.   return GIFIN_SUCCESS;
  478. }
  479.  
  480. /*
  481.  * read a new data block from the input stream
  482.  */
  483.  
  484. static int gifin_read_data_block()
  485. {
  486.   /* read the data block header */
  487.   buf_cnt = zgetc(ins);
  488.  
  489.   /* read the data block body */
  490.   if (zread(ins, buf, buf_cnt) != buf_cnt)
  491.     return GIFIN_ERR_EOF;
  492.  
  493.   buf_idx = 0;
  494.  
  495.   /* done! */
  496.   return GIFIN_SUCCESS;
  497. }
  498.  
  499. /*
  500.  * push a string (denoted by a code) onto the pixel stack
  501.  * (returns the code of the first pixel in the string)
  502.  */
  503.  
  504. static int gifin_push_string(code)
  505.      int code;
  506. {
  507.   int rslt;
  508.  
  509.   while (prefix[code] != NULL_CODE)
  510.   {
  511.     PUSH_PIXEL(extnsn[code]);
  512.     code = prefix[code];
  513.   }
  514.  
  515.   PUSH_PIXEL(extnsn[code]);
  516.   rslt = extnsn[code];
  517.  
  518.   return rslt;
  519. }
  520.  
  521. /*
  522.  * add a new string to the string table
  523.  */
  524.  
  525. static gifin_add_string(p, e)
  526.      int p;
  527.      int e;
  528. {
  529.   prefix[table_size] = p;
  530.   extnsn[table_size] = e;
  531.  
  532.   if ((table_size == code_mask) && (code_size < 12))
  533.   {
  534.     code_size += 1;
  535.     code_mask  = (1 << code_size) - 1;
  536.   }
  537.  
  538.   table_size += 1;
  539. }
  540.  
  541. /*
  542.  * semi-graceful fatal error mechanism
  543.  */
  544.  
  545. static gifin_fatal(msg)
  546.      char *msg;
  547. {
  548.   printf("Error reading GIF file: %s\n", msg);
  549.   exit(0);
  550. }
  551.  
  552. /* these are the routines added for interfacing to xloadimage
  553.  */
  554.  
  555. /* tell someone what the image we're loading is.  this could be a little more
  556.  * descriptive but I don't care
  557.  */
  558.  
  559. static void tellAboutImage(name)
  560.      char *name;
  561. {
  562.   printf("%s is a %dx%d %sGIF image with %d colors\n", name,
  563.      gifin_img_width, gifin_img_height,
  564.      (gifin_interlace_flag ? "interlaced " : ""),
  565.      (gifin_l_cmap_flag ? gifin_l_ncolors : gifin_g_ncolors));
  566. }
  567.  
  568. Image *gifLoad(fullname, name, verbose)
  569.      char         *fullname, *name;
  570.      unsigned int  verbose;
  571. { ZFILE *zf;
  572.   Image *image;
  573.   int    x, y, pixel, pass, yrate, scanlen;
  574.   byte  *pixptr, *pixline;
  575.  
  576.   if (! (zf= zopen(fullname)))
  577.     return(NULL);
  578.   if ((gifin_open_file(zf) != GIFIN_SUCCESS) || /* read GIF header */
  579.       (gifin_open_image() != GIFIN_SUCCESS)) {  /* read image header */
  580.     gifin_close_file();
  581.     zclose(zf);
  582.     return(NULL);
  583.   }
  584.   if (verbose)
  585.     tellAboutImage(name);
  586.  
  587.   image= newRGBImage(gifin_img_width, gifin_img_height, (gifin_l_cmap_flag ?
  588.                              gifin_l_pixel_bits :
  589.                              gifin_g_pixel_bits));
  590.   for (x= 0; x < gifin_g_ncolors; x++) {
  591.     image->rgb.red[x]= gifin_g_cmap[GIF_RED][x] << 8;
  592.     image->rgb.green[x]= gifin_g_cmap[GIF_GRN][x] << 8;
  593.     image->rgb.blue[x]= gifin_g_cmap[GIF_BLU][x] << 8;
  594.   }
  595.   image->rgb.used= gifin_g_ncolors;
  596.  
  597.   /* if image has a local colormap, override global colormap
  598.    */
  599.  
  600.   if (gifin_l_cmap_flag) {
  601.     for (x= 0; x < image->rgb.size; x++) {
  602.       image->rgb.red[x]= gifin_g_cmap[GIF_RED][x] << 8;
  603.       image->rgb.green[x]= gifin_g_cmap[GIF_GRN][x] << 8;
  604.       image->rgb.blue[x]= gifin_g_cmap[GIF_BLU][x] << 8;
  605.     }
  606.     image->rgb.used= gifin_l_ncolors;
  607.   }
  608.  
  609.   /* interlaced image -- futz with the vertical trace.  i wish i knew what
  610.    * kind of drugs the GIF people were on when they decided that they
  611.    * needed to support interlacing.
  612.    */
  613.  
  614.   if (gifin_interlace_flag) {
  615.     scanlen= image->height * image->pixlen;
  616.  
  617.     /* interlacing takes four passes to read, each starting at a different
  618.      * vertical point.
  619.      */
  620.  
  621.     for (pass= 0; pass < 4; pass++) {
  622.       y= interlace_start[pass];
  623.       scanlen= image->width * image->pixlen * interlace_rate[pass];
  624.       pixline= image->data + (y * image->width * image->pixlen);
  625.       while (y < gifin_img_height) {
  626.     pixptr= pixline;
  627.     for (x= 0; x < gifin_img_width; x++) {
  628.       if (gifin_get_pixel(&pixel) != GIFIN_SUCCESS) {
  629.         printf("%s: Short read within image data\n", fullname);
  630.         exit(0);
  631.       }
  632.       valToMem(pixel, pixptr, image->pixlen);
  633.       pixptr += image->pixlen;
  634.     }
  635.     y += interlace_rate[pass];
  636.     pixline += scanlen;
  637.       }
  638.     }
  639.   }
  640.  
  641.   /* not an interlaced image, just read in sequentially
  642.    */
  643.  
  644.   else {
  645.     pixptr= image->data;
  646.     for (y= 0; y < gifin_img_height; y++)
  647.       for (x= 0; x < gifin_img_width; x++) {
  648.     if (gifin_get_pixel(&pixel) != GIFIN_SUCCESS) {
  649.       printf("%s: Short read within image data\n", fullname);
  650.       exit(0);
  651.     }
  652.     valToMem(pixel, pixptr, image->pixlen);
  653.     pixptr += image->pixlen;
  654.       }
  655.   }
  656.   gifin_close_file();
  657.   zclose(zf);
  658.   image->title= dupString(name);
  659.   return(image);
  660. }
  661.  
  662. unsigned int gifIdent(fullname, name)
  663.      char *fullname, *name;
  664. { ZFILE        *zf;
  665.   unsigned int  ret;
  666.  
  667.   if (! (zf= zopen(fullname)))
  668.     return(0);
  669.   if ((gifin_open_file(zf) == GIFIN_SUCCESS) &&
  670.       (gifin_open_image() == GIFIN_SUCCESS)) {
  671.     tellAboutImage(name);
  672.     ret= 1;
  673.   }
  674.   else
  675.     ret= 0;
  676.   gifin_close_file();
  677.   zclose(zf);
  678.   return(ret);
  679. }
  680. //E*O*F gif.c//
  681.  
  682. echo x - gif.h
  683. cat > "gif.h" << '//E*O*F gif.h//'
  684. /* gif.h:
  685.  *
  686.  * gifin.h
  687.  * kirk johnson
  688.  * november 1989
  689.  * external interface to gifin.c
  690.  *
  691.  * Copyright 1989 Kirk L. Johnson (see the included file
  692.  * "kljcpyrght.h" for complete copyright information)
  693.  */
  694.  
  695. /*
  696.  * gifin return codes
  697.  */
  698. #define GIFIN_SUCCESS       0   /* success */
  699. #define GIFIN_DONE          1   /* no more images */
  700.  
  701. #define GIFIN_ERR_BAD_SD   -1   /* bad screen descriptor */
  702. #define GIFIN_ERR_BAD_SEP  -2   /* bad image separator */
  703. #define GIFIN_ERR_BAD_SIG  -3   /* bad signature */
  704. #define GIFIN_ERR_EOD      -4   /* unexpected end of raster data */
  705. #define GIFIN_ERR_EOF      -5   /* unexpected end of input stream */
  706. #define GIFIN_ERR_FAO      -6   /* file already open */
  707. #define GIFIN_ERR_IAO      -7   /* image already open */
  708. #define GIFIN_ERR_NFO      -8   /* no file open */
  709. #define GIFIN_ERR_NIO      -9   /* no image open */
  710.  
  711. /*
  712.  * colormap indices 
  713.  */
  714.  
  715. #define GIF_RED  0
  716. #define GIF_GRN  1
  717. #define GIF_BLU  2
  718.  
  719. /*
  720.  * typedef BYTE for convenience
  721.  */
  722.  
  723. typedef unsigned char BYTE;
  724.  
  725. static int gifin_open_file();
  726. static int gifin_open_image();
  727. static int gifin_get_pixel();
  728. static int gifin_close_image();
  729. static int gifin_close_file();
  730. static int gifin_load_cmap();
  731. static int gifin_skip_extension();
  732. static int gifin_read_data_block();
  733. static int gifin_push_string();
  734. static int gifin_add_string();
  735. static int gifin_fatal();
  736.  
  737. /* #defines, typedefs, and such
  738.  */
  739.  
  740. #define GIF_SIG      "GIF87a"
  741. #define GIF_SIG_LEN  6          /* GIF signature length */
  742. #define GIF_SD_SIZE  7          /* GIF screen descriptor size */
  743. #define GIF_ID_SIZE  9          /* GIF image descriptor size */
  744.  
  745. #define GIF_SEPARATOR   ','     /* GIF image separator */
  746. #define GIF_EXTENSION   '!'     /* GIF extension block marker */
  747. #define GIF_TERMINATOR  ';'     /* GIF terminator */
  748.  
  749. #define STAB_SIZE  4096         /* string table size */
  750. #define PSTK_SIZE  1024         /* pixel stack size */
  751.  
  752. #define NULL_CODE  -1           /* string table null code */
  753. //E*O*F gif.h//
  754.  
  755. echo x - kljcpyrght.h
  756. cat > "kljcpyrght.h" << '//E*O*F kljcpyrght.h//'
  757. #ifndef _KLJ_COPYRIGHT_
  758.  
  759. /****
  760.   Copyright 1989 Kirk L. Johnson
  761.  
  762.   Permission to use, copy, modify, distribute, and sell this
  763.   software and its documentation for any purpose is hereby granted
  764.   without fee, provided that the above copyright notice appear in
  765.   all copies and that both that copyright notice and this
  766.   permission notice appear in supporting documentation. The
  767.   author makes no representations about the suitability of this
  768.   software for any purpose. It is provided "as is" without express
  769.   or implied warranty.
  770.  
  771.   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  772.   INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  773.   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT
  774.   OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  775.   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  776.   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  777.   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  778. ****/
  779.  
  780. static char *KLJCopyright = "Copyright 1989 Kirk L. Johnson";
  781. #define _KLJ_COPYRIGHT_
  782. #endif
  783. //E*O*F kljcpyrght.h//
  784.  
  785. exit 0
  786.  
  787.  
  788.