diff --git a/src/library/tier1.c b/src/library/tier1.c index 77afacc..4e0f0ae 100755 --- a/src/library/tier1.c +++ b/src/library/tier1.c @@ -138,6 +138,37 @@ xi_v = SIG2XI[xi_v]; \ } +#define calc_k_mag(stripe, bit_mask, k, l, k_mag) \ +{ \ + k_mag = CONTEXT_MAG; \ + if(stripe[k].delta & bit_mask) \ + { \ + k_mag += 2; \ + } \ + else \ + { \ + if((bit_mask & (stripe[k].sigma >> 1)) || (bit_mask & (stripe[k].sigma << 1)) || \ + (stripe[k].stripe_l->sigma & bit_mask) || (stripe[k].stripe_r->sigma & bit_mask) || \ + (bit_mask & (stripe[k].stripe_l->sigma >> 1)) || (bit_mask & (stripe[k].stripe_l->sigma << 1)) || \ + (bit_mask & (stripe[k].stripe_r->sigma >> 1)) || (bit_mask & (stripe[k].stripe_r->sigma << 1))) \ + { \ + k_mag += 1; \ + } \ + else if((l == 3) && ((0x08 & (stripe[k].stripe_u->sigma << 3)) \ + || (0x08 & (stripe[k].stripe_u->stripe_l->sigma << 3)) \ + || (0x08 & (stripe[k].stripe_u->stripe_r->sigma << 3)))) \ + { \ + k_mag += 1; \ + } \ + else if((l == 0) && ((0x01 & (stripe[k].stripe_d->sigma >> 3)) \ + || (0x01 & (stripe[k].stripe_d->stripe_l->sigma >> 3)) \ + || (0x01 & (stripe[k].stripe_d->stripe_r->sigma >> 3)))) \ + { \ + k_mag += 1; \ + } \ + } \ +} + /************************************************************************************************************\ || ____ _ _ ___ ____ ____ _ _ ____ _ ____ ____ _ _ ____ ___ ____ _ _ ___ ____ || || |___ \/ | |___ |__/ |\ | |__| | | | | |\ | [__ | |__| |\ | | [__ || @@ -1192,34 +1223,7 @@ magnitude_refinement_enc_pass(bwc_coder *const coder, const int8 b) { if(sig & bit_mask) { - k_mag = CONTEXT_MAG; - - if(stripe[k].delta & bit_mask) - { - k_mag += 2; - } - else - { - if((bit_mask & (stripe[k].sigma >> 1)) || (bit_mask & (stripe[k].sigma << 1)) || - (stripe[k].stripe_l->sigma & bit_mask) || (stripe[k].stripe_r->sigma & bit_mask) || - (bit_mask & (stripe[k].stripe_l->sigma >> 1)) || (bit_mask & (stripe[k].stripe_l->sigma << 1)) || - (bit_mask & (stripe[k].stripe_r->sigma >> 1)) || (bit_mask & (stripe[k].stripe_r->sigma << 1))) - { - k_mag += 1; - } - else if((l == 3) && ((0x08 & (stripe[k].stripe_u->sigma << 3)) - || (0x08 & (stripe[k].stripe_u->stripe_l->sigma << 3)) - || (0x08 & (stripe[k].stripe_u->stripe_r->sigma << 3)))) - { - k_mag += 1; - } - else if((l == 0) && ((0x01 & (stripe[k].stripe_d->sigma >> 3)) - || (0x01 & (stripe[k].stripe_d->stripe_l->sigma >> 3)) - || (0x01 & (stripe[k].stripe_d->stripe_r->sigma >> 3)))) - { - k_mag += 1; - } - } + calc_k_mag(stripe, bit_mask, k, l, k_mag); mq_bit_encode(coder->bitcoder, (uchar)((bit >> l) & 0x01), k_mag); @@ -1240,28 +1244,7 @@ magnitude_refinement_enc_pass(bwc_coder *const coder, const int8 b) { if(sig & bit_mask) { - k_mag = CONTEXT_MAG; - - if(stripe[k].delta & bit_mask) - { - k_mag += 2; - } - else - { - if((bit_mask & (stripe[k].sigma >> 1)) || (bit_mask & (stripe[k].sigma << 1)) || - (stripe[k].stripe_l->sigma & bit_mask) || (stripe[k].stripe_r->sigma & bit_mask) || - (bit_mask & (stripe[k].stripe_l->sigma >> 1)) || (bit_mask & (stripe[k].stripe_l->sigma << 1)) || - (bit_mask & (stripe[k].stripe_r->sigma >> 1)) || (bit_mask & (stripe[k].stripe_r->sigma << 1))) - { - k_mag += 1; - } - else if((l == 3) && ((0x08 & (stripe[k].stripe_u->sigma << 3)) - || (0x08 & (stripe[k].stripe_u->stripe_l->sigma << 3)) - || (0x08 & (stripe[k].stripe_u->stripe_r->sigma << 3)))) - { - k_mag += 1; - } - } + calc_k_mag(stripe, bit_mask, k, l, k_mag); mq_bit_encode(coder->bitcoder, (uchar)((bit >> l) & 0x01), k_mag); @@ -1641,34 +1624,7 @@ magnitude_refinement_dec_pass(bwc_coder *const coder, const int8 b) { if(sig & bit_mask) { - k_mag = CONTEXT_MAG; - - if(stripe[k].delta & bit_mask) - { - k_mag += 2; - } - else - { - if((bit_mask & (stripe[k].sigma >> 1)) || (bit_mask & (stripe[k].sigma << 1)) || - (stripe[k].stripe_l->sigma & bit_mask) || (stripe[k].stripe_r->sigma & bit_mask) || - (bit_mask & (stripe[k].stripe_l->sigma >> 1)) || (bit_mask & (stripe[k].stripe_l->sigma << 1)) || - (bit_mask & (stripe[k].stripe_r->sigma >> 1)) || (bit_mask & (stripe[k].stripe_r->sigma << 1))) - { - k_mag += 1; - } - else if((l == 3) && ((0x08 & (stripe[k].stripe_u->sigma << 3)) - || (0x08 & (stripe[k].stripe_u->stripe_l->sigma << 3)) - || (0x08 & (stripe[k].stripe_u->stripe_r->sigma << 3)))) - { - k_mag += 1; - } - else if((l == 0) && ((0x01 & (stripe[k].stripe_d->sigma >> 3)) - || (0x01 & (stripe[k].stripe_d->stripe_l->sigma >> 3)) - || (0x01 & (stripe[k].stripe_d->stripe_r->sigma >> 3)))) - { - k_mag += 1; - } - } + calc_k_mag(stripe, bit_mask, k, l, k_mag); stripe[k].bit[b] |= (mq_bit_decode(coder->bitcoder, k_mag) << l); @@ -1688,28 +1644,7 @@ magnitude_refinement_dec_pass(bwc_coder *const coder, const int8 b) { if(sig & bit_mask) { - k_mag = CONTEXT_MAG; - - if(stripe[k].delta & bit_mask) - { - k_mag += 2; - } - else - { - if((bit_mask & (stripe[k].sigma >> 1)) || (bit_mask & (stripe[k].sigma << 1)) || - (stripe[k].stripe_l->sigma & bit_mask) || (stripe[k].stripe_r->sigma & bit_mask) || - (bit_mask & (stripe[k].stripe_l->sigma >> 1)) || (bit_mask & (stripe[k].stripe_l->sigma << 1)) || - (bit_mask & (stripe[k].stripe_r->sigma >> 1)) || (bit_mask & (stripe[k].stripe_r->sigma << 1))) - { - k_mag += 1; - } - else if((l == 3) && ((0x08 & (stripe[k].stripe_u->sigma << 3)) - || (0x08 & (stripe[k].stripe_u->stripe_l->sigma << 3)) - || (0x08 & (stripe[k].stripe_u->stripe_r->sigma << 3)))) - { - k_mag += 1; - } - } + calc_k_mag(stripe, bit_mask, k, l, k_mag); stripe[k].bit[b] |= (mq_bit_decode(coder->bitcoder, k_mag) << l);