From e90b1605a083938d582dd459f8a14141274e7492 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 24 Sep 2023 16:51:04 +0000 Subject: whitespace git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4685 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/fiasco/codec/approx.c | 140 ++--- converter/other/fiasco/codec/approx.h | 10 +- converter/other/fiasco/codec/bintree.c | 26 +- converter/other/fiasco/codec/bintree.h | 8 +- converter/other/fiasco/codec/coder.h | 4 +- converter/other/fiasco/codec/coeff.c | 194 +++---- converter/other/fiasco/codec/coeff.h | 20 +- converter/other/fiasco/codec/control.c | 204 +++---- converter/other/fiasco/codec/control.h | 14 +- converter/other/fiasco/codec/cwfa.h | 102 ++-- converter/other/fiasco/codec/decoder.h | 52 +- converter/other/fiasco/codec/dfiasco.c | 178 +++--- converter/other/fiasco/codec/dfiasco.h | 8 +- converter/other/fiasco/codec/domain-pool.c | 148 ++--- converter/other/fiasco/codec/domain-pool.h | 28 +- converter/other/fiasco/codec/ip.c | 266 ++++----- converter/other/fiasco/codec/ip.h | 22 +- converter/other/fiasco/codec/motion.c | 428 +++++++------- converter/other/fiasco/codec/motion.h | 14 +- converter/other/fiasco/codec/mwfa.c | 888 ++++++++++++++--------------- converter/other/fiasco/codec/mwfa.h | 14 +- converter/other/fiasco/codec/options.c | 414 +++++++------- converter/other/fiasco/codec/options.h | 80 +-- converter/other/fiasco/codec/prediction.c | 406 ++++++------- converter/other/fiasco/codec/prediction.h | 14 +- converter/other/fiasco/codec/subdivide.c | 426 +++++++------- converter/other/fiasco/codec/subdivide.h | 12 +- converter/other/fiasco/codec/tiling.c | 166 +++--- converter/other/fiasco/codec/tiling.h | 14 +- converter/other/fiasco/codec/wfa.h | 144 ++--- converter/other/fiasco/codec/wfalib.c | 462 +++++++-------- converter/other/fiasco/codec/wfalib.h | 18 +- 32 files changed, 2462 insertions(+), 2462 deletions(-) (limited to 'converter/other/fiasco/codec') diff --git a/converter/other/fiasco/codec/approx.c b/converter/other/fiasco/codec/approx.c index d8fefcaa..a3f6523d 100644 --- a/converter/other/fiasco/codec/approx.c +++ b/converter/other/fiasco/codec/approx.c @@ -2,7 +2,7 @@ * approx.c: Approximation of range images with matching pursuit * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -35,7 +35,7 @@ /***************************************************************************** local variables - + *****************************************************************************/ typedef struct mp @@ -53,13 +53,13 @@ typedef struct mp /***************************************************************************** prototypes - + *****************************************************************************/ static void orthogonalize (unsigned index, unsigned n, unsigned level, real_t min_norm, const word_t *domain_blocks, const coding_t *c); -static void +static void matching_pursuit (mp_t *mp, bool_t full_search, real_t price, unsigned max_edges, int y_state, const range_t *range, const domain_pool_t *domain_pool, const coeff_t *coeff, @@ -68,14 +68,14 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, /***************************************************************************** public code - + *****************************************************************************/ -real_t +real_t approximate_range (real_t max_costs, real_t price, int max_edges, int y_state, range_t *range, domain_pool_t *domain_pool, coeff_t *coeff, const wfa_t *wfa, const coding_t *c) { -/*---------------------------------------------------------------------------- +/*---------------------------------------------------------------------------- Approximate image block 'range' by matching pursuit. This functions calls the matching pursuit algorithm several times (with different parameters) in order to find the best approximation. Refer to function @@ -99,15 +99,15 @@ approximate_range (real_t max_costs, real_t price, int max_edges, */ if (c->options.second_domain_block) { mp_t tmp_mp; - + tmp_mp = mp; /* initial value */ tmp_mp.exclude[0] = tmp_mp.indices [0]; tmp_mp.exclude[1] = NO_EDGE; - + matching_pursuit(&tmp_mp, c->options.full_search, price, max_edges, y_state, range, domain_pool, coeff, wfa, c); - if (tmp_mp.costs < mp.costs) /* success */ + if (tmp_mp.costs < mp.costs) /* success */ mp = tmp_mp; } @@ -123,23 +123,23 @@ approximate_range (real_t max_costs, real_t price, int max_edges, tmp_mp = mp; /* initial value */ iteration = -1; /* initial value */ - + do { int i; - + ++iteration; tmp_mp.exclude[iteration] = NO_EDGE; - + for (i = 0; isdomain(tmp_mp.indices[i]); ++i) { if (tmp_mp.weight [i] == 0) { tmp_mp.exclude[iteration] = tmp_mp.indices [i]; break; } - } + } if (isdomain (tmp_mp.exclude [iteration])) { /* try again */ tmp_mp.exclude [iteration + 1] = NO_EDGE; - + matching_pursuit(&tmp_mp, c->options.full_search, price, max_edges, y_state, range, domain_pool, coeff, wfa, c); @@ -165,25 +165,25 @@ approximate_range (real_t max_costs, real_t price, int max_edges, do { int i; - + ++iteration; tmp_mp.exclude[iteration] = NO_EDGE; - + for (i = 0; isdomain (tmp_mp.indices [i]); ++i) { rpf_t * const rpf = tmp_mp.indices [i] ? coeff->rpf : coeff->dc_rpf; - + if (tmp_mp.weight [i] == btor (rtob (200, rpf), rpf) || tmp_mp.weight [i] == btor (rtob (-200, rpf), rpf)) { tmp_mp.exclude [iteration] = tmp_mp.indices [i]; break; } } - + if (isdomain(tmp_mp.exclude[iteration])) { /* try again */ tmp_mp.exclude[iteration + 1] = NO_EDGE; - + matching_pursuit(&tmp_mp, c->options.full_search, price, max_edges, y_state, range, domain_pool, coeff, wfa, c); @@ -226,10 +226,10 @@ approximate_range (real_t max_costs, real_t price, int max_edges, range->level, y_state, wfa, domain_pool->model); coeff->update (mp.weight, mp.into, range->level, coeff); - + Free(domain_blocks); } - + for (edge = 0; isedge (mp.indices [edge]); ++edge) { range->into [edge] = mp.into [edge]; range->weight [edge] = mp.weight [edge]; @@ -242,7 +242,7 @@ approximate_range (real_t max_costs, real_t price, int max_edges, range->into [0] = NO_EDGE; mp.costs = MAXCOSTS; } - + return mp.costs; } @@ -251,25 +251,25 @@ approximate_range (real_t max_costs, real_t price, int max_edges, /***************************************************************************** local variables - + *****************************************************************************/ -static real_t norm_ortho_vector [MAXSTATES]; +static real_t norm_ortho_vector [MAXSTATES]; /* * Square-norm of the i-th vector of the orthogonal basis (OB) * ||o_i||^2; i = 0, ... ,n */ static real_t ip_image_ortho_vector [MAXEDGES]; -/* - * Inner product between the i-th vector of the OB and the given range: - * ; i = 0, ... ,n +/* + * Inner product between the i-th vector of the OB and the given range: + * ; i = 0, ... ,n */ static real_t ip_domain_ortho_vector [MAXSTATES][MAXEDGES]; -/* - * Inner product between the i-th vector of the OB and the image of domain j: - * ; j = 0, ... , wfa->states; i = 0, ... ,n, +/* + * Inner product between the i-th vector of the OB and the image of domain j: + * ; j = 0, ... , wfa->states; i = 0, ... ,n, */ -static real_t rem_denominator [MAXSTATES]; +static real_t rem_denominator [MAXSTATES]; static real_t rem_numerator [MAXSTATES]; /* * At step n of the orthogonalization the comparative value @@ -280,7 +280,7 @@ static real_t rem_numerator [MAXSTATES]; * the constant (remaining) parts of every domain are * stored in 'rem_numerator' and 'rem_denominator' separately */ -static bool_t used [MAXSTATES]; +static bool_t used [MAXSTATES]; /* * Shows whether a domain image was already used in a * linear combination (YES) or not (NO) @@ -289,10 +289,10 @@ static bool_t used [MAXSTATES]; /***************************************************************************** private code - + *****************************************************************************/ -static void +static void matching_pursuit (mp_t *mp, bool_t full_search, real_t price, unsigned max_edges, int y_state, const range_t *range, const domain_pool_t *domain_pool, const coeff_t *coeff, @@ -313,7 +313,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, * elements in the linear combination is limited by 'max_edges'. In * 'mp', vectors may be specified which should be excluded during the * approximation. - * + * * No return value. * * Side effects: @@ -329,7 +329,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, const real_t min_norm = 2e-3; /* lower bound of norm */ unsigned best_n = 0; unsigned size = size_of_level (range->level); - + /* * Initialize domain pool and inner product arrays */ @@ -378,7 +378,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, + additional_bits) * price + mp->err; n = 0; - do + do { /* * Current approximation is: b = d_0 o_0 + ... + d_(n-1) o_(n-1) @@ -390,15 +390,15 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, * which has minimal costs: s_index. * (No progress is indicated by index == -1) */ - + real_t min_matrix_bits = 0; real_t min_weights_bits = 0; real_t min_error = 0; real_t min_weight [MAXEDGES]; real_t min_costs = full_search ? MAXCOSTS : mp->costs; - - for (index = -1, domain = 0; domain_blocks [domain] >= 0; domain++) - if (!used [domain]) + + for (index = -1, domain = 0; domain_blocks [domain] >= 0; domain++) + if (!used [domain]) { real_t matrix_bits, weights_bits; /* @@ -413,7 +413,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, word_t states [MAXEDGES + 1]; real_t weights [MAXEDGES + 1]; unsigned i, k; - + for (i = 0, k = 0; k < n; k++) if (mp->weight [k] != 0) { @@ -477,7 +477,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, f[k] = ip_image_ortho_vector[k] / norm_ortho_vector[k]; v [k] = mp->indices [k]; } - + for (l = n; l >= 0; --l) { rpf_t * const rpf = domain_blocks[v[l]] ? coeff->rpf : coeff->dc_rpf; @@ -488,13 +488,13 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, { real_t const fl = f[l]; - + for (k = 0; k < l; ++k) { f[k] -= fl * ip_domain_ortho_vector[v[l]][k] / norm_ortho_vector[k]; } } - } + } /* * Compute the number of output bits of the linear @@ -507,7 +507,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, word_t states [MAXEDGES + 1]; real_t weights [MAXEDGES + 1]; int i; - + for (i = 0, k = 0; k <= n; k++) if (f [k] != 0) { @@ -525,10 +525,10 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, range->level, y_state, wfa, domain_pool->model); } - + /* * To compute the approximation error, the corresponding - * linear factors of the linear combination + * linear factors of the linear combination * b = r_0 o_0 + ... + r_(n-1) o_(n-1) + r_n o_'domain' * with orthogonal vectors must be computed with following * formula: @@ -546,7 +546,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, a = get_ip_state_state (domain_blocks [v [l]], domain_blocks [domain], range->level, c); - for (k = 0; k < n; k++) + for (k = 0; k < n; k++) a -= ip_domain_ortho_vector [v [l]][k] / norm_ortho_vector [k] * ip_domain_ortho_vector [domain][k]; @@ -554,7 +554,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, } norm_ortho_vector [n] = rem_denominator [domain]; ip_image_ortho_vector [n] = rem_numerator [domain]; - + for (k = 0; k <= n; k++) for (l = k + 1; (unsigned) l <= n; l++) r [k] += ip_domain_ortho_vector [v [l]][k] * r [l] @@ -586,40 +586,40 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, } } } - + if (index >= 0) /* found a better approximation */ { if (min_costs < mp->costs) { unsigned k; - + mp->costs = min_costs; mp->err = min_error; mp->matrix_bits = min_matrix_bits; mp->weights_bits = min_weights_bits; - + for (k = 0; k <= n; k++) mp->weight [k] = min_weight [k]; best_n = n + 1; } - + mp->indices [n] = index; mp->into [n] = domain_blocks [index]; used [index] = YES; - /* - * Gram-Schmidt orthogonalization step n + /* + * Gram-Schmidt orthogonalization step n */ orthogonalize (index, n, range->level, min_norm, domain_blocks, c); n++; - } - } + } + } while (n < max_edges && index >= 0); mp->indices [best_n] = NO_EDGE; - + mp->costs = (mp->matrix_bits + mp->weights_bits + additional_bits) * price + mp->err; @@ -641,31 +641,31 @@ orthogonalize (unsigned index, unsigned n, unsigned level, real_t min_norm, * * Side effects: * The remainder values (numerator and denominator) of - * all 'domain_blocks' are updated. + * all 'domain_blocks' are updated. */ { unsigned domain; - + ip_image_ortho_vector [n] = rem_numerator [index]; norm_ortho_vector [n] = rem_denominator [index]; /* - * Compute inner products between all domain images and + * Compute inner products between all domain images and * vector n of the orthogonal basis: - * for (i = 0, ... , wfa->states) + * for (i = 0, ... , wfa->states) * := - * \sum (k = 0, ... , n - 1){ / ||o_k||^2} * Moreover the denominator and numerator parts of the comparative * value are updated. */ - for (domain = 0; domain_blocks [domain] >= 0; domain++) - if (!used [domain]) + for (domain = 0; domain_blocks [domain] >= 0; domain++) + if (!used [domain]) { unsigned k; real_t tmp = get_ip_state_state (domain_blocks [index], domain_blocks [domain], level, c); - - for (k = 0; k < n; k++) + + for (k = 0; k < n; k++) tmp -= ip_domain_ortho_vector [domain][k] / norm_ortho_vector [k] * ip_domain_ortho_vector [index][k]; ip_domain_ortho_vector [domain][n] = tmp; @@ -677,8 +677,8 @@ orthogonalize (unsigned index, unsigned n, unsigned level, real_t min_norm, /* * Exclude vectors with small denominator */ - if (!used [domain]) - if (rem_denominator [domain] / size_of_level (level) < min_norm) + if (!used [domain]) + if (rem_denominator [domain] / size_of_level (level) < min_norm) used [domain] = YES; } } diff --git a/converter/other/fiasco/codec/approx.h b/converter/other/fiasco/codec/approx.h index 42f1458a..cce27eb6 100644 --- a/converter/other/fiasco/codec/approx.h +++ b/converter/other/fiasco/codec/approx.h @@ -1,8 +1,8 @@ /* * approx.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 */ @@ -21,10 +21,10 @@ #include "cwfa.h" #include "domain-pool.h" -real_t +real_t approximate_range (real_t max_costs, real_t price, int max_edges, - int y_state, range_t *range, domain_pool_t *domain_pool, - coeff_t *coeff, const wfa_t *wfa, const coding_t *c); + int y_state, range_t *range, domain_pool_t *domain_pool, + coeff_t *coeff, const wfa_t *wfa, const coding_t *c); #endif /* not _APPROX_H */ diff --git a/converter/other/fiasco/codec/bintree.c b/converter/other/fiasco/codec/bintree.c index b050ab63..ca828fb2 100644 --- a/converter/other/fiasco/codec/bintree.c +++ b/converter/other/fiasco/codec/bintree.c @@ -1,8 +1,8 @@ /* - * bintree.c: Bintree model of WFA tree + * bintree.c: Bintree model of WFA tree + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -28,8 +28,8 @@ /***************************************************************************** - public code - + public code + *****************************************************************************/ void @@ -40,7 +40,7 @@ tree_update (bool_t child, unsigned level, tree_t *model) * No return value. * * Side effects: - * tree model is changed. + * tree model is changed. */ { if (!child) @@ -59,7 +59,7 @@ tree_bits (bool_t child, unsigned level, const tree_t *model) * For each 'level' a different context is used. * * Return value: - * # bits + * # bits */ { real_t prob = model->counts [level] / (real_t) model->total [level]; @@ -80,13 +80,13 @@ init_tree_model (tree_t *tree_model) { unsigned level; unsigned counts_0 [MAXLEVEL] = {20, 17, 15, 10, 5, 4, 3, - 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1 , 1, 1, 1}; + 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1 , 1, 1, 1}; unsigned counts_1 [MAXLEVEL] = {1 , 1, 1, 1, 1, 1, 1, - 1, 1, 2, 3, 5, 10, 15, 20, - 25, 30, 35, 60, 60, 60, 60}; - - for (level = 0; level < MAXLEVEL ; level++) + 1, 1, 2, 3, 5, 10, 15, 20, + 25, 30, 35, 60, 60, 60, 60}; + + for (level = 0; level < MAXLEVEL ; level++) { tree_model->counts [level] = counts_1 [level]; tree_model->total [level] = counts_0 [level] + counts_1 [level]; diff --git a/converter/other/fiasco/codec/bintree.h b/converter/other/fiasco/codec/bintree.h index 3dc88ac1..c68b2e7b 100644 --- a/converter/other/fiasco/codec/bintree.h +++ b/converter/other/fiasco/codec/bintree.h @@ -1,8 +1,8 @@ /* * bintree.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 */ @@ -28,8 +28,8 @@ typedef struct tree * which indicate whether there exists a tree edge or not. */ { - unsigned counts [MAXLEVEL]; /* # NO_RANGE symbols at given level */ - unsigned total [MAXLEVEL]; /* total number of symbols at '' */ + unsigned counts [MAXLEVEL]; /* # NO_RANGE symbols at given level */ + unsigned total [MAXLEVEL]; /* total number of symbols at '' */ } tree_t; real_t diff --git a/converter/other/fiasco/codec/coder.h b/converter/other/fiasco/codec/coder.h index 2fe81d81..4e8e400d 100644 --- a/converter/other/fiasco/codec/coder.h +++ b/converter/other/fiasco/codec/coder.h @@ -1,8 +1,8 @@ /* * coder.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/codec/coeff.c b/converter/other/fiasco/codec/coeff.c index 6d33bad5..3a5a6a0a 100644 --- a/converter/other/fiasco/codec/coeff.c +++ b/converter/other/fiasco/codec/coeff.c @@ -1,8 +1,8 @@ /* - * coeff.c: Matching pursuit coefficients probability model + * coeff.c: Matching pursuit coefficients probability model + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -28,9 +28,9 @@ /* * Coefficient model interface: * Implementing the coefficients model interface requires the - * following steps: + * following steps: * - Add a constructor that initializes the coeff_t structure - * - Allocate new model with default_alloc() + * - Allocate new model with default_alloc() * - Fill the c_array_t coeff_models[] array with constructor and name * - Write code for methods bits() and update() * - Either use default functions for remaining methods or override them @@ -38,21 +38,21 @@ */ /***************************************************************************** - uniform distribution coefficients model + uniform distribution coefficients model *****************************************************************************/ static coeff_t * alloc_uniform_coeff_model (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level); + unsigned min_level, unsigned max_level); static void uniform_update (const real_t *used_coeff, const word_t *used_states, - unsigned level, coeff_t *coeff); + unsigned level, coeff_t *coeff); static real_t uniform_bits (const real_t *used_coeff, const word_t *used_states, - unsigned level, const coeff_t *coeff); + unsigned level, const coeff_t *coeff); /***************************************************************************** - default functions + default functions *****************************************************************************/ static void @@ -63,15 +63,15 @@ static void default_free (coeff_t *coeff); static coeff_t * default_alloc (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level); + unsigned min_level, unsigned max_level); /***************************************************************************** - adaptive arithmetic coding model + adaptive arithmetic coding model *****************************************************************************/ static coeff_t * alloc_aac_coeff_model (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level); + unsigned min_level, unsigned max_level); static void aac_model_free (void *model); static void * @@ -80,70 +80,70 @@ static void * aac_model_duplicate (const coeff_t *coeff, const void *model); static void aac_update (const real_t *used_coeff, const word_t *used_states, - unsigned level, coeff_t *coeff); + unsigned level, coeff_t *coeff); static real_t aac_bits (const real_t *used_coeff, const word_t *used_states, - unsigned level, const coeff_t *coeff); + unsigned level, const coeff_t *coeff); /***************************************************************************** - public code - + public code + *****************************************************************************/ typedef struct c_array { const char *identifier; coeff_t *(*function) (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level); + unsigned min_level, unsigned max_level); } c_array_t; c_array_t coeff_models[] = {{"adaptive", alloc_aac_coeff_model}, - {"uniform", alloc_uniform_coeff_model}, - {NULL, NULL}}; + {"uniform", alloc_uniform_coeff_model}, + {NULL, NULL}}; coeff_t * alloc_coeff_model (const char *coeff_model_name, rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level) + unsigned min_level, unsigned max_level) /* * Allocate a new coefficients model which is identified by the string * 'coeff_model_name'. 'rpf' and 'dc_rpf' define the reduced * precision formats the should be used to quantize normal and DC * components, respectively. 'min_level' and 'max_level' define the * range of range approximations. - * + * * Return value: - * pointer to the allocated coefficients model + * pointer to the allocated coefficients model * * Note: * Refer to 'coeff.h' for a short description of the member functions. */ { unsigned n; - + for (n = 0; coeff_models [n].identifier; n++) /* step through all id's */ - if (strcaseeq (coeff_models [n].identifier, coeff_model_name)) - return coeff_models [n].function (rpf, dc_rpf, min_level, max_level); + if (strcaseeq (coeff_models [n].identifier, coeff_model_name)) + return coeff_models [n].function (rpf, dc_rpf, min_level, max_level); warning ("Can't initialize coefficients model '%s'. " - "Using default value '%s'.", - coeff_model_name, coeff_models [0].identifier); + "Using default value '%s'.", + coeff_model_name, coeff_models [0].identifier); return coeff_models [0].function (rpf, dc_rpf, min_level, max_level); } /***************************************************************************** - private code - + private code + *****************************************************************************/ /***************************************************************************** - uniform distribution coefficients model + uniform distribution coefficients model *****************************************************************************/ static coeff_t * alloc_uniform_coeff_model (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level) + unsigned min_level, unsigned max_level) /* * Underlying probability model: uniform distribution. * I.e. each coefficient is written as such with @@ -154,21 +154,21 @@ alloc_uniform_coeff_model (rpf_t *rpf, rpf_t *dc_rpf, coeff->bits = uniform_bits; coeff->update = uniform_update; - + return coeff; } static real_t uniform_bits (const real_t *used_coeff, const word_t *used_states, - unsigned level, const coeff_t *coeff) + unsigned level, const coeff_t *coeff) { unsigned edge; - real_t bits = 0; /* #bits to store coefficients */ - + real_t bits = 0; /* #bits to store coefficients */ + for (edge = 0; isedge (used_states [edge]); edge++) { rpf_t *rpf = used_states [edge] ? coeff->rpf : coeff->dc_rpf; - + bits += rpf->mantissa_bits + 1; } @@ -177,13 +177,13 @@ uniform_bits (const real_t *used_coeff, const word_t *used_states, static void uniform_update (const real_t *used_coeff, const word_t *used_states, - unsigned level, coeff_t *coeff) + unsigned level, coeff_t *coeff) { - return; /* nothing to do */ + return; /* nothing to do */ } /***************************************************************************** - adaptive arithmetic coding model + adaptive arithmetic coding model *****************************************************************************/ typedef struct aac_model @@ -194,74 +194,74 @@ typedef struct aac_model static coeff_t * alloc_aac_coeff_model (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level) + unsigned min_level, unsigned max_level) /* * Underlying probability model: adaptive arithmetic coding using * the level of a range as context. */ { coeff_t *coeff = default_alloc (rpf, dc_rpf, min_level, max_level); - + coeff->bits = aac_bits; coeff->update = aac_update; coeff->model_free = aac_model_free; coeff->model_duplicate = aac_model_duplicate; - coeff->model = aac_model_alloc (coeff); - + coeff->model = aac_model_alloc (coeff); + return coeff; } static real_t aac_bits (const real_t *used_coeff, const word_t *used_states, - unsigned level, const coeff_t *coeff) + unsigned level, const coeff_t *coeff) { - real_t bits = 0; /* # bits to store coefficients */ - unsigned edge; - int state; + real_t bits = 0; /* # bits to store coefficients */ + unsigned edge; + int state; word_t *counts; aac_model_t *model = (aac_model_t *) coeff->model; counts = model->counts - + (1 << (1 + coeff->dc_rpf->mantissa_bits)) - + ((level - coeff->min_level) - * (1 << (1 + coeff->rpf->mantissa_bits))); - + + (1 << (1 + coeff->dc_rpf->mantissa_bits)) + + ((level - coeff->min_level) + * (1 << (1 + coeff->rpf->mantissa_bits))); + for (edge = 0; isedge (state = used_states [edge]); edge++) if (state) - bits -= log2 (counts [rtob (used_coeff [edge], coeff->rpf)] - / (real_t) model->totals [level - - coeff->min_level + 1]); + bits -= log2 (counts [rtob (used_coeff [edge], coeff->rpf)] + / (real_t) model->totals [level + - coeff->min_level + 1]); else - bits -= log2 (model->counts [rtob (used_coeff [edge], coeff->dc_rpf)] - / (real_t) model->totals [0]); - + bits -= log2 (model->counts [rtob (used_coeff [edge], coeff->dc_rpf)] + / (real_t) model->totals [0]); + return bits; } static void aac_update (const real_t *used_coeff, const word_t *used_states, - unsigned level, coeff_t *coeff) + unsigned level, coeff_t *coeff) { - unsigned edge; - int state; + unsigned edge; + int state; word_t *counts; aac_model_t *model = (aac_model_t *) coeff->model; counts = model->counts - + (1 << (1 + coeff->dc_rpf->mantissa_bits)) - + ((level - coeff->min_level) - * (1 << (1 + coeff->rpf->mantissa_bits))); + + (1 << (1 + coeff->dc_rpf->mantissa_bits)) + + ((level - coeff->min_level) + * (1 << (1 + coeff->rpf->mantissa_bits))); for (edge = 0; isedge (state = used_states [edge]); edge++) if (state) { - counts [rtob (used_coeff [edge], coeff->rpf)]++; - model->totals [level - coeff->min_level + 1]++; + counts [rtob (used_coeff [edge], coeff->rpf)]++; + model->totals [level - coeff->min_level + 1]++; } else { - model->counts [rtob (used_coeff [edge], coeff->dc_rpf)]++; - model->totals [0]++; + model->counts [rtob (used_coeff [edge], coeff->dc_rpf)]++; + model->totals [0]++; } } @@ -272,12 +272,12 @@ aac_model_duplicate (const coeff_t *coeff, const void *model) aac_model_t *dst = aac_model_alloc (coeff); memcpy (dst->counts, src->counts, - sizeof (word_t) * ((coeff->max_level - coeff->min_level + 1) - * (1 << (1 + coeff->rpf->mantissa_bits)) - + (1 << (1 + coeff->dc_rpf->mantissa_bits)))); + sizeof (word_t) * ((coeff->max_level - coeff->min_level + 1) + * (1 << (1 + coeff->rpf->mantissa_bits)) + + (1 << (1 + coeff->dc_rpf->mantissa_bits)))); memcpy (dst->totals, src->totals, - sizeof (word_t) * (coeff->max_level - coeff->min_level + 1 + 1)); - + sizeof (word_t) * (coeff->max_level - coeff->min_level + 1 + 1)); + return dst; } @@ -285,36 +285,36 @@ static void * aac_model_alloc (const coeff_t *coeff) { aac_model_t *model; - unsigned size = (coeff->max_level - coeff->min_level + 1) - * (1 << (1 + coeff->rpf->mantissa_bits)) - + (1 << (1 + coeff->dc_rpf->mantissa_bits)); - - model = Calloc (1, sizeof (aac_model_t)); + unsigned size = (coeff->max_level - coeff->min_level + 1) + * (1 << (1 + coeff->rpf->mantissa_bits)) + + (1 << (1 + coeff->dc_rpf->mantissa_bits)); + + model = Calloc (1, sizeof (aac_model_t)); model->counts = Calloc (size, sizeof (word_t)); model->totals = Calloc (coeff->max_level - coeff->min_level + 1 + 1, - sizeof (word_t)); + sizeof (word_t)); /* * Initialize model */ { unsigned n; word_t *ptr = model->counts; - + for (n = size; n; n--) - *ptr++ = 1; + *ptr++ = 1; model->totals [0] = 1 << (1 + coeff->dc_rpf->mantissa_bits); for (n = coeff->min_level; n <= coeff->max_level; n++) - model->totals [n - coeff->min_level + 1] - = 1 << (1 + coeff->rpf->mantissa_bits); + model->totals [n - coeff->min_level + 1] + = 1 << (1 + coeff->rpf->mantissa_bits); } - + return (void *) model; } static void aac_model_free (void *model) { - aac_model_t *aac_model = (aac_model_t *) model; + aac_model_t *aac_model = (aac_model_t *) model; if (aac_model) { @@ -325,26 +325,26 @@ aac_model_free (void *model) } /***************************************************************************** - default functions + default functions *****************************************************************************/ static coeff_t * default_alloc (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level) + unsigned min_level, unsigned max_level) { coeff_t *coeff = Calloc (1, sizeof (coeff_t)); - coeff->rpf = rpf; - coeff->dc_rpf = dc_rpf; - coeff->min_level = min_level; - coeff->max_level = max_level; - coeff->model = NULL; - coeff->bits = NULL; - coeff->update = NULL; - coeff->free = default_free; - coeff->model_free = default_model_free; + coeff->rpf = rpf; + coeff->dc_rpf = dc_rpf; + coeff->min_level = min_level; + coeff->max_level = max_level; + coeff->model = NULL; + coeff->bits = NULL; + coeff->update = NULL; + coeff->free = default_free; + coeff->model_free = default_model_free; coeff->model_duplicate = default_model_duplicate; - + return coeff; } diff --git a/converter/other/fiasco/codec/coeff.h b/converter/other/fiasco/codec/coeff.h index 6193e2ee..f22de2d7 100644 --- a/converter/other/fiasco/codec/coeff.h +++ b/converter/other/fiasco/codec/coeff.h @@ -1,8 +1,8 @@ /* * coeff.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 */ @@ -23,23 +23,23 @@ typedef struct coeff { - rpf_t *rpf; /* reduced precision format */ - rpf_t *dc_rpf; /* RPF of DC (state 0) component */ - unsigned min_level, max_level; /* allocate memory for [min,..,max] */ - void *model; /* generic pointer to prob. model */ + rpf_t *rpf; /* reduced precision format */ + rpf_t *dc_rpf; /* RPF of DC (state 0) component */ + unsigned min_level, max_level; /* allocate memory for [min,..,max] */ + void *model; /* generic pointer to prob. model */ real_t (*bits) (const real_t *used_coeff, const word_t *used_domains, - unsigned level, const struct coeff *coeff); + unsigned level, const struct coeff *coeff); /* * Compute bit-rate of a range approximation with coefficients given by * -1 terminated list 'used_domains'. */ void (*update) (const real_t *used_coeff, const word_t *used_domains, - unsigned level, struct coeff *coeff); + unsigned level, struct coeff *coeff); /* * Update the probability model according to the chosen approximation. * (given by the -1 terminated list 'used_domains'). */ - void (*free) (struct coeff *coeff); + void (*free) (struct coeff *coeff); /* * Discard the given coefficients struct. */ @@ -55,7 +55,7 @@ typedef struct coeff coeff_t * alloc_coeff_model (const char *coeff_model_name, rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level); + unsigned min_level, unsigned max_level); #endif /* not _COEFF_H */ diff --git a/converter/other/fiasco/codec/control.c b/converter/other/fiasco/codec/control.c index 2ea06052..0588623f 100644 --- a/converter/other/fiasco/codec/control.c +++ b/converter/other/fiasco/codec/control.c @@ -1,8 +1,8 @@ /* - * control.c: Control unit of WFA structure + * control.c: Control unit of WFA structure + * + * 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 */ @@ -17,7 +17,7 @@ #include "config.h" #include - + #include "types.h" #include "macros.h" #include "error.h" @@ -30,24 +30,24 @@ /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ -static void +static void clear_or_alloc (real_t **ptr, size_t size); -static void +static void compute_images (unsigned from, unsigned to, const wfa_t *wfa, coding_t *c); /***************************************************************************** - public code - + public code + *****************************************************************************/ -void +void append_state (bool_t auxiliary_state, real_t final, unsigned level_of_state, - wfa_t *wfa, coding_t *c) + wfa_t *wfa, coding_t *c) /* * Append a 'wfa' state. If 'auxiliary_state' == YES then * allocate memory for inner products and state images. 'final' is @@ -57,13 +57,13 @@ append_state (bool_t auxiliary_state, real_t final, unsigned level_of_state, * No return value. * * Side effects: - * The WFA information are updated in structure 'wfa' - * State images are computed and inner products are cleared (in 'c') + * The WFA information are updated in structure 'wfa' + * State images are computed and inner products are cleared (in 'c') */ { wfa->final_distribution [wfa->states] = final; wfa->level_of_state [wfa->states] = level_of_state; - + if (!auxiliary_state) { unsigned level; @@ -74,63 +74,63 @@ append_state (bool_t auxiliary_state, real_t final, unsigned level_of_state, * Allocate memory for inner products and for state images */ clear_or_alloc (&c->images_of_state [wfa->states], - size_of_tree (c->options.images_level)); - + size_of_tree (c->options.images_level)); + for (level = c->options.images_level + 1; - level <= c->options.lc_max_level; level++) - clear_or_alloc (&c->ip_states_state [wfa->states][level], - wfa->states + 1); + level <= c->options.lc_max_level; level++) + clear_or_alloc (&c->ip_states_state [wfa->states][level], + wfa->states + 1); clear_or_alloc (&c->ip_images_state [wfa->states], - size_of_tree (c->products_level)); + size_of_tree (c->products_level)); /* * Compute the images of the current state at level 0,..,'imageslevel' */ - + c->images_of_state [wfa->states][0] = final; - compute_images (wfa->states, wfa->states, wfa, c); + compute_images (wfa->states, wfa->states, wfa, c); /* * Compute the inner products between the current state and the * old states 0,...,'states'-1 - */ - + */ + compute_ip_states_state (wfa->states, wfa->states, wfa, c); } else { unsigned level; - + wfa->domain_type [wfa->states] = 0; - + /* * Free the allocated memory */ if (c->images_of_state [wfa->states] != NULL) { - Free (c->images_of_state [wfa->states]); - c->images_of_state [wfa->states] = NULL; + Free (c->images_of_state [wfa->states]); + c->images_of_state [wfa->states] = NULL; } for (level = 0; level <= c->options.lc_max_level; level++) - if (c->ip_states_state [wfa->states][level]) - { - Free (c->ip_states_state [wfa->states][level]); - c->ip_states_state [wfa->states][level] = NULL; - } + if (c->ip_states_state [wfa->states][level]) + { + Free (c->ip_states_state [wfa->states][level]); + c->ip_states_state [wfa->states][level] = NULL; + } if (c->ip_images_state [wfa->states]) { - Free (c->ip_images_state [wfa->states]); - c->ip_images_state [wfa->states] = NULL; + Free (c->ip_images_state [wfa->states]); + c->ip_images_state [wfa->states] = NULL; } } - + wfa->states++; - if (wfa->states >= MAXSTATES) + if (wfa->states >= MAXSTATES) error ("Maximum number of states reached!"); -} - -void +} + +void append_basis_states (unsigned basis_states, wfa_t *wfa, coding_t *c) /* * Append the WFA basis states 0, ... , ('basis_states' - 1). @@ -138,8 +138,8 @@ append_basis_states (unsigned basis_states, wfa_t *wfa, coding_t *c) * No return value. * * Side effects: - * The WFA information are updated in structure 'wfa' - * State images and inner products are computed (in 'c') + * The WFA information are updated in structure 'wfa' + * State images and inner products are computed (in 'c') */ { unsigned level, state; @@ -151,30 +151,30 @@ append_basis_states (unsigned basis_states, wfa_t *wfa, coding_t *c) for (state = 0; state < basis_states; state++) { clear_or_alloc (&c->images_of_state [state], - size_of_tree (c->options.images_level)); + size_of_tree (c->options.images_level)); for (level = c->options.images_level + 1; - level <= c->options.lc_max_level; level++) - clear_or_alloc (&c->ip_states_state [state][level], state + 1); + level <= c->options.lc_max_level; level++) + clear_or_alloc (&c->ip_states_state [state][level], state + 1); clear_or_alloc (&c->ip_images_state [state], - size_of_tree (c->products_level)); + size_of_tree (c->products_level)); c->images_of_state [state][0] = wfa->final_distribution [state]; wfa->level_of_state [state] = -1; } - - compute_images (0, basis_states - 1, wfa, c); + + compute_images (0, basis_states - 1, wfa, c); compute_ip_states_state (0, basis_states - 1, wfa, c); wfa->states = basis_states; - - if (wfa->states >= MAXSTATES) + + if (wfa->states >= MAXSTATES) error ("Maximum number of states reached!"); -} - -void +} + +void append_transitions (unsigned state, unsigned label, const real_t *weight, - const word_t *into, wfa_t *wfa) + const word_t *into, wfa_t *wfa) /* * Append the 'wfa' transitions (given by the arrays 'weight' and 'into') * of the range ('state','label'). @@ -182,7 +182,7 @@ append_transitions (unsigned state, unsigned label, const real_t *weight, * No return value. * * Side effects: - * new 'wfa' edges are appended + * new 'wfa' edges are appended */ { unsigned edge; @@ -192,81 +192,81 @@ append_transitions (unsigned state, unsigned label, const real_t *weight, { append_edge (state, into [edge], weight [edge], label, wfa); if (into [edge] == wfa->y_state [state][label]) - wfa->y_column [state][label] = 1; + wfa->y_column [state][label] = 1; } } /***************************************************************************** - private code - + private code + *****************************************************************************/ -static void +static void compute_images (unsigned from, unsigned to, const wfa_t *wfa, coding_t *c) /* - * Computes the images of the given states 'from', ... , 'to' + * Computes the images of the given states 'from', ... , 'to' * at level 0,...,'c->imagelevel'. * Uses the fact that each state image is a linear combination of state * images, i.e. s_i := c_0 s_0 + ... + c_i s_i. */ { unsigned label, level, state; - + /* * Compute the images Phi(state) - * # level = 0 - * ## level = 1 - * #### level = 2 - * ######## level = 3 + * # level = 0 + * ## level = 1 + * #### level = 2 + * ######## level = 3 * ... * ########...## level = imageslevel */ - + for (level = 1; level <= c->options.images_level; level++) for (state = from; state <= to; state++) - for (label = 0; label < MAXLABELS; label++) - { - real_t *dst, *src; - unsigned edge; - int domain; /* current domain */ - - if (ischild (domain = wfa->tree[state][label])) - { - dst = c->images_of_state [state] + address_of_level (level) + - label * size_of_level (level - 1); - src = c->images_of_state [domain] - + address_of_level (level - 1); - memcpy (dst, src, size_of_level (level - 1) * sizeof (real_t)); - } - for (edge = 0; isedge (domain = wfa->into[state][label][edge]); - edge++) - { - unsigned n; - real_t weight = wfa->weight [state][label][edge]; - - dst = c->images_of_state [state] + address_of_level (level) + - label * size_of_level (level - 1); - src = c->images_of_state [domain] - + address_of_level (level - 1); - - for (n = size_of_level (level - 1); n; n--) - *dst++ += *src++ * weight; - } - } + for (label = 0; label < MAXLABELS; label++) + { + real_t *dst, *src; + unsigned edge; + int domain; /* current domain */ + + if (ischild (domain = wfa->tree[state][label])) + { + dst = c->images_of_state [state] + address_of_level (level) + + label * size_of_level (level - 1); + src = c->images_of_state [domain] + + address_of_level (level - 1); + memcpy (dst, src, size_of_level (level - 1) * sizeof (real_t)); + } + for (edge = 0; isedge (domain = wfa->into[state][label][edge]); + edge++) + { + unsigned n; + real_t weight = wfa->weight [state][label][edge]; + + dst = c->images_of_state [state] + address_of_level (level) + + label * size_of_level (level - 1); + src = c->images_of_state [domain] + + address_of_level (level - 1); + + for (n = size_of_level (level - 1); n; n--) + *dst++ += *src++ * weight; + } + } } -static void +static void clear_or_alloc (real_t **ptr, size_t size) /* - * if *ptr == NULL allocate memory with Calloc - * otherwise fill the real_t-array ptr[] with 0 + * if *ptr == NULL allocate memory with Calloc + * otherwise fill the real_t-array ptr[] with 0 */ { - if (*ptr == NULL) + if (*ptr == NULL) *ptr = Calloc (size, sizeof (real_t)); - else + else memset (*ptr, 0, size * sizeof (real_t)); - + } diff --git a/converter/other/fiasco/codec/control.h b/converter/other/fiasco/codec/control.h index 6c0834a1..9bfc9b50 100644 --- a/converter/other/fiasco/codec/control.h +++ b/converter/other/fiasco/codec/control.h @@ -1,8 +1,8 @@ /* * control.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,14 +20,14 @@ #include "cwfa.h" #include "types.h" -void +void append_transitions (unsigned state, unsigned label, const real_t *weight, - const word_t *into, wfa_t *wfa); -void + const word_t *into, wfa_t *wfa); +void append_basis_states (unsigned basis_states, wfa_t *wfa, coding_t *c); -void +void append_state (bool_t auxiliary_state, real_t final, unsigned level_of_state, - wfa_t *wfa, coding_t *c); + wfa_t *wfa, coding_t *c); #endif /* not _CONTROL_H */ diff --git a/converter/other/fiasco/codec/cwfa.h b/converter/other/fiasco/codec/cwfa.h index e8e2d474..4fed343c 100644 --- a/converter/other/fiasco/codec/cwfa.h +++ b/converter/other/fiasco/codec/cwfa.h @@ -1,8 +1,8 @@ /* * cwfa.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 */ @@ -32,15 +32,15 @@ extern const real_t MAXCOSTS; typedef struct motion { - image_t *original; /* Current image */ - image_t *past; /* Preceding image */ - image_t *future; /* Succeeding image */ - frame_type_e frame_type; /* frame type: B_, P_ I_FRAME */ - unsigned number; /* display number of frame */ - real_t *xbits; /* # bits for mv x-component */ - real_t *ybits; /* # bits for mv y-component */ - real_t **mc_forward_norms; /* norms of mcpe */ - real_t **mc_backward_norms; /* norms of mcpe */ + image_t *original; /* Current image */ + image_t *past; /* Preceding image */ + image_t *future; /* Succeeding image */ + frame_type_e frame_type; /* frame type: B_, P_ I_FRAME */ + unsigned number; /* display number of frame */ + real_t *xbits; /* # bits for mv x-component */ + real_t *ybits; /* # bits for mv y-component */ + real_t **mc_forward_norms; /* norms of mcpe */ + real_t **mc_backward_norms; /* norms of mcpe */ } motion_t; typedef struct range @@ -48,30 +48,30 @@ typedef struct range * Information about current range in the original image. * Approximation data (error, encoding bits, approximation type and factors * of the linear combination) are also saved. - */ + */ { unsigned global_address; /* We need absolute image addresses - for distance calculations. */ - unsigned x, y; /* Coordinates of upper left corner */ - unsigned image; /* Position in the tree */ - unsigned address; /* Address of the pixel data */ - unsigned level; /* Level of the range */ - real_t weight [MAXEDGES + 1]; /* coeff. of the approximation */ - word_t into [MAXEDGES + 1]; /* used domains of the approximation */ - int tree; /* == domain : range is approximated - with new state 'domain' - == RANGE : - with a linear comb. */ - real_t err; /* approximation error */ - real_t tree_bits; /* # bits to encode tree */ - real_t matrix_bits; /* # bits to encode matrices */ - real_t weights_bits; /* # bits to encode weights */ - mv_t mv; /* motion vector */ - real_t mv_tree_bits; /* # bits to encode mv tree */ - real_t mv_coord_bits; /* # bits to encode mv coordinates */ - real_t nd_tree_bits; /* # bits to encode nd tree */ - real_t nd_weights_bits; /* # bits to encode nd factors */ - bool_t prediction; /* range is predicted? */ + for distance calculations. */ + unsigned x, y; /* Coordinates of upper left corner */ + unsigned image; /* Position in the tree */ + unsigned address; /* Address of the pixel data */ + unsigned level; /* Level of the range */ + real_t weight [MAXEDGES + 1]; /* coeff. of the approximation */ + word_t into [MAXEDGES + 1]; /* used domains of the approximation */ + int tree; /* == domain : range is approximated + with new state 'domain' + == RANGE : + with a linear comb. */ + real_t err; /* approximation error */ + real_t tree_bits; /* # bits to encode tree */ + real_t matrix_bits; /* # bits to encode matrices */ + real_t weights_bits; /* # bits to encode weights */ + mv_t mv; /* motion vector */ + real_t mv_tree_bits; /* # bits to encode mv tree */ + real_t mv_coord_bits; /* # bits to encode mv coordinates */ + real_t nd_tree_bits; /* # bits to encode nd tree */ + real_t nd_weights_bits; /* # bits to encode nd factors */ + bool_t prediction; /* range is predicted? */ } range_t; typedef struct coding @@ -80,27 +80,27 @@ typedef struct coding * process. */ { - real_t price; /* determines quality of approx. */ - real_t **images_of_state; /* image of state i at level - 0, ... , imageslevel */ + real_t price; /* determines quality of approx. */ + real_t **images_of_state; /* image of state i at level + 0, ... , imageslevel */ real_t *(*ip_states_state)[MAXLEVEL]; /* inner products between state i - and states 0, ... , i - at all image levels */ - real_t **ip_images_state; /* inner products between all - ranges and state i */ - real_t *pixels; /* current image pixels stored in tree - order (only leaves are stored) */ - unsigned products_level; /* inner products are stored up to - this level */ - tiling_t *tiling; /* tiling of the entire image */ - tree_t tree; /* probability model */ - tree_t p_tree; /* prediction probability model */ - motion_t *mt; /* motion compensation information */ - coeff_t *coeff; - coeff_t *d_coeff; + and states 0, ... , i + at all image levels */ + real_t **ip_images_state; /* inner products between all + ranges and state i */ + real_t *pixels; /* current image pixels stored in tree + order (only leaves are stored) */ + unsigned products_level; /* inner products are stored up to + this level */ + tiling_t *tiling; /* tiling of the entire image */ + tree_t tree; /* probability model */ + tree_t p_tree; /* prediction probability model */ + motion_t *mt; /* motion compensation information */ + coeff_t *coeff; + coeff_t *d_coeff; domain_pool_t *domain_pool; domain_pool_t *d_domain_pool; - c_options_t options; /* global options */ + c_options_t options; /* global options */ } coding_t; #endif /* not _CWFA_H */ diff --git a/converter/other/fiasco/codec/decoder.h b/converter/other/fiasco/codec/decoder.h index 7823ab91..d11ccefd 100644 --- a/converter/other/fiasco/codec/decoder.h +++ b/converter/other/fiasco/codec/decoder.h @@ -1,8 +1,8 @@ /* * decode.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 */ @@ -23,41 +23,41 @@ typedef struct video { - unsigned future_display; /* number of a future frame */ - unsigned display; /* current display number */ - image_t *frame; /* current frame */ - image_t *sframe; /* current smoothed frame */ - image_t *future; /* future reference */ - image_t *sfuture; /* future (smmothed) reference */ - image_t *past ; /* past reference */ - wfa_t *wfa; /* current wfa */ - wfa_t *wfa_future; /* future wfa */ - wfa_t *wfa_past; /* past wfa */ + unsigned future_display; /* number of a future frame */ + unsigned display; /* current display number */ + image_t *frame; /* current frame */ + image_t *sframe; /* current smoothed frame */ + image_t *future; /* future reference */ + image_t *sfuture; /* future (smmothed) reference */ + image_t *past ; /* past reference */ + wfa_t *wfa; /* current wfa */ + wfa_t *wfa_future; /* future wfa */ + wfa_t *wfa_past; /* past wfa */ } video_t; typedef struct dectimer { - unsigned int input [3]; - unsigned int preprocessing [3]; - unsigned int decoder [3]; - unsigned int cleanup [3]; - unsigned int motion [3]; - unsigned int smooth [3]; - unsigned int display [3]; - unsigned int frames [3]; + unsigned int input [3]; + unsigned int preprocessing [3]; + unsigned int decoder [3]; + unsigned int cleanup [3]; + unsigned int motion [3]; + unsigned int smooth [3]; + unsigned int display [3]; + unsigned int frames [3]; } dectimer_t; image_t * get_next_frame (bool_t store_wfa, int enlarge_factor, - int smoothing, const char *reference_frame, - format_e format, video_t *video, dectimer_t *timer, - wfa_t *orig_wfa, bitfile_t *input); + int smoothing, const char *reference_frame, + format_e format, video_t *video, dectimer_t *timer, + wfa_t *orig_wfa, bitfile_t *input); image_t * decode_image (unsigned orig_width, unsigned orig_height, format_e format, - unsigned *dec_timer, const wfa_t *wfa); + unsigned *dec_timer, const wfa_t *wfa); word_t * decode_range (unsigned range_state, unsigned range_label, unsigned range_level, - word_t **domain, wfa_t *wfa); + word_t **domain, wfa_t *wfa); image_t * decode_state (unsigned state, unsigned level, wfa_t *wfa); void diff --git a/converter/other/fiasco/codec/dfiasco.c b/converter/other/fiasco/codec/dfiasco.c index ce25654a..3f5d3fcc 100644 --- a/converter/other/fiasco/codec/dfiasco.c +++ b/converter/other/fiasco/codec/dfiasco.c @@ -1,7 +1,7 @@ /* - * dfiasco.c: Decoder public interface + * dfiasco.c: Decoder public interface * - * 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 @@ -37,7 +37,7 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -47,11 +47,11 @@ static void free_dfiasco (dfiasco_t *dfiasco); static dfiasco_t * alloc_dfiasco (wfa_t *wfa, video_t *video, bitfile_t *input, - int enlarge_factor, int smoothing, format_e image_format); + int enlarge_factor, int smoothing, format_e image_format); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -60,24 +60,24 @@ fiasco_decoder_new (const char *filename, const fiasco_d_options_t *options) { try { - bitfile_t *input; /* pointer to WFA FIASCO stream */ - wfa_t *wfa; /* wfa structure */ - video_t *video; /* information about decoder state */ - const d_options_t *dop; /* decoder additional options */ - dfiasco_t *dfiasco; /* decoder internal state */ - fiasco_decoder_t *decoder; /* public interface to decoder */ + bitfile_t *input; /* pointer to WFA FIASCO stream */ + wfa_t *wfa; /* wfa structure */ + video_t *video; /* information about decoder state */ + const d_options_t *dop; /* decoder additional options */ + dfiasco_t *dfiasco; /* decoder internal state */ + fiasco_decoder_t *decoder; /* public interface to decoder */ fiasco_d_options_t *default_options = NULL; if (options) { - dop = cast_d_options ((fiasco_d_options_t *) options); - if (!dop) - return NULL; + dop = cast_d_options ((fiasco_d_options_t *) options); + if (!dop) + return NULL; } else { - default_options = fiasco_d_options_new (); - dop = cast_d_options (default_options); + default_options = fiasco_d_options_new (); + dop = cast_d_options (default_options); } wfa = alloc_wfa (NO); @@ -85,8 +85,8 @@ fiasco_decoder_new (const char *filename, const fiasco_d_options_t *options) input = open_wfa (filename, wfa->wfainfo); read_basis (wfa->wfainfo->basis_name, wfa); - decoder = Calloc (1, sizeof (fiasco_decoder_t)); - decoder->delete = fiasco_decoder_delete; + decoder = Calloc (1, sizeof (fiasco_decoder_t)); + decoder->delete = fiasco_decoder_delete; decoder->write_frame = fiasco_decoder_write_frame; decoder->get_frame = fiasco_decoder_get_frame; decoder->get_length = fiasco_decoder_get_length; @@ -98,46 +98,46 @@ fiasco_decoder_new (const char *filename, const fiasco_d_options_t *options) decoder->is_color = fiasco_decoder_is_color; decoder->private = dfiasco - = alloc_dfiasco (wfa, video, input, - dop->magnification, - dop->smoothing, - dop->image_format); + = alloc_dfiasco (wfa, video, input, + dop->magnification, + dop->smoothing, + dop->image_format); if (default_options) - fiasco_d_options_delete (default_options); + fiasco_d_options_delete (default_options); if (dfiasco->enlarge_factor >= 0) { - int n; - unsigned long pixels = wfa->wfainfo->width * wfa->wfainfo->height; - - for (n = 1; n <= (int) dfiasco->enlarge_factor; n++) - { - if (pixels << (n << 1) > 2048 * 2048) - { - set_error (_("Magnifaction factor `%d' is too large. " - "Maximum value is %d."), - dfiasco->enlarge_factor, MAX(0, n - 1)); - fiasco_decoder_delete (decoder); - return NULL; - } - } + int n; + unsigned long pixels = wfa->wfainfo->width * wfa->wfainfo->height; + + for (n = 1; n <= (int) dfiasco->enlarge_factor; n++) + { + if (pixels << (n << 1) > 2048 * 2048) + { + set_error (_("Magnifaction factor `%d' is too large. " + "Maximum value is %d."), + dfiasco->enlarge_factor, MAX(0, n - 1)); + fiasco_decoder_delete (decoder); + return NULL; + } + } } else { - int n; - - for (n = 0; n <= (int) - dfiasco->enlarge_factor; n++) - { - if (wfa->wfainfo->width >> n < 32 - || wfa->wfainfo->height >> n < 32) - { - set_error (_("Magnifaction factor `%d' is too small. " - "Minimum value is %d."), - dfiasco->enlarge_factor, - MAX(0, n - 1)); - fiasco_decoder_delete (decoder); - return NULL; - } - } + int n; + + for (n = 0; n <= (int) - dfiasco->enlarge_factor; n++) + { + if (wfa->wfainfo->width >> n < 32 + || wfa->wfainfo->height >> n < 32) + { + set_error (_("Magnifaction factor `%d' is too small. " + "Minimum value is %d."), + dfiasco->enlarge_factor, - MAX(0, n - 1)); + fiasco_decoder_delete (decoder); + return NULL; + } + } } return (fiasco_decoder_t *) decoder; } @@ -149,7 +149,7 @@ fiasco_decoder_new (const char *filename, const fiasco_d_options_t *options) int fiasco_decoder_write_frame (fiasco_decoder_t *decoder, - const char *filename) + const char *filename) { dfiasco_t *dfiasco = cast_dfiasco (decoder); @@ -159,15 +159,15 @@ fiasco_decoder_write_frame (fiasco_decoder_t *decoder, { try { - image_t *frame = get_next_frame (NO, dfiasco->enlarge_factor, - dfiasco->smoothing, NULL, - FORMAT_4_4_4, dfiasco->video, NULL, - dfiasco->wfa, dfiasco->input); - write_image (filename, frame); + image_t *frame = get_next_frame (NO, dfiasco->enlarge_factor, + dfiasco->smoothing, NULL, + FORMAT_4_4_4, dfiasco->video, NULL, + dfiasco->wfa, dfiasco->input); + write_image (filename, frame); } catch { - return 0; + return 0; } return 1; } @@ -184,25 +184,25 @@ fiasco_decoder_get_frame (fiasco_decoder_t *decoder) { try { - fiasco_image_t *image = Calloc (1, sizeof (fiasco_image_t)); - image_t *frame = get_next_frame (NO, dfiasco->enlarge_factor, - dfiasco->smoothing, NULL, - dfiasco->image_format, - dfiasco->video, NULL, - dfiasco->wfa, dfiasco->input); - - frame->reference_count++; /* for motion compensation */ - image->private = frame; - image->delete = fiasco_image_delete; - image->get_width = fiasco_image_get_width; - image->get_height = fiasco_image_get_height; - image->is_color = fiasco_image_is_color; - - return image; + fiasco_image_t *image = Calloc (1, sizeof (fiasco_image_t)); + image_t *frame = get_next_frame (NO, dfiasco->enlarge_factor, + dfiasco->smoothing, NULL, + dfiasco->image_format, + dfiasco->video, NULL, + dfiasco->wfa, dfiasco->input); + + frame->reference_count++; /* for motion compensation */ + image->private = frame; + image->delete = fiasco_image_delete; + image->get_width = fiasco_image_get_width; + image->get_height = fiasco_image_get_height; + image->is_color = fiasco_image_is_color; + + return image; } catch { - return NULL; + return NULL; } } } @@ -241,9 +241,9 @@ fiasco_decoder_get_width (fiasco_decoder_t *decoder) unsigned width; if (dfiasco->enlarge_factor >= 0) - width = dfiasco->wfa->wfainfo->width << dfiasco->enlarge_factor; + width = dfiasco->wfa->wfainfo->width << dfiasco->enlarge_factor; else - width = dfiasco->wfa->wfainfo->width >> - dfiasco->enlarge_factor; + width = dfiasco->wfa->wfainfo->width >> - dfiasco->enlarge_factor; return width & 1 ? width + 1 : width; } @@ -261,9 +261,9 @@ fiasco_decoder_get_height (fiasco_decoder_t *decoder) unsigned height; if (dfiasco->enlarge_factor >= 0) - height = dfiasco->wfa->wfainfo->height << dfiasco->enlarge_factor; + height = dfiasco->wfa->wfainfo->height << dfiasco->enlarge_factor; else - height = dfiasco->wfa->wfainfo->height >> - dfiasco->enlarge_factor; + height = dfiasco->wfa->wfainfo->height >> - dfiasco->enlarge_factor; return height & 1 ? height + 1 : height; } @@ -329,30 +329,30 @@ fiasco_decoder_delete (fiasco_decoder_t *decoder) /***************************************************************************** - private code + private code *****************************************************************************/ static dfiasco_t * alloc_dfiasco (wfa_t *wfa, video_t *video, bitfile_t *input, - int enlarge_factor, int smoothing, format_e image_format) + int enlarge_factor, int smoothing, format_e image_format) /* * FIASCO decoder constructor: * Initialize decoder structure. * * Return value: - * pointer to the new decoder structure + * pointer to the new decoder structure */ { dfiasco_t *dfiasco = Calloc (1, sizeof (dfiasco_t)); strcpy (dfiasco->id, "DFIASCO"); - dfiasco->wfa = wfa; - dfiasco->video = video; - dfiasco->input = input; + dfiasco->wfa = wfa; + dfiasco->video = video; + dfiasco->input = input; dfiasco->enlarge_factor = enlarge_factor; - dfiasco->smoothing = smoothing; + dfiasco->smoothing = smoothing; dfiasco->image_format = image_format; return dfiasco; @@ -367,7 +367,7 @@ free_dfiasco (dfiasco_t *dfiasco) * No return value. * * Side effects: - * 'video' struct is discarded. + * 'video' struct is discarded. */ { Free (dfiasco); @@ -380,7 +380,7 @@ cast_dfiasco (fiasco_decoder_t *dfiasco) * Check whether `dfiasco' is a valid object of type dfiasco_t. * * Return value: - * pointer to dfiasco_t struct on success + * pointer to dfiasco_t struct on success * NULL otherwise */ { @@ -389,8 +389,8 @@ cast_dfiasco (fiasco_decoder_t *dfiasco) { if (!streq (this->id, "DFIASCO")) { - set_error (_("Parameter `dfiasco' doesn't match required type.")); - return NULL; + set_error (_("Parameter `dfiasco' doesn't match required type.")); + return NULL; } } else diff --git a/converter/other/fiasco/codec/dfiasco.h b/converter/other/fiasco/codec/dfiasco.h index eed12b6b..765a09d4 100644 --- a/converter/other/fiasco/codec/dfiasco.h +++ b/converter/other/fiasco/codec/dfiasco.h @@ -1,8 +1,8 @@ /* * dfiasco.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 */ @@ -29,7 +29,7 @@ typedef struct dfiasco wfa_t *wfa; video_t *video; bitfile_t *input; - int enlarge_factor; + int enlarge_factor; int smoothing; format_e image_format; } dfiasco_t; diff --git a/converter/other/fiasco/codec/domain-pool.c b/converter/other/fiasco/codec/domain-pool.c index 1c14a30c..e9986269 100644 --- a/converter/other/fiasco/codec/domain-pool.c +++ b/converter/other/fiasco/codec/domain-pool.c @@ -2,7 +2,7 @@ * domain-pool.c: Domain pool management (probability model) * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -34,9 +34,9 @@ /* * Domain pool model interface: * Implementing the domain pool model interface requires the - * following steps: + * following steps: * - Add a constructor that initializes the domain_pool_t structure - * - Allocate new model with default_alloc() + * - Allocate new model with default_alloc() * - Fill the dp_array_t domain_pools array with constructor and name * - Write code for methods bits() and generate() * - Either use default functions for remaining methods or override them @@ -44,9 +44,9 @@ */ /***************************************************************************** - + local variables - + *****************************************************************************/ static real_t *matrix_0 = NULL; @@ -174,7 +174,7 @@ default_alloc (void); /***************************************************************************** public code - + *****************************************************************************/ typedef struct dp_array @@ -185,7 +185,7 @@ typedef struct dp_array } dp_array_t; dp_array_t const domain_pools[] = {{"adaptive", alloc_qac_domain_pool}, - {"constant", alloc_const_domain_pool}, + {"constant", alloc_const_domain_pool}, {"basis", alloc_basis_domain_pool}, {"uniform", alloc_uniform_domain_pool}, {"rle", alloc_rle_domain_pool}, @@ -199,8 +199,8 @@ alloc_domain_pool (const char *domain_pool_name, unsigned max_domains, * Allocate a new domain pool identified by the string * 'domain_pool_name'. Maximum number of domain images (each one * represented by one state of the given 'wfa') is specified by - * 'max_domains'. - * + * 'max_domains'. + * * Return value: * pointer to the allocated domain pool * @@ -209,16 +209,16 @@ alloc_domain_pool (const char *domain_pool_name, unsigned max_domains, */ { unsigned n; - + if (!max_domains) { warning ("Can't generate empty domain pool. " "Using at least DC component."); max_domains = 1; } - + for (n = 0; domain_pools [n].identifier; n++) /* step through all id's */ - if (strcaseeq (domain_pools [n].identifier, domain_pool_name)) + if (strcaseeq (domain_pools [n].identifier, domain_pool_name)) return domain_pools [n].function (max_domains, max_edges, wfa); warning ("Can't initialize domain pool '%s'. Using default value '%s'.", @@ -230,7 +230,7 @@ alloc_domain_pool (const char *domain_pool_name, unsigned max_domains, /***************************************************************************** private code - + *****************************************************************************/ /***************************************************************************** @@ -256,7 +256,7 @@ alloc_qac_domain_pool (unsigned max_domains, unsigned max_edges, { domain_pool_t *pool; unsigned state; - + pool = default_alloc (); pool->model = qac_model_alloc (max_domains); pool->generate = qac_generate; @@ -266,7 +266,7 @@ alloc_qac_domain_pool (unsigned max_domains, unsigned max_edges, pool->chroma = qac_chroma; pool->model_free = qac_model_free; pool->model_duplicate = qac_model_duplicate; - + for (state = 0; state < wfa->basis_states; state++) if (usedomain (state, wfa)) qac_append (state, -1, wfa, pool->model); @@ -308,7 +308,7 @@ qac_model_duplicate (const void *src) qdst = qac_model_alloc (qsrc->max_domains); qdst->y_index = qsrc->y_index; qdst->n = qsrc->n; - + memcpy (qdst->index, qsrc->index, qsrc->n * sizeof (word_t)); memcpy (qdst->states, qsrc->states, qsrc->n * sizeof (word_t)); @@ -325,14 +325,14 @@ qac_generate (unsigned level, int y_state, const wfa_t *wfa, const void *model) if (y_state >= 0 && !usedomain (y_state, wfa)) /* don't use y-state */ y_state = -1; - + domains = Calloc (qac_model->n + 2, sizeof (word_t)); memcpy (domains, qac_model->states, qac_model->n * sizeof (word_t)); for (n = 0; n < qac_model->n; n++) if (domains [n] == y_state) /* match */ - y_state_is_domain = YES; + y_state_is_domain = YES; if (y_state_is_domain) domains [qac_model->n] = -1; /* end marker */ @@ -361,11 +361,11 @@ qac_bits (const word_t *domains, const word_t *used_domains, bits += matrix_0 [qac_model->index [domain]]; if (y_state >= 0) bits += matrix_0 [qac_model->y_index]; - + if (used_domains != NULL) { unsigned edge; - + for (edge = 0; isedge (domain = used_domains [edge]); edge++) if (domains [domain] == y_state) { @@ -377,8 +377,8 @@ qac_bits (const word_t *domains, const word_t *used_domains, bits -= matrix_0 [qac_model->index [domain]]; bits += matrix_1 [qac_model->index [domain]]; } - } - + } + return bits; } @@ -391,7 +391,7 @@ qac_update (const word_t *domains, const word_t *used_domains, bool_t used_y_state = NO; qac_model_t *qac_model = (qac_model_t *) model; bool_t y_state_is_domain = NO; - + if (y_state >= 0 && !usedomain (y_state, wfa)) /* don't use y-state */ y_state = -1; @@ -399,9 +399,9 @@ qac_update (const word_t *domains, const word_t *used_domains, { qac_model->index [domain]++; /* mark domains unused. */ if (qac_model->states [domain] == y_state) /* match */ - y_state_is_domain = YES; + y_state_is_domain = YES; } - + for (edge = 0; isedge (domain = used_domains [edge]); edge++) if (domains [domain] == y_state) /* chroma coding */ { @@ -413,24 +413,24 @@ qac_update (const word_t *domains, const word_t *used_domains, else /* luminance coding */ { qac_model->index [used_domains [edge]]--; /* undo */ - qac_model->index [used_domains [edge]] >>= 1; + qac_model->index [used_domains [edge]] >>= 1; } if (y_state >= 0 && !used_y_state) qac_model->y_index++; /* update y-state model */ - + for (domain = 0; domain < qac_model->n; domain++) if (qac_model->index [domain] > 1020) /* check for overflow */ - qac_model->index [domain] = 1020; + qac_model->index [domain] = 1020; if (qac_model->y_index > 1020) /* check for overflow */ - qac_model->y_index = 1020; + qac_model->y_index = 1020; } static bool_t qac_append (unsigned new_state, unsigned level, const wfa_t *wfa, void *model) { qac_model_t *qac_model = (qac_model_t *) model; /* probability model */ - + if (qac_model->n >= qac_model->max_domains) return NO; /* don't use state in domain pool */ else @@ -448,14 +448,14 @@ static void qac_chroma (unsigned max_domains, const wfa_t *wfa, void *model) { qac_model_t *qac_model = (qac_model_t *) model; /* probability model */ - + if (max_domains < qac_model->n) /* choose most probable domains */ { word_t *domains; unsigned n, new, old; word_t *states = Calloc (max_domains, sizeof (word_t)); word_t *index = Calloc (max_domains, sizeof (word_t)); - + domains = compute_hits (wfa->basis_states, wfa->states - 1, max_domains, wfa); for (n = 0; n < max_domains && domains [n] >= 0; n++) @@ -491,11 +491,11 @@ alloc_const_domain_pool (unsigned max_domains, unsigned max_edges, */ { domain_pool_t *pool; - - pool = default_alloc (); + + pool = default_alloc (); pool->generate = const_generate; pool->bits = const_bits; - + return pool; } @@ -504,10 +504,10 @@ const_generate (unsigned level, int y_state, const wfa_t *wfa, const void *model) { word_t *domains = Calloc (2, sizeof (word_t)); - + domains [0] = 0; domains [1] = -1; - + return domains; } @@ -548,11 +548,11 @@ alloc_uniform_domain_pool (unsigned max_domains, unsigned max_edges, */ { domain_pool_t *pool; - - pool = default_alloc (); + + pool = default_alloc (); pool->generate = uniform_generate; pool->bits = uniform_bits; - + return pool; } @@ -567,17 +567,17 @@ uniform_generate (unsigned level, int y_state, const wfa_t *wfa, if (usedomain (state, wfa)) domains [n++] = state; domains [n] = -1; - + return domains; } - + static real_t uniform_bits (const word_t *domains, const word_t *used_domains, unsigned level, int y_state, const wfa_t *wfa, const void *model) { unsigned state, n; real_t bits = 0; - + for (state = 0, n = 0; state < wfa->states; state++) if (usedomain (state, wfa)) n++; @@ -587,7 +587,7 @@ uniform_bits (const word_t *domains, const word_t *used_domains, if (used_domains != NULL) { int edge; - + for (edge = 0; isedge (used_domains [edge]); edge++) bits -= log2 (1.0 / n); } @@ -615,13 +615,13 @@ alloc_rle_domain_pool (unsigned max_domains, unsigned max_edges, const wfa_t *wfa) /* * Domain pool with state images {0, ..., 'max_domains'). - * Underlying probability model: rle + * Underlying probability model: rle */ { domain_pool_t *pool; unsigned state; - - pool = default_alloc (); + + pool = default_alloc (); pool->model = rle_model_alloc (max_domains); pool->model_free = rle_model_free; pool->model_duplicate = rle_model_duplicate; @@ -643,7 +643,7 @@ rle_model_alloc (unsigned max_domains) { unsigned m; rle_model_t *model = Calloc (1, sizeof (rle_model_t)); - + for (m = model->total = 0; m < MAXEDGES + 1; m++, model->total++) model->count [m] = 1; @@ -652,7 +652,7 @@ rle_model_alloc (unsigned max_domains) model->n = 0; model->y_index = 0; model->max_domains = max_domains; - + return model; } @@ -676,12 +676,12 @@ rle_model_duplicate (const void *src) model->states = Calloc (model->max_domains, sizeof (word_t)); model->total = rle_src->total; model->y_index = rle_src->y_index; - + memcpy (model->states, rle_src->states, model->max_domains * sizeof (word_t)); memcpy (model->count, rle_src->count, (MAXEDGES + 1) * sizeof (word_t)); - + return model; } @@ -692,17 +692,17 @@ rle_generate (unsigned level, int y_state, const wfa_t *wfa, const void *model) unsigned n; rle_model_t *rle_model = (rle_model_t *) model; bool_t y_state_is_domain = NO; - + if (y_state >= 0 && !usedomain (y_state, wfa)) /* don't use y-state */ y_state = -1; - + domains = Calloc (rle_model->n + 2, sizeof (word_t)); memcpy (domains, rle_model->states, rle_model->n * sizeof (word_t)); for (n = 0; n < rle_model->n; n++) if (domains [n] == y_state) /* match */ - y_state_is_domain = YES; + y_state_is_domain = YES; if (y_state_is_domain) domains [rle_model->n] = -1; /* end marker */ @@ -726,17 +726,17 @@ rle_bits (const word_t *domains, const word_t *used_domains, rle_model_t *rle_model = (rle_model_t *) model; unsigned last; int into; - + if (y_state >= 0 && !usedomain (y_state, wfa)) /* don't use y-state */ y_state = -1; if (used_domains) { word_t domain; - + if (y_state >= 0) bits += matrix_0 [rle_model->y_index]; - + for (edge = n = 0; isedge (domain = used_domains [edge]); edge++) if (domains [domain] != y_state) sorted [n++] = used_domains [edge]; @@ -745,7 +745,7 @@ rle_bits (const word_t *domains, const word_t *used_domains, bits -= matrix_0 [rle_model->y_index]; bits += matrix_1 [rle_model->y_index]; } - + if (n > 1) qsort (sorted, n, sizeof (word_t), sort_asc_word); } @@ -761,7 +761,7 @@ rle_bits (const word_t *domains, const word_t *used_domains, word_t array0 [2] = {NO_EDGE}; bits += qac_bits (array0, array0, level, y_state, wfa, rle_model->domain_0); } - + last = 1; for (edge = 0; edge < n; edge++) if ((into = sorted [edge]) && rle_model->n - 1 - last) @@ -769,7 +769,7 @@ rle_bits (const word_t *domains, const word_t *used_domains, bits += bits_bin_code (into - last, rle_model->n - 1 - last); last = into + 1; } - + return bits; } @@ -781,21 +781,21 @@ rle_update (const word_t *domains, const word_t *used_domains, bool_t state_0 = NO, state_y = NO; word_t array0 [2] = {0, NO_EDGE}; unsigned edge = 0; - + if (y_state >= 0 && !usedomain (y_state, wfa)) /* don't use y-state */ y_state = -1; if (used_domains) { word_t domain; - + for (edge = 0; isedge (domain = used_domains [edge]); edge++) if (domains [domain] == 0) state_0 = YES; else if (domains [domain] == y_state) state_y = YES; } - + rle_model->count [edge]++; rle_model->total++; @@ -807,14 +807,14 @@ rle_update (const word_t *domains, const word_t *used_domains, else rle_model->y_index++; if (rle_model->y_index > 1020) /* check for overflow */ - rle_model->y_index = 1020; + rle_model->y_index = 1020; } static bool_t rle_append (unsigned new_state, unsigned level, const wfa_t *wfa, void *model) { rle_model_t *rle_model = (rle_model_t *) model; /* probability model */ - + if (rle_model->n >= rle_model->max_domains) return NO; /* don't use state in domain pool */ else @@ -827,7 +827,7 @@ rle_append (unsigned new_state, unsigned level, const wfa_t *wfa, void *model) assert (rle_model->n == 1); qac_append (0, -1, wfa, rle_model->domain_0); } - + return YES; /* state will be used in domain pool */ } } @@ -836,14 +836,14 @@ static void rle_chroma (unsigned max_domains, const wfa_t *wfa, void *model) { rle_model_t *rle_model = (rle_model_t *) model; /* probability model */ - + if (max_domains < rle_model->n) /* choose most probable domains */ { unsigned n; word_t *states = Calloc (max_domains, sizeof (word_t)); word_t *domains = compute_hits (wfa->basis_states, wfa->states - 1, max_domains, wfa); - + for (n = 0; n < max_domains && domains [n] >= 0; n++) states [n] = domains [n]; @@ -868,12 +868,12 @@ alloc_rle_no_chroma_domain_pool (unsigned max_domains, unsigned max_edges, const wfa_t *wfa) /* * Domain pool with state images {0, ..., 'max_domains'). - * Underlying probability model: rle + * Underlying probability model: rle * Domain pool is not changed for chroma bands */ { domain_pool_t *pool = alloc_rle_domain_pool (max_domains, max_edges, wfa); - + pool->chroma = default_chroma; return pool; @@ -898,7 +898,7 @@ default_alloc (void) pool->free = default_free; pool->model_free = default_model_free; pool->model_duplicate = default_model_duplicate; - + return pool; } @@ -964,12 +964,12 @@ init_matrix_probabilities (void) { if (matrix_0 == NULL || matrix_1 == NULL) { - unsigned index; + unsigned index; unsigned n, exp; - + matrix_0 = Calloc (1 << (MAX_PROB + 1), sizeof (real_t)); matrix_1 = Calloc (1 << (MAX_PROB + 1), sizeof (real_t)); - + for (index = 0, n = MIN_PROB; n <= MAX_PROB; n++) for (exp = 0; exp < (unsigned) 1 << n; exp++, index++) { diff --git a/converter/other/fiasco/codec/domain-pool.h b/converter/other/fiasco/codec/domain-pool.h index a2c46141..b3258b67 100644 --- a/converter/other/fiasco/codec/domain-pool.h +++ b/converter/other/fiasco/codec/domain-pool.h @@ -1,8 +1,8 @@ /* * domain-pool.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,42 +22,42 @@ typedef struct domain_pool { - void *model; /* probability model */ + void *model; /* probability model */ word_t *(*generate) (unsigned level, int y_state, const wfa_t *wfa, - const void *model); + const void *model); /* * Generate set of domain images which may be used for an approximation. * Use parameters 'level', 'y_state' and 'wfa' to make the decision. */ real_t (*bits) (const word_t *domains, const word_t *used_domains, - unsigned level, int y_state, const wfa_t *wfa, - const void *model); + unsigned level, int y_state, const wfa_t *wfa, + const void *model); /* * Compute bit-rate of a range approximation with domains given by * the -1 terminated list 'used_domains'. */ - void (*update) (const word_t *domains, const word_t *used_domains, - unsigned level, int y_state, const wfa_t *wfa, - void *model); + void (*update) (const word_t *domains, const word_t *used_domains, + unsigned level, int y_state, const wfa_t *wfa, + void *model); /* * Update the probability model according to the chosen approximation. * (given by the -1 terminated list 'used_domains'). */ bool_t (*append) (unsigned state, unsigned level, const wfa_t *wfa, - void *model); + void *model); /* * Try to append a new state to the domain pool. */ - void (*chroma) (unsigned max_domains, const wfa_t *wfa, void *model); + void (*chroma) (unsigned max_domains, const wfa_t *wfa, void *model); /* * Derive a new domain pool that will be used for chroma channel - * coding + * coding */ void (*free) (struct domain_pool *pool); /* * Discard the given domain pool struct. */ - void (*model_free) (void *model); + void (*model_free) (void *model); /* * Free given probability model. */ @@ -69,7 +69,7 @@ typedef struct domain_pool domain_pool_t * alloc_domain_pool (const char *domain_pool_name, unsigned max_domains, - unsigned max_edges, const wfa_t *wfa); + unsigned max_edges, const wfa_t *wfa); #endif /* not _DOMAIN_POOL_H */ diff --git a/converter/other/fiasco/codec/ip.c b/converter/other/fiasco/codec/ip.c index 18257a06..4209ab21 100644 --- a/converter/other/fiasco/codec/ip.c +++ b/converter/other/fiasco/codec/ip.c @@ -1,7 +1,7 @@ /* - * ip.c: Computation of inner products + * ip.c: Computation of inner products * - * 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,29 +26,29 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static real_t standard_ip_image_state (unsigned address, unsigned level, unsigned domain, - const coding_t *c); + const coding_t *c); static real_t standard_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, - const coding_t *c); + const coding_t *c); /***************************************************************************** - public code + public code *****************************************************************************/ real_t get_ip_image_state (unsigned image, unsigned address, unsigned level, - unsigned domain, const coding_t *c) + unsigned domain, const coding_t *c) /* * Return value: - * Inner product between 'image' ('address') and + * Inner product between 'image' ('address') and * 'domain' at given 'level' */ { @@ -71,8 +71,8 @@ get_ip_image_state (unsigned image, unsigned address, unsigned level, void compute_ip_images_state (unsigned image, unsigned address, unsigned level, - unsigned n, unsigned from, - const wfa_t *wfa, coding_t *c) + unsigned n, unsigned from, + const wfa_t *wfa, coding_t *c) /* * Compute the inner products between all states * 'from', ... , 'wfa->max_states' and the range images 'image' @@ -81,84 +81,84 @@ compute_ip_images_state (unsigned image, unsigned address, unsigned level, * No return value. * * Side effects: - * inner product tables 'c->ip_images_states' are updated + * inner product tables 'c->ip_images_states' are updated */ { if (level > c->options.images_level) { unsigned state, label; - if (level > c->options.images_level + 1) /* recursive computation */ - compute_ip_images_state (MAXLABELS * image + 1, address * MAXLABELS, - level - 1, MAXLABELS * n, from, wfa, c); + if (level > c->options.images_level + 1) /* recursive computation */ + compute_ip_images_state (MAXLABELS * image + 1, address * MAXLABELS, + level - 1, MAXLABELS * n, from, wfa, c); /* * Compute inner product */ for (label = 0; label < MAXLABELS; label++) - for (state = from; state < wfa->states; state++) - if (need_image (state, wfa)) - { - unsigned edge, count; - int domain; - real_t *dst, *src; - - if (ischild (domain = wfa->tree [state][label])) - { - if (level > c->options.images_level + 1) - { - dst = c->ip_images_state [state] + image; - src = c->ip_images_state [domain] - + image * MAXLABELS + label + 1; - for (count = n; count; count--, src += MAXLABELS) - *dst++ += *src; - } - else - { - unsigned newadr = address * MAXLABELS + label; - - dst = c->ip_images_state [state] + image; - - for (count = n; count; count--, newadr += MAXLABELS) - *dst++ += standard_ip_image_state (newadr, level - 1, - domain, c); - } - } - for (edge = 0; isedge (domain = wfa->into [state][label][edge]); - edge++) - { - real_t weight = wfa->weight [state][label][edge]; - - if (level > c->options.images_level + 1) - { - dst = c->ip_images_state [state] + image; - src = c->ip_images_state [domain] - + image * MAXLABELS + label + 1; - for (count = n; count; count--, src += MAXLABELS) - *dst++ += *src * weight; - } - else - { - unsigned newadr = address * MAXLABELS + label; - - dst = c->ip_images_state [state] + image; - - for (count = n; count; count--, newadr += MAXLABELS) - *dst++ += weight * - standard_ip_image_state (newadr, level - 1, - domain, c); - } - } - } + for (state = from; state < wfa->states; state++) + if (need_image (state, wfa)) + { + unsigned edge, count; + int domain; + real_t *dst, *src; + + if (ischild (domain = wfa->tree [state][label])) + { + if (level > c->options.images_level + 1) + { + dst = c->ip_images_state [state] + image; + src = c->ip_images_state [domain] + + image * MAXLABELS + label + 1; + for (count = n; count; count--, src += MAXLABELS) + *dst++ += *src; + } + else + { + unsigned newadr = address * MAXLABELS + label; + + dst = c->ip_images_state [state] + image; + + for (count = n; count; count--, newadr += MAXLABELS) + *dst++ += standard_ip_image_state (newadr, level - 1, + domain, c); + } + } + for (edge = 0; isedge (domain = wfa->into [state][label][edge]); + edge++) + { + real_t weight = wfa->weight [state][label][edge]; + + if (level > c->options.images_level + 1) + { + dst = c->ip_images_state [state] + image; + src = c->ip_images_state [domain] + + image * MAXLABELS + label + 1; + for (count = n; count; count--, src += MAXLABELS) + *dst++ += *src * weight; + } + else + { + unsigned newadr = address * MAXLABELS + label; + + dst = c->ip_images_state [state] + image; + + for (count = n; count; count--, newadr += MAXLABELS) + *dst++ += weight * + standard_ip_image_state (newadr, level - 1, + domain, c); + } + } + } } } real_t get_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, - const coding_t *c) + const coding_t *c) /* * Return value: - * Inner product between 'domain1' and 'domain2' at given 'level'. + * Inner product between 'domain1' and 'domain2' at given 'level'. */ { if (level <= c->options.images_level) @@ -175,15 +175,15 @@ get_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, * Use already computed inner products stored in 'ip_images_states' */ if (domain2 < domain1) - return c->ip_states_state [domain1][level][domain2]; + return c->ip_states_state [domain1][level][domain2]; else - return c->ip_states_state [domain2][level][domain1]; + return c->ip_states_state [domain2][level][domain1]; } } void compute_ip_states_state (unsigned from, unsigned to, - const wfa_t *wfa, coding_t *c) + const wfa_t *wfa, coding_t *c) /* * Computes the inner products between the current state 'state1' and the * old states 0,...,'state1'-1 @@ -191,7 +191,7 @@ compute_ip_states_state (unsigned from, unsigned to, * No return value. * * Side effects: - * inner product tables 'c->ip_states_state' are computed. + * inner product tables 'c->ip_states_state' are computed. */ { unsigned level; @@ -202,72 +202,72 @@ compute_ip_states_state (unsigned from, unsigned to, */ for (level = c->options.images_level + 1; - level <= c->options.lc_max_level; level++) + level <= c->options.lc_max_level; level++) for (state1 = from; state1 <= to; state1++) - for (state2 = 0; state2 <= state1; state2++) - if (need_image (state2, wfa)) - { - unsigned label; - real_t ip = 0; - - for (label = 0; label < MAXLABELS; label++) - { - int domain1, domain2; - unsigned edge1, edge2; - real_t sum, weight2; - - if (ischild (domain1 = wfa->tree [state1][label])) - { - sum = 0; - if (ischild (domain2 = wfa->tree [state2][label])) - sum = get_ip_state_state (domain1, domain2, - level - 1, c); - - for (edge2 = 0; - isedge (domain2 = wfa->into [state2][label][edge2]); - edge2++) - { - weight2 = wfa->weight [state2][label][edge2]; - sum += weight2 * get_ip_state_state (domain1, domain2, - level - 1, c); - } - ip += sum; - } - for (edge1 = 0; - isedge (domain1 = wfa->into [state1][label][edge1]); - edge1++) - { - real_t weight1 = wfa->weight [state1][label][edge1]; - - sum = 0; - if (ischild (domain2 = wfa->tree [state2][label])) - sum = get_ip_state_state (domain1, domain2, - level - 1, c); - - for (edge2 = 0; - isedge (domain2 = wfa->into [state2][label][edge2]); - edge2++) - { - weight2 = wfa->weight [state2][label][edge2]; - sum += weight2 * get_ip_state_state (domain1, domain2, - level - 1, c); - } - ip += weight1 * sum; - } - } - c->ip_states_state [state1][level][state2] = ip; - } + for (state2 = 0; state2 <= state1; state2++) + if (need_image (state2, wfa)) + { + unsigned label; + real_t ip = 0; + + for (label = 0; label < MAXLABELS; label++) + { + int domain1, domain2; + unsigned edge1, edge2; + real_t sum, weight2; + + if (ischild (domain1 = wfa->tree [state1][label])) + { + sum = 0; + if (ischild (domain2 = wfa->tree [state2][label])) + sum = get_ip_state_state (domain1, domain2, + level - 1, c); + + for (edge2 = 0; + isedge (domain2 = wfa->into [state2][label][edge2]); + edge2++) + { + weight2 = wfa->weight [state2][label][edge2]; + sum += weight2 * get_ip_state_state (domain1, domain2, + level - 1, c); + } + ip += sum; + } + for (edge1 = 0; + isedge (domain1 = wfa->into [state1][label][edge1]); + edge1++) + { + real_t weight1 = wfa->weight [state1][label][edge1]; + + sum = 0; + if (ischild (domain2 = wfa->tree [state2][label])) + sum = get_ip_state_state (domain1, domain2, + level - 1, c); + + for (edge2 = 0; + isedge (domain2 = wfa->into [state2][label][edge2]); + edge2++) + { + weight2 = wfa->weight [state2][label][edge2]; + sum += weight2 * get_ip_state_state (domain1, domain2, + level - 1, c); + } + ip += weight1 * sum; + } + } + c->ip_states_state [state1][level][state2] = ip; + } } /***************************************************************************** - private code + private code *****************************************************************************/ static real_t standard_ip_image_state (unsigned address, unsigned level, unsigned domain, - const coding_t *c) + const coding_t *c) /* * Returns the inner product between the subimage 'address' and the * state image 'domain' at given 'level'. The stored state images @@ -275,7 +275,7 @@ standard_ip_image_state (unsigned address, unsigned level, unsigned domain, * standard way by multiplying the corresponding pixel values. * * Return value: - * computed inner product + * computed inner product */ { unsigned i; @@ -296,7 +296,7 @@ standard_ip_image_state (unsigned address, unsigned level, unsigned domain, static real_t standard_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, - const coding_t *c) + const coding_t *c) /* * Returns the inner product between the subimage 'address' and the * state image 'state' at given 'level'. The stored state images are @@ -304,7 +304,7 @@ standard_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, * multiplying the corresponding pixel values. * * Return value: - * computed inner product + * computed inner product */ { unsigned i; diff --git a/converter/other/fiasco/codec/ip.h b/converter/other/fiasco/codec/ip.h index 0c693826..f7d7efac 100644 --- a/converter/other/fiasco/codec/ip.h +++ b/converter/other/fiasco/codec/ip.h @@ -1,8 +1,8 @@ /* * ip.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,19 +19,19 @@ #include "cwfa.h" -void +void compute_ip_states_state (unsigned from, unsigned to, - const wfa_t *wfa, coding_t *c); -real_t + const wfa_t *wfa, coding_t *c); +real_t get_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, - const coding_t *c); -void + const coding_t *c); +void compute_ip_images_state (unsigned image, unsigned address, unsigned level, - unsigned n, unsigned from, - const wfa_t *wfa, coding_t *c); -real_t + unsigned n, unsigned from, + const wfa_t *wfa, coding_t *c); +real_t get_ip_image_state (unsigned image, unsigned address, unsigned level, - unsigned domain, const coding_t *c); + unsigned domain, const coding_t *c); #endif /* not _IP_H */ diff --git a/converter/other/fiasco/codec/motion.c b/converter/other/fiasco/codec/motion.c index 0d1fa099..18d3bdd3 100644 --- a/converter/other/fiasco/codec/motion.c +++ b/converter/other/fiasco/codec/motion.c @@ -1,9 +1,9 @@ /* - * motion.c: Motion compensation code + * motion.c: Motion compensation code + * + * Written by: Ullrich Hafner + * Michael Unger * - * Written by: Ullrich Hafner - * Michael Unger - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -31,13 +31,13 @@ /***************************************************************************** - public code - + public code + *****************************************************************************/ void restore_mc (int enlarge_factor, image_t *image, const image_t *past, - const image_t *future, const wfa_t *wfa) + const image_t *future, const wfa_t *wfa) /* * Restore motion compensated prediction of 'image' represented by 'wfa'. * If 'enlarge_factor' != 0 then enlarge image by given amount. @@ -48,193 +48,193 @@ restore_mc (int enlarge_factor, image_t *image, const image_t *past, { unsigned state, label; unsigned root_state; - word_t *mcblock1, *mcblock2; /* MC blocks */ + word_t *mcblock1, *mcblock2; /* MC blocks */ #define FX(v) ((image->format == FORMAT_4_2_0) && band != Y ? ((v) / 2) : v) - + mcblock1 = Calloc (size_of_level (MAX((int) wfa->wfainfo->p_max_level - + 2 * enlarge_factor, 0)), - sizeof (word_t)); + + 2 * enlarge_factor, 0)), + sizeof (word_t)); mcblock2 = Calloc (size_of_level (MAX((int) wfa->wfainfo->p_max_level - + 2 * enlarge_factor, 0)), - sizeof (word_t)); + + 2 * enlarge_factor, 0)), + sizeof (word_t)); if (!image->color) root_state = wfa->root_state; else root_state = wfa->tree [wfa->tree [wfa->root_state][0]][0]; - + for (state = wfa->basis_states; state <= root_state; state++) for (label = 0; label < MAXLABELS; label++) - if (wfa->mv_tree[state][label].type != NONE) - { - color_e band; - unsigned level = wfa->level_of_state [state] - 1; - unsigned width = width_of_level (level); - unsigned height = height_of_level (level); - unsigned offset = image->width - width; - - switch (wfa->mv_tree [state][label].type) - { - case FORWARD: - for (band = first_band (image->color); - band <= last_band (image->color); band++) - { - extract_mc_block (mcblock1, FX (width), FX (height), - past->pixels [band], FX (past->width), - wfa->wfainfo->half_pixel, - FX (wfa->x [state][label]), - FX (wfa->y [state][label]), - FX (wfa->mv_tree [state][label].fx), - FX (wfa->mv_tree [state][label].fy)); - { - word_t *mc1; /* current pixel in MC block */ - word_t *orig; /* current pixel in original image */ - unsigned x, y; /* pixel coordinates */ - - mc1 = mcblock1; - orig = (word_t *) image->pixels [band] - + FX (wfa->x[state][label]) - + FX (wfa->y[state][label]) * FX (image->width); - - for (y = FX (height); y; y--) - { - for (x = FX (width); x; x--) - *orig++ += *mc1++; - - orig += FX (offset); - } - } - } - break; - case BACKWARD: - for (band = first_band (image->color); - band <= last_band (image->color); band++) - { - extract_mc_block (mcblock1, FX (width), FX (height), - future->pixels [band], - FX (future->width), - wfa->wfainfo->half_pixel, - FX (wfa->x [state][label]), - FX (wfa->y [state][label]), - FX (wfa->mv_tree [state][label].bx), - FX (wfa->mv_tree [state][label].by)); - { - word_t *mc1; /* current pixel in MC block 1 */ - word_t *orig; /* current pixel in original image */ - unsigned x, y; /* pixel coordinates */ - - mc1 = mcblock1; - orig = (word_t *) image->pixels [band] - + FX (wfa->x[state][label]) - + FX (wfa->y[state][label]) * FX (image->width); - - for (y = FX (height); y; y--) - { - for (x = FX (width); x; x--) - *orig++ += *mc1++; - - orig += FX (offset); - } - } - } - break; - case INTERPOLATED: - for (band = first_band (image->color); - band <= last_band (image->color); band++) - { - extract_mc_block (mcblock1, FX (width), FX (height), - past->pixels [band], FX (past->width), - wfa->wfainfo->half_pixel, - FX (wfa->x[state][label]), - FX (wfa->y[state][label]), - FX (wfa->mv_tree[state][label].fx), - FX (wfa->mv_tree[state][label].fy)); - extract_mc_block (mcblock2, FX (width), FX (height), - future->pixels [band], - FX (future->width), - wfa->wfainfo->half_pixel, - FX (wfa->x[state][label]), - FX (wfa->y[state][label]), - FX (wfa->mv_tree[state][label].bx), - FX (wfa->mv_tree[state][label].by)); - { - word_t *mc1; /* current pixel in MC block 1 */ - word_t *mc2; /* current pixel in MC block 1 */ - word_t *orig; /* current pixel in original image */ - unsigned x, y; /* pixel coordinates */ - - mc1 = mcblock1; - mc2 = mcblock2; - orig = (word_t *) image->pixels [band] - + FX (wfa->x[state][label]) - + FX (wfa->y[state][label]) * FX (image->width); - - for (y = FX (height); y; y--) - { - for (x = FX (width); x; x--) + if (wfa->mv_tree[state][label].type != NONE) + { + color_e band; + unsigned level = wfa->level_of_state [state] - 1; + unsigned width = width_of_level (level); + unsigned height = height_of_level (level); + unsigned offset = image->width - width; + + switch (wfa->mv_tree [state][label].type) + { + case FORWARD: + for (band = first_band (image->color); + band <= last_band (image->color); band++) + { + extract_mc_block (mcblock1, FX (width), FX (height), + past->pixels [band], FX (past->width), + wfa->wfainfo->half_pixel, + FX (wfa->x [state][label]), + FX (wfa->y [state][label]), + FX (wfa->mv_tree [state][label].fx), + FX (wfa->mv_tree [state][label].fy)); + { + word_t *mc1; /* current pixel in MC block */ + word_t *orig; /* current pixel in original image */ + unsigned x, y; /* pixel coordinates */ + + mc1 = mcblock1; + orig = (word_t *) image->pixels [band] + + FX (wfa->x[state][label]) + + FX (wfa->y[state][label]) * FX (image->width); + + for (y = FX (height); y; y--) + { + for (x = FX (width); x; x--) + *orig++ += *mc1++; + + orig += FX (offset); + } + } + } + break; + case BACKWARD: + for (band = first_band (image->color); + band <= last_band (image->color); band++) + { + extract_mc_block (mcblock1, FX (width), FX (height), + future->pixels [band], + FX (future->width), + wfa->wfainfo->half_pixel, + FX (wfa->x [state][label]), + FX (wfa->y [state][label]), + FX (wfa->mv_tree [state][label].bx), + FX (wfa->mv_tree [state][label].by)); + { + word_t *mc1; /* current pixel in MC block 1 */ + word_t *orig; /* current pixel in original image */ + unsigned x, y; /* pixel coordinates */ + + mc1 = mcblock1; + orig = (word_t *) image->pixels [band] + + FX (wfa->x[state][label]) + + FX (wfa->y[state][label]) * FX (image->width); + + for (y = FX (height); y; y--) + { + for (x = FX (width); x; x--) + *orig++ += *mc1++; + + orig += FX (offset); + } + } + } + break; + case INTERPOLATED: + for (band = first_band (image->color); + band <= last_band (image->color); band++) + { + extract_mc_block (mcblock1, FX (width), FX (height), + past->pixels [band], FX (past->width), + wfa->wfainfo->half_pixel, + FX (wfa->x[state][label]), + FX (wfa->y[state][label]), + FX (wfa->mv_tree[state][label].fx), + FX (wfa->mv_tree[state][label].fy)); + extract_mc_block (mcblock2, FX (width), FX (height), + future->pixels [band], + FX (future->width), + wfa->wfainfo->half_pixel, + FX (wfa->x[state][label]), + FX (wfa->y[state][label]), + FX (wfa->mv_tree[state][label].bx), + FX (wfa->mv_tree[state][label].by)); + { + word_t *mc1; /* current pixel in MC block 1 */ + word_t *mc2; /* current pixel in MC block 1 */ + word_t *orig; /* current pixel in original image */ + unsigned x, y; /* pixel coordinates */ + + mc1 = mcblock1; + mc2 = mcblock2; + orig = (word_t *) image->pixels [band] + + FX (wfa->x[state][label]) + + FX (wfa->y[state][label]) * FX (image->width); + + for (y = FX (height); y; y--) + { + for (x = FX (width); x; x--) #ifdef HAVE_SIGNED_SHIFT - *orig++ += (*mc1++ + *mc2++) >> 1; + *orig++ += (*mc1++ + *mc2++) >> 1; #else /* not HAVE_SIGNED_SHIFT */ - *orig++ += (*mc1++ + *mc2++) / 2; + *orig++ += (*mc1++ + *mc2++) / 2; #endif /* not HAVE_SIGNED_SHIFT */ - orig += FX (offset); - } - } - } - break; - default: - break; - } - } + orig += FX (offset); + } + } + } + break; + default: + break; + } + } if (image->color) { - unsigned n; - word_t *ptr; + unsigned n; + word_t *ptr; static int *clipping = NULL; - unsigned shift = image->format == FORMAT_4_2_0 ? 2 : 0; + unsigned shift = image->format == FORMAT_4_2_0 ? 2 : 0; - if (!clipping) /* initialize clipping table */ + if (!clipping) /* initialize clipping table */ { - int i; - - clipping = Calloc (256 * 3, sizeof (int)); - for (i = -128; i < 128; i++) - clipping [256 + i + 128] = i; - for (i = 0; i < 256; i++) - clipping [i] = clipping [256]; - for (i = 512; i < 512 + 256; i++) - clipping [i] = clipping [511]; - clipping += 256 + 128; + int i; + + clipping = Calloc (256 * 3, sizeof (int)); + for (i = -128; i < 128; i++) + clipping [256 + i + 128] = i; + for (i = 0; i < 256; i++) + clipping [i] = clipping [256]; + for (i = 512; i < 512 + 256; i++) + clipping [i] = clipping [511]; + clipping += 256 + 128; } - + ptr = image->pixels [Cb]; for (n = (image->width * image->height) >> shift; n; n--, ptr++) #ifdef HAVE_SIGNED_SHIFT - *ptr = clipping [*ptr >> 4] << 4; + *ptr = clipping [*ptr >> 4] << 4; #else /* not HAVE_SIGNED_SHIFT */ - *ptr = clipping [*ptr / 16] * 16; + *ptr = clipping [*ptr / 16] * 16; #endif /* not HAVE_SIGNED_SHIFT */ ptr = image->pixels [Cr]; for (n = (image->width * image->height) >> shift; n; n--, ptr++) #ifdef HAVE_SIGNED_SHIFT - *ptr = clipping [*ptr >> 4] << 4; + *ptr = clipping [*ptr >> 4] << 4; #else /* not HAVE_SIGNED_SHIFT */ *ptr = clipping [*ptr / 16] * 16; #endif /* not HAVE_SIGNED_SHIFT */ } - + Free (mcblock1); Free (mcblock2); } void extract_mc_block (word_t *mcblock, unsigned width, unsigned height, - const word_t *reference, unsigned ref_width, - bool_t half_pixel, unsigned xo, unsigned yo, - unsigned mx, unsigned my) + const word_t *reference, unsigned ref_width, + bool_t half_pixel, unsigned xo, unsigned yo, + unsigned mx, unsigned my) /* * Extract motion compensation image 'mcblock' of size 'width'x'height' * from 'reference' image (width is given by 'ref_width'). @@ -244,93 +244,93 @@ extract_mc_block (word_t *mcblock, unsigned width, unsigned height, * No return value. * * Side effects: - * 'mcblock[]' MCPE block is filled with reference pixels + * 'mcblock[]' MCPE block is filled with reference pixels */ { - if (!half_pixel) /* Fullpixel precision */ + if (!half_pixel) /* Fullpixel precision */ { - const word_t *rblock; /* pointer to reference image */ - unsigned y; /* current row */ - + const word_t *rblock; /* pointer to reference image */ + unsigned y; /* current row */ + rblock = reference + (yo + my) * ref_width + (xo + mx); - for (y = height; y; y--) + for (y = height; y; y--) { - memcpy (mcblock, rblock, width * sizeof (word_t)); + memcpy (mcblock, rblock, width * sizeof (word_t)); - mcblock += width; - rblock += ref_width; + mcblock += width; + rblock += ref_width; } } - else /* Halfpixel precision */ + else /* Halfpixel precision */ { - unsigned x, y; /* current coordinates */ - unsigned offset; /* remaining pixels in row */ - const word_t *rblock; /* pointer to reference image */ - const word_t *ryblock; /* pointer to next line */ - const word_t *rxblock; /* pointer to next column */ - const word_t *rxyblock; /* pointer to next column & row */ - + unsigned x, y; /* current coordinates */ + unsigned offset; /* remaining pixels in row */ + const word_t *rblock; /* pointer to reference image */ + const word_t *ryblock; /* pointer to next line */ + const word_t *rxblock; /* pointer to next column */ + const word_t *rxyblock; /* pointer to next column & row */ + rblock = reference + (yo + my / 2) * ref_width + (xo + mx / 2); - ryblock = rblock + ref_width; /* pixel in next row */ - rxblock = rblock + 1; /* pixel in next column */ - rxyblock = ryblock + 1; /* pixel in next row & column */ + ryblock = rblock + ref_width; /* pixel in next row */ + rxblock = rblock + 1; /* pixel in next column */ + rxyblock = ryblock + 1; /* pixel in next row & column */ offset = ref_width - width; - + if ((mx & 1) == 0) { - if ((my & 1) == 0) /* Don't use halfpixel refinement */ - for (y = height; y; y--) - { - memcpy (mcblock, rblock, width * sizeof (word_t)); - - mcblock += width; - rblock += ref_width; - } - else /* Halfpixel in y direction */ - for (y = height; y; y--) - { - for (x = width; x; x--) + if ((my & 1) == 0) /* Don't use halfpixel refinement */ + for (y = height; y; y--) + { + memcpy (mcblock, rblock, width * sizeof (word_t)); + + mcblock += width; + rblock += ref_width; + } + else /* Halfpixel in y direction */ + for (y = height; y; y--) + { + for (x = width; x; x--) #ifdef HAVE_SIGNED_SHIFT - *mcblock++ = (*rblock++ + *ryblock++) >> 1; + *mcblock++ = (*rblock++ + *ryblock++) >> 1; #else /* not HAVE_SIGNED_SHIFT */ - *mcblock++ = (*rblock++ + *ryblock++) / 2; + *mcblock++ = (*rblock++ + *ryblock++) / 2; #endif /* not HAVE_SIGNED_SHIFT */ - rblock += offset; - ryblock += offset; - } + rblock += offset; + ryblock += offset; + } } else { - if ((my & 1) == 0) /* Halfpixel in x direction */ - for (y = height; y; y--) - { - for (x = width; x; x--) + if ((my & 1) == 0) /* Halfpixel in x direction */ + for (y = height; y; y--) + { + for (x = width; x; x--) #ifdef HAVE_SIGNED_SHIFT - *mcblock++ = (*rblock++ + *rxblock++) >> 1; + *mcblock++ = (*rblock++ + *rxblock++) >> 1; #else /* not HAVE_SIGNED_SHIFT */ - *mcblock++ = (*rblock++ + *rxblock++) / 2; + *mcblock++ = (*rblock++ + *rxblock++) / 2; #endif /* not HAVE_SIGNED_SHIFT */ - rblock += offset; - rxblock += offset; - } - else /* Halfpixel in xy direction */ - for (y = height; y; y--) - { - for (x = width; x; x--) + rblock += offset; + rxblock += offset; + } + else /* Halfpixel in xy direction */ + for (y = height; y; y--) + { + for (x = width; x; x--) #ifdef HAVE_SIGNED_SHIFT - *mcblock++ = (*rblock++ + *rxblock++ - + *ryblock++ + *rxyblock++) >> 2; + *mcblock++ = (*rblock++ + *rxblock++ + + *ryblock++ + *rxyblock++) >> 2; #else /* not HAVE_SIGNED_SHIFT */ - *mcblock++ = (*rblock++ + *rxblock++ - + *ryblock++ + *rxyblock++) / 4; + *mcblock++ = (*rblock++ + *rxblock++ + + *ryblock++ + *rxyblock++) / 4; #endif /* not HAVE_SIGNED_SHIFT */ - rblock += offset; - ryblock += offset; - rxblock += offset; - rxyblock += offset; - } + rblock += offset; + ryblock += offset; + rxblock += offset; + rxyblock += offset; + } } } } diff --git a/converter/other/fiasco/codec/motion.h b/converter/other/fiasco/codec/motion.h index 82d1f1ec..f913c65d 100644 --- a/converter/other/fiasco/codec/motion.h +++ b/converter/other/fiasco/codec/motion.h @@ -1,9 +1,9 @@ /* * motion.h * - * Written by: Ullrich Hafner - * Michael Unger - * + * Written by: Ullrich Hafner + * Michael Unger + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -24,12 +24,12 @@ void restore_mc (int enlarge_factor, image_t *image, const image_t *past, - const image_t *future, const wfa_t *wfa); + const image_t *future, const wfa_t *wfa); void extract_mc_block (word_t *mcblock, unsigned width, unsigned height, - const word_t *reference, unsigned ref_width, - bool_t half_pixel, unsigned xo, unsigned yo, - unsigned mx, unsigned my); + const word_t *reference, unsigned ref_width, + bool_t half_pixel, unsigned xo, unsigned yo, + unsigned mx, unsigned my); #endif /* not _MOTION_H */ diff --git a/converter/other/fiasco/codec/mwfa.c b/converter/other/fiasco/codec/mwfa.c index 0be08a4f..f83f2d00 100644 --- a/converter/other/fiasco/codec/mwfa.c +++ b/converter/other/fiasco/codec/mwfa.c @@ -1,9 +1,9 @@ /* - * mwfa.c: Initialization of MWFA coder + * mwfa.c: Initialization of MWFA coder + * + * Written by: Michael Unger + * Ullrich Hafner * - * Written by: Michael Unger - * Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -38,33 +38,33 @@ static const unsigned local_range = 6; /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ static void get_mcpe (word_t *mcpe, const image_t *original, - unsigned x0, unsigned y0, unsigned width, unsigned height, - const word_t *mcblock1, const word_t *mcblock2); + unsigned x0, unsigned y0, unsigned width, unsigned height, + const word_t *mcblock1, const word_t *mcblock2); static real_t mcpe_norm (const image_t *original, unsigned x0, unsigned y0, unsigned width, - unsigned height, const word_t *mcblock1, const word_t *mcblock2); -static real_t + unsigned height, const word_t *mcblock1, const word_t *mcblock2); +static real_t find_best_mv (real_t price, const image_t *original, const image_t *reference, - unsigned x0, unsigned y0, unsigned width, unsigned height, - real_t *bits, int *mx, int *my, const real_t *mc_norms, - const wfa_info_t *wi, const motion_t *mt); + unsigned x0, unsigned y0, unsigned width, unsigned height, + real_t *bits, int *mx, int *my, const real_t *mc_norms, + const wfa_info_t *wi, const motion_t *mt); static real_t find_second_mv (real_t price, const image_t *original, - const image_t *reference, const word_t *mcblock1, - unsigned xr, unsigned yr, unsigned width, unsigned height, - real_t *bits, int *mx, int *my, const wfa_info_t *wi, - const motion_t *mt); + const image_t *reference, const word_t *mcblock1, + unsigned xr, unsigned yr, unsigned width, unsigned height, + real_t *bits, int *mx, int *my, const wfa_info_t *wi, + const motion_t *mt); /***************************************************************************** - public code - + public code + *****************************************************************************/ motion_t * @@ -75,32 +75,32 @@ alloc_motion (const wfa_info_t *wi) * fill in default values specified by 'wi'. * * Return value: - * pointer to the new option structure or NULL on error + * pointer to the new option structure or NULL on error */ { - int dx; /* motion vector coordinate */ + int dx; /* motion vector coordinate */ unsigned level; unsigned range_size = wi->half_pixel - ? square (wi->search_range) - : square (2 * wi->search_range); + ? square (wi->search_range) + : square (2 * wi->search_range); motion_t *mt = Calloc (1, sizeof (motion_t)); - + mt->original = NULL; mt->past = NULL; mt->future = NULL; - mt->xbits = Calloc (2 * wi->search_range, sizeof (real_t)); - mt->ybits = Calloc (2 * wi->search_range, sizeof (real_t)); + mt->xbits = Calloc (2 * wi->search_range, sizeof (real_t)); + mt->ybits = Calloc (2 * wi->search_range, sizeof (real_t)); for (dx = -wi->search_range; dx < (int) wi->search_range; dx++) { mt->xbits [dx + wi->search_range] - = mt->ybits [dx + wi->search_range] - = mv_code_table [dx + wi->search_range][1]; + = mt->ybits [dx + wi->search_range] + = mv_code_table [dx + wi->search_range][1]; } - + mt->mc_forward_norms = Calloc (MAXLEVEL, sizeof (real_t *)); mt->mc_backward_norms = Calloc (MAXLEVEL, sizeof (real_t *)); - + for (level = wi->p_min_level; level <= wi->p_max_level; level++) { mt->mc_forward_norms [level] = Calloc (range_size, sizeof (real_t)); @@ -119,7 +119,7 @@ free_motion (motion_t *mt) * No return value. * * Side effects: - * structure 'motion' is discarded. + * structure 'motion' is discarded. */ { unsigned level; @@ -129,9 +129,9 @@ free_motion (motion_t *mt) for (level = 0; level < MAXLEVEL; level++) { if (mt->mc_forward_norms [level]) - Free (mt->mc_forward_norms [level]); + Free (mt->mc_forward_norms [level]); if (mt->mc_backward_norms [level]) - Free (mt->mc_backward_norms [level]); + Free (mt->mc_backward_norms [level]); } Free (mt->mc_forward_norms); Free (mt->mc_backward_norms); @@ -140,7 +140,7 @@ free_motion (motion_t *mt) void subtract_mc (image_t *image, const image_t *past, const image_t *future, - const wfa_t *wfa) + const wfa_t *wfa) /* * Subtract motion compensation from chrom channels of 'image'. * Reference frames are given by 'past' and 'future'. @@ -150,135 +150,135 @@ subtract_mc (image_t *image, const image_t *past, const image_t *future, { unsigned state, label; word_t *mcblock1 = Calloc (size_of_level (wfa->wfainfo->p_max_level), - sizeof (word_t)); + sizeof (word_t)); word_t *mcblock2 = Calloc (size_of_level (wfa->wfainfo->p_max_level), - sizeof (word_t)); + sizeof (word_t)); for (state = wfa->basis_states; state < wfa->states; state++) for (label = 0; label < MAXLABELS; label++) - if (wfa->mv_tree [state][label].type != NONE) - { - color_e band; /* current color band */ - unsigned width, height; /* size of mcblock */ - unsigned offset; /* remaining pixels in original */ - - width = width_of_level (wfa->level_of_state [state] - 1); - height = height_of_level (wfa->level_of_state [state] - 1); - offset = image->width - width; - - switch (wfa->mv_tree [state][label].type) - { - case FORWARD: - for (band = first_band (image->color) + 1; - band <= last_band (image->color); band++) - { - unsigned y; /* row of block */ - word_t *mc1; /* pixel in MC block 1 */ - word_t *orig; /* pixel in original image */ - - extract_mc_block (mcblock1, width, height, - past->pixels [band], past->width, - wfa->wfainfo->half_pixel, - wfa->x [state][label], - wfa->y [state][label], - (wfa->mv_tree [state][label].fx / 2) - * 2, - (wfa->mv_tree [state][label].fy / 2) - * 2); - mc1 = mcblock1; - orig = image->pixels [band] + wfa->x [state][label] - + wfa->y [state][label] * image->width; - - for (y = height; y; y--) - { - unsigned x; /* column of block */ - - for (x = width; x; x--) - *orig++ -= *mc1++; - - orig += offset; - } - } - break; - case BACKWARD: - for (band = first_band (image->color) + 1; - band <= last_band (image->color); band++) - { - unsigned y; /* row of block */ - word_t *mc1; /* pixel in MC block 1 */ - word_t *orig; /* pixel in original image */ - - extract_mc_block (mcblock1, width, height, - future->pixels [band], future->width, - wfa->wfainfo->half_pixel, - wfa->x [state][label], - wfa->y [state][label], - (wfa->mv_tree [state][label].bx / 2) - * 2, - (wfa->mv_tree [state][label].by / 2) - * 2); - mc1 = mcblock1; - orig = image->pixels [band] + wfa->x [state][label] - + wfa->y [state][label] * image->width; - - for (y = height; y; y--) - { - unsigned x; /* column of block */ - - for (x = width; x; x--) - *orig++ -= *mc1++; - - orig += offset; - } - } - break; - case INTERPOLATED: - for (band = first_band (image->color) + 1; - band <= last_band (image->color); band++) - { - unsigned y; /* row of block */ - word_t *mc1; /* pixel in MC block 1 */ - word_t *mc2; /* pixel in MC block 2 */ - word_t *orig; /* pixel in original image */ - - extract_mc_block (mcblock1, width, height, - past->pixels [band], past->width, - wfa->wfainfo->half_pixel, - wfa->x [state][label], - wfa->y [state][label], - (wfa->mv_tree[state][label].fx / 2) - * 2, - (wfa->mv_tree[state][label].fy / 2) - * 2); - extract_mc_block (mcblock2, width, height, - future->pixels [band], future->width, - wfa->wfainfo->half_pixel, - wfa->x [state][label], - wfa->y [state][label], - (wfa->mv_tree[state][label].bx / 2) - * 2, - (wfa->mv_tree[state][label].by / 2) - * 2); - mc1 = mcblock1; - mc2 = mcblock2; - orig = image->pixels [band] + wfa->x [state][label] - + wfa->y [state][label] * image->width; - - for (y = height; y; y--) - { - unsigned x; /* column of block */ - - for (x = width; x; x--) - *orig++ -= (*mc1++ + *mc2++) / 2; - - orig += offset; - } - } - break; - default: - break; - } - } + if (wfa->mv_tree [state][label].type != NONE) + { + color_e band; /* current color band */ + unsigned width, height; /* size of mcblock */ + unsigned offset; /* remaining pixels in original */ + + width = width_of_level (wfa->level_of_state [state] - 1); + height = height_of_level (wfa->level_of_state [state] - 1); + offset = image->width - width; + + switch (wfa->mv_tree [state][label].type) + { + case FORWARD: + for (band = first_band (image->color) + 1; + band <= last_band (image->color); band++) + { + unsigned y; /* row of block */ + word_t *mc1; /* pixel in MC block 1 */ + word_t *orig; /* pixel in original image */ + + extract_mc_block (mcblock1, width, height, + past->pixels [band], past->width, + wfa->wfainfo->half_pixel, + wfa->x [state][label], + wfa->y [state][label], + (wfa->mv_tree [state][label].fx / 2) + * 2, + (wfa->mv_tree [state][label].fy / 2) + * 2); + mc1 = mcblock1; + orig = image->pixels [band] + wfa->x [state][label] + + wfa->y [state][label] * image->width; + + for (y = height; y; y--) + { + unsigned x; /* column of block */ + + for (x = width; x; x--) + *orig++ -= *mc1++; + + orig += offset; + } + } + break; + case BACKWARD: + for (band = first_band (image->color) + 1; + band <= last_band (image->color); band++) + { + unsigned y; /* row of block */ + word_t *mc1; /* pixel in MC block 1 */ + word_t *orig; /* pixel in original image */ + + extract_mc_block (mcblock1, width, height, + future->pixels [band], future->width, + wfa->wfainfo->half_pixel, + wfa->x [state][label], + wfa->y [state][label], + (wfa->mv_tree [state][label].bx / 2) + * 2, + (wfa->mv_tree [state][label].by / 2) + * 2); + mc1 = mcblock1; + orig = image->pixels [band] + wfa->x [state][label] + + wfa->y [state][label] * image->width; + + for (y = height; y; y--) + { + unsigned x; /* column of block */ + + for (x = width; x; x--) + *orig++ -= *mc1++; + + orig += offset; + } + } + break; + case INTERPOLATED: + for (band = first_band (image->color) + 1; + band <= last_band (image->color); band++) + { + unsigned y; /* row of block */ + word_t *mc1; /* pixel in MC block 1 */ + word_t *mc2; /* pixel in MC block 2 */ + word_t *orig; /* pixel in original image */ + + extract_mc_block (mcblock1, width, height, + past->pixels [band], past->width, + wfa->wfainfo->half_pixel, + wfa->x [state][label], + wfa->y [state][label], + (wfa->mv_tree[state][label].fx / 2) + * 2, + (wfa->mv_tree[state][label].fy / 2) + * 2); + extract_mc_block (mcblock2, width, height, + future->pixels [band], future->width, + wfa->wfainfo->half_pixel, + wfa->x [state][label], + wfa->y [state][label], + (wfa->mv_tree[state][label].bx / 2) + * 2, + (wfa->mv_tree[state][label].by / 2) + * 2); + mc1 = mcblock1; + mc2 = mcblock2; + orig = image->pixels [band] + wfa->x [state][label] + + wfa->y [state][label] * image->width; + + for (y = height; y; y--) + { + unsigned x; /* column of block */ + + for (x = width; x; x--) + *orig++ -= (*mc1++ + *mc2++) / 2; + + orig += offset; + } + } + break; + default: + break; + } + } Free (mcblock1); Free (mcblock2); @@ -286,7 +286,7 @@ subtract_mc (image_t *image, const image_t *past, const image_t *future, void find_P_frame_mc (word_t *mcpe, real_t price, range_t *range, - const wfa_info_t *wi, const motion_t *mt) + const wfa_info_t *wi, const motion_t *mt) /* * Determine best motion vector for P-frame. * @@ -301,7 +301,7 @@ find_P_frame_mc (word_t *mcpe, real_t price, range_t *range, unsigned width = width_of_level (range->level); unsigned height = height_of_level (range->level); word_t *mcblock = Calloc (width * height, sizeof (word_t)); - + range->mv_tree_bits = 1; range->mv.type = FORWARD; @@ -309,24 +309,24 @@ find_P_frame_mc (word_t *mcpe, real_t price, range_t *range, * Find best matching forward prediction */ find_best_mv (price, mt->original, mt->past, range->x, range->y, - width, height, &range->mv_coord_bits, &range->mv.fx, - &range->mv.fy, mt->mc_forward_norms [range->level], wi, mt); + width, height, &range->mv_coord_bits, &range->mv.fx, + &range->mv.fy, mt->mc_forward_norms [range->level], wi, mt); /* * Compute MCPE */ extract_mc_block (mcblock, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, range->x, range->y, - range->mv.fx, range->mv.fy); + mt->past->width, wi->half_pixel, range->x, range->y, + range->mv.fx, range->mv.fy); get_mcpe (mcpe, mt->original, range->x, range->y, width, height, - mcblock, NULL); + mcblock, NULL); Free (mcblock); } void find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, - const wfa_info_t *wi, const motion_t *mt) + const wfa_info_t *wi, const motion_t *mt) /* * Determines best motion compensation for B-frame. * Steps: @@ -338,104 +338,104 @@ find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, * FORWARD 000 * BACKWARD 001 * INTERPOLATED 01 - * + * * Return values: * range->mvt_bits (# of mv-tree bits) * range->mvxybits (# of bits for vector components) * mt->mcpe (MCPE in scan-order) */ { - mc_type_e mctype; /* type of motion compensation */ - real_t forward_costs; /* costs of FORWARD mc */ - real_t backward_costs; /* costs of BACKWARD mc */ - real_t interp_costs; /* costs of INTERPOLATED mc */ - real_t forward_bits; /* bits for FORWARD mc */ - real_t backward_bits; /* bits for BACKWARD mc */ - real_t interp_bits; /* bits for INTERPOLATED mc */ - int fx, fy; /* coordinates FORWARD mc */ - int bx, by; /* coordinates BACKWARD mc */ - int ifx, ify; /* coordinates forw. INTERPOLATED mc */ - int ibx, iby; /* coordinates back. INTERPOLATED mc */ + mc_type_e mctype; /* type of motion compensation */ + real_t forward_costs; /* costs of FORWARD mc */ + real_t backward_costs; /* costs of BACKWARD mc */ + real_t interp_costs; /* costs of INTERPOLATED mc */ + real_t forward_bits; /* bits for FORWARD mc */ + real_t backward_bits; /* bits for BACKWARD mc */ + real_t interp_bits; /* bits for INTERPOLATED mc */ + int fx, fy; /* coordinates FORWARD mc */ + int bx, by; /* coordinates BACKWARD mc */ + int ifx, ify; /* coordinates forw. INTERPOLATED mc */ + int ibx, iby; /* coordinates back. INTERPOLATED mc */ unsigned width = width_of_level (range->level); unsigned height = height_of_level (range->level); word_t *mcblock1 = Calloc (width * height, sizeof (word_t)); word_t *mcblock2 = Calloc (width * height, sizeof (word_t)); - + /* * Forward interpolation: use past frame as reference */ forward_costs = find_best_mv (price, mt->original, mt->past, - range->x, range->y, width, height, - &forward_bits, &fx, &fy, - mt->mc_forward_norms [range->level], wi, mt) - + 3 * price; /* code 000 */ + range->x, range->y, width, height, + &forward_bits, &fx, &fy, + mt->mc_forward_norms [range->level], wi, mt) + + 3 * price; /* code 000 */ /* * Backward interpolation: use future frame as reference */ backward_costs = find_best_mv (price, mt->original, mt->future, - range->x, range->y, width, height, - &backward_bits, &bx, &by, - mt->mc_backward_norms [range->level], wi, mt) - + 3 * price; /* code 001 */ + range->x, range->y, width, height, + &backward_bits, &bx, &by, + mt->mc_backward_norms [range->level], wi, mt) + + 3 * price; /* code 001 */ /* * Bidirectional interpolation: use both past and future frame as reference */ - if (wi->cross_B_search) + if (wi->cross_B_search) { - real_t icosts1; /* costs interpolation alternative 1 */ - real_t icosts2; /* costs interpolation alternative 2 */ - real_t ibackward_bits; /* additional bits alternative 1 */ - real_t iforward_bits; /* additional bits alternative 1 */ - + real_t icosts1; /* costs interpolation alternative 1 */ + real_t icosts2; /* costs interpolation alternative 2 */ + real_t ibackward_bits; /* additional bits alternative 1 */ + real_t iforward_bits; /* additional bits alternative 1 */ + /* * Alternative 1: keep forward mv and vary backward mv locally */ extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, - range->x, range->y, fx, fy); + mt->past->width, wi->half_pixel, + range->x, range->y, fx, fy); - ibx = bx; /* start with backward coordinates */ + ibx = bx; /* start with backward coordinates */ iby = by; icosts1 = find_second_mv (price, mt->original, mt->future, - mcblock1, range->x, range->y, width, height, - &ibackward_bits, &ibx, &iby, wi, mt) - + (forward_bits + 2) * price; /* code 01 */ + mcblock1, range->x, range->y, width, height, + &ibackward_bits, &ibx, &iby, wi, mt) + + (forward_bits + 2) * price; /* code 01 */ /* * Alternative 2: Keep backward mv and vary forward mv locally */ extract_mc_block (mcblock1, width, height, mt->future->pixels [GRAY], - mt->future->width, wi->half_pixel, - range->x, range->y, bx, by); + mt->future->width, wi->half_pixel, + range->x, range->y, bx, by); ifx = fx; ify = fy; icosts2 = find_second_mv (price, mt->original, mt->past, - mcblock1, range->x, range->y, width, height, - &iforward_bits, &ifx, &ify, wi, mt) - + (backward_bits + 2) * price; /* code 01 */ - + mcblock1, range->x, range->y, width, height, + &iforward_bits, &ifx, &ify, wi, mt) + + (backward_bits + 2) * price; /* code 01 */ + /* * Choose best alternative */ if (icosts1 < icosts2) { - ifx = fx; - ify = fy; - interp_bits = forward_bits + ibackward_bits; - interp_costs = icosts1; + ifx = fx; + ify = fy; + interp_bits = forward_bits + ibackward_bits; + interp_costs = icosts1; } else { - ibx = bx; - iby = by; - interp_bits = iforward_bits + backward_bits; - interp_costs = icosts2; + ibx = bx; + iby = by; + interp_bits = iforward_bits + backward_bits; + interp_costs = icosts2; } } - else /* local exhaustive search */ + else /* local exhaustive search */ { /* * Keep forward and backward mv because of time constraints @@ -448,14 +448,14 @@ find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, interp_bits = forward_bits + backward_bits; extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, - range->x, range->y, fx, fy); + mt->past->width, wi->half_pixel, + range->x, range->y, fx, fy); extract_mc_block (mcblock2, width, height, mt->future->pixels [GRAY], - mt->future->width, wi->half_pixel, - range->x, range->y, bx, by); + mt->future->width, wi->half_pixel, + range->x, range->y, bx, by); interp_costs = mcpe_norm (mt->original, range->x, range->y, - width, height, mcblock1, mcblock2) - + (interp_bits + 2) * price; /* code 01 */ + width, height, mcblock1, mcblock2) + + (interp_bits + 2) * price; /* code 01 */ } /* @@ -464,63 +464,63 @@ find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, if (forward_costs <= interp_costs) { if (forward_costs <= backward_costs) - mctype = FORWARD; + mctype = FORWARD; else - mctype = BACKWARD; + mctype = BACKWARD; } else { if (backward_costs <= interp_costs) - mctype = BACKWARD; + mctype = BACKWARD; else - mctype = INTERPOLATED; + mctype = INTERPOLATED; } switch (mctype) { case FORWARD: - range->mv_tree_bits = 3; - range->mv_coord_bits = forward_bits; - range->mv.type = FORWARD; - range->mv.fx = fx; - range->mv.fy = fy; - extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, - range->x, range->y, range->mv.fx, range->mv.fy); - get_mcpe (mcpe, mt->original, range->x, range->y, width, height, - mcblock1, NULL); - break; + range->mv_tree_bits = 3; + range->mv_coord_bits = forward_bits; + range->mv.type = FORWARD; + range->mv.fx = fx; + range->mv.fy = fy; + extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], + mt->past->width, wi->half_pixel, + range->x, range->y, range->mv.fx, range->mv.fy); + get_mcpe (mcpe, mt->original, range->x, range->y, width, height, + mcblock1, NULL); + break; case BACKWARD: - range->mv_tree_bits = 3; - range->mv_coord_bits = backward_bits; - range->mv.type = BACKWARD; - range->mv.bx = bx; - range->mv.by = by; - extract_mc_block (mcblock1, width, height, mt->future->pixels [GRAY], - mt->future->width, wi->half_pixel, - range->x, range->y, range->mv.bx, range->mv.by); - get_mcpe (mcpe, mt->original, range->x, range->y, width, height, - mcblock1, NULL); - break; + range->mv_tree_bits = 3; + range->mv_coord_bits = backward_bits; + range->mv.type = BACKWARD; + range->mv.bx = bx; + range->mv.by = by; + extract_mc_block (mcblock1, width, height, mt->future->pixels [GRAY], + mt->future->width, wi->half_pixel, + range->x, range->y, range->mv.bx, range->mv.by); + get_mcpe (mcpe, mt->original, range->x, range->y, width, height, + mcblock1, NULL); + break; case INTERPOLATED: - range->mv_tree_bits = 2; - range->mv_coord_bits = interp_bits; - range->mv.type = INTERPOLATED; - range->mv.fx = ifx; - range->mv.fy = ify; - range->mv.bx = ibx; - range->mv.by = iby; - extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, - range->x, range->y, range->mv.fx, range->mv.fy); - extract_mc_block (mcblock2, width, height, mt->future->pixels [GRAY], - mt->future->width, wi->half_pixel, - range->x, range->y, range->mv.bx, range->mv.by); - get_mcpe (mcpe, mt->original, range->x, range->y, width, height, - mcblock1, mcblock2); - break; + range->mv_tree_bits = 2; + range->mv_coord_bits = interp_bits; + range->mv.type = INTERPOLATED; + range->mv.fx = ifx; + range->mv.fy = ify; + range->mv.bx = ibx; + range->mv.by = iby; + extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], + mt->past->width, wi->half_pixel, + range->x, range->y, range->mv.fx, range->mv.fy); + extract_mc_block (mcblock2, width, height, mt->future->pixels [GRAY], + mt->future->width, wi->half_pixel, + range->x, range->y, range->mv.bx, range->mv.by); + get_mcpe (mcpe, mt->original, range->x, range->y, width, height, + mcblock1, mcblock2); + break; default: - break; + break; } Free (mcblock1); @@ -529,7 +529,7 @@ find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, void fill_norms_table (unsigned x0, unsigned y0, unsigned level, - const wfa_info_t *wi, motion_t *mt) + const wfa_info_t *wi, motion_t *mt) /* * Compute norms of difference images for all possible displacements * in 'mc_forward_norm' and 'mc_backward_norm'. @@ -537,50 +537,50 @@ fill_norms_table (unsigned x0, unsigned y0, unsigned level, * No return value. * * Side effects: - * 'mt->mc_backward_norms' are computed - * 'mt->mc_forward_norms' are computed + * 'mt->mc_backward_norms' are computed + * 'mt->mc_forward_norms' are computed */ { - int mx, my; /* coordinates of motion vector */ - unsigned sr; /* mv search range +-'sr' pixels */ - unsigned index = 0; /* index of motion vector */ + int mx, my; /* coordinates of motion vector */ + unsigned sr; /* mv search range +-'sr' pixels */ + unsigned index = 0; /* index of motion vector */ unsigned width = width_of_level (level); unsigned height = height_of_level (level); word_t *mcblock = Calloc (width * height, sizeof (word_t)); sr = wi->half_pixel ? wi->search_range / 2 : wi->search_range; - + for (my = -sr; my < (int) sr; my++) for (mx = -sr; mx < (int) sr; mx++, index++) { - if ((int) x0 + mx < 0 || /* block outside visible area */ - x0 + mx + width > mt->original->width || - (int) y0 + my < 0 || - y0 + my + height > mt->original->height) - { - mt->mc_forward_norms [level][index] = 0.0; - mt->mc_backward_norms [level][index] = 0.0; - } - else - { - extract_mc_block (mcblock, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, - x0, y0, mx, my); - mt->mc_forward_norms [level][index] - = mcpe_norm (mt->original, x0, y0, width, height, - mcblock, NULL); - - if (mt->frame_type == B_FRAME) - { - extract_mc_block (mcblock, width, height, - mt->future->pixels [GRAY], - mt->future->width, wi->half_pixel, - x0, y0, mx, my); - mt->mc_backward_norms[level][index] - = mcpe_norm (mt->original, x0, y0, width, height, - mcblock, NULL); - } - } + if ((int) x0 + mx < 0 || /* block outside visible area */ + x0 + mx + width > mt->original->width || + (int) y0 + my < 0 || + y0 + my + height > mt->original->height) + { + mt->mc_forward_norms [level][index] = 0.0; + mt->mc_backward_norms [level][index] = 0.0; + } + else + { + extract_mc_block (mcblock, width, height, mt->past->pixels [GRAY], + mt->past->width, wi->half_pixel, + x0, y0, mx, my); + mt->mc_forward_norms [level][index] + = mcpe_norm (mt->original, x0, y0, width, height, + mcblock, NULL); + + if (mt->frame_type == B_FRAME) + { + extract_mc_block (mcblock, width, height, + mt->future->pixels [GRAY], + mt->future->width, wi->half_pixel, + x0, y0, mx, my); + mt->mc_backward_norms[level][index] + = mcpe_norm (mt->original, x0, y0, width, height, + mcblock, NULL); + } + } } Free (mcblock); @@ -588,14 +588,14 @@ fill_norms_table (unsigned x0, unsigned y0, unsigned level, /***************************************************************************** - private code - + private code + *****************************************************************************/ static void get_mcpe (word_t *mcpe, const image_t *original, unsigned x0, unsigned y0, - unsigned width, unsigned height, const word_t *mcblock1, - const word_t *mcblock2) + unsigned width, unsigned height, const word_t *mcblock1, + const word_t *mcblock2) /* * Compute MCPE image 'original' - reference. The reference is either * composed of 'mcblock1' or of ('mcblock1' + 'mcblock2') / 2 (if @@ -605,44 +605,44 @@ get_mcpe (word_t *mcpe, const image_t *original, unsigned x0, unsigned y0, * No return value. * * Side effects: - * 'mcpe []' is filled with the delta image + * 'mcpe []' is filled with the delta image */ { - const word_t *oblock; /* pointer to original image */ + const word_t *oblock; /* pointer to original image */ assert (mcpe); - + oblock = original->pixels [GRAY] + y0 * original->width + x0; - if (mcblock2 != NULL) /* interpolated prediction */ + if (mcblock2 != NULL) /* interpolated prediction */ { - unsigned x, y; /* current coordinates */ - - for (y = height; y; y--) + unsigned x, y; /* current coordinates */ + + for (y = height; y; y--) { - for (x = width; x; x--) - *mcpe++ = *oblock++ - (*mcblock1++ + *mcblock2++) / 2; + for (x = width; x; x--) + *mcpe++ = *oblock++ - (*mcblock1++ + *mcblock2++) / 2; - oblock += original->width - width; + oblock += original->width - width; } } - else /* forward or backward prediction */ + else /* forward or backward prediction */ { - unsigned x, y; /* current coordinates */ - - for (y = height; y; y--) + unsigned x, y; /* current coordinates */ + + for (y = height; y; y--) { - for (x = width; x; x--) - *mcpe++ = *oblock++ - *mcblock1++; - - oblock += original->width - width; + for (x = width; x; x--) + *mcpe++ = *oblock++ - *mcblock1++; + + oblock += original->width - width; } } } static real_t mcpe_norm (const image_t *original, unsigned x0, unsigned y0, unsigned width, - unsigned height, const word_t *mcblock1, const word_t *mcblock2) + unsigned height, const word_t *mcblock1, const word_t *mcblock2) /* * Compute norm of motion compensation prediction error. * Coordinates of 'original' block are given by ('x0', 'y0') @@ -650,79 +650,79 @@ mcpe_norm (const image_t *original, unsigned x0, unsigned y0, unsigned width, * Reference blocks are stored in 'mcimage1' and 'mcimage2'. * * Return value: - * square of norm of difference image + * square of norm of difference image */ { unsigned n; real_t norm = 0; word_t *mcpe = Calloc (width * height, sizeof (word_t)); word_t *ptr = mcpe; - + get_mcpe (mcpe, original, x0, y0, width, height, mcblock1, mcblock2); - for (n = height * width; n; n--, ptr++) + for (n = height * width; n; n--, ptr++) norm += square (*ptr / 16); - + Free (mcpe); - + return norm; } -static real_t +static real_t find_best_mv (real_t price, const image_t *original, const image_t *reference, - unsigned x0, unsigned y0, unsigned width, unsigned height, - real_t *bits, int *mx, int *my, const real_t *mc_norms, - const wfa_info_t *wi, const motion_t *mt) + unsigned x0, unsigned y0, unsigned width, unsigned height, + real_t *bits, int *mx, int *my, const real_t *mc_norms, + const wfa_info_t *wi, const motion_t *mt) /* * Find best matching motion vector in image 'reference' to predict * the block ('x0', 'y0') of size 'width'x'height in image 'original'. * * Return values: - * prediction costs + * prediction costs * * Side effects: - * 'mx', 'my' coordinates of motion vector - * 'bits' number of bits to encode mv + * 'mx', 'my' coordinates of motion vector + * 'bits' number of bits to encode mv */ { - unsigned sr; /* mv search range +/- 'sr' pixels */ - unsigned index; /* index of motion vector */ - int x, y; /* coordinates of motion vector */ - real_t costs; /* costs arising if mv is chosen */ - real_t mincosts = MAXCOSTS; /* best costs so far */ - unsigned bitshift; /* half_pixel coordinates multiplier */ - + unsigned sr; /* mv search range +/- 'sr' pixels */ + unsigned index; /* index of motion vector */ + int x, y; /* coordinates of motion vector */ + real_t costs; /* costs arising if mv is chosen */ + real_t mincosts = MAXCOSTS; /* best costs so far */ + unsigned bitshift; /* half_pixel coordinates multiplier */ + *mx = *my = 0; /* * Find best fitting motion vector: * Use exhaustive search in the interval x,y +- sr (no halfpixel accuracy) - * or x,y +- sr/2 (halfpixel accuracy) + * or x,y +- sr/2 (halfpixel accuracy) */ - sr = wi->half_pixel ? wi->search_range / 2 : wi->search_range; - bitshift = (wi->half_pixel ? 2 : 1); /* bit0 reserved for halfpixel pred. */ - + sr = wi->half_pixel ? wi->search_range / 2 : wi->search_range; + bitshift = (wi->half_pixel ? 2 : 1); /* bit0 reserved for halfpixel pred. */ + for (index = 0, y = -sr; y < (int) sr; y++) for (x = -sr; x < (int) sr; x++, index++) - if ((int) x0 + x >= 0 && (int) y0 + y >= 0 && - x0 + x + width <= original->width && - y0 + y + height <= original->height) - { - /* - * Block is inside visible area. - * Compare current costs with 'mincosts' - */ - costs = mc_norms [index] - + (mt->xbits [(x + sr) * bitshift] - + mt->ybits [(y + sr) * bitshift]) * price; - - if (costs < mincosts) - { - mincosts = costs; - *mx = x * bitshift; - *my = y * bitshift; - } - } + if ((int) x0 + x >= 0 && (int) y0 + y >= 0 && + x0 + x + width <= original->width && + y0 + y + height <= original->height) + { + /* + * Block is inside visible area. + * Compare current costs with 'mincosts' + */ + costs = mc_norms [index] + + (mt->xbits [(x + sr) * bitshift] + + mt->ybits [(y + sr) * bitshift]) * price; + + if (costs < mincosts) + { + mincosts = costs; + *mx = x * bitshift; + *my = y * bitshift; + } + } /* * Halfpixel prediction: @@ -730,53 +730,53 @@ find_best_mv (real_t price, const image_t *original, const image_t *reference, */ if (wi->half_pixel) { - int rx, ry; /* halfpixel refinement */ - unsigned bestrx, bestry; /* coordinates of best mv */ + int rx, ry; /* halfpixel refinement */ + unsigned bestrx, bestry; /* coordinates of best mv */ word_t *mcblock = Calloc (width * height, sizeof (word_t)); - + bestrx = bestry = 0; for (rx = -1; rx <= 1; rx++) - for (ry = -1; ry <= 1; ry++) - { - /* - * Check if the new motion vector is in allowed area - */ - if (rx == 0 && ry == 0) /* already tested */ - continue; - if ((int) x0 + (*mx / 2) + rx < 0 || /* outside visible area */ - x0 + (*mx / 2) + rx + width > original->width || - (int) y0 + (*my / 2) + ry < 0 || - y0 + (*my / 2) + ry + height > original->height) - continue; - if (*mx + rx < (int) -sr || *mx + rx >= (int) sr || - *my + ry < (int) -sr || *my + ry >= (int) sr) - continue; /* out of bounds */ - - /* - * Compute costs of new motion compensation - */ - extract_mc_block (mcblock, width, height, - reference->pixels [GRAY], - reference->width, wi->half_pixel, - x0, y0, *mx + rx, *my + ry); - costs = mcpe_norm (mt->original, x0, y0, width, height, mcblock, - NULL) - + (mt->xbits [*mx + rx + sr * bitshift] - + mt->ybits [*my + ry + sr * bitshift]) * price; - if (costs < mincosts) - { - bestrx = rx; - bestry = ry; - mincosts = costs; - } - } + for (ry = -1; ry <= 1; ry++) + { + /* + * Check if the new motion vector is in allowed area + */ + if (rx == 0 && ry == 0) /* already tested */ + continue; + if ((int) x0 + (*mx / 2) + rx < 0 || /* outside visible area */ + x0 + (*mx / 2) + rx + width > original->width || + (int) y0 + (*my / 2) + ry < 0 || + y0 + (*my / 2) + ry + height > original->height) + continue; + if (*mx + rx < (int) -sr || *mx + rx >= (int) sr || + *my + ry < (int) -sr || *my + ry >= (int) sr) + continue; /* out of bounds */ + + /* + * Compute costs of new motion compensation + */ + extract_mc_block (mcblock, width, height, + reference->pixels [GRAY], + reference->width, wi->half_pixel, + x0, y0, *mx + rx, *my + ry); + costs = mcpe_norm (mt->original, x0, y0, width, height, mcblock, + NULL) + + (mt->xbits [*mx + rx + sr * bitshift] + + mt->ybits [*my + ry + sr * bitshift]) * price; + if (costs < mincosts) + { + bestrx = rx; + bestry = ry; + mincosts = costs; + } + } *mx += bestrx; *my += bestry; Free (mcblock); } /* halfpixel */ - + *bits = mt->xbits [*mx + sr * bitshift] + mt->ybits [*my + sr * bitshift]; return mincosts; @@ -784,28 +784,28 @@ find_best_mv (real_t price, const image_t *original, const image_t *reference, static real_t find_second_mv (real_t price, const image_t *original, - const image_t *reference, const word_t *mcblock1, - unsigned xr, unsigned yr, unsigned width, unsigned height, - real_t *bits, int *mx, int *my, const wfa_info_t *wi, - const motion_t *mt) + const image_t *reference, const word_t *mcblock1, + unsigned xr, unsigned yr, unsigned width, unsigned height, + real_t *bits, int *mx, int *my, const wfa_info_t *wi, + const motion_t *mt) /* * Search local area (*mx,*my) for best additional mv. * Overwrite mt->tmpblock. * TODO check sr = search_range * * Return values: - * prediction costs + * prediction costs * * Side effects: - * 'mx','my' coordinates of mv - * 'bits' number of bits to encode mv + * 'mx','my' coordinates of mv + * 'bits' number of bits to encode mv */ { - real_t mincosts = MAXCOSTS; /* best costs so far */ - unsigned sr; /* MV search range +/- 'sr' pixels */ - int x, y; /* coordinates of motion vector */ - int y0, y1, x0, x1; /* start/end coord. of search range */ - unsigned bitshift; /* half_pixel coordinates multiplier */ + real_t mincosts = MAXCOSTS; /* best costs so far */ + unsigned sr; /* MV search range +/- 'sr' pixels */ + int x, y; /* coordinates of motion vector */ + int y0, y1, x0, x1; /* start/end coord. of search range */ + unsigned bitshift; /* half_pixel coordinates multiplier */ word_t *mcblock2 = Calloc (width * height, sizeof (word_t)); sr = wi->search_range; @@ -817,40 +817,40 @@ find_second_mv (real_t price, const image_t *original, *mx = *my = 0; - bitshift = (wi->half_pixel ? 2 : 1); /* bit0 reserved for halfpixel pred. */ + bitshift = (wi->half_pixel ? 2 : 1); /* bit0 reserved for halfpixel pred. */ + - for (y = y0; y < y1; y++) for (x = x0; x < x1; x++) { - real_t costs; /* costs arising if mv is chosen */ - - /* - * Test each mv ('x', 'y') in the given search range: - * Get the new motion compensation image from 'reference' and compute - * the norm of the motion compensation prediction error - * 'original' - 0.5 * ('firstmc' + 'reference') - */ - if ((int) (xr * bitshift) + x < 0 || /* outside visible area */ - xr * bitshift + x > (original->width - width) * bitshift || - (int) (yr * bitshift) + y < 0 || - yr * bitshift + y > (original->height - height) * bitshift) - continue; - - extract_mc_block (mcblock2, width, height, - reference->pixels [GRAY], reference->width, - wi->half_pixel, x0, y0, x, y); - - costs = mcpe_norm (mt->original, x0, y0, width, height, - mcblock1, mcblock2) - + (mt->xbits [x + sr] + mt->ybits [y + sr]) * price; - - if (costs < mincosts) - { - mincosts = costs; - *mx = x; - *my = y; - } + real_t costs; /* costs arising if mv is chosen */ + + /* + * Test each mv ('x', 'y') in the given search range: + * Get the new motion compensation image from 'reference' and compute + * the norm of the motion compensation prediction error + * 'original' - 0.5 * ('firstmc' + 'reference') + */ + if ((int) (xr * bitshift) + x < 0 || /* outside visible area */ + xr * bitshift + x > (original->width - width) * bitshift || + (int) (yr * bitshift) + y < 0 || + yr * bitshift + y > (original->height - height) * bitshift) + continue; + + extract_mc_block (mcblock2, width, height, + reference->pixels [GRAY], reference->width, + wi->half_pixel, x0, y0, x, y); + + costs = mcpe_norm (mt->original, x0, y0, width, height, + mcblock1, mcblock2) + + (mt->xbits [x + sr] + mt->ybits [y + sr]) * price; + + if (costs < mincosts) + { + mincosts = costs; + *mx = x; + *my = y; + } } *bits = mt->xbits [*mx + sr] + mt->ybits [*my + sr]; diff --git a/converter/other/fiasco/codec/mwfa.h b/converter/other/fiasco/codec/mwfa.h index 2c1e7c9f..1e35eef2 100644 --- a/converter/other/fiasco/codec/mwfa.h +++ b/converter/other/fiasco/codec/mwfa.h @@ -1,9 +1,9 @@ /* * mwfa.h * - * Written by: Michael Unger - * Ullrich Hafner - * + * Written by: Michael Unger + * Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -25,16 +25,16 @@ void fill_norms_table (unsigned x0, unsigned y0, unsigned level, - const wfa_info_t *wi, motion_t *mt); + const wfa_info_t *wi, motion_t *mt); void find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, - const wfa_info_t *wi, const motion_t *mt); + const wfa_info_t *wi, const motion_t *mt); void find_P_frame_mc (word_t *mcpe, real_t price, range_t *range, - const wfa_info_t *wi, const motion_t *mt); + const wfa_info_t *wi, const motion_t *mt); void subtract_mc (image_t *image, const image_t *past, const image_t *future, - const wfa_t *wfa); + const wfa_t *wfa); void free_motion (motion_t *mt); motion_t * diff --git a/converter/other/fiasco/codec/options.c b/converter/other/fiasco/codec/options.c index b9c64efd..8029a48e 100644 --- a/converter/other/fiasco/codec/options.c +++ b/converter/other/fiasco/codec/options.c @@ -1,8 +1,8 @@ /* - * options.c: FIASCO options handling + * options.c: FIASCO options handling + * + * 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 */ @@ -44,10 +44,10 @@ fiasco_c_options_new (void) * fill in default values. * * Return value: - * pointer to the new option structure + * pointer to the new option structure */ { - c_options_t *options = calloc (1, sizeof (c_options_t)); + c_options_t *options = calloc (1, sizeof (c_options_t)); fiasco_c_options_t *public = calloc (1, sizeof (fiasco_c_options_t)); if (!options || !public) @@ -55,9 +55,9 @@ fiasco_c_options_new (void) set_error (_("Out of memory.")); return NULL; } - public->private = options; - public->delete = fiasco_c_options_delete; - public->set_tiling = fiasco_c_options_set_tiling; + public->private = options; + public->delete = fiasco_c_options_delete; + public->set_tiling = fiasco_c_options_set_tiling; public->set_frame_pattern = fiasco_c_options_set_frame_pattern; public->set_basisfile = fiasco_c_options_set_basisfile; public->set_chroma_quality = fiasco_c_options_set_chroma_quality; @@ -66,57 +66,57 @@ fiasco_c_options_new (void) public->set_quantization = fiasco_c_options_set_quantization; public->set_progress_meter = fiasco_c_options_set_progress_meter; public->set_smoothing = fiasco_c_options_set_smoothing; - public->set_title = fiasco_c_options_set_title; + public->set_title = fiasco_c_options_set_title; public->set_comment = fiasco_c_options_set_comment; - + strcpy (options->id, "COFIASCO"); /* * Set default value of fiasco options */ - options->basis_name = strdup ("small.fco"); - options->lc_min_level = 4; - options->lc_max_level = 12; - options->p_min_level = 8; - options->p_max_level = 10; - options->images_level = 5; - options->max_states = MAXSTATES; - options->chroma_max_states = 40; - options->max_elements = MAXEDGES; - options->tiling_exponent = 4; - options->tiling_method = FIASCO_TILING_VARIANCE_DSC; - options->id_domain_pool = strdup ("rle"); - options->id_d_domain_pool = strdup ("rle"); - options->id_rpf_model = strdup ("adaptive"); - options->id_d_rpf_model = strdup ("adaptive"); - options->rpf_mantissa = 3; - options->rpf_range = FIASCO_RPF_RANGE_1_50; - options->dc_rpf_mantissa = 5; - options->dc_rpf_range = FIASCO_RPF_RANGE_1_00; - options->d_rpf_mantissa = 3; - options->d_rpf_range = FIASCO_RPF_RANGE_1_50; - options->d_dc_rpf_mantissa = 5; - options->d_dc_rpf_range = FIASCO_RPF_RANGE_1_00; - options->chroma_decrease = 2.0; - options->prediction = NO; - options->delta_domains = YES; - options->normal_domains = YES; - options->search_range = 16; - options->fps = 25; - options->pattern = strdup ("IPPPPPPPPP"); - options->reference_filename = NULL; + options->basis_name = strdup ("small.fco"); + options->lc_min_level = 4; + options->lc_max_level = 12; + options->p_min_level = 8; + options->p_max_level = 10; + options->images_level = 5; + options->max_states = MAXSTATES; + options->chroma_max_states = 40; + options->max_elements = MAXEDGES; + options->tiling_exponent = 4; + options->tiling_method = FIASCO_TILING_VARIANCE_DSC; + options->id_domain_pool = strdup ("rle"); + options->id_d_domain_pool = strdup ("rle"); + options->id_rpf_model = strdup ("adaptive"); + options->id_d_rpf_model = strdup ("adaptive"); + options->rpf_mantissa = 3; + options->rpf_range = FIASCO_RPF_RANGE_1_50; + options->dc_rpf_mantissa = 5; + options->dc_rpf_range = FIASCO_RPF_RANGE_1_00; + options->d_rpf_mantissa = 3; + options->d_rpf_range = FIASCO_RPF_RANGE_1_50; + options->d_dc_rpf_mantissa = 5; + options->d_dc_rpf_range = FIASCO_RPF_RANGE_1_00; + options->chroma_decrease = 2.0; + options->prediction = NO; + options->delta_domains = YES; + options->normal_domains = YES; + options->search_range = 16; + options->fps = 25; + options->pattern = strdup ("IPPPPPPPPP"); + options->reference_filename = NULL; options->half_pixel_prediction = NO; - options->cross_B_search = YES; - options->B_as_past_ref = YES; + options->cross_B_search = YES; + options->B_as_past_ref = YES; options->check_for_underflow = NO; - options->check_for_overflow = NO; + options->check_for_overflow = NO; options->second_domain_block = NO; - options->full_search = NO; - options->progress_meter = FIASCO_PROGRESS_NONE; - options->smoothing = 70; - options->comment = strdup (""); - options->title = strdup (""); - + options->full_search = NO; + options->progress_meter = FIASCO_PROGRESS_NONE; + options->smoothing = 70; + options->comment = strdup (""); + options->title = strdup (""); + return public; } @@ -129,14 +129,14 @@ fiasco_c_options_delete (fiasco_c_options_t *options) * No return value. * * Side effects: - * structure 'options' is discarded. + * structure 'options' is discarded. */ { c_options_t *this = cast_c_options (options); if (!this) return; - + Free (this->id_domain_pool); Free (this->id_d_domain_pool); Free (this->id_rpf_model); @@ -144,7 +144,7 @@ fiasco_c_options_delete (fiasco_c_options_t *options) Free (this->pattern); Free (this->comment); Free (this->title); - + Free (this); return; @@ -152,15 +152,15 @@ fiasco_c_options_delete (fiasco_c_options_t *options) int fiasco_c_options_set_tiling (fiasco_c_options_t *options, - fiasco_tiling_e method, unsigned exponent) + fiasco_tiling_e method, unsigned exponent) /* * Set tiling `method' and `exponent'. * See type `fiasco_tiling_e' for a list of valid tiling `methods'. * The image is subdivied into 2^`exponent' tiles * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -175,21 +175,21 @@ fiasco_c_options_set_tiling (fiasco_c_options_t *options, case FIASCO_TILING_SPIRAL_DSC: case FIASCO_TILING_VARIANCE_ASC: case FIASCO_TILING_VARIANCE_DSC: - this->tiling_method = method; - break; + this->tiling_method = method; + break; default: - set_error (_("Invalid tiling method `%d' specified " - "(valid methods are 0, 1, 2, or 3)."), method); - return 0; + set_error (_("Invalid tiling method `%d' specified " + "(valid methods are 0, 1, 2, or 3)."), method); + return 0; } this->tiling_exponent = exponent; - + return 1; } int fiasco_c_options_set_frame_pattern (fiasco_c_options_t *options, - const char *pattern) + const char *pattern) /* * Set `pattern' of input frames. * `pattern' has to be a sequence of the following @@ -201,10 +201,10 @@ fiasco_c_options_set_frame_pattern (fiasco_c_options_t *options, * * When coding video frames the prediction type of input frame N is determined * by reading `pattern' [N] (`pattern' is periodically extended). - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -226,49 +226,49 @@ fiasco_c_options_set_frame_pattern (fiasco_c_options_t *options, else { const char *str; - bool_t parse_error = NO; - int c = 0; - + bool_t parse_error = NO; + int c = 0; + for (str = pattern; *str && !parse_error; str++) - switch (*str) - { - case 'i': - case 'I': - case 'b': - case 'B': - case 'p': - case 'P': - break; - default: - c = *str; - parse_error = YES; - } + switch (*str) + { + case 'i': + case 'I': + case 'b': + case 'B': + case 'p': + case 'P': + break; + default: + c = *str; + parse_error = YES; + } if (parse_error) { - set_error (_("Frame type pattern contains invalid character `%c' " - "(choose I, B or P)."), c); - return 0; + set_error (_("Frame type pattern contains invalid character `%c' " + "(choose I, B or P)."), c); + return 0; } else { - Free (this->pattern); - this->pattern = strdup (pattern); + Free (this->pattern); + this->pattern = strdup (pattern); - return 1; + return 1; } } } int fiasco_c_options_set_basisfile (fiasco_c_options_t *options, - const char *filename) + const char *filename) /* * Set `filename' of FIASCO initial basis. - * + * * Return value: - * 1 on success (if the file is readable) - * 0 otherwise + * 1 on success (if the file is readable) + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -289,14 +289,14 @@ fiasco_c_options_set_basisfile (fiasco_c_options_t *options, FILE *file = open_file (filename, "FIASCO_DATA", READ_ACCESS); if (file) { - fclose (file); - return 1; + fclose (file); + return 1; } else { - set_error (_("Can't read basis file `%s'.\n%s."), filename, - get_system_error ()); - return 0; + set_error (_("Can't read basis file `%s'.\n%s."), filename, + get_system_error ()); + return 0; } */ return 1; } @@ -304,20 +304,20 @@ fiasco_c_options_set_basisfile (fiasco_c_options_t *options, int fiasco_c_options_set_chroma_quality (fiasco_c_options_t *options, - float quality_factor, - unsigned dictionary_size) + float quality_factor, + unsigned dictionary_size) /* * Set color compression parameters. * When coding chroma channels (Cb and Cr) * - approximation quality is given by `quality_factor' * `Y quality' and * - `dictionary_size' gives the number of dictionary elements. - * + * * If 'quality' <= 0 then the luminancy coding quality is also during * chroma channel coding. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -329,13 +329,13 @@ fiasco_c_options_set_chroma_quality (fiasco_c_options_t *options, else if (!dictionary_size) { set_error (_("Size of chroma compression dictionary has to be " - "a positive number.")); + "a positive number.")); return 0; } else if (quality_factor <= 0) { set_error (_("Quality of chroma channel compression has to be " - "positive value.")); + "positive value.")); return 0; } else @@ -349,32 +349,32 @@ fiasco_c_options_set_chroma_quality (fiasco_c_options_t *options, int fiasco_c_options_set_optimizations (fiasco_c_options_t *options, - unsigned min_block_level, - unsigned max_block_level, - unsigned max_elements, - unsigned dictionary_size, - unsigned optimization_level) + unsigned min_block_level, + unsigned max_block_level, + unsigned max_elements, + unsigned dictionary_size, + unsigned optimization_level) /* * Set various optimization parameters. * - During compression only image blocks of size * {`min_block_level', ... ,`max_block_level'} are considered. * The smaller this set of blocks is the faster the coder runs - * and the worse the image quality will be. + * and the worse the image quality will be. * - An individual approximation may use at most `max_elements' * elements of the dictionary which itself contains at most * `dictionary_size' elements. The smaller these values are - * the faster the coder runs and the worse the image quality will be. + * the faster the coder runs and the worse the image quality will be. * - `optimization_level' enables some additional low level optimizations. * 0: standard approximation method * 1: significantly increases the approximation quality, * running time is twice as high as with the standard method - * 2: hardly increases the approximation quality of method 1, + * 2: hardly increases the approximation quality of method 1, * running time is twice as high as with method 1 * (this method just remains for completeness) * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -391,7 +391,7 @@ fiasco_c_options_set_optimizations (fiasco_c_options_t *options, else if (!max_elements) { set_error (_("At least one dictionary element has to be used " - "in an approximation.")); + "in an approximation.")); return 0; } else if (max_block_level < 4) @@ -407,19 +407,19 @@ fiasco_c_options_set_optimizations (fiasco_c_options_t *options, else if (max_block_level < min_block_level) { set_error (_("Maximum block size has to be larger or " - "equal minimum block size.")); + "equal minimum block size.")); return 0; } else { - this->lc_min_level = min_block_level; - this->lc_max_level = max_block_level; - this->max_states = dictionary_size; - this->max_elements = max_elements; + this->lc_min_level = min_block_level; + this->lc_max_level = max_block_level; + this->max_states = dictionary_size; + this->max_elements = max_elements; this->second_domain_block = optimization_level > 0 ? YES : NO; this->check_for_overflow = optimization_level > 1 ? YES : NO; this->check_for_underflow = optimization_level > 1 ? YES : NO; - this->full_search = optimization_level > 1 ? YES : NO; + this->full_search = optimization_level > 1 ? YES : NO; return 1; } @@ -427,9 +427,9 @@ fiasco_c_options_set_optimizations (fiasco_c_options_t *options, int fiasco_c_options_set_prediction (fiasco_c_options_t *options, - int intra_prediction, - unsigned min_block_level, - unsigned max_block_level) + int intra_prediction, + unsigned min_block_level, + unsigned max_block_level) /* * Set minimum and maximum size of image block prediction to * `min_block_level' and `max_block_level'. @@ -438,8 +438,8 @@ fiasco_c_options_set_prediction (fiasco_c_options_t *options, * Prediction of intra frames is only used if `intra_prediction' != 0. * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -451,19 +451,19 @@ fiasco_c_options_set_prediction (fiasco_c_options_t *options, else if (max_block_level < 6) { set_error (_("Maximum prediction block size has to be " - "at least level 6")); + "at least level 6")); return 0; } else if (min_block_level < 6) { set_error (_("Minimum prediction block size has to be " - "at least level 6")); + "at least level 6")); return 0; } else if (max_block_level < min_block_level) { set_error (_("Maximum prediction block size has to be larger or " - "equal minimum block size.")); + "equal minimum block size.")); return 0; } else @@ -471,17 +471,17 @@ fiasco_c_options_set_prediction (fiasco_c_options_t *options, this->p_min_level = min_block_level; this->p_max_level = max_block_level; this->prediction = intra_prediction; - + return 1; } } int fiasco_c_options_set_video_param (fiasco_c_options_t *options, - unsigned frames_per_second, - int half_pixel_prediction, - int cross_B_search, - int B_as_past_ref) + unsigned frames_per_second, + int half_pixel_prediction, + int cross_B_search, + int B_as_past_ref) /* * Set various parameters used for video compensation. * 'frames_per_second' defines the frame rate which should be @@ -494,10 +494,10 @@ fiasco_c_options_set_video_param (fiasco_c_options_t *options, * exhaustive search (in the given search range) is used. * If 'B_as_past_ref' is not 0 then B frames are allowed to be used * for B frame predicion. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -508,10 +508,10 @@ fiasco_c_options_set_video_param (fiasco_c_options_t *options, } else { - this->fps = frames_per_second; + this->fps = frames_per_second; this->half_pixel_prediction = half_pixel_prediction; - this->cross_B_search = cross_B_search; - this->B_as_past_ref = B_as_past_ref; + this->cross_B_search = cross_B_search; + this->B_as_past_ref = B_as_past_ref; return 1; } @@ -519,20 +519,20 @@ fiasco_c_options_set_video_param (fiasco_c_options_t *options, int fiasco_c_options_set_quantization (fiasco_c_options_t *options, - unsigned mantissa, - fiasco_rpf_range_e range, - unsigned dc_mantissa, - fiasco_rpf_range_e dc_range) + unsigned mantissa, + fiasco_rpf_range_e range, + unsigned dc_mantissa, + fiasco_rpf_range_e dc_range) /* * Set accuracy of coefficients quantization. * DC coefficients (of the constant dictionary vector f(x,y) = 1) * are quantized to values of the interval [-`dc_range', `dc_range'] using * #`dc_mantissa' bits. All other quantized coefficients are quantized in * an analogous way using the parameters `range' and `mantissa'. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -544,46 +544,46 @@ fiasco_c_options_set_quantization (fiasco_c_options_t *options, else if (mantissa < 2 || mantissa > 8 || dc_mantissa < 2 || dc_mantissa > 8) { set_error (_("Number of RPF mantissa bits `%d', `%d' have to be in " - "the interval [2,8]."), mantissa, dc_mantissa); + "the interval [2,8]."), mantissa, dc_mantissa); return 0; } else { if ((range == FIASCO_RPF_RANGE_0_75 - || range == FIASCO_RPF_RANGE_1_00 - || range == FIASCO_RPF_RANGE_1_50 - || range == FIASCO_RPF_RANGE_2_00) - && - (dc_range == FIASCO_RPF_RANGE_0_75 - || dc_range == FIASCO_RPF_RANGE_1_00 - || dc_range == FIASCO_RPF_RANGE_1_50 - || dc_range == FIASCO_RPF_RANGE_2_00)) + || range == FIASCO_RPF_RANGE_1_00 + || range == FIASCO_RPF_RANGE_1_50 + || range == FIASCO_RPF_RANGE_2_00) + && + (dc_range == FIASCO_RPF_RANGE_0_75 + || dc_range == FIASCO_RPF_RANGE_1_00 + || dc_range == FIASCO_RPF_RANGE_1_50 + || dc_range == FIASCO_RPF_RANGE_2_00)) { - this->rpf_range = range; - this->dc_rpf_range = dc_range; - this->rpf_mantissa = mantissa; - this->dc_rpf_mantissa = dc_mantissa; + this->rpf_range = range; + this->dc_rpf_range = dc_range; + this->rpf_mantissa = mantissa; + this->dc_rpf_mantissa = dc_mantissa; - return 1; + return 1; } else { - set_error (_("Invalid RPF ranges `%d', `%d' specified."), - range, dc_range); - return 0; + set_error (_("Invalid RPF ranges `%d', `%d' specified."), + range, dc_range); + return 0; } } } int fiasco_c_options_set_progress_meter (fiasco_c_options_t *options, - fiasco_progress_e type) + fiasco_progress_e type) /* * Set type of progress meter. * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -597,12 +597,12 @@ fiasco_c_options_set_progress_meter (fiasco_c_options_t *options, case FIASCO_PROGRESS_BAR: case FIASCO_PROGRESS_PERCENT: case FIASCO_PROGRESS_NONE: - this->progress_meter = type; - break; + this->progress_meter = type; + break; default: - set_error (_("Invalid progress meter `%d' specified " - "(valid values are 0, 1, or 2)."), type); - return 0; + set_error (_("Invalid progress meter `%d' specified " + "(valid values are 0, 1, or 2)."), type); + return 0; } return 1; } @@ -611,10 +611,10 @@ int fiasco_c_options_set_smoothing (fiasco_c_options_t *options, int smoothing) /* * Define `smoothing'-percentage along partitioning borders. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -639,10 +639,10 @@ int fiasco_c_options_set_comment (fiasco_c_options_t *options, const char *comment) /* * Define `comment' of FIASCO stream. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -667,10 +667,10 @@ int fiasco_c_options_set_title (fiasco_c_options_t *options, const char *title) /* * Define `title' of FIASCO stream. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -698,7 +698,7 @@ cast_c_options (fiasco_c_options_t *options) * Check whether `options' is a valid object of type c_options_t. * * Return value: - * pointer to options struct on success + * pointer to options struct on success * NULL otherwise */ { @@ -707,8 +707,8 @@ cast_c_options (fiasco_c_options_t *options) { if (!streq (this->id, "COFIASCO")) { - set_error (_("Parameter `options' doesn't match required type.")); - return NULL; + set_error (_("Parameter `options' doesn't match required type.")); + return NULL; } } else @@ -721,7 +721,7 @@ cast_c_options (fiasco_c_options_t *options) /************************************************************************** *************************************************************************** - DECODER + DECODER *************************************************************************** **************************************************************************/ @@ -733,10 +733,10 @@ fiasco_d_options_new (void) * fill in default values. * * Return value: - * pointer to the new option structure + * pointer to the new option structure */ { - d_options_t *options = calloc (1, sizeof (d_options_t)); + d_options_t *options = calloc (1, sizeof (d_options_t)); fiasco_d_options_t *public = calloc (1, sizeof (fiasco_d_options_t)); if (!options || !public) @@ -744,21 +744,21 @@ fiasco_d_options_new (void) set_error (_("Out of memory.")); return NULL; } - public->private = options; - public->delete = fiasco_d_options_delete; + public->private = options; + public->delete = fiasco_d_options_delete; public->set_smoothing = fiasco_d_options_set_smoothing; public->set_magnification = fiasco_d_options_set_magnification; public->set_4_2_0_format = fiasco_d_options_set_4_2_0_format; - + strcpy (options->id, "DOFIASCO"); /* * Set default value of fiasco decoder options */ - options->smoothing = 70; + options->smoothing = 70; options->magnification = 0; options->image_format = FORMAT_4_4_4; - + return public; } @@ -771,14 +771,14 @@ fiasco_d_options_delete (fiasco_d_options_t *options) * No return value. * * Side effects: - * structure 'options' is discarded. + * structure 'options' is discarded. */ { d_options_t *this = cast_d_options (options); if (!this) return; - + Free (this); return; @@ -788,10 +788,10 @@ int fiasco_d_options_set_smoothing (fiasco_d_options_t *options, int smoothing) /* * Define `smoothing'-percentage along partitioning borders. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { d_options_t *this = (d_options_t *) cast_d_options (options); @@ -822,8 +822,8 @@ fiasco_d_options_set_magnification (fiasco_d_options_t *options, int level) * etc. * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { d_options_t *this = (d_options_t *) cast_d_options (options); @@ -843,10 +843,10 @@ int fiasco_d_options_set_4_2_0_format (fiasco_d_options_t *options, int format) /* * Set image format to 4:2:0 or 4:4:4. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { d_options_t *this = (d_options_t *) cast_d_options (options); @@ -869,18 +869,18 @@ cast_d_options (fiasco_d_options_t *options) * Check whether `options' is a valid object of type d_options_t. * * Return value: - * pointer to options struct on success + * pointer to options struct on success * NULL otherwise */ { d_options_t *this = (d_options_t *) options->private; - + if (this) { if (!streq (this->id, "DOFIASCO")) { - set_error (_("Parameter `options' doesn't match required type.")); - return NULL; + set_error (_("Parameter `options' doesn't match required type.")); + return NULL; } } else diff --git a/converter/other/fiasco/codec/options.h b/converter/other/fiasco/codec/options.h index 783c41ef..e39550f6 100644 --- a/converter/other/fiasco/codec/options.h +++ b/converter/other/fiasco/codec/options.h @@ -1,8 +1,8 @@ /* * options.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,49 +19,49 @@ typedef struct c_options { - char id [9]; - char *basis_name; - unsigned lc_min_level; - unsigned lc_max_level; - unsigned p_min_level; - unsigned p_max_level; - unsigned images_level; - unsigned max_states; - unsigned chroma_max_states; - unsigned max_elements; - unsigned tiling_exponent; + char id [9]; + char *basis_name; + unsigned lc_min_level; + unsigned lc_max_level; + unsigned p_min_level; + unsigned p_max_level; + unsigned images_level; + unsigned max_states; + unsigned chroma_max_states; + unsigned max_elements; + unsigned tiling_exponent; fiasco_tiling_e tiling_method; - char *id_domain_pool; - char *id_d_domain_pool; - char *id_rpf_model; - char *id_d_rpf_model; - unsigned rpf_mantissa; - real_t rpf_range; - unsigned dc_rpf_mantissa; + char *id_domain_pool; + char *id_d_domain_pool; + char *id_rpf_model; + char *id_d_rpf_model; + unsigned rpf_mantissa; + real_t rpf_range; + unsigned dc_rpf_mantissa; fiasco_rpf_range_e dc_rpf_range; - unsigned d_rpf_mantissa; + unsigned d_rpf_mantissa; fiasco_rpf_range_e d_rpf_range; - unsigned d_dc_rpf_mantissa; + unsigned d_dc_rpf_mantissa; fiasco_rpf_range_e d_dc_rpf_range; - real_t chroma_decrease; - bool_t prediction; - bool_t delta_domains; - bool_t normal_domains; - unsigned search_range; - unsigned fps; - char *pattern; - char *reference_filename; - bool_t half_pixel_prediction; - bool_t cross_B_search; - bool_t B_as_past_ref; - bool_t check_for_underflow; - bool_t check_for_overflow; - bool_t second_domain_block; - bool_t full_search; + real_t chroma_decrease; + bool_t prediction; + bool_t delta_domains; + bool_t normal_domains; + unsigned search_range; + unsigned fps; + char *pattern; + char *reference_filename; + bool_t half_pixel_prediction; + bool_t cross_B_search; + bool_t B_as_past_ref; + bool_t check_for_underflow; + bool_t check_for_overflow; + bool_t second_domain_block; + bool_t full_search; fiasco_progress_e progress_meter; - char *title; - char *comment; - unsigned smoothing; + char *title; + char *comment; + unsigned smoothing; } c_options_t; typedef struct d_options diff --git a/converter/other/fiasco/codec/prediction.c b/converter/other/fiasco/codec/prediction.c index c592baa5..c321391a 100644 --- a/converter/other/fiasco/codec/prediction.c +++ b/converter/other/fiasco/codec/prediction.c @@ -1,8 +1,8 @@ /* - * prediction.c: Range image prediction with MC or ND + * prediction.c: Range image prediction with MC or ND * - * Written by: Ullrich Hafner - * Michael Unger + * Written by: Ullrich Hafner + * Michael Unger * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -40,7 +40,7 @@ /***************************************************************************** - local variables + local variables *****************************************************************************/ @@ -55,7 +55,7 @@ typedef struct state_data real_t *ip_states_state [MAXLEVEL]; word_t tree [MAXLABELS]; - mv_t mv_tree [MAXLABELS]; + mv_t mv_tree [MAXLABELS]; word_t y_state [MAXLABELS]; byte_t y_column [MAXLABELS]; byte_t prediction [MAXLABELS]; @@ -70,49 +70,49 @@ typedef struct state_data /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static real_t nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, - range_t *range, wfa_t *wfa, coding_t *c); + range_t *range, wfa_t *wfa, coding_t *c); static real_t mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, - range_t *range, wfa_t *wfa, coding_t *c); + range_t *range, wfa_t *wfa, coding_t *c); static state_data_t * store_state_data (unsigned from, unsigned to, unsigned max_level, - wfa_t *wfa, coding_t *c); + wfa_t *wfa, coding_t *c); static void restore_state_data (unsigned from, unsigned to, unsigned max_level, - state_data_t *data, wfa_t *wfa, coding_t *c); + state_data_t *data, wfa_t *wfa, coding_t *c); /***************************************************************************** - public code + public code *****************************************************************************/ real_t predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, - coding_t *c, unsigned band, int y_state, unsigned states, - const tree_t *tree_model, const tree_t *p_tree_model, - const void *domain_model, const void *d_domain_model, - const void *coeff_model, const void *d_coeff_model) + coding_t *c, unsigned band, int y_state, unsigned states, + const tree_t *tree_model, const tree_t *p_tree_model, + const void *domain_model, const void *d_domain_model, + const void *coeff_model, const void *d_coeff_model) { - unsigned state; /* counter */ - void *rec_domain_model; /* domain model after recursion */ - void *rec_d_domain_model; /* p domain model after recursion */ - void *rec_coeff_model; /* coeff model after recursion */ - void *rec_d_coeff_model; /* d coeff model after recursion */ - tree_t rec_tree_model; /* tree_model after '' */ - tree_t rec_p_tree_model; /* p_tree_model after '' */ - unsigned rec_states; /* wfa->states after '' */ - real_t *rec_pixels; /* c->pixels after '' */ - state_data_t *rec_state_data; /* state_data struct after '' */ - real_t costs; /* current approximation costs */ - unsigned level; /* counter */ - state_data_t *sd; /* pointer to state_data field */ + unsigned state; /* counter */ + void *rec_domain_model; /* domain model after recursion */ + void *rec_d_domain_model; /* p domain model after recursion */ + void *rec_coeff_model; /* coeff model after recursion */ + void *rec_d_coeff_model; /* d coeff model after recursion */ + tree_t rec_tree_model; /* tree_model after '' */ + tree_t rec_p_tree_model; /* p_tree_model after '' */ + unsigned rec_states; /* wfa->states after '' */ + real_t *rec_pixels; /* c->pixels after '' */ + state_data_t *rec_state_data; /* state_data struct after '' */ + real_t costs; /* current approximation costs */ + unsigned level; /* counter */ + state_data_t *sd; /* pointer to state_data field */ /* * Store WFA data from state 'lc_states' to 'wfa->states' - 1 and @@ -127,7 +127,7 @@ predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, rec_states = wfa->states; rec_pixels = c->pixels; rec_state_data = store_state_data (states, rec_states - 1, - c->options.lc_max_level, wfa, c); + c->options.lc_max_level, wfa, c); /* * Restore probability models to the state before the recursive subdivision @@ -138,9 +138,9 @@ predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, c->p_tree = *p_tree_model; c->domain_pool->model = c->domain_pool->model_duplicate (domain_model); c->d_domain_pool->model = c->d_domain_pool->model_duplicate (d_domain_model); - c->coeff->model = c->coeff->model_duplicate (c->coeff, coeff_model); - c->d_coeff->model = c->d_coeff->model_duplicate (c->d_coeff, - d_coeff_model); + c->coeff->model = c->coeff->model_duplicate (c->coeff, coeff_model); + c->d_coeff->model = c->d_coeff->model_duplicate (c->d_coeff, + d_coeff_model); if (c->mt->frame_type == I_FRAME) costs = nd_prediction (max_costs, price, band, y_state, range, wfa, c); @@ -156,27 +156,27 @@ predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, */ for (state = states; state < rec_states; state++) { - sd = &rec_state_data [state - states]; - for (level = c->options.images_level + 1; - level <= c->options.lc_max_level; level++) - if (sd->ip_states_state [level] != NULL) - Free (sd->ip_states_state [level]); - if (sd->images_of_state != NULL) - Free (sd->images_of_state); - if (sd->inner_products != NULL) - Free (sd->inner_products); + sd = &rec_state_data [state - states]; + for (level = c->options.images_level + 1; + level <= c->options.lc_max_level; level++) + if (sd->ip_states_state [level] != NULL) + Free (sd->ip_states_state [level]); + if (sd->images_of_state != NULL) + Free (sd->images_of_state); + if (sd->inner_products != NULL) + Free (sd->inner_products); } if (states < rec_states) - Free (rec_state_data); + Free (rec_state_data); c->domain_pool->model_free (rec_domain_model); c->d_domain_pool->model_free (rec_d_domain_model); c->coeff->model_free (rec_coeff_model); c->d_coeff->model_free (rec_d_coeff_model); costs = (range->tree_bits + range->matrix_bits + range->weights_bits - + range->mv_tree_bits + range->mv_coord_bits - + range->nd_tree_bits + range->nd_weights_bits) * price - + range->err; + + range->mv_tree_bits + range->mv_coord_bits + + range->nd_tree_bits + range->nd_weights_bits) * price + + range->err; } else { @@ -198,9 +198,9 @@ predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, range->prediction = NO; if (wfa->states != states) - remove_states (states, wfa); + remove_states (states, wfa); restore_state_data (states, rec_states - 1, c->options.lc_max_level, - rec_state_data, wfa, c); + rec_state_data, wfa, c); costs = MAXCOSTS; } @@ -216,8 +216,8 @@ clear_norms_table (unsigned level, const wfa_info_t *wi, motion_t *mt) */ { unsigned range_size = wi->half_pixel - ? square (wi->search_range) - : square (2 * wi->search_range); + ? square (wi->search_range) + : square (2 * wi->search_range); if (level > wi->p_min_level) { @@ -236,34 +236,34 @@ update_norms_table (unsigned level, const wfa_info_t *wi, motion_t *mt) */ { unsigned range_size = wi->half_pixel - ? square (wi->search_range) - : square (2 * wi->search_range); + ? square (wi->search_range) + : square (2 * wi->search_range); if (level > wi->p_min_level) { - unsigned index; /* index of motion vector */ + unsigned index; /* index of motion vector */ for (index = 0; index < range_size; index++) - mt->mc_forward_norms [level][index] - += mt->mc_forward_norms [level - 1][index]; + mt->mc_forward_norms [level][index] + += mt->mc_forward_norms [level - 1][index]; if (mt->frame_type == B_FRAME) - for (index = 0; index < range_size; index++) - mt->mc_backward_norms [level][index] - += mt->mc_backward_norms [level - 1][index]; + for (index = 0; index < range_size; index++) + mt->mc_backward_norms [level][index] + += mt->mc_backward_norms [level - 1][index]; } } /***************************************************************************** - private code + private code *****************************************************************************/ static real_t mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, - range_t *range, wfa_t *wfa, coding_t *c) + range_t *range, wfa_t *wfa, coding_t *c) { - real_t costs; /* current approximation costs */ + real_t costs; /* current approximation costs */ range_t prange = *range; unsigned width = width_of_level (range->level); unsigned height = height_of_level (range->level); @@ -286,12 +286,12 @@ mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, costs = (prange.mv_tree_bits + prange.mv_coord_bits) * price; - if (costs < max_costs) /* motion vector not too expensive */ + if (costs < max_costs) /* motion vector not too expensive */ { - unsigned last_state; /* last WFA state before recursion */ - real_t *ipi [MAXSTATES]; /* inner products pointers */ + unsigned last_state; /* last WFA state before recursion */ + real_t *ipi [MAXSTATES]; /* inner products pointers */ unsigned state; - real_t mvt, mvc; + real_t mvt, mvc; c->pixels = Calloc (width * height, sizeof (real_t)); cut_to_bintree (c->pixels, mcpe, width, height, 0, 0, width, height); @@ -301,12 +301,12 @@ mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, */ last_state = wfa->states - 1; for (state = 0; state <= last_state; state++) - if (need_image (state, wfa)) - { - ipi [state] = c->ip_images_state[state]; - c->ip_images_state[state] - = Calloc (size_of_tree (c->products_level), sizeof (real_t)); - } + if (need_image (state, wfa)) + { + ipi [state] = c->ip_images_state[state]; + c->ip_images_state[state] + = Calloc (size_of_tree (c->products_level), sizeof (real_t)); + } mvc = prange.mv_coord_bits; mvt = prange.mv_tree_bits; @@ -322,42 +322,42 @@ mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, prange.nd_tree_bits = 0; compute_ip_images_state (prange.image, prange.address, prange.level, - 1, 0, wfa, c); + 1, 0, wfa, c); costs += subdivide (max_costs - costs, band, y_state, &prange, - wfa, c, NO, YES); + wfa, c, NO, YES); - if (costs < max_costs) /* use motion compensation */ + if (costs < max_costs) /* use motion compensation */ { - unsigned img, adr; /* temp. values */ - - img = range->image; - adr = range->address; - *range = prange; - range->image = img; - range->address = adr; - range->mv_coord_bits = mvc; - range->mv_tree_bits = mvt; - range->prediction = YES; - - for (state = last_state + 1; state < wfa->states; state++) - if (need_image (state, wfa)) - memset (c->ip_images_state [state], 0, - size_of_tree (c->products_level) * sizeof (real_t)); - - costs = (range->tree_bits + range->matrix_bits + range->weights_bits - + range->mv_tree_bits + range->mv_coord_bits - + range->nd_tree_bits + range->nd_weights_bits) * price - + range->err; + unsigned img, adr; /* temp. values */ + + img = range->image; + adr = range->address; + *range = prange; + range->image = img; + range->address = adr; + range->mv_coord_bits = mvc; + range->mv_tree_bits = mvt; + range->prediction = YES; + + for (state = last_state + 1; state < wfa->states; state++) + if (need_image (state, wfa)) + memset (c->ip_images_state [state], 0, + size_of_tree (c->products_level) * sizeof (real_t)); + + costs = (range->tree_bits + range->matrix_bits + range->weights_bits + + range->mv_tree_bits + range->mv_coord_bits + + range->nd_tree_bits + range->nd_weights_bits) * price + + range->err; } else - costs = MAXCOSTS; + costs = MAXCOSTS; for (state = 0; state <= last_state; state++) - if (need_image (state, wfa)) - { - Free (c->ip_images_state[state]); - c->ip_images_state[state] = ipi [state]; - } + if (need_image (state, wfa)) + { + Free (c->ip_images_state[state]); + c->ip_images_state[state] = ipi [state]; + } Free (c->pixels); } else @@ -370,9 +370,9 @@ mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, static real_t nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, - range_t *range, wfa_t *wfa, coding_t *c) + range_t *range, wfa_t *wfa, coding_t *c) { - real_t costs; /* current approximation costs */ + real_t costs; /* current approximation costs */ range_t lrange = *range; /* @@ -380,13 +380,13 @@ nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, */ { real_t x = get_ip_image_state (range->image, range->address, - range->level, 0, c); + range->level, 0, c); real_t y = get_ip_state_state (0, 0, range->level, c); real_t w = btor (rtob (x / y, c->coeff->dc_rpf), c->coeff->dc_rpf); word_t s [2] = {0, -1}; - lrange.into [0] = 0; - lrange.into [1] = NO_EDGE; + lrange.into [0] = 0; + lrange.into [1] = NO_EDGE; lrange.weight [0] = w; lrange.mv_coord_bits = 0; lrange.mv_tree_bits = 0; @@ -404,10 +404,10 @@ nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, if (costs < max_costs) { unsigned state; - range_t rrange; /* range: recursive subdivision */ - unsigned last_state; /* last WFA state before recursion */ - real_t *ipi [MAXSTATES]; /* inner products pointers */ - unsigned width = width_of_level (range->level); + range_t rrange; /* range: recursive subdivision */ + unsigned last_state; /* last WFA state before recursion */ + real_t *ipi [MAXSTATES]; /* inner products pointers */ + unsigned width = width_of_level (range->level); unsigned height = height_of_level (range->level); real_t *pixels; @@ -415,15 +415,15 @@ nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, * Generate difference image original - approximation */ { - unsigned n; - real_t *src, *dst; /* pointers to image data */ - real_t w = - lrange.weight [0] * c->images_of_state [0][0]; + unsigned n; + real_t *src, *dst; /* pointers to image data */ + real_t w = - lrange.weight [0] * c->images_of_state [0][0]; - src = c->pixels + range->address * size_of_level (range->level); - dst = c->pixels = pixels = Calloc (width * height, sizeof (real_t)); + src = c->pixels + range->address * size_of_level (range->level); + dst = c->pixels = pixels = Calloc (width * height, sizeof (real_t)); - for (n = width * height; n; n--) - *dst++ = *src++ + w; + for (n = width * height; n; n--) + *dst++ = *src++ + w; } /* @@ -442,56 +442,56 @@ nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, last_state = wfa->states - 1; for (state = 0; state <= last_state; state++) - if (need_image (state, wfa)) - { - ipi [state] = c->ip_images_state[state]; - c->ip_images_state[state] - = Calloc (size_of_tree (c->products_level), sizeof (real_t)); - } + if (need_image (state, wfa)) + { + ipi [state] = c->ip_images_state[state]; + c->ip_images_state[state] + = Calloc (size_of_tree (c->products_level), sizeof (real_t)); + } compute_ip_images_state (rrange.image, rrange.address, rrange.level, - 1, 0, wfa, c); + 1, 0, wfa, c); costs += subdivide (max_costs - costs, band, y_state, &rrange, wfa, c, - NO, YES); + NO, YES); Free (pixels); if (costs < max_costs && ischild (rrange.tree)) /* use prediction */ { - unsigned img, adr; - unsigned edge; - - img = range->image; - adr = range->address; - *range = rrange; - range->image = img; - range->address = adr; - range->nd_tree_bits += lrange.nd_tree_bits; - range->nd_weights_bits += lrange.weights_bits; - - for (edge = 0; isedge (lrange.into [edge]); edge++) - { - range->into [edge] = lrange.into [edge]; - range->weight [edge] = lrange.weight [edge]; - } - range->into [edge] = NO_EDGE; - range->prediction = edge; - - for (state = last_state + 1; state < wfa->states; state++) - if (need_image (state, wfa)) - memset (c->ip_images_state [state], 0, - size_of_tree (c->products_level) * sizeof (real_t)); + unsigned img, adr; + unsigned edge; + + img = range->image; + adr = range->address; + *range = rrange; + range->image = img; + range->address = adr; + range->nd_tree_bits += lrange.nd_tree_bits; + range->nd_weights_bits += lrange.weights_bits; + + for (edge = 0; isedge (lrange.into [edge]); edge++) + { + range->into [edge] = lrange.into [edge]; + range->weight [edge] = lrange.weight [edge]; + } + range->into [edge] = NO_EDGE; + range->prediction = edge; + + for (state = last_state + 1; state < wfa->states; state++) + if (need_image (state, wfa)) + memset (c->ip_images_state [state], 0, + size_of_tree (c->products_level) * sizeof (real_t)); } else - costs = MAXCOSTS; + costs = MAXCOSTS; for (state = 0; state <= last_state; state++) - if (need_image (state, wfa)) - { - Free (c->ip_images_state [state]); - c->ip_images_state [state] = ipi [state]; - } + if (need_image (state, wfa)) + { + Free (c->ip_images_state [state]); + c->ip_images_state [state] = ipi [state]; + } } else costs = MAXCOSTS; @@ -501,20 +501,20 @@ nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, static state_data_t * store_state_data (unsigned from, unsigned to, unsigned max_level, - wfa_t *wfa, coding_t *c) + wfa_t *wfa, coding_t *c) /* * Save and remove all states starting from state 'from'. * * Return value: - * pointer to array of state_data structs + * pointer to array of state_data structs */ { - state_data_t *data; /* array of savestates */ - state_data_t *sd; /* pointer to current savestates */ - unsigned state, label, level; + state_data_t *data; /* array of savestates */ + state_data_t *sd; /* pointer to current savestates */ + unsigned state, label, level; if (to < from) - return NULL; /* nothing to do */ + return NULL; /* nothing to do */ data = Calloc (to - from + 1, sizeof (state_data_t)); @@ -534,30 +534,30 @@ store_state_data (unsigned from, unsigned to, unsigned max_level, for (label = 0; label < MAXLABELS; label++) { - sd->tree [label] = wfa->tree [state][label]; - sd->y_state [label] = wfa->y_state [state][label]; - sd->y_column [label] = wfa->y_column [state][label]; - sd->mv_tree [label] = wfa->mv_tree [state][label]; - sd->x [label] = wfa->x [state][label]; - sd->y [label] = wfa->y [state][label]; - sd->prediction [label] = wfa->prediction [state][label]; - - memcpy (sd->weight [label], wfa->weight [state][label], - sizeof (real_t) * (MAXEDGES + 1)); - memcpy (sd->int_weight [label], wfa->int_weight [state][label], - sizeof (word_t) * (MAXEDGES + 1)); - memcpy (sd->into [label], wfa->into [state][label], - sizeof (word_t) * (MAXEDGES + 1)); - - wfa->into [state][label][0] = NO_EDGE; - wfa->tree [state][label] = RANGE; - wfa->y_state [state][label] = RANGE; + sd->tree [label] = wfa->tree [state][label]; + sd->y_state [label] = wfa->y_state [state][label]; + sd->y_column [label] = wfa->y_column [state][label]; + sd->mv_tree [label] = wfa->mv_tree [state][label]; + sd->x [label] = wfa->x [state][label]; + sd->y [label] = wfa->y [state][label]; + sd->prediction [label] = wfa->prediction [state][label]; + + memcpy (sd->weight [label], wfa->weight [state][label], + sizeof (real_t) * (MAXEDGES + 1)); + memcpy (sd->int_weight [label], wfa->int_weight [state][label], + sizeof (word_t) * (MAXEDGES + 1)); + memcpy (sd->into [label], wfa->into [state][label], + sizeof (word_t) * (MAXEDGES + 1)); + + wfa->into [state][label][0] = NO_EDGE; + wfa->tree [state][label] = RANGE; + wfa->y_state [state][label] = RANGE; } for (level = c->options.images_level + 1; level <= max_level; - level++) + level++) { - sd->ip_states_state [level] = c->ip_states_state [state][level]; - c->ip_states_state [state][level] = NULL; + sd->ip_states_state [level] = c->ip_states_state [state][level]; + c->ip_states_state [state][level] = NULL; } } @@ -566,18 +566,18 @@ store_state_data (unsigned from, unsigned to, unsigned max_level, static void restore_state_data (unsigned from, unsigned to, unsigned max_level, - state_data_t *data, wfa_t *wfa, coding_t *c) + state_data_t *data, wfa_t *wfa, coding_t *c) /* * Restore all state data starting from state 'from'. * * No return value. */ { - state_data_t *sd; /* pointer to state_data item */ - unsigned state, label, level; + state_data_t *sd; /* pointer to state_data item */ + unsigned state, label, level; if (to < from) - return; /* nothing to do */ + return; /* nothing to do */ for (state = from; state <= to; state++) { @@ -588,35 +588,35 @@ restore_state_data (unsigned from, unsigned to, unsigned max_level, wfa->domain_type [state] = sd->domain_type; if (c->images_of_state [state] != NULL) - Free (c->images_of_state [state]); + Free (c->images_of_state [state]); c->images_of_state [state] = sd->images_of_state; if (c->ip_images_state [state] != NULL) - Free (c->ip_images_state [state]); + Free (c->ip_images_state [state]); c->ip_images_state [state] = sd->inner_products; for (label = 0; label < MAXLABELS; label++) { - wfa->tree [state][label] = sd->tree [label]; - wfa->y_state [state][label] = sd->y_state [label]; - wfa->y_column [state][label] = sd->y_column [label]; - wfa->mv_tree [state][label] = sd->mv_tree [label]; - wfa->x [state][label] = sd->x [label]; - wfa->y [state][label] = sd->y [label]; - wfa->prediction [state][label] = sd->prediction [label]; - - memcpy (wfa->weight [state][label], sd->weight [label], - sizeof(real_t) * (MAXEDGES + 1)); - memcpy (wfa->int_weight [state][label], sd->int_weight [label], - sizeof(word_t) * (MAXEDGES + 1)); - memcpy (wfa->into [state][label], sd->into [label], - sizeof(word_t) * (MAXEDGES + 1)); + wfa->tree [state][label] = sd->tree [label]; + wfa->y_state [state][label] = sd->y_state [label]; + wfa->y_column [state][label] = sd->y_column [label]; + wfa->mv_tree [state][label] = sd->mv_tree [label]; + wfa->x [state][label] = sd->x [label]; + wfa->y [state][label] = sd->y [label]; + wfa->prediction [state][label] = sd->prediction [label]; + + memcpy (wfa->weight [state][label], sd->weight [label], + sizeof(real_t) * (MAXEDGES + 1)); + memcpy (wfa->int_weight [state][label], sd->int_weight [label], + sizeof(word_t) * (MAXEDGES + 1)); + memcpy (wfa->into [state][label], sd->into [label], + sizeof(word_t) * (MAXEDGES + 1)); } for (level = c->options.images_level + 1; level <= max_level; - level++) + level++) { - if (c->ip_states_state [state][level] != NULL) - Free (c->ip_states_state [state][level]); - c->ip_states_state [state][level] = sd->ip_states_state [level]; + if (c->ip_states_state [state][level] != NULL) + Free (c->ip_states_state [state][level]); + c->ip_states_state [state][level] = sd->ip_states_state [level]; } } diff --git a/converter/other/fiasco/codec/prediction.h b/converter/other/fiasco/codec/prediction.h index 0646dfd8..10b432b3 100644 --- a/converter/other/fiasco/codec/prediction.h +++ b/converter/other/fiasco/codec/prediction.h @@ -1,9 +1,9 @@ /* * prediction.h * - * Written by: Ullrich Hafner - * Michael Unger - * + * Written by: Ullrich Hafner + * Michael Unger + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -23,10 +23,10 @@ real_t predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, - coding_t *c, unsigned band, int y_state, unsigned states, - const tree_t *tree_model, const tree_t *p_tree_model, - const void *domain_model, const void *d_domain_model, - const void *coeff_model, const void *d_coeff_model); + coding_t *c, unsigned band, int y_state, unsigned states, + const tree_t *tree_model, const tree_t *p_tree_model, + const void *domain_model, const void *d_domain_model, + const void *coeff_model, const void *d_coeff_model); void update_norms_table (unsigned level, const wfa_info_t *wi, motion_t *mt); void diff --git a/converter/other/fiasco/codec/subdivide.c b/converter/other/fiasco/codec/subdivide.c index 3ddf1ffc..7eb951c0 100644 --- a/converter/other/fiasco/codec/subdivide.c +++ b/converter/other/fiasco/codec/subdivide.c @@ -1,7 +1,7 @@ /* - * subdivide.c: Recursive subdivision of range images + * subdivide.c: Recursive subdivision of range images * - * 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 @@ -41,27 +41,27 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, - const range_t *child, const int *y_state, - wfa_t *wfa, coding_t *c); + const range_t *child, const int *y_state, + wfa_t *wfa, coding_t *c); static void init_range (range_t *range, const image_t *image, unsigned band, - const wfa_t *wfa, coding_t *c); + const wfa_t *wfa, coding_t *c); /***************************************************************************** - public code + public code *****************************************************************************/ real_t subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, - wfa_t *wfa, coding_t *c, bool_t prediction, bool_t delta) + wfa_t *wfa, coding_t *c, bool_t prediction, bool_t delta) /* * Subdivide the current 'range' recursively and decide whether * a linear combination, a recursive subdivision, or a prediction is @@ -73,46 +73,46 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, * If 'delta' is TRUE then current range is already predicted. * * Return value: - * costs of the best approximation or MAXCOSTS if costs exceed 'max_costs' + * costs of the best approximation or MAXCOSTS if costs exceed 'max_costs' * * Side effects: - * 'range' factors and costs of linear combination are modified - * 'wfa' new transitions and prediction coefficients are added - * 'c' pixels and inner products are updated + * 'range' factors and costs of linear combination are modified + * 'wfa' new transitions and prediction coefficients are added + * 'c' pixels and inner products are updated */ { real_t subdivide_costs; /* Costs arising from approx. the current - range with two children */ + range with two children */ real_t lincomb_costs; /* Costs arising from approx. the current - range with a linear combination */ - int new_y_state [MAXLABELS]; /* Corresponding state of Y */ - real_t price; /* Approximation costs multiplier */ - bool_t try_mc; /* YES: try MC prediction */ - bool_t try_nd; /* YES: try ND prediction */ - unsigned states; /* Number of states before the - recursive subdivision starts */ - void *domain_model; /* copy of domain pool model */ - void *d_domain_model; /* copy of delta domain pool model */ - void *lc_domain_model; /* copy of domain pool model */ - void *lc_d_domain_model; /* copy of delta domain pool model */ - void *coeff_model; /* copy of coefficients model */ - void *d_coeff_model; /* copy of delta coefficients model */ - void *lc_coeff_model; /* copy of coefficients model */ - void *lc_d_coeff_model; /* copy of delta coefficients model */ - tree_t tree_model; /* copy of tree model */ - tree_t p_tree_model; /* copy of pred. tree model */ - range_t lrange; /* range of lin. comb. approx. */ - range_t rrange; /* range of recursive approx. */ - range_t child [MAXLABELS]; /* new children of the current range */ - static unsigned percent = 0; /* status of progress meter */ + range with a linear combination */ + int new_y_state [MAXLABELS]; /* Corresponding state of Y */ + real_t price; /* Approximation costs multiplier */ + bool_t try_mc; /* YES: try MC prediction */ + bool_t try_nd; /* YES: try ND prediction */ + unsigned states; /* Number of states before the + recursive subdivision starts */ + void *domain_model; /* copy of domain pool model */ + void *d_domain_model; /* copy of delta domain pool model */ + void *lc_domain_model; /* copy of domain pool model */ + void *lc_d_domain_model; /* copy of delta domain pool model */ + void *coeff_model; /* copy of coefficients model */ + void *d_coeff_model; /* copy of delta coefficients model */ + void *lc_coeff_model; /* copy of coefficients model */ + void *lc_d_coeff_model; /* copy of delta coefficients model */ + tree_t tree_model; /* copy of tree model */ + tree_t p_tree_model; /* copy of pred. tree model */ + range_t lrange; /* range of lin. comb. approx. */ + range_t rrange; /* range of recursive approx. */ + range_t child [MAXLABELS]; /* new children of the current range */ + static unsigned percent = 0; /* status of progress meter */ if (wfa->wfainfo->level == range->level) percent = 0; - range->into [0] = NO_EDGE; /* default approximation: empty */ + range->into [0] = NO_EDGE; /* default approximation: empty */ range->tree = RANGE; - if (range->level < 3) /* Don't process small ranges */ + if (range->level < 3) /* Don't process small ranges */ return MAXCOSTS; /* @@ -122,35 +122,35 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, if (c->tiling->exponent && range->level == wfa->wfainfo->level - c->tiling->exponent) { - unsigned width, height; /* size of range (dummies)*/ + unsigned width, height; /* size of range (dummies)*/ if (c->tiling->vorder [range->global_address] < 0) - return 0; /* nothing to do */ + return 0; /* nothing to do */ else - locate_subimage (wfa->wfainfo->level, range->level, - c->tiling->vorder [range->global_address], - &range->x, &range->y, &width, &height); + locate_subimage (wfa->wfainfo->level, range->level, + c->tiling->vorder [range->global_address], + &range->x, &range->y, &width, &height); } if (range->x >= c->mt->original->width || range->y >= c->mt->original->height) - return 0; /* range is not visible */ + return 0; /* range is not visible */ /* * Check whether prediction is allowed or not * mc == motion compensation, nd == nondeterminism */ try_mc = (prediction && c->mt->frame_type != I_FRAME - && range->level >= wfa->wfainfo->p_min_level - && range->level <= wfa->wfainfo->p_max_level - && (range->x + width_of_level (range->level) - <= c->mt->original->width) - && (range->y + height_of_level (range->level) - <= c->mt->original->height)); + && range->level >= wfa->wfainfo->p_min_level + && range->level <= wfa->wfainfo->p_max_level + && (range->x + width_of_level (range->level) + <= c->mt->original->width) + && (range->y + height_of_level (range->level) + <= c->mt->original->height)); try_nd = (prediction && c->mt->frame_type == I_FRAME - && range->level >= wfa->wfainfo->p_min_level - && range->level <= wfa->wfainfo->p_max_level); + && range->level >= wfa->wfainfo->p_min_level + && range->level <= wfa->wfainfo->p_max_level); if (try_mc) clear_norms_table (range->level, wfa->wfainfo, c->mt); @@ -171,15 +171,15 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, /* * Compute children of corresponding state in Y band */ - if (band != Y) /* Cb and Cr bands only */ + if (band != Y) /* Cb and Cr bands only */ { unsigned label; for (label = 0; label < MAXLABELS; label++) - if (ischild (y_state)) - new_y_state [label] = wfa->tree [y_state][label]; - else - new_y_state [label] = RANGE; + if (ischild (y_state)) + new_y_state [label] = wfa->tree [y_state][label]; + else + new_y_state [label] = RANGE; } else new_y_state [0] = new_y_state [1] = RANGE; @@ -210,13 +210,13 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, lrange.mv_coord_bits = 0; lrange.nd_tree_bits = 0; lrange.nd_weights_bits = 0; - lrange.prediction = NO; + lrange.prediction = NO; lincomb_costs - = approximate_range (max_costs, price, c->options.max_elements, - y_state, &lrange, - (delta ? c->d_domain_pool : c->domain_pool), - (delta ? c->d_coeff : c->coeff), wfa, c); + = approximate_range (max_costs, price, c->options.max_elements, + y_state, &lrange, + (delta ? c->d_domain_pool : c->domain_pool), + (delta ? c->d_coeff : c->coeff), wfa, c); } else lincomb_costs = MAXCOSTS; @@ -236,7 +236,7 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, c->d_domain_pool->model = c->d_domain_pool->model_duplicate (d_domain_model); c->coeff->model = c->coeff->model_duplicate (c->coeff, coeff_model); c->d_coeff->model = c->d_coeff->model_duplicate (c->d_coeff, - d_coeff_model); + d_coeff_model); /* * Second alternative of range approximation: @@ -256,122 +256,122 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, rrange.matrix_bits = 0; rrange.weights_bits = 0; rrange.err = 0; - rrange.mv_tree_bits = try_mc ? 1 : 0; /* mc allowed but not used */ + rrange.mv_tree_bits = try_mc ? 1 : 0; /* mc allowed but not used */ rrange.mv_coord_bits = 0; rrange.nd_tree_bits = try_nd ? - tree_bits (CHILD, lrange.level, &c->p_tree): 0; + tree_bits (CHILD, lrange.level, &c->p_tree): 0; rrange.nd_weights_bits = 0; - rrange.prediction = NO; + rrange.prediction = NO; /* * Initialize the cost function and subdivide the current range. * Every child is approximated by a recursive call of subdivide() */ subdivide_costs = (rrange.tree_bits + rrange.weights_bits - + rrange.matrix_bits + rrange.mv_tree_bits - + rrange.mv_coord_bits + rrange.nd_tree_bits - + rrange.nd_weights_bits) * price; + + rrange.matrix_bits + rrange.mv_tree_bits + + rrange.mv_coord_bits + rrange.nd_tree_bits + + rrange.nd_weights_bits) * price; for (label = 0; label < MAXLABELS; label++) { - real_t remaining_costs; /* upper limit for next recursion */ - - child[label].image = rrange.image * MAXLABELS + label + 1; - child[label].address = rrange.address * MAXLABELS + label; - child[label].global_address = rrange.global_address * MAXLABELS - + label; - child[label].level = rrange.level - 1; - child[label].x = rrange.level & 1 - ? rrange.x - : (rrange.x - + label * width_of_level (rrange.level - 1)); - child[label].y = rrange.level & 1 - ? (rrange.y - + label * height_of_level (rrange.level - 1)) - : rrange.y; - - /* - * If necessary compute the inner products of the new states - * (generated during the recursive approximation of child [0]) - */ - if (label && rrange.level <= c->options.lc_max_level) - compute_ip_images_state (child[label].image, child[label].address, - child[label].level, 1, states, wfa, c); - /* - * Call subdivide() for both children. - * Abort the recursion if 'subdivide_costs' exceed 'lincomb_costs' - * or 'max_costs'. - */ - remaining_costs = MIN(lincomb_costs, max_costs) - subdivide_costs; - - if (remaining_costs > 0) /* still a way for improvement */ - { - subdivide_costs += subdivide (remaining_costs, band, - new_y_state [label], &child [label], - wfa, c, prediction, delta); - } - else if (try_mc && child[label].level >= wfa->wfainfo->p_min_level) - { - fill_norms_table (child[label].x, child[label].y, - child[label].level, wfa->wfainfo, c->mt); - } - - if (try_mc) - update_norms_table (rrange.level, wfa->wfainfo, c->mt); - - /* - * Update of progress meter - */ - if (c->options.progress_meter != FIASCO_PROGRESS_NONE) - { - if (c->options.progress_meter == FIASCO_PROGRESS_PERCENT) - { - unsigned new_percent; /* new status of progress meter */ - - new_percent = (child[label].global_address + 1) * 100.0 - / (1 << (wfa->wfainfo->level - child[label].level)); - if (new_percent > percent) - { - percent = new_percent; - info ("%3d%% \r", percent); - } - } - else if (c->options.progress_meter == FIASCO_PROGRESS_BAR) - { - unsigned new_percent; /* new status of progress meter */ - - new_percent = (child[label].global_address + 1) * 50.0 - / (1 << (wfa->wfainfo->level - - child[label].level)); - for (; new_percent > percent; percent++) - { - info ("#"); - } - } - } - - /* - * If costs of subdivision exceed costs of linear combination - * then abort recursion. - */ - if (subdivide_costs >= MIN(lincomb_costs, max_costs)) - { - subdivide_costs = MAXCOSTS; - break; - } - rrange.err += child [label].err; - rrange.tree_bits += child [label].tree_bits; - rrange.matrix_bits += child [label].matrix_bits; - rrange.weights_bits += child [label].weights_bits; - rrange.mv_tree_bits += child [label].mv_tree_bits; - rrange.mv_coord_bits += child [label].mv_coord_bits; - rrange.nd_weights_bits += child [label].nd_weights_bits; - rrange.nd_tree_bits += child [label].nd_tree_bits; - - tree_update (ischild (child [label].tree) ? CHILD : LEAF, - child [label].level, &c->tree); - tree_update (child [label].prediction ? LEAF : CHILD, - child [label].level, &c->p_tree); + real_t remaining_costs; /* upper limit for next recursion */ + + child[label].image = rrange.image * MAXLABELS + label + 1; + child[label].address = rrange.address * MAXLABELS + label; + child[label].global_address = rrange.global_address * MAXLABELS + + label; + child[label].level = rrange.level - 1; + child[label].x = rrange.level & 1 + ? rrange.x + : (rrange.x + + label * width_of_level (rrange.level - 1)); + child[label].y = rrange.level & 1 + ? (rrange.y + + label * height_of_level (rrange.level - 1)) + : rrange.y; + + /* + * If necessary compute the inner products of the new states + * (generated during the recursive approximation of child [0]) + */ + if (label && rrange.level <= c->options.lc_max_level) + compute_ip_images_state (child[label].image, child[label].address, + child[label].level, 1, states, wfa, c); + /* + * Call subdivide() for both children. + * Abort the recursion if 'subdivide_costs' exceed 'lincomb_costs' + * or 'max_costs'. + */ + remaining_costs = MIN(lincomb_costs, max_costs) - subdivide_costs; + + if (remaining_costs > 0) /* still a way for improvement */ + { + subdivide_costs += subdivide (remaining_costs, band, + new_y_state [label], &child [label], + wfa, c, prediction, delta); + } + else if (try_mc && child[label].level >= wfa->wfainfo->p_min_level) + { + fill_norms_table (child[label].x, child[label].y, + child[label].level, wfa->wfainfo, c->mt); + } + + if (try_mc) + update_norms_table (rrange.level, wfa->wfainfo, c->mt); + + /* + * Update of progress meter + */ + if (c->options.progress_meter != FIASCO_PROGRESS_NONE) + { + if (c->options.progress_meter == FIASCO_PROGRESS_PERCENT) + { + unsigned new_percent; /* new status of progress meter */ + + new_percent = (child[label].global_address + 1) * 100.0 + / (1 << (wfa->wfainfo->level - child[label].level)); + if (new_percent > percent) + { + percent = new_percent; + info ("%3d%% \r", percent); + } + } + else if (c->options.progress_meter == FIASCO_PROGRESS_BAR) + { + unsigned new_percent; /* new status of progress meter */ + + new_percent = (child[label].global_address + 1) * 50.0 + / (1 << (wfa->wfainfo->level + - child[label].level)); + for (; new_percent > percent; percent++) + { + info ("#"); + } + } + } + + /* + * If costs of subdivision exceed costs of linear combination + * then abort recursion. + */ + if (subdivide_costs >= MIN(lincomb_costs, max_costs)) + { + subdivide_costs = MAXCOSTS; + break; + } + rrange.err += child [label].err; + rrange.tree_bits += child [label].tree_bits; + rrange.matrix_bits += child [label].matrix_bits; + rrange.weights_bits += child [label].weights_bits; + rrange.mv_tree_bits += child [label].mv_tree_bits; + rrange.mv_coord_bits += child [label].mv_coord_bits; + rrange.nd_weights_bits += child [label].nd_weights_bits; + rrange.nd_tree_bits += child [label].nd_tree_bits; + + tree_update (ischild (child [label].tree) ? CHILD : LEAF, + child [label].level, &c->tree); + tree_update (child [label].prediction ? LEAF : CHILD, + child [label].level, &c->p_tree); } } else @@ -382,9 +382,9 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, * Predict range via motion compensation or nondeterminism and * approximate delta image. */ - if (try_mc || try_nd) /* try prediction */ + if (try_mc || try_nd) /* try prediction */ { - real_t prediction_costs; /* Costs arising from approx. the current + real_t prediction_costs; /* Costs arising from approx. the current range with prediction */ prediction_costs @@ -393,7 +393,7 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, price, range, wfa, c, band, y_state, states, &tree_model, &p_tree_model, domain_model, d_domain_model, coeff_model, d_coeff_model); - if (prediction_costs < MAXCOSTS) /* prediction has smallest costs */ + if (prediction_costs < MAXCOSTS) /* prediction has smallest costs */ { c->domain_pool->model_free (domain_model); c->d_domain_pool->model_free (d_domain_model); @@ -426,13 +426,13 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, c->domain_pool->model = domain_model; c->d_domain_pool->model = d_domain_model; - c->coeff->model = coeff_model; - c->d_coeff->model = d_coeff_model; + c->coeff->model = coeff_model; + c->d_coeff->model = d_coeff_model; c->tree = tree_model; c->p_tree = p_tree_model; if (wfa->states != states) - remove_states (states, wfa); + remove_states (states, wfa); return MAXCOSTS; } @@ -455,15 +455,15 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, c->domain_pool->model = lc_domain_model; c->d_domain_pool->model = lc_d_domain_model; - c->coeff->model = lc_coeff_model; - c->d_coeff->model = lc_d_coeff_model; + c->coeff->model = lc_coeff_model; + c->d_coeff->model = lc_d_coeff_model; c->tree = tree_model; c->p_tree = p_tree_model; *range = lrange; if (wfa->states != states) - remove_states (states, wfa); + remove_states (states, wfa); return lincomb_costs; } @@ -478,15 +478,15 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, * - if state is (partially) outside image geometry */ if (band > Y - || (c->tiling->exponent - && rrange.level > wfa->wfainfo->level - c->tiling->exponent) - || (range->x + width_of_level (range->level) - > c->mt->original->width) - || (range->y + height_of_level (range->level) - > c->mt->original->height)) - init_new_state (YES, delta, &rrange, child, new_y_state, wfa, c); + || (c->tiling->exponent + && rrange.level > wfa->wfainfo->level - c->tiling->exponent) + || (range->x + width_of_level (range->level) + > c->mt->original->width) + || (range->y + height_of_level (range->level) + > c->mt->original->height)) + init_new_state (YES, delta, &rrange, child, new_y_state, wfa, c); else - init_new_state (NO, delta, &rrange, child, new_y_state, wfa, c); + init_new_state (NO, delta, &rrange, child, new_y_state, wfa, c); *range = rrange; @@ -505,8 +505,8 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, void cut_to_bintree (real_t *dst, const word_t *src, - unsigned src_width, unsigned src_height, - unsigned x0, unsigned y0, unsigned width, unsigned height) + unsigned src_width, unsigned src_height, + unsigned x0, unsigned y0, unsigned width, unsigned height) /* * Cut region ('x0', 'y0', 'width', 'height') of the pixel array 'src'. * Size of image is given by 'src_width' x 'src_height'. @@ -515,15 +515,15 @@ cut_to_bintree (real_t *dst, const word_t *src, * No return value. * * Side effects: - * 'dst []' is filled with corresponding region. + * 'dst []' is filled with corresponding region. */ { const unsigned mask01 = 0x555555; /* binary ...010101010101 */ const unsigned mask10 = 0xaaaaaa; /* binary ...101010101010 */ const unsigned mask01plus1 = mask01 + 1; /* binary ...010101010110 */ const unsigned mask10plus1 = mask10 + 1; /* binary ...101010101011 */ - unsigned x, y; /* pixel coordinates */ - unsigned xmask, ymask; /* address conversion */ + unsigned x, y; /* pixel coordinates */ + unsigned xmask, ymask; /* address conversion */ if (width != height && width != (height >> 1)) error ("Bintree cutting requires special type of images."); @@ -534,24 +534,24 @@ cut_to_bintree (real_t *dst, const word_t *src, xmask = 0; for (x = x0; x < x0 + width; x++, xmask = (xmask + mask01plus1) & mask10) { - if (y >= src_height || x >= src_width) - dst [xmask | ymask] = 0; - else - dst [xmask | ymask] = src [y * src_width + x] / 16; + if (y >= src_height || x >= src_width) + dst [xmask | ymask] = 0; + else + dst [xmask | ymask] = src [y * src_width + x] / 16; } } } /***************************************************************************** - private code + private code *****************************************************************************/ static void init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, - const range_t *child, const int *y_state, - wfa_t *wfa, coding_t *c) + const range_t *child, const int *y_state, + wfa_t *wfa, coding_t *c) /* * Initializes a new state with all parameters needed for the encoding step. * If flag 'auxiliary_state' is set then don't insert state into domain pools. @@ -563,7 +563,7 @@ init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, * No return value. * * Side effects: - * New state is appended to 'wfa' (and also its inner products and images + * New state is appended to 'wfa' (and also its inner products and images * are computed and stored in 'c') */ { @@ -573,13 +573,13 @@ init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, if (!auxiliary_state) { if (!delta || c->options.delta_domains) - state_is_domain = c->domain_pool->append (wfa->states, range->level, - wfa, c->domain_pool->model); + state_is_domain = c->domain_pool->append (wfa->states, range->level, + wfa, c->domain_pool->model); if (delta || c->options.normal_domains) - state_is_domain = c->d_domain_pool->append (wfa->states, range->level, - wfa, - c->d_domain_pool->model) - || state_is_domain; + state_is_domain = c->d_domain_pool->append (wfa->states, range->level, + wfa, + c->d_domain_pool->model) + || state_is_domain; } else state_is_domain = NO; @@ -597,7 +597,7 @@ init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, wfa->prediction [wfa->states][label] = child [label].prediction; append_transitions (wfa->states, label, child [label].weight, - child [label].into, wfa); + child [label].into, wfa); } wfa->delta_state [wfa->states] = delta; @@ -607,13 +607,13 @@ init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, /* state_is_domain = YES; */ append_state (!state_is_domain, - compute_final_distribution (wfa->states, wfa), - range->level, wfa, c); + compute_final_distribution (wfa->states, wfa), + range->level, wfa, c); } static void init_range (range_t *range, const image_t *image, unsigned band, - const wfa_t *wfa, coding_t *c) + const wfa_t *wfa, coding_t *c) /* * Read a new 'range' of the image 'image_name' (current color component * is 'band') and compute the new inner product arrays. @@ -621,9 +621,9 @@ init_range (range_t *range, const image_t *image, unsigned band, * No return value. * * Side effects: - * 'c->pixels' are filled with pixel values of image block - * 'c->ip_images_state' are computed with respect to new image block - * 'range->address' and 'range->image' are initialized with zero + * 'c->pixels' are filled with pixel values of image block + * 'c->ip_images_state' are computed with respect to new image block + * 'range->address' and 'range->image' are initialized with zero */ { unsigned state; @@ -633,13 +633,13 @@ init_range (range_t *range, const image_t *image, unsigned band, */ for (state = 0; state < wfa->states; state++) if (need_image (state, wfa)) - memset (c->ip_images_state[state], 0, - size_of_tree (c->products_level) * sizeof(real_t)); + memset (c->ip_images_state[state], 0, + size_of_tree (c->products_level) * sizeof(real_t)); cut_to_bintree (c->pixels, image->pixels [band], - image->width, image->height, - range->x, range->y, width_of_level (range->level), - height_of_level (range->level)); + image->width, image->height, + range->x, range->y, width_of_level (range->level), + height_of_level (range->level)); range->address = range->image = 0; compute_ip_images_state (0, 0, range->level, 1, 0, wfa, c); diff --git a/converter/other/fiasco/codec/subdivide.h b/converter/other/fiasco/codec/subdivide.h index bd9cd10e..dbd5620a 100644 --- a/converter/other/fiasco/codec/subdivide.h +++ b/converter/other/fiasco/codec/subdivide.h @@ -1,8 +1,8 @@ /* * subdivide.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,13 +20,13 @@ #include "types.h" #include "cwfa.h" -real_t +real_t subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, - wfa_t *wfa, coding_t *c, bool_t prediction, bool_t delta); + wfa_t *wfa, coding_t *c, bool_t prediction, bool_t delta); void cut_to_bintree (real_t *dst, const word_t *src, - unsigned src_width, unsigned src_height, - unsigned x0, unsigned y0, unsigned width, unsigned height); + unsigned src_width, unsigned src_height, + unsigned x0, unsigned y0, unsigned width, unsigned height); #endif /* not _SUBDIVIDE_H */ diff --git a/converter/other/fiasco/codec/tiling.c b/converter/other/fiasco/codec/tiling.c index 9af43da0..08423b24 100644 --- a/converter/other/fiasco/codec/tiling.c +++ b/converter/other/fiasco/codec/tiling.c @@ -1,8 +1,8 @@ /* - * tiling.c: Subimage permutation + * tiling.c: Subimage permutation + * + * 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 */ @@ -33,8 +33,8 @@ typedef struct var_list { - int address; /* bintree address */ - real_t variance; /* variance of tile */ + int address; /* bintree address */ + real_t variance; /* variance of tile */ } var_list_t; #ifndef LITERAL_FN_DEF_MATCH @@ -71,17 +71,17 @@ cmpdecvar(const void * const value1, tiling_t * alloc_tiling (fiasco_tiling_e method, unsigned tiling_exponent, - unsigned image_level) + unsigned image_level) /* * Image tiling constructor. * Allocate memory for the tiling_t structure. * `method' defines the tiling method (spiral or variance, * ascending or descending). * In case of invalid parameters, a structure with tiling.exponent == 0 is - * returned. + * returned. * * Return value - * pointer to the new tiling structure on success + * pointer to the new tiling structure on success */ { tiling_t *tiling = Calloc (1, sizeof (tiling_t)); @@ -90,21 +90,21 @@ alloc_tiling (fiasco_tiling_e method, unsigned tiling_exponent, { tiling_exponent = 6; warning (_("Image tiles must be at least 8x8 pixels large.\n" - "Setting tiling size to 8x8 pixels.")); + "Setting tiling size to 8x8 pixels.")); } - + switch (method) { case FIASCO_TILING_SPIRAL_ASC: case FIASCO_TILING_SPIRAL_DSC: case FIASCO_TILING_VARIANCE_ASC: case FIASCO_TILING_VARIANCE_DSC: - tiling_exponent = tiling_exponent; - break; + tiling_exponent = tiling_exponent; + break; default: - warning (_("Invalid tiling method specified. Disabling tiling.")); - tiling_exponent = 0; - break; + warning (_("Invalid tiling method specified. Disabling tiling.")); + tiling_exponent = 0; + break; } return tiling; @@ -119,7 +119,7 @@ free_tiling (tiling_t *tiling) * No return value. * * Side effects: - * structure 'tiling' is discarded. + * structure 'tiling' is discarded. */ { if (tiling->vorder) @@ -145,88 +145,88 @@ perform_tiling (const image_t *image, tiling_t *tiling) * No return value. * * Side effects: - * The tiling permutation is stored in 'tiling->vorder'. + * The tiling permutation is stored in 'tiling->vorder'. */ { if (tiling->exponent) { - unsigned tiles = 1 << tiling->exponent; /* number of image tiles */ - bool_t *tile_valid; /* tile i is in valid range ? */ - + unsigned tiles = 1 << tiling->exponent; /* number of image tiles */ + bool_t *tile_valid; /* tile i is in valid range ? */ + tiling->vorder = Calloc (tiles, sizeof (int)); tile_valid = Calloc (tiles, sizeof (bool_t)); if (tiling->method == FIASCO_TILING_VARIANCE_ASC - || tiling->method == FIASCO_TILING_VARIANCE_DSC) + || tiling->method == FIASCO_TILING_VARIANCE_DSC) { - unsigned address; /* bintree address of tile */ - unsigned number; /* number of image tiles */ - unsigned lx = log2 (image->width - 1) + 1; /* x level */ - unsigned ly = log2 (image->height - 1) + 1; /* y level */ - unsigned level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0); - var_list_t *var_list = Calloc (tiles, sizeof (var_list_t)); - - /* - * Compute variances of image tiles - */ - for (number = 0, address = 0; address < tiles; address++) - { - unsigned width, height; /* size of image tile */ - unsigned x0, y0; /* NW corner of image tile */ - - locate_subimage (level, level - tiling->exponent, address, - &x0, &y0, &width, &height); - if (x0 < image->width && y0 < image->height) /* valid range */ - { - if (x0 + width > image->width) /* outside image area */ - width = image->width - x0; - if (y0 + height > image->height) /* outside image area */ - height = image->height - y0; - - var_list [number].variance - = variance (image->pixels [GRAY], x0, y0, - width, height, image->width); - var_list [number].address = address; - number++; - tile_valid [address] = YES; - } - else - tile_valid [address] = NO; - } - - /* - * Sort image tiles according to sign of 'tiling->exp' - */ - if (tiling->method == FIASCO_TILING_VARIANCE_DSC) - qsort (var_list, number, sizeof (var_list_t), cmpdecvar); - else - qsort (var_list, number, sizeof (var_list_t), cmpincvar); - - for (number = 0, address = 0; address < tiles; address++) - if (tile_valid [address]) - { - tiling->vorder [address] = var_list [number].address; - number++; - debug_message ("tile number %d has original address %d", - number, tiling->vorder [address]); - } - else - tiling->vorder [address] = -1; - - Free (var_list); + unsigned address; /* bintree address of tile */ + unsigned number; /* number of image tiles */ + unsigned lx = log2 (image->width - 1) + 1; /* x level */ + unsigned ly = log2 (image->height - 1) + 1; /* y level */ + unsigned level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0); + var_list_t *var_list = Calloc (tiles, sizeof (var_list_t)); + + /* + * Compute variances of image tiles + */ + for (number = 0, address = 0; address < tiles; address++) + { + unsigned width, height; /* size of image tile */ + unsigned x0, y0; /* NW corner of image tile */ + + locate_subimage (level, level - tiling->exponent, address, + &x0, &y0, &width, &height); + if (x0 < image->width && y0 < image->height) /* valid range */ + { + if (x0 + width > image->width) /* outside image area */ + width = image->width - x0; + if (y0 + height > image->height) /* outside image area */ + height = image->height - y0; + + var_list [number].variance + = variance (image->pixels [GRAY], x0, y0, + width, height, image->width); + var_list [number].address = address; + number++; + tile_valid [address] = YES; + } + else + tile_valid [address] = NO; + } + + /* + * Sort image tiles according to sign of 'tiling->exp' + */ + if (tiling->method == FIASCO_TILING_VARIANCE_DSC) + qsort (var_list, number, sizeof (var_list_t), cmpdecvar); + else + qsort (var_list, number, sizeof (var_list_t), cmpincvar); + + for (number = 0, address = 0; address < tiles; address++) + if (tile_valid [address]) + { + tiling->vorder [address] = var_list [number].address; + number++; + debug_message ("tile number %d has original address %d", + number, tiling->vorder [address]); + } + else + tiling->vorder [address] = -1; + + Free (var_list); } else if (tiling->method == FIASCO_TILING_SPIRAL_DSC - || tiling->method == FIASCO_TILING_SPIRAL_ASC) + || tiling->method == FIASCO_TILING_SPIRAL_ASC) { - compute_spiral (tiling->vorder, image->width, image->height, - tiling->exponent, - tiling->method == FIASCO_TILING_SPIRAL_ASC); + compute_spiral (tiling->vorder, image->width, image->height, + tiling->exponent, + tiling->method == FIASCO_TILING_SPIRAL_ASC); } else { - warning ("We do not know the tiling method.\n" - "Skipping image tiling step."); - tiling->exponent = 0; + warning ("We do not know the tiling method.\n" + "Skipping image tiling step."); + tiling->exponent = 0; } } } diff --git a/converter/other/fiasco/codec/tiling.h b/converter/other/fiasco/codec/tiling.h index 6668ad8b..ef6d426d 100644 --- a/converter/other/fiasco/codec/tiling.h +++ b/converter/other/fiasco/codec/tiling.h @@ -1,8 +1,8 @@ /* * tiling.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,17 +22,17 @@ typedef struct tiling { - unsigned exponent; /* Image is split in 2^exp tiles */ - fiasco_tiling_e method; /* Method of Image tiling */ - int *vorder; /* Block permutation (size = 2^exp) - -1 indicates empty block */ + unsigned exponent; /* Image is split in 2^exp tiles */ + fiasco_tiling_e method; /* Method of Image tiling */ + int *vorder; /* Block permutation (size = 2^exp) + -1 indicates empty block */ } tiling_t; void perform_tiling (const image_t *image, tiling_t *tiling); tiling_t * alloc_tiling (fiasco_tiling_e method, unsigned tiling_exponent, - unsigned image_level); + unsigned image_level); void free_tiling (tiling_t *tiling); diff --git a/converter/other/fiasco/codec/wfa.h b/converter/other/fiasco/codec/wfa.h index 4e66ccbd..ae86d216 100644 --- a/converter/other/fiasco/codec/wfa.h +++ b/converter/other/fiasco/codec/wfa.h @@ -1,7 +1,7 @@ /* * wfa.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,38 +19,38 @@ #define MAXEDGES 5 #define MAXSTATES 6000 -#define MAXLABELS 2 /* only bintree possible anymore */ +#define MAXLABELS 2 /* only bintree possible anymore */ #define MAXLEVEL 22 #define FIASCO_BINFILE_RELEASE 2 -#define FIASCO_MAGIC "FIASCO" /* FIASCO magic number */ +#define FIASCO_MAGIC "FIASCO" /* FIASCO magic number */ #define FIASCO_BASIS_MAGIC "Fiasco" /* FIASCO initial basis */ -#define NO_EDGE -1 -#define RANGE -1 -#define NO_RANGE 0 +#define NO_EDGE -1 +#define RANGE -1 +#define NO_RANGE 0 -#define CHILD 1 -#define LEAF 0 +#define CHILD 1 +#define LEAF 0 -#define MAX_PROB 9 -#define MIN_PROB 1 +#define MAX_PROB 9 +#define MIN_PROB 1 /* * WFA state types: - * 0: state is not allowed to be used in an - * approximation and it's image is not needed - * for ip computations. - * AUXILIARY_MASK: state is required for computation of ip's but is not - * allowed to be used in an approximation. - * USE_DOMAIN_MASK: state is allowed to be used in an approximation. + * 0: state is not allowed to be used in an + * approximation and it's image is not needed + * for ip computations. + * AUXILIARY_MASK: state is required for computation of ip's but is not + * allowed to be used in an approximation. + * USE_DOMAIN_MASK: state is allowed to be used in an approximation. */ enum state_types {AUXILIARY_MASK = 1 << 0, USE_DOMAIN_MASK = 1 << 1}; -#define isedge(x) ((x) != NO_EDGE) -#define isdomain(x) ((x) != NO_EDGE) -#define isrange(x) ((x) == RANGE) -#define ischild(x) ((x) != RANGE) +#define isedge(x) ((x) != NO_EDGE) +#define isdomain(x) ((x) != NO_EDGE) +#define isrange(x) ((x) == RANGE) +#define ischild(x) ((x) != RANGE) #define isauxiliary(d,wfa) ((wfa)->domain_type[d] & AUXILIARY_MASK) #define usedomain(d, wfa) ((wfa)->domain_type[d] & USE_DOMAIN_MASK) #define need_image(d,wfa) (isauxiliary ((d), (wfa)) || usedomain ((d), (wfa))) @@ -64,15 +64,15 @@ typedef struct mv * Motion vector components */ { - mc_type_e type; /* motion compensation type */ - int fx, fy; /* forward vector coordinates */ - int bx, by; /* backward vector coordinates */ + mc_type_e type; /* motion compensation type */ + int fx, fy; /* forward vector coordinates */ + int bx, by; /* backward vector coordinates */ } mv_t; typedef struct range_info { - unsigned x, y; /* coordinates of upper left corner */ - unsigned level; /* bintree level of range */ + unsigned x, y; /* coordinates of upper left corner */ + unsigned level; /* bintree level of range */ } range_info_t; #include "image.h" @@ -81,32 +81,32 @@ typedef struct range_info typedef struct wfa_info { - char *wfa_name; /* filename of the WFA */ - char *basis_name; /* filename of the initial basis */ - char *title; /* title of FIASCO stream */ - char *comment; /* comment for FIASCO stream */ - - unsigned max_states; /* max. cardinality of domain pool */ - unsigned chroma_max_states; /* max. cardinality of domain pool for - chroma band coding */ - bool_t color; /* color image */ - unsigned width; /* image width */ - unsigned height; /* image height */ - unsigned level; /* image level */ - rpf_t *rpf; /* Standard reduced precision format */ - rpf_t *dc_rpf; /* DC reduced precision format */ - rpf_t *d_rpf; /* Delta reduced precision format */ - rpf_t *d_dc_rpf; /* Delta DC reduced precision format */ - unsigned frames; /* number of frames in the video */ - unsigned fps; /* number of frames per second */ - unsigned p_min_level; /* min. level of prediction */ - unsigned p_max_level; /* max. level of prediction */ - unsigned search_range; /* motion vector interval */ - bool_t half_pixel; /* usage of half pixel precision */ - bool_t cross_B_search; /* usage of Cross-B-Search */ - bool_t B_as_past_ref; /* usage of B frames as ref's */ - unsigned smoothing; /* smoothing of image along borders */ - unsigned release; /* FIASCO file format release */ + char *wfa_name; /* filename of the WFA */ + char *basis_name; /* filename of the initial basis */ + char *title; /* title of FIASCO stream */ + char *comment; /* comment for FIASCO stream */ + + unsigned max_states; /* max. cardinality of domain pool */ + unsigned chroma_max_states; /* max. cardinality of domain pool for + chroma band coding */ + bool_t color; /* color image */ + unsigned width; /* image width */ + unsigned height; /* image height */ + unsigned level; /* image level */ + rpf_t *rpf; /* Standard reduced precision format */ + rpf_t *dc_rpf; /* DC reduced precision format */ + rpf_t *d_rpf; /* Delta reduced precision format */ + rpf_t *d_dc_rpf; /* Delta DC reduced precision format */ + unsigned frames; /* number of frames in the video */ + unsigned fps; /* number of frames per second */ + unsigned p_min_level; /* min. level of prediction */ + unsigned p_max_level; /* max. level of prediction */ + unsigned search_range; /* motion vector interval */ + bool_t half_pixel; /* usage of half pixel precision */ + bool_t cross_B_search; /* usage of Cross-B-Search */ + bool_t B_as_past_ref; /* usage of B frames as ref's */ + unsigned smoothing; /* smoothing of image along borders */ + unsigned release; /* FIASCO file format release */ } wfa_info_t; typedef struct wfa @@ -114,27 +114,27 @@ typedef struct wfa * Used to store all information and data structures of a WFA */ { - wfa_info_t *wfainfo; /* misc. information about the WFA */ - frame_type_e frame_type; /* intra, predicted, bi-directional */ - unsigned states; /* number of states */ - unsigned basis_states; /* number of states in the basis */ - unsigned root_state; /* root of the tree */ - real_t *final_distribution; /* one pixel images */ - byte_t *level_of_state; /* level of the image part which is - represented by the current state */ - byte_t *domain_type; /* Bit_0==1: auxiliary state - Bit_1==1: used for Y compr */ - mv_t (*mv_tree)[MAXLABELS]; /* motion vectors */ - word_t (*tree)[MAXLABELS]; /* bintree partitioning */ - u_word_t (*x)[MAXLABELS]; /* range coordinate */ - u_word_t (*y)[MAXLABELS]; /* range coordinate */ - word_t (*into)[MAXLABELS][MAXEDGES + 1]; /* domain references */ - real_t (*weight)[MAXLABELS][MAXEDGES + 1]; /* lin.comb. coefficients */ - word_t (*int_weight)[MAXLABELS][MAXEDGES + 1]; /* bin. representation */ - word_t (*y_state)[MAXLABELS]; /* bintree of Y component */ - byte_t (*y_column)[MAXLABELS]; /* array for Y component references */ - byte_t (*prediction)[MAXLABELS]; /* DC prediction */ - bool_t (*delta_state); /* delta state */ + wfa_info_t *wfainfo; /* misc. information about the WFA */ + frame_type_e frame_type; /* intra, predicted, bi-directional */ + unsigned states; /* number of states */ + unsigned basis_states; /* number of states in the basis */ + unsigned root_state; /* root of the tree */ + real_t *final_distribution; /* one pixel images */ + byte_t *level_of_state; /* level of the image part which is + represented by the current state */ + byte_t *domain_type; /* Bit_0==1: auxiliary state + Bit_1==1: used for Y compr */ + mv_t (*mv_tree)[MAXLABELS]; /* motion vectors */ + word_t (*tree)[MAXLABELS]; /* bintree partitioning */ + u_word_t (*x)[MAXLABELS]; /* range coordinate */ + u_word_t (*y)[MAXLABELS]; /* range coordinate */ + word_t (*into)[MAXLABELS][MAXEDGES + 1]; /* domain references */ + real_t (*weight)[MAXLABELS][MAXEDGES + 1]; /* lin.comb. coefficients */ + word_t (*int_weight)[MAXLABELS][MAXEDGES + 1]; /* bin. representation */ + word_t (*y_state)[MAXLABELS]; /* bintree of Y component */ + byte_t (*y_column)[MAXLABELS]; /* array for Y component references */ + byte_t (*prediction)[MAXLABELS]; /* DC prediction */ + bool_t (*delta_state); /* delta state */ } wfa_t; #endif /* not _WFA_H */ diff --git a/converter/other/fiasco/codec/wfalib.c b/converter/other/fiasco/codec/wfalib.c index 90420d6f..fd73092f 100644 --- a/converter/other/fiasco/codec/wfalib.c +++ b/converter/other/fiasco/codec/wfalib.c @@ -1,8 +1,8 @@ /* - * wfalib.c: Library functions both for encoding and decoding + * wfalib.c: Library functions both for encoding 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 */ @@ -35,8 +35,8 @@ /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ static unsigned @@ -44,8 +44,8 @@ xy_to_address (unsigned x, unsigned y, unsigned level, unsigned n); /***************************************************************************** - public code - + public code + *****************************************************************************/ wfa_t * @@ -56,11 +56,11 @@ alloc_wfa (bool_t coding) * Flag 'coding' indicates whether WFA is used for coding or decoding. * * Return value: - * pointer to the new WFA structure + * pointer to the new WFA structure */ { wfa_t *wfa = Calloc (1, sizeof (wfa_t)); - + /* * Allocate memory */ @@ -74,17 +74,17 @@ alloc_wfa (bool_t coding) wfa->mv_tree = Calloc (MAXSTATES * MAXLABELS, sizeof (mv_t)); wfa->y_state = Calloc (MAXSTATES * MAXLABELS, sizeof (word_t)); wfa->into = Calloc (MAXSTATES * MAXLABELS * (MAXEDGES + 1), - sizeof (word_t)); + sizeof (word_t)); wfa->weight = Calloc (MAXSTATES * MAXLABELS * (MAXEDGES + 1), - sizeof (real_t)); + sizeof (real_t)); wfa->int_weight = Calloc (MAXSTATES * MAXLABELS * (MAXEDGES + 1), - sizeof (word_t)); + sizeof (word_t)); wfa->wfainfo = Calloc (1, sizeof (wfa_info_t));; wfa->prediction = Calloc (MAXSTATES * MAXLABELS, sizeof (byte_t)); wfa->wfainfo->wfa_name = NULL; wfa->wfainfo->basis_name = NULL; - wfa->wfainfo->title = strdup (""); + wfa->wfainfo->title = strdup (""); wfa->wfainfo->comment = strdup (""); /* @@ -96,24 +96,24 @@ alloc_wfa (bool_t coding) wfa->states = 0; wfa->basis_states = 0; wfa->root_state = 0; - for (state = 0; state < MAXSTATES; state++) + for (state = 0; state < MAXSTATES; state++) { - wfa->final_distribution [state] = 0; - wfa->domain_type [state] = 0; - for (label = 0; label < MAXLABELS; label++) - { - wfa->into [state][label][0] = NO_EDGE; - wfa->tree [state][label] = RANGE; - wfa->y_state [state][label] = RANGE; - } + wfa->final_distribution [state] = 0; + wfa->domain_type [state] = 0; + for (label = 0; label < MAXLABELS; label++) + { + wfa->into [state][label][0] = NO_EDGE; + wfa->tree [state][label] = RANGE; + wfa->y_state [state][label] = RANGE; + } } } - if (coding) /* initialize additional variables */ + if (coding) /* initialize additional variables */ wfa->y_column = Calloc (MAXSTATES * MAXLABELS, sizeof (byte_t)); else wfa->y_column = NULL; - + return wfa; } @@ -126,7 +126,7 @@ free_wfa (wfa_t *wfa) * No return value. * * Side effects: - * 'wfa' struct is discarded. + * 'wfa' struct is discarded. */ { if (wfa->wfainfo->wfa_name) @@ -157,14 +157,14 @@ free_wfa (wfa_t *wfa) Free (wfa); } -real_t +real_t compute_final_distribution (unsigned state, const wfa_t *wfa) /* * Compute the final distribution of the given 'state'. * Uses the fact that the generated 'wfa' is average preserving. * * Return value: - * final distribution + * final distribution */ { unsigned label; @@ -174,14 +174,14 @@ compute_final_distribution (unsigned state, const wfa_t *wfa) { unsigned edge; int domain; - + if (ischild (domain = wfa->tree [state][label])) - final += wfa->final_distribution [domain]; + final += wfa->final_distribution [domain]; for (edge = 0; isedge (domain = wfa->into [state][label][edge]); edge++) - final += wfa->weight [state][label][edge] - * wfa->final_distribution [domain]; + final += wfa->weight [state][label][edge] + * wfa->final_distribution [domain]; } - + return final / MAXLABELS; } @@ -193,10 +193,10 @@ compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa) * {i | 'from' <= i <= 'to'}. I.e. domains are in {i | from <= i < 'to'} * Always ensure that state 0 is among selected states even though from * may be > 0. - * + * * Return value: - * pointer to array of the most popular state images - * sorted by increasing state numbers and terminated by -1 + * pointer to array of the most popular state images + * sorted by increasing state numbers and terminated by -1 */ { word_t *domains; @@ -209,12 +209,12 @@ compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa) hits [domain].value = domain; hits [domain].key = 0; } - + for (state = from; state <= to; state++) for (label = 0; label < MAXLABELS; label++) - for (edge = 0; isedge (domain = wfa->into [state][label][edge]); - edge++) - hits [domain].key++; + for (edge = 0; isedge (domain = wfa->into [state][label][edge]); + edge++) + hits [domain].key++; qsort (hits + 1, to - 1, sizeof (pair_t), sort_desc_pair); @@ -222,23 +222,23 @@ compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa) domains = Calloc (n + 1, sizeof (word_t)); for (domain = 0; domain < (int) n && (!domain || hits [domain].key); - domain++) + domain++) domains [domain] = hits [domain].value; if (n != domain) debug_message ("Only %d domains have been used in the luminance.", - domain); + domain); n = domain; qsort (domains, n, sizeof (word_t), sort_asc_word); domains [n] = -1; - + Free (hits); - + return domains; } void append_edge (unsigned from, unsigned into, real_t weight, - unsigned label, wfa_t *wfa) + unsigned label, wfa_t *wfa) /* * Append an edge from state 'from' to state 'into' with * the given 'label' and 'weight' to the 'wfa'. @@ -246,10 +246,10 @@ append_edge (unsigned from, unsigned into, real_t weight, * No return value. * * Side effects: - * 'wfa' structure is changed. + * 'wfa' structure is changed. */ { - unsigned new; /* position of the new edge */ + unsigned new; /* position of the new edge */ unsigned edge; /* @@ -257,7 +257,7 @@ append_edge (unsigned from, unsigned into, real_t weight, * edges are sorted by increasing 'into' values */ for (new = 0; (isedge (wfa->into [from][label][new]) - && wfa->into [from][label][new] < (int) into); new++) + && wfa->into [from][label][new] < (int) into); new++) ; /* * Move the edges 'n' to position 'n+1', for n = max, ..., 'new' @@ -269,7 +269,7 @@ append_edge (unsigned from, unsigned into, real_t weight, wfa->into [from][label][edge] = wfa->into [from][label][edge - 1]; wfa->weight [from][label][edge] = wfa->weight [from][label][edge - 1]; wfa->int_weight [from][label][edge] - = wfa->int_weight [from][label][edge - 1]; + = wfa->int_weight [from][label][edge - 1]; } /* * Insert the new edge @@ -279,15 +279,15 @@ append_edge (unsigned from, unsigned into, real_t weight, wfa->int_weight [from][label][edge] = weight * 512 + 0.5; } -void +void remove_states (unsigned from, wfa_t *wfa) -/* +/* * Remove 'wfa' states 'wfa->basis_states',...,'wfa->states' - 1. * * No return value. * * Side effects: - * 'wfa' structure is cleared for the given states. + * 'wfa' structure is cleared for the given states. */ { unsigned state; @@ -295,18 +295,18 @@ remove_states (unsigned from, wfa_t *wfa) for (state = from; state < wfa->states; state++) { unsigned label; - - for (label = 0; label < MAXLABELS; label++) + + for (label = 0; label < MAXLABELS; label++) { - wfa->into [state][label][0] = NO_EDGE; - wfa->tree [state][label] = RANGE; - wfa->prediction [state][label] = FALSE; - wfa->y_state [state][label] = RANGE; - wfa->mv_tree [state][label].type = NONE; - wfa->mv_tree [state][label].fx = 0; - wfa->mv_tree [state][label].fy = 0; - wfa->mv_tree [state][label].bx = 0; - wfa->mv_tree [state][label].by = 0; + wfa->into [state][label][0] = NO_EDGE; + wfa->tree [state][label] = RANGE; + wfa->prediction [state][label] = FALSE; + wfa->y_state [state][label] = RANGE; + wfa->mv_tree [state][label].type = NONE; + wfa->mv_tree [state][label].fx = 0; + wfa->mv_tree [state][label].fy = 0; + wfa->mv_tree [state][label].bx = 0; + wfa->mv_tree [state][label].by = 0; } wfa->domain_type [state] = 0; wfa->delta_state [state] = FALSE; @@ -323,7 +323,7 @@ copy_wfa (wfa_t *dst, const wfa_t *src) * No return value. * * Side effects: - * 'dst' is filled with same data as 'src' + * 'dst' is filled with same data as 'src' * * NOTE: size of WFA 'dst' must be at least size of WFA 'src' */ @@ -339,11 +339,11 @@ copy_wfa (wfa_t *dst, const wfa_t *src) memset (dst->y, 0, MAXSTATES * MAXLABELS * sizeof (word_t)); memset (dst->y_state, 0, MAXSTATES * MAXLABELS * sizeof (word_t)); memset (dst->into, NO_EDGE, - MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); + MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); memset (dst->weight, 0, - MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (real_t)); + MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (real_t)); memset (dst->int_weight, 0, - MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); + MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); memset (dst->prediction, 0, MAXSTATES * MAXLABELS * sizeof (byte_t)); memset (dst->delta_state, 0, MAXSTATES * sizeof (bool_t)); if (dst->y_column) @@ -352,62 +352,62 @@ copy_wfa (wfa_t *dst, const wfa_t *src) for (state = 0; state < MAXSTATES; state++) /* clear WFA struct */ { unsigned label; - + for (label = 0; label < MAXLABELS; label++) { - dst->into [state][label][0] = NO_EDGE; - dst->tree [state][label] = RANGE; - dst->mv_tree [state][label].type = NONE; - dst->y_state[state][label] = RANGE; + dst->into [state][label][0] = NO_EDGE; + dst->tree [state][label] = RANGE; + dst->mv_tree [state][label].type = NONE; + dst->y_state[state][label] = RANGE; } dst->delta_state [state] = NO; dst->domain_type [state] = 0; } - + dst->frame_type = src->frame_type; - dst->states = src->states; + dst->states = src->states; dst->basis_states = src->basis_states; dst->root_state = src->root_state; memcpy (dst->wfainfo, src->wfainfo, sizeof (wfa_info_t)); - if (dst->states == 0) /* nothing to do */ + if (dst->states == 0) /* nothing to do */ return; memcpy (dst->final_distribution, src->final_distribution, - src->states * sizeof (real_t)); + src->states * sizeof (real_t)); memcpy (dst->level_of_state, src->level_of_state, - src->states * sizeof (byte_t)); + src->states * sizeof (byte_t)); memcpy (dst->domain_type, src->domain_type, - src->states * sizeof (byte_t)); + src->states * sizeof (byte_t)); memcpy (dst->delta_state, src->delta_state, - src->states * sizeof (bool_t)); + src->states * sizeof (bool_t)); memcpy (dst->mv_tree, src->mv_tree, - src->states * MAXLABELS * sizeof (mv_t)); + src->states * MAXLABELS * sizeof (mv_t)); memcpy (dst->tree, src->tree, - src->states * MAXLABELS * sizeof (word_t)); + src->states * MAXLABELS * sizeof (word_t)); memcpy (dst->x, src->x, - src->states * MAXLABELS * sizeof (word_t)); + src->states * MAXLABELS * sizeof (word_t)); memcpy (dst->y, src->y, - src->states * MAXLABELS * sizeof (word_t)); + src->states * MAXLABELS * sizeof (word_t)); memcpy (dst->y_state, src->y_state, - src->states * MAXLABELS * sizeof (word_t)); + src->states * MAXLABELS * sizeof (word_t)); memcpy (dst->into, src->into, - src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); + src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); memcpy (dst->weight, src->weight, - src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (real_t)); + src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (real_t)); memcpy (dst->int_weight, src->int_weight, - src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); + src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); memcpy (dst->prediction, src->prediction, - src->states * MAXLABELS * sizeof (byte_t)); + src->states * MAXLABELS * sizeof (byte_t)); if (dst->y_column) memcpy (dst->y_column, src->y_column, - src->states * MAXLABELS * sizeof (byte_t)); + src->states * MAXLABELS * sizeof (byte_t)); } void locate_subimage (unsigned orig_level, unsigned level, unsigned bintree, - unsigned *x, unsigned *y, unsigned *width, unsigned *height) + unsigned *x, unsigned *y, unsigned *width, unsigned *height) /* * Compute pixel coordinates of the subimage which 'bintree' address is given. * The level of the original image is 'orig_level' and the level of the @@ -416,14 +416,14 @@ locate_subimage (unsigned orig_level, unsigned level, unsigned bintree, * No return value. * * Side effects: - * '*x', '*y' coordinates of the upper left corner - * '*width', '*height' size of image + * '*x', '*y' coordinates of the upper left corner + * '*width', '*height' size of image */ { /* * Compute coordinates of the subimage */ - *x = *y = 0; /* start at NW corner */ + *x = *y = 0; /* start at NW corner */ *width = width_of_level (level); *height = height_of_level (level); @@ -439,31 +439,31 @@ locate_subimage (unsigned orig_level, unsigned level, unsigned bintree, } else if (level < orig_level) { - unsigned mask; /* mask for bintree -> xy conversion */ - bool_t hor; /* 1 next subdivision is horizontal - 0 next subdivision is vertical */ - unsigned l = orig_level - 1; /* current level */ - - hor = orig_level % 2; /* start with vertival subdivision - for square image and vice versa */ - + unsigned mask; /* mask for bintree -> xy conversion */ + bool_t hor; /* 1 next subdivision is horizontal + 0 next subdivision is vertical */ + unsigned l = orig_level - 1; /* current level */ + + hor = orig_level % 2; /* start with vertival subdivision + for square image and vice versa */ + for (mask = 1 << (orig_level - level - 1); mask; mask >>= 1, hor = !hor) { - if (bintree & mask) /* change coordinates */ - { - if (hor) /* horizontal subdivision */ - *y += height_of_level (l); - else /* vertical subdivision */ - *x += width_of_level (l); - } - l--; + if (bintree & mask) /* change coordinates */ + { + if (hor) /* horizontal subdivision */ + *y += height_of_level (l); + else /* vertical subdivision */ + *x += width_of_level (l); + } + l--; } } } void compute_spiral (int *vorder, unsigned image_width, unsigned image_height, - unsigned tiling_exp, bool_t inc_spiral) + unsigned tiling_exp, bool_t inc_spiral) /* * Compute image tiling with spiral order. * 'inc_spiral' specifies whether the spiral starts in the middle @@ -474,28 +474,28 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height, * No return value. * * Side effects: - * vorder[] is filled with tiling permutation + * vorder[] is filled with tiling permutation */ { - unsigned x, y; /* current position */ - unsigned xmin, xmax, ymin, ymax; /* boundaries for current line */ - unsigned width, height; /* offset for each tile */ - unsigned lx, ly, level; /* level x and y */ - unsigned tiles; /* total number of tiles */ - unsigned address; /* bintree address */ - + unsigned x, y; /* current position */ + unsigned xmin, xmax, ymin, ymax; /* boundaries for current line */ + unsigned width, height; /* offset for each tile */ + unsigned lx, ly, level; /* level x and y */ + unsigned tiles; /* total number of tiles */ + unsigned address; /* bintree address */ + lx = log2 (image_width - 1) + 1; ly = log2 (image_height - 1) + 1; level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0); - tiles = 1 << tiling_exp; /* Number of image tiles */ + tiles = 1 << tiling_exp; /* Number of image tiles */ width = width_of_level (level - tiling_exp); height = height_of_level (level - tiling_exp); for (address = 0; address < tiles; address++) { unsigned x0, y0, width, height; - + locate_subimage (level, level - tiling_exp, address, - &x0, &y0, &width, &height); + &x0, &y0, &width, &height); vorder [address] = (x0 < image_width && y0 < image_height) ? 0 : -1; } @@ -507,7 +507,7 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height, /* * 1234 - * CDE5 Traverse image in spiral order + * CDE5 Traverse image in spiral order * BGF6 starting at the top left corner * A987 */ @@ -515,59 +515,59 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height, { for (x = xmin, y = ymin; x < xmax; x += width) /* W>E */ { - while (vorder [address] == -1) - address++; - if (x < image_width && y < image_height) /* valid range */ - vorder [address++] = xy_to_address (x, y, level, tiling_exp); - while (address < tiles && vorder [address] == -1) - address++; + while (vorder [address] == -1) + address++; + if (x < image_width && y < image_height) /* valid range */ + vorder [address++] = xy_to_address (x, y, level, tiling_exp); + while (address < tiles && vorder [address] == -1) + address++; } ymin += height; if (address >= tiles) - break; - + break; + for (x = xmax - width, y = ymin; y < ymax; y += height) /* N>S */ { - while (vorder [address] == -1) - address++; - if (x <= image_width && y <= image_height) /* valid range */ - vorder [address++] = xy_to_address (x, y, level, tiling_exp); - while (address < tiles && vorder [address] == -1) - address++; + while (vorder [address] == -1) + address++; + if (x <= image_width && y <= image_height) /* valid range */ + vorder [address++] = xy_to_address (x, y, level, tiling_exp); + while (address < tiles && vorder [address] == -1) + address++; } xmax -= width; if (address >= tiles) - break; + break; for (x = xmax - width, y = ymax - width; x >= xmin; x -= width) /* E= tiles) - break; + break; - for (x = xmin, y = ymax - height; y >= ymin; y -= height) /* S>N */ + for (x = xmin, y = ymax - height; y >= ymin; y -= height) /* S>N */ { - while (vorder [address] == -1) - address++; - if (x <= image_width && y <= image_height) /* valid range */ - vorder [address++] = xy_to_address (x, y, level, tiling_exp); - while (address < tiles && vorder [address] == -1) - address++; + while (vorder [address] == -1) + address++; + if (x <= image_width && y <= image_height) /* valid range */ + vorder [address++] = xy_to_address (x, y, level, tiling_exp); + while (address < tiles && vorder [address] == -1) + address++; } xmin += width; - + if (address >= tiles) - break; + break; } if (inc_spiral) @@ -576,18 +576,18 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height, while (i < j) { - int tmp; - - while (vorder [i] == -1) - i++; - while (vorder [j] == -1) - j--; - - tmp = vorder [i]; - vorder [i] = vorder [j]; - vorder [j] = tmp; - i++; - j--; + int tmp; + + while (vorder [i] == -1) + i++; + while (vorder [j] == -1) + j--; + + tmp = vorder [i]; + vorder [i] = vorder [j]; + vorder [j] = tmp; + i++; + j--; } } /* @@ -595,109 +595,109 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height, */ { unsigned number; - + for (number = 0, address = 0; address < tiles; address++) - if (vorder [address] != -1) - debug_message ("number %d: address %d", - number++, vorder [address]); + if (vorder [address] != -1) + debug_message ("number %d: address %d", + number++, vorder [address]); } } bool_t find_range (unsigned x, unsigned y, unsigned band, - const wfa_t *wfa, unsigned *range_state, unsigned *range_label) + const wfa_t *wfa, unsigned *range_state, unsigned *range_label) /* * Find a range ('*range_state', '*range_label') that contains * pixel ('x', 'y') in the iven color 'band'. * * Return value: - * TRUE on success, or FALSE if there is no such range + * TRUE on success, or FALSE if there is no such range * * Side effects: - * '*range_state' and '*range_label' are modified on success. + * '*range_state' and '*range_label' are modified on success. */ { unsigned state, label; unsigned first_state, last_state; bool_t success = NO; - + first_state = wfa->basis_states; last_state = wfa->states; if (wfa->wfainfo->color) switch (band) { - case Y: - first_state = wfa->basis_states; - last_state = wfa->tree [wfa->tree [wfa->root_state][0]][0]; - break; - case Cb: - first_state = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; - last_state = wfa->tree [wfa->tree [wfa->root_state][0]][1]; - break; - case Cr: - first_state = wfa->tree [wfa->tree [wfa->root_state][0]][1] + 1; - last_state = wfa->states; - break; - default: - error ("unknown color component."); + case Y: + first_state = wfa->basis_states; + last_state = wfa->tree [wfa->tree [wfa->root_state][0]][0]; + break; + case Cb: + first_state = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; + last_state = wfa->tree [wfa->tree [wfa->root_state][0]][1]; + break; + case Cr: + first_state = wfa->tree [wfa->tree [wfa->root_state][0]][1] + 1; + last_state = wfa->states; + break; + default: + error ("unknown color component."); } for (state = first_state; state < last_state; state++) for (label = 0; label < MAXLABELS; label++) - if (isrange (wfa->tree [state][label])) - if (x >= wfa->x [state][label] && y >= wfa->y [state][label] - && x < (unsigned) (wfa->x [state][label] - + width_of_level (wfa->level_of_state [state] - 1)) - && y < (unsigned) (wfa->y [state][label] - + height_of_level (wfa->level_of_state [state] - 1))) - { - success = YES; - *range_state = state; - *range_label = label; - - return success; - } + if (isrange (wfa->tree [state][label])) + if (x >= wfa->x [state][label] && y >= wfa->y [state][label] + && x < (unsigned) (wfa->x [state][label] + + width_of_level (wfa->level_of_state [state] - 1)) + && y < (unsigned) (wfa->y [state][label] + + height_of_level (wfa->level_of_state [state] - 1))) + { + success = YES; + *range_state = state; + *range_label = label; + + return success; + } return success; } void sort_ranges (unsigned state, unsigned *domain, - range_sort_t *rs, const wfa_t *wfa) + range_sort_t *rs, const wfa_t *wfa) /* * Generate list of ranges in coder order. * 'state' is the current state of the call tree while 'domain' is the * index of the last added WFA state. * * Side effects: - * 'domain' is incremented after recursion returns - * 'rs' is filled accordingly + * 'domain' is incremented after recursion returns + * 'rs' is filled accordingly * * No return value. */ { unsigned label; - + for (label = 0; label < MAXLABELS; label++) { if (isrange (wfa->tree [state][label])) - rs->range_subdivided [rs->range_no] = NO; + rs->range_subdivided [rs->range_no] = NO; else { - sort_ranges (wfa->tree [state][label], domain, rs, wfa); - rs->range_subdivided [rs->range_no] = YES; + sort_ranges (wfa->tree [state][label], domain, rs, wfa); + rs->range_subdivided [rs->range_no] = YES; } rs->range_state [rs->range_no] = state; rs->range_label [rs->range_no] = label; rs->range_max_domain [rs->range_no] = *domain; while (!usedomain (rs->range_max_domain [rs->range_no], wfa)) - rs->range_max_domain [rs->range_no]--; + rs->range_max_domain [rs->range_no]--; if (label == 1 || !rs->range_subdivided [rs->range_no]) - rs->range_no++; + rs->range_no++; } - + (*domain)++; } @@ -709,11 +709,11 @@ locate_delta_images (wfa_t *wfa) * via MC or ND. * * Return value: - * TRUE at least one state is part of a delta approximation - * FALSE no delta approximations in this WFA + * TRUE at least one state is part of a delta approximation + * FALSE no delta approximations in this WFA * * Side effects: - * 'wfa->delta [state][label]' is set accordingly. + * 'wfa->delta [state][label]' is set accordingly. */ { unsigned state, label; @@ -724,22 +724,22 @@ locate_delta_images (wfa_t *wfa) for (state = wfa->root_state; state >= wfa->basis_states; state--) for (label = 0; label < MAXLABELS; label++) - if (ischild (wfa->tree [state][label])) - if (wfa->mv_tree [state][label].type != NONE - || isedge (wfa->into [state][label][0]) - || wfa->delta_state [state]) - { - delta = YES; - wfa->delta_state [wfa->tree [state][label]] = YES; - } + if (ischild (wfa->tree [state][label])) + if (wfa->mv_tree [state][label].type != NONE + || isedge (wfa->into [state][label][0]) + || wfa->delta_state [state]) + { + delta = YES; + wfa->delta_state [wfa->tree [state][label]] = YES; + } return delta; } /***************************************************************************** - private code - + private code + ******************************************************************************/ static unsigned @@ -750,25 +750,25 @@ xy_to_address (unsigned x, unsigned y, unsigned level, unsigned n) * 'n' specifies number of iterations. * * Return value: - * address of subimage - */ -{ + * address of subimage + */ +{ unsigned address = 0; while (n--) { address <<= 1; - if (--level % 2) + if (--level % 2) { - if (x & width_of_level (level)) - address++; + if (x & width_of_level (level)) + address++; } else { - if (y & height_of_level (level)) - address++; + if (y & height_of_level (level)) + address++; } } - + return address; } diff --git a/converter/other/fiasco/codec/wfalib.h b/converter/other/fiasco/codec/wfalib.h index 5c1e0907..63723f30 100644 --- a/converter/other/fiasco/codec/wfalib.h +++ b/converter/other/fiasco/codec/wfalib.h @@ -1,8 +1,8 @@ /* * wfalib.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 */ @@ -34,26 +34,26 @@ bool_t locate_delta_images (wfa_t *wfa); void sort_ranges (unsigned state, unsigned *domain, - range_sort_t *rs, const wfa_t *wfa); + range_sort_t *rs, const wfa_t *wfa); bool_t find_range (unsigned x, unsigned y, unsigned band, - const wfa_t *wfa, unsigned *range_state, unsigned *range_label); + const wfa_t *wfa, unsigned *range_state, unsigned *range_label); void compute_spiral (int *vorder, unsigned image_width, unsigned image_height, - unsigned tiling_exp, bool_t inc_spiral); + unsigned tiling_exp, bool_t inc_spiral); void locate_subimage (unsigned orig_level, unsigned level, unsigned bintree, - unsigned *x, unsigned *y, unsigned *width, unsigned *height); + unsigned *x, unsigned *y, unsigned *width, unsigned *height); void copy_wfa (wfa_t *dst, const wfa_t *src); -void +void remove_states (unsigned from, wfa_t *wfa); void append_edge (unsigned from, unsigned into, real_t weight, - unsigned label, wfa_t *wfa); + unsigned label, wfa_t *wfa); word_t * compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa); -real_t +real_t compute_final_distribution (unsigned state, const wfa_t *wfa); wfa_t * alloc_wfa (bool_t coding); -- cgit 1.4.1