diff options
Diffstat (limited to 'converter/other/fiasco/output/tree.c')
-rw-r--r-- | converter/other/fiasco/output/tree.c | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/converter/other/fiasco/output/tree.c b/converter/other/fiasco/output/tree.c index 55080a51..02afec50 100644 --- a/converter/other/fiasco/output/tree.c +++ b/converter/other/fiasco/output/tree.c @@ -1,7 +1,7 @@ /* - * tree.c: Output of bintree partitioning + * tree.c: Output of bintree partitioning * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -29,17 +29,17 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void encode_tree (bitfile_t *output, const byte_t *data, unsigned n_data, - unsigned scaling, u_word_t sum0, u_word_t sum1); + unsigned scaling, u_word_t sum0, u_word_t sum1); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -53,13 +53,13 @@ write_tree (const wfa_t *wfa, bitfile_t *output) * No return value. */ { - unsigned queue [MAXSTATES]; /* state numbers in BFO */ - unsigned current; /* current node to process */ - unsigned last; /* last node (update every new node) */ - unsigned label; /* current label */ - int into; /* next child */ - byte_t *tree_string; /* bitstring to encode */ - unsigned total = 0; /* number of ranges */ + unsigned queue [MAXSTATES]; /* state numbers in BFO */ + unsigned current; /* current node to process */ + unsigned last; /* last node (update every new node) */ + unsigned label; /* current label */ + int into; /* next child */ + byte_t *tree_string; /* bitstring to encode */ + unsigned total = 0; /* number of ranges */ unsigned bits = bits_processed (output); /* number of bits */ /* @@ -72,17 +72,17 @@ write_tree (const wfa_t *wfa, bitfile_t *output) queue [0] = wfa->root_state; for (last = 1, current = 0; current < last; current++) for (label = 0; label < MAXLABELS; label++) - if (!isrange (into = wfa->tree [queue[current]][label])) /* child ? */ - { - queue [last++] = into; - tree_string [total++] = 1; - } - else /* or range ? */ - tree_string [total++] = 0; + if (!isrange (into = wfa->tree [queue[current]][label])) /* child ? */ + { + queue [last++] = into; + tree_string [total++] = 1; + } + else /* or range ? */ + tree_string [total++] = 0; if (total != (wfa->states - wfa->basis_states) * MAXLABELS) error ("total [%d] != (states - basis_states) * 2 [%d]", total, - (wfa->states - wfa->basis_states) * MAXLABELS); + (wfa->states - wfa->basis_states) * MAXLABELS); { unsigned scale = total / 20 ; @@ -93,20 +93,20 @@ write_tree (const wfa_t *wfa, bitfile_t *output) Free (tree_string); debug_message ("tree: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total, - total > 0 ? ((bits_processed (output) - bits) - / (double) total) : 0); + bits_processed (output) - bits, total, + total > 0 ? ((bits_processed (output) - bits) + / (double) total) : 0); } /***************************************************************************** - private code + private code *****************************************************************************/ static void encode_tree (bitfile_t *output, const byte_t *data, unsigned n_data, - unsigned scaling, u_word_t sum0, u_word_t sum1) + unsigned scaling, u_word_t sum0, u_word_t sum1) /* * Encode bintree data with adaptive binary arithmetic coding. * Write 'n_data' output symbols stored in 'data' to stream 'output'. @@ -116,10 +116,10 @@ encode_tree (bitfile_t *output, const byte_t *data, unsigned n_data, * No return value. */ { - u_word_t low; /* Start of the current code range */ - u_word_t high; /* End of the current code range */ - u_word_t underflow; /* Number of underflow bits pending */ - unsigned n; /* Data counter */ + u_word_t low; /* Start of the current code range */ + u_word_t high; /* End of the current code range */ + u_word_t underflow; /* Number of underflow bits pending */ + unsigned n; /* Data counter */ low = 0; high = 0xffff; @@ -127,29 +127,29 @@ encode_tree (bitfile_t *output, const byte_t *data, unsigned n_data, for (n = n_data; n; n--) { - unsigned range; /* Current interval range */ + unsigned range; /* Current interval range */ if (!*data++) { - /* - * encode a '0' - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum0) / sum1 - 1); + /* + * encode a '0' + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum0) / sum1 - 1); - RESCALE_OUTPUT_INTERVAL; + RESCALE_OUTPUT_INTERVAL; - sum0++; + sum0++; } else { - /* - * encode a '1' - */ - range = (high - low) + 1; - low = low + (u_word_t) ((range * sum0) / sum1); + /* + * encode a '1' + */ + range = (high - low) + 1; + low = low + (u_word_t) ((range * sum0) / sum1); - RESCALE_OUTPUT_INTERVAL; + RESCALE_OUTPUT_INTERVAL; } /* * Update the frequency counts @@ -157,12 +157,12 @@ encode_tree (bitfile_t *output, const byte_t *data, unsigned n_data, sum1++; if (sum1 > scaling) /* Scale the symbol frequencies */ { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; } } /* |