diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-09-24 16:51:04 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-09-24 16:51:04 +0000 |
commit | e90b1605a083938d582dd459f8a14141274e7492 (patch) | |
tree | d01b692f4c437b6fe831d0308a330e3e5246fcd7 /converter/other/fiasco/output/nd.c | |
parent | 0f567f941233d027720170114917327b842d4188 (diff) | |
download | netpbm-mirror-e90b1605a083938d582dd459f8a14141274e7492.tar.gz netpbm-mirror-e90b1605a083938d582dd459f8a14141274e7492.tar.xz netpbm-mirror-e90b1605a083938d582dd459f8a14141274e7492.zip |
whitespace
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4685 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/fiasco/output/nd.c')
-rw-r--r-- | converter/other/fiasco/output/nd.c | 180 |
1 files changed, 90 insertions, 90 deletions
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); } } |