From 05dea4441dbcc2ff8e371fa52ba238344728e8b3 Mon Sep 17 00:00:00 2001 From: Rupert Date: Sun, 3 Nov 2024 21:52:49 +0100 Subject: [PATCH] auto-generation: small fixes * found one last error in huffman makeup codes * use smaller types (short/char) to reduce table size * small fixes, formatting --- gen-huffman-codes.h | 4 ++-- gen-huffman.c | 54 ++++++++++++++++++++++++++------------------- gen-reversebits.c | 40 ++++++++++++++++----------------- huffman.c | 11 +-------- 4 files changed, 54 insertions(+), 55 deletions(-) diff --git a/gen-huffman-codes.h b/gen-huffman-codes.h index 7410984..1bc4eb8 100644 --- a/gen-huffman-codes.h +++ b/gen-huffman-codes.h @@ -189,7 +189,7 @@ static struct Huffcode huff_makeup_white[] = { { 64, "11011" }, { 1984, "000000010010" }, { 2048, "000000010011" }, { 2112, "000000010100" }, - { 2170, "000000010101" }, + { 2176, "000000010101" }, { 2240, "000000010110" }, { 2304, "000000010111" }, { 2368, "000000011100" }, @@ -231,7 +231,7 @@ static struct Huffcode huff_makeup_black[] = { { 64, "0000001111" }, { 1984, "000000010010" }, { 2048, "000000010011" }, { 2112, "000000010100" }, - { 2170, "000000010101" }, + { 2176, "000000010101" }, { 2240, "000000010110" }, { 2304, "000000010111" }, { 2368, "000000011100" }, diff --git a/gen-huffman.c b/gen-huffman.c index 93b204c..f5884f5 100644 --- a/gen-huffman.c +++ b/gen-huffman.c @@ -71,35 +71,43 @@ int main(int argc, char *argv[]) s_buildtree(); fprintf(file, "/* bmplib - %s\n" - " *\n" - " * Copyright (c) 2024, Rupert Weber.\n" - " *\n" - " * This file is part of bmplib.\n" - " * bmplib is free software: you can redistribute it and/or modify\n" - " * it under the terms of the GNU Lesser General Public License as\n" - " * published by the Free Software Foundation, either version 3 of\n" - " * the License, or (at your option) any later version.\n" - " *\n" - " * This program is distributed in the hope that it will be useful,\n" - " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - " * GNU Lesser General Public License for more details.\n" - " *\n" - " * You should have received a copy of the GNU Lesser General Public\n" - " * License along with this library.\n" - " * If not, see \n" - " */\n\n" - "/* This file is auto-generated by %s */\n\n\n", + " *\n" + " * Copyright (c) 2024, Rupert Weber.\n" + " *\n" + " * This file is part of bmplib.\n" + " * bmplib is free software: you can redistribute it and/or modify\n" + " * it under the terms of the GNU Lesser General Public License as\n" + " * published by the Free Software Foundation, either version 3 of\n" + " * the License, or (at your option) any later version.\n" + " *\n" + " * This program is distributed in the hope that it will be useful,\n" + " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + " * GNU Lesser General Public License for more details.\n" + " *\n" + " * You should have received a copy of the GNU Lesser General Public\n" + " * License along with this library.\n" + " * If not, see \n" + " */\n\n" + "/* This file is auto-generated by %s */\n\n\n", src_name, this_name); - fprintf(file, "static int blackroot = %d;\n", black_tree); - fprintf(file, "static int whiteroot = %d;\n\n\n", white_tree); - fprintf(file, "static struct Node nodebuffer[] = {\n"); + fputs("struct Node {\n" + "\tsigned short l;\n" + "\tsigned short r;\n" + "\tshort value;\n" + "\tchar terminal;\n" + "\tchar makeup;\n" + "};\n\n", file); + + fprintf(file, "static const int blackroot = %d;\n", black_tree); + fprintf(file, "static const int whiteroot = %d;\n\n\n", white_tree); + fprintf(file, "static const struct Node nodebuffer[] = {\n"); for (i = 0; i < ARR_SIZE(nodebuffer); i++) { fprintf(file, "\t{ %3d, %3d, %4d, %d, %d },\n", n[i].l, n[i].r, n[i].value, n[i].terminal, n[i].makeup); } - fprintf(file, "};\n"); + fputs("};\n", file); return 0; } diff --git a/gen-reversebits.c b/gen-reversebits.c index 6c1cfb8..419473a 100644 --- a/gen-reversebits.c +++ b/gen-reversebits.c @@ -53,28 +53,28 @@ int main(int argc, char *argv[]) } fprintf(file, "/* bmplib - %s\n" - " *\n" - " * Copyright (c) 2024, Rupert Weber.\n" - " *\n" - " * This file is part of bmplib.\n" - " * bmplib is free software: you can redistribute it and/or modify\n" - " * it under the terms of the GNU Lesser General Public License as\n" - " * published by the Free Software Foundation, either version 3 of\n" - " * the License, or (at your option) any later version.\n" - " *\n" - " * This program is distributed in the hope that it will be useful,\n" - " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - " * GNU Lesser General Public License for more details.\n" - " *\n" - " * You should have received a copy of the GNU Lesser General Public\n" - " * License along with this library.\n" - " * If not, see \n" - " */\n\n" - "/* This file is auto-generated by %s */\n\n\n", + " *\n" + " * Copyright (c) 2024, Rupert Weber.\n" + " *\n" + " * This file is part of bmplib.\n" + " * bmplib is free software: you can redistribute it and/or modify\n" + " * it under the terms of the GNU Lesser General Public License as\n" + " * published by the Free Software Foundation, either version 3 of\n" + " * the License, or (at your option) any later version.\n" + " *\n" + " * This program is distributed in the hope that it will be useful,\n" + " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + " * GNU Lesser General Public License for more details.\n" + " *\n" + " * You should have received a copy of the GNU Lesser General Public\n" + " * License along with this library.\n" + " * If not, see \n" + " */\n\n" + "/* This file is auto-generated by %s */\n\n\n", src_name, this_name); - fprintf(file, "static const int reversebits[] = {\n\t"); + fprintf(file, "static const unsigned char reversebits[] = {\n\t"); for (int i = 0; i < 256; i++) { reversed = reverse(i, 8); fprintf(file, "0x%02x, ", reversed); diff --git a/huffman.c b/huffman.c index a62e26f..5113756 100644 --- a/huffman.c +++ b/huffman.c @@ -31,18 +31,9 @@ #include "bmp-common.h" #include "reversebits.h" #include "huffman.h" +#include "huffman-codes.h" -struct Node { - int l; - int r; - int value; - int terminal; - int makeup; -}; - -#include "huffman-codes.h" /* auto-generated by huffman-gen-codes.c */ - static int s_findnode(uint32_t bits, int nbits, int black, int *found);