home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / grfx_snd / tifflib / source / mkspans.c < prev    next >
C/C++ Source or Header  |  1992-11-09  |  2KB  |  62 lines

  1. #pragma warn -use
  2. static char     *sccsid = "@(#)TIFF/mkspans.c 1.04, Copyright (c) Sam Leffler, Dieter Linde, "__DATE__;
  3. #pragma warn .use
  4. /*
  5.  * Hack program to construct tables used to find runs of zeros and ones in Group 3 Fax encoding.
  6.  */
  7. #include <stdlib.h>
  8. #include "tiffio.h"
  9.  
  10. /****************************************************************************
  11.  *
  12.  */
  13. static void
  14. dumparray(
  15.            char     *name,
  16.         u_char    runs[256]
  17.         )
  18. {
  19.         register int     i;
  20.         register char     *sep;
  21.  
  22.         printf("static u_char\t%s[256] = {\n", name);
  23.         sep = "\t";
  24.         for (i = 0; i < 256; i++) {
  25.                 printf("%s%d", sep, runs[i]);
  26.                 if (((i + 1) % 16) == 0) {
  27.                         printf(",\t/* 0x%02x - 0x%02x */\n", i - 15, i);
  28.                         sep = "\t";
  29.                 } 
  30.                 else
  31.                         sep = ", ";
  32.         }
  33.         printf("\n};\n");
  34. }
  35.  
  36. /****************************************************************************
  37.  *
  38.  */
  39. void
  40. main(
  41.     void
  42.     )
  43. {
  44.         register int     run, runlen, i;
  45.         u_char        runs[2][256];
  46.  
  47.         bzero(runs[0], sizeof(char) * 256);
  48.         bzero(runs[1], sizeof(char) * 256);
  49.         runlen = 1;
  50.         for (run = 0x80; run != 0xff; run = (run >> 1) | 0x80) {
  51.                   for (i = run - 1; i >= 0; i--) {
  52.                            runs[1][run|i] = runlen;
  53.                            runs[0][(~(run | i)) & 0xff] = runlen;
  54.                 }
  55.                 runlen++;
  56.         }
  57.         runs[1][0xff] = runs[0][0] = 8;
  58.         dumparray("bruns", runs[0]);
  59.         dumparray("wruns", runs[1]);
  60.         exit(0);
  61. }
  62.