Mon, 14 Dec 2009 16:18:21 +0000
remove erroneous 0.33-philpem1 tag
eric@53 | 1 | /* |
eric@125 | 2 | * tumble: build a PDF file from image files |
eric@53 | 3 | * |
eric@53 | 4 | * bitblt table generator |
eric@159 | 5 | * $Id: bitblt_table_gen.c,v 1.8 2003/08/18 01:59:41 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@159 | 74 | #ifdef WORDS_BIGENDIAN |
eric@159 | 75 | for (i = 7 - start_bit; i >= 0; i--) |
eric@159 | 76 | { |
eric@159 | 77 | int bit = (byte >> i) & 1; |
eric@159 | 78 | if (bit == desired_val) |
eric@159 | 79 | count++; |
eric@159 | 80 | else |
eric@159 | 81 | break; |
eric@159 | 82 | } |
eric@159 | 83 | #else |
eric@56 | 84 | for (i = start_bit; i < 8; i++) |
eric@56 | 85 | { |
eric@56 | 86 | int bit = (byte >> i) & 1; |
eric@56 | 87 | if (bit == desired_val) |
eric@56 | 88 | count++; |
eric@56 | 89 | else |
eric@56 | 90 | break; |
eric@56 | 91 | } |
eric@159 | 92 | #endif |
eric@159 | 93 | |
eric@56 | 94 | return (count); |
eric@56 | 95 | } |
eric@56 | 96 | |
eric@56 | 97 | |
eric@97 | 98 | void gen_run_length_table (bool header, int val, char *name) |
eric@56 | 99 | { |
eric@56 | 100 | int i, j; |
eric@56 | 101 | |
eric@97 | 102 | if (header) |
eric@97 | 103 | printf ("extern "); |
eric@97 | 104 | printf ("const uint8_t %s [8][256]", name); |
eric@97 | 105 | if (header) |
eric@97 | 106 | { |
eric@97 | 107 | printf (";\n"); |
eric@97 | 108 | return; |
eric@97 | 109 | } |
eric@97 | 110 | printf (" =\n"); |
eric@56 | 111 | printf ("{\n"); |
eric@56 | 112 | for (i = 0; i < 8; i++) |
eric@56 | 113 | { |
eric@56 | 114 | printf (" {\n"); |
eric@56 | 115 | for (j = 0; j < 256; j++) |
eric@56 | 116 | { |
eric@56 | 117 | if ((j & 15) == 0) |
eric@56 | 118 | printf (" "); |
eric@56 | 119 | printf ("%d", count_run (j, i, val)); |
eric@56 | 120 | if (j != 0xff) |
eric@56 | 121 | printf (","); |
eric@56 | 122 | if ((j & 15) == 15) |
eric@56 | 123 | printf ("\n"); |
eric@56 | 124 | else |
eric@56 | 125 | printf (" "); |
eric@56 | 126 | } |
eric@56 | 127 | printf (" }"); |
eric@56 | 128 | if (i != 7) |
eric@56 | 129 | printf (","); |
eric@56 | 130 | printf ("\n"); |
eric@56 | 131 | } |
eric@56 | 132 | printf ("};\n"); |
eric@56 | 133 | } |
eric@56 | 134 | |
eric@56 | 135 | |
eric@56 | 136 | int main (int argc, char *argv[]) |
eric@56 | 137 | { |
eric@97 | 138 | bool header; |
eric@97 | 139 | |
eric@97 | 140 | if (argc != 2) |
eric@97 | 141 | { |
eric@97 | 142 | fprintf (stderr, "wrong arg count\n"); |
eric@97 | 143 | exit (2); |
eric@97 | 144 | } |
eric@97 | 145 | if (strcmp (argv [1], "-h") == 0) |
eric@97 | 146 | header = 1; |
eric@97 | 147 | else if (strcmp (argv [1], "-c") == 0) |
eric@97 | 148 | header = 0; |
eric@97 | 149 | else |
eric@97 | 150 | { |
eric@97 | 151 | fprintf (stderr, "wrong args\n"); |
eric@97 | 152 | exit (2); |
eric@97 | 153 | } |
eric@97 | 154 | |
eric@56 | 155 | printf ("/* This file is automatically generated; do not edit */\n"); |
eric@56 | 156 | printf ("\n"); |
eric@56 | 157 | |
eric@97 | 158 | if (! header) |
eric@97 | 159 | { |
eric@97 | 160 | printf ("#include <stdint.h>\n"); |
eric@97 | 161 | printf ("#include \"bitblt_tables.h\"\n"); |
eric@97 | 162 | printf ("\n"); |
eric@97 | 163 | } |
eric@97 | 164 | |
eric@97 | 165 | gen_bit_reverse_table (header); |
eric@56 | 166 | printf ("\n"); |
eric@56 | 167 | |
eric@97 | 168 | gen_run_length_table (header, 0, "rle_tab"); |
eric@56 | 169 | printf ("\n"); |
eric@56 | 170 | |
eric@53 | 171 | return (0); |
eric@53 | 172 | } |