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