diff options
Diffstat (limited to 'converter/other/fiasco/lib')
-rw-r--r-- | converter/other/fiasco/lib/arith.c | 440 | ||||
-rw-r--r-- | converter/other/fiasco/lib/arith.h | 40 | ||||
-rw-r--r-- | converter/other/fiasco/lib/bit-io.h | 20 | ||||
-rw-r--r-- | converter/other/fiasco/lib/dither.c | 2258 | ||||
-rw-r--r-- | converter/other/fiasco/lib/dither.h | 8 | ||||
-rw-r--r-- | converter/other/fiasco/lib/error.c | 20 | ||||
-rw-r--r-- | converter/other/fiasco/lib/error.h | 6 | ||||
-rw-r--r-- | converter/other/fiasco/lib/image.h | 16 | ||||
-rw-r--r-- | converter/other/fiasco/lib/list.c | 108 | ||||
-rw-r--r-- | converter/other/fiasco/lib/list.h | 32 | ||||
-rw-r--r-- | converter/other/fiasco/lib/macros.h | 36 | ||||
-rw-r--r-- | converter/other/fiasco/lib/misc.c | 198 | ||||
-rw-r--r-- | converter/other/fiasco/lib/misc.h | 26 | ||||
-rw-r--r-- | converter/other/fiasco/lib/mvcode.c | 2 | ||||
-rw-r--r-- | converter/other/fiasco/lib/rpf.c | 34 | ||||
-rw-r--r-- | converter/other/fiasco/lib/rpf.h | 14 | ||||
-rw-r--r-- | converter/other/fiasco/lib/types.h | 2 |
17 files changed, 1630 insertions, 1630 deletions
diff --git a/converter/other/fiasco/lib/arith.c b/converter/other/fiasco/lib/arith.c index e61e753e..7fac0c6d 100644 --- a/converter/other/fiasco/lib/arith.c +++ b/converter/other/fiasco/lib/arith.c @@ -1,7 +1,7 @@ /* - * arith.c: Adaptive arithmetic coding and decoding + * arith.c: Adaptive arithmetic coding and decoding * - * 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 @@ -26,7 +26,7 @@ /****************************************************************************** - public code + public code ******************************************************************************/ @@ -37,7 +37,7 @@ alloc_encoder (bitfile_t *output) * Initialize the arithmetic coder. * * Return value: - * A pointer to the new coder structure + * A pointer to the new coder structure */ { arith_t *arith = Calloc (1, sizeof (arith_t)); @@ -47,7 +47,7 @@ alloc_encoder (bitfile_t *output) arith->low = LOW; arith->high = HIGH; arith->underflow = 0; - arith->file = output; + arith->file = output; return arith; } @@ -62,9 +62,9 @@ free_encoder (arith_t *arith) * 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 */ + 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 */ bitfile_t *output; assert (arith); @@ -94,22 +94,22 @@ encode_symbol (unsigned symbol, arith_t *arith, model_t *model) * symbol counts are rescaled). * * Return value: - * information content of the encoded symbol. + * information content of the encoded symbol. * * Side effects: - * 'model' is updated (probability distribution) - * 'arith' is updated (coder state) + * 'model' is updated (probability distribution) + * 'arith' is updated (coder state) */ { - u_word_t low_count; /* lower bound of 'symbol' interval */ - u_word_t high_count; /* upper bound of 'symbol' interval */ - u_word_t scale; /* range of all 'm' symbol intervals */ - unsigned range; /* range of current interval */ - unsigned index; /* index of probability model */ - 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 */ - bitfile_t *output; /* output file */ + u_word_t low_count; /* lower bound of 'symbol' interval */ + u_word_t high_count; /* upper bound of 'symbol' interval */ + u_word_t scale; /* range of all 'm' symbol intervals */ + unsigned range; /* range of current interval */ + unsigned index; /* index of probability model */ + 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 */ + bitfile_t *output; /* output file */ assert (model && arith); @@ -123,28 +123,28 @@ encode_symbol (unsigned symbol, arith_t *arith, model_t *model) assert (high > low); - if (model->order > 0) /* order-'n' model*/ + if (model->order > 0) /* order-'n' model*/ { - unsigned power; /* multiplicator */ + unsigned power; /* multiplicator */ unsigned i; /* * Compute index of the probability model to use. * See init_model() for more details. */ - power = 1; /* multiplicator */ - index = 0; /* address of prob. model */ + power = 1; /* multiplicator */ + index = 0; /* address of prob. model */ for (i = 0; i < model->order; i++) /* generate a M-nary number */ { - index += model->context [i] * power; - power *= model->symbols; + index += model->context [i] * power; + power *= model->symbols; } - index *= model->symbols + 1; /* we need space for M + 1 elements */ + index *= model->symbols + 1; /* we need space for M + 1 elements */ for (i = 0; i < model->order - 1; i++) - model->context [i] = model->context [i + 1]; + model->context [i] = model->context [i + 1]; model->context [i] = symbol; } else @@ -163,7 +163,7 @@ encode_symbol (unsigned symbol, arith_t *arith, model_t *model) RESCALE_OUTPUT_INTERVAL; - if (model->scale > 0) /* adaptive model */ + if (model->scale > 0) /* adaptive model */ { unsigned i; @@ -171,23 +171,23 @@ encode_symbol (unsigned symbol, arith_t *arith, model_t *model) * Update probability model */ for (i = symbol + 1; i <= model->symbols; i++) - model->totals [index + i]++; + model->totals [index + i]++; if (model->totals [index + model->symbols] > model->scale) /* scaling */ { - for (i = 1; i <= model->symbols; i++) - { - model->totals [index + i] >>= 1; - if (model->totals [index + i] <= model->totals [index + i - 1]) - model->totals [index + i] = model->totals [index + i - 1] + 1; - } + for (i = 1; i <= model->symbols; i++) + { + model->totals [index + i] >>= 1; + if (model->totals [index + i] <= model->totals [index + i - 1]) + model->totals [index + i] = model->totals [index + i - 1] + 1; + } } } /* * Store interval values */ - arith->low = low; - arith->high = high; + arith->low = low; + arith->high = high; arith->underflow = underflow; return - log2 ((high_count - low_count) / (real_t) scale); @@ -195,8 +195,8 @@ encode_symbol (unsigned symbol, arith_t *arith, model_t *model) void encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, - const unsigned *c_symbols, unsigned n_context, unsigned n_data, - unsigned scaling) + const unsigned *c_symbols, unsigned n_context, unsigned n_data, + unsigned scaling) /* * Arithmetic coding of #'n_data' symbols given in the array 'data'. * If 'n_context' > 1 then a number (context [n]) is assigned to every @@ -207,10 +207,10 @@ encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, * No return value. */ { - u_word_t **totals; /* probability model */ + u_word_t **totals; /* probability model */ if (!n_context) - n_context = 1; /* always use one context */ + n_context = 1; /* always use one context */ assert (output && c_symbols && data); assert (n_context == 1 || context); @@ -224,13 +224,13 @@ encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, for (c = 0; c < n_context; c++) { - unsigned i; + unsigned i; - totals [c] = Calloc (c_symbols [c] + 1, sizeof (u_word_t)); - totals [c][0] = 0; + totals [c] = Calloc (c_symbols [c] + 1, sizeof (u_word_t)); + totals [c][0] = 0; - for (i = 0; i < c_symbols [c]; i++) - totals [c][i + 1] = totals [c][i] + 1; + for (i = 0; i < c_symbols [c]; i++) + totals [c][i + 1] = totals [c][i] + 1; } } @@ -238,52 +238,52 @@ encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, * Encode array elements */ { - u_word_t low = 0; /* Start of the current code range */ - u_word_t high = 0xffff; /* End of the current code range */ - u_word_t underflow = 0; /* Number of underflow bits pending */ + u_word_t low = 0; /* Start of the current code range */ + u_word_t high = 0xffff; /* End of the current code range */ + u_word_t underflow = 0; /* Number of underflow bits pending */ unsigned n; for (n = 0; n < n_data; n++) { - u_word_t low_count; /* lower bound of 'symbol' interval */ - u_word_t high_count; /* upper bound of 'symbol' interval */ - u_word_t scale; /* range of all 'm' symbol intervals */ - unsigned range; /* current range */ - int d; /* current data symbol */ - int c; /* context of current data symbol */ - - d = data [n]; - c = n_context > 1 ? context [n] : 0; - - scale = totals [c][c_symbols [c]]; - low_count = totals [c][d]; - high_count = totals [c][d + 1]; - - /* - * Rescale high and low for the new symbol. - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * high_count) / scale - 1); - low = low + (u_word_t) ((range * low_count) / scale); - RESCALE_OUTPUT_INTERVAL; - - /* - * Update probability models - */ - { - unsigned i; - - for (i = d + 1; i < c_symbols [c] + 1; i++) - totals [c][i]++; - - if (totals [c][c_symbols [c]] > scaling) /* scaling */ - for (i = 1; i < c_symbols [c] + 1; i++) - { - totals [c][i] >>= 1; - if (totals [c][i] <= totals [c][i - 1]) - totals [c][i] = totals [c][i - 1] + 1; - } - } + u_word_t low_count; /* lower bound of 'symbol' interval */ + u_word_t high_count; /* upper bound of 'symbol' interval */ + u_word_t scale; /* range of all 'm' symbol intervals */ + unsigned range; /* current range */ + int d; /* current data symbol */ + int c; /* context of current data symbol */ + + d = data [n]; + c = n_context > 1 ? context [n] : 0; + + scale = totals [c][c_symbols [c]]; + low_count = totals [c][d]; + high_count = totals [c][d + 1]; + + /* + * Rescale high and low for the new symbol. + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * high_count) / scale - 1); + low = low + (u_word_t) ((range * low_count) / scale); + RESCALE_OUTPUT_INTERVAL; + + /* + * Update probability models + */ + { + unsigned i; + + for (i = d + 1; i < c_symbols [c] + 1; i++) + totals [c][i]++; + + if (totals [c][c_symbols [c]] > scaling) /* scaling */ + for (i = 1; i < c_symbols [c] + 1; i++) + { + totals [c][i] >>= 1; + if (totals [c][i] <= totals [c][i - 1]) + totals [c][i] = totals [c][i - 1] + 1; + } + } } /* * Flush arithmetic encoder @@ -299,7 +299,7 @@ encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, { unsigned c; for (c = 0; c < n_context; c++) - Free (totals [c]); + Free (totals [c]); Free (totals); } } @@ -312,7 +312,7 @@ alloc_decoder (bitfile_t *input) * 16 input bits from the stream 'input'. * * Return value: - * A pointer to the new decoder structure + * A pointer to the new decoder structure */ { @@ -338,7 +338,7 @@ free_decoder (arith_t *arith) * No return value. * * Side effects: - * structure 'arith' is discarded. + * structure 'arith' is discarded. */ { assert (arith); @@ -357,22 +357,22 @@ decode_symbol (arith_t *arith, model_t *model) * decoding the symbol (if necessary also rescale the symbol counts). * * Return value: - * decoded symbol + * decoded symbol * * Side effects: - * 'model' is updated (probability distribution) - * 'arith' is updated (decoder state) + * 'model' is updated (probability distribution) + * 'arith' is updated (decoder state) */ { - unsigned range; /* range of current interval */ - unsigned count; /* value in the current interval */ - unsigned index; /* index of probability model */ - unsigned symbol; /* decoded symbol */ - u_word_t scale; /* range of all 'm' symbol intervals */ - u_word_t low; /* start of the current code range */ - u_word_t high; /* end of the current code range */ - u_word_t code; /* the present input code value */ - bitfile_t *input; /* input file */ + unsigned range; /* range of current interval */ + unsigned count; /* value in the current interval */ + unsigned index; /* index of probability model */ + unsigned symbol; /* decoded symbol */ + u_word_t scale; /* range of all 'm' symbol intervals */ + u_word_t low; /* start of the current code range */ + u_word_t high; /* end of the current code range */ + u_word_t code; /* the present input code value */ + bitfile_t *input; /* input file */ assert (arith && model); @@ -386,25 +386,25 @@ decode_symbol (arith_t *arith, model_t *model) assert (high > low); - if (model->order > 0) /* order-'n' model */ + if (model->order > 0) /* order-'n' model */ { - unsigned power; /* multiplicator */ + unsigned power; /* multiplicator */ unsigned i; /* * Compute index of the probability model to use. * See init_model() for more details. */ - power = 1; /* multiplicator */ - index = 0; /* address of prob. model */ + power = 1; /* multiplicator */ + index = 0; /* address of prob. model */ for (i = 0; i < model->order; i++) /* generate a m-nary number */ { - index += model->context[i] * power; - power *= model->symbols; + index += model->context[i] * power; + power *= model->symbols; } - index *= model->symbols + 1; /* we need space for m + 1 elements */ + index *= model->symbols + 1; /* we need space for m + 1 elements */ } else index = 0; @@ -414,15 +414,15 @@ decode_symbol (arith_t *arith, model_t *model) count = ((code - low + 1) * scale - 1) / range; for (symbol = model->symbols; count < model->totals [index + symbol]; - symbol--) + symbol--) ; - if (model->order > 0) /* order-'n' model */ + if (model->order > 0) /* order-'n' model */ { unsigned i; for (i = 0; i < model->order - 1; i++) - model->context [i] = model->context [i + 1]; + model->context [i] = model->context [i + 1]; model->context [i] = symbol; } @@ -430,8 +430,8 @@ decode_symbol (arith_t *arith, model_t *model) * Compute interval boundaries */ { - u_word_t low_count; /* lower bound of 'symbol' interval */ - u_word_t high_count; /* upper bound of 'symbol' interval */ + u_word_t low_count; /* lower bound of 'symbol' interval */ + u_word_t high_count; /* upper bound of 'symbol' interval */ low_count = model->totals [index + symbol]; high_count = model->totals [index + symbol + 1]; @@ -441,7 +441,7 @@ decode_symbol (arith_t *arith, model_t *model) RESCALE_INPUT_INTERVAL; - if (model->scale > 0) /* adaptive model */ + if (model->scale > 0) /* adaptive model */ { unsigned i; @@ -449,15 +449,15 @@ decode_symbol (arith_t *arith, model_t *model) * Update probability model */ for (i = symbol + 1; i <= model->symbols; i++) - model->totals [index + i]++; + model->totals [index + i]++; if (model->totals [index + model->symbols] > model->scale) /* scaling */ { - for (i = 1; i <= model->symbols; i++) - { - model->totals [index + i] >>= 1; - if (model->totals [index + i] <= model->totals [index + i - 1]) - model->totals [index + i] = model->totals [index + i - 1] + 1; - } + for (i = 1; i <= model->symbols; i++) + { + model->totals [index + i] >>= 1; + if (model->totals [index + i] <= model->totals [index + i - 1]) + model->totals [index + i] = model->totals [index + i - 1] + 1; + } } } @@ -473,8 +473,8 @@ decode_symbol (arith_t *arith, model_t *model) unsigned * decode_array (bitfile_t *input, const unsigned *context, - const unsigned *c_symbols, unsigned n_context, - unsigned n_data, unsigned scaling) + const unsigned *c_symbols, unsigned n_context, + unsigned n_data, unsigned scaling) /* * Arithmetic decoding of #'n_data' symbols. * If 'n_context' > 1 then a number (context [n]) is assigned to every @@ -483,14 +483,14 @@ decode_array (bitfile_t *input, const unsigned *context, * Rescale probability models if range > 'scaling'. * * Return value: - * pointer to array containing the decoded symbols + * pointer to array containing the decoded symbols */ { - unsigned *data; /* array to store decoded symbols */ - u_word_t **totals; /* probability model */ + unsigned *data; /* array to store decoded symbols */ + u_word_t **totals; /* probability model */ if (n_context < 1) - n_context = 1; /* always use one context */ + n_context = 1; /* always use one context */ assert (input && c_symbols); assert (n_context == 1 || context); @@ -505,13 +505,13 @@ decode_array (bitfile_t *input, const unsigned *context, for (c = 0; c < n_context; c++) { - unsigned i; + unsigned i; - totals [c] = Calloc (c_symbols [c] + 1, sizeof (u_word_t)); - totals [c][0] = 0; + totals [c] = Calloc (c_symbols [c] + 1, sizeof (u_word_t)); + totals [c][0] = 0; - for (i = 0; i < c_symbols [c]; i++) - totals [c][i + 1] = totals [c][i] + 1; + for (i = 0; i < c_symbols [c]; i++) + totals [c][i + 1] = totals [c][i] + 1; } } @@ -520,54 +520,54 @@ decode_array (bitfile_t *input, const unsigned *context, */ { u_word_t code = get_bits (input, 16); /* The present input code value */ - u_word_t low = 0; /* Start of the current code range */ - u_word_t high = 0xffff; /* End of the current code range */ + u_word_t low = 0; /* Start of the current code range */ + u_word_t high = 0xffff; /* End of the current code range */ unsigned n; for (n = 0; n < n_data; n++) { - u_word_t scale; /* range of all 'm' symbol intervals */ - u_word_t low_count; /* lower bound of 'symbol' interval */ - u_word_t high_count; /* upper bound of 'symbol' interval */ - unsigned count; /* value in the current interval */ - unsigned range; /* current interval range */ - unsigned d; /* current data symbol */ - unsigned c; /* context of current data symbol */ - - c = n_context > 1 ? context [n] : 0; - - assert (high > low); - scale = totals [c][c_symbols [c]]; - range = (high - low) + 1; - count = (((code - low) + 1 ) * scale - 1) / range; - - for (d = c_symbols [c]; count < totals [c][d]; d--) /* next symbol */ - ; - low_count = totals [c][d]; - high_count = totals [c][d + 1]; - - high = low + (u_word_t) ((range * high_count) / scale - 1 ); - low = low + (u_word_t) ((range * low_count) / scale ); - RESCALE_INPUT_INTERVAL; - - /* - * Updata probability models - */ - { - unsigned i; - - for (i = d + 1; i < c_symbols [c] + 1; i++) - totals [c][i]++; - - if (totals [c][c_symbols [c]] > scaling) /* scaling */ - for (i = 1; i < c_symbols [c] + 1; i++) - { - totals [c][i] >>= 1; - if (totals [c][i] <= totals [c][i - 1]) - totals [c][i] = totals [c][i - 1] + 1; - } - } - data [n] = d; + u_word_t scale; /* range of all 'm' symbol intervals */ + u_word_t low_count; /* lower bound of 'symbol' interval */ + u_word_t high_count; /* upper bound of 'symbol' interval */ + unsigned count; /* value in the current interval */ + unsigned range; /* current interval range */ + unsigned d; /* current data symbol */ + unsigned c; /* context of current data symbol */ + + c = n_context > 1 ? context [n] : 0; + + assert (high > low); + scale = totals [c][c_symbols [c]]; + range = (high - low) + 1; + count = (((code - low) + 1 ) * scale - 1) / range; + + for (d = c_symbols [c]; count < totals [c][d]; d--) /* next symbol */ + ; + low_count = totals [c][d]; + high_count = totals [c][d + 1]; + + high = low + (u_word_t) ((range * high_count) / scale - 1 ); + low = low + (u_word_t) ((range * low_count) / scale ); + RESCALE_INPUT_INTERVAL; + + /* + * Updata probability models + */ + { + unsigned i; + + for (i = d + 1; i < c_symbols [c] + 1; i++) + totals [c][i]++; + + if (totals [c][c_symbols [c]] > scaling) /* scaling */ + for (i = 1; i < c_symbols [c] + 1; i++) + { + totals [c][i] >>= 1; + if (totals [c][i] <= totals [c][i - 1]) + totals [c][i] = totals [c][i - 1] + 1; + } + } + data [n] = d; } INPUT_BYTE_ALIGN (input); } @@ -579,7 +579,7 @@ decode_array (bitfile_t *input, const unsigned *context, unsigned c; for (c = 0; c < n_context; c++) - Free (totals [c]); + Free (totals [c]); Free (totals); } @@ -599,17 +599,17 @@ alloc_model (unsigned m, unsigned scale, unsigned n, unsigned *totals) * the initial counts. * * Return value: - * a pointer to the new probability model structure. + * a pointer to the new probability model structure. * * Note: We recommend a small size of the alphabet because no escape codes * are used to encode/decode previously unseen symbols. * */ { - model_t *model; /* new probability model */ - unsigned num; /* number of contexts to allocate */ - bool_t cont; /* continue flag */ - bool_t dec; /* next order flag */ + model_t *model; /* new probability model */ + unsigned num; /* number of contexts to allocate */ + bool_t cont; /* continue flag */ + bool_t dec; /* next order flag */ unsigned i; /* @@ -630,56 +630,56 @@ alloc_model (unsigned m, unsigned scale, unsigned n, unsigned *totals) model->totals = Calloc (num * (model->symbols + 1), sizeof (unsigned)); for (i = 0; i < model->order; i++) - model->context[i] = 0; /* start with context 0,0, .. ,0 */ + model->context[i] = 0; /* start with context 0,0, .. ,0 */ cont = YES; - while (cont) /* repeat while context != M ... M */ + while (cont) /* repeat while context != M ... M */ { - int power; /* multiplicator */ - int index; /* index of probability model */ + int power; /* multiplicator */ + int index; /* index of probability model */ /* * There are m^n different contexts: * Let "context_1 context_2 ... context_n symbol" be the current input * stream then the index of the probability model is given by: * index = context_1 * M^0 + context_2 * M^1 + ... + context_n * M^(n-1) */ - power = 1; /* multiplicator */ - index = 0; /* address of prob. model */ + power = 1; /* multiplicator */ + index = 0; /* address of prob. model */ - for (i = 0; i < model->order; i++) /* generate a m-nary number */ + for (i = 0; i < model->order; i++) /* generate a m-nary number */ { - index += model->context[i] * power; - power *= model->symbols; + index += model->context[i] * power; + power *= model->symbols; } - index *= model->symbols + 1; /* size of each model is m + 1 */ + index *= model->symbols + 1; /* size of each model is m + 1 */ - model->totals [index + 0] = 0; /* always zero */ + model->totals [index + 0] = 0; /* always zero */ for (i = 1; i <= model->symbols; i++) /* prob of each symbol is 1/m or - as given in totals */ - model->totals[index + i] = model->totals [index + i - 1] - + (totals ? totals [i - 1] : 1); - - if (model->order == 0) /* order-0 model */ - cont = NO; - else /* try next context */ - for (i = model->order - 1, dec = YES; dec; i--) - { - dec = NO; - model->context[i]++; - if (model->context[i] >= model->symbols) - { - /* change previous context */ - model->context[i] = 0; - if (i > 0) /* there's still a context remaining */ - dec = YES; - else - cont = NO; /* all context models initialized */ - } - } + as given in totals */ + model->totals[index + i] = model->totals [index + i - 1] + + (totals ? totals [i - 1] : 1); + + if (model->order == 0) /* order-0 model */ + cont = NO; + else /* try next context */ + for (i = model->order - 1, dec = YES; dec; i--) + { + dec = NO; + model->context[i]++; + if (model->context[i] >= model->symbols) + { + /* change previous context */ + model->context[i] = 0; + if (i > 0) /* there's still a context remaining */ + dec = YES; + else + cont = NO; /* all context models initialized */ + } + } } for (i = 0; i < model->order; i++) - model->context[i] = 0; /* start with context 0,0, .. ,0 */ + model->context[i] = 0; /* start with context 0,0, .. ,0 */ return model; } @@ -693,13 +693,13 @@ free_model (model_t *model) * No return value. * * Side effects: - * struct 'model' is discarded + * struct 'model' is discarded */ { if (model != NULL) { if (model->context != NULL) - Free (model->context); + Free (model->context); Free (model->totals); Free (model); } diff --git a/converter/other/fiasco/lib/arith.h b/converter/other/fiasco/lib/arith.h index 04297eb5..152dabab 100644 --- a/converter/other/fiasco/lib/arith.h +++ b/converter/other/fiasco/lib/arith.h @@ -20,24 +20,24 @@ typedef struct model { - unsigned symbols; /* number of symbols in the alphabet */ - unsigned scale; /* if totals > scale rescale totals */ - unsigned order; /* order of the probability model */ - unsigned *context; /* context of the model */ - unsigned *totals; /* the totals */ + unsigned symbols; /* number of symbols in the alphabet */ + unsigned scale; /* if totals > scale rescale totals */ + unsigned order; /* order of the probability model */ + unsigned *context; /* context of the model */ + unsigned *totals; /* the totals */ } model_t; typedef struct arith { - 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 code; /* the present input code value */ - bitfile_t *file; /* I/O stream */ + 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 code; /* the present input code value */ + bitfile_t *file; /* I/O stream */ } arith_t; enum interval {LOW = 0x0000, FIRST_QUARTER = 0x4000, HALF = 0x8000, - THIRD_QUARTER = 0xc000, HIGH = 0xffff}; + THIRD_QUARTER = 0xc000, HIGH = 0xffff}; arith_t * alloc_encoder (bitfile_t *file); @@ -47,8 +47,8 @@ real_t encode_symbol (unsigned symbol, arith_t *arith, model_t *model); void encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, - const unsigned *c_symbols, unsigned n_context, unsigned n_data, - unsigned scaling); + const unsigned *c_symbols, unsigned n_context, unsigned n_data, + unsigned scaling); arith_t * alloc_decoder (bitfile_t *input); void @@ -57,8 +57,8 @@ unsigned decode_symbol (arith_t *arith, model_t *model); unsigned * decode_array (bitfile_t *input, const unsigned *context, - const unsigned *c_symbols, unsigned n_context, - unsigned n_data, unsigned scaling); + const unsigned *c_symbols, unsigned n_context, + unsigned n_data, unsigned scaling); model_t * alloc_model (unsigned m, unsigned scale, unsigned n, unsigned *totals); void @@ -67,7 +67,7 @@ free_model (model_t *model); #define RESCALE_INPUT_INTERVAL for (;;) \ if ((high >= HALF) && (low < HALF) && \ ((low & FIRST_QUARTER) != FIRST_QUARTER \ - || (high & FIRST_QUARTER) != 0)) \ + || (high & FIRST_QUARTER) != 0)) \ { \ break; \ } \ @@ -88,8 +88,8 @@ free_model (model_t *model); high |= HALF + 1; \ code <<= 1; \ code += get_bit (input); \ - } - + } + #define RESCALE_OUTPUT_INTERVAL for (;;) \ { \ if (high < HALF) \ @@ -116,7 +116,7 @@ free_model (model_t *model); high <<= 1; \ high |= 1; \ low <<= 1; \ - } - + } + #endif /* not _ARITH_H */ diff --git a/converter/other/fiasco/lib/bit-io.h b/converter/other/fiasco/lib/bit-io.h index 08029824..6de7e396 100644 --- a/converter/other/fiasco/lib/bit-io.h +++ b/converter/other/fiasco/lib/bit-io.h @@ -1,7 +1,7 @@ /* * bit-io.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 @@ -27,14 +27,14 @@ typedef enum {READ_ACCESS, WRITE_ACCESS} openmode_e; typedef struct bitfile { - FILE *file; /* associated filepointer */ - char *filename; /* corresponding filename */ - byte_t *buffer; /* stream buffer */ - byte_t *ptr; /* pointer to current buffer pos */ - unsigned bytepos; /* current I/O byte */ - unsigned bitpos; /* current I/O bit */ - unsigned bits_processed; /* number of bits already processed */ - openmode_e mode; /* access mode */ + FILE *file; /* associated filepointer */ + char *filename; /* corresponding filename */ + byte_t *buffer; /* stream buffer */ + byte_t *ptr; /* pointer to current buffer pos */ + unsigned bytepos; /* current I/O byte */ + unsigned bitpos; /* current I/O bit */ + unsigned bits_processed; /* number of bits already processed */ + openmode_e mode; /* access mode */ } bitfile_t; FILE * @@ -47,7 +47,7 @@ void put_bits (bitfile_t *bitfile, unsigned value, unsigned bits); bool_t get_bit (bitfile_t *bitfile); -unsigned +unsigned get_bits (bitfile_t *bitfile, unsigned bits); void close_bitfile (bitfile_t *bitfile); diff --git a/converter/other/fiasco/lib/dither.c b/converter/other/fiasco/lib/dither.c index 669bb16c..c394f5ec 100644 --- a/converter/other/fiasco/lib/dither.c +++ b/converter/other/fiasco/lib/dither.c @@ -1,8 +1,8 @@ /* - * dither.c: Various dithering routines + * dither.c: Various dithering routines + * + * Adapted by: Ullrich Hafner * - * Adapted by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -10,17 +10,17 @@ /* * Copyright (c) 1995 Erik Corry * All rights reserved. - * + * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. - * + * * IN NO EVENT SHALL ERIK CORRY BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ERIK CORRY HAS BEEN ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * ERIK CORRY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" @@ -52,25 +52,25 @@ /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ -static int +static int display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image); + const fiasco_image_t *fiasco_image); -static int +static int display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image); + const fiasco_image_t *fiasco_image); -static int +static int display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image); + const fiasco_image_t *fiasco_image); -static int +static int display_32_bit (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image); + const fiasco_image_t *fiasco_image); static int free_bits_at_bottom (unsigned long a); @@ -80,26 +80,26 @@ number_of_bits_set (unsigned long a); /***************************************************************************** - public code - + public code + *****************************************************************************/ fiasco_renderer_t * fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, - unsigned long blue_mask, unsigned bpp, - int double_resolution) + unsigned long blue_mask, unsigned bpp, + int double_resolution) /* * FIASCO renderer constructor. * Allocate memory for the FIASCO renderer structure and * initialize values. * `red_mask', `green_mask', and `blue_mask' are the corresponding masks - * of the X11R6 XImage structure. + * of the X11R6 XImage structure. * `bpp' gives the depth of the image in bits per pixel (16, 24, or 32). * If `double_resolution' is not 0 the the image width and height is doubled. * (fast pixel doubling, no interpolation!) * * Return value: - * pointer to the new structure or NULL on error + * pointer to the new structure or NULL on error */ { if (bpp != 16 && bpp != 24 && bpp !=32) @@ -111,30 +111,30 @@ fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, { fiasco_renderer_t *render = calloc (1, sizeof (fiasco_renderer_t)); renderer_private_t *private = calloc (1, sizeof (renderer_private_t)); - bool_t twopixels = (bpp == 16 && double_resolution); - int crval, cbval, i; /* counter */ + bool_t twopixels = (bpp == 16 && double_resolution); + int crval, cbval, i; /* counter */ if (!render || !private) { - set_error (_("Out of memory.")); - return NULL; + set_error (_("Out of memory.")); + return NULL; } switch (bpp) { - case 16: - render->render = display_16_bit; - break; - case 24: - if (red_mask > green_mask) - render->render = display_24_bit_rgb; - else - render->render = display_24_bit_bgr; - break; - case 32: - render->render = display_32_bit; - break; - default: - break; /* does not happen */ + case 16: + render->render = display_16_bit; + break; + case 24: + if (red_mask > green_mask) + render->render = display_24_bit_rgb; + else + render->render = display_24_bit_bgr; + break; + case 32: + render->render = display_32_bit; + break; + default: + break; /* does not happen */ } render->private = private; render->delete = fiasco_renderer_delete; @@ -146,42 +146,42 @@ fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, private->Cb_b_tab = calloc (256 + 2 * 1024, sizeof (int)); if (!private->Cr_r_tab || !private->Cr_g_tab - || !private->Cb_b_tab || !private->Cb_g_tab) + || !private->Cb_b_tab || !private->Cb_g_tab) { - set_error (_("Out of memory.")); - return NULL; + set_error (_("Out of memory.")); + return NULL; } - + for (i = 1024; i < 1024 + 256; i++) { - cbval = crval = i - 128 - 1024; + cbval = crval = i - 128 - 1024; - private->Cr_r_tab [i] = 1.4022 * crval + 0.5; - private->Cr_g_tab [i] = -0.7145 * crval + 0.5; - private->Cb_g_tab [i] = -0.3456 * cbval + 0.5; - private->Cb_b_tab [i] = 1.7710 * cbval + 0.5; + private->Cr_r_tab [i] = 1.4022 * crval + 0.5; + private->Cr_g_tab [i] = -0.7145 * crval + 0.5; + private->Cb_g_tab [i] = -0.3456 * cbval + 0.5; + private->Cb_b_tab [i] = 1.7710 * cbval + 0.5; } for (i = 0; i < 1024; i++) { - private->Cr_r_tab [i] = private->Cr_r_tab [1024]; - private->Cr_g_tab [i] = private->Cr_g_tab [1024]; - private->Cb_g_tab [i] = private->Cb_g_tab [1024]; - private->Cb_b_tab [i] = private->Cb_b_tab [1024]; + private->Cr_r_tab [i] = private->Cr_r_tab [1024]; + private->Cr_g_tab [i] = private->Cr_g_tab [1024]; + private->Cb_g_tab [i] = private->Cb_g_tab [1024]; + private->Cb_b_tab [i] = private->Cb_b_tab [1024]; } for (i = 1024 + 256; i < 2048 + 256; i++) { - private->Cr_r_tab [i] = private->Cr_r_tab [1024 + 255]; - private->Cr_g_tab [i] = private->Cr_g_tab [1024 + 255]; - private->Cb_g_tab [i] = private->Cb_g_tab [1024 + 255]; - private->Cb_b_tab [i] = private->Cb_b_tab [1024 + 255]; + private->Cr_r_tab [i] = private->Cr_r_tab [1024 + 255]; + private->Cr_g_tab [i] = private->Cr_g_tab [1024 + 255]; + private->Cb_g_tab [i] = private->Cb_g_tab [1024 + 255]; + private->Cb_b_tab [i] = private->Cb_b_tab [1024 + 255]; } private->Cr_r_tab += 1024 + 128; private->Cr_g_tab += 1024 + 128; private->Cb_g_tab += 1024 + 128; private->Cb_b_tab += 1024 + 128; - - /* + + /* * Set up entries 0-255 in rgb-to-pixel value tables. */ private->r_table = calloc (256 + 2 * 1024, sizeof (unsigned int)); @@ -190,38 +190,38 @@ fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, private->y_table = calloc (256 + 2 * 1024, sizeof (unsigned int)); if (!private->r_table || !private->g_table - || !private->b_table || !private->y_table) + || !private->b_table || !private->y_table) { - set_error (_("Out of memory.")); - return NULL; + set_error (_("Out of memory.")); + return NULL; } - + for (i = 0; i < 256; i++) { - private->r_table [i + 1024] - = i >> (8 - number_of_bits_set(red_mask)); - private->r_table [i + 1024] - <<= free_bits_at_bottom (red_mask); - private->g_table [i + 1024] - = i >> (8 - number_of_bits_set (green_mask)); - private->g_table [i + 1024] - <<= free_bits_at_bottom (green_mask); - private->b_table [i + 1024] - <<= free_bits_at_bottom (blue_mask); - private->b_table [i + 1024] - = i >> (8 - number_of_bits_set (blue_mask)); - if (twopixels) - { - private->r_table [i + 1024] = ((private->r_table [i + 1024] << 16) - | private->r_table [i + 1024]); - private->g_table [i + 1024] = ((private->g_table [i + 1024] << 16) - | private->g_table [i + 1024]); - private->b_table [i + 1024] = ((private->b_table [i + 1024] << 16) - | private->b_table [i + 1024]); - } - private->y_table [i + 1024] = (private->r_table [i + 1024] - | private->g_table [i + 1024] - | private->b_table [i + 1024]); + private->r_table [i + 1024] + = i >> (8 - number_of_bits_set(red_mask)); + private->r_table [i + 1024] + <<= free_bits_at_bottom (red_mask); + private->g_table [i + 1024] + = i >> (8 - number_of_bits_set (green_mask)); + private->g_table [i + 1024] + <<= free_bits_at_bottom (green_mask); + private->b_table [i + 1024] + <<= free_bits_at_bottom (blue_mask); + private->b_table [i + 1024] + = i >> (8 - number_of_bits_set (blue_mask)); + if (twopixels) + { + private->r_table [i + 1024] = ((private->r_table [i + 1024] << 16) + | private->r_table [i + 1024]); + private->g_table [i + 1024] = ((private->g_table [i + 1024] << 16) + | private->g_table [i + 1024]); + private->b_table [i + 1024] = ((private->b_table [i + 1024] << 16) + | private->b_table [i + 1024]); + } + private->y_table [i + 1024] = (private->r_table [i + 1024] + | private->g_table [i + 1024] + | private->b_table [i + 1024]); } /* @@ -230,14 +230,14 @@ fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, */ for (i = 0; i < 1024; i++) { - private->r_table [i] = private->r_table [1024]; - private->r_table [i + 1024 + 256] = private->r_table [1024 + 255]; - private->g_table [i] = private->g_table [1024]; - private->g_table [i + 1024 + 256] = private->g_table [1024 + 255]; - private->b_table [i] = private->b_table [1024]; - private->b_table [i + 1024 + 256] = private->b_table [1024 + 255]; - private->y_table [i] = private->y_table [1024]; - private->y_table [i + 1024 + 256] = private->y_table [1024 + 255]; + private->r_table [i] = private->r_table [1024]; + private->r_table [i + 1024 + 256] = private->r_table [1024 + 255]; + private->g_table [i] = private->g_table [1024]; + private->g_table [i + 1024 + 256] = private->g_table [1024 + 255]; + private->b_table [i] = private->b_table [1024]; + private->b_table [i + 1024 + 256] = private->b_table [1024 + 255]; + private->y_table [i] = private->y_table [1024]; + private->y_table [i + 1024 + 256] = private->y_table [1024 + 255]; } private->r_table += 1024; @@ -247,7 +247,7 @@ fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, return render; } - + } void @@ -259,7 +259,7 @@ fiasco_renderer_delete (fiasco_renderer_t *renderer) * No return value. * * Side effects: - * structure 'renderer' is discarded. + * structure 'renderer' is discarded. */ { if (!renderer) @@ -284,8 +284,8 @@ fiasco_renderer_delete (fiasco_renderer_t *renderer) int fiasco_renderer_render (const fiasco_renderer_t *renderer, - unsigned char *ximage, - const fiasco_image_t *fiasco_image) + unsigned char *ximage, + const fiasco_image_t *fiasco_image) { if (!renderer) { @@ -298,8 +298,8 @@ fiasco_renderer_render (const fiasco_renderer_t *renderer, /***************************************************************************** - private code - + private code + *****************************************************************************/ /* @@ -313,7 +313,7 @@ fiasco_renderer_render (const fiasco_renderer_t *renderer, * mode, since this involves getting down to byte level again. It is * assumed that the bits for each color are contiguous in the * longword. - * + * * Writing to memory is done in shorts or ints. (Unfortunately, short * is not very fast on Alpha, so there is room for improvement * here). There is no dither time check for overflow - instead the @@ -357,9 +357,9 @@ free_bits_at_bottom (unsigned long a) return 1 + free_bits_at_bottom ( a >> 1); } -static int +static int display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image) + const fiasco_image_t *fiasco_image) /* * Convert 'image' to 16 bit color bitmap. * If 'double_resolution' is true then double image size in both directions. @@ -367,13 +367,13 @@ display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, * No return value. * * Side effects: - * 'out[]' is filled with dithered image + * 'out[]' is filled with dithered image */ { const image_t *image; renderer_private_t *private; - byte_t *out; - + byte_t *out; + if (!this) { set_error (_("Parameter `%s' not defined (NULL)."), "this"); @@ -390,21 +390,21 @@ display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, return 0; } - out = (byte_t *) ximage; + out = (byte_t *) ximage; image = cast_image ((fiasco_image_t *) fiasco_image); if (!image) return 0; private = (renderer_private_t *) this->private; - + if (image->color) { - word_t *cbptr, *crptr; /* pointer to chroma bands */ - word_t *yptr; /* pointers to lumincance band */ - int yval, crval, cbval; /* pixel value in YCbCr color space */ - int R, G, B; /* pixel value in RGB color space */ - int n; /* pixel counter */ - int x, y; /* pixel coordinates */ - int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; + word_t *cbptr, *crptr; /* pointer to chroma bands */ + word_t *yptr; /* pointers to lumincance band */ + int yval, crval, cbval; /* pixel value in YCbCr color space */ + int R, G, B; /* pixel value in RGB color space */ + int n; /* pixel counter */ + int x, y; /* pixel coordinates */ + int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; unsigned int *r_table, *g_table, *b_table; Cr_g_tab = private->Cr_g_tab; @@ -420,245 +420,245 @@ display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, if (image->format == FORMAT_4_2_0) { - u_word_t *dst, *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - if (private->double_resolution) - { - yptr2 = yptr + image->width; - dst = (u_word_t *) out; - dst2 = dst + 4 * image->width; - for (y = image->height / 2; y; y--) - { - for (x = image->width / 2; x; x--) - { + u_word_t *dst, *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + if (private->double_resolution) + { + yptr2 = yptr + image->width; + dst = (u_word_t *) out; + dst2 = dst + 4 * image->width; + for (y = image->height / 2; y; y--) + { + for (x = image->width / 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr++ >> 4) + 128; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr++ / 16 + 128; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - } - memcpy (dst, dst - 2 * image->width, - 2 * image->width * sizeof (u_word_t)); - memcpy (dst2, dst2 - 2 * image->width, - 2 * image->width * sizeof (u_word_t)); - yptr += image->width; - yptr2 += image->width; - dst += 3 * image->width * 2; - dst2 += 3 * image->width * 2; - } - } - else - { - yptr2 = yptr + image->width; - dst = (u_word_t *) out; - dst2 = dst + image->width; - - for (y = image->height / 2; y; y--) - { - for (x = image->width / 2; x; x--) - { + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + } + memcpy (dst, dst - 2 * image->width, + 2 * image->width * sizeof (u_word_t)); + memcpy (dst2, dst2 - 2 * image->width, + 2 * image->width * sizeof (u_word_t)); + yptr += image->width; + yptr2 += image->width; + dst += 3 * image->width * 2; + dst2 += 3 * image->width * 2; + } + } + else + { + yptr2 = yptr + image->width; + dst = (u_word_t *) out; + dst2 = dst + image->width; + + for (y = image->height / 2; y; y--) + { + for (x = image->width / 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr++ >> 4) + 128; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr++ / 16 + 128; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - } - yptr += image->width; - yptr2 += image->width; - dst += image->width; - dst2 += image->width; - } - } + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + } + yptr += image->width; + yptr2 += image->width; + dst += image->width; + dst2 += image->width; + } + } } - else /* 4:4:4 format */ + else /* 4:4:4 format */ { - if (private->double_resolution) - { - unsigned int *dst; /* pointer to dithered pixels */ - - dst = (unsigned int *) out; - - for (y = image->height; y; y--) - { - for (x = image->width; x; x--) - { + if (private->double_resolution) + { + unsigned int *dst; /* pointer to dithered pixels */ + + dst = (unsigned int *) out; + + for (y = image->height; y; y--) + { + for (x = image->width; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - - *dst++ = r_table [R] | g_table [G] | b_table [B]; - } - memcpy (dst, dst - image->width, - image->width * sizeof (unsigned int)); - dst += image->width; - } - } - else - { - u_word_t *dst; /* pointer to dithered pixels */ - - dst = (u_word_t *) out; - - for (n = image->width * image->height; n; n--) - { + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + + *dst++ = r_table [R] | g_table [G] | b_table [B]; + } + memcpy (dst, dst - image->width, + image->width * sizeof (unsigned int)); + dst += image->width; + } + } + else + { + u_word_t *dst; /* pointer to dithered pixels */ + + dst = (u_word_t *) out; + + for (n = image->width * image->height; n; n--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - } - } + *dst++ = r_table [R] | g_table [G] | b_table [B]; + } + } } } else { - unsigned int *dst; /* pointer to dithered pixels */ - word_t *src; /* current pixel of frame */ + unsigned int *dst; /* pointer to dithered pixels */ + word_t *src; /* current pixel of frame */ unsigned int *y_table; y_table = private->y_table; dst = (unsigned int *) out; src = image->pixels [GRAY]; - + if (private->double_resolution) { - int x, y; /* pixel coordinates */ - - for (y = image->height; y; y--) - { - for (x = image->width; x; x--) - { - int value; - + int x, y; /* pixel coordinates */ + + for (y = image->height; y; y--) + { + for (x = image->width; x; x--) + { + int value; + #ifdef HAVE_SIGNED_SHIFT - value = y_table [*src++ >> 4]; + value = y_table [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - value = y_table [*src++ / 16]; + value = y_table [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = (value << 16) | value; - } - - memcpy (dst, dst - image->width, - image->width * sizeof (unsigned int)); - dst += image->width; - } + *dst++ = (value << 16) | value; + } + + memcpy (dst, dst - image->width, + image->width * sizeof (unsigned int)); + dst += image->width; + } } else { - int n; /* pixel counter */ - - for (n = image->width * image->height / 2; n; n--, src += 2) + int n; /* pixel counter */ + + for (n = image->width * image->height / 2; n; n--, src += 2) #ifdef HAVE_SIGNED_SHIFT -# if BYTE_ORDER == LITTLE_ENDIAN - *dst++ = (y_table [src [1] >> 4] << 16) | y_table [src [0] >> 4]; -# else - *dst++ = (y_table [src [0] >> 4] << 16) | y_table [src [1] >> 4]; -# endif +# if BYTE_ORDER == LITTLE_ENDIAN + *dst++ = (y_table [src [1] >> 4] << 16) | y_table [src [0] >> 4]; +# else + *dst++ = (y_table [src [0] >> 4] << 16) | y_table [src [1] >> 4]; +# endif #else /* not HAVE_SIGNED_SHIFT */ -# if BYTE_ORDER == LITTLE_ENDIAN - *dst++ = (y_table [src [1] / 16] << 16) | y_table [src [0] / 16]; -# else - *dst++ = (y_table [src [0] / 16] << 16) | y_table [src [1] / 16]; -# endif +# if BYTE_ORDER == LITTLE_ENDIAN + *dst++ = (y_table [src [1] / 16] << 16) | y_table [src [0] / 16]; +# else + *dst++ = (y_table [src [0] / 16] << 16) | y_table [src [1] / 16]; +# endif #endif /* not HAVE_SIGNED_SHIFT */ } } @@ -666,9 +666,9 @@ display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, return 1; } -static int +static int display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image) + const fiasco_image_t *fiasco_image) /* * Convert 'image' to 16 bit color bitmap. * If 'double_resolution' is true then double image size in both directions. @@ -676,13 +676,13 @@ display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, * No return value. * * Side effects: - * 'out[]' is filled with dithered image + * 'out[]' is filled with dithered image */ { - unsigned *gray_clip = init_clipping (); + unsigned *gray_clip = init_clipping (); const image_t *image; renderer_private_t *private; - byte_t *out; + byte_t *out; if (!gray_clip) return 0; @@ -702,17 +702,17 @@ display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, return 0; } - out = (byte_t *) ximage; + out = (byte_t *) ximage; image = cast_image ((fiasco_image_t *) fiasco_image); if (!image) return 0; private = (renderer_private_t *) this->private; - + if (image->color) { - word_t *cbptr, *crptr; /* pointer to chroma bands */ - word_t *yptr; /* pointers to lumincance band */ - int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; + word_t *cbptr, *crptr; /* pointer to chroma bands */ + word_t *yptr; /* pointers to lumincance band */ + int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; Cr_g_tab = private->Cr_g_tab; Cr_r_tab = private->Cr_r_tab; @@ -724,396 +724,396 @@ display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, if (image->format == FORMAT_4_2_0) { - if (private->double_resolution) - { - int yval1; /* lumincance pixel */ - int crval1, cbval1; /* chroma pixels */ - int yval2; /* pixel in YCbCr color space */ - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* pointer to dithered pixels */ - unsigned int *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - dst = (unsigned int *) out; - dst2 = dst + (image->width >> 1) * 3 * 2; - yptr2 = yptr + image->width; - - for (y = image->height >> 1; y; y--) - { - for (x = image->width >> 1; x; x--) - { + if (private->double_resolution) + { + int yval1; /* lumincance pixel */ + int crval1, cbval1; /* chroma pixels */ + int yval2; /* pixel in YCbCr color space */ + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* pointer to dithered pixels */ + unsigned int *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + dst = (unsigned int *) out; + dst2 = dst + (image->width >> 1) * 3 * 2; + yptr2 = yptr + image->width; + + for (y = image->height >> 1; y; y--) + { + for (x = image->width >> 1; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); - *dst++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); - *dst++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); + *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); + *dst++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); + *dst++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); - *dst2++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); - *dst2++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); - } - memcpy (dst, dst - (image->width >> 1) * 3, - (image->width >> 1) * 3 * sizeof (unsigned int)); - memcpy (dst2, dst2 - (image->width >> 1) * 3, - (image->width >> 1) * 3 * sizeof (unsigned int)); - dst += (image->width >> 1) * 3 * 3; - dst2 += (image->width >> 1) * 3 * 3; - yptr += image->width; - yptr2 += image->width; - } - } - else - { - int yval1; /* lumincance pixel */ - int crval1, cbval1; /* chroma pixels */ - int yval2; /* pixel in YCbCr color space */ - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* pointer to dithered pixels */ - unsigned int *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - dst = (unsigned int *) out; - dst2 = dst + (image->width >> 2) * 3; - yptr2 = yptr + image->width; - - for (y = image->height >> 1; y; y--) - { - for (x = image->width >> 2; x; x--) - { + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); + *dst2++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); + *dst2++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); + } + memcpy (dst, dst - (image->width >> 1) * 3, + (image->width >> 1) * 3 * sizeof (unsigned int)); + memcpy (dst2, dst2 - (image->width >> 1) * 3, + (image->width >> 1) * 3 * sizeof (unsigned int)); + dst += (image->width >> 1) * 3 * 3; + dst2 += (image->width >> 1) * 3 * 3; + yptr += image->width; + yptr2 += image->width; + } + } + else + { + int yval1; /* lumincance pixel */ + int crval1, cbval1; /* chroma pixels */ + int yval2; /* pixel in YCbCr color space */ + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* pointer to dithered pixels */ + unsigned int *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + dst = (unsigned int *) out; + dst2 = dst + (image->width >> 2) * 3; + yptr2 = yptr + image->width; + + for (y = image->height >> 1; y; y--) + { + for (x = image->width >> 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); - *dst = G2 | (R2 << 8); + *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); + *dst = G2 | (R2 << 8); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); - *dst2 = G2 | (R2 << 8); - + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); + *dst2 = G2 | (R2 << 8); + #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ |= (B1 << 16) | (G1 << 24); - *dst++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); + *dst++ |= (B1 << 16) | (G1 << 24); + *dst++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ |= (B1 << 16) | (G1 << 24); - *dst2++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); - } - dst += (image->width >> 2) * 3; - dst2 += (image->width >> 2) * 3; - yptr += image->width; - yptr2 += image->width; - } - } + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ |= (B1 << 16) | (G1 << 24); + *dst2++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); + } + dst += (image->width >> 2) * 3; + dst2 += (image->width >> 2) * 3; + yptr += image->width; + yptr2 += image->width; + } + } } - else /* 4:4:4 format */ + else /* 4:4:4 format */ { - if (private->double_resolution) - { - unsigned int R1, G1, B1; /* pixel1 in RGB color space */ - unsigned int R2, G2, B2; /* pixel2 in RGB color space */ - int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ - int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* dithered pixel pointer */ - - dst = (unsigned int *) out; - - for (y = image->height; y; y--) - { - for (x = image->width >> 1; x; x--) - { + if (private->double_resolution) + { + unsigned int R1, G1, B1; /* pixel1 in RGB color space */ + unsigned int R2, G2, B2; /* pixel2 in RGB color space */ + int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ + int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* dithered pixel pointer */ + + dst = (unsigned int *) out; + + for (y = image->height; y; y--) + { + for (x = image->width >> 1; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] - + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - - *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); - *dst++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); - *dst++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); - } - memcpy (dst, dst - 3 * (image->width >> 1), - 3 * (image->width >> 1) * sizeof (unsigned int)); - dst += 3 * (image->width >> 1); - } - } - else - { - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ - int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ - int n; /* pixel counter */ - unsigned int *dst; /* dithered pixel pointer */ - - dst = (unsigned int *) out; - - for (n = (image->width * image->height) >> 2; n; n--) - { + + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + + *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); + *dst++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); + *dst++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); + } + memcpy (dst, dst - 3 * (image->width >> 1), + 3 * (image->width >> 1) * sizeof (unsigned int)); + dst += 3 * (image->width >> 1); + } + } + else + { + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ + int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ + int n; /* pixel counter */ + unsigned int *dst; /* dithered pixel pointer */ + + dst = (unsigned int *) out; + + for (n = (image->width * image->height) >> 2; n; n--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); - *dst = G2 | (R2 << 8); + *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); + *dst = G2 | (R2 << 8); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - - *dst++ |= (B1 << 16) | (G1 << 24); - *dst++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); - } - } + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + + *dst++ |= (B1 << 16) | (G1 << 24); + *dst++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); + } + } } } else { - unsigned int *dst; /* pointer to dithered pixels */ - word_t *src; /* current pixel of frame */ + unsigned int *dst; /* pointer to dithered pixels */ + word_t *src; /* current pixel of frame */ dst = (unsigned int *) out; src = image->pixels [GRAY]; if (private->double_resolution) { - int x, y; /* pixel counter */ - unsigned *shift_clipping = gray_clip + 128; - - for (y = image->height; y; y--) - { - for (x = image->width >> 1; x; x--) - { - unsigned int val1, val2; + int x, y; /* pixel counter */ + unsigned *shift_clipping = gray_clip + 128; + + for (y = image->height; y; y--) + { + for (x = image->width >> 1; x; x--) + { + unsigned int val1, val2; #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = val1 | (val1 << 8) | (val1 << 16) | (val1 << 24); - *dst++ = val1 | (val1 << 8) | (val2 << 16) | (val2 << 24); - *dst++ = val2 | (val2 << 8) | (val2 << 16) | (val2 << 24); - } + *dst++ = val1 | (val1 << 8) | (val1 << 16) | (val1 << 24); + *dst++ = val1 | (val1 << 8) | (val2 << 16) | (val2 << 24); + *dst++ = val2 | (val2 << 8) | (val2 << 16) | (val2 << 24); + } - memcpy (dst, dst - 3 * (image->width >> 1), - 3 * (image->width >> 1) * sizeof (unsigned int)); - dst += 3 * (image->width >> 1); - } + memcpy (dst, dst - 3 * (image->width >> 1), + 3 * (image->width >> 1) * sizeof (unsigned int)); + dst += 3 * (image->width >> 1); + } } else { - int n; /* pixel counter */ - unsigned *shift_clipping = gray_clip + 128; + int n; /* pixel counter */ + unsigned *shift_clipping = gray_clip + 128; - for (n = (image->width * image->height) >> 2; n; n--) - { - unsigned int val1, val2; + for (n = (image->width * image->height) >> 2; n; n--) + { + unsigned int val1, val2; #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = val1 | (val1 << 8) - | (val1 << 16) | (val2 << 24); /* RGBR */ - *dst = val2 | (val2 << 8); /* GB-- */ + *dst++ = val1 | (val1 << 8) + | (val1 << 16) | (val2 << 24); /* RGBR */ + *dst = val2 | (val2 << 8); /* GB-- */ #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - - *dst++ |= (val1 << 16) | (val1 << 24); /* --RG */ - *dst++ = val1 | (val2 << 8) - | (val2 << 16) | (val2 << 24); /* BRGB */ - } + + *dst++ |= (val1 << 16) | (val1 << 24); /* --RG */ + *dst++ = val1 | (val2 << 8) + | (val2 << 16) | (val2 << 24); /* BRGB */ + } } } - + return 1; } -static int +static int display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image) + const fiasco_image_t *fiasco_image) /* * Convert 'image' to 16 bit color bitmap. * If 'double_resolution' is true then double image size in both directions. @@ -1121,13 +1121,13 @@ display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, * No return value. * * Side effects: - * 'out[]' is filled with dithered image + * 'out[]' is filled with dithered image */ { - unsigned *gray_clip = init_clipping (); + unsigned *gray_clip = init_clipping (); const image_t *image; renderer_private_t *private; - byte_t *out; + byte_t *out; if (!gray_clip) return 0; @@ -1147,17 +1147,17 @@ display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, return 0; } - out = (byte_t *) ximage; + out = (byte_t *) ximage; image = cast_image ((fiasco_image_t *) fiasco_image); if (!image) return 0; private = (renderer_private_t *) this->private; - + if (image->color) { - word_t *cbptr, *crptr; /* pointer to chroma bands */ - word_t *yptr; /* pointers to lumincance band */ - int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; + word_t *cbptr, *crptr; /* pointer to chroma bands */ + word_t *yptr; /* pointers to lumincance band */ + int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; Cr_g_tab = private->Cr_g_tab; Cr_r_tab = private->Cr_r_tab; @@ -1169,396 +1169,396 @@ display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, if (image->format == FORMAT_4_2_0) { - if (private->double_resolution) - { - int yval1; /* lumincance pixel */ - int crval1, cbval1; /* chroma pixels */ - int yval2; /* pixel in YCbCr color space */ - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* pointer to dithered pixels */ - unsigned int *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - dst = (unsigned int *) out; - dst2 = dst + (image->width >> 1) * 3 * 2; - yptr2 = yptr + image->width; - - for (y = image->height >> 1; y; y--) - { - for (x = image->width >> 1; x; x--) - { + if (private->double_resolution) + { + int yval1; /* lumincance pixel */ + int crval1, cbval1; /* chroma pixels */ + int yval2; /* pixel in YCbCr color space */ + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* pointer to dithered pixels */ + unsigned int *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + dst = (unsigned int *) out; + dst2 = dst + (image->width >> 1) * 3 * 2; + yptr2 = yptr + image->width; + + for (y = image->height >> 1; y; y--) + { + for (x = image->width >> 1; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); - *dst++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); - *dst++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); + *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); + *dst++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); + *dst++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); - *dst2++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); - *dst2++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); - } - memcpy (dst, dst - (image->width >> 1) * 3, - (image->width >> 1) * 3 * sizeof (unsigned int)); - memcpy (dst2, dst2 - (image->width >> 1) * 3, - (image->width >> 1) * 3 * sizeof (unsigned int)); - dst += (image->width >> 1) * 3 * 3; - dst2 += (image->width >> 1) * 3 * 3; - yptr += image->width; - yptr2 += image->width; - } - } - else - { - int yval1; /* lumincance pixel */ - int crval1, cbval1; /* chroma pixels */ - int yval2; /* pixel in YCbCr color space */ - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* pointer to dithered pixels */ - unsigned int *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - dst = (unsigned int *) out; - dst2 = dst + (image->width >> 2) * 3; - yptr2 = yptr + image->width; - - for (y = image->height >> 1; y; y--) - { - for (x = image->width >> 2; x; x--) - { + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); + *dst2++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); + *dst2++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); + } + memcpy (dst, dst - (image->width >> 1) * 3, + (image->width >> 1) * 3 * sizeof (unsigned int)); + memcpy (dst2, dst2 - (image->width >> 1) * 3, + (image->width >> 1) * 3 * sizeof (unsigned int)); + dst += (image->width >> 1) * 3 * 3; + dst2 += (image->width >> 1) * 3 * 3; + yptr += image->width; + yptr2 += image->width; + } + } + else + { + int yval1; /* lumincance pixel */ + int crval1, cbval1; /* chroma pixels */ + int yval2; /* pixel in YCbCr color space */ + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* pointer to dithered pixels */ + unsigned int *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + dst = (unsigned int *) out; + dst2 = dst + (image->width >> 2) * 3; + yptr2 = yptr + image->width; + + for (y = image->height >> 1; y; y--) + { + for (x = image->width >> 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); - *dst = G2 | (B2 << 8); + *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); + *dst = G2 | (B2 << 8); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); - *dst2 = G2 | (B2 << 8); - + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); + *dst2 = G2 | (B2 << 8); + #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ |= (R1 << 16) | (G1 << 24); - *dst++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); + *dst++ |= (R1 << 16) | (G1 << 24); + *dst++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ |= (R1 << 16) | (G1 << 24); - *dst2++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); - } - dst += (image->width >> 2) * 3; - dst2 += (image->width >> 2) * 3; - yptr += image->width; - yptr2 += image->width; - } - } + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ |= (R1 << 16) | (G1 << 24); + *dst2++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); + } + dst += (image->width >> 2) * 3; + dst2 += (image->width >> 2) * 3; + yptr += image->width; + yptr2 += image->width; + } + } } - else /* 4:4:4 format */ + else /* 4:4:4 format */ { - if (private->double_resolution) - { - unsigned int R1, G1, B1; /* pixel1 in RGB color space */ - unsigned int R2, G2, B2; /* pixel2 in RGB color space */ - int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ - int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* dithered pixel pointer */ - - dst = (unsigned int *) out; - - for (y = image->height; y; y--) - { - for (x = image->width >> 1; x; x--) - { + if (private->double_resolution) + { + unsigned int R1, G1, B1; /* pixel1 in RGB color space */ + unsigned int R2, G2, B2; /* pixel2 in RGB color space */ + int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ + int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* dithered pixel pointer */ + + dst = (unsigned int *) out; + + for (y = image->height; y; y--) + { + for (x = image->width >> 1; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] - + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - - *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); - *dst++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); - *dst++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); - } - memcpy (dst, dst - 3 * (image->width >> 1), - 3 * (image->width >> 1) * sizeof (unsigned int)); - dst += 3 * (image->width >> 1); - } - } - else - { - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ - int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ - int n; /* pixel counter */ - unsigned int *dst; /* dithered pixel pointer */ - - dst = (unsigned int *) out; - - for (n = (image->width * image->height) >> 2; n; n--) - { + + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + + *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); + *dst++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); + *dst++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); + } + memcpy (dst, dst - 3 * (image->width >> 1), + 3 * (image->width >> 1) * sizeof (unsigned int)); + dst += 3 * (image->width >> 1); + } + } + else + { + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ + int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ + int n; /* pixel counter */ + unsigned int *dst; /* dithered pixel pointer */ + + dst = (unsigned int *) out; + + for (n = (image->width * image->height) >> 2; n; n--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); - *dst = G2 | (B2 << 8); + *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); + *dst = G2 | (B2 << 8); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - - *dst++ |= (R1 << 16) | (G1 << 24); - *dst++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); - } - } + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + + *dst++ |= (R1 << 16) | (G1 << 24); + *dst++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); + } + } } } else { - unsigned int *dst; /* pointer to dithered pixels */ - word_t *src; /* current pixel of frame */ + unsigned int *dst; /* pointer to dithered pixels */ + word_t *src; /* current pixel of frame */ dst = (unsigned int *) out; src = image->pixels [GRAY]; if (private->double_resolution) { - int x, y; /* pixel counter */ - unsigned *shift_clipping = gray_clip + 128; - - for (y = image->height; y; y--) - { - for (x = image->width >> 1; x; x--) - { - unsigned int val1, val2; + int x, y; /* pixel counter */ + unsigned *shift_clipping = gray_clip + 128; + + for (y = image->height; y; y--) + { + for (x = image->width >> 1; x; x--) + { + unsigned int val1, val2; #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = val1 | (val1 << 8) | (val1 << 16) | (val1 << 24); - *dst++ = val1 | (val1 << 8) | (val2 << 16) | (val2 << 24); - *dst++ = val2 | (val2 << 8) | (val2 << 16) | (val2 << 24); - } + *dst++ = val1 | (val1 << 8) | (val1 << 16) | (val1 << 24); + *dst++ = val1 | (val1 << 8) | (val2 << 16) | (val2 << 24); + *dst++ = val2 | (val2 << 8) | (val2 << 16) | (val2 << 24); + } - memcpy (dst, dst - 3 * (image->width >> 1), - 3 * (image->width >> 1) * sizeof (unsigned int)); - dst += 3 * (image->width >> 1); - } + memcpy (dst, dst - 3 * (image->width >> 1), + 3 * (image->width >> 1) * sizeof (unsigned int)); + dst += 3 * (image->width >> 1); + } } else { - int n; /* pixel counter */ - unsigned *shift_clipping = gray_clip + 128; + int n; /* pixel counter */ + unsigned *shift_clipping = gray_clip + 128; - for (n = (image->width * image->height) >> 2; n; n--) - { - unsigned int val1, val2; + for (n = (image->width * image->height) >> 2; n; n--) + { + unsigned int val1, val2; #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = val1 | (val1 << 8) - | (val1 << 16) | (val2 << 24); /* RGBR */ - *dst = val2 | (val2 << 8); /* GB-- */ + *dst++ = val1 | (val1 << 8) + | (val1 << 16) | (val2 << 24); /* RGBR */ + *dst = val2 | (val2 << 8); /* GB-- */ #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - - *dst++ |= (val1 << 16) | (val1 << 24); /* --RG */ - *dst++ = val1 | (val2 << 8) - | (val2 << 16) | (val2 << 24); /* BRGB */ - } + + *dst++ |= (val1 << 16) | (val1 << 24); /* --RG */ + *dst++ = val1 | (val2 << 8) + | (val2 << 16) | (val2 << 24); /* BRGB */ + } } } - + return 1; } -static int +static int display_32_bit (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image) + const fiasco_image_t *fiasco_image) /* * Convert 'image' to 16 bit color bitmap. * If 'double_resolution' is true then double image size in both directions. @@ -1566,13 +1566,13 @@ display_32_bit (const struct fiasco_renderer *this, unsigned char *ximage, * No return value. * * Side effects: - * 'out[]' is filled with dithered image + * 'out[]' is filled with dithered image */ { const image_t *image; renderer_private_t *private; - byte_t *out; - + byte_t *out; + if (!this) { set_error (_("Parameter `%s' not defined (NULL)."), "this"); @@ -1589,21 +1589,21 @@ display_32_bit (const struct fiasco_renderer *this, unsigned char *ximage, return 0; } - out = (byte_t *) ximage; + out = (byte_t *) ximage; private = (renderer_private_t *) this->private; image = cast_image ((fiasco_image_t *) fiasco_image); if (!image) return 0; - + if (image->color) { - word_t *cbptr, *crptr; /* pointer to chroma bands */ - word_t *yptr; /* pointers to lumincance band */ - int yval, crval, cbval; /* pixel value in YCbCr color space */ - int R, G, B; /* pixel value in RGB color space */ - int n; /* pixel counter */ - int x, y; /* pixel coordinates */ - int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; + word_t *cbptr, *crptr; /* pointer to chroma bands */ + word_t *yptr; /* pointers to lumincance band */ + int yval, crval, cbval; /* pixel value in YCbCr color space */ + int R, G, B; /* pixel value in RGB color space */ + int n; /* pixel counter */ + int x, y; /* pixel coordinates */ + int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; unsigned int *r_table, *g_table, *b_table; Cr_g_tab = private->Cr_g_tab; @@ -1619,245 +1619,245 @@ display_32_bit (const struct fiasco_renderer *this, unsigned char *ximage, if (image->format == FORMAT_4_2_0) { - unsigned int *dst, *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - if (private->double_resolution) - { - yptr2 = yptr + image->width; - dst = (unsigned int *) out; - dst2 = dst + 4 * image->width; - for (y = image->height / 2; y; y--) - { - for (x = image->width / 2; x; x--) - { + unsigned int *dst, *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + if (private->double_resolution) + { + yptr2 = yptr + image->width; + dst = (unsigned int *) out; + dst2 = dst + 4 * image->width; + for (y = image->height / 2; y; y--) + { + for (x = image->width / 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr++ >> 4) + 128; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr++ / 16 + 128; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - } - memcpy (dst, dst - 2 * image->width, - 2 * image->width * sizeof (unsigned int)); - memcpy (dst2, dst2 - 2 * image->width, - 2 * image->width * sizeof (unsigned int)); - yptr += image->width; - yptr2 += image->width; - dst += 3 * image->width * 2; - dst2 += 3 * image->width * 2; - } - } - else - { - yptr2 = yptr + image->width; - dst = (unsigned int *) out; - dst2 = dst + image->width; - - for (y = image->height / 2; y; y--) - { - for (x = image->width / 2; x; x--) - { + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + } + memcpy (dst, dst - 2 * image->width, + 2 * image->width * sizeof (unsigned int)); + memcpy (dst2, dst2 - 2 * image->width, + 2 * image->width * sizeof (unsigned int)); + yptr += image->width; + yptr2 += image->width; + dst += 3 * image->width * 2; + dst2 += 3 * image->width * 2; + } + } + else + { + yptr2 = yptr + image->width; + dst = (unsigned int *) out; + dst2 = dst + image->width; + + for (y = image->height / 2; y; y--) + { + for (x = image->width / 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr++ >> 4) + 128; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr++ / 16 + 128; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - } - yptr += image->width; - yptr2 += image->width; - dst += image->width; - dst2 += image->width; - } - } + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + } + yptr += image->width; + yptr2 += image->width; + dst += image->width; + dst2 += image->width; + } + } } - else /* 4:4:4 format */ + else /* 4:4:4 format */ { - if (private->double_resolution) - { - unsigned int *dst; /* pointer to dithered pixels */ - - dst = (unsigned int *) out; - - for (y = image->height; y; y--) - { - for (x = image->width; x; x--) - { + if (private->double_resolution) + { + unsigned int *dst; /* pointer to dithered pixels */ + + dst = (unsigned int *) out; + + for (y = image->height; y; y--) + { + for (x = image->width; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - - *dst++ = r_table [R] | g_table [G] | b_table [B]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - } - memcpy (dst, dst - 2 * image->width, - 2 * image->width * sizeof (unsigned int)); - dst += image->width * 2; - } - } - else - { - unsigned int *dst; /* pointer to dithered pixels */ - - dst = (unsigned int *) out; - - for (n = image->width * image->height; n; n--) - { + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + + *dst++ = r_table [R] | g_table [G] | b_table [B]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + } + memcpy (dst, dst - 2 * image->width, + 2 * image->width * sizeof (unsigned int)); + dst += image->width * 2; + } + } + else + { + unsigned int *dst; /* pointer to dithered pixels */ + + dst = (unsigned int *) out; + + for (n = image->width * image->height; n; n--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - } - } + *dst++ = r_table [R] | g_table [G] | b_table [B]; + } + } } } else { - unsigned int *dst; /* pointer to dithered pixels */ - word_t *src; /* current pixel of frame */ + unsigned int *dst; /* pointer to dithered pixels */ + word_t *src; /* current pixel of frame */ unsigned int *y_table; y_table = private->y_table; dst = (unsigned int *) out; src = image->pixels [GRAY]; - + if (private->double_resolution) { - int x, y; /* pixel coordinates */ - - for (y = image->height; y; y--) - { - for (x = image->width; x; x--) - { - int value; + int x, y; /* pixel coordinates */ + + for (y = image->height; y; y--) + { + for (x = image->width; x; x--) + { + int value; #ifdef HAVE_SIGNED_SHIFT - value = y_table [*src++ >> 4]; + value = y_table [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - value = y_table [*src++ / 16]; + value = y_table [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = value; - *dst++ = value; - } - - memcpy (dst, dst - 2 * image->width, - 2 * image->width * sizeof (unsigned int)); - dst += 2 * image->width; - } + *dst++ = value; + *dst++ = value; + } + + memcpy (dst, dst - 2 * image->width, + 2 * image->width * sizeof (unsigned int)); + dst += 2 * image->width; + } } else { - int n; /* pixel counter */ - - for (n = image->width * image->height; n; n--) + int n; /* pixel counter */ + + for (n = image->width * image->height; n; n--) #ifdef HAVE_SIGNED_SHIFT - *dst++ = y_table [*src++ >> 4]; + *dst++ = y_table [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - *dst++ = y_table [*src++ / 16]; + *dst++ = y_table [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ } } - + return 1; } - + diff --git a/converter/other/fiasco/lib/dither.h b/converter/other/fiasco/lib/dither.h index 767bca28..e786af1f 100644 --- a/converter/other/fiasco/lib/dither.h +++ b/converter/other/fiasco/lib/dither.h @@ -1,8 +1,8 @@ /* * dither.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 */ @@ -19,9 +19,9 @@ typedef struct renderer_private { - int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; + int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; unsigned int *r_table, *g_table, *b_table, *y_table; - bool_t double_resolution; + bool_t double_resolution; } renderer_private_t; #endif /* _DITHER_H */ diff --git a/converter/other/fiasco/lib/error.c b/converter/other/fiasco/lib/error.c index 394f896f..30d0cf97 100644 --- a/converter/other/fiasco/lib/error.c +++ b/converter/other/fiasco/lib/error.c @@ -1,11 +1,11 @@ /* - * error.c: Error handling + * error.c: Error handling * - * Written by: Stefan Frank - * Ullrich Hafner + * Written by: Stefan Frank + * Ullrich Hafner * - * Credits: Modelled after variable argument routines from Jef - * Poskanzer's pbmplus package. + * Credits: Modelled after variable argument routines from Jef + * Poskanzer's pbmplus package. * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -24,7 +24,7 @@ #include <string.h> #if HAVE_SETJMP_H -# include <setjmp.h> +# include <setjmp.h> #endif /* HAVE_SETJMP_H */ #include "types.h" @@ -36,12 +36,12 @@ /***************************************************************************** - local variables + local variables *****************************************************************************/ static fiasco_verbosity_e verboselevel = FIASCO_SOME_VERBOSITY; -static char *error_message = NULL; +static char *error_message = NULL; #if HAVE_SETJMP_H jmp_buf env; @@ -49,7 +49,7 @@ jmp_buf env; /***************************************************************************** - public code + public code *****************************************************************************/ @@ -195,7 +195,7 @@ warning(const char * const format, ...) { /*---------------------------------------------------------------------------- Issue a warning. -----------------------------------------------------------------------------*/ - va_list args; + va_list args; VA_START (args, format); diff --git a/converter/other/fiasco/lib/error.h b/converter/other/fiasco/lib/error.h index 4159ccd2..dd6a049f 100644 --- a/converter/other/fiasco/lib/error.h +++ b/converter/other/fiasco/lib/error.h @@ -1,6 +1,6 @@ /* * error.h - * + * * Written by: Stefan Frank * Ullrich Hafner * @@ -19,11 +19,11 @@ void file_error (const char *filename); void message (const char *format, ...); -void +void debug_message (const char *format, ...); void warning (const char *format, ...); -void +void info (const char *format, ...); const char * get_system_error (void); diff --git a/converter/other/fiasco/lib/image.h b/converter/other/fiasco/lib/image.h index c3c5f0df..d6a3c6c0 100644 --- a/converter/other/fiasco/lib/image.h +++ b/converter/other/fiasco/lib/image.h @@ -1,8 +1,8 @@ /* * image.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 */ @@ -31,11 +31,11 @@ typedef struct image { char id [8]; /* NUL-terminated "IFIASCO" */ unsigned reference_count; - unsigned width; /* Width of the image */ - unsigned height; /* Height of the image */ - bool_t color; /* Color or grayscale image */ - format_e format; /* Pixel format 4:4:4 or 4:2:0 */ - word_t *pixels [3]; /* Pixels in short format */ + unsigned width; /* Width of the image */ + unsigned height; /* Height of the image */ + bool_t color; /* Color or grayscale image */ + format_e format; /* Pixel format 4:4:4 or 4:2:0 */ + word_t *pixels [3]; /* Pixels in short format */ } image_t; image_t * @@ -48,7 +48,7 @@ void free_image (image_t *image); FILE * read_pnmheader (const char *image_name, unsigned *width, unsigned *height, - bool_t *color); + bool_t *color); image_t * read_image_stream(FILE * const ifP, diff --git a/converter/other/fiasco/lib/list.c b/converter/other/fiasco/lib/list.c index b67ff4b8..24ba4985 100644 --- a/converter/other/fiasco/lib/list.c +++ b/converter/other/fiasco/lib/list.c @@ -1,8 +1,8 @@ /* - * list.c: List operations + * list.c: List operations + * + * 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 */ @@ -27,8 +27,8 @@ /***************************************************************************** - public code - + public code + *****************************************************************************/ list_t * @@ -39,15 +39,15 @@ alloc_list (size_t size_of_element) * Size of list element values is given by 'size_of_element'. * * Return value: - * pointer to an empty list + * pointer to an empty list */ { list_t *new_list = Calloc (1, sizeof (list_t)); assert (size_of_element > 0); - new_list->head = NULL; - new_list->tail = NULL; + new_list->head = NULL; + new_list->tail = NULL; new_list->size_of_element = size_of_element; return new_list; @@ -62,11 +62,11 @@ free_list (list_t *list) * No return value. * * Side effects: - * struct 'list' is discarded + * struct 'list' is discarded */ { assert (list); - + while (list_remove (list, HEAD, NULL)) ; Free (list); @@ -76,7 +76,7 @@ void list_insert (list_t *list, pos_e pos, const void *data) /* * Insert a new 'list' element at head ('pos' = HEAD) or - * tail ('pos' = TAIL) of 'list'. + * tail ('pos' = TAIL) of 'list'. * 'data' is a pointer to a memory segment of size * 'list'->size_of_element containing the value to store. * The value is directly copied - no references are stored. @@ -84,14 +84,14 @@ list_insert (list_t *list, pos_e pos, const void *data) * No return value. * * Side effects: - * lists current tail or head is replaced by the new element + * lists current tail or head is replaced by the new element */ { node_t *element; assert (list && data); - element = Calloc (1, sizeof (node_t)); + element = Calloc (1, sizeof (node_t)); element->value = Calloc (1, list->size_of_element); memcpy (element->value, data, list->size_of_element); @@ -100,20 +100,20 @@ list_insert (list_t *list, pos_e pos, const void *data) element->next = NULL; element->prev = list->tail; if (list->tail) - list->tail->next = element; + list->tail->next = element; list->tail = element; if (!list->head) - list->head = element; + list->head = element; } - else /* pos == HEAD */ + else /* pos == HEAD */ { element->prev = NULL; element->next = list->head; if (list->head) - list->head->prev = element; + list->head->prev = element; list->head = element; if (!list->tail) - list->tail = element; + list->tail = element; } } @@ -123,57 +123,57 @@ list_remove (list_t *list, pos_e pos, void *data) * Remove 'list' element from head or tail of 'list'. * * Return value: - * TRUE on success, - * FALSE if list is empty or - * if list value data is NULL + * TRUE on success, + * FALSE if list is empty or + * if list value data is NULL * * Side effects: - * lists current head or tail is removed - * value of the removed list element (if not NULL) is copied to + * lists current head or tail is removed + * value of the removed list element (if not NULL) is copied to * 'data' (if 'data' is not NULL) */ { node_t *element; - void *valueptr; + void *valueptr; assert (list); - + if (pos == TAIL) { element = list->tail; if (element) { - list->tail = element->prev; - valueptr = element->value; - Free (element); + list->tail = element->prev; + valueptr = element->value; + Free (element); } else - valueptr = NULL; - if (!list->tail) /* 'element' was last node */ - list->head = NULL; + valueptr = NULL; + if (!list->tail) /* 'element' was last node */ + list->head = NULL; } - else /* pos == HEAD */ + else /* pos == HEAD */ { element = list->head; if (element) { - list->head = element->next; - valueptr = element->value; - Free (element); + list->head = element->next; + valueptr = element->value; + Free (element); } else - valueptr = NULL; - if (!list->head) /* 'element' was last node */ - list->tail = NULL; + valueptr = NULL; + if (!list->head) /* 'element' was last node */ + list->tail = NULL; } - if (valueptr) /* copy value of node */ + if (valueptr) /* copy value of node */ { - if (data) - memcpy (data, valueptr, list->size_of_element); + if (data) + memcpy (data, valueptr, list->size_of_element); Free (valueptr); } - + return valueptr ? TRUE : FALSE; } @@ -184,27 +184,27 @@ list_element_n (const list_t *list, pos_e pos, unsigned n, void *data) * (First element is list head if 'pos' == HEAD * or list tail if 'pos' == TAIL. * Accordingly, traverse the list in ascending or descending order). - * + * * Return value: - * TRUE on success, FALSE if there is no element 'n' + * TRUE on success, FALSE if there is no element 'n' * * Side effects: - * value of list element 'n' is copied to 'data' + * value of list element 'n' is copied to 'data' */ { node_t *element; assert (list && data); - + if (pos == HEAD) for (element = list->head; element != NULL && n; - element = element->next, n--) - ; + element = element->next, n--) + ; else for (element = list->tail; element != NULL && n; - element = element->prev, n--) - ; - + element = element->prev, n--) + ; + if (element) { memcpy (data, element->value, list->size_of_element); @@ -220,14 +220,14 @@ list_sizeof (const list_t *list) * Count number of 'list' elements. * * Return value: - * number of 'list' elements. + * number of 'list' elements. */ { node_t *element; unsigned n = 0; assert (list); - + for (element = list->head; element != NULL; element = element->next) n++; @@ -247,7 +247,7 @@ list_foreach (const list_t *list, void (*function)(void *, void *), void *data) node_t *element; assert (list && function && data); - + for (element = list->head; element; element = element->next) function (element->value, data); } diff --git a/converter/other/fiasco/lib/list.h b/converter/other/fiasco/lib/list.h index 68577dfd..3ba860c0 100644 --- a/converter/other/fiasco/lib/list.h +++ b/converter/other/fiasco/lib/list.h @@ -1,8 +1,8 @@ /* * list.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,16 +22,16 @@ typedef struct node { - struct node *prev; /* pointer to prev list element */ - struct node *next; /* pointer to next list element */ - void *value; /* pointer to value of node */ + struct node *prev; /* pointer to prev list element */ + struct node *next; /* pointer to next list element */ + void *value; /* pointer to value of node */ } node_t; typedef struct list { node_t *head; node_t *tail; - size_t size_of_element; /* number of bytes to store value */ + size_t size_of_element; /* number of bytes to store value */ } list_t; typedef enum {TAIL, HEAD} pos_e; @@ -41,26 +41,26 @@ typedef enum {TAIL, HEAD} pos_e; */ typedef list_t lqueue_t ; -#define alloc_queue alloc_list -#define free_queue free_list -#define queue_append(q, d) (list_insert ((q), TAIL, (d))) -#define queue_remove(q, d) (list_remove ((q), HEAD, (d))) +#define alloc_queue alloc_list +#define free_queue free_list +#define queue_append(q, d) (list_insert ((q), TAIL, (d))) +#define queue_remove(q, d) (list_remove ((q), HEAD, (d))) typedef list_t lstack_t ; -#define alloc_stack alloc_list -#define free_stack free_list -#define stack_push(q, d) (list_insert ((q), TAIL, (d))) -#define stack_pop(q, d) (list_remove ((q), TAIL, (d))) +#define alloc_stack alloc_list +#define free_stack free_list +#define stack_push(q, d) (list_insert ((q), TAIL, (d))) +#define stack_pop(q, d) (list_remove ((q), TAIL, (d))) list_t * alloc_list (size_t size_of_element); -void +void free_list (list_t *list); bool_t list_element_n (const list_t *list, pos_e pos, unsigned n, void *data); void list_foreach (const list_t *list, void (*function)(void *, void *), - void *data); + void *data); void list_insert (list_t *list, pos_e pos, const void *data); bool_t diff --git a/converter/other/fiasco/lib/macros.h b/converter/other/fiasco/lib/macros.h index 2f404a74..aafea45b 100644 --- a/converter/other/fiasco/lib/macros.h +++ b/converter/other/fiasco/lib/macros.h @@ -1,8 +1,8 @@ /* * macros.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 */ @@ -20,34 +20,34 @@ #include <string.h> /******************************************************************************* - System configuration section - + System configuration section + *******************************************************************************/ #ifndef SEEK_CUR -# define SEEK_CUR 1 +# define SEEK_CUR 1 #endif /* not SEEK_CUR */ /***************************************************************************** - Various macros - + Various macros + *****************************************************************************/ -#define square(x) ((x) * (x)) -#define first_band(color) ((unsigned) ((color) ? Y : GRAY)) +#define square(x) ((x) * (x)) +#define first_band(color) ((unsigned) ((color) ? Y : GRAY)) #define last_band(color) ((unsigned) ((color) ? Cr : GRAY)) -#define width_of_level(l) ((unsigned) (1 << ((l) >> 1))) -#define height_of_level(l) ((unsigned) (1 << (((l) + 1) >> 1))) -#define size_of_level(l) ((unsigned) (1 << (l))) -#define address_of_level(l) ((unsigned) (size_of_level (l) - 1)) -#define size_of_tree(l) ((unsigned) (address_of_level ((l) + 1))) -#define is_odd(n) (abs (n) % 2) -#define _(x) (x) +#define width_of_level(l) ((unsigned) (1 << ((l) >> 1))) +#define height_of_level(l) ((unsigned) (1 << (((l) + 1) >> 1))) +#define size_of_level(l) ((unsigned) (1 << (l))) +#define address_of_level(l) ((unsigned) (size_of_level (l) - 1)) +#define size_of_tree(l) ((unsigned) (address_of_level ((l) + 1))) +#define is_odd(n) (abs (n) % 2) +#define _(x) (x) -#define MAXSTRLEN 1024 -#define MAXSTRLEN_SCANF "%1024s" +#define MAXSTRLEN 1024 +#define MAXSTRLEN_SCANF "%1024s" typedef enum color {GRAY = 0, Y = 0, Cb = 1, Cr = 2} color_e; diff --git a/converter/other/fiasco/lib/misc.c b/converter/other/fiasco/lib/misc.c index c5629c5c..d02511de 100644 --- a/converter/other/fiasco/lib/misc.c +++ b/converter/other/fiasco/lib/misc.c @@ -1,11 +1,11 @@ /* - * misc.c: Some useful functions, that don't fit in one of - * the other files and that are needed by at least - * two modules. + * misc.c: Some useful functions, that don't fit in one of + * the other files and that are needed by at least + * two modules. + * + * Written by: Stefan Frank + * Ullrich Hafner * - * Written by: Stefan Frank - * Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -23,14 +23,14 @@ #include <ctype.h> #ifdef TIME_WITH_SYS_TIME -# include <sys/time.h> -# include <time.h> +# include <sys/time.h> +# include <time.h> #else /* not TIME_WITH_SYS_TIME */ -# if HAVE_SYS_TIME_H -# include <sys/time.h> -# else /* not HAVE_SYS_TIME_H */ -# include <time.h> -# endif /* not HAVE_SYS_TIME_H */ +# if HAVE_SYS_TIME_H +# include <sys/time.h> +# else /* not HAVE_SYS_TIME_H */ +# include <time.h> +# endif /* not HAVE_SYS_TIME_H */ #endif /* not TIME_WITH_SYS_TIME */ #include <stdlib.h> @@ -47,8 +47,8 @@ /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ static void @@ -56,8 +56,8 @@ remove_comments (FILE *file); /***************************************************************************** - public code - + public code + *****************************************************************************/ void * @@ -66,14 +66,14 @@ Calloc (size_t n, size_t size) * Allocate memory like calloc (). * * Return value: Pointer to the new block of memory on success, - * otherwise the program is terminated. + * otherwise the program is terminated. */ { - void *ptr; /* pointer to the new memory block */ + void *ptr; /* pointer to the new memory block */ if (n <= 0 || size <= 0) error ("Can't allocate memory for %d items of size %d", - (int) n, (int) size); + (int) n, (int) size); ptr = calloc (n, size); if (!ptr) @@ -100,20 +100,20 @@ unsigned prg_timer (clock_t *last_timer, enum action_e action) /* * If 'action' == START then store current value of system timer. - * If 'action' == STOP then compute number of elapsed micro seconds since - * the last time 'prg_timer' was called - * with 'action' == START. + * If 'action' == STOP then compute number of elapsed micro seconds since + * the last time 'prg_timer' was called + * with 'action' == START. * * Return value: - * Number of elapsed micro seconds if 'action' == STOP - * 0 if 'action' == START + * Number of elapsed micro seconds if 'action' == STOP + * 0 if 'action' == START * * Side effects: - * last_timer is set to current timer if action == START + * last_timer is set to current timer if action == START */ { assert (last_timer); - + if (action == START) { *last_timer = clock (); @@ -123,19 +123,19 @@ prg_timer (clock_t *last_timer, enum action_e action) return (clock () - *last_timer) / (CLOCKS_PER_SEC / 1000.0); } -real_t +real_t read_real (FILE *infile) -/* +/* * Read one real value from the given input stream 'infile'. - * + * * Return value: - * real value on success + * real value on success */ { float input; assert (infile); - + remove_comments (infile); if (fscanf(infile, "%f", &input) != 1) error("Can't read float value!"); @@ -143,26 +143,26 @@ read_real (FILE *infile) return (real_t) input; } -int +int read_int (FILE *infile) -/* +/* * Read one integer value from the given input stream 'infile'. * * Return value: - * integer value on success + * integer value on success */ { - int input; /* integer */ + int input; /* integer */ assert (infile); - + remove_comments (infile); if (fscanf(infile, "%d", &input) != 1) error("Can't read integer value!"); return input; } - + static void remove_comments (FILE *file) /* @@ -171,27 +171,27 @@ remove_comments (FILE *file) * No return value. */ { - int c; /* current character */ - + int c; /* current character */ + assert (file); - + do { while (isspace(c = getc (file))) - ; + ; if (c == EOF) - error ("EOF reached, input seems to be truncated!"); + error ("EOF reached, input seems to be truncated!"); if (c == '#') { - int dummy; - - while (((dummy = getc (file)) != '\n') && dummy != EOF) - ; - if (dummy == EOF) - error ("EOF reached, input seems to be truncated!"); + int dummy; + + while (((dummy = getc (file)) != '\n') && dummy != EOF) + ; + if (dummy == EOF) + error ("EOF reached, input seems to be truncated!"); } - else - ungetc (c, file); + else + ungetc (c, file); } while (c == '#'); } @@ -203,10 +203,10 @@ write_rice_code (unsigned value, unsigned rice_k, bitfile_t *output) * No return value. */ { - unsigned unary; /* unary part of Rice Code */ + unsigned unary; /* unary part of Rice Code */ assert (output); - + for (unary = value >> rice_k; unary; unary--) put_bit (output, 1); put_bit (output, 0); @@ -219,13 +219,13 @@ read_rice_code (unsigned rice_k, bitfile_t *input) * Read a Rice encoded integer (base 'rice_k') from the stream 'input'. * * Return value: - * decoded integer + * decoded integer */ { - unsigned unary; /* unary part of Rice code */ - + unsigned unary; /* unary part of Rice code */ + assert (input); - + for (unary = 0; get_bit (input); unary++) /* unary part */ ; @@ -243,15 +243,15 @@ write_bin_code (unsigned value, unsigned maxval, bitfile_t *output) { unsigned k; unsigned r; - + assert (output && maxval && value <= maxval); k = log2 (maxval + 1); r = (maxval + 1) % (1 << k); - if (value < maxval + 1 - 2 * r) /* 0, ... , maxval - 2r */ + if (value < maxval + 1 - 2 * r) /* 0, ... , maxval - 2r */ put_bits (output, value, k); - else /* maxval - 2r + 1, ..., maxval */ + else /* maxval - 2r + 1, ..., maxval */ put_bits (output, value + maxval + 1 - 2 * r, k + 1); } @@ -261,13 +261,13 @@ read_bin_code (unsigned maxval, bitfile_t *input) * Read a bincode encoded integer from the stream 'input'. * * Return value: - * decoded integer + * decoded integer */ { unsigned k; unsigned r; unsigned value; - + assert (input); k = log2 (maxval + 1); @@ -280,7 +280,7 @@ read_bin_code (unsigned maxval, bitfile_t *input) { value <<= 1; if (get_bit (input)) - value++; + value++; return value - maxval - 1 + 2 * r; } } @@ -292,12 +292,12 @@ bits_rice_code (unsigned value, unsigned rice_k) * with given Rice code 'rice_k'. * * Return value: - * number of bits + * number of bits */ { unsigned unary; unsigned bits = 0; - + for (unary = value >> rice_k; unary; unary--) bits++; bits += rice_k + 1; @@ -312,7 +312,7 @@ bits_bin_code (unsigned value, unsigned maxval) * with adjusted binary code of given maximum value 'maxval'. * * Return value: - * number of bits + * number of bits */ { unsigned k; @@ -332,30 +332,30 @@ init_clipping (void) * Initialize the clipping tables * * Return value: - * pointer to clipping table + * pointer to clipping table */ { - static unsigned *gray_clip = NULL; /* clipping array */ + static unsigned *gray_clip = NULL; /* clipping array */ - if (gray_clip == NULL) /* initialize clipping table */ + if (gray_clip == NULL) /* initialize clipping table */ { - int i; /* counter */ + int i; /* counter */ gray_clip = calloc (256 * 3, sizeof (unsigned)); if (!gray_clip) { - set_error (_("Out of memory.")); - return NULL; + set_error (_("Out of memory.")); + return NULL; } gray_clip += 256; for (i = -256; i < 512; i++) - if (i < 0) - gray_clip [i] = 0; - else if (i > 255) - gray_clip [i] = 255; - else - gray_clip [i] = i; + if (i < 0) + gray_clip [i] = 0; + else if (i > 255) + gray_clip [i] = 255; + else + gray_clip [i] = i; } return gray_clip; @@ -369,29 +369,29 @@ memmove (void *v_dst, const void *v_src, size_t n) * The memory areas may overlap. * * Return value: - * pointer 'dest' + * pointer 'dest' */ { - byte_t *to, *dst = (byte_t *) v_dst; - const byte_t *from, *src = (byte_t *) v_src; - + byte_t *to, *dst = (byte_t *) v_dst; + const byte_t *from, *src = (byte_t *) v_src; + assert (v_dst && v_src); - + if (dst <= src) { from = src; to = dst; for (; n; n--) - *to++ = *from++; + *to++ = *from++; } else - { + { from = src + (n - 1); to = dst + (n - 1); for (; n; n--) - *to-- = *from--; + *to-- = *from--; } - + return v_dst; } #endif /* not HAVE_MEMMOVE */ @@ -405,7 +405,7 @@ double Log2 (double x) /* * Return value: - * base-2 logarithm of 'x' + * base-2 logarithm of 'x' */ { return log (x) / 0.69314718; @@ -413,32 +413,32 @@ Log2 (double x) real_t variance (const word_t *pixels, unsigned x0, unsigned y0, - unsigned width, unsigned height, unsigned cols) + unsigned width, unsigned height, unsigned cols) /* - * Compute variance of subimage ('x0', y0', 'width', 'height') of + * Compute variance of subimage ('x0', y0', 'width', 'height') of * the image data given by 'pixels' ('cols' is the number of pixels * in one row of the image). * * Return value: - * variance + * variance */ { - real_t average; /* average of pixel values */ - real_t variance; /* variance of pixel values */ - unsigned x, y; /* pixel counter */ - unsigned n; /* number of pixels */ + real_t average; /* average of pixel values */ + real_t variance; /* variance of pixel values */ + unsigned x, y; /* pixel counter */ + unsigned n; /* number of pixels */ assert (pixels); - + for (average = 0, n = 0, y = y0; y < y0 + height; y++) for (x = x0; x < MIN(x0 + width, cols); x++, n++) - average += pixels [y * cols + x] / 16; + average += pixels [y * cols + x] / 16; average /= n; for (variance = 0, y = y0; y < y0 + height; y++) for (x = x0; x < MIN(x0 + width, cols); x++) - variance += square ((pixels [y * cols + x] / 16) - average); + variance += square ((pixels [y * cols + x] / 16) - average); return variance; } @@ -482,7 +482,7 @@ sort_asc_pair (const void *value1, const void *value2) { word_t v1 = ((pair_t *) value1)->key; word_t v2 = ((pair_t *) value2)->key; - + if (v1 < v2) return -1; else if (v1 > v2) diff --git a/converter/other/fiasco/lib/misc.h b/converter/other/fiasco/lib/misc.h index 6f643b7a..48f8bdaa 100644 --- a/converter/other/fiasco/lib/misc.h +++ b/converter/other/fiasco/lib/misc.h @@ -1,9 +1,9 @@ /* * misc.h * - * Written by: Stefan Frank - * Ullrich Hafner - * + * Written by: Stefan Frank + * Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -21,14 +21,14 @@ #include "config.h" #if TIME_WITH_SYS_TIME -# include <sys/time.h> -# include <time.h> +# include <sys/time.h> +# include <time.h> #else /* not TIME_WITH_SYS_TIME */ -# if HAVE_SYS_TIME_H -# include <sys/time.h> -# else /* not HAVE_SYS_TIME_H */ -# include <time.h> -# endif /* not HAVE_SYS_TIME_H */ +# if HAVE_SYS_TIME_H +# include <sys/time.h> +# else /* not HAVE_SYS_TIME_H */ +# include <time.h> +# endif /* not HAVE_SYS_TIME_H */ #endif /* not TIME_WITH_SYS_TIME */ #include <stdio.h> @@ -43,9 +43,9 @@ void Free (void *memory); unsigned prg_timer (clock_t *ptimer, enum action_e action); -int +int read_int(FILE *infile); -real_t +real_t read_real(FILE *infile); unsigned read_rice_code (unsigned rice_k, bitfile_t *input); @@ -63,7 +63,7 @@ unsigned * init_clipping (void); real_t variance (const word_t *pixels, unsigned x0, unsigned y0, - unsigned width, unsigned height, unsigned cols); + unsigned width, unsigned height, unsigned cols); #ifndef HAVE_MEMMOVE void * diff --git a/converter/other/fiasco/lib/mvcode.c b/converter/other/fiasco/lib/mvcode.c index d9ce91e2..0e6b6626 100644 --- a/converter/other/fiasco/lib/mvcode.c +++ b/converter/other/fiasco/lib/mvcode.c @@ -8,7 +8,7 @@ unsigned mv_code_table [33][2] = {0x19, 11}, {0x1b, 11}, {0x1d, 11}, {0x1f, 11}, {0x21, 11}, {0x23, 11}, {0x13, 10}, {0x15, 10}, {0x17, 10}, {0x7, 8}, {0x9, 8}, {0xb, 8}, {0x7, 7}, {0x3, 5}, {0x3, 4}, {0x3, 3}, {0x1, 1}, {0x2, 3}, {0x2, 4}, {0x2, 5}, - {0x6, 7}, {0xa, 8}, {0x8, 8}, {0x6, 8}, {0x16, 10}, {0x14, 10}, {0x12, 10}, + {0x6, 7}, {0xa, 8}, {0x8, 8}, {0x6, 8}, {0x16, 10}, {0x14, 10}, {0x12, 10}, {0x22, 11}, {0x20, 11}, {0x1e, 11}, {0x1c, 11}, {0x1a, 11}, {0x18, 11} }; diff --git a/converter/other/fiasco/lib/rpf.c b/converter/other/fiasco/lib/rpf.c index e6ff6e09..61e2f953 100644 --- a/converter/other/fiasco/lib/rpf.c +++ b/converter/other/fiasco/lib/rpf.c @@ -4,7 +4,7 @@ * Written by: Stefan Frank * Richard Krampfl * Ullrich Hafner - * + * * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> */ @@ -32,7 +32,7 @@ int const RPF_ZERO = -1; /***************************************************************************** private code - + *****************************************************************************/ @@ -62,25 +62,25 @@ rtob (real_t const f, * Convert real number 'f' into fixed point format. * The real number in [-'range'; +'range'] is scaled to [-1 ; +1]. * Sign and the first 'precision' - 1 bits of the mantissa are - * packed into one integer. + * packed into one integer. * * Return value: * real value in reduced precision format */ -{ +{ /* * Extract mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) */ double const normalized = f / rpfP->range; - /* 'f' scaled to [-1,+1] */ + /* 'f' scaled to [-1,+1] */ FracExp const fracExp = fracExpFromDouble(normalized); unsigned int const signedMantissa = (unsigned int) (fracExp.fraction * (1<<23)); unsigned int mantissa; unsigned int sign; /* 0 for positive; 1 for negative */ - + if (signedMantissa < 0) { mantissa = -signedMantissa; sign = 1; @@ -92,16 +92,16 @@ rtob (real_t const f, /* * Generate reduced precision mantissa. */ - if (fracExp.exponent > 0) + if (fracExp.exponent > 0) mantissa <<= fracExp.exponent; else - mantissa >>= -fracExp.exponent; - + mantissa >>= -fracExp.exponent; + mantissa >>= (23 - rpfP->mantissa_bits - 1); mantissa += 1; /* Round last bit. */ mantissa >>= 1; - + if (mantissa == 0) /* close to zero */ return RPF_ZERO; else if (mantissa >= (1U << rpfP->mantissa_bits)) /* overflow */ @@ -126,7 +126,7 @@ btor (int const binary, unsigned int mantissa; float sign; float f; - + if (binary == RPF_ZERO) return 0; @@ -137,16 +137,16 @@ btor (int const binary, * Restore IEEE float format: * mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) */ - + sign = (binary & 0x1) == 0 ? 1.0 : -1.0; - mantissa = (binary & ((0x1 << (rpfP->mantissa_bits + 1)) - 1)) >> 1; + mantissa = (binary & ((0x1 << (rpfP->mantissa_bits + 1)) - 1)) >> 1; mantissa <<= (23 - rpfP->mantissa_bits); - if (mantissa == 0) + if (mantissa == 0) f = sign; else f = sign * (float) mantissa / 8388608; - + return f * rpfP->range; /* expand [ -1 ; +1 ] to [ -range ; +range ] */ } @@ -163,7 +163,7 @@ alloc_rpf (unsigned const mantissa, * Number of mantissa bits is given by `mantissa'. * The range of the real values is in the interval [-`range', +`range']. * In case of invalid parameters, a structure with default values is - * returned. + * returned. * * Return value * pointer to the new rpf structure @@ -172,7 +172,7 @@ alloc_rpf (unsigned const mantissa, rpf_t * rpfP; MALLOCVAR(rpfP); - + if (mantissa < 2) { warning (_("Size of RPF mantissa has to be in the interval [2,8]. " "Using minimum value 2.\n")); diff --git a/converter/other/fiasco/lib/rpf.h b/converter/other/fiasco/lib/rpf.h index e543f855..19e330fb 100644 --- a/converter/other/fiasco/lib/rpf.h +++ b/converter/other/fiasco/lib/rpf.h @@ -1,10 +1,10 @@ /* * rpf.h * - * Written by: Stefan Frank - * Richard Krampfl - * Ullrich Hafner - * + * Written by: Stefan Frank + * Richard Krampfl + * Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -24,14 +24,14 @@ typedef struct rpf { - unsigned mantissa_bits; /* number of bits used for mantissa */ - real_t range; /* scale value to [-range, +range] */ + unsigned mantissa_bits; /* number of bits used for mantissa */ + real_t range; /* scale value to [-range, +range] */ fiasco_rpf_range_e range_e; } rpf_t; int rtob (real_t real, const rpf_t *rpf); -real_t +real_t btor (int b, const rpf_t *rpf); rpf_t * alloc_rpf (unsigned mantissa, fiasco_rpf_range_e range); diff --git a/converter/other/fiasco/lib/types.h b/converter/other/fiasco/lib/types.h index 02e40a90..ce216ce5 100644 --- a/converter/other/fiasco/lib/types.h +++ b/converter/other/fiasco/lib/types.h @@ -2,7 +2,7 @@ * types.h * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ |