bitblt_table_gen.c

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

author
eric
date
Wed, 19 Feb 2003 10:34:35 +0000
changeset 56
425e8c46d318
parent 53
bb180150e603
child 58
d1c6dc4bf34a
permissions
-rw-r--r--

added code to generate RLE tables.

eric@53 1 /*
eric@53 2 * t2p: Create a PDF file from the contents of one or more TIFF
eric@53 3 * bilevel image files. The images in the resulting PDF file
eric@53 4 * will be compressed using ITU-T T.6 (G4) fax encoding.
eric@53 5 *
eric@53 6 * bitblt table generator
eric@56 7 * $Id: bitblt_table_gen.c,v 1.2 2003/02/19 02:34:35 eric Exp $
eric@53 8 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
eric@53 9 *
eric@53 10 * This program is free software; you can redistribute it and/or modify
eric@53 11 * it under the terms of the GNU General Public License version 2 as
eric@53 12 * published by the Free Software Foundation. Note that permission is
eric@53 13 * not granted to redistribute this program under the terms of any
eric@53 14 * other version of the General Public License.
eric@53 15 *
eric@53 16 * This program is distributed in the hope that it will be useful,
eric@53 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
eric@53 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eric@53 19 * GNU General Public License for more details.
eric@53 20 *
eric@53 21 * You should have received a copy of the GNU General Public License
eric@53 22 * along with this program; if not, write to the Free Software
eric@53 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
eric@53 24 */
eric@53 25
eric@53 26
eric@53 27 #include <stdio.h>
eric@53 28
eric@56 29 void gen_bit_reverse_table (void)
eric@53 30 {
eric@53 31 int i, j;
eric@53 32
eric@53 33 printf ("static const uint8_t bit_reverse_byte [0x100] =\n");
eric@53 34 printf ("{\n");
eric@53 35 for (i = 0; i < 0x100; i++)
eric@53 36 {
eric@53 37 if ((i & 7) == 0)
eric@53 38 printf (" ");
eric@53 39 j = (((i & 0x01) << 7) |
eric@53 40 ((i & 0x02) << 5) |
eric@53 41 ((i & 0x04) << 3) |
eric@53 42 ((i & 0x08) << 1) |
eric@53 43 ((i & 0x10) >> 1) |
eric@53 44 ((i & 0x20) >> 3) |
eric@53 45 ((i & 0x40) >> 5) |
eric@53 46 ((i & 0x80) >> 7));
eric@53 47 printf ("0x%02x", j);
eric@53 48 if (i != 0xff)
eric@53 49 printf (",");
eric@53 50 if ((i & 7) == 7)
eric@53 51 printf ("\n");
eric@53 52 else
eric@53 53 printf (" ");
eric@53 54 }
eric@53 55 printf ("};\n");
eric@56 56 }
eric@56 57
eric@56 58
eric@56 59 int count_run (int byte, int start_bit, int desired_val)
eric@56 60 {
eric@56 61 int count = 0;
eric@56 62 int i;
eric@56 63
eric@56 64 for (i = start_bit; i < 8; i++)
eric@56 65 {
eric@56 66 int bit = (byte >> i) & 1;
eric@56 67 if (bit == desired_val)
eric@56 68 count++;
eric@56 69 else
eric@56 70 break;
eric@56 71 }
eric@56 72 return (count);
eric@56 73 }
eric@56 74
eric@56 75
eric@56 76 void gen_run_length_table (int val, char *name)
eric@56 77 {
eric@56 78 int i, j;
eric@56 79
eric@56 80 printf ("static const uint8_t %s [8][256] =\n", name);
eric@56 81 printf ("{\n");
eric@56 82 for (i = 0; i < 8; i++)
eric@56 83 {
eric@56 84 printf (" {\n");
eric@56 85 for (j = 0; j < 256; j++)
eric@56 86 {
eric@56 87 if ((j & 15) == 0)
eric@56 88 printf (" ");
eric@56 89 printf ("%d", count_run (j, i, val));
eric@56 90 if (j != 0xff)
eric@56 91 printf (",");
eric@56 92 if ((j & 15) == 15)
eric@56 93 printf ("\n");
eric@56 94 else
eric@56 95 printf (" ");
eric@56 96 }
eric@56 97 printf (" }");
eric@56 98 if (i != 7)
eric@56 99 printf (",");
eric@56 100 printf ("\n");
eric@56 101 }
eric@56 102 printf ("};\n");
eric@56 103 }
eric@56 104
eric@56 105
eric@56 106 int main (int argc, char *argv[])
eric@56 107 {
eric@56 108 printf ("/* This file is automatically generated; do not edit */\n");
eric@56 109 printf ("\n");
eric@56 110
eric@56 111 gen_bit_reverse_table ();
eric@56 112 printf ("\n");
eric@56 113
eric@56 114 gen_run_length_table (0, "white_rle_tab");
eric@56 115 printf ("\n");
eric@56 116 gen_run_length_table (1, "black_rle_tab");
eric@56 117 printf ("\n");
eric@56 118
eric@53 119 return (0);
eric@53 120 }
eric@56 121