diff options
Diffstat (limited to 'converter/other/fiasco/output')
-rw-r--r-- | converter/other/fiasco/output/matrices.c | 560 | ||||
-rw-r--r-- | converter/other/fiasco/output/matrices.h | 6 | ||||
-rw-r--r-- | converter/other/fiasco/output/mc.c | 200 | ||||
-rw-r--r-- | converter/other/fiasco/output/mc.h | 6 | ||||
-rw-r--r-- | converter/other/fiasco/output/nd.c | 180 | ||||
-rw-r--r-- | converter/other/fiasco/output/nd.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/output/tree.c | 98 | ||||
-rw-r--r-- | converter/other/fiasco/output/tree.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/output/weights.c | 76 | ||||
-rw-r--r-- | converter/other/fiasco/output/weights.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/output/write.c | 58 | ||||
-rw-r--r-- | converter/other/fiasco/output/write.h | 4 |
12 files changed, 600 insertions, 600 deletions
diff --git a/converter/other/fiasco/output/matrices.c b/converter/other/fiasco/output/matrices.c index 7dc0e6d9..32289dec 100644 --- a/converter/other/fiasco/output/matrices.c +++ b/converter/other/fiasco/output/matrices.c @@ -1,8 +1,8 @@ /* - * matrices.c: Output of transitions matrices + * matrices.c: Output of transitions 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 */ @@ -38,13 +38,13 @@ /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ static unsigned delta_encoding (bool_t use_normal_domains, bool_t use_delta_domains, - const wfa_t *wfa, unsigned last_domain, bitfile_t *output); + const wfa_t *wfa, unsigned last_domain, bitfile_t *output); static unsigned column_0_encoding (const wfa_t *wfa, unsigned last_row, bitfile_t *output); static unsigned @@ -52,75 +52,75 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output); /***************************************************************************** - public code - + public code + *****************************************************************************/ unsigned write_matrices (bool_t use_normal_domains, bool_t use_delta_domains, - const wfa_t *wfa, bitfile_t *output) + const wfa_t *wfa, bitfile_t *output) /* * Write transition matrices of 'wfa' to stream 'output'. * * Return value: - * number of transitions encoded + * number of transitions encoded */ { - unsigned root_state; /* root of luminance */ - unsigned total = 0; /* number of transitions */ - + unsigned root_state; /* root of luminance */ + unsigned total = 0; /* number of transitions */ + 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_encoding (wfa, root_state, output); total += delta_encoding (use_normal_domains, use_delta_domains, - wfa, root_state, output); - + wfa, root_state, output); + if (wfa->wfainfo->color) total += chroma_encoding (wfa, output); - + return total; } /***************************************************************************** - private code - + private code + *****************************************************************************/ static unsigned delta_encoding (bool_t use_normal_domains, bool_t use_delta_domains, - const wfa_t *wfa, unsigned last_domain, bitfile_t *output) + const wfa_t *wfa, unsigned last_domain, bitfile_t *output) /* * Write transition matrices with delta coding to stream '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) */ { - range_sort_t rs; /* ranges are sorted as in the coder */ - unsigned max_domain; /* dummy used for recursion */ - unsigned total = 0; - + range_sort_t rs; /* ranges are sorted as in the coder */ + unsigned max_domain; /* dummy used for recursion */ + unsigned total = 0; + /* * 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); - + /* * Compute and write distribution of #edges */ @@ -132,138 +132,138 @@ delta_encoding (bool_t use_normal_domains, bool_t use_delta_domains, unsigned edges = 0; unsigned M = 0; unsigned bits = bits_processed (output); - + for (n = 0; n < MAXEDGES + 1; n++) - count [n] = 0; - + count [n] = 0; + for (state = wfa->basis_states; state <= last_domain; state++) - for (label = 0; label < MAXLABELS; label++) - if (isrange (wfa->tree [state][label])) - { - for (edge = 0; isedge (wfa->into [state][label][edge]); edge++) - ; - count [edge]++; - edges++; - M = MAX(edge, M); - } + for (label = 0; label < MAXLABELS; label++) + if (isrange (wfa->tree [state][label])) + { + for (edge = 0; isedge (wfa->into [state][label][edge]); edge++) + ; + count [edge]++; + edges++; + M = MAX(edge, M); + } write_rice_code (M, 3, output); for (n = 0; n <= M; n++) /* NETPBM: The following causes a crash when last_domain < 4, because it requests writing of a negative number of bits. And we have seen - last_domain = 3. But we have no clue what last_domain means, or + last_domain = 3. But we have no clue what last_domain means, or even what a rice code is, so we don't know where the error lies. - -Bryan 2001.02.09 + -Bryan 2001.02.09 */ - write_rice_code (count [n], (int) log2 (last_domain) - 2, output); + write_rice_code (count [n], (int) log2 (last_domain) - 2, output); /* * Arithmetic coding of values */ { - unsigned range; - model_t *elements = alloc_model (M + 1, 0, 0, count); - arith_t *encoder = alloc_encoder (output); - - for (range = 0; range < rs.range_no; range++) - if (!rs.range_subdivided [range]) - { - state = rs.range_state [range]; - label = rs.range_label [range]; - for (edge = 0; isedge (wfa->into [state][label][edge]); edge++) - ; - - encode_symbol (edge, encoder, elements); - } - free_encoder (encoder); - free_model (elements); + unsigned range; + model_t *elements = alloc_model (M + 1, 0, 0, count); + arith_t *encoder = alloc_encoder (output); + + for (range = 0; range < rs.range_no; range++) + if (!rs.range_subdivided [range]) + { + state = rs.range_state [range]; + label = rs.range_label [range]; + for (edge = 0; isedge (wfa->into [state][label][edge]); edge++) + ; + + encode_symbol (edge, encoder, elements); + } + free_encoder (encoder); + free_model (elements); } debug_message ("delta-#edges: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, edges, - edges > 0 ? ((bits_processed (output) - bits) / - (double) edges) : 0); + bits_processed (output) - bits, edges, + edges > 0 ? ((bits_processed (output) - bits) / + (double) edges) : 0); } /* * Write matrix elements */ { - unsigned bits = bits_processed (output); + unsigned bits = bits_processed (output); u_word_t *mapping1 = Calloc (wfa->states, sizeof (u_word_t)); u_word_t *mapping2 = Calloc (wfa->states, sizeof (u_word_t)); - unsigned range; + unsigned range; put_bit (output, use_normal_domains); put_bit (output, use_delta_domains); - + /* * Generate array of states which are admitted domains. * When coding intra frames 'mapping1' == 'mapping2' otherwise - * 'mapping1' is a list of 'normal' domains which are admitted for + * 'mapping1' is a list of 'normal' domains which are admitted for * coding intra blocks * 'mapping2' is a list of 'delta' domains which are admitted for - * coding the motion compensated prediction error + * coding the motion compensated prediction error */ { - unsigned n1, n2, state; - - for (n1 = n2 = state = 0; state < wfa->states; state++) - { - mapping1 [state] = n1; - if (usedomain (state, wfa) - && (state < wfa->basis_states || use_delta_domains - || !wfa->delta_state [state])) - n1++; - - mapping2 [state] = n2; - if (usedomain (state, wfa) - && (state < wfa->basis_states || use_normal_domains - || wfa->delta_state [state])) - n2++; - } - debug_message ("# normal states = %d, # delta states = %d," - " # WFA states = %d", n1, n2, wfa->states); + unsigned n1, n2, state; + + for (n1 = n2 = state = 0; state < wfa->states; state++) + { + mapping1 [state] = n1; + if (usedomain (state, wfa) + && (state < wfa->basis_states || use_delta_domains + || !wfa->delta_state [state])) + n1++; + + mapping2 [state] = n2; + if (usedomain (state, wfa) + && (state < wfa->basis_states || use_normal_domains + || wfa->delta_state [state])) + n2++; + } + debug_message ("# normal states = %d, # delta states = %d," + " # WFA states = %d", n1, n2, wfa->states); } - + for (range = 0; range < rs.range_no; range++) - if (!rs.range_subdivided [range]) - { - unsigned state = rs.range_state [range]; - unsigned label = rs.range_label [range]; - unsigned last = 1; - u_word_t *mapping; - unsigned max_value; - unsigned edge; - word_t domain; - - if (wfa->delta_state [state] || - wfa->mv_tree [state][label].type != NONE) - mapping = mapping2; - else - mapping = mapping1; - - max_value = mapping [rs.range_max_domain [range]]; - - for (edge = 0; isedge (domain = wfa->into [state][label][edge]); - edge++) - if (domain > 0) - { - total++; - if (max_value - last) - { - write_bin_code (mapping [domain] - last, - max_value - last, output); - last = mapping [domain] + 1; - } - } - } + if (!rs.range_subdivided [range]) + { + unsigned state = rs.range_state [range]; + unsigned label = rs.range_label [range]; + unsigned last = 1; + u_word_t *mapping; + unsigned max_value; + unsigned edge; + word_t domain; + + if (wfa->delta_state [state] || + wfa->mv_tree [state][label].type != NONE) + mapping = mapping2; + else + mapping = mapping1; + + max_value = mapping [rs.range_max_domain [range]]; + + for (edge = 0; isedge (domain = wfa->into [state][label][edge]); + edge++) + if (domain > 0) + { + total++; + if (max_value - last) + { + write_bin_code (mapping [domain] - last, + max_value - last, output); + last = mapping [domain] + 1; + } + } + } debug_message ("delta-index: %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); Free (mapping1); Free (mapping2); } - + Free (rs.range_state); Free (rs.range_label); Free (rs.range_max_domain); @@ -280,17 +280,17 @@ column_0_encoding (const wfa_t *wfa, unsigned last_row, bitfile_t *output) * 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) */ { - u_word_t high; /* Start of the current code range */ - u_word_t low; /* End of the current code range */ - unsigned *prob; /* probability array */ - unsigned row; /* current matrix row */ - unsigned label; /* current matrix label */ - unsigned underflow; /* Underflow bits */ - unsigned index; /* probability index */ - unsigned total = 0; /* Number of '1' elements */ + u_word_t high; /* Start of the current code range */ + u_word_t low; /* End of the current code range */ + unsigned *prob; /* probability array */ + unsigned row; /* current matrix row */ + unsigned label; /* current matrix label */ + unsigned underflow; /* Underflow bits */ + unsigned index; /* probability index */ + unsigned total = 0; /* Number of '1' elements */ unsigned bits = bits_processed (output); /* @@ -300,18 +300,18 @@ column_0_encoding (const wfa_t *wfa, unsigned last_row, bitfile_t *output) */ { unsigned n; - unsigned exp; /* current exponent */ - + 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 */ - underflow = 0; /* no underflow bits */ + + high = HIGH; /* 1.0 */ + low = LOW; /* 0.0 */ + underflow = 0; /* no underflow bits */ index = 0; @@ -325,50 +325,50 @@ column_0_encoding (const wfa_t *wfa, unsigned last_row, bitfile_t *output) */ for (row = wfa->basis_states; row <= last_row; row++) for (label = 0; label < MAXLABELS; label++) - if (isrange (wfa->tree [row][label])) - { - if (wfa->into [row][label][0] != 0) - { - /* - * encode the MPS '0' - */ - high = high - ((high - low) >> prob [index]) - 1; - RESCALE_OUTPUT_INTERVAL; - - if (index < 1020) - index++; - } - else - { - /* - * encode the LPS '1' - */ - low = high - ((high - low) >> prob [index]); - - RESCALE_OUTPUT_INTERVAL; - - total++; - index >>= 1; - } - } + if (isrange (wfa->tree [row][label])) + { + if (wfa->into [row][label][0] != 0) + { + /* + * encode the MPS '0' + */ + high = high - ((high - low) >> prob [index]) - 1; + RESCALE_OUTPUT_INTERVAL; + + if (index < 1020) + index++; + } + else + { + /* + * encode the LPS '1' + */ + low = high - ((high - low) >> prob [index]); + + RESCALE_OUTPUT_INTERVAL; + + total++; + index >>= 1; + } + } /* * Flush the quasi-arithmetic encoder */ low = high; RESCALE_OUTPUT_INTERVAL; - + OUTPUT_BYTE_ALIGN (output); Free (prob); debug_message ("delta-state0: %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); return total; -} +} static unsigned chroma_encoding (const wfa_t *wfa, bitfile_t *output) @@ -377,24 +377,24 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output) * chroma channels Cb and Cr to stream 'output'. * * Return value: - * number of non-zero matrix elements (WFA edges) + * number of non-zero matrix elements (WFA edges) */ { - unsigned domain; /* current domain, counter */ - unsigned label; /* current label */ - unsigned total = 0; /* number of '1' elements */ - u_word_t high; /* Start of the current code range */ - u_word_t low; /* End of the current code range */ - unsigned underflow; /* underflow bits */ - unsigned *prob; /* probability array */ - unsigned index; /* probability index, counter */ - unsigned next_index; /* probability of last domain */ - unsigned row; /* current matrix row */ + unsigned domain; /* current domain, counter */ + unsigned label; /* current label */ + unsigned total = 0; /* number of '1' elements */ + u_word_t high; /* Start of the current code range */ + u_word_t low; /* End of the current code range */ + unsigned underflow; /* underflow bits */ + unsigned *prob; /* probability array */ + unsigned index; /* probability index, counter */ + unsigned next_index; /* probability of last domain */ + unsigned row; /* current matrix row */ word_t *y_domains; - unsigned count = 0; /* number of transitions for part 1 */ + unsigned count = 0; /* number of transitions for part 1 */ unsigned bits = bits_processed (output); - + /* * Compute the asymmetric probability array * prob[] = { 1/2, 1/2, 1/4, 1/4, 1/4, 1/4, @@ -402,24 +402,24 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output) */ { unsigned n; - unsigned exp; /* current exponent */ - + 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 */ - underflow = 0; /* no underflow bits */ + + high = HIGH; /* 1.0 */ + low = LOW; /* 0.0 */ + underflow = 0; /* no underflow bits */ next_index = index = 0; 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 of all, read all matrix columns given in the list 'y_domains' @@ -428,67 +428,67 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output) */ for (domain = 0; y_domains [domain] != -1; domain++) { - bool_t save_index = YES; /* YES: store current prob. index */ - + bool_t save_index = YES; /* YES: store current prob. index */ + row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; index = next_index; - + for (; row < wfa->states; row++) { - for (label = 0; label < MAXLABELS; label++) - if (isrange (wfa->tree [row][label])) - { - unsigned edge; - int into; - bool_t match; /* approx with current domain found */ - - for (match = NO, edge = 0; - isedge (into = wfa->into [row][label][edge]) - && (unsigned) into < row; - edge++) - if (into == y_domains [domain] - && into != wfa->y_state [row][label]) - match = YES; - if (!match) - { - /* - * encode the MPS '0' - */ - high = high - ((high - low) >> prob [index]) - 1; - - RESCALE_OUTPUT_INTERVAL; - - if (index < 1020) - index++; - } - else - { - /* - * encode the LPS '1' - */ - low = high - ((high - low) >> prob [index]); - - RESCALE_OUTPUT_INTERVAL; - - total++; - index >>= 1; - } - } - if (save_index) - { - next_index = index; - save_index = NO; - } + for (label = 0; label < MAXLABELS; label++) + if (isrange (wfa->tree [row][label])) + { + unsigned edge; + int into; + bool_t match; /* approx with current domain found */ + + for (match = NO, edge = 0; + isedge (into = wfa->into [row][label][edge]) + && (unsigned) into < row; + edge++) + if (into == y_domains [domain] + && into != wfa->y_state [row][label]) + match = YES; + if (!match) + { + /* + * encode the MPS '0' + */ + high = high - ((high - low) >> prob [index]) - 1; + + RESCALE_OUTPUT_INTERVAL; + + if (index < 1020) + index++; + } + else + { + /* + * encode the LPS '1' + */ + low = high - ((high - low) >> prob [index]); + + RESCALE_OUTPUT_INTERVAL; + + total++; + index >>= 1; + } + } + if (save_index) + { + next_index = index; + save_index = NO; + } } } debug_message ("CbCr_matrix: %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); count = total; bits = bits_processed (output); - + /* * Encode the additional column which indicates whether there * are transitions to a state with same spatial coordinates @@ -500,32 +500,32 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output) next_index = index = 0; for (row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; - row < wfa->states; row++) + row < wfa->states; row++) for (label = 0; label < MAXLABELS; label++) - if (!wfa->y_column [row][label]) - { - /* - * encode the MPS '0' - */ - high = high - ((high - low) >> prob [index]) - 1; - - RESCALE_OUTPUT_INTERVAL; - - if (index < 1020) - index++; - } - else - { - /* - * encode the LPS '1' - */ - low = high - ((high - low) >> prob [index]); - - RESCALE_OUTPUT_INTERVAL; - - index >>= 1; - total++; - } + if (!wfa->y_column [row][label]) + { + /* + * encode the MPS '0' + */ + high = high - ((high - low) >> prob [index]) - 1; + + RESCALE_OUTPUT_INTERVAL; + + if (index < 1020) + index++; + } + else + { + /* + * encode the LPS '1' + */ + low = high - ((high - low) >> prob [index]); + + RESCALE_OUTPUT_INTERVAL; + + index >>= 1; + total++; + } /* * Flush the quasi-arithmetic encoder @@ -536,12 +536,12 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output) OUTPUT_BYTE_ALIGN (output); debug_message ("Yreferences: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total - count, - total - count > 0 ? ((bits_processed (output) - bits) / - (double) (total - count)) : 0); + bits_processed (output) - bits, total - count, + total - count > 0 ? ((bits_processed (output) - bits) / + (double) (total - count)) : 0); Free (prob); Free (y_domains); - + return total; } diff --git a/converter/other/fiasco/output/matrices.h b/converter/other/fiasco/output/matrices.h index 44671496..6e6ec8a5 100644 --- a/converter/other/fiasco/output/matrices.h +++ b/converter/other/fiasco/output/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 */ @@ -22,7 +22,7 @@ unsigned write_matrices (bool_t use_normal_domains, bool_t use_delta_domains, - const wfa_t *wfa, bitfile_t *output); + const wfa_t *wfa, bitfile_t *output); #endif /* _MATRICES_H */ diff --git a/converter/other/fiasco/output/mc.c b/converter/other/fiasco/output/mc.c index 170a2648..06ed0524 100644 --- a/converter/other/fiasco/output/mc.c +++ b/converter/other/fiasco/output/mc.c @@ -1,8 +1,8 @@ /* - * mc.c: Output of motion compensation + * mc.c: Output of motion compensation * - * Written by: Michael Unger - * Ullrich Hafner + * Written by: Michael Unger + * Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -29,7 +29,7 @@ /***************************************************************************** - local variables + local variables *****************************************************************************/ @@ -55,19 +55,19 @@ enum vlc_e {CODE = 0, BITS = 1}; /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void encode_mc_tree (unsigned max_state, frame_type_e frame_type, const wfa_t *wfa, - bitfile_t *output); + bitfile_t *output); static void encode_mc_coords (unsigned max_state, const wfa_t *wfa, bitfile_t *output); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -75,8 +75,8 @@ void write_mc (frame_type_e frame_type, const wfa_t *wfa, bitfile_t *output) { 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; encode_mc_tree (max_state, frame_type, wfa, output); encode_mc_coords (max_state, wfa, output); @@ -84,13 +84,13 @@ write_mc (frame_type_e frame_type, const wfa_t *wfa, bitfile_t *output) /***************************************************************************** - private code + private code *****************************************************************************/ static void encode_mc_tree (unsigned max_state, frame_type_e frame_type, const wfa_t *wfa, - bitfile_t *output) + bitfile_t *output) /* * Write tree of motion compensation decisions to the 'output' stream. * Depending on 'frame_type' different decoding methods are used. @@ -99,20 +99,20 @@ encode_mc_tree (unsigned max_state, frame_type_e frame_type, const wfa_t *wfa, * No return value. */ { - unsigned label; /* current label */ - unsigned state; /* current state */ - unsigned total = 0; /* number of motion tree decisions */ - unsigned queue [MAXSTATES]; /* state numbers in BFO */ - unsigned current; /* current node to process */ - unsigned last; /* last node (update every new node) */ - mc_type_e type; /* type of motion compensation */ - unsigned (*mc_tree_codes)[2]; /* pointer to VLC table */ + unsigned label; /* current label */ + unsigned state; /* current state */ + unsigned total = 0; /* number of motion tree decisions */ + unsigned queue [MAXSTATES]; /* state numbers in BFO */ + unsigned current; /* current node to process */ + unsigned last; /* last node (update every new node) */ + mc_type_e type; /* type of motion compensation */ + unsigned (*mc_tree_codes)[2]; /* pointer to VLC table */ unsigned bits = bits_processed (output); /* number of bits used */ if (frame_type == P_FRAME) - mc_tree_codes = p_frame_codes; /* binary code */ + mc_tree_codes = p_frame_codes; /* binary code */ else - mc_tree_codes = b_frame_codes; /* variable length code */ + mc_tree_codes = b_frame_codes; /* variable length code */ /* * Traverse tree in breadth first order (starting at @@ -122,37 +122,37 @@ encode_mc_tree (unsigned max_state, frame_type_e frame_type, const wfa_t *wfa, 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 = 'mc_max_level' */ + queue [last++] = state; /* init level = 'mc_max_level' */ for (current = 0; current < last; current++) for (label = 0; label < MAXLABELS; label++) { - state = queue [current]; - type = wfa->mv_tree [state][label].type; - if (wfa->x [state][label] - + 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) - { - put_bits (output, mc_tree_codes [type][CODE], - mc_tree_codes [type][BITS]); - total++; - } - if (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 */ + state = queue [current]; + type = wfa->mv_tree [state][label].type; + if (wfa->x [state][label] + + 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) + { + put_bits (output, mc_tree_codes [type][CODE], + mc_tree_codes [type][BITS]); + total++; + } + if (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 */ } OUTPUT_BYTE_ALIGN (output); debug_message ("mc-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); } static void @@ -165,85 +165,85 @@ encode_mc_coords (unsigned max_state, const wfa_t *wfa, bitfile_t *output) * No return value. */ { - unsigned state; /* current state */ - unsigned label; /* current label */ - unsigned level_count [MAXLEVEL]; /* number of mv per level */ - unsigned level; /* counter */ - unsigned ftotal = 0; /* #forward motion tree decisions */ - unsigned btotal = 0; /* #backward decisions */ - unsigned itotal = 0; /* #interpolated decisions */ + unsigned state; /* current state */ + unsigned label; /* current label */ + unsigned level_count [MAXLEVEL]; /* number of mv per level */ + unsigned level; /* counter */ + unsigned ftotal = 0; /* #forward motion tree decisions */ + unsigned btotal = 0; /* #backward decisions */ + unsigned itotal = 0; /* #interpolated decisions */ unsigned bits = bits_processed (output); /* number of bits used */ unsigned sr = wfa->wfainfo->search_range; /* search range */ for (level = wfa->wfainfo->p_max_level; - level >= wfa->wfainfo->p_min_level; level--) + level >= wfa->wfainfo->p_min_level; level--) level_count [level] = 0; for (state = wfa->basis_states; state < max_state; state++) for (label = 0; label < MAXLABELS; label++) { - mv_t *mv = &wfa->mv_tree[state][label]; /* motion vector info */ - - if (mv->type != NONE) - { - level_count [wfa->level_of_state [state] - 1]++; - switch (mv->type) - { - case FORWARD: - put_bits (output, - mv_code_table[(mv->fx + sr)][CODE], - mv_code_table[(mv->fx + sr)][BITS]); - put_bits (output, - mv_code_table[(mv->fy + sr)][CODE], - mv_code_table[(mv->fy + sr)][BITS]); - ftotal++; - break; - case BACKWARD: - put_bits (output, - mv_code_table[(mv->bx + sr)][CODE], - mv_code_table[(mv->bx + sr)][BITS]); - put_bits (output, - mv_code_table[(mv->by + sr)][CODE], - mv_code_table[(mv->by + sr)][BITS]); - btotal++; - break; - case INTERPOLATED: - put_bits (output, - mv_code_table[(mv->fx + sr)][CODE], - mv_code_table[(mv->fx + sr)][BITS]); - put_bits (output, - mv_code_table[(mv->fy + sr)][CODE], - mv_code_table[(mv->fy + sr)][BITS]); - put_bits (output, - mv_code_table[(mv->bx + sr)][CODE], - mv_code_table[(mv->bx + sr)][BITS]); - put_bits (output, - mv_code_table[(mv->by + sr)][CODE], - mv_code_table[(mv->by + sr)][BITS]); - itotal++; - break; - default: - break; - } - } + mv_t *mv = &wfa->mv_tree[state][label]; /* motion vector info */ + + if (mv->type != NONE) + { + level_count [wfa->level_of_state [state] - 1]++; + switch (mv->type) + { + case FORWARD: + put_bits (output, + mv_code_table[(mv->fx + sr)][CODE], + mv_code_table[(mv->fx + sr)][BITS]); + put_bits (output, + mv_code_table[(mv->fy + sr)][CODE], + mv_code_table[(mv->fy + sr)][BITS]); + ftotal++; + break; + case BACKWARD: + put_bits (output, + mv_code_table[(mv->bx + sr)][CODE], + mv_code_table[(mv->bx + sr)][BITS]); + put_bits (output, + mv_code_table[(mv->by + sr)][CODE], + mv_code_table[(mv->by + sr)][BITS]); + btotal++; + break; + case INTERPOLATED: + put_bits (output, + mv_code_table[(mv->fx + sr)][CODE], + mv_code_table[(mv->fx + sr)][BITS]); + put_bits (output, + mv_code_table[(mv->fy + sr)][CODE], + mv_code_table[(mv->fy + sr)][BITS]); + put_bits (output, + mv_code_table[(mv->bx + sr)][CODE], + mv_code_table[(mv->bx + sr)][BITS]); + put_bits (output, + mv_code_table[(mv->by + sr)][CODE], + mv_code_table[(mv->by + sr)][BITS]); + itotal++; + break; + default: + break; + } + } } OUTPUT_BYTE_ALIGN (output); debug_message ("Motion compensation: %d forward, %d backward, " - "%d interpolated", ftotal, btotal, itotal); + "%d interpolated", ftotal, btotal, itotal); for (level = wfa->wfainfo->p_max_level; - level >= wfa->wfainfo->p_min_level; level--) + level >= wfa->wfainfo->p_min_level; level--) debug_message ("Level %d: %d motion vectors", level, level_count[level]); { unsigned total = ftotal * 2 + btotal * 2 + itotal * 4; debug_message ("mv-coord: %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); } return; diff --git a/converter/other/fiasco/output/mc.h b/converter/other/fiasco/output/mc.h index cacddfe7..9e15ae3d 100644 --- a/converter/other/fiasco/output/mc.h +++ b/converter/other/fiasco/output/mc.h @@ -1,9 +1,9 @@ /* * mc.h * - * Written by: Michael Unger - * Ullrich Hafner - * + * Written by: Michael Unger + * 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/output/nd.c b/converter/other/fiasco/output/nd.c index b1dd6746..67b8b106 100644 --- a/converter/other/fiasco/output/nd.c +++ b/converter/other/fiasco/output/nd.c @@ -1,7 +1,7 @@ /* - * nd.c: Output of prediction tree + * nd.c: Output 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 @@ -31,7 +31,7 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -42,7 +42,7 @@ encode_nd_coefficients (unsigned total, const wfa_t *wfa, bitfile_t *output); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -63,7 +63,7 @@ write_nd (const wfa_t *wfa, bitfile_t *output) /***************************************************************************** - private code + private code *****************************************************************************/ @@ -75,13 +75,13 @@ encode_nd_tree (const wfa_t *wfa, bitfile_t *output) * No return value. */ { - lqueue_t *queue; /* queue of states */ - int state, next; /* state and its current child */ - unsigned used, not_used; /* counter ND used/not used */ - 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 */ - u_word_t sum0, sum1; /* Probability model */ + lqueue_t *queue; /* queue of states */ + int state, next; /* state and its current child */ + unsigned used, not_used; /* counter ND used/not used */ + 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 */ + u_word_t sum0, sum1; /* Probability model */ unsigned bits = bits_processed (output); used = not_used = 0; @@ -108,60 +108,60 @@ encode_nd_tree (const wfa_t *wfa, bitfile_t *output) 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 range; /* Current interval range */ - - if (isedge (wfa->into [next][label][0])) /* prediction used */ - { - used++; - - /* - * Encode a '1' symbol - */ - range = (high - low) + 1; - low = low + (u_word_t) ((range * sum0) / sum1); - RESCALE_OUTPUT_INTERVAL; - } - else /* no predict., continue with children */ - { - not_used++; - if (wfa->level_of_state [state] > wfa->wfainfo->p_min_level) - queue_append (queue, &state); - - /* - * Encode a '0' symbol - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum0) / sum1 - 1); - RESCALE_OUTPUT_INTERVAL; - sum0++; - } - /* - * 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; - } - } + for (label = 0; label < MAXLABELS; label++) + if (ischild (state = wfa->tree [next][label])) + { + unsigned range; /* Current interval range */ + + if (isedge (wfa->into [next][label][0])) /* prediction used */ + { + used++; + + /* + * Encode a '1' symbol + */ + range = (high - low) + 1; + low = low + (u_word_t) ((range * sum0) / sum1); + RESCALE_OUTPUT_INTERVAL; + } + else /* no predict., continue with children */ + { + not_used++; + if (wfa->level_of_state [state] > wfa->wfainfo->p_min_level) + queue_append (queue, &state); + + /* + * Encode a '0' symbol + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum0) / sum1 - 1); + RESCALE_OUTPUT_INTERVAL; + sum0++; + } + /* + * 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; + } + } } } @@ -175,14 +175,14 @@ encode_nd_tree (const wfa_t *wfa, bitfile_t *output) OUTPUT_BYTE_ALIGN (output); debug_message ("%d nd fields: %d used nd, %d used not nd", used + not_used, - used, not_used); + used, not_used); { unsigned total = used + not_used; debug_message ("nd-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); } return used; @@ -201,42 +201,42 @@ encode_nd_coefficients (unsigned total, const wfa_t *wfa, bitfile_t *output) unsigned bits = bits_processed (output); { - unsigned *coefficients; /* array of factors to encode */ - unsigned *ptr; /* pointer to current factor */ - unsigned state, label, edge; - word_t domain; + unsigned *coefficients; /* array of factors to encode */ + unsigned *ptr; /* pointer to current factor */ + unsigned state, label, edge; + word_t domain; ptr = coefficients = Calloc (total, sizeof (unsigned)); 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])) - for (edge = 0; isedge (domain = wfa->into [state][label][edge]); - edge++) - { - if (ptr - coefficients >= (int) total) - error ("Can't write more than %d coefficients.", total); - - *ptr++ = rtob (wfa->weight [state][label][edge], - wfa->wfainfo->dc_rpf); - } + for (label = 0; label < MAXLABELS; label++) + if (ischild (wfa->tree [state][label]) + && isedge (wfa->into [state][label][0])) + for (edge = 0; isedge (domain = wfa->into [state][label][edge]); + edge++) + { + if (ptr - coefficients >= (int) total) + error ("Can't write more than %d coefficients.", total); + + *ptr++ = rtob (wfa->weight [state][label][edge], + wfa->wfainfo->dc_rpf); + } /* * Encode array of coefficients with arithmetic coding */ { - const int scaling = 50; /* scaling factor of prob. model */ - unsigned c_symbols = 1 << (wfa->wfainfo->dc_rpf->mantissa_bits + 1); + const int scaling = 50; /* scaling factor of prob. model */ + unsigned c_symbols = 1 << (wfa->wfainfo->dc_rpf->mantissa_bits + 1); - encode_array (output, coefficients, NULL, &c_symbols, 1, - total, scaling); + encode_array (output, coefficients, NULL, &c_symbols, 1, + total, scaling); } debug_message ("nd-factors: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total, - total ? ((bits_processed (output) - bits) - / (double) total) : 0); + bits_processed (output) - bits, total, + total ? ((bits_processed (output) - bits) + / (double) total) : 0); Free (coefficients); } } diff --git a/converter/other/fiasco/output/nd.h b/converter/other/fiasco/output/nd.h index 01a37838..7b8ea9fe 100644 --- a/converter/other/fiasco/output/nd.h +++ b/converter/other/fiasco/output/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/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; } } /* diff --git a/converter/other/fiasco/output/tree.h b/converter/other/fiasco/output/tree.h index 50fe2279..bcf50ec1 100644 --- a/converter/other/fiasco/output/tree.h +++ b/converter/other/fiasco/output/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/output/weights.c b/converter/other/fiasco/output/weights.c index 0203fef0..4eb068ac 100644 --- a/converter/other/fiasco/output/weights.c +++ b/converter/other/fiasco/output/weights.c @@ -1,8 +1,8 @@ /* - * weights.c: Output of weights + * weights.c: Output of weights + * + * 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 */ @@ -32,8 +32,8 @@ /***************************************************************************** - public code - + public code + *****************************************************************************/ void @@ -45,20 +45,20 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) * No return value. */ { - unsigned state, label; /* current label */ - unsigned offset1, offset2; /* model offsets. */ - unsigned offset3, offset4; /* model offsets. */ - unsigned *weights_array; /* array of weights to encode */ - unsigned *wptr; /* pointer to current weight */ - unsigned *level_array; /* array of corresponding levels */ - unsigned *lptr; /* pointer to current corr. level */ - int min_level, max_level; /* min and max range level */ - int d_min_level, d_max_level; /* min and max delta range level */ - bool_t dc, d_dc; /* true if dc or delta dc are used */ - bool_t delta_approx = NO; /* true if delta has been used */ - unsigned delta_count = 0; /* number of delta ranges */ - unsigned bits = bits_processed (output); - + unsigned state, label; /* current label */ + unsigned offset1, offset2; /* model offsets. */ + unsigned offset3, offset4; /* model offsets. */ + unsigned *weights_array; /* array of weights to encode */ + unsigned *wptr; /* pointer to current weight */ + unsigned *level_array; /* array of corresponding levels */ + unsigned *lptr; /* pointer to current corr. level */ + int min_level, max_level; /* min and max range level */ + int d_min_level, d_max_level; /* min and max delta range level */ + bool_t dc, d_dc; /* true if dc or delta dc are used */ + bool_t delta_approx = NO; /* true if delta has been used */ + unsigned delta_count = 0; /* number of delta ranges */ + unsigned bits = bits_processed (output); + /* * Check whether delta approximation has been used */ @@ -68,14 +68,14 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) delta_approx = YES; break; } - + /* * Generate array of corresponding levels (context of probability model) */ min_level = d_min_level = MAXLEVEL; max_level = d_max_level = 0; - dc = d_dc = NO; - + 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])) @@ -95,24 +95,24 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) dc = YES; } } - if (min_level > max_level) /* no lc found */ + if (min_level > max_level) /* no lc found */ max_level = min_level - 1; if (d_min_level > d_max_level) d_max_level = d_min_level - 1; /* * Context model: - * 0 DC weight - * 1 Delta DC weight - * 2-k normal weights per level - * k+1 - m Delta weights per level + * 0 DC weight + * 1 Delta DC weight + * 2-k normal weights per level + * k+1 - m Delta weights per level */ offset1 = dc ? 1 : 0; offset2 = offset1 + (d_dc ? 1 : 0); offset3 = offset2 + (max_level - min_level + 1); offset4 = offset3 + (d_max_level - d_min_level + 1); - + /* * Weights are encoded as follows: * all weights of state n @@ -127,15 +127,15 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) for (label = 0; label < MAXLABELS; label++) if (isrange (wfa->tree [state][label])) { - int edge; /* current edge */ - int domain; /* current domain (context of model) */ - + int edge; /* current edge */ + int domain; /* current domain (context of model) */ + for (edge = 0; isedge (domain = wfa->into [state][label][edge]); edge++) { if (wptr - weights_array >= (int) total) error ("Can't write more than %d weights.", total); - if (domain) /* not DC component */ + if (domain) /* not DC component */ { if (delta_approx && wfa->delta_state [state]) /* delta */ { @@ -153,7 +153,7 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) + wfa->level_of_state [state] - 1 - min_level; } } - else /* DC component */ + else /* DC component */ { if (delta_approx && wfa->delta_state [state]) /* delta */ { @@ -172,9 +172,9 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) } { - unsigned i; - unsigned *c_symbols = Calloc (offset4, sizeof (int)); - const int scale = 500; /* scaling of probability model */ + unsigned i; + unsigned *c_symbols = Calloc (offset4, sizeof (int)); + const int scale = 500; /* scaling of probability model */ c_symbols [0] = 1 << (wfa->wfainfo->dc_rpf->mantissa_bits + 1); if (offset1 != offset2) @@ -184,12 +184,12 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) 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); - + encode_array (output, weights_array, level_array, c_symbols, offset4, total, scale); Free (c_symbols); } - + debug_message ("%d delta weights out of %d.", delta_count, total); debug_message ("weights: %5d bits. (%5d symbols => %5.2f bps)", bits_processed (output) - bits, total, diff --git a/converter/other/fiasco/output/weights.h b/converter/other/fiasco/output/weights.h index f22bd9f8..505918ad 100644 --- a/converter/other/fiasco/output/weights.h +++ b/converter/other/fiasco/output/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 */ diff --git a/converter/other/fiasco/output/write.c b/converter/other/fiasco/output/write.c index d6faee26..8c825a12 100644 --- a/converter/other/fiasco/output/write.c +++ b/converter/other/fiasco/output/write.c @@ -2,7 +2,7 @@ * write.c: Output of WFA files * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -32,11 +32,11 @@ #include "mc.h" #include "nd.h" #include "write.h" - + /***************************************************************************** prototypes - + *****************************************************************************/ static void @@ -46,7 +46,7 @@ write_tiling (const tiling_t *tiling, bitfile_t *output); public code - + *****************************************************************************/ @@ -61,26 +61,26 @@ write_next_wfa (const wfa_t *wfa, const coding_t *c, bitfile_t *output) { unsigned edges = 0; /* number of transitions */ unsigned bits; - + debug_message ("--------------------------------------" "--------------------------------------"); if (c->mt->number == 0) /* first WFA */ write_header (wfa->wfainfo, output); - + bits = bits_processed (output); - + /* * Frame header information */ { const int rice_k = 8; /* parameter of Rice Code */ - write_rice_code (wfa->states, rice_k, output); - write_rice_code (c->mt->frame_type, rice_k, output); - write_rice_code (c->mt->number, rice_k, output); + write_rice_code (wfa->states, rice_k, output); + write_rice_code (c->mt->frame_type, rice_k, output); + write_rice_code (c->mt->number, rice_k, output); } - + OUTPUT_BYTE_ALIGN (output); debug_message ("frame-header: %5d bits.", bits_processed (output) - bits); @@ -99,7 +99,7 @@ write_next_wfa (const wfa_t *wfa, const coding_t *c, bitfile_t *output) if (c->options.prediction) /* write nondeterministic approx. */ { - put_bit (output, 1); + put_bit (output, 1); write_nd (wfa, output); } else @@ -107,7 +107,7 @@ write_next_wfa (const wfa_t *wfa, const coding_t *c, bitfile_t *output) if (c->mt->frame_type != I_FRAME) /* write motion compensation info */ write_mc (c->mt->frame_type, wfa, output); - + edges = write_matrices (c->options.normal_domains, c->options.delta_domains, wfa, output); @@ -140,7 +140,7 @@ write_header (const wfa_info_t *wi, bitfile_t *output) for (text = wi->basis_name; *text; text++) put_bits (output, *text, 8); put_bits (output, *text, 8); - + write_rice_code (FIASCO_BINFILE_RELEASE, rice_k, output); write_rice_code (HEADER_TITLE, rice_k, output); @@ -149,24 +149,24 @@ write_header (const wfa_info_t *wi, bitfile_t *output) text++) put_bits (output, *text, 8); put_bits (output, 0, 8); - + write_rice_code (HEADER_COMMENT, rice_k, output); for (text = wi->comment; text && *text && text - wi->comment < MAXSTRLEN - 2; text++) put_bits (output, *text, 8); put_bits (output, 0, 8); - + write_rice_code (HEADER_END, rice_k, output); - - write_rice_code (wi->max_states, rice_k, output); - put_bit (output, wi->color ? 1 : 0); + + write_rice_code (wi->max_states, rice_k, output); + put_bit (output, wi->color ? 1 : 0); write_rice_code (wi->width, rice_k, output); write_rice_code (wi->height, rice_k, output); if (wi->color) - write_rice_code (wi->chroma_max_states, rice_k, output); - write_rice_code (wi->p_min_level, rice_k, output); - write_rice_code (wi->p_max_level, rice_k, output); + write_rice_code (wi->chroma_max_states, rice_k, output); + write_rice_code (wi->p_min_level, rice_k, output); + write_rice_code (wi->p_max_level, rice_k, output); write_rice_code (wi->frames, rice_k, output); write_rice_code (wi->smoothing, rice_k, output); @@ -202,9 +202,9 @@ write_header (const wfa_info_t *wi, bitfile_t *output) if (wi->frames > 1) /* motion compensation stuff */ { - write_rice_code (wi->fps, rice_k, output); - write_rice_code (wi->search_range, rice_k, output); - put_bit (output, wi->half_pixel ? 1 : 0); + write_rice_code (wi->fps, rice_k, output); + write_rice_code (wi->search_range, rice_k, output); + put_bit (output, wi->half_pixel ? 1 : 0); put_bit (output, wi->B_as_past_ref ? 1 : 0); } @@ -215,7 +215,7 @@ write_header (const wfa_info_t *wi, bitfile_t *output) /***************************************************************************** private code - + *****************************************************************************/ static void @@ -228,21 +228,21 @@ write_tiling (const tiling_t *tiling, bitfile_t *output) { const unsigned rice_k = 8; /* parameter of Rice Code */ unsigned bits = bits_processed (output); - + write_rice_code (tiling->exponent, rice_k, output); if (tiling->method == FIASCO_TILING_VARIANCE_ASC || tiling->method == FIASCO_TILING_VARIANCE_DSC) { unsigned tile; /* current image tile */ - put_bit (output, 1); + put_bit (output, 1); for (tile = 0; tile < 1U << tiling->exponent; tile++) if (tiling->vorder [tile] != -1) /* image tile is visible */ put_bits (output, tiling->vorder [tile], tiling->exponent); } else { - put_bit (output, 0); + put_bit (output, 0); put_bit (output, tiling->method == FIASCO_TILING_SPIRAL_ASC); } diff --git a/converter/other/fiasco/output/write.h b/converter/other/fiasco/output/write.h index 6bdc2f1b..1fb3393c 100644 --- a/converter/other/fiasco/output/write.h +++ b/converter/other/fiasco/output/write.h @@ -1,8 +1,8 @@ /* * write.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 */ |