refactor: move duplicated code into macro (k_sig)
This commit is contained in:
parent
d8e2e58862
commit
55921f7d9a
1 changed files with 35 additions and 144 deletions
|
@ -99,6 +99,27 @@
|
||||||
mq_bit_encode(bitcoder, 0, CONTEXT_UNI); \
|
mq_bit_encode(bitcoder, 0, CONTEXT_UNI); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define calc_k_sig(stripe, bit_mask, k, l, k_h, k_v, k_d, k_sig) \
|
||||||
|
{ \
|
||||||
|
k_h = (stripe[k].stripe_l->sigma & bit_mask) + (stripe[k].stripe_r->sigma & bit_mask); \
|
||||||
|
k_v = ((bit_mask & (stripe[k].sigma >> 1)) + (bit_mask & (stripe[k].sigma << 1))); \
|
||||||
|
k_d = ((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))); \
|
||||||
|
if(l == 3) \
|
||||||
|
{ \
|
||||||
|
k_v += ((0x01 & stripe[k].stripe_u->sigma) << 3); \
|
||||||
|
k_d += ((0x01 & stripe[k].stripe_u->stripe_l->sigma) + \
|
||||||
|
(0x01 & stripe[k].stripe_u->stripe_r->sigma)) << 3; \
|
||||||
|
} \
|
||||||
|
else if(l == 0) \
|
||||||
|
{ \
|
||||||
|
k_v += ((0x08 & stripe[k].stripe_d->sigma) >> 3); \
|
||||||
|
k_d += ((0x08 & stripe[k].stripe_d->stripe_l->sigma) + \
|
||||||
|
(0x08 & stripe[k].stripe_d->stripe_r->sigma)) >> 3; \
|
||||||
|
} \
|
||||||
|
k_sig = ((15 * k_h + 5 * k_v + k_d) >> l); \
|
||||||
|
}
|
||||||
|
|
||||||
/************************************************************************************************************\
|
/************************************************************************************************************\
|
||||||
|| ____ _ _ ___ ____ ____ _ _ ____ _ ____ ____ _ _ ____ ___ ____ _ _ ___ ____ ||
|
|| ____ _ _ ___ ____ ____ _ _ ____ _ ____ ____ _ _ ____ ___ ____ _ _ ___ ____ ||
|
||||||
|| |___ \/ | |___ |__/ |\ | |__| | | | | |\ | [__ | |__| |\ | | [__ ||
|
|| |___ \/ | |___ |__/ |\ | |__| | | | | |\ | [__ | |__| |\ | | [__ ||
|
||||||
|
@ -1004,27 +1025,7 @@ significance_propagation_enc_pass(bwc_coder *const coder, const int8 b)
|
||||||
{
|
{
|
||||||
if(!(stripe[k].sigma & bit_mask))
|
if(!(stripe[k].sigma & bit_mask))
|
||||||
{
|
{
|
||||||
k_h = (stripe[k].stripe_l->sigma & bit_mask) + (stripe[k].stripe_r->sigma & bit_mask);
|
calc_k_sig(stripe, bit_mask, k, l, k_h, k_v, k_d, k_sig);
|
||||||
|
|
||||||
k_v = ((bit_mask & (stripe[k].sigma >> 1)) + (bit_mask & (stripe[k].sigma << 1)));
|
|
||||||
|
|
||||||
k_d = ((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)));
|
|
||||||
|
|
||||||
if(l == 3)
|
|
||||||
{
|
|
||||||
k_v += ((0x01 & stripe[k].stripe_u->sigma) << 3);
|
|
||||||
k_d += ((0x01 & stripe[k].stripe_u->stripe_l->sigma) +
|
|
||||||
(0x01 & stripe[k].stripe_u->stripe_r->sigma)) << 3;
|
|
||||||
}
|
|
||||||
else if(l == 0)
|
|
||||||
{
|
|
||||||
k_v += ((0x08 & stripe[k].stripe_d->sigma) >> 3);
|
|
||||||
k_d += ((0x08 & stripe[k].stripe_d->stripe_l->sigma) +
|
|
||||||
(0x08 & stripe[k].stripe_d->stripe_r->sigma)) >> 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_sig = ((15 * k_h + 5 * k_v + k_d) >> l);
|
|
||||||
|
|
||||||
if(k_sig)
|
if(k_sig)
|
||||||
{
|
{
|
||||||
|
@ -1083,21 +1084,7 @@ significance_propagation_enc_pass(bwc_coder *const coder, const int8 b)
|
||||||
{
|
{
|
||||||
if(!(stripe[k].sigma & bit_mask))
|
if(!(stripe[k].sigma & bit_mask))
|
||||||
{
|
{
|
||||||
k_h = (stripe[k].stripe_l->sigma & bit_mask) + (stripe[k].stripe_r->sigma & bit_mask);
|
calc_k_sig(stripe, bit_mask, k, l, k_h, k_v, k_d, k_sig);
|
||||||
|
|
||||||
k_v = ((bit_mask & (stripe[k].sigma >> 1)) + (bit_mask & (stripe[k].sigma << 1)));
|
|
||||||
|
|
||||||
k_d = ((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)));
|
|
||||||
|
|
||||||
if(l == 3)
|
|
||||||
{
|
|
||||||
k_v += ((0x01 & stripe[k].stripe_u->sigma) << 3);
|
|
||||||
k_d += ((0x01 & stripe[k].stripe_u->stripe_l->sigma) +
|
|
||||||
(0x01 & stripe[k].stripe_u->stripe_r->sigma)) << 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_sig = ((15 * k_h + 5 * k_v + k_d) >> l);
|
|
||||||
|
|
||||||
if(k_sig && (stripe[k].sigma^bit_mask))
|
if(k_sig && (stripe[k].sigma^bit_mask))
|
||||||
{
|
{
|
||||||
|
@ -1338,6 +1325,7 @@ cleanup_enc_pass(bwc_coder *const coder, const int8 b)
|
||||||
uint64 k, x;
|
uint64 k, x;
|
||||||
int64 mse;
|
int64 mse;
|
||||||
uint16 k_h, k_v, k_d;
|
uint16 k_h, k_v, k_d;
|
||||||
|
uint16 k_sig;
|
||||||
uint16 xi_h, xi_v;
|
uint16 xi_h, xi_v;
|
||||||
uint8 bit_mask, l;
|
uint8 bit_mask, l;
|
||||||
uint8 dist_shift, dist_corr;
|
uint8 dist_shift, dist_corr;
|
||||||
|
@ -1403,27 +1391,8 @@ cleanup_enc_pass(bwc_coder *const coder, const int8 b)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
k_h = (stripe[k].stripe_l->sigma & bit_mask) + (stripe[k].stripe_r->sigma & bit_mask);
|
calc_k_sig(stripe, bit_mask, k, l, k_h, k_v, k_d, k_sig);
|
||||||
|
mq_bit_encode(coder->bitcoder, (uchar)((bit >> l) & 0x01), coder->sig2context[k_sig]);
|
||||||
k_v = ((bit_mask & (stripe[k].sigma >> 1)) + (bit_mask & (stripe[k].sigma << 1)));
|
|
||||||
|
|
||||||
k_d = ((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)));
|
|
||||||
|
|
||||||
if(l == 3)
|
|
||||||
{
|
|
||||||
k_v += ((0x01 & stripe[k].stripe_u->sigma) << 3);
|
|
||||||
k_d += ((0x01 & stripe[k].stripe_u->stripe_l->sigma) +
|
|
||||||
(0x01 & stripe[k].stripe_u->stripe_r->sigma)) << 3;
|
|
||||||
}
|
|
||||||
else if(l == 0)
|
|
||||||
{
|
|
||||||
k_v += ((0x08 & stripe[k].stripe_d->sigma) >> 3);
|
|
||||||
k_d += ((0x08 & stripe[k].stripe_d->stripe_l->sigma) +
|
|
||||||
(0x08 & stripe[k].stripe_d->stripe_r->sigma)) >> 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
mq_bit_encode(coder->bitcoder, (uchar)((bit >> l) & 0x01), coder->sig2context[(15 * k_h + 5 * k_v + k_d) >> l]);
|
|
||||||
}
|
}
|
||||||
if(bit & bit_mask)
|
if(bit & bit_mask)
|
||||||
{
|
{
|
||||||
|
@ -1464,21 +1433,8 @@ cleanup_enc_pass(bwc_coder *const coder, const int8 b)
|
||||||
{
|
{
|
||||||
if(!(stripe[k].sigma & bit_mask) && !(stripe[k].pi & bit_mask))
|
if(!(stripe[k].sigma & bit_mask) && !(stripe[k].pi & bit_mask))
|
||||||
{
|
{
|
||||||
k_h = (stripe[k].stripe_l->sigma & bit_mask) + (stripe[k].stripe_r->sigma & bit_mask);
|
calc_k_sig(stripe, bit_mask, k, l, k_h, k_v, k_d, k_sig);
|
||||||
|
mq_bit_encode(coder->bitcoder, (uchar)((bit >> l) & 0x01), coder->sig2context[k_sig]);
|
||||||
k_v = ((bit_mask & (stripe[k].sigma >> 1)) + (bit_mask & (stripe[k].sigma << 1)));
|
|
||||||
|
|
||||||
k_d = ((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)));
|
|
||||||
|
|
||||||
if(l == 3)
|
|
||||||
{
|
|
||||||
k_v += ((0x01 & stripe[k].stripe_u->sigma) << 3);
|
|
||||||
k_d += ((0x01 & stripe[k].stripe_u->stripe_l->sigma) +
|
|
||||||
(0x01 & stripe[k].stripe_u->stripe_r->sigma)) << 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
mq_bit_encode(coder->bitcoder, (uchar)((bit >> l) & 0x01), coder->sig2context[(15 * k_h + 5 * k_v + k_d) >> l]);
|
|
||||||
|
|
||||||
if(bit & bit_mask)
|
if(bit & bit_mask)
|
||||||
{
|
{
|
||||||
|
@ -1581,27 +1537,7 @@ significance_propagation_dec_pass(bwc_coder *const coder, const int8 b)
|
||||||
{
|
{
|
||||||
if(!(stripe[k].sigma & bit_mask))
|
if(!(stripe[k].sigma & bit_mask))
|
||||||
{
|
{
|
||||||
k_h = (stripe[k].stripe_l->sigma & bit_mask) + (stripe[k].stripe_r->sigma & bit_mask);
|
calc_k_sig(stripe, bit_mask, k, l, k_h, k_v, k_d, k_sig);
|
||||||
|
|
||||||
k_v = ((bit_mask & (stripe[k].sigma >> 1)) + (bit_mask & (stripe[k].sigma << 1)));
|
|
||||||
|
|
||||||
k_d = ((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)));
|
|
||||||
|
|
||||||
if(l == 3)
|
|
||||||
{
|
|
||||||
k_v += ((0x01 & stripe[k].stripe_u->sigma) << 3);
|
|
||||||
k_d += ((0x01 & stripe[k].stripe_u->stripe_l->sigma) +
|
|
||||||
(0x01 & stripe[k].stripe_u->stripe_r->sigma)) << 3;
|
|
||||||
}
|
|
||||||
else if(l == 0)
|
|
||||||
{
|
|
||||||
k_v += ((0x08 & stripe[k].stripe_d->sigma) >> 3);
|
|
||||||
k_d += ((0x08 & stripe[k].stripe_d->stripe_l->sigma) +
|
|
||||||
(0x08 & stripe[k].stripe_d->stripe_r->sigma)) >> 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_sig = ((15 * k_h + 5 * k_v + k_d) >> l);
|
|
||||||
|
|
||||||
if(k_sig)
|
if(k_sig)
|
||||||
{
|
{
|
||||||
|
@ -1660,21 +1596,7 @@ significance_propagation_dec_pass(bwc_coder *const coder, const int8 b)
|
||||||
{
|
{
|
||||||
if(!(stripe[k].sigma & bit_mask))
|
if(!(stripe[k].sigma & bit_mask))
|
||||||
{
|
{
|
||||||
k_h = (stripe[k].stripe_l->sigma & bit_mask) + (stripe[k].stripe_r->sigma & bit_mask);
|
calc_k_sig(stripe, bit_mask, k, l, k_h, k_v, k_d, k_sig);
|
||||||
|
|
||||||
k_v = ((bit_mask & (stripe[k].sigma >> 1)) + (bit_mask & (stripe[k].sigma << 1)));
|
|
||||||
|
|
||||||
k_d = ((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)));
|
|
||||||
|
|
||||||
if(l == 3)
|
|
||||||
{
|
|
||||||
k_v += ((0x01 & stripe[k].stripe_u->sigma) << 3);
|
|
||||||
k_d += ((0x01 & stripe[k].stripe_u->stripe_l->sigma) +
|
|
||||||
(0x01 & stripe[k].stripe_u->stripe_r->sigma)) << 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_sig = ((15 * k_h + 5 * k_v + k_d) >> l);
|
|
||||||
|
|
||||||
if(k_sig && (stripe[k].sigma^bit_mask))
|
if(k_sig && (stripe[k].sigma^bit_mask))
|
||||||
{
|
{
|
||||||
|
@ -1906,6 +1828,7 @@ cleanup_dec_pass(bwc_coder *const coder, const int8 b)
|
||||||
uint64 i, j;
|
uint64 i, j;
|
||||||
uint64 k, x;
|
uint64 k, x;
|
||||||
uint16 k_h, k_v, k_d;
|
uint16 k_h, k_v, k_d;
|
||||||
|
uint16 k_sig;
|
||||||
uint16 xi_h, xi_v;
|
uint16 xi_h, xi_v;
|
||||||
uint8 bit_mask, l;
|
uint8 bit_mask, l;
|
||||||
uint8 bit;
|
uint8 bit;
|
||||||
|
@ -1962,27 +1885,8 @@ cleanup_dec_pass(bwc_coder *const coder, const int8 b)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
k_h = (stripe[k].stripe_l->sigma & bit_mask) + (stripe[k].stripe_r->sigma & bit_mask);
|
calc_k_sig(stripe, bit_mask, k, l, k_h, k_v, k_d, k_sig);
|
||||||
|
bit |= (mq_bit_decode(coder->bitcoder, coder->sig2context[k_sig]) << l);
|
||||||
k_v = ((bit_mask & (stripe[k].sigma >> 1)) + (bit_mask & (stripe[k].sigma << 1)));
|
|
||||||
|
|
||||||
k_d = ((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)));
|
|
||||||
|
|
||||||
if(l == 3)
|
|
||||||
{
|
|
||||||
k_v += ((0x01 & stripe[k].stripe_u->sigma) << 3);
|
|
||||||
k_d += ((0x01 & stripe[k].stripe_u->stripe_l->sigma) +
|
|
||||||
(0x01 & stripe[k].stripe_u->stripe_r->sigma)) << 3;
|
|
||||||
}
|
|
||||||
else if(l == 0)
|
|
||||||
{
|
|
||||||
k_v += ((0x08 & stripe[k].stripe_d->sigma) >> 3);
|
|
||||||
k_d += ((0x08 & stripe[k].stripe_d->stripe_l->sigma) +
|
|
||||||
(0x08 & stripe[k].stripe_d->stripe_r->sigma)) >> 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
bit |= (mq_bit_decode(coder->bitcoder, coder->sig2context[(15 * k_h + 5 * k_v + k_d) >> l]) << l);
|
|
||||||
}
|
}
|
||||||
if(bit & bit_mask)
|
if(bit & bit_mask)
|
||||||
{
|
{
|
||||||
|
@ -2024,21 +1928,8 @@ cleanup_dec_pass(bwc_coder *const coder, const int8 b)
|
||||||
{
|
{
|
||||||
if(!(stripe[k].sigma & bit_mask) && !(stripe[k].pi & bit_mask))
|
if(!(stripe[k].sigma & bit_mask) && !(stripe[k].pi & bit_mask))
|
||||||
{
|
{
|
||||||
k_h = (stripe[k].stripe_l->sigma & bit_mask) + (stripe[k].stripe_r->sigma & bit_mask);
|
calc_k_sig(stripe, bit_mask, k, l, k_h, k_v, k_d, k_sig);
|
||||||
|
bit |= (mq_bit_decode(coder->bitcoder, coder->sig2context[k_sig]) << l);
|
||||||
k_v = ((bit_mask & (stripe[k].sigma >> 1)) + (bit_mask & (stripe[k].sigma << 1)));
|
|
||||||
|
|
||||||
k_d = ((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)));
|
|
||||||
|
|
||||||
if(l == 3)
|
|
||||||
{
|
|
||||||
k_v += ((0x01 & stripe[k].stripe_u->sigma) << 3);
|
|
||||||
k_d += ((0x01 & stripe[k].stripe_u->stripe_l->sigma) +
|
|
||||||
(0x01 & stripe[k].stripe_u->stripe_r->sigma)) << 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
bit |= (mq_bit_decode(coder->bitcoder, coder->sig2context[(15 * k_h + 5 * k_v + k_d) >> l]) << l);
|
|
||||||
|
|
||||||
if(bit & bit_mask)
|
if(bit & bit_mask)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue