bitblt_table_gen.c

Wed, 12 Mar 2003 07:53:55 +0000

author
eric
date
Wed, 12 Mar 2003 07:53:55 +0000
changeset 102
f6c042f4dadb
parent 98
5fb9b9f7c2b8
child 125
e2ef1c2f9eca
permissions
-rw-r--r--

made callback functions static.

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