Tue, 25 Mar 2003 09:38:08 +0000
support both big- and little-endian TIFF files. don't crash in close_input_file() if current_input_handler is NULL.
1 /*
2 * tumble: build a PDF file from image files
3 *
4 * bitblt table generator
5 * $Id: bitblt_table_gen.c,v 1.7 2003/03/13 00:57:05 eric Exp $
6 * Copyright 2003 Eric Smith <eric@brouhaha.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation. Note that permission is
11 * not granted to redistribute this program under the terms of any
12 * other version of the General Public License.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
22 */
25 #include <stdbool.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
31 void gen_bit_reverse_table (bool header)
32 {
33 int i, j;
35 if (header)
36 printf ("extern ");
37 printf ("const uint8_t bit_reverse_byte [0x100]");
38 if (header)
39 {
40 printf (";\n");
41 return;
42 }
43 printf (" =\n");
44 printf ("{\n");
45 for (i = 0; i < 0x100; i++)
46 {
47 if ((i & 7) == 0)
48 printf (" ");
49 j = (((i & 0x01) << 7) |
50 ((i & 0x02) << 5) |
51 ((i & 0x04) << 3) |
52 ((i & 0x08) << 1) |
53 ((i & 0x10) >> 1) |
54 ((i & 0x20) >> 3) |
55 ((i & 0x40) >> 5) |
56 ((i & 0x80) >> 7));
57 printf ("0x%02x", j);
58 if (i != 0xff)
59 printf (",");
60 if ((i & 7) == 7)
61 printf ("\n");
62 else
63 printf (" ");
64 }
65 printf ("};\n");
66 }
69 int count_run (int byte, int start_bit, int desired_val)
70 {
71 int count = 0;
72 int i;
74 for (i = start_bit; i < 8; i++)
75 {
76 int bit = (byte >> i) & 1;
77 if (bit == desired_val)
78 count++;
79 else
80 break;
81 }
82 return (count);
83 }
86 void gen_run_length_table (bool header, int val, char *name)
87 {
88 int i, j;
90 if (header)
91 printf ("extern ");
92 printf ("const uint8_t %s [8][256]", name);
93 if (header)
94 {
95 printf (";\n");
96 return;
97 }
98 printf (" =\n");
99 printf ("{\n");
100 for (i = 0; i < 8; i++)
101 {
102 printf (" {\n");
103 for (j = 0; j < 256; j++)
104 {
105 if ((j & 15) == 0)
106 printf (" ");
107 printf ("%d", count_run (j, i, val));
108 if (j != 0xff)
109 printf (",");
110 if ((j & 15) == 15)
111 printf ("\n");
112 else
113 printf (" ");
114 }
115 printf (" }");
116 if (i != 7)
117 printf (",");
118 printf ("\n");
119 }
120 printf ("};\n");
121 }
124 int main (int argc, char *argv[])
125 {
126 bool header;
128 if (argc != 2)
129 {
130 fprintf (stderr, "wrong arg count\n");
131 exit (2);
132 }
133 if (strcmp (argv [1], "-h") == 0)
134 header = 1;
135 else if (strcmp (argv [1], "-c") == 0)
136 header = 0;
137 else
138 {
139 fprintf (stderr, "wrong args\n");
140 exit (2);
141 }
143 printf ("/* This file is automatically generated; do not edit */\n");
144 printf ("\n");
146 if (! header)
147 {
148 printf ("#include <stdint.h>\n");
149 printf ("#include \"bitblt_tables.h\"\n");
150 printf ("\n");
151 }
153 gen_bit_reverse_table (header);
154 printf ("\n");
156 gen_run_length_table (header, 0, "rle_tab");
157 printf ("\n");
159 return (0);
160 }