Thu, 20 Mar 2003 07:03:29 +0000
no DEBUG in release version.
eric@53 | 1 | /* |
eric@125 | 2 | * tumble: build a PDF file from image files |
eric@53 | 3 | * |
eric@53 | 4 | * bitblt table generator |
eric@125 | 5 | * $Id: bitblt_table_gen.c,v 1.7 2003/03/13 00:57:05 eric Exp $ |
eric@78 | 6 | * Copyright 2003 Eric Smith <eric@brouhaha.com> |
eric@53 | 7 | * |
eric@53 | 8 | * This program is free software; you can redistribute it and/or modify |
eric@53 | 9 | * it under the terms of the GNU General Public License version 2 as |
eric@53 | 10 | * published by the Free Software Foundation. Note that permission is |
eric@53 | 11 | * not granted to redistribute this program under the terms of any |
eric@53 | 12 | * other version of the General Public License. |
eric@53 | 13 | * |
eric@53 | 14 | * This program is distributed in the hope that it will be useful, |
eric@53 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
eric@53 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
eric@53 | 17 | * GNU General Public License for more details. |
eric@53 | 18 | * |
eric@53 | 19 | * You should have received a copy of the GNU General Public License |
eric@53 | 20 | * along with this program; if not, write to the Free Software |
eric@53 | 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA |
eric@53 | 22 | */ |
eric@53 | 23 | |
eric@53 | 24 | |
eric@97 | 25 | #include <stdbool.h> |
eric@53 | 26 | #include <stdio.h> |
eric@97 | 27 | #include <stdlib.h> |
eric@98 | 28 | #include <string.h> |
eric@98 | 29 | |
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 | } |