Wed, 12 Mar 2003 10:59:29 +0000
optimized g4_find_pixel().
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.6 2003/03/11 22:40:34 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 <stdbool.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
33 void gen_bit_reverse_table (bool header)
34 {
35 int i, j;
37 if (header)
38 printf ("extern ");
39 printf ("const uint8_t bit_reverse_byte [0x100]");
40 if (header)
41 {
42 printf (";\n");
43 return;
44 }
45 printf (" =\n");
46 printf ("{\n");
47 for (i = 0; i < 0x100; i++)
48 {
49 if ((i & 7) == 0)
50 printf (" ");
51 j = (((i & 0x01) << 7) |
52 ((i & 0x02) << 5) |
53 ((i & 0x04) << 3) |
54 ((i & 0x08) << 1) |
55 ((i & 0x10) >> 1) |
56 ((i & 0x20) >> 3) |
57 ((i & 0x40) >> 5) |
58 ((i & 0x80) >> 7));
59 printf ("0x%02x", j);
60 if (i != 0xff)
61 printf (",");
62 if ((i & 7) == 7)
63 printf ("\n");
64 else
65 printf (" ");
66 }
67 printf ("};\n");
68 }
71 int count_run (int byte, int start_bit, int desired_val)
72 {
73 int count = 0;
74 int i;
76 for (i = start_bit; i < 8; i++)
77 {
78 int bit = (byte >> i) & 1;
79 if (bit == desired_val)
80 count++;
81 else
82 break;
83 }
84 return (count);
85 }
88 void gen_run_length_table (bool header, int val, char *name)
89 {
90 int i, j;
92 if (header)
93 printf ("extern ");
94 printf ("const uint8_t %s [8][256]", name);
95 if (header)
96 {
97 printf (";\n");
98 return;
99 }
100 printf (" =\n");
101 printf ("{\n");
102 for (i = 0; i < 8; i++)
103 {
104 printf (" {\n");
105 for (j = 0; j < 256; j++)
106 {
107 if ((j & 15) == 0)
108 printf (" ");
109 printf ("%d", count_run (j, i, val));
110 if (j != 0xff)
111 printf (",");
112 if ((j & 15) == 15)
113 printf ("\n");
114 else
115 printf (" ");
116 }
117 printf (" }");
118 if (i != 7)
119 printf (",");
120 printf ("\n");
121 }
122 printf ("};\n");
123 }
126 int main (int argc, char *argv[])
127 {
128 bool header;
130 if (argc != 2)
131 {
132 fprintf (stderr, "wrong arg count\n");
133 exit (2);
134 }
135 if (strcmp (argv [1], "-h") == 0)
136 header = 1;
137 else if (strcmp (argv [1], "-c") == 0)
138 header = 0;
139 else
140 {
141 fprintf (stderr, "wrong args\n");
142 exit (2);
143 }
145 printf ("/* This file is automatically generated; do not edit */\n");
146 printf ("\n");
148 if (! header)
149 {
150 printf ("#include <stdint.h>\n");
151 printf ("#include \"bitblt_tables.h\"\n");
152 printf ("\n");
153 }
155 gen_bit_reverse_table (header);
156 printf ("\n");
158 gen_run_length_table (header, 0, "rle_tab");
159 printf ("\n");
161 return (0);
162 }