added code to generate RLE tables.

Wed, 19 Feb 2003 10:34:35 +0000

author
eric
date
Wed, 19 Feb 2003 10:34:35 +0000
changeset 56
425e8c46d318
parent 55
43a9b9f27403
child 57
b2a2f61135bb

added code to generate RLE tables.

bitblt_table_gen.c file | annotate | diff | revisions
     1.1 diff -r 43a9b9f27403 -r 425e8c46d318 bitblt_table_gen.c
     1.2 --- a/bitblt_table_gen.c	Wed Feb 19 10:20:05 2003 +0000
     1.3 +++ b/bitblt_table_gen.c	Wed Feb 19 10:34:35 2003 +0000
     1.4 @@ -4,7 +4,7 @@
     1.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     1.6   *
     1.7   * bitblt table generator
     1.8 - * $Id: bitblt_table_gen.c,v 1.1 2003/02/19 02:14:44 eric Exp $
     1.9 + * $Id: bitblt_table_gen.c,v 1.2 2003/02/19 02:34:35 eric Exp $
    1.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    1.11   *
    1.12   * This program is free software; you can redistribute it and/or modify
    1.13 @@ -26,12 +26,10 @@
    1.14  
    1.15  #include <stdio.h>
    1.16  
    1.17 -int main (int argc, char *argv[])
    1.18 +void gen_bit_reverse_table (void)
    1.19  {
    1.20    int i, j;
    1.21  
    1.22 -  printf ("/* This file is automatically generated; do not edit */\n");
    1.23 -  printf ("\n");
    1.24    printf ("static const uint8_t bit_reverse_byte [0x100] =\n");
    1.25    printf ("{\n");
    1.26    for (i = 0; i < 0x100; i++)
    1.27 @@ -55,5 +53,69 @@
    1.28  	printf (" ");
    1.29      }
    1.30    printf ("};\n");
    1.31 +}
    1.32 +
    1.33 +
    1.34 +int count_run (int byte, int start_bit, int desired_val)
    1.35 +{
    1.36 +  int count = 0;
    1.37 +  int i;
    1.38 +
    1.39 +  for (i = start_bit; i < 8; i++)
    1.40 +    {
    1.41 +      int bit = (byte >> i) & 1;
    1.42 +      if (bit == desired_val)
    1.43 +	count++;
    1.44 +      else
    1.45 +	break;
    1.46 +    }
    1.47 +  return (count);
    1.48 +}
    1.49 +
    1.50 +
    1.51 +void gen_run_length_table (int val, char *name)
    1.52 +{
    1.53 +  int i, j;
    1.54 +
    1.55 +  printf ("static const uint8_t %s [8][256] =\n", name);
    1.56 +  printf ("{\n");
    1.57 +  for (i = 0; i < 8; i++)
    1.58 +    {
    1.59 +      printf ("  {\n");
    1.60 +      for (j = 0; j < 256; j++)
    1.61 +	{
    1.62 +	  if ((j & 15) == 0)
    1.63 +	    printf ("  ");
    1.64 +	  printf ("%d", count_run (j, i, val));
    1.65 +	  if (j != 0xff)
    1.66 +	    printf (",");
    1.67 +	  if ((j & 15) == 15)
    1.68 +	    printf ("\n");
    1.69 +	  else
    1.70 +	    printf (" ");
    1.71 +	}
    1.72 +      printf ("  }");
    1.73 +      if (i != 7)
    1.74 +	printf (",");
    1.75 +      printf ("\n");
    1.76 +    }
    1.77 +  printf ("};\n");
    1.78 +}
    1.79 +
    1.80 +
    1.81 +int main (int argc, char *argv[])
    1.82 +{
    1.83 +  printf ("/* This file is automatically generated; do not edit */\n");
    1.84 +  printf ("\n");
    1.85 +
    1.86 +  gen_bit_reverse_table ();
    1.87 +  printf ("\n");
    1.88 +
    1.89 +  gen_run_length_table (0, "white_rle_tab");
    1.90 +  printf ("\n");
    1.91 +  gen_run_length_table (1, "black_rle_tab");
    1.92 +  printf ("\n");
    1.93 +
    1.94    return (0);
    1.95  }
    1.96 +