bitblt_table_gen.c

Wed, 12 Mar 2003 06:39:22 +0000

author
eric
date
Wed, 12 Mar 2003 06:39:22 +0000
changeset 97
f2e13c2ff575
parent 78
74b6b230f85d
child 98
5fb9b9f7c2b8
permissions
-rw-r--r--

changed bitblt_table_gen.c to generate both a header and a C source file (bitblt_tables.[ch]).

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