home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / DVPG30FS.ZIP / JJRDGIF.C < prev    next >
C/C++ Source or Header  |  1993-12-03  |  19KB  |  606 lines

  1. /*
  2.  * jrdgif.c
  3.  *
  4.  * Copyright (C) 1991, 1992, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains routines to read input images in GIF format.
  9.  *
  10.  * These routines may need modification for non-Unix environments or
  11.  * specialized applications.  As they stand, they assume input from
  12.  * an ordinary stdio stream.  They further assume that reading begins
  13.  * at the start of the file; input_init may need work if the
  14.  * user interface has already read some data (e.g., to determine that
  15.  * the file is indeed GIF format).
  16.  *
  17.  * These routines are invoked via the methods get_input_row
  18.  * and input_init/term.
  19.  */
  20.  
  21. /*
  22.  * This code is loosely based on giftoppm from the PBMPLUS distribution
  23.  * of Feb. 1991.  That file contains the following copyright notice:
  24.  * +-------------------------------------------------------------------+
  25.  * | Copyright 1990, David Koblas.                                     |
  26.  * |   Permission to use, copy, modify, and distribute this software   |
  27.  * |   and its documentation for any purpose and without fee is hereby |
  28.  * |   granted, provided that the above copyright notice appear in all |
  29.  * |   copies and that both that copyright notice and this permission  |
  30.  * |   notice appear in supporting documentation.  This software is    |
  31.  * |   provided "as is" without express or implied warranty.           |
  32.  * +-------------------------------------------------------------------+
  33.  *
  34.  * We are also required to state that
  35.  *    "The Graphics Interchange Format(c) is the Copyright property of
  36.  *    CompuServe Incorporated. GIF(sm) is a Service Mark property of
  37.  *    CompuServe Incorporated."
  38.  */
  39.  
  40. /*#include "jinclude.h"*/
  41. #include "extern.h"        /* jpeg viewer vars + includes jinclude.h */
  42.  
  43.  
  44. #ifdef GIF_SUPPORTED
  45.  
  46. JSAMPARRAY gif_colormap;    /* colormap pointer */
  47.  
  48. int    /* vars to aid viewing of interlaced GIF */
  49.         step_size,        /* increment for current pass */
  50.         index,            /* current index ie the n'th count for pass y */
  51.         pass_num;        /* the current pass */
  52.  
  53. #define    MAXCOLORMAPSIZE    256    /* max # of colors in a GIF colormap */
  54. #define NUMCOLORS    3    /* # of colors */
  55. #define CM_RED        0    /* color component numbers */
  56. #define CM_GREEN    1
  57. #define CM_BLUE        2
  58.  
  59. #define    MAX_LZW_BITS    12    /* maximum LZW code size */
  60. #define LZW_TABLE_SIZE    (1<<MAX_LZW_BITS) /* # of possible LZW symbols */
  61.  
  62. /* Macros for extracting header data --- note we assume chars may be signed */
  63.  
  64. #define LM_to_uint(a,b)        ((((b)&0xFF) << 8) | ((a)&0xFF))
  65.  
  66. #define BitSet(byte, bit)    ((byte) & (bit))
  67. #define INTERLACE    0x40    /* mask for bit signifying interlaced image */
  68. #define COLORMAPFLAG    0x80    /* mask for bit signifying colormap presence */
  69.  
  70. /* Eric addition - storage for 1 row of GIF */
  71. static JSAMPIMAGE row_ptr;
  72.  
  73. static decompress_info_ptr cinfo_global;
  74. FILE * infile;
  75. static int temp_var;
  76. char *fetch_buf;
  77.  
  78. #define    ReadOK(file,buffer,len)    (JFREAD(file,buffer,len) == ((size_t) (len)))
  79.  
  80. /* Static vars for GetCode and LZWReadByte */
  81.  
  82. static char code_buf[256+4];    /* current input data block */
  83. static int last_byte;        /* # of bytes in code_buf */
  84. static int last_bit;        /* # of bits in code_buf */
  85. static int cur_bit;        /* next bit index to read */
  86. static boolean out_of_blocks;    /* TRUE if hit terminator data block */
  87.  
  88. static int input_code_size;    /* codesize given in GIF file */
  89. static int clear_code,end_code; /* values for Clear and End codes */
  90.  
  91. static int code_size;        /* current actual code size */
  92. static int limit_code;        /* 2^code_size */
  93. static int max_code;        /* first unused code value */
  94. static boolean first_time;    /* flags first call to LZWReadByte */
  95.  
  96. /* LZW decompression tables:
  97.  *   symbol_head[K] = prefix symbol of any LZW symbol K (0..LZW_TABLE_SIZE-1)
  98.  *   symbol_tail[K] = suffix byte   of any LZW symbol K (0..LZW_TABLE_SIZE-1)
  99.  * Note that entries 0..end_code of the above tables are not used,
  100.  * since those symbols represent raw bytes or special codes.
  101.  *
  102.  * The stack represents the not-yet-used expansion of the last LZW symbol.
  103.  * In the worst case, a symbol could expand to as many bytes as there are
  104.  * LZW symbols, so we allocate LZW_TABLE_SIZE bytes for the stack.
  105.  * (This is conservative since that number includes the raw-byte symbols.)
  106.  *
  107.  * The tables are allocated from FAR heap space since they would use up
  108.  * rather a lot of the near data space in a PC.
  109.  */
  110.  
  111. static UINT16 *symbol_head; /* => table of prefix symbols */
  112. static UINT8  *symbol_tail; /* => table of suffix bytes */
  113. static UINT8  *symbol_stack; /* stack for symbol expansions */
  114. static UINT8  *sp;        /* stack pointer */
  115.  
  116. /* Static state for interlaced image processing */
  117.  
  118. static boolean is_interlaced;    /* TRUE if have interlaced image */
  119.  
  120.  
  121. /* Forward declarations */
  122. METHODDEF void load_interlaced_image PP((decompress_info_ptr cinfo, JSAMPIMAGE pixel_row));
  123.  
  124.  
  125. /* declarations */
  126. int near ReadByte (void);
  127. int near GetCode (void);
  128. int near LZWReadByte (void);
  129. void near DoExtension (void);
  130. void near SkipDataBlocks (void);
  131. int near GetDataBlock (void);
  132.  
  133.  
  134. int near ReadByte (void)        /* was LOCAL */
  135. /* Read next byte from GIF file */
  136. {
  137.   if ((temp_var = getc(infile)) == EOF)
  138.      ERREXIT(cinfo_global->emethods, "Premature EOF in GIF file");
  139.   return temp_var;
  140. }
  141.  
  142.  
  143. LOCAL int near
  144. GetDataBlock ()
  145. /* Read a GIF data block, which has a leading count byte */
  146. /* A zero-length block marks the end of a data block sequence */
  147. {
  148. /* use the fact that the data is in temp_var */
  149.  
  150.   ReadByte();
  151.   if (temp_var > 0) {
  152.      if (! ReadOK(cinfo_global->input_file, fetch_buf, temp_var))
  153.         ERREXIT(cinfo_global->emethods, "Premature EOF in GIF file");
  154.   }
  155.   return temp_var;
  156. }
  157.  
  158.  
  159. LOCAL void near
  160. SkipDataBlocks (void)
  161. /* Skip a series of data blocks, until a block terminator is found */
  162. {
  163.   char buf[256];
  164.     fetch_buf = buf;    /* set pointer to temp buffer */
  165.  
  166.   while (GetDataBlock() > 0)
  167.      /* skip */;
  168. }
  169.  
  170.  
  171. LOCAL void
  172. ReInitLZW (void)
  173. /* (Re)initialize LZW state; shared code for startup and Clear processing */
  174. {
  175.   code_size = input_code_size+1;
  176.   limit_code = clear_code << 1;    /* 2^code_size */
  177.   max_code = clear_code + 2;    /* first unused code value */
  178.   sp = symbol_stack;        /* init stack to empty */
  179. }
  180.  
  181.  
  182. LOCAL void
  183. InitLZWCode (void)
  184. /* Initialize for a series of LZWReadByte (and hence GetCode) calls */
  185. {
  186.   /* GetCode initialization */
  187.   last_byte = 2;        /* make safe to "recopy last two bytes" */
  188.   last_bit = 0;            /* nothing in the buffer */
  189.   cur_bit = 0;            /* force buffer load on first call */
  190.   out_of_blocks = FALSE;
  191.  
  192.   /* LZWReadByte initialization */
  193.   clear_code = 1 << input_code_size; /* compute special code values */
  194.   end_code = clear_code + 1;    /* note that these do not change */
  195.   first_time = TRUE;
  196.   ReInitLZW();
  197. }
  198.  
  199.  
  200. LOCAL int near
  201. GetCode (void)
  202. /* Fetch the next code_size bits from the GIF data */
  203. /* We assume code_size is less than 16 */
  204. {
  205.   register INT32 accum;
  206.   int offs, ret, count;
  207.  
  208.   if ( (cur_bit+code_size) > last_bit) {
  209.      /* Time to reload the buffer */
  210.      if (out_of_blocks) {
  211.         WARNMS(cinfo_global->emethods, "Ran out of GIF bits");
  212.         return end_code;        /* fake something useful */
  213.      }
  214.      /* preserve last two bytes of what we have -- assume code_size <= 16 */
  215.      code_buf[0] = code_buf[last_byte-2];
  216.      code_buf[1] = code_buf[last_byte-1];
  217.      /* Load more bytes; set flag if we reach the terminator block */
  218.      fetch_buf = &code_buf[2];
  219.      if ((count = GetDataBlock()) == 0) {
  220.         out_of_blocks = TRUE;
  221.         WARNMS(cinfo_global->emethods, "Ran out of GIF bits");
  222.         return end_code;        /* fake something useful */
  223.      }
  224.      /* Reset counters */
  225.      cur_bit = (cur_bit - last_bit) + 16;
  226.      last_byte = 2 + count;
  227.      last_bit = last_byte * 8;
  228.   }
  229.  
  230.   /* Form up next 24 bits in accum */
  231.   offs = cur_bit >> 3;        /* byte containing cur_bit */
  232. #ifdef CHAR_IS_UNSIGNED
  233.   accum = code_buf[offs+2];
  234.   accum <<= 8;
  235.   accum |= code_buf[offs+1];
  236.   accum <<= 8;
  237.   accum |= code_buf[offs];
  238. #else
  239.   accum = code_buf[offs+2] & 0xFF;
  240.   accum <<= 8;
  241.   accum |= code_buf[offs+1] & 0xFF;
  242.   accum <<= 8;
  243.   accum |= code_buf[offs] & 0xFF;
  244. #endif
  245.  
  246.   /* Right-align cur_bit in accum, then mask off desired number of bits */
  247.   accum >>= (cur_bit & 7);
  248.   ret = ((int) accum) & ((1 << code_size) - 1);
  249.  
  250.   cur_bit += code_size;
  251.   return ret;
  252. }
  253.  
  254.  
  255.  
  256. LOCAL int near
  257. LZWReadByte (void)
  258. /* Read an LZW-compressed byte */
  259. {
  260.   static int oldcode;        /* previous LZW symbol */
  261.   static int firstcode;        /* first byte of oldcode's expansion */
  262.   register int code;        /* current working code */
  263.   int incode;            /* saves actual input code */
  264.  
  265.     /* First time, just eat the expected Clear code(s) and return next code, */
  266.     /* which is expected to be a raw byte. */
  267.     if (first_time) goto first_time_called;
  268.  
  269.     /* If any codes are stacked from a previously read symbol, return them */
  270.     if (sp > symbol_stack) goto early_return;
  271.  
  272.     /* Time to read a new symbol */
  273.     code = GetCode();
  274.  
  275.  
  276.   if (code == clear_code) goto got_clear_code;
  277.  
  278.   if (code == end_code) goto got_end_code;
  279.  
  280.   /* Got normal raw byte or LZW symbol */
  281.   incode = code;        /* save for a moment */
  282.  
  283.   if (code >= max_code) {    /* special case for not-yet-defined symbol */
  284.      /* code == max_code is OK; anything bigger is bad data */
  285.      if (code > max_code) {
  286.         WARNMS(cinfo_global->emethods, "Corrupt data in GIF file");
  287.         incode = 0;        /* prevent creation of loops in symbol table */
  288.      }
  289.      *sp++ = (UINT8) firstcode;    /* it will be defined as oldcode/firstcode */
  290.      code = oldcode;
  291.   }
  292.  
  293.   /* If it's a symbol, expand it into the stack */
  294.   while (code >= clear_code) {
  295.      *sp++ = symbol_tail[code];    /* tail of symbol: a simple byte value */
  296.      code = symbol_head[code];    /* head of symbol: another LZW symbol */
  297.   }
  298.   /* At this point code just represents a raw byte */
  299.   firstcode = code;        /* save for possible future use */
  300.  
  301.   /* If there's room in table, */
  302.   if ((code = max_code) < LZW_TABLE_SIZE) {
  303.      /* Define a new symbol = prev sym + head of this sym's expansion */
  304.      symbol_head[code] = oldcode;
  305.      symbol_tail[code] = (UINT8) firstcode;
  306.      max_code++;
  307.      /* Is it time to increase code_size? */
  308.      if ((max_code >= limit_code) && (code_size < MAX_LZW_BITS)) {
  309.         code_size++;
  310.         limit_code <<= 1;        /* keep equal to 2^code_size */
  311.      }
  312.   }
  313.  
  314.   oldcode = incode;        /* save last input symbol for future use */
  315.   return firstcode;        /* return first byte of symbol's expansion */
  316.  
  317.  
  318. early_return:
  319.     return (int) *(--sp);
  320.  
  321. first_time_called:
  322.      first_time = FALSE;
  323. /*     code = clear_code;        /* enables sharing code with Clear case */
  324.  
  325. got_clear_code:
  326.      /* Reinit static state, swallow any extra Clear codes, and */
  327.      /* return next code, which is expected to be a raw byte. */
  328.      ReInitLZW();
  329.      do {
  330.         code = GetCode();
  331.      } while (code == clear_code);
  332.      if (code > clear_code) {    /* make sure it is a raw byte */
  333.         WARNMS(cinfo_global->emethods, "Corrupt data in GIF file");
  334.         code = 0;            /* use something valid */
  335.      }
  336.      firstcode = oldcode = code;    /* make firstcode, oldcode valid! */
  337.      return code;
  338.  
  339. got_end_code:
  340.      /* Skip the rest of the image, unless GetCode already read terminator */
  341.      if (! out_of_blocks) {
  342.         SkipDataBlocks();
  343.         out_of_blocks = TRUE;
  344.      }
  345.      /* Complain that there's not enough data */
  346.      WARNMS(cinfo_global->emethods, "Premature end of GIF image");
  347.      /* Pad data with 0's */
  348.      return 0;            /* fake something usable */
  349. }
  350.  
  351.  
  352. LOCAL void
  353. ReadColorMap (decompress_info_ptr cinfo, int cmaplen, JSAMPARRAY cmap)
  354. /* Read a GIF colormap */
  355. {
  356.   int i;
  357.  
  358.   for (i = 0; i < cmaplen; i++) {
  359.      cmap[CM_RED][i]   = (JSAMPLE) ReadByte();
  360.      cmap[CM_GREEN][i] = (JSAMPLE) ReadByte();
  361.      cmap[CM_BLUE][i]  = (JSAMPLE) ReadByte();
  362.   }
  363. }
  364.  
  365.  
  366. LOCAL void near
  367. DoExtension (void)
  368. /* Process an extension block */
  369. /* Currently we ignore 'em all */
  370. {
  371.   int extlabel;
  372.  
  373.   /* Read extension label byte */
  374.   extlabel = ReadByte();
  375.   TRACEMS1(cinfo_global->emethods, 1, "Ignoring GIF extension block of type 0x%02x",
  376.         extlabel);
  377.   /* Skip the data block(s) associated with the extension */
  378.   SkipDataBlocks();
  379. }
  380.  
  381.  
  382. /*
  383.  * Read the file header; return image size and component count.
  384.  */
  385.  
  386. METHODDEF void
  387. input_init (decompress_info_ptr cinfo)
  388. {
  389.   char hdrbuf[10];        /* workspace for reading control blocks */
  390.   UINT16 width, height;        /* image dimensions */
  391.   int colormaplen, aspectRatio;
  392.   int c;
  393.  
  394.   /* Allocate space to store the colormap */
  395.   gif_colormap = (*cinfo->emethods->alloc_small_sarray)
  396.         ((long) MAXCOLORMAPSIZE, (long) NUMCOLORS);
  397.  
  398.   /* Read and verify GIF Header */
  399.   if (! ReadOK(cinfo->input_file, hdrbuf, 6))
  400.      ERREXIT(cinfo->emethods, "Not a GIF file");
  401.   if (hdrbuf[0] != 'G' || hdrbuf[1] != 'I' || hdrbuf[2] != 'F')
  402.      ERREXIT(cinfo->emethods, "Not a GIF file");
  403.   /* Check for expected version numbers.
  404.     * If unknown version, give warning and try to process anyway;
  405.     * this is per recommendation in GIF89a standard.
  406.     */
  407.   if ((hdrbuf[3] != '8' || hdrbuf[4] != '7' || hdrbuf[5] != 'a') &&
  408.         (hdrbuf[3] != '8' || hdrbuf[4] != '9' || hdrbuf[5] != 'a'))
  409.      TRACEMS3(cinfo->emethods, 1,
  410.           "Warning: unexpected GIF version number '%c%c%c'",
  411.           hdrbuf[3], hdrbuf[4], hdrbuf[5]);
  412.  
  413.   /* Read and decipher Logical Screen Descriptor */
  414.   if (! ReadOK(cinfo->input_file, hdrbuf, 7))
  415.      ERREXIT(cinfo->emethods, "Premature EOF in GIF file");
  416.   width = LM_to_uint(hdrbuf[0],hdrbuf[1]);
  417.   height = LM_to_uint(hdrbuf[2],hdrbuf[3]);
  418.   colormaplen = 2 << (hdrbuf[4] & 0x07);
  419.   /* we ignore the color resolution, sort flag, and background color index */
  420.   aspectRatio = hdrbuf[6] & 0xFF;
  421.   if (aspectRatio != 0 && aspectRatio != 49)
  422.      TRACEMS(cinfo->emethods, 1, "Warning: nonsquare pixels in input");
  423.  
  424.   /* Read global colormap if header indicates it is present */
  425.   if (BitSet(hdrbuf[4], COLORMAPFLAG))
  426.      ReadColorMap(cinfo, colormaplen, gif_colormap);
  427.  
  428.   /* Scan until we reach start of desired image.
  429.     * We don't currently support skipping images, but could add it easily.
  430.    */
  431.   for (;;) {
  432.      c = ReadByte();
  433.  
  434.      if (c == ';')        /* GIF terminator?? */
  435.       ERREXIT(cinfo->emethods, "Too few images in GIF file");
  436.  
  437.     if (c == '!') {        /* Extension */
  438.         DoExtension();
  439.         continue;
  440.      }
  441.     
  442.      if (c != ',') {        /* Not an image separator? */
  443.       TRACEMS1(cinfo->emethods, 1, "Bogus input char 0x%02x, ignoring", c);
  444.         continue;
  445.      }
  446.  
  447.      /* Read and decipher Local Image Descriptor */
  448.      if (! ReadOK(cinfo->input_file, hdrbuf, 9))
  449.       ERREXIT(cinfo->emethods, "Premature EOF in GIF file");
  450.     /* we ignore top/left position info, also sort flag */
  451.      width = LM_to_uint(hdrbuf[4],hdrbuf[5]);
  452.      height = LM_to_uint(hdrbuf[6],hdrbuf[7]);
  453.     is_interlaced = BitSet(hdrbuf[8], INTERLACE);
  454.  
  455.      /* Read local colormap if header indicates it is present */
  456.     /* Note: if we wanted to support skipping images, */
  457.     /* we'd need to skip rather than read colormap for ignored images */
  458.     if (BitSet(hdrbuf[8], COLORMAPFLAG)) {
  459.         colormaplen = 2 << (hdrbuf[8] & 0x07);
  460.         ReadColorMap(cinfo, colormaplen, gif_colormap);
  461.      }
  462.  
  463.      input_code_size = ReadByte(); /* get minimum-code-size byte */
  464.      if (input_code_size < 2 || input_code_size >= MAX_LZW_BITS)
  465.         ERREXIT1(cinfo->emethods, "Bogus codesize %d", input_code_size);
  466.  
  467.      /* Reached desired image, so break out of loop */
  468.      /* If we wanted to skip this image, */
  469.      /* we'd call SkipDataBlocks and then continue the loop */
  470.      break;
  471.   }
  472.  
  473.   /* Prepare to read selected image: first initialize LZW decompressor */
  474.   symbol_head = (*cinfo->emethods->alloc_small)
  475.                 (LZW_TABLE_SIZE * SIZEOF(UINT16));
  476. /*  symbol_tail = (UINT8 FAR *) (*cinfo->emethods->alloc_medium)
  477.                 (LZW_TABLE_SIZE * SIZEOF(UINT8));
  478.   symbol_stack = (UINT8 FAR *) (*cinfo->emethods->alloc_medium)
  479.                 (LZW_TABLE_SIZE * SIZEOF(UINT8));
  480. */
  481.   symbol_tail = (*cinfo->emethods->alloc_small)
  482.                 (LZW_TABLE_SIZE * SIZEOF(UINT8));
  483.   symbol_stack = (*cinfo->emethods->alloc_small)
  484.                 (LZW_TABLE_SIZE * SIZEOF(UINT8));
  485.   InitLZWCode();
  486.  
  487.   /*
  488.     * If image is interlaced, we read it into a full-size sample array,
  489.     * decompressing as we go; then get_input_row selects rows from the
  490.     * sample array in the proper order.
  491.     */
  492.   if (is_interlaced) {
  493.      row_ordering = INTERLACED;
  494.      cinfo->methods->get_input_row = load_interlaced_image;
  495.  
  496. /* setup for an interlaced GIF */
  497.     step_size = 8;
  498.     index = -8;        /* make sure it counts to 0 the first time */
  499.     pass_num = 0;
  500.  
  501.      }
  502.  
  503.   /* Return info about the image. */
  504.   cinfo->colormap = gif_colormap;
  505.     cinfo->color_map_present = 1;
  506.   cinfo->actual_number_of_colors = 256;
  507.   cinfo->color_out_comps = NUMCOLORS;
  508.   cinfo->final_out_comps = NUMCOLORS;
  509.   cinfo->out_color_space = CS_RGB;        /* indicate as color */
  510.   cinfo->image_width = width;
  511.   cinfo->image_height = height;
  512.   cinfo->data_precision = 8;    /* always, even if 12-bit JSAMPLEs */
  513.   cinfo->final_out_comps = 1;    /* this is a color pallet picture - always */
  514.  
  515.   TRACEMS3(cinfo->emethods, 1, "%ux%ux%d GIF image",
  516.         (unsigned int) width, (unsigned int) height, colormaplen);
  517. }
  518.  
  519.  
  520. /*
  521.  * Read one row of pixels.
  522.  * This version is used for noninterlaced GIF images:
  523.  * we read directly from the GIF file.
  524.  */
  525.  
  526. METHODDEF void
  527. get_input_row (decompress_info_ptr cinfo, JSAMPIMAGE pixel_row)
  528. {
  529.   register JSAMPROW ptr0;
  530.   register int col;
  531.  
  532.     ptr0 = pixel_row[0][0];
  533.     for (col = picture_x_size; col > 0; col--)
  534.         *ptr0++ = LZWReadByte();
  535.  
  536. /*        data_ref_ptr = *((*cinfo->emethods->access_big_sarray) (raw_pic_ptr, read_row++, TRUE));
  537.         _fmemcpy((void FAR *) data_ref_ptr, (void FAR *) data_ptr, (size_t) bytes_per_line);
  538.         }
  539.     draw_line(gr_row++, data_ptr, line_buffer_ptr);
  540. */
  541. }
  542.  
  543.  
  544. /*
  545.  * Read one row of pixels.
  546.  * This version is used for the calls to get_input_row when
  547.  * reading an interlaced image
  548.  */
  549.  
  550. METHODDEF void
  551. load_interlaced_image (decompress_info_ptr cinfo, JSAMPIMAGE pixel_row)
  552. {
  553.   JSAMPROW ptr0;
  554.   int col;
  555.  
  556.     ptr0 = pixel_row[0][0];
  557.     for (col = picture_x_size; col > 0; col--)
  558.         *ptr0++ = LZWReadByte();
  559.     index += step_size;
  560.     gr_row = index;
  561.     if (index >= picture_y_size)
  562.         switch(++pass_num){
  563.             case 1:
  564.                 index = gr_row = 4;
  565.                 break;
  566.             case 2:
  567.                 index = gr_row = 2;
  568.                 step_size = 4;
  569.                 break;
  570.             case 3:
  571.                 index = gr_row = 1;
  572.                 step_size = 2;
  573.                 break;
  574.             }
  575. }
  576.  
  577.  
  578.  
  579.  
  580. /*
  581.  * The method selection routine for GIF format input.
  582.  * Note that this must be called by the user interface before calling
  583.  * jpeg_compress.  If multiple input formats are supported, the
  584.  * user interface is responsible for discovering the file format and
  585.  * calling the appropriate method selection routine.
  586.  */
  587.  
  588. GLOBAL void
  589. selrgif (decompress_info_ptr cinfo)
  590. {
  591. /* new to speed things up */
  592.     cinfo_global = cinfo;
  593.     infile = cinfo->input_file;
  594.  
  595.     cinfo->num_components = 1;            /* defaults to make GIF work */
  596.     cinfo->jpeg_color_space = CS_RGB;    /* always assume color - mainly signals that the color pallet has 3 components */
  597.     cinfo->out_color_space = CS_RGB;        /* ie default to color not grayscale */
  598.  
  599.   cinfo->methods->read_file_header = input_init;
  600.   cinfo->methods->get_input_row = get_input_row; /* assume uninterlaced */
  601. }
  602.  
  603.  
  604.  
  605. #endif /* GIF_SUPPORTED */
  606.