1.1 diff -r 4830f4d7ba7a -r e63762afae80 pdf_g4_table_gen.c 1.2 --- a/pdf_g4_table_gen.c Sat Mar 08 10:02:13 2003 +0000 1.3 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.4 @@ -1,284 +0,0 @@ 1.5 -/* 1.6 - * t2p: Create a PDF file from the contents of one or more TIFF 1.7 - * bilevel image files. The images in the resulting PDF file 1.8 - * will be compressed using ITU-T T.6 (G4) fax encoding. 1.9 - * 1.10 - * G4 table generator 1.11 - * $Id: pdf_g4_table_gen.c,v 1.2 2003/03/05 12:44:33 eric Exp $ 1.12 - * Copyright 2003 Eric Smith <eric@brouhaha.com> 1.13 - * 1.14 - * This program is free software; you can redistribute it and/or modify 1.15 - * it under the terms of the GNU General Public License version 2 as 1.16 - * published by the Free Software Foundation. Note that permission is 1.17 - * not granted to redistribute this program under the terms of any 1.18 - * other version of the General Public License. 1.19 - * 1.20 - * This program is distributed in the hope that it will be useful, 1.21 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.22 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.23 - * GNU General Public License for more details. 1.24 - * 1.25 - * You should have received a copy of the GNU General Public License 1.26 - * along with this program; if not, write to the Free Software 1.27 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 1.28 - */ 1.29 - 1.30 - 1.31 -#include <stdbool.h> 1.32 -#include <stdint.h> 1.33 -#include <stdio.h> 1.34 -#include <stdlib.h> 1.35 -#include <string.h> 1.36 - 1.37 - 1.38 -void emit_code (int indent, char *code, int last, bool comment, int cval) 1.39 -{ 1.40 - int i; 1.41 - int count = 0; 1.42 - uint32_t val = 0; 1.43 - 1.44 - printf ("%*s{ ", indent, ""); 1.45 - 1.46 - printf ("%d, ", strlen (code)); 1.47 - 1.48 - for (i = 0; i < strlen (code); i++) 1.49 - switch (code [i]) 1.50 - { 1.51 - case '0': val = (val << 1); count++; break; 1.52 - case '1': val = (val << 1) + 1; count++; break; 1.53 - case ' ': break; 1.54 - default: 1.55 - fprintf (stderr, "internal error\n"); 1.56 - exit (2); 1.57 - } 1.58 - 1.59 - printf ("0x%0*x", (count + 3)/4, val); 1.60 - 1.61 - printf (" }"); 1.62 - if (! last) 1.63 - printf (","); 1.64 - if (comment) 1.65 - printf (" /* %d */", cval); 1.66 - printf ("\n"); 1.67 -} 1.68 - 1.69 - 1.70 -char *long_makeup_code [12] = 1.71 - { 1.72 - /* 1792 */ "00000001000", 1.73 - /* 1856 */ "00000001100", 1.74 - /* 1920 */ "00000001101", 1.75 - /* 1984 */ "000000010010", 1.76 - /* 2048 */ "000000010011", 1.77 - /* 2112 */ "000000010100", 1.78 - /* 2176 */ "000000010101", 1.79 - /* 2240 */ "000000010110", 1.80 - /* 2304 */ "000000010111", 1.81 - /* 2368 */ "000000011100", 1.82 - /* 2432 */ "000000011101", 1.83 - /* 2496 */ "000000011110" 1.84 - /* 2560 "000000011111" hard-coded, doesn't need to be in table */ 1.85 - }; 1.86 - 1.87 - 1.88 -void print_long_makeup_code (void) 1.89 -{ 1.90 - int i; 1.91 - 1.92 - printf ("static g4_bits g4_long_makeup_code [12] =\n"); 1.93 - printf (" {\n"); 1.94 - for (i = 0; i < 12; i++) 1.95 - emit_code (4, long_makeup_code [i], i == 11, 1, i * 64 + 1792); 1.96 - printf (" };\n"); 1.97 -} 1.98 - 1.99 - 1.100 -char *makeup_code [64][2] = 1.101 - { 1.102 - { /* 64 */ "11011", "0000001111" }, 1.103 - { /* 128 */ "10010", "000011001000" }, 1.104 - { /* 192 */ "010111", "000011001001" }, 1.105 - { /* 256 */ "0110111", "000001011011" }, 1.106 - { /* 320 */ "00110110", "000000110011" }, 1.107 - { /* 384 */ "00110111", "000000110100" }, 1.108 - { /* 448 */ "01100100", "000000110101" }, 1.109 - { /* 512 */ "01100101", "0000001101100" }, 1.110 - { /* 576 */ "01101000", "0000001101101" }, 1.111 - { /* 640 */ "01100111", "0000001001010" }, 1.112 - { /* 704 */ "011001100", "0000001001011" }, 1.113 - { /* 768 */ "011001101", "0000001001100" }, 1.114 - { /* 832 */ "011010010", "0000001001101" }, 1.115 - { /* 896 */ "011010011", "0000001110010" }, 1.116 - { /* 960 */ "011010100", "0000001110011" }, 1.117 - { /* 1024 */ "011010101", "0000001110100" }, 1.118 - { /* 1088 */ "011010110", "0000001110101" }, 1.119 - { /* 1152 */ "011010111", "0000001110110" }, 1.120 - { /* 1216 */ "011011000", "0000001110111" }, 1.121 - { /* 1280 */ "011011001", "0000001010010" }, 1.122 - { /* 1344 */ "011011010", "0000001010011" }, 1.123 - { /* 1408 */ "011011011", "0000001010100" }, 1.124 - { /* 1472 */ "010011000", "0000001010101" }, 1.125 - { /* 1536 */ "010011001", "0000001011010" }, 1.126 - { /* 1600 */ "010011010", "0000001011011" }, 1.127 - { /* 1664 */ "011000", "0000001100100" }, 1.128 - { /* 1728 */ "010011011", "0000001100101" } 1.129 - }; 1.130 - 1.131 - 1.132 -void print_makeup_code (void) 1.133 -{ 1.134 - int i; 1.135 - 1.136 - printf ("static g4_bits g4_makeup_code [2] [27] =\n"); 1.137 - printf (" {\n"); 1.138 - printf (" {\n"); 1.139 - printf (" /* white */\n"); 1.140 - for (i = 0; i <= 26; i++) 1.141 - emit_code (6, makeup_code [i][0], i == 26, 1, (i + 1) * 64); 1.142 - printf (" },\n"); 1.143 - printf (" {\n"); 1.144 - printf (" /* black */\n"); 1.145 - for (i = 0; i <= 26; i++) 1.146 - emit_code (6, makeup_code [i][1], i == 26, 1, (i + 1) * 64); 1.147 - printf (" }\n"); 1.148 - printf (" };\n"); 1.149 -} 1.150 - 1.151 - 1.152 -char *h_code [64][2] = 1.153 - { 1.154 - { /* 0 */ "00110101", "0000110111" }, 1.155 - { /* 1 */ "000111", "010" }, 1.156 - { /* 2 */ "0111", "11" }, 1.157 - { /* 3 */ "1000", "10" }, 1.158 - { /* 4 */ "1011", "011" }, 1.159 - { /* 5 */ "1100", "0011" }, 1.160 - { /* 6 */ "1110", "0010" }, 1.161 - { /* 7 */ "1111", "00011" }, 1.162 - { /* 8 */ "10011", "000101" }, 1.163 - { /* 9 */ "10100", "000100" }, 1.164 - { /* 10 */ "00111", "0000100" }, 1.165 - { /* 11 */ "01000", "0000101" }, 1.166 - { /* 12 */ "001000", "0000111" }, 1.167 - { /* 13 */ "000011", "00000100" }, 1.168 - { /* 14 */ "110100", "00000111" }, 1.169 - { /* 15 */ "110101", "000011000" }, 1.170 - { /* 16 */ "101010", "0000010111" }, 1.171 - { /* 17 */ "101011", "0000011000" }, 1.172 - { /* 18 */ "0100111", "0000001000" }, 1.173 - { /* 19 */ "0001100", "00001100111" }, 1.174 - { /* 20 */ "0001000", "00001101000" }, 1.175 - { /* 21 */ "0010111", "00001101100" }, 1.176 - { /* 22 */ "0000011", "00000110111" }, 1.177 - { /* 23 */ "0000100", "00000101000" }, 1.178 - { /* 24 */ "0101000", "00000010111" }, 1.179 - { /* 25 */ "0101011", "00000011000" }, 1.180 - { /* 26 */ "0010011", "000011001010" }, 1.181 - { /* 27 */ "0100100", "000011001011" }, 1.182 - { /* 28 */ "0011000", "000011001100" }, 1.183 - { /* 29 */ "00000010", "000011001101" }, 1.184 - { /* 30 */ "00000011", "000001101000" }, 1.185 - { /* 31 */ "00011010", "000001101001" }, 1.186 - { /* 32 */ "00011011", "000001101010" }, 1.187 - { /* 33 */ "00010010", "000001101011" }, 1.188 - { /* 34 */ "00010011", "000011010010" }, 1.189 - { /* 35 */ "00010100", "000011010011" }, 1.190 - { /* 36 */ "00010101", "000011010100" }, 1.191 - { /* 37 */ "00010110", "000011010101" }, 1.192 - { /* 38 */ "00010111", "000011010110" }, 1.193 - { /* 39 */ "00101000", "000011010111" }, 1.194 - { /* 40 */ "00101001", "000001101100" }, 1.195 - { /* 41 */ "00101010", "000001101101" }, 1.196 - { /* 42 */ "00101011", "000011011010" }, 1.197 - { /* 43 */ "00101100", "000011011011" }, 1.198 - { /* 44 */ "00101101", "000001010100" }, 1.199 - { /* 45 */ "00000100", "000001010101" }, 1.200 - { /* 46 */ "00000101", "000001010110" }, 1.201 - { /* 47 */ "00001010", "000001010111" }, 1.202 - { /* 48 */ "00001011", "000001100100" }, 1.203 - { /* 49 */ "01010010", "000001100101" }, 1.204 - { /* 50 */ "01010011", "000001010010" }, 1.205 - { /* 51 */ "01010100", "000001010011" }, 1.206 - { /* 52 */ "01010101", "000000100100" }, 1.207 - { /* 53 */ "00100100", "000000110111" }, 1.208 - { /* 54 */ "00100101", "000000111000" }, 1.209 - { /* 55 */ "01011000", "000000100111" }, 1.210 - { /* 56 */ "01011001", "000000101000" }, 1.211 - { /* 57 */ "01011010", "000001011000" }, 1.212 - { /* 58 */ "01011011", "000001011001" }, 1.213 - { /* 59 */ "01001010", "000000101011" }, 1.214 - { /* 60 */ "01001011", "000000101100" }, 1.215 - { /* 61 */ "00110010", "000001011010" }, 1.216 - { /* 62 */ "00110011", "000001100110" }, 1.217 - { /* 63 */ "00110100", "000001100111" } 1.218 - }; 1.219 - 1.220 - 1.221 -void print_h_code (void) 1.222 -{ 1.223 - int i; 1.224 - 1.225 - printf ("static g4_bits g4_h_code [2] [64] =\n"); 1.226 - printf (" {\n"); 1.227 - printf (" {\n"); 1.228 - printf (" /* white */\n"); 1.229 - for (i = 0; i <= 63; i++) 1.230 - emit_code (6, h_code [i][0], i == 63, 1, i); 1.231 - printf (" },\n"); 1.232 - printf (" {\n"); 1.233 - printf (" /* black */\n"); 1.234 - for (i = 0; i <= 63; i++) 1.235 - emit_code (6, h_code [i][1], i == 63, 1, i); 1.236 - printf (" }\n"); 1.237 - printf (" };\n"); 1.238 -} 1.239 - 1.240 - 1.241 -char *v_code [7] = 1.242 - { 1.243 - /* -3 */ "0000010", 1.244 - /* -2 */ "000010", 1.245 - /* -1 */ "010", 1.246 - /* 0 */ "1", 1.247 - /* 1 */ "011", 1.248 - /* 2 */ "000011", 1.249 - /* 3 */ "0000011" 1.250 - }; 1.251 - 1.252 - 1.253 -void print_v_code (void) 1.254 -{ 1.255 - int i; 1.256 - 1.257 - printf ("static g4_bits g4_vert_code [7] =\n"); 1.258 - printf (" {\n"); 1.259 - for (i = 0; i <= 6; i++) 1.260 - emit_code (4, v_code [i], i == 6, 1, i - 3); 1.261 - printf (" };\n"); 1.262 -} 1.263 - 1.264 - 1.265 -int main (int argc, char *argv []) 1.266 -{ 1.267 - printf ("/* This file is automatically generated; do not edit */\n"); 1.268 - printf ("\n"); 1.269 - printf ("typedef struct\n"); 1.270 - printf ("{\n"); 1.271 - printf (" uint32_t count;\n"); 1.272 - printf (" uint32_t bits;\n"); 1.273 - printf ("} g4_bits;\n"); 1.274 - printf ("\n"); 1.275 - 1.276 - print_long_makeup_code (); 1.277 - printf ("\n"); 1.278 - 1.279 - print_makeup_code (); 1.280 - printf ("\n"); 1.281 - 1.282 - print_h_code (); 1.283 - printf ("\n"); 1.284 - 1.285 - print_v_code (); 1.286 - 1.287 - exit (0); 1.288 -}