diff options
Diffstat (limited to 'converter/other/fiasco/input')
-rw-r--r-- | converter/other/fiasco/input/basis.c | 88 | ||||
-rw-r--r-- | converter/other/fiasco/input/basis.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/input/matrices.c | 636 | ||||
-rw-r--r-- | converter/other/fiasco/input/matrices.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/input/mc.c | 226 | ||||
-rw-r--r-- | converter/other/fiasco/input/mc.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/input/nd.c | 194 | ||||
-rw-r--r-- | converter/other/fiasco/input/nd.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/input/read.c | 354 | ||||
-rw-r--r-- | converter/other/fiasco/input/read.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/input/tree.c | 224 | ||||
-rw-r--r-- | converter/other/fiasco/input/tree.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/input/weights.c | 16 | ||||
-rw-r--r-- | converter/other/fiasco/input/weights.h | 4 |
14 files changed, 883 insertions, 883 deletions
diff --git a/converter/other/fiasco/input/basis.c b/converter/other/fiasco/input/basis.c index e5ced0d0..4be7f4ed 100644 --- a/converter/other/fiasco/input/basis.c +++ b/converter/other/fiasco/input/basis.c @@ -1,7 +1,7 @@ /* - * basis.c: WFA initial basis files + * basis.c: WFA initial basis files * - * 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 @@ -43,7 +43,7 @@ typedef struct /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -58,7 +58,7 @@ static basis_file_t const basis_files[] = { /***************************************************************************** - public code + public code *****************************************************************************/ @@ -70,69 +70,69 @@ get_linked_basis (const char *basis_name, wfa_t *wfa) * according to the stored data, otherwise print a warning message. * * Return value: - * true on success, false if basis is not available yet. + * true on success, false if basis is not available yet. * * Side effects: - * 'wfa' struct is filled on success. + * 'wfa' struct is filled on success. */ { - bool_t success = NO; /* indicates if basis is found */ - unsigned n; /* counter */ - basis_values_t bv; /* basis values */ + bool_t success = NO; /* indicates if basis is found */ + unsigned n; /* counter */ + basis_values_t bv; /* basis values */ for (n = 0; basis_files [n].filename != NULL; n++) - if (streq (basis_files [n].filename, basis_name)) /* basis is stored */ + if (streq (basis_files [n].filename, basis_name)) /* basis is stored */ { - unsigned state, edge; - - (*basis_files [n].function) (&bv); /* initialize local variables */ - /* - * Generate WFA - */ - wfa->basis_states = wfa->states = bv.states + 1; - wfa->domain_type[0] = USE_DOMAIN_MASK; - wfa->final_distribution[0] = 128; - append_edge (0, 0, 1.0, 0, wfa); - append_edge (0, 0, 1.0, 1, wfa); - for (state = 1; state < wfa->basis_states; state++) - { - wfa->final_distribution [state] = bv.final [state - 1]; - wfa->domain_type [state] = bv.use_domain [state - 1] - ? USE_DOMAIN_MASK - : AUXILIARY_MASK; - } - for (edge = 0; isedge (bv.transitions [edge][0]); edge++) - append_edge (bv.transitions [edge][0], bv.transitions [edge][1], - bv.transitions [edge][2], bv.transitions [edge][3], - wfa); - - success = YES; - break; + unsigned state, edge; + + (*basis_files [n].function) (&bv); /* initialize local variables */ + /* + * Generate WFA + */ + wfa->basis_states = wfa->states = bv.states + 1; + wfa->domain_type[0] = USE_DOMAIN_MASK; + wfa->final_distribution[0] = 128; + append_edge (0, 0, 1.0, 0, wfa); + append_edge (0, 0, 1.0, 1, wfa); + for (state = 1; state < wfa->basis_states; state++) + { + wfa->final_distribution [state] = bv.final [state - 1]; + wfa->domain_type [state] = bv.use_domain [state - 1] + ? USE_DOMAIN_MASK + : AUXILIARY_MASK; + } + for (edge = 0; isedge (bv.transitions [edge][0]); edge++) + append_edge (bv.transitions [edge][0], bv.transitions [edge][1], + bv.transitions [edge][2], bv.transitions [edge][3], + wfa); + + success = YES; + break; } if (!success) warning ("WFA initial basis '%s' isn't linked with the executable yet." - "\nLoading basis from disk instead.", basis_name); + "\nLoading basis from disk instead.", basis_name); return success; } /***************************************************************************** - private code + private code *****************************************************************************/ /***************************************************************************** - basis "small.wfa" + basis "small.wfa" *****************************************************************************/ -static unsigned states_small = 2; -static bool_t use_domain_small[] = {YES, YES}; -static real_t final_small[] = {64, 64}; -static real_t transitions_small[][4] = {{1, 2, 0.5, 0}, {1, 2, 0.5, 1}, - {1, 0, 0.5, 1}, {2, 1, 1.0, 0}, - {2, 1, 1.0, 1}, {-1, 0, 0, 0}}; +static unsigned states_small = 2; +static bool_t use_domain_small[] = {YES, YES}; +static real_t final_small[] = {64, 64}; +static real_t transitions_small[][4] = {{1, 2, 0.5, 0}, {1, 2, 0.5, 1}, + {1, 0, 0.5, 1}, {2, 1, 1.0, 0}, + {2, 1, 1.0, 1}, {-1, 0, 0, 0}}; static void small_init (basis_values_t *bv) { diff --git a/converter/other/fiasco/input/basis.h b/converter/other/fiasco/input/basis.h index e2242198..d6d2f8b3 100644 --- a/converter/other/fiasco/input/basis.h +++ b/converter/other/fiasco/input/basis.h @@ -1,8 +1,8 @@ /* * basis.h * - * 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 */ diff --git a/converter/other/fiasco/input/matrices.c b/converter/other/fiasco/input/matrices.c index d20a27eb..f59b5a30 100644 --- a/converter/other/fiasco/input/matrices.c +++ b/converter/other/fiasco/input/matrices.c @@ -1,7 +1,7 @@ /* - * matrices.c: Input of transition matrices + * matrices.c: Input of transition matrices * - * 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 @@ -28,12 +28,12 @@ #include "matrices.h" #if STDC_HEADERS -# include <stdlib.h> +# include <stdlib.h> #endif /* not STDC_HEADERS */ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -48,7 +48,7 @@ compute_y_state (int state, int y_state, wfa_t *wfa); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -58,16 +58,16 @@ read_matrices (wfa_t *wfa, bitfile_t *input) * Read transitions of WFA given from the stream 'input'. * * Return value: - * number of edges + * number of edges * * Side effects: - * 'wfa->into' is filled with decoded values + * 'wfa->into' is filled with decoded values */ { - unsigned total; /* total number of edges in the WFA */ + unsigned total; /* total number of edges in the WFA */ unsigned root_state = wfa->wfainfo->color - ? wfa->tree [wfa->tree [wfa->root_state][0]][0] - : wfa->root_state; + ? wfa->tree [wfa->tree [wfa->root_state][0]][0] + : wfa->root_state; total = column_0_decoding (wfa, root_state, input); total += delta_decoding (wfa, root_state, input); @@ -79,7 +79,7 @@ read_matrices (wfa_t *wfa, bitfile_t *input) /***************************************************************************** - private code + private code *****************************************************************************/ @@ -91,34 +91,34 @@ delta_decoding (wfa_t *wfa, unsigned last_domain, bitfile_t *input) * 'last_domain' is the maximum state number used as domain image. * * Return value: - * number of non-zero matrix elements (WFA edges) + * number of non-zero matrix elements (WFA edges) * * Side effects: - * 'wfa->into' is filled with decoded values + * 'wfa->into' is filled with decoded values */ { - range_sort_t rs; /* ranges are sorted as in the coder */ - unsigned max_domain; /* dummy used for recursion */ - unsigned range; - unsigned count [MAXEDGES + 1]; - unsigned state, label; - unsigned *n_edges; /* number of elements per row */ - unsigned total = 0; /* total number of decoded edges */ + range_sort_t rs; /* ranges are sorted as in the coder */ + unsigned max_domain; /* dummy used for recursion */ + unsigned range; + unsigned count [MAXEDGES + 1]; + unsigned state, label; + unsigned *n_edges; /* number of elements per row */ + unsigned total = 0; /* total number of decoded edges */ /* * Generate a list of range blocks. * The order is the same as in the coder. */ rs.range_state = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (u_word_t)); + sizeof (u_word_t)); rs.range_label = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (byte_t)); + sizeof (byte_t)); rs.range_max_domain = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (u_word_t)); + sizeof (u_word_t)); rs.range_subdivided = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (bool_t)); - rs.range_no = 0; - max_domain = wfa->basis_states - 1; + sizeof (bool_t)); + rs.range_no = 0; + max_domain = wfa->basis_states - 1; sort_ranges (last_domain, &max_domain, &rs, wfa); /* @@ -127,42 +127,42 @@ delta_decoding (wfa_t *wfa, unsigned last_domain, bitfile_t *input) { arith_t *decoder; model_t *elements; - unsigned max_edges = read_rice_code (3, input); + unsigned max_edges = read_rice_code (3, input); /* * Get the probability array of the number of edges distribution * and allocate the corresponding model. */ { - unsigned edge; + unsigned edge; - for (edge = 0; edge <= max_edges; edge++) - count [edge] = read_rice_code ((int) log2 (last_domain) - 2, - input); - elements = alloc_model (max_edges + 1, 0, 0, count); + for (edge = 0; edge <= max_edges; edge++) + count [edge] = read_rice_code ((int) log2 (last_domain) - 2, + input); + elements = alloc_model (max_edges + 1, 0, 0, count); } /* * Get number of elements per matrix row */ { - unsigned row; - - n_edges = Calloc (wfa->states, sizeof (unsigned)); - decoder = alloc_decoder (input); - for (row = range = 0; range < rs.range_no; range++) - if (!rs.range_subdivided [range]) - { - state = rs.range_state [range]; - label = rs.range_label [range]; - - n_edges [row++] - = decode_symbol (decoder, elements) - - (isedge (wfa->into [state][label][0]) ? 1 : 0); - } - - free_decoder (decoder); - free_model (elements); + unsigned row; + + n_edges = Calloc (wfa->states, sizeof (unsigned)); + decoder = alloc_decoder (input); + for (row = range = 0; range < rs.range_no; range++) + if (!rs.range_subdivided [range]) + { + state = rs.range_state [range]; + label = rs.range_label [range]; + + n_edges [row++] + = decode_symbol (decoder, elements) + - (isedge (wfa->into [state][label][0]) ? 1 : 0); + } + + free_decoder (decoder); + free_model (elements); } } @@ -175,8 +175,8 @@ delta_decoding (wfa_t *wfa, unsigned last_domain, bitfile_t *input) u_word_t *mapping_coder1 = Calloc (wfa->states, sizeof (word_t)); u_word_t *mapping2 = Calloc (wfa->states, sizeof (word_t)); u_word_t *mapping_coder2 = Calloc (wfa->states, sizeof (word_t)); - bool_t use_normal_domains = get_bit (input); - bool_t use_delta_domains = get_bit (input); + bool_t use_normal_domains = get_bit (input); + bool_t use_delta_domains = get_bit (input); /* * Generate array of states which are admitted domains. @@ -187,63 +187,63 @@ delta_decoding (wfa_t *wfa, unsigned last_domain, bitfile_t *input) * coding the motion compensated prediction error */ { - unsigned n1, n2, state; - - for (n1 = n2 = state = 0; state < wfa->states; state++) - { - mapping1 [n1] = state; - mapping_coder1 [state] = n1; - if (usedomain (state, wfa) - && (state < wfa->basis_states - || use_delta_domains || !wfa->delta_state [state])) - n1++; - - mapping2 [n2] = state; - mapping_coder2 [state] = n2; - if (usedomain (state, wfa) - && (state < wfa->basis_states || use_normal_domains - || wfa->delta_state [state])) - n2++; - } + unsigned n1, n2, state; + + for (n1 = n2 = state = 0; state < wfa->states; state++) + { + mapping1 [n1] = state; + mapping_coder1 [state] = n1; + if (usedomain (state, wfa) + && (state < wfa->basis_states + || use_delta_domains || !wfa->delta_state [state])) + n1++; + + mapping2 [n2] = state; + mapping_coder2 [state] = n2; + if (usedomain (state, wfa) + && (state < wfa->basis_states || use_normal_domains + || wfa->delta_state [state])) + n2++; + } } for (row = 0, range = 0; range < rs.range_no; range++) - if (!rs.range_subdivided [range]) - { - u_word_t *mapping; - u_word_t *mapping_coder; - unsigned max_value; - unsigned edge; - unsigned state = rs.range_state [range]; - unsigned label = rs.range_label [range]; - unsigned last = 1; - - if (wfa->delta_state [state] || - wfa->mv_tree [state][label].type != NONE) - { - mapping = mapping2; - mapping_coder = mapping_coder2; - } - else - { - mapping = mapping1; - mapping_coder = mapping_coder1; - } - max_value = mapping_coder [rs.range_max_domain [range]]; - for (edge = n_edges [row]; edge; edge--) - { - unsigned domain; - - if (max_value - last) - domain = read_bin_code (max_value - last, input) + last; - else - domain = max_value; - append_edge (state, mapping [domain], -1, label, wfa); - last = domain + 1; - total++; - } - row++; - } + if (!rs.range_subdivided [range]) + { + u_word_t *mapping; + u_word_t *mapping_coder; + unsigned max_value; + unsigned edge; + unsigned state = rs.range_state [range]; + unsigned label = rs.range_label [range]; + unsigned last = 1; + + if (wfa->delta_state [state] || + wfa->mv_tree [state][label].type != NONE) + { + mapping = mapping2; + mapping_coder = mapping_coder2; + } + else + { + mapping = mapping1; + mapping_coder = mapping_coder1; + } + max_value = mapping_coder [rs.range_max_domain [range]]; + for (edge = n_edges [row]; edge; edge--) + { + unsigned domain; + + if (max_value - last) + domain = read_bin_code (max_value - last, input) + last; + else + domain = max_value; + append_edge (state, mapping [domain], -1, label, wfa); + last = domain + 1; + total++; + } + row++; + } Free (mapping1); Free (mapping_coder1); Free (mapping2); @@ -267,23 +267,23 @@ column_0_decoding (wfa_t *wfa, unsigned last_row, bitfile_t *input) * All rows from 'wfa->basis_states' up to 'last_row' are decoded. * * Return value: - * number of non-zero matrix elements (WFA edges) + * number of non-zero matrix elements (WFA edges) * * Side effects: - * 'wfa->into' is filled with decoded values + * 'wfa->into' is filled with decoded values */ { - unsigned row; /* current matrix row */ - unsigned total = 0; /* total number of edges in col 0 */ - unsigned *prob_ptr; /* pointer to current probability */ - unsigned *last; /* pointer to minimum probability */ - unsigned *first; /* pointer to maximum probability */ - unsigned *new_prob_ptr; /* ptr to probability of last domain */ - unsigned *prob; /* probability array */ - u_word_t high; /* Start of the current code range */ - u_word_t low; /* End of the current code range */ - u_word_t code; /* The present input code value */ - word_t *is_leaf; /* pointer to the tree structure */ + unsigned row; /* current matrix row */ + unsigned total = 0; /* total number of edges in col 0 */ + unsigned *prob_ptr; /* pointer to current probability */ + unsigned *last; /* pointer to minimum probability */ + unsigned *first; /* pointer to maximum probability */ + unsigned *new_prob_ptr; /* ptr to probability of last domain */ + unsigned *prob; /* probability array */ + u_word_t high; /* Start of the current code range */ + u_word_t low; /* End of the current code range */ + u_word_t code; /* The present input code value */ + word_t *is_leaf; /* pointer to the tree structure */ /* * Compute the asymmetric probability array @@ -292,14 +292,14 @@ column_0_decoding (wfa_t *wfa, unsigned last_row, bitfile_t *input) */ { unsigned n; - unsigned index; /* probability index */ - unsigned exp; /* current exponent */ + unsigned index; /* probability index */ + unsigned exp; /* current exponent */ prob = Calloc (1 << (MAX_PROB + 1), sizeof (unsigned)); for (index = 0, n = MIN_PROB; n <= MAX_PROB; n++) - for (exp = 0; exp < 1U << n; exp++, index++) - prob [index] = n; + for (exp = 0; exp < 1U << n; exp++, index++) + prob [index] = n; } first = prob_ptr = new_prob_ptr = prob; @@ -307,8 +307,8 @@ column_0_decoding (wfa_t *wfa, unsigned last_row, bitfile_t *input) is_leaf = wfa->tree [wfa->basis_states]; /* use pointer arithmetics ... */ - high = HIGH; /* 1.0 */ - low = LOW; /* 0.0 */ + high = HIGH; /* 1.0 */ + low = LOW; /* 0.0 */ code = get_bits (input, 16); /* @@ -324,73 +324,73 @@ column_0_decoding (wfa_t *wfa, unsigned last_row, bitfile_t *input) */ for (row = wfa->basis_states; row <= last_row; row++) { - unsigned count; /* value in the current interval */ + unsigned count; /* value in the current interval */ /* * Read label 0 element */ - if (isrange (*is_leaf++)) /* valid matrix index */ + if (isrange (*is_leaf++)) /* valid matrix index */ { - count = high - ((high - low) >> *prob_ptr); - if (code < count) - { - if (prob_ptr < last) /* model update */ - prob_ptr++; - /* - * Decode the MPS '0' - */ - high = count - 1; - - RESCALE_INPUT_INTERVAL; - } - else - { - prob_ptr = ((prob_ptr - first) >> 1) + first; /* model update */ - /* - * Decode the LPS '1' - */ - low = count; - - RESCALE_INPUT_INTERVAL; - /* - * Restore the transition (weight = -1) - */ - append_edge (row, 0, -1, 0, wfa); - total++; - } + count = high - ((high - low) >> *prob_ptr); + if (code < count) + { + if (prob_ptr < last) /* model update */ + prob_ptr++; + /* + * Decode the MPS '0' + */ + high = count - 1; + + RESCALE_INPUT_INTERVAL; + } + else + { + prob_ptr = ((prob_ptr - first) >> 1) + first; /* model update */ + /* + * Decode the LPS '1' + */ + low = count; + + RESCALE_INPUT_INTERVAL; + /* + * Restore the transition (weight = -1) + */ + append_edge (row, 0, -1, 0, wfa); + total++; + } } /* * Read label 1 element */ if (isrange (*is_leaf++)) /* valid matrix index */ { - count = high - ((high - low) >> *prob_ptr); - if (code < count) - { - if (prob_ptr < last) - prob_ptr++; /* model update */ - /* - * Decode the MPS '0' - */ - high = count - 1; - - RESCALE_INPUT_INTERVAL; - } - else - { - prob_ptr = ((prob_ptr - first) >> 1) + first; /* model update */ - /* - * Decode the LPS '1' - */ - low = count; - - RESCALE_INPUT_INTERVAL; - /* - * Restore the transition (weight = -1) - */ - append_edge (row, 0, -1, 1, wfa); - total++; - } + count = high - ((high - low) >> *prob_ptr); + if (code < count) + { + if (prob_ptr < last) + prob_ptr++; /* model update */ + /* + * Decode the MPS '0' + */ + high = count - 1; + + RESCALE_INPUT_INTERVAL; + } + else + { + prob_ptr = ((prob_ptr - first) >> 1) + first; /* model update */ + /* + * Decode the LPS '1' + */ + low = count; + + RESCALE_INPUT_INTERVAL; + /* + * Restore the transition (weight = -1) + */ + append_edge (row, 0, -1, 1, wfa); + total++; + } } } @@ -408,24 +408,24 @@ chroma_decoding (wfa_t *wfa, bitfile_t *input) * chroma channels Cb and Cr from stream 'input'. * * Return value: - * number of non-zero matrix elements (WFA edges) + * number of non-zero matrix elements (WFA edges) * * Side effects: - * 'wfa->into' is filled with decoded values + * 'wfa->into' is filled with decoded values */ { - unsigned domain; /* current domain, counter */ - unsigned total = 0; /* total number of chroma edges */ - unsigned *prob_ptr; /* pointer to current probability */ - unsigned *last; /* pointer to minimum probability */ - unsigned *first; /* pointer to maximum probability */ - unsigned *new_prob_ptr; /* ptr to probability of last domain */ - unsigned *prob; /* probability array */ - u_word_t high; /* Start of the current code range */ - u_word_t low; /* End of the current code range */ - u_word_t code; /* The present input code value */ - word_t *y_domains; /* domain images corresponding to Y */ - int save_index; /* YES: store current probability */ + unsigned domain; /* current domain, counter */ + unsigned total = 0; /* total number of chroma edges */ + unsigned *prob_ptr; /* pointer to current probability */ + unsigned *last; /* pointer to minimum probability */ + unsigned *first; /* pointer to maximum probability */ + unsigned *new_prob_ptr; /* ptr to probability of last domain */ + unsigned *prob; /* probability array */ + u_word_t high; /* Start of the current code range */ + u_word_t low; /* End of the current code range */ + u_word_t code; /* The present input code value */ + word_t *y_domains; /* domain images corresponding to Y */ + int save_index; /* YES: store current probability */ /* * Compute the asymmetric probability array @@ -434,26 +434,26 @@ chroma_decoding (wfa_t *wfa, bitfile_t *input) */ { unsigned n; - unsigned index; /* probability index */ - unsigned exp; /* current exponent */ + unsigned index; /* probability index */ + unsigned exp; /* current exponent */ prob = Calloc (1 << (MAX_PROB + 1), sizeof (unsigned)); for (index = 0, n = MIN_PROB; n <= MAX_PROB; n++) - for (exp = 0; exp < 1U << n; exp++, index++) - prob [index] = n; + for (exp = 0; exp < 1U << n; exp++, index++) + prob [index] = n; } - high = HIGH; /* 1.0 */ - low = LOW; /* 0.0 */ + high = HIGH; /* 1.0 */ + low = LOW; /* 0.0 */ code = get_bits (input, 16); /* * Compute list of admitted domains */ y_domains = compute_hits (wfa->basis_states, - wfa->tree [wfa->tree [wfa->root_state][0]][0], - wfa->wfainfo->chroma_max_states, wfa); + wfa->tree [wfa->tree [wfa->root_state][0]][0], + wfa->wfainfo->chroma_max_states, wfa); first = prob_ptr = new_prob_ptr = prob; last = first + 1020; @@ -465,7 +465,7 @@ chroma_decoding (wfa_t *wfa, bitfile_t *input) */ for (domain = 0; y_domains [domain] != -1; domain++) { - unsigned row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; + unsigned row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; word_t *is_leaf = wfa->tree [row]; prob_ptr = new_prob_ptr; @@ -473,87 +473,87 @@ chroma_decoding (wfa_t *wfa, bitfile_t *input) for (; row < wfa->states; row++) { - unsigned count; /* value in the current interval */ - /* - * Read label 0 element - */ - if (isrange (*is_leaf++)) /* valid matrix index */ - { - count = high - ((high - low) >> *prob_ptr); - if (code < count) - { - if (prob_ptr < last) - prob_ptr++; - /* - * Decode the MPS '0' - */ - high = count - 1; - - RESCALE_INPUT_INTERVAL; - } - else - { - prob_ptr = ((prob_ptr - first) >> 1) + first; - /* - * Decode the LPS '1' - */ - low = count; - - RESCALE_INPUT_INTERVAL; - /* - * Restore the transition (weight = -1) - */ - append_edge (row, y_domains [domain], -1, 0, wfa); - total++; - } - } - /* - * Read label 1 element - */ - if (isrange (*is_leaf++)) /* valid matrix index */ - { - count = high - ((high - low) >> *prob_ptr); - if (code < count) - { - if (prob_ptr < last) - prob_ptr++; - /* - * Decode the MPS '0' - */ - high = count - 1; - - RESCALE_INPUT_INTERVAL; - } - else - { - prob_ptr = ((prob_ptr - first) >> 1) + first; - /* - * Decode the LPS '1' - */ - low = count; - - RESCALE_INPUT_INTERVAL; - /* - * Restore the transition (weight = -1) - */ - append_edge (row, y_domains [domain], -1, 1, wfa); - total++; - } - } - if (save_index) - { - save_index = NO; - new_prob_ptr = prob_ptr; - } + unsigned count; /* value in the current interval */ + /* + * Read label 0 element + */ + if (isrange (*is_leaf++)) /* valid matrix index */ + { + count = high - ((high - low) >> *prob_ptr); + if (code < count) + { + if (prob_ptr < last) + prob_ptr++; + /* + * Decode the MPS '0' + */ + high = count - 1; + + RESCALE_INPUT_INTERVAL; + } + else + { + prob_ptr = ((prob_ptr - first) >> 1) + first; + /* + * Decode the LPS '1' + */ + low = count; + + RESCALE_INPUT_INTERVAL; + /* + * Restore the transition (weight = -1) + */ + append_edge (row, y_domains [domain], -1, 0, wfa); + total++; + } + } + /* + * Read label 1 element + */ + if (isrange (*is_leaf++)) /* valid matrix index */ + { + count = high - ((high - low) >> *prob_ptr); + if (code < count) + { + if (prob_ptr < last) + prob_ptr++; + /* + * Decode the MPS '0' + */ + high = count - 1; + + RESCALE_INPUT_INTERVAL; + } + else + { + prob_ptr = ((prob_ptr - first) >> 1) + first; + /* + * Decode the LPS '1' + */ + low = count; + + RESCALE_INPUT_INTERVAL; + /* + * Restore the transition (weight = -1) + */ + append_edge (row, y_domains [domain], -1, 1, wfa); + total++; + } + } + if (save_index) + { + save_index = NO; + new_prob_ptr = prob_ptr; + } } } Free (y_domains); compute_y_state (wfa->tree [wfa->tree [wfa->root_state][0]][1], - wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa); + wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa); compute_y_state (wfa->tree [wfa->tree [wfa->root_state][1]][0], - wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa); + wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa); first = prob_ptr = new_prob_ptr = prob; @@ -565,44 +565,44 @@ chroma_decoding (wfa_t *wfa, bitfile_t *input) * Again, quasi arithmetic decoding is used for this task. */ { - unsigned row; + unsigned row; for (row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; - row < wfa->states; row++) + row < wfa->states; row++) { - int label; /* current label */ - - for (label = 0; label < MAXLABELS; label++) - { - u_word_t count = high - ((high - low) >> *prob_ptr); - - if (code < count) - { - if (prob_ptr < last) - prob_ptr++; - /* - * Decode the MPS '0' - */ - high = count - 1; - - RESCALE_INPUT_INTERVAL; - } - else - { - prob_ptr = ((prob_ptr - first) >> 1) + first; - /* - * Decode the LPS '1' - */ - low = count; - - RESCALE_INPUT_INTERVAL; - /* - * Restore the transition (weight = -1) - */ - append_edge (row, wfa->y_state [row][label], -1, label, wfa); - total++; - } - } + int label; /* current label */ + + for (label = 0; label < MAXLABELS; label++) + { + u_word_t count = high - ((high - low) >> *prob_ptr); + + if (code < count) + { + if (prob_ptr < last) + prob_ptr++; + /* + * Decode the MPS '0' + */ + high = count - 1; + + RESCALE_INPUT_INTERVAL; + } + else + { + prob_ptr = ((prob_ptr - first) >> 1) + first; + /* + * Decode the LPS '1' + */ + low = count; + + RESCALE_INPUT_INTERVAL; + /* + * Restore the transition (weight = -1) + */ + append_edge (row, wfa->y_state [row][label], -1, label, wfa); + total++; + } + } } } @@ -625,20 +625,20 @@ compute_y_state (int state, int y_state, wfa_t *wfa) * No return value. * * Side effects: - * 'wfa->y_state' is filled with the generated tree structure. + * 'wfa->y_state' is filled with the generated tree structure. */ { unsigned label; for (label = 0; label < MAXLABELS; label++) if (isrange (y_state)) - wfa->y_state [state][label] = RANGE; + wfa->y_state [state][label] = RANGE; else { - wfa->y_state [state][label] = wfa->tree [y_state][label]; - if (!isrange (wfa->tree [state][label])) - compute_y_state (wfa->tree [state][label], - wfa->y_state [state][label], wfa); + wfa->y_state [state][label] = wfa->tree [y_state][label]; + if (!isrange (wfa->tree [state][label])) + compute_y_state (wfa->tree [state][label], + wfa->y_state [state][label], wfa); } } diff --git a/converter/other/fiasco/input/matrices.h b/converter/other/fiasco/input/matrices.h index 6d1cef15..193bc6a7 100644 --- a/converter/other/fiasco/input/matrices.h +++ b/converter/other/fiasco/input/matrices.h @@ -1,8 +1,8 @@ /* * matrices.h * - * 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 */ diff --git a/converter/other/fiasco/input/mc.c b/converter/other/fiasco/input/mc.c index afc0c1c3..8d93d931 100644 --- a/converter/other/fiasco/input/mc.c +++ b/converter/other/fiasco/input/mc.c @@ -1,8 +1,8 @@ /* - * mc.c: Input of motion compensation + * mc.c: Input of motion compensation * * written by: Michael Unger - * Ullrich Hafner + * Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -31,27 +31,27 @@ /***************************************************************************** - local variables + local variables *****************************************************************************/ typedef struct huff_node { - int code_index; /* leaf if index >= 0 */ - struct huff_node *left; /* follow if '0' bit read */ - struct huff_node *right; /* follow if '1' bit read */ - int index_set [34]; + int code_index; /* leaf if index >= 0 */ + struct huff_node *left; /* follow if '0' bit read */ + struct huff_node *right; /* follow if '1' bit read */ + int index_set [34]; } huff_node_t; /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void decode_mc_tree (frame_type_e frame_type, unsigned max_state, - wfa_t *wfa, bitfile_t *input); + wfa_t *wfa, bitfile_t *input); static void decode_mc_coords (unsigned max_state, wfa_t *wfa, bitfile_t *input); static int @@ -63,7 +63,7 @@ create_huff_node (huff_node_t *hn, int bits_processed); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -76,12 +76,12 @@ read_mc (frame_type_e frame_type, wfa_t *wfa, bitfile_t *input) * No return value. * * Side effects: - * 'wfa->mv_tree' is filled with the decoded values. + * 'wfa->mv_tree' is filled with the decoded values. */ { unsigned max_state = wfa->wfainfo->color - ? wfa->tree [wfa->tree [wfa->root_state][0]][0] - : wfa->states; + ? wfa->tree [wfa->tree [wfa->root_state][0]][0] + : wfa->states; decode_mc_tree (frame_type, max_state, wfa, input); decode_mc_coords (max_state, wfa, input); @@ -89,13 +89,13 @@ read_mc (frame_type_e frame_type, wfa_t *wfa, bitfile_t *input) /***************************************************************************** - private code + private code *****************************************************************************/ static void decode_mc_tree (frame_type_e frame_type, unsigned max_state, - wfa_t *wfa, bitfile_t *input) + wfa_t *wfa, bitfile_t *input) /* * Read tree of motion compensation decisions of the 'input' stream. * Depending on 'frame_type' different decoding methods are used. @@ -104,13 +104,13 @@ decode_mc_tree (frame_type_e frame_type, unsigned max_state, * No return value. * * Side effects: - * 'wfa->mv_tree' is filled with decoded values. + * 'wfa->mv_tree' is filled with decoded values. */ { - unsigned state; /* current state */ - unsigned *queue; /* states in breadth first order */ - unsigned last; /* last node - (update for each new node) */ + unsigned state; /* current state */ + unsigned *queue; /* states in breadth first order */ + unsigned last; /* last node + (update for each new node) */ /* * Traverse tree in breadth first order (starting at level @@ -120,68 +120,68 @@ decode_mc_tree (frame_type_e frame_type, unsigned max_state, queue = Calloc (MAXSTATES, sizeof (unsigned)); for (last = 0, state = wfa->basis_states; state < max_state; state++) if (wfa->level_of_state [state] - 1 == (int) wfa->wfainfo->p_max_level) - queue [last++] = state; /* init level 'p_max_level' */ + queue [last++] = state; /* init level 'p_max_level' */ if (frame_type == P_FRAME) { - unsigned label; /* current label */ - unsigned current; /* current node to process */ + unsigned label; /* current label */ + unsigned current; /* current node to process */ for (current = 0; current < last; current++) - for (label = 0; label < MAXLABELS; label++) - { - state = queue[current]; - if (wfa->x [state][label] /* process visible states only */ - + width_of_level (wfa->level_of_state [state] - 1) - <= wfa->wfainfo->width - && - wfa->y [state][label] - + height_of_level (wfa->level_of_state [state] - 1) - <= wfa->wfainfo->height) - { - wfa->mv_tree [state][label].type - = get_bit (input) ? NONE : FORWARD; - } - else - wfa->mv_tree [state][label].type = NONE; - if (wfa->mv_tree [state][label].type == NONE && - !isrange (wfa->tree [state][label]) && - wfa->level_of_state [state] - 1 >= - (int) wfa->wfainfo->p_min_level) - queue [last++] = wfa->tree [state][label]; /* append child */ - } + for (label = 0; label < MAXLABELS; label++) + { + state = queue[current]; + if (wfa->x [state][label] /* process visible states only */ + + width_of_level (wfa->level_of_state [state] - 1) + <= wfa->wfainfo->width + && + wfa->y [state][label] + + height_of_level (wfa->level_of_state [state] - 1) + <= wfa->wfainfo->height) + { + wfa->mv_tree [state][label].type + = get_bit (input) ? NONE : FORWARD; + } + else + wfa->mv_tree [state][label].type = NONE; + if (wfa->mv_tree [state][label].type == NONE && + !isrange (wfa->tree [state][label]) && + wfa->level_of_state [state] - 1 >= + (int) wfa->wfainfo->p_min_level) + queue [last++] = wfa->tree [state][label]; /* append child */ + } } else { - unsigned label; /* current label */ - unsigned current; /* current node to process */ + unsigned label; /* current label */ + unsigned current; /* current node to process */ for (current = 0; current < last; current++) - for (label = 0; label < MAXLABELS; label++) - { - state = queue[current]; - if (wfa->x [state][label] /* process visible states only */ - + width_of_level (wfa->level_of_state [state] - 1) - > wfa->wfainfo->width - || - wfa->y [state][label] - + height_of_level (wfa->level_of_state [state] - 1) - > wfa->wfainfo->height) - wfa->mv_tree[state][label].type = NONE; - else if (get_bit (input)) /* 1 */ - wfa->mv_tree[state][label].type = NONE; - else if (get_bit (input)) /* 01 */ - wfa->mv_tree[state][label].type = INTERPOLATED; - else if (get_bit (input)) /* 001 */ - wfa->mv_tree[state][label].type = BACKWARD; - else /* 000 */ - wfa->mv_tree[state][label].type = FORWARD; - if (wfa->mv_tree[state][label].type == NONE && - !isrange (wfa->tree[state][label]) && - wfa->level_of_state[state] - 1 - >= (int) wfa->wfainfo->p_min_level) - queue[last++] = wfa->tree[state][label]; /* append child */ - } + for (label = 0; label < MAXLABELS; label++) + { + state = queue[current]; + if (wfa->x [state][label] /* process visible states only */ + + width_of_level (wfa->level_of_state [state] - 1) + > wfa->wfainfo->width + || + wfa->y [state][label] + + height_of_level (wfa->level_of_state [state] - 1) + > wfa->wfainfo->height) + wfa->mv_tree[state][label].type = NONE; + else if (get_bit (input)) /* 1 */ + wfa->mv_tree[state][label].type = NONE; + else if (get_bit (input)) /* 01 */ + wfa->mv_tree[state][label].type = INTERPOLATED; + else if (get_bit (input)) /* 001 */ + wfa->mv_tree[state][label].type = BACKWARD; + else /* 000 */ + wfa->mv_tree[state][label].type = FORWARD; + if (wfa->mv_tree[state][label].type == NONE && + !isrange (wfa->tree[state][label]) && + wfa->level_of_state[state] - 1 + >= (int) wfa->wfainfo->p_min_level) + queue[last++] = wfa->tree[state][label]; /* append child */ + } } INPUT_BYTE_ALIGN (input); @@ -198,12 +198,12 @@ decode_mc_coords (unsigned max_state, wfa_t *wfa, bitfile_t *input) * No return value. * * Side effects: - * 'wfa->mv_tree' is filled with decoded values. + * 'wfa->mv_tree' is filled with decoded values. */ { - unsigned label; /* current label */ - unsigned state; /* current state */ - mv_t *mv; /* current motion vector */ + unsigned label; /* current label */ + unsigned state; /* current state */ + mv_t *mv; /* current motion vector */ static huff_node_t *huff_mv_root = NULL; /* root of huffman tree */ if (huff_mv_root == NULL) @@ -212,26 +212,26 @@ decode_mc_coords (unsigned max_state, wfa_t *wfa, bitfile_t *input) for (state = wfa->basis_states; state < max_state; state++) for (label = 0; label < MAXLABELS; label++) { - mv = &wfa->mv_tree[state][label]; - switch (mv->type) - { - case NONE: - break; - case FORWARD: - mv->fx = get_mv (1, huff_mv_root, input); - mv->fy = get_mv (1, huff_mv_root, input); - break; - case BACKWARD: - mv->bx = get_mv (1, huff_mv_root, input); - mv->by = get_mv (1, huff_mv_root, input); - break; - case INTERPOLATED: - mv->fx = get_mv (1, huff_mv_root, input); - mv->fy = get_mv (1, huff_mv_root, input); - mv->bx = get_mv (1, huff_mv_root, input); - mv->by = get_mv (1, huff_mv_root, input); - break; - } + mv = &wfa->mv_tree[state][label]; + switch (mv->type) + { + case NONE: + break; + case FORWARD: + mv->fx = get_mv (1, huff_mv_root, input); + mv->fy = get_mv (1, huff_mv_root, input); + break; + case BACKWARD: + mv->bx = get_mv (1, huff_mv_root, input); + mv->by = get_mv (1, huff_mv_root, input); + break; + case INTERPOLATED: + mv->fx = get_mv (1, huff_mv_root, input); + mv->fy = get_mv (1, huff_mv_root, input); + mv->bx = get_mv (1, huff_mv_root, input); + mv->by = get_mv (1, huff_mv_root, input); + break; + } } INPUT_BYTE_ALIGN (input); @@ -249,11 +249,11 @@ get_mv (int f_code, huff_node_t *hn, bitfile_t *input) while (hn->code_index < 0) { if (hn->code_index == -2) - error ("wrong huffman code !"); + error ("wrong huffman code !"); if (get_bit (input)) - hn = hn->right; + hn = hn->right; else - hn = hn->left; + hn = hn->left; } vlc_code = hn->code_index - 16; if (vlc_code == 0 || f_code == 1) @@ -275,7 +275,7 @@ create_huff_tree (void) * Construct huffman tree from code table */ { - unsigned i; + unsigned i; huff_node_t *huff_root = Calloc (1, sizeof (huff_node_t)); /* @@ -286,7 +286,7 @@ create_huff_tree (void) for (i = 0; i < 33; i++) huff_root->index_set [i] = i; - huff_root->index_set [i] = -1; /* end marker */ + huff_root->index_set [i] = -1; /* end marker */ create_huff_node (huff_root, 0); @@ -299,14 +299,14 @@ create_huff_node (huff_node_t *hn, int bits_processed) * Create one node in the huffman tree */ { - int lind = 0; /* next index of left huff_node */ - int rind = 0; /* next index of right huff_node */ + int lind = 0; /* next index of left huff_node */ + int rind = 0; /* next index of right huff_node */ int code_len, i, ind; hn->code_index = -1; - if (hn->index_set [0] < 0) /* empty index set ? */ + if (hn->index_set [0] < 0) /* empty index set ? */ { - hn->code_index = -2; /* error */ + hn->code_index = -2; /* error */ return; } hn->left = Calloc (1, sizeof (huff_node_t)); @@ -315,19 +315,19 @@ create_huff_node (huff_node_t *hn, int bits_processed) for (i = 0; (ind = hn->index_set[i]) >= 0; i++) { code_len = mv_code_table[ind][1]; - if (code_len == bits_processed) /* generate leaf */ + if (code_len == bits_processed) /* generate leaf */ { - hn->code_index = ind; - Free (hn->left); - Free (hn->right); - return; + hn->code_index = ind; + Free (hn->left); + Free (hn->right); + return; } if (mv_code_table[ind][0] & (1 << (code_len - 1 - bits_processed))) - hn->right->index_set[rind++] = ind; + hn->right->index_set[rind++] = ind; else - hn->left->index_set[lind++] = ind; + hn->left->index_set[lind++] = ind; } - hn->right->index_set[rind] = -1; /* set end markers */ + hn->right->index_set[rind] = -1; /* set end markers */ hn->left->index_set[lind] = -1; create_huff_node (hn->left, bits_processed + 1); create_huff_node (hn->right, bits_processed + 1); diff --git a/converter/other/fiasco/input/mc.h b/converter/other/fiasco/input/mc.h index 9d9d714d..a61f7e4a 100644 --- a/converter/other/fiasco/input/mc.h +++ b/converter/other/fiasco/input/mc.h @@ -2,8 +2,8 @@ * mc.h * * written by: Michael Unger - * Ullrich Hafner - + * Ullrich Hafner + * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/input/nd.c b/converter/other/fiasco/input/nd.c index 129a150e..0317073a 100644 --- a/converter/other/fiasco/input/nd.c +++ b/converter/other/fiasco/input/nd.c @@ -1,7 +1,7 @@ /* - * nd.c: Input of prediction tree + * nd.c: Input of prediction tree * - * 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 @@ -30,7 +30,7 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -41,7 +41,7 @@ decode_nd_tree (wfa_t *wfa, bitfile_t *input); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -52,7 +52,7 @@ read_nd (wfa_t *wfa, bitfile_t *input) * ND is used only at levels {'wfa->p_min_level', ... , 'wfa->p_max_level'}. * * Side effects: - * 'wfa->into' and 'wfa->weights' are filled with the decoded values + * 'wfa->into' and 'wfa->weights' are filled with the decoded values */ { unsigned total = decode_nd_tree (wfa, input); @@ -63,7 +63,7 @@ read_nd (wfa_t *wfa, bitfile_t *input) /***************************************************************************** - private code + private code *****************************************************************************/ @@ -75,16 +75,16 @@ decode_nd_tree (wfa_t *wfa, bitfile_t *input) * No return value. * * Side effects: - * 'wfa->into' is filled with the decoded values + * 'wfa->into' is filled with the decoded values */ { - lqueue_t *queue; /* queue of states */ - int next, state; /* state and its current child */ - unsigned total = 0; /* total number of predicted states */ - u_word_t sum0, sum1; /* Probability model */ - u_word_t code; /* The present input code value */ - u_word_t low; /* Start of the current code range */ - u_word_t high; /* End of the current code range */ + lqueue_t *queue; /* queue of states */ + int next, state; /* state and its current child */ + unsigned total = 0; /* total number of predicted states */ + u_word_t sum0, sum1; /* Probability model */ + u_word_t code; /* The present input code value */ + u_word_t low; /* Start of the current code range */ + u_word_t high; /* End of the current code range */ /* * Initialize arithmetic decoder @@ -108,78 +108,78 @@ decode_nd_tree (wfa_t *wfa, bitfile_t *input) if (wfa->level_of_state [next] > wfa->wfainfo->p_max_level + 1) { - /* - * Nondetermismn is not allowed at levels larger than - * 'wfa->wfainfo->p_max_level'. - */ - for (label = 0; label < MAXLABELS; label++) - if (ischild (state = wfa->tree [next][label])) - queue_append (queue, &state); /* continue with children */ + /* + * Nondetermismn is not allowed at levels larger than + * 'wfa->wfainfo->p_max_level'. + */ + for (label = 0; label < MAXLABELS; label++) + if (ischild (state = wfa->tree [next][label])) + queue_append (queue, &state); /* continue with children */ } else if (wfa->level_of_state [next] > wfa->wfainfo->p_min_level) { - for (label = 0; label < MAXLABELS; label++) - if (ischild (state = wfa->tree [next][label])) - { - unsigned count; /* Current interval count */ - unsigned range; /* Current interval range */ - - count = (((code - low) + 1) * sum1 - 1) / ((high - low) + 1); - if (count < sum0) - { - /* - * Decode a '0' symbol - * First, the range is expanded to account for the - * symbol removal. - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum0) / sum1 - 1 ); - RESCALE_INPUT_INTERVAL; - /* - * Update the frequency counts - */ - sum0++; - sum1++; - if (sum1 > 50) /* scale the symbol frequencies */ - { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; - } - if (wfa->level_of_state [state] > wfa->wfainfo->p_min_level) - queue_append (queue, &state); - } - else - { - /* - * Decode a '1' symbol - * First, the range is expanded to account for the - * symbol removal. - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum1) / sum1 - 1); - low = low + (u_word_t) ((range * sum0) / sum1); - RESCALE_INPUT_INTERVAL; - /* - * Update the frequency counts - */ - sum1++; - if (sum1 > 50) /* scale the symbol frequencies */ - { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; - } - append_edge (next, 0, -1, label, wfa); - total++; - } - } + for (label = 0; label < MAXLABELS; label++) + if (ischild (state = wfa->tree [next][label])) + { + unsigned count; /* Current interval count */ + unsigned range; /* Current interval range */ + + count = (((code - low) + 1) * sum1 - 1) / ((high - low) + 1); + if (count < sum0) + { + /* + * Decode a '0' symbol + * First, the range is expanded to account for the + * symbol removal. + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum0) / sum1 - 1 ); + RESCALE_INPUT_INTERVAL; + /* + * Update the frequency counts + */ + sum0++; + sum1++; + if (sum1 > 50) /* scale the symbol frequencies */ + { + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; + } + if (wfa->level_of_state [state] > wfa->wfainfo->p_min_level) + queue_append (queue, &state); + } + else + { + /* + * Decode a '1' symbol + * First, the range is expanded to account for the + * symbol removal. + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum1) / sum1 - 1); + low = low + (u_word_t) ((range * sum0) / sum1); + RESCALE_INPUT_INTERVAL; + /* + * Update the frequency counts + */ + sum1++; + if (sum1 > 50) /* scale the symbol frequencies */ + { + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; + } + append_edge (next, 0, -1, label, wfa); + total++; + } + } } } free_queue (queue); @@ -199,21 +199,21 @@ decode_nd_coefficients (unsigned total, wfa_t *wfa, bitfile_t *input) * No return value. * * Side effects: - * 'wfa->weights' is filled with the decoded values. + * 'wfa->weights' is filled with the decoded values. */ { - unsigned *coefficients; /* array of factors to encode */ - unsigned *ptr; /* pointer to current factor */ + unsigned *coefficients; /* array of factors to encode */ + unsigned *ptr; /* pointer to current factor */ /* * Decode array of coefficients stored with arithmetic coding */ { - const int scaling = 50; /* scaling factor of prob. model */ + const int scaling = 50; /* scaling factor of prob. model */ unsigned c_symbols = 1 << (wfa->wfainfo->dc_rpf->mantissa_bits + 1); ptr = coefficients = decode_array (input, NULL, &c_symbols, 1, - total, scaling); + total, scaling); } /* @@ -223,15 +223,15 @@ decode_nd_coefficients (unsigned total, wfa_t *wfa, bitfile_t *input) unsigned state, label; for (state = wfa->basis_states; state < wfa->states; state++) - for (label = 0; label < MAXLABELS; label++) - if (ischild (wfa->tree [state][label]) - && isedge (wfa->into [state][label][0])) - { - wfa->weight [state][label][0] = btor (*ptr++, - wfa->wfainfo->dc_rpf); - wfa->int_weight [state][label][0] - = wfa->weight [state][label][0] * 512 + 0.5; - } + for (label = 0; label < MAXLABELS; label++) + if (ischild (wfa->tree [state][label]) + && isedge (wfa->into [state][label][0])) + { + wfa->weight [state][label][0] = btor (*ptr++, + wfa->wfainfo->dc_rpf); + wfa->int_weight [state][label][0] + = wfa->weight [state][label][0] * 512 + 0.5; + } } Free (coefficients); } diff --git a/converter/other/fiasco/input/nd.h b/converter/other/fiasco/input/nd.h index 0fe06cf1..57f46440 100644 --- a/converter/other/fiasco/input/nd.h +++ b/converter/other/fiasco/input/nd.h @@ -1,8 +1,8 @@ /* * nd.h * - * 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 */ diff --git a/converter/other/fiasco/input/read.c b/converter/other/fiasco/input/read.c index c3aa77a8..50e271e5 100644 --- a/converter/other/fiasco/input/read.c +++ b/converter/other/fiasco/input/read.c @@ -1,7 +1,7 @@ /* - * read.c: Input of WFA files + * read.c: Input of WFA files * - * 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 @@ -46,17 +46,17 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void read_tiling (tiling_t *tiling, unsigned image_width, unsigned image_height, - unsigned image_level, bitfile_t *input); + unsigned image_level, bitfile_t *input); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -66,14 +66,14 @@ open_wfa (const char *filename, wfa_info_t *wi) * Open WFA file 'filename' and read header information. * * Return value: - * Pointer to input stream (fileposition: first WFA frame) + * Pointer to input stream (fileposition: first WFA frame) * * Side effects: - * The values of the header of 'filename' are copied to 'wfainfo'. + * The values of the header of 'filename' are copied to 'wfainfo'. * */ { - bitfile_t *input; /* pointer to WFA bitfile */ + bitfile_t *input; /* pointer to WFA bitfile */ assert (filename && wi); @@ -83,7 +83,7 @@ open_wfa (const char *filename, wfa_info_t *wi) * Check whether 'filename' is a regular WFA file */ { - unsigned n; + unsigned n; const char *str; if (!(input = open_bitfile (filename, "FIASCO_DATA", READ_ACCESS))) @@ -92,57 +92,57 @@ open_wfa (const char *filename, wfa_info_t *wi) for (str = FIASCO_MAGIC, n = strlen (FIASCO_MAGIC); n; n--) if (get_bits (input, 8) != (unsigned) *str++) error ("Input file %s is not a valid FIASCO file!", filename); - get_bits (input, 8); /* fetch newline */ + get_bits (input, 8); /* fetch newline */ } /* * Read WFA header information */ { - char basis_name [MAXSTRLEN]; /* temp. buffer */ - const unsigned rice_k = 8; /* parameter of Rice Code */ - char *str = basis_name; + char basis_name [MAXSTRLEN]; /* temp. buffer */ + const unsigned rice_k = 8; /* parameter of Rice Code */ + char *str = basis_name; while ((*str++ = get_bits (input, 8)) != 0 - && str < basis_name + MAXSTRLEN) - ; + && str < basis_name + MAXSTRLEN) + ; if (str == basis_name + MAXSTRLEN) - error ("Input file %s is not a valid FIASCO file!", filename); + error ("Input file %s is not a valid FIASCO file!", filename); { - wi->release = read_rice_code (rice_k, input); + wi->release = read_rice_code (rice_k, input); - if (wi->release > FIASCO_BINFILE_RELEASE) - error ("Can't decode FIASCO files of file format release `%d'." - "\nCurrent file format release is `%d'.", wi->release, - FIASCO_BINFILE_RELEASE); + if (wi->release > FIASCO_BINFILE_RELEASE) + error ("Can't decode FIASCO files of file format release `%d'." + "\nCurrent file format release is `%d'.", wi->release, + FIASCO_BINFILE_RELEASE); } if (wi->release > 1) { - header_type_e type; - - while ((type = read_rice_code (rice_k, input)) != HEADER_END) - { - char buffer [MAXSTRLEN]; - unsigned n = 0; - - switch (type) - { - case HEADER_TITLE: - while ((buffer [n++] = get_bits (input, 8))) - ; - wi->title = strdup (buffer); - break; - case HEADER_COMMENT: - while ((buffer [n++] = get_bits (input, 8))) - ; - wi->comment = strdup (buffer); - break; - default: /* should not happen */ - break; - } - } + header_type_e type; + + while ((type = read_rice_code (rice_k, input)) != HEADER_END) + { + char buffer [MAXSTRLEN]; + unsigned n = 0; + + switch (type) + { + case HEADER_TITLE: + while ((buffer [n++] = get_bits (input, 8))) + ; + wi->title = strdup (buffer); + break; + case HEADER_COMMENT: + while ((buffer [n++] = get_bits (input, 8))) + ; + wi->comment = strdup (buffer); + break; + default: /* should not happen */ + break; + } + } } wi->basis_name = strdup (basis_name); @@ -155,65 +155,65 @@ open_wfa (const char *filename, wfa_info_t *wi) * Compute bintree level */ { - unsigned lx = log2 (wi->width - 1) + 1; - unsigned ly = log2 (wi->height - 1) + 1; + unsigned lx = log2 (wi->width - 1) + 1; + unsigned ly = log2 (wi->height - 1) + 1; - wi->level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0); + wi->level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0); } wi->chroma_max_states = wi->color ? read_rice_code (rice_k, input) : -1; wi->p_min_level = read_rice_code (rice_k, input); wi->p_max_level = read_rice_code (rice_k, input); wi->frames = read_rice_code (rice_k, input); - wi->smoothing = read_rice_code (rice_k, input); + wi->smoothing = read_rice_code (rice_k, input); /* * Read RPF models from disk */ { - unsigned mantissa; - fiasco_rpf_range_e range; - - mantissa = get_bits (input, 3) + 2; - range = get_bits (input, 2); - wi->rpf = alloc_rpf (mantissa, range); - - if (get_bit (input)) /* different DC model */ - { - mantissa = get_bits (input, 3) + 2; - range = get_bits (input, 2); - wi->dc_rpf = alloc_rpf (mantissa, range); - } - else /* use same model for DC coefficients */ - wi->dc_rpf = alloc_rpf (wi->rpf->mantissa_bits, - wi->rpf->range_e); - - if (get_bit (input)) /* different delta model */ - { - mantissa = get_bits (input, 3) + 2; - range = get_bits (input, 2); - wi->d_rpf = alloc_rpf (mantissa, range); - } - else - wi->d_rpf = alloc_rpf (wi->rpf->mantissa_bits, - wi->rpf->range_e); - - if (get_bit (input)) /* different DC delta model */ - { - mantissa = get_bits (input, 3) + 2; - range = get_bits (input, 2); - wi->d_dc_rpf = alloc_rpf (mantissa, range); - } - else - wi->d_dc_rpf = alloc_rpf (wi->dc_rpf->mantissa_bits, - wi->dc_rpf->range_e); + unsigned mantissa; + fiasco_rpf_range_e range; + + mantissa = get_bits (input, 3) + 2; + range = get_bits (input, 2); + wi->rpf = alloc_rpf (mantissa, range); + + if (get_bit (input)) /* different DC model */ + { + mantissa = get_bits (input, 3) + 2; + range = get_bits (input, 2); + wi->dc_rpf = alloc_rpf (mantissa, range); + } + else /* use same model for DC coefficients */ + wi->dc_rpf = alloc_rpf (wi->rpf->mantissa_bits, + wi->rpf->range_e); + + if (get_bit (input)) /* different delta model */ + { + mantissa = get_bits (input, 3) + 2; + range = get_bits (input, 2); + wi->d_rpf = alloc_rpf (mantissa, range); + } + else + wi->d_rpf = alloc_rpf (wi->rpf->mantissa_bits, + wi->rpf->range_e); + + if (get_bit (input)) /* different DC delta model */ + { + mantissa = get_bits (input, 3) + 2; + range = get_bits (input, 2); + wi->d_dc_rpf = alloc_rpf (mantissa, range); + } + else + wi->d_dc_rpf = alloc_rpf (wi->dc_rpf->mantissa_bits, + wi->dc_rpf->range_e); } - if (wi->frames > 1) /* motion compensation stuff */ + if (wi->frames > 1) /* motion compensation stuff */ { - wi->fps = read_rice_code (rice_k, input); - wi->search_range = read_rice_code (rice_k, input); - wi->half_pixel = get_bit (input) ? YES : NO; - wi->B_as_past_ref = get_bit (input) ? YES : NO; + wi->fps = read_rice_code (rice_k, input); + wi->search_range = read_rice_code (rice_k, input); + wi->half_pixel = get_bit (input) ? YES : NO; + wi->B_as_past_ref = get_bit (input) ? YES : NO; } } @@ -230,12 +230,12 @@ read_basis (const char *filename, wfa_t *wfa) * No return value. * * Side effects: - * wfa->into, wfa->weights, wfa->final_distribution, wfa->basis_states - * wfa->domain_type wfa->wfainfo->basis_name, are filled with the - * values of the WFA basis. + * wfa->into, wfa->weights, wfa->final_distribution, wfa->basis_states + * wfa->domain_type wfa->wfainfo->basis_name, are filled with the + * values of the WFA basis. */ { - FILE *input; /* ASCII WFA initial basis file */ + FILE *input; /* ASCII WFA initial basis file */ assert (filename && wfa); @@ -243,27 +243,27 @@ read_basis (const char *filename, wfa_t *wfa) !streq (wfa->wfainfo->basis_name, filename)) { if (wfa->wfainfo->basis_name) - Free (wfa->wfainfo->basis_name); + Free (wfa->wfainfo->basis_name); wfa->wfainfo->basis_name = strdup (filename); } if (get_linked_basis (filename, wfa)) - return; /* basis is linked with executable */ + return; /* basis is linked with executable */ /* * Check whether 'wfa_name' is a regular ASCII WFA initial basis file */ { - char magic [MAXSTRLEN]; /* WFA magic number */ + char magic [MAXSTRLEN]; /* WFA magic number */ if (!(input = open_file (filename, "FIASCO_DATA", READ_ACCESS))) - file_error(filename); + file_error(filename); if (fscanf (input, MAXSTRLEN_SCANF, magic) != 1) - error ("Format error: ASCII FIASCO initial basis file %s", filename); + error ("Format error: ASCII FIASCO initial basis file %s", filename); else if (!streq (FIASCO_BASIS_MAGIC, magic)) - error ("Input file %s is not an ASCII FIASCO initial basis!", - filename); + error ("Input file %s is not an ASCII FIASCO initial basis!", + filename); } /* @@ -273,74 +273,74 @@ read_basis (const char *filename, wfa_t *wfa) * Don't define any transitions of state 0 in an initial basis. * * Header: - * type |description - * ----------------+----------- - * string |MAGIC Number "Wfa" - * int |Number of basis states 'N' - * bool_t-array[N] |use vector in linear combinations, - * |0: don't use vector (auxiliary state) - * |1: use vector in linear combinations - * float-array[N] |final distribution of every state + * type |description + * ----------------+----------- + * string |MAGIC Number "Wfa" + * int |Number of basis states 'N' + * bool_t-array[N] |use vector in linear combinations, + * |0: don't use vector (auxiliary state) + * |1: use vector in linear combinations + * float-array[N] |final distribution of every state * * Transitions: * - * <state 1> current state - * <label> <into> <weight> transition 1 of current state - * <label> <into> <weight> transition 2 of current state + * <state 1> current state + * <label> <into> <weight> transition 1 of current state + * <label> <into> <weight> transition 2 of current state * ... - * <-1> last transition marker + * <-1> last transition marker * <state 2> * ... - * <-1> last transition marker + * <-1> last transition marker * <state N> * ... * - * <-1> last transition marker - * <-1> last state marker + * <-1> last transition marker + * <-1> last state marker */ { unsigned state; if (fscanf (input ,"%u", &wfa->basis_states) != 1) - error ("Format error: ASCII FIASCO initial basis file %s", filename); + error ("Format error: ASCII FIASCO initial basis file %s", filename); /* * State 0 is assumed to be the constant function f(x, y) = 128. */ wfa->domain_type [0] = USE_DOMAIN_MASK; wfa->final_distribution [0] = 128; - wfa->states = wfa->basis_states; + wfa->states = wfa->basis_states; wfa->basis_states++; append_edge (0, 0, 1.0, 0, wfa); append_edge (0, 0, 1.0, 1, wfa); for (state = 1; state < wfa->basis_states; state++) - wfa->domain_type [state] - = read_int (input) ? USE_DOMAIN_MASK : AUXILIARY_MASK; + wfa->domain_type [state] + = read_int (input) ? USE_DOMAIN_MASK : AUXILIARY_MASK; for (state = 1; state < wfa->basis_states; state++) - wfa->final_distribution[state] = read_real (input); + wfa->final_distribution[state] = read_real (input); /* * Read transitions */ for (state = 1; state < wfa->basis_states; state++) { - unsigned domain; - int label; - real_t weight; - - if (read_int (input) != (int) state) - error ("Format error: ASCII FIASCO initial basis file %s", - filename); - - while((label = read_int (input)) != -1) - { - domain = read_int (input); - weight = read_real (input); - append_edge (state, domain, weight, label, wfa); - } + unsigned domain; + int label; + real_t weight; + + if (read_int (input) != (int) state) + error ("Format error: ASCII FIASCO initial basis file %s", + filename); + + while((label = read_int (input)) != -1) + { + domain = read_int (input); + weight = read_real (input); + append_edge (state, domain, weight, label, wfa); + } } } @@ -357,13 +357,13 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) * No return value. * * Side effects: - * wfa->into, wfa->weights, wfa->final_distribution, wfa->states - * wfa->x, wfa->y, wfa->level_of_state, wfa->domain_type + * wfa->into, wfa->weights, wfa->final_distribution, wfa->states + * wfa->x, wfa->y, wfa->level_of_state, wfa->domain_type * mt->type, mt->number are filled with the values of the WFA file. */ { - tiling_t tiling; /* tiling information */ - unsigned frame_number; /* current frame number */ + tiling_t tiling; /* tiling information */ + unsigned frame_number; /* current frame number */ assert (wfa && input); @@ -371,14 +371,14 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) * Frame header information */ { - const unsigned rice_k = 8; /* parameter of Rice Code */ + const unsigned rice_k = 8; /* parameter of Rice Code */ wfa->states = read_rice_code (rice_k, input); wfa->frame_type = read_rice_code (rice_k, input); frame_number = read_rice_code (rice_k, input); } - if (wfa->wfainfo->release > 1) /* no alignment in version 1 */ + if (wfa->wfainfo->release > 1) /* no alignment in version 1 */ { INPUT_BYTE_ALIGN (input); } @@ -386,9 +386,9 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) /* * Read image tiling info */ - if (get_bit (input)) /* tiling performed ? */ + if (get_bit (input)) /* tiling performed ? */ read_tiling (&tiling, wfa->wfainfo->width, wfa->wfainfo->height, - wfa->wfainfo->level, input); + wfa->wfainfo->level, input); else tiling.exponent = 0; @@ -404,30 +404,30 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) unsigned state; for (state = wfa->basis_states; state < wfa->states; state++) - if ((!wfa->wfainfo->color - || (int) state <= wfa->tree [wfa->tree [wfa->root_state][0]][0]) - && - (!tiling.exponent || - wfa->level_of_state [state] <= (wfa->wfainfo->level - - tiling.exponent)) - && ((wfa->x [state][0] - + width_of_level (wfa->level_of_state [state])) - <= wfa->wfainfo->width) - && ((wfa->y [state][0] - + height_of_level (wfa->level_of_state [state])) - <= wfa->wfainfo->height)) - wfa->domain_type [state] = USE_DOMAIN_MASK; - else - wfa->domain_type [state] = 0; + if ((!wfa->wfainfo->color + || (int) state <= wfa->tree [wfa->tree [wfa->root_state][0]][0]) + && + (!tiling.exponent || + wfa->level_of_state [state] <= (wfa->wfainfo->level + - tiling.exponent)) + && ((wfa->x [state][0] + + width_of_level (wfa->level_of_state [state])) + <= wfa->wfainfo->width) + && ((wfa->y [state][0] + + height_of_level (wfa->level_of_state [state])) + <= wfa->wfainfo->height)) + wfa->domain_type [state] = USE_DOMAIN_MASK; + else + wfa->domain_type [state] = 0; } if (tiling.exponent) Free (tiling.vorder); - if (get_bit (input)) /* nondeterministic prediction used */ + if (get_bit (input)) /* nondeterministic prediction used */ read_nd (wfa, input); - if (wfa->frame_type != I_FRAME) /* motion compensation used */ + if (wfa->frame_type != I_FRAME) /* motion compensation used */ read_mc (wfa->frame_type, wfa, input); locate_delta_images (wfa); @@ -439,7 +439,7 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) unsigned edges = read_matrices (wfa, input); if (edges) - read_weights (edges, wfa, input); + read_weights (edges, wfa, input); } /* @@ -449,8 +449,8 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) unsigned state; for (state = wfa->basis_states; state <= wfa->states; state++) - wfa->final_distribution[state] - = compute_final_distribution (state, wfa); + wfa->final_distribution[state] + = compute_final_distribution (state, wfa); } return frame_number; @@ -458,13 +458,13 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) /***************************************************************************** - private code + private code *****************************************************************************/ static void read_tiling (tiling_t *tiling, unsigned image_width, unsigned image_height, - unsigned image_level, bitfile_t *input) + unsigned image_level, bitfile_t *input) /* * Read image tiling information from the given file 'input' * and store parameters in struct 'tiling'. @@ -472,32 +472,32 @@ read_tiling (tiling_t *tiling, unsigned image_width, unsigned image_height, * No return value. */ { - const unsigned rice_k = 8; /* parameter of Rice Code */ + const unsigned rice_k = 8; /* parameter of Rice Code */ tiling->exponent = read_rice_code (rice_k, input); - if (get_bit (input)) /* variance order */ + if (get_bit (input)) /* variance order */ { - unsigned tile; /* current image tile */ - unsigned x0, y0; /* NW corner of image tile */ - unsigned width, height; /* size of image tile */ + unsigned tile; /* current image tile */ + unsigned x0, y0; /* NW corner of image tile */ + unsigned width, height; /* size of image tile */ tiling->vorder = Calloc (1 << tiling->exponent, sizeof (int)); for (tile = 0; tile < 1U << tiling->exponent; tile++) { - locate_subimage (image_level, image_level - tiling->exponent, tile, - &x0, &y0, &width, &height); - if (x0 < image_width && y0 < image_height) - tiling->vorder [tile] = get_bits (input, tiling->exponent); - else - tiling->vorder [tile] = -1; + locate_subimage (image_level, image_level - tiling->exponent, tile, + &x0, &y0, &width, &height); + if (x0 < image_width && y0 < image_height) + tiling->vorder [tile] = get_bits (input, tiling->exponent); + else + tiling->vorder [tile] = -1; } } - else /* spiral order */ + else /* spiral order */ { tiling->vorder = Calloc (1 << tiling->exponent, sizeof (int)); compute_spiral (tiling->vorder, image_width, image_height, - tiling->exponent, get_bit (input) ? YES : NO); + tiling->exponent, get_bit (input) ? YES : NO); } } diff --git a/converter/other/fiasco/input/read.h b/converter/other/fiasco/input/read.h index 1f59f103..f41cb874 100644 --- a/converter/other/fiasco/input/read.h +++ b/converter/other/fiasco/input/read.h @@ -1,8 +1,8 @@ /* * read.h * - * 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 */ diff --git a/converter/other/fiasco/input/tree.c b/converter/other/fiasco/input/tree.c index 74ceeb68..8d81ae1b 100644 --- a/converter/other/fiasco/input/tree.c +++ b/converter/other/fiasco/input/tree.c @@ -1,7 +1,7 @@ /* - * tree.c: Input of bintree partitioning + * tree.c: Input 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 @@ -30,22 +30,22 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static unsigned restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, - unsigned y, unsigned *dst_state, - word_t (*bfo_tree)[MAXLABELS], - wfa_t *wfa, tiling_t *tiling); + unsigned y, unsigned *dst_state, + word_t (*bfo_tree)[MAXLABELS], + wfa_t *wfa, tiling_t *tiling); static void decode_tree (bitfile_t *input, byte_t *data, unsigned n_data, unsigned scaling, - u_word_t sum0, u_word_t sum1); + u_word_t sum0, u_word_t sum1); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -58,12 +58,12 @@ read_tree (wfa_t *wfa, tiling_t *tiling, bitfile_t *input) * No return value. * * Side effects: - * 'wfa->tree', 'wfa->x', 'wfa->y', 'wfa->level_of_state' + * 'wfa->tree', 'wfa->x', 'wfa->y', 'wfa->level_of_state' * are filled with decoded values. */ { - byte_t *bitstring; /* the encoded data */ - word_t (*bfo_tree)[MAXLABELS]; /* node numbers in BFO */ + byte_t *bitstring; /* the encoded data */ + word_t (*bfo_tree)[MAXLABELS]; /* node numbers in BFO */ /* * Read WFA tree stored in breadth first order @@ -80,15 +80,15 @@ read_tree (wfa_t *wfa, tiling_t *tiling, bitfile_t *input) * Generate tree using a breadth first traversal */ { - unsigned next; /* next free node number of the tree */ - unsigned state; - unsigned label; - byte_t *buffer = bitstring; /* pointer to decoded data */ + unsigned next; /* next free node number of the tree */ + unsigned state; + unsigned label; + byte_t *buffer = bitstring; /* pointer to decoded data */ bfo_tree = Calloc (wfa->states * MAXLABELS, sizeof (word_t)); for (state = 0, next = 1; state < next; state++) - for (label = 0; label < MAXLABELS; label++) - bfo_tree [state][label] = *buffer++ ? next++ : RANGE; + for (label = 0; label < MAXLABELS; label++) + bfo_tree [state][label] = *buffer++ ? next++ : RANGE; } /* @@ -98,9 +98,9 @@ read_tree (wfa_t *wfa, tiling_t *tiling, bitfile_t *input) unsigned dst_state = wfa->basis_states; wfa->root_state - = restore_depth_first_order (0, (wfa->wfainfo->level - + (wfa->wfainfo->color ? 2 : 0)), - 0, 0, &dst_state, bfo_tree, wfa, tiling); + = restore_depth_first_order (0, (wfa->wfainfo->level + + (wfa->wfainfo->color ? 2 : 0)), + 0, 0, &dst_state, bfo_tree, wfa, tiling); } Free (bitstring); @@ -109,15 +109,15 @@ read_tree (wfa_t *wfa, tiling_t *tiling, bitfile_t *input) /***************************************************************************** - private code + private code *****************************************************************************/ static unsigned restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, - unsigned y, unsigned *dst_state, - word_t (*bfo_tree)[MAXLABELS], - wfa_t *wfa, tiling_t *tiling) + unsigned y, unsigned *dst_state, + word_t (*bfo_tree)[MAXLABELS], + wfa_t *wfa, tiling_t *tiling) /* * Map state 'src_state' (breadth first order) * to state '*dst_state' (depth first order) @@ -127,17 +127,17 @@ restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, * of size 'image_level'. 'tiling' defines the image partitioning. * * Return value: - * new node number in depth first order + * new node number in depth first order * * Side effects: - * 'wfa->tree', 'wfa->x', 'wfa->y', 'wfa->level_of_state' + * 'wfa->tree', 'wfa->x', 'wfa->y', 'wfa->level_of_state' * are filled with decoded values. */ { - unsigned newx [MAXLABELS]; /* x coordinate of children */ - unsigned newy [MAXLABELS]; /* y coordinate of children */ - unsigned x0, y0; /* NW corner of image tile */ - unsigned width, height; /* size of image tile */ + unsigned newx [MAXLABELS]; /* x coordinate of children */ + unsigned newy [MAXLABELS]; /* y coordinate of children */ + unsigned x0, y0; /* NW corner of image tile */ + unsigned width, height; /* size of image tile */ /* * If tiling is performed then replace current coordinates @@ -148,14 +148,14 @@ restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, for (tile = 0; tile < 1U << tiling->exponent; tile++) { - locate_subimage (wfa->wfainfo->level, level, tile, - &x0, &y0, &width, &height); - if (x0 == x && y0 == y) /* matched ! */ - { - locate_subimage (wfa->wfainfo->level, level, tiling->vorder[tile], - &x, &y, &width, &height); - break; - } + locate_subimage (wfa->wfainfo->level, level, tile, + &x0, &y0, &width, &height); + if (x0 == x && y0 == y) /* matched ! */ + { + locate_subimage (wfa->wfainfo->level, level, tiling->vorder[tile], + &x, &y, &width, &height); + break; + } } } /* @@ -175,24 +175,24 @@ restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, * Remap node numbers */ { - int child [MAXLABELS]; /* children of current node (state) */ - int domain; /* current domain */ + int child [MAXLABELS]; /* children of current node (state) */ + int domain; /* current domain */ unsigned label; for (label = 0; label < MAXLABELS; label++) - if (!isrange (domain = bfo_tree [src_state][label])) - child [label] = restore_depth_first_order (domain, level - 1, - newx [label], - newy [label], dst_state, - bfo_tree, wfa, tiling); - else - child [label] = RANGE; + if (!isrange (domain = bfo_tree [src_state][label])) + child [label] = restore_depth_first_order (domain, level - 1, + newx [label], + newy [label], dst_state, + bfo_tree, wfa, tiling); + else + child [label] = RANGE; for (label = 0; label < MAXLABELS; label++) { - wfa->tree [*dst_state][label] = child [label]; - wfa->x [*dst_state][label] = newx [label]; - wfa->y [*dst_state][label] = newy [label]; + wfa->tree [*dst_state][label] = child [label]; + wfa->x [*dst_state][label] = newx [label]; + wfa->y [*dst_state][label] = newy [label]; } wfa->level_of_state [*dst_state] = level; } @@ -208,26 +208,26 @@ restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, static void decode_tree (bitfile_t *input, byte_t *data, unsigned n_data, unsigned scaling, - u_word_t sum0, u_word_t sum1) + u_word_t sum0, u_word_t sum1) /* * Decode bintree partitioning using adaptive binary arithmetic decoding. - * 'input' input stream, - * 'data' buffer for decoded szmbols, - * 'n_data' number of symbols to decode, - * 'scaling' rescale probability models if range > 'scaling' - * 'sum0' initial totals of symbol '0' - * 'sum1' initial totals of symbol '1' + * 'input' input stream, + * 'data' buffer for decoded szmbols, + * 'n_data' number of symbols to decode, + * 'scaling' rescale probability models if range > 'scaling' + * 'sum0' initial totals of symbol '0' + * 'sum1' initial totals of symbol '1' * * No return value. * * Side effects: - * 'data []' is filled with the decoded bitstring + * 'data []' is filled with the decoded bitstring */ { - u_word_t code; /* The present input code value */ - u_word_t low; /* Start of the current code range */ - u_word_t high; /* End of the current code range */ - unsigned n; /* Data counter */ + u_word_t code; /* The present input code value */ + u_word_t low; /* Start of the current code range */ + u_word_t high; /* End of the current code range */ + unsigned n; /* Data counter */ assert (data); @@ -237,64 +237,64 @@ decode_tree (bitfile_t *input, byte_t *data, unsigned n_data, unsigned scaling, for (n = n_data; n; n--) { - unsigned count; /* Current interval count */ - unsigned range; /* Current interval range */ + unsigned count; /* Current interval count */ + unsigned range; /* Current interval range */ count = (((code - low) + 1) * sum1 - 1) / ((high - low) + 1); if (count < sum0) { - /* - * Decode a '0' symbol - * First, the range is expanded to account for the symbol removal. - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum0) / sum1 - 1 ); - - RESCALE_INPUT_INTERVAL; - - *data++ = 0; - /* - * Update the frequency counts - */ - sum0++; - sum1++; - if (sum1 > scaling) /* scale the symbol frequencies */ - { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; - } + /* + * Decode a '0' symbol + * First, the range is expanded to account for the symbol removal. + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum0) / sum1 - 1 ); + + RESCALE_INPUT_INTERVAL; + + *data++ = 0; + /* + * Update the frequency counts + */ + sum0++; + sum1++; + if (sum1 > scaling) /* scale the symbol frequencies */ + { + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; + } } else { - /* - * Decode a '1' symbol - * First, the range is expanded to account for the symbol removal. - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum1) / sum1 - 1); - low = low + (u_word_t) ((range * sum0) / sum1); - - RESCALE_INPUT_INTERVAL; - - *data++ = 1; - /* - * Update the frequency counts - */ - sum1++; - if (sum1 > scaling) /* scale the symbol frequencies */ - { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; - } + /* + * Decode a '1' symbol + * First, the range is expanded to account for the symbol removal. + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum1) / sum1 - 1); + low = low + (u_word_t) ((range * sum0) / sum1); + + RESCALE_INPUT_INTERVAL; + + *data++ = 1; + /* + * Update the frequency counts + */ + sum1++; + if (sum1 > scaling) /* scale the symbol frequencies */ + { + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; + } } } INPUT_BYTE_ALIGN (input); diff --git a/converter/other/fiasco/input/tree.h b/converter/other/fiasco/input/tree.h index f743ee98..31b73fa5 100644 --- a/converter/other/fiasco/input/tree.h +++ b/converter/other/fiasco/input/tree.h @@ -1,8 +1,8 @@ /* * tree.h * - * 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 */ diff --git a/converter/other/fiasco/input/weights.c b/converter/other/fiasco/input/weights.c index 8a1e8899..debf38ad 100644 --- a/converter/other/fiasco/input/weights.c +++ b/converter/other/fiasco/input/weights.c @@ -2,7 +2,7 @@ * weights.c: Input of weights * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -32,7 +32,7 @@ /***************************************************************************** public code - + *****************************************************************************/ void @@ -55,7 +55,7 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input) unsigned offset1, offset2; /* prob. model offsets. */ unsigned offset3, offset4; /* prob. model offsets. */ bool_t delta_approx = NO; /* true if delta has been used */ - + /* * Check whether delta approximation has been used */ @@ -65,7 +65,7 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input) delta_approx = YES; break; } - + /* * Generate array of corresponding levels (context of probability model) */ @@ -82,7 +82,7 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input) min_level = d_min_level = MAXLEVEL; max_level = d_max_level = 0; dc = d_dc = NO; - + for (state = wfa->basis_states; state < wfa->states; state++) for (label = 0; label < MAXLABELS; label++) if (isrange (wfa->tree [state][label])) @@ -156,7 +156,7 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input) c_symbols [i] = 1 << (wfa->wfainfo->rpf->mantissa_bits + 1); for (; i < offset4; i++) c_symbols [i] = 1 << (wfa->wfainfo->d_rpf->mantissa_bits + 1); - + weights_array = decode_array (input, level_array, c_symbols, offset4, total, scale); Free (c_symbols); @@ -198,7 +198,7 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input) = wfa->weight [state][label][edge] * 512 + 0.5; } } - + Free (weights_array); } - + diff --git a/converter/other/fiasco/input/weights.h b/converter/other/fiasco/input/weights.h index 36cea5c2..4a6bdf0a 100644 --- a/converter/other/fiasco/input/weights.h +++ b/converter/other/fiasco/input/weights.h @@ -1,8 +1,8 @@ /* * weights.h * - * 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 */ |