Skip to content

Commit

Permalink
Bug fixes. 32 bit loss should be working now. MacOS may still have a …
Browse files Browse the repository at this point in the history
…problem.
  • Loading branch information
aous72 committed Nov 3, 2024
1 parent 2b6fb15 commit 8e1935f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
22 changes: 19 additions & 3 deletions src/core/coding/ojph_block_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,29 @@ namespace ojph {
* + 4 * mel event for initial row of quads when needed \n
* \n
* Each entry contains, starting from the LSB \n
* \li \c total prefix length for quads 0 and 1 (3 bits) \n
* \li \c total suffix length for quads 0 and 1 (4 bits) \n
* \li \c total total prefix length for quads 0 and 1 (3 bits) \n
* \li \c total total suffix length for quads 0 and 1 (4 bits) \n
* \li \c suffix length for quad 0 (3 bits) \n
* \li \c prefix for quad 0 (3 bits) \n
* \li \c prefix for quad 1 (3 bits) \n
* \n
* Another table is uvlc_bias, which is needed to correctly decode the
* extension u_ext for initial row of quads. Under certain condition,
* we deduct 1 or 2 from u_q0 and u_q1 before encoding them; so for us
* to know that decoding u_ext is needed, we recreate the u_q0 and u_q1
* that we actually encoded. \n
* For simplicity, we use the same index as before \n
* \li \c u_q0 bias is 2 bits \n
* \li \c u_q1 bias is 2 bits \n
*/

/// @brief uvlc_tbl0 contains decoding information for initial row of quads
ui16 uvlc_tbl0[256+64] = { 0 };
/// @brief uvlc_tbl1 contains decoding information for non-initial row of
/// quads
ui16 uvlc_tbl1[256] = { 0 };
/// @brief uvlc_bias contains decoding info. for initial row of quads
ui8 uvlc_bias[256+64] = { 0 };
/// @}

//************************************************************************/
Expand Down Expand Up @@ -199,8 +210,10 @@ namespace ojph {
ui32 mode = i >> 6;
ui32 vlc = i & 0x3F;

if (mode == 0) // both u_off are 0
if (mode == 0) { // both u_off are 0
uvlc_tbl0[i] = 0;
uvlc_bias[i] = 0;
}
else if (mode <= 2) // u_off are either 01 or 10
{
ui32 d = dec[vlc & 0x7]; //look at the least significant 3 bits
Expand Down Expand Up @@ -232,6 +245,7 @@ namespace ojph {
total_suffix = u0_suffix_len;
u0 = d0 >> 5;
u1 = (vlc & 1) + 1;
uvlc_bias[i] = 4; // 0b00 for u0 and 0b01 for u1
}
else
{
Expand All @@ -240,6 +254,7 @@ namespace ojph {
total_suffix = u0_suffix_len + ((d1 >> 2) & 0x7);
u0 = d0 >> 5;
u1 = d1 >> 5;
uvlc_bias[i] = 0;
}

uvlc_tbl0[i] = (ui16)(total_prefix |
Expand All @@ -265,6 +280,7 @@ namespace ojph {
(u0_suffix_len << 7) |
(u0 << 10) |
(u1 << 13));
uvlc_bias[i] = 10; // 0b10 for u0 and 0b10 for u1
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/coding/ojph_block_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ namespace ojph{
extern ui16 vlc_tbl1[1024];
extern ui16 uvlc_tbl0[256+64];
extern ui16 uvlc_tbl1[256];

extern ui8 uvlc_bias[256+64];
} // !namespace local
} // !namespace ojph
24 changes: 13 additions & 11 deletions src/core/coding/ojph_block_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,9 @@ namespace ojph {
// run = mel_get_run(&mel); // get another run

//decode uvlc_mode to get u for both quads
ui32 uvlc_entry = uvlc_tbl0[uvlc_mode + (vlc_val & 0x3F)];
ui32 idx = uvlc_mode + (ui32)(vlc_val & 0x3F);
ui32 uvlc_entry = uvlc_tbl0[idx];
ui16 u_bias = uvlc_bias[idx];
//remove total prefix length
vlc_val = rev_advance64(&vlc, uvlc_entry & 0x7);
uvlc_entry >>= 3;
Expand All @@ -2037,21 +2039,21 @@ namespace ojph {
// quad 0 length
len = uvlc_entry & 0x7; // quad 0 suffix length
uvlc_entry >>= 3;
ui16 u_q0 = (ui16)(1 + (uvlc_entry&7) + (tmp&~(0xFFU<<len)));//kap. 1
ui16 u_q1 = (ui16)(1 + (uvlc_entry >> 3) + (tmp >> len)); //kappa==1
ui16 u_q0 = (ui16)((uvlc_entry & 7) + (tmp & ~(0xFFU << len)));
ui16 u_q1 = (ui16)((uvlc_entry >> 3) + (tmp >> len));

// decode u_q extensions, which is needed only when u_q > 32
ui16 u_ext; bool cond0, cond1;
cond0 = u_q0 > 32;
u_ext = (ui16)(cond0 ? (uvlc_entry & 0xF) : 0);
cond0 = u_q0 - (u_bias & 0x3) > 32;
u_ext = (ui16)(cond0 ? (vlc_val & 0xF) : 0);
vlc_val = rev_advance64(&vlc, cond0 ? 4 : 0);
u_q0 = (ui16)(u_q0 + (u_ext << 2));
sp[1] = u_q0;
cond1 = u_q1 > 32;
u_ext = (ui16)(cond1 ? (uvlc_entry & 0xF) : 0);
sp[1] = u_q0 + 1; // kappa = 1
cond1 = u_q1 - (u_bias >> 2) > 32;
u_ext = (ui16)(cond1 ? (vlc_val & 0xF) : 0);
vlc_val = rev_advance64(&vlc, cond1 ? 4 : 0);
u_q1 = (ui16)(u_q1 + (u_ext << 2));
sp[3] = u_q1;
sp[3] = u_q1 + 1; // kappa = 1
}
sp[0] = sp[1] = 0;

Expand Down Expand Up @@ -2165,12 +2167,12 @@ namespace ojph {
// decode u_q extensions, which is needed only when u_q > 32
ui16 u_ext; bool cond0, cond1;
cond0 = u_q0 > 32;
u_ext = (ui16)(cond0 ? (uvlc_entry & 0xF) : 0);
u_ext = (ui16)(cond0 ? (vlc_val & 0xF) : 0);
vlc_val = rev_advance64(&vlc, cond0 ? 4 : 0);
u_q0 = (ui16)(u_q0 + (u_ext << 2));
sp[1] = u_q0;
cond1 = u_q1 > 32;
u_ext = (ui16)(cond1 ? (uvlc_entry & 0xF) : 0);
u_ext = (ui16)(cond1 ? (vlc_val & 0xF) : 0);
vlc_val = rev_advance64(&vlc, cond1 ? 4 : 0);
u_q1 = (ui16)(u_q1 + (u_ext << 2));
sp[3] = u_q1;
Expand Down

0 comments on commit 8e1935f

Please sign in to comment.