refactor: move duplicated code into macro (xi)

This commit is contained in:
Gregor Weiss 2024-09-23 13:30:39 +02:00
parent 55921f7d9a
commit 2ddd711267
Signed by: Gregor Weiss
GPG key ID: 61E170A8BBFE5756

View file

@ -120,6 +120,24 @@
k_sig = ((15 * k_h + 5 * k_v + k_d) >> l); \
}
#define calc_xi(stripe, bit_mask, k, l, xi_h, xi_v) \
{ \
xi_h = ((bit_mask & stripe[k].stripe_l->sigma) | ((bit_mask & stripe[k].stripe_l->xi) << 2) | \
((bit_mask & stripe[k].stripe_r->sigma) << 1) | ((bit_mask & stripe[k].stripe_r->xi) << 3)) >> l; \
xi_v = ((bit_mask & (stripe[k].sigma >> 1)) | ((bit_mask & (stripe[k].xi >> 1)) << 2) | \
((bit_mask & (stripe[k].sigma << 1)) << 1) | ((bit_mask & (stripe[k].xi << 1)) << 3)) >> l; \
if(l == 3) \
{ \
xi_v |= ((0x01 & stripe[k].stripe_u->sigma) | ((0x01 & stripe[k].stripe_u->xi) << 2)); \
} \
else if(l == 0) \
{ \
xi_v |= (((0x08 & stripe[k].stripe_d->sigma) >> 2) | (0x08 & stripe[k].stripe_d->xi)); \
} \
xi_h = SIG2XI[xi_h]; \
xi_v = SIG2XI[xi_v]; \
}
/************************************************************************************************************\
|| ____ _ _ ___ ____ ____ _ _ ____ _ ____ ____ _ _ ____ ___ ____ _ _ ___ ____ ||
|| |___ \/ | |___ |__/ |\ | |__| | | | | |\ | [__ | |__| |\ | | [__ ||
@ -1033,24 +1051,7 @@ significance_propagation_enc_pass(bwc_coder *const coder, const int8 b)
if(bit & bit_mask)
{
xi_h = ((bit_mask & stripe[k].stripe_l->sigma) | ((bit_mask & stripe[k].stripe_l->xi) << 2) |
((bit_mask & stripe[k].stripe_r->sigma) << 1) | ((bit_mask & stripe[k].stripe_r->xi) << 3)) >> l;
xi_v = ((bit_mask & (stripe[k].sigma >> 1)) | ((bit_mask & (stripe[k].xi >> 1)) << 2) |
((bit_mask & (stripe[k].sigma << 1)) << 1) | ((bit_mask & (stripe[k].xi << 1)) << 3)) >> l;
if(l == 3)
{
xi_v |= ((0x01 & stripe[k].stripe_u->sigma) | ((0x01 & stripe[k].stripe_u->xi) << 2));
}
else if(l == 0)
{
xi_v |= (((0x08 & stripe[k].stripe_d->sigma) >> 2) | (0x08 & stripe[k].stripe_d->xi));
}
xi_h = SIG2XI[xi_h];
xi_v = SIG2XI[xi_v];
calc_xi(stripe, bit_mask, k, l, xi_h, xi_v);
mq_bit_encode(coder->bitcoder, (uchar)(((bit_mask & stripe[k].xi) >> l)^XI2CONT[(xi_h << 2) | xi_v][1]),
XI2CONT[(xi_h << 2) | xi_v][0]);
@ -1092,20 +1093,7 @@ significance_propagation_enc_pass(bwc_coder *const coder, const int8 b)
if(bit & bit_mask)
{
xi_h = ((bit_mask & stripe[k].stripe_l->sigma) | ((bit_mask & stripe[k].stripe_l->xi) << 2) |
((bit_mask & stripe[k].stripe_r->sigma) << 1) | ((bit_mask & stripe[k].stripe_r->xi) << 3)) >> l;
xi_v = ((bit_mask & (stripe[k].sigma >> 1)) | ((bit_mask & (stripe[k].xi >> 1)) << 2) |
((bit_mask & (stripe[k].sigma << 1)) << 1) | ((bit_mask & (stripe[k].xi << 1)) << 3)) >> l;
if(l == 3)
{
xi_v |= ((0x01 & stripe[k].stripe_u->sigma) | ((0x01 & stripe[k].stripe_u->xi) << 2));
}
xi_h = SIG2XI[xi_h];
xi_v = SIG2XI[xi_v];
calc_xi(stripe, bit_mask, k, l, xi_h, xi_v);
mq_bit_encode(coder->bitcoder, (uchar)(((bit_mask & stripe[k].xi) >> l)^XI2CONT[(xi_h << 2) | xi_v][1]),
XI2CONT[(xi_h << 2) | xi_v][0]);
@ -1396,24 +1384,7 @@ cleanup_enc_pass(bwc_coder *const coder, const int8 b)
}
if(bit & bit_mask)
{
xi_h = ((bit_mask & stripe[k].stripe_l->sigma) | ((bit_mask & stripe[k].stripe_l->xi) << 2) |
((bit_mask & stripe[k].stripe_r->sigma) << 1) | ((bit_mask & stripe[k].stripe_r->xi) << 3)) >> l;
xi_v = ((bit_mask & (stripe[k].sigma >> 1)) | ((bit_mask & (stripe[k].xi >> 1)) << 2) |
((bit_mask & (stripe[k].sigma << 1)) << 1) | ((bit_mask & (stripe[k].xi << 1)) << 3)) >> l;
if(l == 3)
{
xi_v |= ((0x01 & stripe[k].stripe_u->sigma) | ((0x01 & stripe[k].stripe_u->xi) << 2));
}
else if(l == 0)
{
xi_v |= (((0x08 & stripe[k].stripe_d->sigma) >> 2) | (0x08 & stripe[k].stripe_d->xi));
}
xi_h = SIG2XI[xi_h];
xi_v = SIG2XI[xi_v];
calc_xi(stripe, bit_mask, k, l, xi_h, xi_v);
mq_bit_encode(coder->bitcoder, (uchar)(((bit_mask & stripe[k].xi) >> l)^XI2CONT[(xi_h << 2) | xi_v][1]),
XI2CONT[(xi_h << 2) | xi_v][0]);
@ -1438,20 +1409,7 @@ cleanup_enc_pass(bwc_coder *const coder, const int8 b)
if(bit & bit_mask)
{
xi_h = ((bit_mask & stripe[k].stripe_l->sigma) | ((bit_mask & stripe[k].stripe_l->xi) << 2) |
((bit_mask & stripe[k].stripe_r->sigma) << 1) | ((bit_mask & stripe[k].stripe_r->xi) << 3)) >> l;
xi_v = ((bit_mask & (stripe[k].sigma >> 1)) | ((bit_mask & (stripe[k].xi >> 1)) << 2) |
((bit_mask & (stripe[k].sigma << 1)) << 1) | ((bit_mask & (stripe[k].xi << 1)) << 3)) >> l;
if(l == 3)
{
xi_v |= ((0x01 & stripe[k].stripe_u->sigma) | ((0x01 & stripe[k].stripe_u->xi) << 2));
}
xi_h = SIG2XI[xi_h];
xi_v = SIG2XI[xi_v];
calc_xi(stripe, bit_mask, k, l, xi_h, xi_v);
mq_bit_encode(coder->bitcoder, (uchar)(((bit_mask & stripe[k].xi) >> l)^XI2CONT[(xi_h << 2) | xi_v][1]),
XI2CONT[(xi_h << 2) | xi_v][0]);
@ -1547,23 +1505,7 @@ significance_propagation_dec_pass(bwc_coder *const coder, const int8 b)
{
stripe[k].bit[b] |= (bit << l);
xi_h = ((bit_mask & stripe[k].stripe_l->sigma) | ((bit_mask & stripe[k].stripe_l->xi) << 2) |
((bit_mask & stripe[k].stripe_r->sigma) << 1) | ((bit_mask & stripe[k].stripe_r->xi) << 3)) >> l;
xi_v = ((bit_mask & (stripe[k].sigma >> 1)) | ((bit_mask & (stripe[k].xi >> 1)) << 2) |
((bit_mask & (stripe[k].sigma << 1)) << 1) | ((bit_mask & (stripe[k].xi << 1)) << 3)) >> l;
if(l == 3)
{
xi_v |= ((0x01 & stripe[k].stripe_u->sigma) | ((0x01 & stripe[k].stripe_u->xi) << 2));
}
else if(l == 0)
{
xi_v |= (((0x08 & stripe[k].stripe_d->sigma) >> 2) | (0x08 & stripe[k].stripe_d->xi));
}
xi_h = SIG2XI[xi_h];
xi_v = SIG2XI[xi_v];
calc_xi(stripe, bit_mask, l, k, xi_h, xi_v);
stripe[k].xi |= ((XI2CONT[(xi_h << 2) | xi_v][1] ^ mq_bit_decode(coder->bitcoder, XI2CONT[(xi_h << 2) | xi_v][0])) << l);
@ -1606,19 +1548,7 @@ significance_propagation_dec_pass(bwc_coder *const coder, const int8 b)
{
stripe[k].bit[b] |= (bit << l);
xi_h = ((bit_mask & stripe[k].stripe_l->sigma) | ((bit_mask & stripe[k].stripe_l->xi) << 2) |
((bit_mask & stripe[k].stripe_r->sigma) << 1) | ((bit_mask & stripe[k].stripe_r->xi) << 3)) >> l;
xi_v = ((bit_mask & (stripe[k].sigma >> 1)) | ((bit_mask & (stripe[k].xi >> 1)) << 2) |
((bit_mask & (stripe[k].sigma << 1)) << 1) | ((bit_mask & (stripe[k].xi << 1)) << 3)) >> l;
if(l == 3)
{
xi_v |= ((0x01 & stripe[k].stripe_u->sigma) | ((0x01 & stripe[k].stripe_u->xi) << 2));
}
xi_h = SIG2XI[xi_h];
xi_v = SIG2XI[xi_v];
calc_xi(stripe, bit_mask, k, l, xi_h, xi_v);
stripe[k].xi |= ((XI2CONT[(xi_h << 2) | xi_v][1] ^ mq_bit_decode(coder->bitcoder, XI2CONT[(xi_h << 2) | xi_v][0])) << l);
@ -1890,23 +1820,7 @@ cleanup_dec_pass(bwc_coder *const coder, const int8 b)
}
if(bit & bit_mask)
{
xi_h = ((bit_mask & stripe[k].stripe_l->sigma) | ((bit_mask & stripe[k].stripe_l->xi) << 2) |
((bit_mask & stripe[k].stripe_r->sigma) << 1) | ((bit_mask & stripe[k].stripe_r->xi) << 3)) >> l;
xi_v = ((bit_mask & (stripe[k].sigma >> 1)) | ((bit_mask & (stripe[k].xi >> 1)) << 2) |
((bit_mask & (stripe[k].sigma << 1)) << 1) | ((bit_mask & (stripe[k].xi << 1)) << 3)) >> l;
if(l == 3)
{
xi_v |= ((0x01 & stripe[k].stripe_u->sigma) | ((0x01 & stripe[k].stripe_u->xi) << 2));
}
else if(l == 0)
{
xi_v |= (((0x08 & stripe[k].stripe_d->sigma) >> 2) | (0x08 & stripe[k].stripe_d->xi));
}
xi_h = SIG2XI[xi_h];
xi_v = SIG2XI[xi_v];
calc_xi(stripe, bit_mask, k, l, xi_h, xi_v);
stripe[k].xi |= ((XI2CONT[(xi_h << 2) | xi_v][1] ^ mq_bit_decode(coder->bitcoder, XI2CONT[(xi_h << 2) | xi_v][0])) << l);
@ -1933,19 +1847,7 @@ cleanup_dec_pass(bwc_coder *const coder, const int8 b)
if(bit & bit_mask)
{
xi_h = ((bit_mask & stripe[k].stripe_l->sigma) | ((bit_mask & stripe[k].stripe_l->xi) << 2) |
((bit_mask & stripe[k].stripe_r->sigma) << 1) | ((bit_mask & stripe[k].stripe_r->xi) << 3)) >> l;
xi_v = ((bit_mask & (stripe[k].sigma >> 1)) | ((bit_mask & (stripe[k].xi >> 1)) << 2) |
((bit_mask & (stripe[k].sigma << 1)) << 1) | ((bit_mask & (stripe[k].xi << 1)) << 3)) >> l;
if(l == 3)
{
xi_v |= ((0x01 & stripe[k].stripe_u->sigma) | ((0x01 & stripe[k].stripe_u->xi) << 2));
}
xi_h = SIG2XI[xi_h];
xi_v = SIG2XI[xi_v];
calc_xi(stripe, bit_mask, k, l, xi_h, xi_v);
stripe[k].xi |= ((XI2CONT[(xi_h << 2) | xi_v][1] ^ mq_bit_decode(coder->bitcoder, XI2CONT[(xi_h << 2) | xi_v][0])) << l);