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