home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_06 / 8n06049a < prev    next >
Text File  |  1989-06-11  |  2KB  |  58 lines

  1.  
  2. Listing 1. The bit-wide technique: a straightforward but slow way to
  3. decode a Group 3 image
  4.  
  5. #define INVALID_CODE -1
  6. #define EOL_CODE -2
  7.  
  8. decode_image () {
  9.   ...
  10.   while (!end_of_file) {
  11.     /* loop for each row in the image */
  12.     ...
  13.     while (!end_of_row) {
  14.       /* loop for each pair of runs in the row */
  15.       int runlength;
  16.       while (63 < (runlength = decode_white_run ())) {
  17.         if (runlength == EOL_CODE) end_of_row = TRUE;
  18.         else if (runlength == INVALID_CODE)
  19.           ... error condition ...;
  20.         else /* a legal white run */
  21.           spit_out_white_pixels (runlength);
  22.       }
  23.       while (63 < (runlength = decode_black_run ())) {
  24.         if (runlength == EOL_CODE) end_of_row = TRUE;
  25.         else if (runlength == INVALID_CODE)
  26.           ... error condition ...;
  27.         else /* a legal black run */
  28.           spit_out_black_pixels (runlength);
  29.       }
  30.     }
  31.   }
  32. }
  33.  
  34. int decode_white_run () {
  35.   if (next_bit ()) /* 1... */ {
  36.     if (next_bit ()) /* 11... */ {
  37.       if (next_bit ()) /* 111... */ {
  38.         if (next_bit ()) /* 1111 */ return (7);
  39.         else /* 1110 */ return (6);
  40.       }
  41.       else /* 110... */ {
  42.         if (next_bit ()) /* 1101... */ {
  43.           if (next_bit ()) /* 1101 1 */ return (64);
  44.           else /* 1101 0... */ {
  45.             if (next_bit ()) /* 1101 01 */ return (15);
  46. ... omit a lot of ifs and elses and braces ...
  47.       if (next_bit ()) /* 0000 0000 001 */ return (INVALID_CODE);
  48.       else /* 0000 0000 000... */ {
  49.         if (next_bit ()) /* 0000 0000 0001 */ return (EOL_CODE);
  50.         else /* 0000 0000 0000 */ return (INVALID_CODE);
  51. ... omit a lot of braces ...
  52. }
  53.  
  54. int decode_black_run () {
  55. ... a lot like the preceding ... }
  56.  
  57.  
  58.