Mon, 14 Dec 2009 16:18:21 +0000
remove erroneous 0.33-philpem1 tag
1 /*
2 * tumble: build a PDF file from image files
3 *
4 * bitblt table generator
5 * $Id: bitblt_table_gen.c,v 1.8 2003/08/18 01:59:41 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 #ifdef WORDS_BIGENDIAN
75 for (i = 7 - start_bit; i >= 0; i--)
76 {
77 int bit = (byte >> i) & 1;
78 if (bit == desired_val)
79 count++;
80 else
81 break;
82 }
83 #else
84 for (i = start_bit; i < 8; i++)
85 {
86 int bit = (byte >> i) & 1;
87 if (bit == desired_val)
88 count++;
89 else
90 break;
91 }
92 #endif
94 return (count);
95 }
98 void gen_run_length_table (bool header, int val, char *name)
99 {
100 int i, j;
102 if (header)
103 printf ("extern ");
104 printf ("const uint8_t %s [8][256]", name);
105 if (header)
106 {
107 printf (";\n");
108 return;
109 }
110 printf (" =\n");
111 printf ("{\n");
112 for (i = 0; i < 8; i++)
113 {
114 printf (" {\n");
115 for (j = 0; j < 256; j++)
116 {
117 if ((j & 15) == 0)
118 printf (" ");
119 printf ("%d", count_run (j, i, val));
120 if (j != 0xff)
121 printf (",");
122 if ((j & 15) == 15)
123 printf ("\n");
124 else
125 printf (" ");
126 }
127 printf (" }");
128 if (i != 7)
129 printf (",");
130 printf ("\n");
131 }
132 printf ("};\n");
133 }
136 int main (int argc, char *argv[])
137 {
138 bool header;
140 if (argc != 2)
141 {
142 fprintf (stderr, "wrong arg count\n");
143 exit (2);
144 }
145 if (strcmp (argv [1], "-h") == 0)
146 header = 1;
147 else if (strcmp (argv [1], "-c") == 0)
148 header = 0;
149 else
150 {
151 fprintf (stderr, "wrong args\n");
152 exit (2);
153 }
155 printf ("/* This file is automatically generated; do not edit */\n");
156 printf ("\n");
158 if (! header)
159 {
160 printf ("#include <stdint.h>\n");
161 printf ("#include \"bitblt_tables.h\"\n");
162 printf ("\n");
163 }
165 gen_bit_reverse_table (header);
166 printf ("\n");
168 gen_run_length_table (header, 0, "rle_tab");
169 printf ("\n");
171 return (0);
172 }