home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 317_01 / g4sdecod.c < prev    next >
C/C++ Source or Header  |  1990-06-18  |  40KB  |  1,502 lines

  1. /*    $Id: g4sdecod.c 1.2 90/06/09 18:23:27 marking Exp $
  2.  *
  3.  NAME
  4.  *    g4sdecod.c -- decode group 4 data using nested if statements
  5.  *
  6.  TYPE
  7.  *    C procedures
  8.  *
  9.  SYNOPSIS
  10.  *    char    g4i_initialize (short image_width, short image_length);
  11.  *    char    g4i_decode (void);
  12.  *
  13.  DESCRIPTION
  14.  *    In order to acquire data from the image and to return run lengths and
  15.  *    new line information, these routines invoke procedures provided by the
  16.  *    caller. These caller-provided procedures are invoked throught pointers
  17.  *    which have been stuffed by the caller with the procedure addresses.
  18.  *    To acquire a new data byte, g4i_decode () calls (*p_g4i_next_byte) ().
  19.  *    To report the decoding of a black or white run, the routines
  20.  *    (*p_decode_black) () or (*p_decode_white) () are called.
  21.  *
  22.  RETURNS
  23.  *    Initialization always returns zero.
  24.  *
  25.  *    For decoding,
  26.  *        0    end of image reached
  27.  *        -1    on error (bad data)
  28.  *    The decode loop will be prematurely terminated if decode_return is
  29.  *    set to not zero, and the value of decode_return will be returned.
  30.  *    No code here does this, but it might be useful under certain
  31.  *    circumstances.
  32.  *
  33.  LEGAL
  34.  *    Copyright 1989, 1990 Michael P. Marking, Post Office Box 8039,
  35.  *    Scottsdale, Arizona 85252-8039. All rights reserved.
  36.  *
  37.  *    License is granted by the copyright holder to distribute and use this
  38.  *    code without payment of royalties or the necessity of notification as
  39.  *    long as this notice (all the text under "LEGAL") is included.
  40.  *
  41.  *    Reference: $Id: g4sdecod.c 1.2 90/06/09 18:23:27 marking Exp $
  42.  *
  43.  *    This program is offered without any warranty of any kind. It includes
  44.  *    no warranty of merchantability or fitness for any purpose. Testing and
  45.  *    suitability for any use are the sole responsibility of the user.
  46.  * 
  47.  HISTORY
  48.  *    $Log:    g4sdecod.c $
  49.  * Revision 1.2  90/06/09  18:23:27  marking
  50.  * clean up comments for release
  51.  * 
  52.  * Revision 1.1  90/05/01  02:00:00  marking
  53.  * Initial revision
  54.  * 
  55.  *
  56.  NOTES
  57.  *
  58.  PORTABILITY
  59.  *    Tested using Microsoft C 5.1. Some memory models may not work due to
  60.  *    the large decoding arrays.
  61.  *
  62.  *    There is a non-portable use of "global" variables in the file g3g4.h,
  63.  *    about which a minority of compilers will justifiably complain. Certain
  64.  *    variables are declared in g3g4.h without extern keywords. Strictly
  65.  *    speaking, they should be declared extern in all but one module, but
  66.  *    that would require complication of g3g4.h. If it gets past your
  67.  *    compiler and linker, you can probably ignore it.
  68.  *
  69.  SEE ALSO
  70.  *    g3tdecod.c -- decode group 3 image using tables
  71.  *    builddec.c -- build image decoding tables
  72.  *
  73.  INFORMATION
  74.  *    Although there is no support offered with this program, the author will
  75.  *    endeavor to correct errors. Updates will also be made available from
  76.  *    time to time.
  77.  *
  78.  *    Contact: Michael P. Marking, Post Office Box 8039, Scottsdale, Arizona
  79.  *    85252-8039 USA. Replies are not guaranteed to be swift. Beginning
  80.  *    July 1990, e-mail may be sent to uunet!ipel!marking.
  81.  *
  82.  *    Also beginning in July 1990, this code will be archived at the
  83.  *    ipel!phoenix BBS in file g3g4.zoo. The 24-hour telephone number
  84.  *    for 300/1200/2400 is (602)274-0462. When logging in, specify user
  85.  *    "public", system "bbs", and password "public".
  86.  *
  87.  *    This code is also available from the C Users Group in volume 317.
  88.  */
  89.  
  90. #include "g3g4.h"
  91.  
  92. /* #define TRACE 1 */
  93.  
  94. /* implementation limits: Due to the sizes of arrays and variables, and not
  95.    due to any restrictions in the algorithm, the following limits exist:
  96.      maximum number of pixels per row: 65533
  97.      maximum number of rows per image: none
  98.      maximum or minimum k-factor: none
  99.      maximum number of runs per row: 16382 white, 16382 black
  100.    To increase (or decrease) these limits, it will be necessary to play with
  101.    array and variable sizes.  On segmented machines (such as the 8086), a
  102.    different memory model may be necessary.  The algorithm itself has no
  103.    limits on image size or complexity, and the stack requirements are in-
  104.    sensitive to changes in these limits or to image complexity. */
  105.  
  106. #define EVEN 0
  107. #define ODD 1
  108.  
  109. static short a0, a1, a2, b0, b1, b2, bit_number, code_byte;
  110. static unsigned char color, current_row, mode;
  111. static unsigned short even_runs [32768], odd_runs [32768];
  112. static unsigned short even_index, odd_index;
  113. static short column_limit;
  114. static short row_number = 0;
  115.   /* Depending as current_row == EVEN or current_row == ODD, the runs of the
  116.      current row are represented in even_runs [] or odd_runs [].  The white
  117.      runs have even subscripts and the black runs have odd subscripts.  The
  118.      values of the array elements are the offsets of the beginnings of the
  119.      corresponding runs from the beginning of the row.  As defined by the
  120.      specification,
  121.     a0 is the reference or starting changing element on the coding line.
  122.         It may be considered the "current position".
  123.     a1 is the next changing element to the right of a0 on the coding line.
  124.     a2 is the next changing element to the right of a1 on the coding line.
  125.     b1 is the first changing element on the reference line to the right of
  126.         a0 and of opposite color to a0.
  127.     b2 is the next changing element to the right of b1 on the reference
  128.         line.
  129.      Furthermore,
  130.     b0 is the "previous" value of b1. 
  131.      Depending as current_row == EVEN or == ODD, even_index or odd_index is
  132.      the subscript of the entry in even_runs [] or odd_runs [] corresponding
  133.      to the run containing the current value of a0, and its counterpart cor-
  134.      responds to the run containing b1. */
  135.  
  136. static void new_row (void);
  137. static short decode_white_run (void);
  138. static short decode_black_run (void);
  139. static short decode_white_word (void);
  140. static short decode_black_word (void);
  141. static char next_bit (void);
  142. static short null_mode (void);
  143.  
  144. static char decode_return;
  145.  
  146. /* g4i_decode () successively invokes (*p_decode_next_byte) () for each byte of the
  147.    encoded image, and calls (*p_decode_white) () or (*p_decode_black) () as
  148.    required to return the image contents on a run-by-run basis. */
  149. char g4i_decode ()
  150. {
  151.   /* At the beginning of this routine, we are in the NULL mode, which is to
  152.      to say that no codewords are currently understood or digested.  The
  153.      variable bit_number has been initialized to zero, to indicate that the
  154.      next (first) codeword is to begin with bit zero of the next code byte.
  155.      This betrays an assumption that all images begin on byte boundaries, a
  156.      condition that can be changed by arranging for bit_number to be set
  157.      otherwise by g4i_initialize () or elsewhere. */
  158.   while (!decode_return)
  159.   {
  160.     mode = (unsigned char) null_mode ();
  161.     if (current_row == EVEN)
  162.     {
  163.       b0 = b1;
  164.       b1 = odd_runs [odd_index];
  165.       if ((b1 <= a0) && a0)
  166.       {
  167.     odd_index += 2;
  168.     b0 = odd_runs [odd_index - 1];
  169.     b1 = odd_runs [odd_index];
  170.       }
  171.       b2 = odd_runs [odd_index + 1];
  172.     }
  173.     else /* current_row == ODD */
  174.     {
  175.       b0 = b1;
  176.       b1 = even_runs [even_index];
  177.       if ((b1 <= a0) && a0)
  178.       {
  179.     even_index += 2;
  180.     b0 = even_runs [even_index - 1];
  181.     b1 = even_runs [even_index];
  182.       }
  183.       b2 = even_runs [even_index + 1];
  184.     }
  185.     #if defined (TRACE)
  186.       if (trace_flag)
  187.       {
  188.     if (current_row == EVEN)
  189.     {
  190.       printf ("\n ref_index=%hd b1=%hd b2=%hd a0=%hd curr[%hd]=%hd "
  191.         "color=%hd ",
  192.         odd_index, b1, b2, a0, even_index, even_runs [even_index],
  193.         (short) color);
  194.     }
  195.     else /* current_row == ODD */
  196.     {
  197.       printf ("\n ref_index=%hd b1=%hd b2=%hd a0=%hd curr[%hd]=%hd "
  198.         "color=%hd ",
  199.         even_index, b1, b2, a0, odd_index, odd_runs [odd_index],
  200.         (short) color);
  201.     }
  202.       }
  203.     #endif
  204.     switch (mode)
  205.     {
  206.       case PASS_MODE: /* skip (pass) two color changes on the previous row */
  207.     #if defined (TRACE)
  208.       if (trace_flag) printf (" P ");
  209.     #endif
  210.     if (color == WHITE) (*p_decode_white) ((short) (b2 - a0));
  211.     else /* color == BLACK */ (*p_decode_black) ((short) (b2 - a0));
  212.     a0 = b2;
  213.     if (current_row == EVEN)
  214.     {
  215.       odd_index += 2;
  216.       b1 = odd_runs [odd_index];
  217.     }
  218.     else /* current_row == ODD */
  219.     {
  220.       even_index += 2;
  221.       b1 = even_runs [even_index];
  222.     }
  223.     break;
  224.       case HORIZONTAL_MODE: /* revert to 1-dimensional modified Huffman
  225.     encoding for a pair of runs */
  226.     #if defined (TRACE)
  227.       if (trace_flag) printf (" H ");
  228.     #endif
  229.     if (color == WHITE)
  230.     {
  231.       short black_runlength, white_runlength;
  232.       white_runlength = decode_white_run ();
  233.       (*p_decode_white) ((short) white_runlength);
  234.       a1 = (a0 += white_runlength);
  235.       black_runlength = decode_black_run ();
  236.       (*p_decode_black) ((short) black_runlength);
  237.       a2 = (a0 += black_runlength);
  238.     }
  239.     else /* color == BLACK */
  240.     {
  241.       short black_runlength, white_runlength;
  242.       black_runlength = decode_black_run ();
  243.       (*p_decode_black) ((short) black_runlength);
  244.       a1 = (a0 += black_runlength);
  245.       white_runlength = decode_white_run ();
  246.       (*p_decode_white) ((short) white_runlength);
  247.       a2 = (a0 += white_runlength);
  248.     }
  249.     if (current_row == EVEN)
  250.     {
  251.       even_runs [++even_index] = a1;
  252.       even_runs [++even_index] = a2;
  253.       while (a0 > odd_runs [odd_index]) odd_index += 2;
  254.       b1 = odd_runs [odd_index];
  255.     }
  256.     else /* current_row == ODD */
  257.     {
  258.       odd_runs [++odd_index] = a1;
  259.       odd_runs [++odd_index] = a2;
  260.       while (a0 > even_runs [even_index]) even_index += 2;
  261.       b1 = even_runs [even_index];
  262.     }
  263.     break;
  264.       case VERTICAL_V0_MODE: /* the next color change begins at the same
  265.     location as in the previous row */
  266.     #if defined (TRACE)
  267.       if (trace_flag) printf (" V0 ");
  268.     #endif
  269.     if (color == WHITE)
  270.     {
  271.       (*p_decode_white) ((short) (b1 - a0));
  272.       color = BLACK;
  273.     }
  274.     else /* color == BLACK */
  275.     {
  276.       (*p_decode_black) ((short) (b1 - a0));
  277.       color = WHITE;
  278.     }
  279.     a0 = b1; 
  280.     if (current_row == EVEN)
  281.     {
  282.       even_runs [++even_index] = a0;
  283.       odd_index++;
  284.     }
  285.     else /* current_row == ODD */
  286.     {
  287.       odd_runs [++odd_index] = a0;
  288.       even_index++;
  289.     }
  290.     break;
  291.       case VERTICAL_VR1_MODE: /* the next color change begins one pixel to the
  292.     right of its location on the previous row */
  293.     #if defined (TRACE)
  294.       if (trace_flag) printf (" VR1 ");
  295.     #endif
  296.     if (color == WHITE)
  297.     {
  298.       (*p_decode_white) ((short) (b1 - a0 + 1));
  299.       color = BLACK;
  300.     }
  301.     else /* color == BLACK */
  302.     {
  303.       (*p_decode_black) ((short) (b1 - a0 + 1));
  304.       color = WHITE;
  305.     }
  306.     a0 = b1 + 1; 
  307.     if (current_row == EVEN)
  308.     {
  309.       even_runs [++even_index] = a0;
  310.       odd_index++;
  311.     }
  312.     else /* current_row == ODD */
  313.     {
  314.       odd_runs [++odd_index] = a0;
  315.       even_index++;
  316.     }
  317.     break;
  318.       case VERTICAL_VR2_MODE: /* the next color change begins two pixels to
  319.     the right of its location on the previous row */
  320.     #if defined (TRACE)
  321.       if (trace_flag) printf (" VR2 ");
  322.     #endif
  323.     if (color == WHITE)
  324.     {
  325.       (*p_decode_white) ((short) (b1 - a0 + 2));
  326.       color = BLACK;
  327.     }
  328.     else /* color == BLACK */
  329.     {
  330.       (*p_decode_black) ((short) (b1 - a0 + 2));
  331.       color = WHITE;
  332.     }
  333.     a0 = b1 + 2; 
  334.     if (current_row == EVEN)
  335.     {
  336.       even_runs [++even_index] = a0;
  337.       odd_index++;
  338.     }
  339.     else /* current_row == ODD */
  340.     {
  341.       odd_runs [++odd_index] = a0;
  342.       even_index++;
  343.     }
  344.     break;
  345.       case VERTICAL_VR3_MODE: /* the next color change begins three pixels to
  346.     the right of its location on the previous row */
  347.     #if defined (TRACE)
  348.       if (trace_flag) printf (" VR3 ");
  349.     #endif
  350.     if (color == WHITE)
  351.     {
  352.       (*p_decode_white) ((short) (b1 - a0 + 3));
  353.       color = BLACK;
  354.     }
  355.     else /* color == BLACK */
  356.     {
  357.       (*p_decode_black) ((short) (b1 - a0 + 3));
  358.       color = WHITE;
  359.     }
  360.     a0 = b1 + 3; 
  361.     if (current_row == EVEN)
  362.     {
  363.       even_runs [++even_index] = a0;
  364.       odd_index++;
  365.     }
  366.     else /* current_row == ODD */
  367.     {
  368.       odd_runs [++odd_index] = a0;
  369.       even_index++;
  370.     }
  371.     break;
  372.       case VERTICAL_VL1_MODE: /* the next color change begins one pixel to the
  373.     left of its location on the previous row */
  374.     #if defined (TRACE)
  375.       if (trace_flag) printf (" VL1 ");
  376.     #endif
  377.     if (color == WHITE)
  378.     {
  379.       (*p_decode_white) ((short) (b1 - a0 - 1));
  380.       color = BLACK;
  381.     }
  382.     else /* color == BLACK */
  383.     {
  384.       (*p_decode_black) ((short) (b1 - a0 - 1));
  385.       color = WHITE;
  386.     }
  387.     a0 = b1 - 1; 
  388.     if (current_row == EVEN)
  389.     {
  390.       even_runs [++even_index] = a0;
  391.       odd_index++;
  392.     }
  393.     else /* current_row == ODD */
  394.     {
  395.       odd_runs [++odd_index] = a0;
  396.       even_index++;
  397.     }
  398.     break;
  399.       case VERTICAL_VL2_MODE: /* the next color change begins two pixels to
  400.     the left of its location on the previous row */
  401.     #if defined (TRACE)
  402.       if (trace_flag) printf (" VL2 ");
  403.     #endif
  404.     if (color == WHITE)
  405.     {
  406.       (*p_decode_white) ((short) (b1 - a0 - 2));
  407.       color = BLACK;
  408.     }
  409.     else /* color == BLACK */
  410.     {
  411.       (*p_decode_black) ((short) (b1 - a0 - 2));
  412.       color = WHITE;
  413.     }
  414.     a0 = b1 - 2; 
  415.     if (current_row == EVEN)
  416.     {
  417.       even_runs [++even_index] = a0;
  418.       if (a0 < b0) odd_index--;
  419.       else odd_index++;
  420.     }
  421.     else /* current_row == ODD */
  422.     {
  423.       odd_runs [++odd_index] = a0;
  424.       if (a0 < b0) even_index--;
  425.       else even_index++;
  426.     }
  427.     break;
  428.       case VERTICAL_VL3_MODE: /* the next color change begins three pixels to
  429.     the left of its location on the previous row */
  430.     #if defined (TRACE)
  431.       if (trace_flag) printf (" VL3 ");
  432.     #endif
  433.     if (color == WHITE)
  434.     {
  435.       (*p_decode_white) ((short) (b1 - a0 - 3));
  436.       color = BLACK;
  437.     }
  438.     else /* color == BLACK */
  439.     {
  440.       (*p_decode_black) ((short) (b1 - a0 - 3));
  441.       color = WHITE;
  442.     }
  443.     a0 = b1 - 3; 
  444.     if (current_row == EVEN)
  445.     {
  446.       even_runs [++even_index] = a0;
  447.       if (a0 < b0) odd_index--;
  448.       else odd_index++;
  449.     }
  450.     else /* current_row == ODD */
  451.     {
  452.       odd_runs [++odd_index] = a0;
  453.       if (a0 < b0) even_index--;
  454.       else even_index++;
  455.     }
  456.     break;
  457.       case EXT_MODE_UNCOMPRESSED: /* enter extension type 7 ("111"), an
  458.     uncompressed encoding scheme */
  459.     return (ERROR_UNSUPPORTED_EXTENSION);
  460.     break;
  461.       case ERROR_MODE: /* The bit pattern found corresponds to an unknown or
  462.     invalid codeword.  This MAY be one of the seven possible extensions
  463.     not defined by the specification. */
  464.     return (ERROR_INVALID_CODEWORD);
  465.     break;
  466.       case ERROR_MODE_1: /* assumed in this implementation to be equivalent
  467.     to EOFB (end-of-facsimile-block) */
  468.     return (RETURN_OK);
  469.     break;
  470.       default: /* we should never get here; if we do, the tables are bad */
  471.     return (ERROR_PROGRAM_LOGIC);
  472.     break;
  473.     }
  474.     if (a0 >= column_limit) new_row ();
  475.   }
  476.   return (decode_return);
  477. }
  478.  
  479. /* g4i_initialize () is called to set up to decode a new image.  All of the
  480.    static data (flags, etc) for g4i_decode () are initialized, allowing the
  481.    decoding of multiple images in a run as long as g4i_initialize () is
  482.    called before each one. */
  483. char g4i_initialize (short image_width, short image_length)
  484. {
  485.   color = WHITE;
  486.   bit_number= 0;
  487.   current_row = ODD;
  488.   even_runs [0] = 0;
  489.   even_runs [1] = image_width; /* initial b1 */
  490.   even_runs [2] = image_width; /* initial b2 */
  491.   odd_runs [0] = 0;
  492.   a0 = 0;
  493.   even_index = 1; odd_index = 0;
  494.   column_limit = image_width;
  495.   row_number = 0;
  496.   b1 = -1;
  497.   decode_return = 0;
  498.   return (0);
  499. }
  500.  
  501. static short null_mode ()
  502. {
  503.   if (next_bit ()) /* 1 */ return (VERTICAL_V0_MODE);
  504.   else /* 0... */
  505.   {
  506.     if (next_bit ()) /* 01... */
  507.     {
  508.       if (next_bit ()) /* 011 */ return (VERTICAL_VR1_MODE);
  509.       else /* 010 */ return (VERTICAL_VL1_MODE);
  510.     }
  511.     else /* 00... */
  512.     {
  513.       if (next_bit ()) /* 001 */ return (HORIZONTAL_MODE);
  514.       else /* 000... */
  515.       {
  516.     if (next_bit ()) /* 0001 */ return (PASS_MODE);
  517.     else /* 0000... */
  518.     {
  519.       if (next_bit ()) /* 0000 1... */
  520.       {
  521.         if (next_bit ()) /* 0000 11 */ return (VERTICAL_VR2_MODE);
  522.         else /* 0000 10 */ return (VERTICAL_VL2_MODE);
  523.       }
  524.       else /* 0000 0... */
  525.       {
  526.         if (next_bit ()) /* 0000 01... */
  527.         {
  528.           if (next_bit ()) /* 0000 011 */ return (VERTICAL_VR3_MODE);
  529.           else /* 0000 010 */ return (VERTICAL_VL3_MODE);
  530.         }
  531.         else /* 0000 00... */
  532.         {
  533.           if (next_bit ()) /* 0000 001... */
  534.           {
  535.         if (next_bit ()) /* 0000 0011... */
  536.         {
  537.           if (next_bit ()) /* 0000 0011 1... */
  538.           {
  539.             if (next_bit ()) /* 0000 0011 11 */
  540.                     return (EXT_MODE_UNCOMPRESSED);
  541.             else /* 0000 0011 10 */ return (ERROR_MODE);
  542.           }
  543.           else /* 0000 0011 0 */ return (ERROR_MODE);
  544.         }
  545.         else /* 0000 0010 */ return (ERROR_MODE);
  546.           }
  547.           else /* 0000 000 */ return (ERROR_MODE_1);
  548.         /* under the assumption that there are no errors in the file,
  549.             then this bit string can only be the beginning of an
  550.             EOFB (end-of-facsimile-block) code */
  551.         }
  552.       }
  553.     }
  554.       }
  555.     }
  556.   }
  557.   return (-1);
  558. }
  559.  
  560. static void new_row ()
  561. {
  562.   (*p_decode_new_row) ();
  563.   color = WHITE;
  564.   if (current_row == ODD)
  565.   {
  566.     current_row = EVEN;
  567.     odd_runs [++odd_index] = a0;
  568.     odd_runs [++odd_index] = a0;
  569.     odd_index = 1;
  570.     even_index = 0;
  571.   }
  572.   else /* current_row == EVEN */
  573.   {
  574.     current_row = ODD;
  575.     even_runs [++even_index] = a0;
  576.     even_runs [++even_index] = a0;
  577.     even_index = 1;
  578.     odd_index = 0;
  579.   }
  580.   a0 = 0;
  581.   b1 = -1;
  582.   #if defined (TRACE)
  583.     row_number++;
  584.   #endif
  585. }
  586.  
  587. static char next_bit (void)
  588. {
  589.   char value;
  590.   static unsigned char decode_mask [8] =
  591.     { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
  592.   if (!bit_number) code_byte = (*p_decode_next_byte) ();
  593.   if ((unsigned char) code_byte & decode_mask [bit_number]) value = 1;
  594.   else value = 0;
  595.   if (++bit_number > 7) bit_number = 0;
  596.   return (value);
  597. }
  598.  
  599. /*
  600.  *    return the length of the next run, assumed to be black
  601.  */
  602.  
  603. static short decode_black_run ()
  604. {
  605.   short cumulative = 0, code_value;
  606.   for (;;)
  607.   {
  608.     code_value = decode_black_word ();
  609.     cumulative += code_value;
  610.     if (code_value < 0) return (code_value);
  611.     if (code_value < 64) return (cumulative);
  612.   }
  613. }
  614.  
  615. static short decode_black_word ()
  616. {
  617.   if (next_bit ()) /* 1... */
  618.   {
  619.     if (next_bit ()) /* 11 */ return (2);
  620.     else /* 10 */ return (3);
  621.   }
  622.   else /* 0... */
  623.   {
  624.     if (next_bit ()) /* 01... */
  625.     {
  626.       if (next_bit ()) /* 011 */ return (4);
  627.       else /* 010 */ return (1);
  628.     }
  629.     else /* 00... */
  630.     {
  631.       if (next_bit ()) /* 001... */
  632.       {
  633.     if (next_bit ()) /* 0011 */ return (5);
  634.     else /* 0010 */ return (6);
  635.       }
  636.       else /* 000... */
  637.       {
  638.     if (next_bit ()) /* 0001... */
  639.     {
  640.       if (next_bit ()) /* 0001 1 */ return (7);
  641.       else /* 0001 0... */
  642.       {
  643.         if (next_bit ()) /* 0001 01 */ return (8);
  644.         else /* 0001 00 */ return (9);
  645.       }
  646.     }
  647.     else /* 0000... */
  648.     {
  649.       if (next_bit ()) /* 0000 1... */
  650.       {
  651.         if (next_bit ()) /* 0000 11... */
  652.         {
  653.           if (next_bit ()) /* 0000 111 */ return (12);
  654.           else /* 0000 110... */
  655.           {
  656.         if (next_bit ()) /* 0000 1101... */
  657.         {
  658.           if (next_bit ()) /* 0000 1101 1... */
  659.           {
  660.             if (next_bit ()) /* 0000 1101 11 */ return (0);
  661.             else /* 0000 1101 10... */
  662.             {
  663.               if (next_bit ()) /* 0000 1101 101... */
  664.               {
  665.             if (next_bit ()) /* 0000 1101 1011 */ return (43);
  666.             else /* 0000 1101 1010 */ return (42);
  667.               }
  668.               else /* 0000 1101 100 */ return (21);
  669.             }
  670.           }
  671.           else /* 0000 1101 0... */
  672.           {
  673.             if (next_bit ()) /* 0000 1101 01... */
  674.             {
  675.               if (next_bit ()) /* 0000 1101 011... */
  676.               {
  677.             if (next_bit ()) /* 0000 1101 0111 */ return (39);
  678.             else /* 0000 1101 0110 */ return (38);
  679.               }
  680.               else /* 0000 1101 010... */
  681.               {
  682.             if (next_bit ()) /* 0000 1101 0101 */ return (37);
  683.             else /* 0000 1101 0100 */ return (36);
  684.               }
  685.             }
  686.             else /* 0000 1101 00... */
  687.             {
  688.               if (next_bit ()) /* 0000 1101 001... */
  689.               {
  690.             if (next_bit ()) /* 0000 1101 0011 */ return (35);
  691.             else /* 0000 1101 0010 */ return (34);
  692.               }
  693.               else /* 0000 1101 000 */ return (20);
  694.             }
  695.           }
  696.         }
  697.         else /* 0000 1100... */
  698.         {
  699.           if (next_bit ()) /* 0000 1100 1... */
  700.           {
  701.             if (next_bit ()) /* 0000 1100 11... */
  702.             {
  703.               if (next_bit ()) /* 0000 1100 111 */ return (19);
  704.               else /* 0000 1100 110... */
  705.               {
  706.             if (next_bit ()) /* 0000 1100 1101 */ return (29);
  707.             else /* 0000 1100 1100 */ return (28);
  708.               }
  709.             }
  710.             else /* 0000 1100 10... */
  711.             {
  712.               if (next_bit ()) /* 0000 1100 101.. */
  713.               {
  714.             if (next_bit ()) /* 0000 1100 1011 */ return (27);
  715.             else /* 0000 1100 1010 */ return (26);
  716.               }
  717.               else /* 0000 1100 100... */
  718.               {
  719.             if (next_bit ()) /* 0000 1100 1001 */ return (192);
  720.             else /* 0000 1100 1000 */ return (128);
  721.               }
  722.             }
  723.           }
  724.           else /* 0000 1100 0 */ return (15);
  725.         }
  726.           }
  727.         }
  728.         else /* 0000 10... */
  729.         {
  730.           if (next_bit ()) /* 0000 101 */ return (11);
  731.           else /* 0000 100 */ return (10);
  732.         }
  733.       }
  734.       else /* 0000 0... */
  735.       {
  736.         if (next_bit ()) /* 0000 01... */
  737.         {
  738.           if (next_bit ()) /* 0000 011... */
  739.           {
  740.         if (next_bit ()) /* 0000 0111 */ return (14);
  741.         else /* 0000 0110... */
  742.         {
  743.           if (next_bit ()) /* 0000 0110 1... */
  744.           {
  745.             if (next_bit ()) /* 0000 0110 11... */
  746.             {
  747.               if (next_bit ()) /* 0000 0110 111 */ return (22);
  748.               else /* 0000 0110 110... */
  749.               {
  750.             if (next_bit ()) /* 0000 0110 1101 */ return (41);
  751.             else /* 0000 0110 1100 */ return (40);
  752.               }
  753.             }
  754.             else /* 0000 0110 10... */
  755.             {
  756.               if (next_bit ()) /* 0000 0110 101... */
  757.               {
  758.             if (next_bit ()) /* 0000 0110 1011 */ return (33);
  759.             else /* 0000 0110 1010 */ return (32);
  760.               }
  761.               else /* 0000 0110 100... */
  762.               {
  763.             if (next_bit ()) /* 0000 0110 1001 */ return (31);
  764.             else /* 0000 0110 1000 */ return (30);
  765.               }
  766.             }
  767.           }
  768.           else /* 0000 0110 0... */
  769.           {
  770.             if (next_bit ()) /* 0000 0110 01... */
  771.             {
  772.               if (next_bit ()) /* 0000 0110 011... */
  773.               {
  774.             if (next_bit ()) /* 0000 0110 0111 */ return (63);
  775.             else /* 0000 0110 0110 */ return (62);
  776.               }
  777.               else /* 0000 0110 010... */
  778.               {
  779.             if (next_bit ()) /* 0000 0110 0101 */ return (49);
  780.             else /* 0000 0110 0100 */ return (48);
  781.               }
  782.             }
  783.             else /* 0000 0110 00 */ return (17);
  784.           }
  785.         }
  786.           }
  787.           else /* 0000 010... */
  788.           {
  789.         if (next_bit ()) /* 0000 0101... */
  790.         {
  791.           if (next_bit ()) /* 0000 0101 1... */
  792.           {
  793.             if (next_bit ()) /* 0000 0101 11 */ return (16);
  794.             else /* 0000 0101 10... */
  795.             {
  796.               if (next_bit ()) /* 0000 0101 101... */
  797.               {
  798.             if (next_bit ()) /* 0000 0101 1011 */ return (256);
  799.             else /* 0000 0101 1010 */ return (61);
  800.               }
  801.               else /* 0000 0101 100... */
  802.               {
  803.             if (next_bit ()) /* 0000 0101 1001 */ return (58);
  804.             else /* 0000 0101 1000 */ return (57);
  805.               }
  806.             }
  807.           }
  808.           else /* 0000 0101 0... */
  809.           {
  810.             if (next_bit ()) /* 0000 0101 01... */
  811.             {
  812.               if (next_bit ()) /* 0000 0101 011... */
  813.               {
  814.             if (next_bit ()) /* 0000 0101 0111 */ return (47);
  815.             else /* 0000 0101 0110 */ return (46);
  816.               }
  817.               else /* 0000 0101 010... */
  818.               {
  819.             if (next_bit ()) /* 0000 0101 0101 */ return (45);
  820.             else /* 0000 0101 0100 */ return (44);
  821.               }
  822.             }
  823.             else /* 0000 0101 00... */
  824.             {
  825.               if (next_bit ()) /* 0000 0101 001... */
  826.               {
  827.             if (next_bit ()) /* 0000 0101 0011 */ return (51);
  828.             else /* 0000 0101 0010 */ return (50);
  829.               }
  830.               else /* 0000 0101 000 */ return (23);
  831.             }
  832.           }
  833.         }
  834.         else /* 0000 0100 */ return (13);
  835.           }
  836.         }
  837.         else /* 0000 00... */
  838.         {
  839.           if (next_bit ()) /* 0000 001... */
  840.           {
  841.         if (next_bit ()) /* 0000 0011... */
  842.         {
  843.           if (next_bit ()) /* 0000 0011 1... */
  844.           {
  845.             if (next_bit ()) /* 0000 0011 11 */ return (64);
  846.             else /* 0000 0011 10... */
  847.             {
  848.               if (next_bit ()) /* 0000 0011 101... */
  849.               {
  850.             if (next_bit ()) /* 0000 0011 1011... */
  851.             {
  852.               if (next_bit ()) /* 0000 0011 1011 1 */ return (1216);
  853.               else /* 0000 0011 1011 0 */ return (1152);
  854.             }
  855.             else /* 0000 0011 1010... */
  856.             {
  857.               if (next_bit ()) /* 0000 0011 1010 1 */ return (1088);
  858.               else /* 0000 0011 1010 0 */ return (1024);
  859.             }
  860.               }
  861.               else /* 0000 0011 100... */
  862.               {
  863.             if (next_bit ()) /* 0000 0011 1001... */
  864.             {
  865.               if (next_bit ()) /* 0000 0011 1001 1 */ return (960);
  866.               else /* 0000 0011 1001 0 */ return (896);
  867.             }
  868.             else /* 0000 0011 1000 */ return (54);
  869.               }
  870.             }
  871.           }
  872.           else /* 0000 0011 0... */
  873.           {
  874.             if (next_bit ()) /* 0000 0011 01... */
  875.             {
  876.               if (next_bit ()) /* 0000 0011 011... */
  877.               {
  878.             if (next_bit ()) /* 0000 0011 0111 */ return (53);
  879.             else /* 0000 0011 0110... */
  880.             {
  881.               if (next_bit ()) /* 0000 0011 0110 1 */ return (576);
  882.               else /* 0000 0011 0110 0 */ return (512);
  883.             }
  884.               }
  885.               else /* 0000 0011 010... */
  886.               {
  887.             if (next_bit ()) /* 0000 0011 0101 */ return (448);
  888.             else /* 0000 0011 0100 */ return (384);
  889.               }
  890.             }
  891.             else /* 0000 0011 00... */
  892.             {
  893.               if (next_bit ()) /* 0000 0011 001... */
  894.               {
  895.             if (next_bit ()) /* 0000 0011 0011 */ return (320);
  896.             else /* 0000 0011 0010... */
  897.             {
  898.               if (next_bit ()) /* 0000 0011 0010 1 */ return (1728);
  899.               else /* 0000 0011 0010 0 */ return (1664);
  900.             }
  901.               }
  902.               else /* 0000 0011 000 */ return (25);
  903.             }
  904.           }
  905.         }
  906.         else /* 0000 0010... */
  907.         {
  908.           if (next_bit ()) /* 0000 0010 1... */
  909.           {
  910.             if (next_bit ()) /* 0000 0010 11... */
  911.             {
  912.               if (next_bit ()) /* 0000 0010 111 */ return (24);
  913.               else /* 0000 0010 110... */
  914.               {
  915.             if (next_bit ()) /* 0000 0010 1101... */
  916.             {
  917.               if (next_bit ()) /* 0000 0010 1101 1 */ return (1600);
  918.               else /* 0000 0010 1101 0 */ return (1536);
  919.             }
  920.             else /* 0000 0010 1100 */ return (60);
  921.               }
  922.             }
  923.             else /* 0000 0010 10... */
  924.             {
  925.               if (next_bit ()) /* 0000 0010 101... */
  926.               {
  927.             if (next_bit ()) /* 0000 0010 1011 */ return (59);
  928.             else /* 0000 0010 1010... */
  929.             {
  930.               if (next_bit ()) /* 0000 0010 1010 1 */ return (1472);
  931.               else /* 0000 0010 1010 0 */ return (1408);
  932.             }
  933.               }
  934.               else /* 0000 0010 100... */
  935.               {
  936.             if (next_bit ()) /* 0000 0010 1001... */
  937.             {
  938.               if (next_bit ()) /* 0000 0010 1001 1 */ return (1344);
  939.               else /* 0000 0010 1001 0 */ return (1280);
  940.             }
  941.             else /* 0000 0010 1000 */ return (56);
  942.               }
  943.             }
  944.           }
  945.           else /* 0000 0010 0... */
  946.           {
  947.             if (next_bit ()) /* 0000 0010 01... */
  948.             {
  949.               if (next_bit ()) /* 0000 0010 011... */
  950.               {
  951.             if (next_bit ()) /* 0000 0010 0111 */ return (55);
  952.             else /* 0000 0010 0110... */
  953.             {
  954.               if (next_bit ()) /* 0000 0010 0110 1 */ return (832);
  955.               else /* 0000 0010 0110 0 */ return (768);
  956.             }
  957.               }
  958.               else /* 0000 0010 010... */
  959.               {
  960.             if (next_bit ()) /* 0000 0010 0101... */
  961.             {
  962.               if (next_bit ()) /* 0000 0010 0101 1 */ return (704);
  963.               else /* 0000 0010 0101 0 */ return (640);
  964.             }
  965.             else /* 0000 0010 0100 */ return (52);
  966.               }
  967.             }
  968.             else /* 0000 0010 00 */ return (18);
  969.           }
  970.         }
  971.           }
  972.           else /* 0000 000... */
  973.           {
  974.         if (next_bit ()) /* 0000 0001... */
  975.         {
  976.           if (next_bit ()) /* 0000 0001 1... */
  977.           {
  978.             if (next_bit ()) /* 0000 0001 11... */
  979.             {
  980.               if (next_bit ()) /* 0000 0001 111... */
  981.               {
  982.             if (next_bit ()) /* 0000 0001 1111 */ return (2560);
  983.             else /* 0000 0001 1110 */ return (2496);
  984.               }
  985.               else /* 0000 0001 110... */
  986.               {
  987.             if (next_bit ()) /* 0000 0001 1101 */ return (2432);
  988.             else /* 0000 0001 1100 */ return (2368);
  989.               }
  990.             }
  991.             else /* 0000 0001 10... */
  992.             {
  993.               if (next_bit ()) /* 0000 0001 101 */ return (1920);
  994.               else /* 0000 0001 100 */ return (1856);
  995.             }
  996.           }
  997.           else /* 0000 0001 0... */
  998.           {
  999.             if (next_bit ()) /* 0000 0001 01... */
  1000.             {
  1001.               if (next_bit ()) /* 0000 0001 011... */
  1002.               {
  1003.             if (next_bit ()) /* 0000 0001 0111 */ return (2304);
  1004.             else /* 0000 0001 0110 */ return (2240);
  1005.               }
  1006.               else /* 0000 0001 010... */
  1007.               {
  1008.             if (next_bit ()) /* 0000 0001 0101 */ return (2176);
  1009.             else /* 0000 0001 0100 */ return (2112);
  1010.               }
  1011.             }
  1012.             else /* 0000 0001 00... */
  1013.             {
  1014.               if (next_bit ()) /* 0000 0001 001... */
  1015.               {
  1016.             if (next_bit ()) /* 0000 0001 0011 */ return (2048);
  1017.             else /* 0000 0001 0010 */ return (1984);
  1018.               }
  1019.               else /* 0000 0001 000 */ return (1792);
  1020.             }
  1021.           }
  1022.         }
  1023.         else /* 0000 0000... */
  1024.         {
  1025.           if (next_bit ()) /* 0000 0000 1 */ return (INVALID_CODE);
  1026.           else /* 0000 0000 0... */
  1027.           {
  1028.             if (next_bit ()) /* 0000 0000 01 */ return (INVALID_CODE);
  1029.             else /* 0000 0000 00... */
  1030.             {
  1031.               if (next_bit ()) /* 0000 0000 001 */
  1032.                             return (INVALID_CODE);
  1033.               else /* 0000 0000 000... */
  1034.               {
  1035.             if (next_bit ()) /* 0000 0000 0001 */ return (EOL_CODE);
  1036.             else /* 0000 0000 0000 */ return (INVALID_CODE);
  1037.               }
  1038.             }
  1039.           }
  1040.         }
  1041.           }
  1042.         }
  1043.       }
  1044.     }
  1045.       }
  1046.     }
  1047.   }
  1048. }
  1049.  
  1050. /*
  1051.  *    return the length of the next run, assumed to be white 
  1052.  */
  1053.  
  1054. static short decode_white_run ()
  1055. {
  1056.   short cumulative = 0, code_value;
  1057.   for (;;)
  1058.   {
  1059.     code_value = decode_white_word ();
  1060.     cumulative += code_value;
  1061.     if (code_value < 0) return (code_value);
  1062.     if (code_value < 64) return (cumulative);
  1063.   }
  1064. }
  1065.  
  1066. static short decode_white_word ()
  1067. {
  1068.   if (next_bit ()) /* 1... */
  1069.   {
  1070.     if (next_bit ()) /* 11... */
  1071.     {
  1072.       if (next_bit ()) /* 111... */
  1073.       {
  1074.     if (next_bit ()) /* 1111 */ return (7);
  1075.     else /* 1110 */ return (6);
  1076.       }
  1077.       else /* 110... */
  1078.       {
  1079.     if (next_bit ()) /* 1101... */
  1080.     {
  1081.       if (next_bit ()) /* 1101 1 */ return (64);
  1082.       else /* 1101 0... */
  1083.       {
  1084.         if (next_bit ()) /* 1101 01 */ return (15);
  1085.         else /* 1101 00 */ return (14);
  1086.       }
  1087.     }
  1088.     else /* 1100 */ return (5);
  1089.       }
  1090.     }
  1091.     else /* 10... */
  1092.     {
  1093.       if (next_bit ()) /* 101... */
  1094.       {
  1095.     if (next_bit ()) /* 1011 */ return (4);
  1096.     else /* 1010... */
  1097.     {
  1098.       if (next_bit ()) /* 10101... */
  1099.       {
  1100.         if (next_bit ()) /* 101011 */ return (17);
  1101.         else /* 101010 */ return (16);
  1102.       }
  1103.       else /* 10100 */ return (9);
  1104.     }
  1105.       }
  1106.       else /* 100... */
  1107.       {
  1108.     if (next_bit ()) /* 1001... */
  1109.     {
  1110.       if (next_bit ()) /* 10011 */ return (8);
  1111.       else /* 10010 */ return (128);
  1112.     }
  1113.     else /* 1000 */ return (3);
  1114.       }
  1115.     }
  1116.   }
  1117.   else /* 0... */
  1118.   {
  1119.     if (next_bit ()) /* 01... */
  1120.     {
  1121.       if (next_bit ()) /* 011... */
  1122.       {
  1123.     if (next_bit ()) /* 0111 */ return (2);
  1124.     else /* 0110... */
  1125.     {
  1126.       if (next_bit ()) /* 01101... */
  1127.       {
  1128.         if (next_bit ()) /* 011011... */
  1129.         {
  1130.           if (next_bit ()) /* 0110111 */ return (256);
  1131.           else /* 0110110... */
  1132.           {
  1133.         if (next_bit ()) /* 01101101... */
  1134.         {
  1135.           if (next_bit ()) /* 011011011 */ return (1408);
  1136.           else /* 011011010 */ return (1344);
  1137.         }
  1138.             else /* 01101100... */
  1139.         {
  1140.           if (next_bit ()) /* 011011001 */ return (1280);
  1141.           else /* 011011000 */ return (1216);
  1142.         }
  1143.           }
  1144.         }
  1145.         else /* 011010... */
  1146.         {
  1147.           if (next_bit ()) /* 0110101... */
  1148.           {
  1149.         if (next_bit ()) /* 01101011... */
  1150.         {
  1151.           if (next_bit ()) /* 011010111 */ return (1152);
  1152.           else /* 011010110 */ return (1088);
  1153.         }
  1154.         else /* 01101010... */
  1155.         {
  1156.           if (next_bit ()) /* 011010101 */ return (1024);
  1157.           else /* 011010100 */ return (960);
  1158.         }
  1159.           }
  1160.           else /* 0110100... */
  1161.           {
  1162.         if (next_bit ()) /* 01101001... */
  1163.         {
  1164.           if (next_bit ()) /* 011010011 */ return (896);
  1165.           else /* 011010010 */ return (832);
  1166.         }
  1167.         else /* 01101000 */ return (576);
  1168.           }
  1169.         }
  1170.       }
  1171.       else /* 01100... */
  1172.       {
  1173.         if (next_bit ()) /* 011001... */
  1174.         {
  1175.           if (next_bit ()) /* 0110011... */
  1176.           {
  1177.         if (next_bit ()) /* 01100111 */ return (640);
  1178.         else /* 01100110 */
  1179.         {
  1180.           if (next_bit ()) /* 011001101 */ return (768);
  1181.           else /* 011001100 */ return (704);
  1182.         }
  1183.           }
  1184.           else /* 0110010 */
  1185.           {
  1186.         if (next_bit ()) /* 01100101 */ return (512);
  1187.         else /* 01100100 */ return (448);
  1188.           }
  1189.         }
  1190.         else /* 011000 */ return (1664);
  1191.       }
  1192.     }
  1193.       }
  1194.       else /* 010... */
  1195.       {
  1196.     if (next_bit ()) /* 0101... */
  1197.     {
  1198.       if (next_bit ()) /* 01011... */
  1199.       {
  1200.         if (next_bit ()) /* 010111 */ return (192);
  1201.         else /* 010110... */
  1202.         {
  1203.           if (next_bit ()) /* 0101101... */
  1204.           {
  1205.         if (next_bit ()) /* 01011011 */ return (58);
  1206.         else /* 01011010 */ return (57);
  1207.           }
  1208.           else /* 0101100... */
  1209.           {
  1210.         if (next_bit ()) /* 01011001 */ return (56);
  1211.         else /* 01011000 */ return (55);
  1212.           }
  1213.         }
  1214.       }
  1215.       else /* 01010... */
  1216.       {
  1217.         if (next_bit ()) /* 010101... */
  1218.         {
  1219.           if (next_bit ()) /* 0101011 */ return (25);
  1220.           else /* 0101010... */
  1221.           {
  1222.         if (next_bit ()) /* 01010101 */ return (52);
  1223.         else /* 01010100 */ return (51);
  1224.           }
  1225.         }
  1226.         else /* 010100... */
  1227.         {
  1228.           if (next_bit ()) /* 0101001... */
  1229.           {
  1230.         if (next_bit ()) /* 01010011 */ return (50);
  1231.         else /* 01010010 */ return (49);
  1232.           }
  1233.           else /* 0101000 */ return (24);
  1234.         }
  1235.       }
  1236.     }
  1237.     else /* 0100... */
  1238.     {
  1239.       if (next_bit ()) /* 01001... */
  1240.       {
  1241.         if (next_bit ()) /* 010011... */
  1242.         {
  1243.           if (next_bit ()) /* 0100111 */ return (18);
  1244.           else /* 0100110... */
  1245.           {
  1246.         if (next_bit ()) /* 01001101... */
  1247.         {
  1248.           if (next_bit ()) /* 010011011 */ return (1728);
  1249.           else /* 010011010 */ return (1600);
  1250.         }
  1251.         else /* 01001100... */
  1252.         {
  1253.           if (next_bit ()) /* 010011001 */ return (1536);
  1254.           else /* 010011000 */ return (1472);
  1255.         }
  1256.           }
  1257.         }
  1258.         else /* 010010... */
  1259.         {
  1260.           if (next_bit ()) /* 0100101... */
  1261.           {
  1262.         if (next_bit ()) /* 01001011 */ return (60);
  1263.         else /* 01001010 */ return (59);
  1264.           }
  1265.           else /* 0100100 */ return (27);
  1266.         }
  1267.       }
  1268.       else /* 01000 */ return (11);
  1269.     }
  1270.       }
  1271.     }
  1272.     else /* 00... */
  1273.     {
  1274.       if (next_bit ()) /* 001... */
  1275.       {
  1276.     if (next_bit ()) /* 0011... */
  1277.     {
  1278.       if (next_bit ()) /* 00111 */ return (10);
  1279.       else /* 00110... */
  1280.       {
  1281.         if (next_bit ()) /* 001101... */
  1282.         {
  1283.           if (next_bit ()) /* 0011011... */
  1284.           {
  1285.         if (next_bit ()) /* 00110111 */ return (384);
  1286.         else /* 00110110 */ return (320);
  1287.           }
  1288.           else /* 0011010... */
  1289.           {
  1290.         if (next_bit ()) /* 00110101 */ return (0);
  1291.         else /* 00110100 */ return (63);
  1292.           }
  1293.         }
  1294.         else /* 001100... */
  1295.         {
  1296.           if (next_bit ()) /* 0011001... */
  1297.           {
  1298.         if (next_bit ()) /* 00110011 */ return (62);
  1299.         else /* 00110010 */ return (61);
  1300.           }
  1301.           else /* 0011000 */ return (28);
  1302.         }
  1303.       }
  1304.     }
  1305.     else /* 0010... */
  1306.     {
  1307.       if (next_bit ()) /* 00101... */
  1308.       {
  1309.         if (next_bit ()) /* 001011... */
  1310.         {
  1311.           if (next_bit ()) /* 0010111 */ return (21);
  1312.           else /* 0010110... */
  1313.           {
  1314.         if (next_bit ()) /* 00101101 */ return (44);
  1315.         else /* 00101100 */ return (43);
  1316.           }
  1317.         }
  1318.         else /* 001010... */
  1319.         {
  1320.           if (next_bit ()) /* 0010101... */
  1321.           {
  1322.         if (next_bit ()) /* 00101011 */ return (42);
  1323.         else /* 00101010 */ return (41);
  1324.           }
  1325.           else /* 0010100... */
  1326.           {
  1327.         if (next_bit ()) /* 00101001 */ return (40);
  1328.         else /* 00101000 */ return (39);
  1329.           }
  1330.         }
  1331.       }
  1332.       else /* 00100... */
  1333.       {
  1334.         if (next_bit ()) /* 001001... */
  1335.         {
  1336.           if (next_bit ()) /* 0010011 */ return (26);
  1337.           else /* 0010010... */
  1338.           {
  1339.         if (next_bit ()) /* 00100101 */ return (54);
  1340.         else /* 00100100 */ return (53);
  1341.           }
  1342.         }
  1343.         else /* 001000 */ return (12);
  1344.       }
  1345.     }
  1346.       }
  1347.       else /* 000... */
  1348.       {
  1349.     if (next_bit ()) /* 0001... */
  1350.     {
  1351.       if (next_bit ()) /* 00011... */
  1352.       {
  1353.         if (next_bit ()) /* 000111 */ return (1);
  1354.         else /* 000110... */
  1355.         {
  1356.           if (next_bit ()) /* 0001101... */
  1357.           {
  1358.         if (next_bit ()) /* 00011011 */ return (32);
  1359.         else /* 00011010 */ return (31);
  1360.           }
  1361.           else /* 0001100 */ return (19);
  1362.         }
  1363.       }
  1364.       else /* 00010... */
  1365.       {
  1366.         if (next_bit ()) /* 000101... */
  1367.         {
  1368.           if (next_bit ()) /* 0001011... */
  1369.           {
  1370.         if (next_bit ()) /* 00010111 */ return (38);
  1371.         else /* 00010110 */ return (37);
  1372.           }
  1373.           else /* 0001010... */
  1374.           {
  1375.         if (next_bit ()) /* 00010101 */ return (36);
  1376.         else /* 00010100 */ return (35);
  1377.           }
  1378.         }
  1379.         else /* 000100... */
  1380.         {
  1381.           if (next_bit ()) /* 0001001... */
  1382.           {
  1383.         if (next_bit ()) /* 00010011 */ return (34);
  1384.         else /* 00010010 */ return (33);
  1385.           }
  1386.           else /* 0001000 */ return (20);
  1387.         }
  1388.       }
  1389.     }
  1390.     else /* 0000... */
  1391.     {
  1392.       if (next_bit ()) /* 00001... */
  1393.       {
  1394.         if (next_bit ()) /* 000011 */ return (13);
  1395.         else /* 000010... */
  1396.         {
  1397.           if (next_bit ()) /* 0000101... */
  1398.           {
  1399.         if (next_bit ()) /* 00001011 */ return (48);
  1400.         else /* 00001010 */ return (47);
  1401.           }
  1402.           else /* 0000100 */ return (23);
  1403.         }
  1404.       }
  1405.       else /* 00000... */
  1406.       {
  1407.         if (next_bit ()) /* 000001... */
  1408.         {
  1409.           if (next_bit ()) /* 0000011 */ return (22);
  1410.           else /* 0000010... */
  1411.           {
  1412.         if (next_bit ()) /* 00000101 */ return (46);
  1413.         else /* 00000100 */ return (45);
  1414.           }
  1415.         }
  1416.         else /* 000000... */
  1417.         {
  1418.           if (next_bit ()) /* 0000001... */
  1419.           {
  1420.         if (next_bit ()) /* 00000011 */ return (30);
  1421.         else /* 00000010 */ return (29);
  1422.           }
  1423.           else /* 0000 000... */
  1424.           {
  1425.         if (next_bit ()) /* 0000 0001... */
  1426.         {
  1427.           if (next_bit ()) /* 0000 0001 1... */
  1428.           {
  1429.             if (next_bit ()) /* 0000 0001 11... */
  1430.             {
  1431.               if (next_bit ()) /* 0000 0001 111... */
  1432.               {
  1433.             if (next_bit ()) /* 0000 0001 1111 */ return (2560);
  1434.             else /* 0000 0001 1110 */ return (2496);
  1435.               }
  1436.               else /* 0000 0001 110... */
  1437.               {
  1438.             if (next_bit ()) /* 0000 0001 1101 */ return (2432);
  1439.             else /* 0000 0001 1100 */ return (2368);
  1440.               }
  1441.             }
  1442.             else /* 0000 0001 10... */
  1443.             {
  1444.               if (next_bit ()) /* 0000 0001 101 */ return (1920);
  1445.               else /* 0000 0001 100 */ return (1856);
  1446.             }
  1447.           }
  1448.           else /* 0000 0001 0... */
  1449.           {
  1450.             if (next_bit ()) /* 0000 0001 01... */
  1451.             {
  1452.               if (next_bit ()) /* 0000 0001 011... */
  1453.               {
  1454.             if (next_bit ()) /* 0000 0001 0111 */ return (2304);
  1455.             else /* 0000 0001 0110 */ return (2240);
  1456.               }
  1457.               else /* 0000 0001 010... */
  1458.               {
  1459.             if (next_bit ()) /* 0000 0001 0101 */ return (2176);
  1460.             else /* 0000 0001 0100 */ return (2112);
  1461.               }
  1462.             }
  1463.             else /* 0000 0001 00... */
  1464.             {
  1465.               if (next_bit ()) /* 0000 0001 001... */
  1466.               {
  1467.             if (next_bit ()) /* 0000 0001 0011 */ return (2048);
  1468.             else /* 0000 0001 0010 */ return (1984);
  1469.               }
  1470.               else /* 0000 0001 000 */ return (1792);
  1471.             }
  1472.           }
  1473.         }
  1474.         else /* 0000 0000... */
  1475.         {
  1476.           if (next_bit ()) /* 0000 0000 1 */ return (INVALID_CODE);
  1477.           else /* 0000 0000 0... */
  1478.           {
  1479.             if (next_bit ()) /* 0000 0000 01 */ return (INVALID_CODE);
  1480.             else /* 0000 0000 00... */
  1481.             {
  1482.               if (next_bit ()) /* 0000 0000 001 */
  1483.                             return (INVALID_CODE);
  1484.               else /* 0000 0000 000... */
  1485.               {
  1486.             if (next_bit ()) /* 0000 0000 0001 */ return (EOL_CODE);
  1487.             else /* 0000 0000 0000 */ return (INVALID_CODE);
  1488.               }
  1489.             }
  1490.           }
  1491.         }
  1492.           }
  1493.         }
  1494.       }
  1495.     }
  1496.       }
  1497.     }
  1498.   }
  1499. }
  1500.  
  1501. /*    end $RCSfile: g4sdecod.c $ */
  1502.