Skip to content

Commit

Permalink
Merge pull request stenzek#2728 from ggrtk/mdec-eob
Browse files Browse the repository at this point in the history
MDEC: EOB is optional for complete blocks
  • Loading branch information
stenzek authored Nov 18, 2021
2 parents 10cf8ef + 1f07ea6 commit 83a031e
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/core/mdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,26 +595,28 @@ bool MDEC::rl_decode_block(s16* blk, const u8* qt)
m_remaining_halfwords--;

m_current_coefficient += ((n >> 10) & 0x3F) + 1;
if (m_current_coefficient >= 64)
if (m_current_coefficient < 64)
{
s32 val = (SignExtendN<10, s32>(static_cast<s32>(n & 0x3FF)) *
static_cast<s32>(ZeroExtend32(qt[m_current_coefficient])) * static_cast<s32>(m_current_q_scale) +
4) /
8;

if (m_current_q_scale == 0)
val = SignExtendN<10, s32>(static_cast<s32>(n & 0x3FF)) * 2;

val = std::clamp(val, -0x400, 0x3FF);
if (m_current_q_scale > 0)
blk[zagzig[m_current_coefficient]] = static_cast<s16>(val);
else if (m_current_q_scale == 0)
blk[m_current_coefficient] = static_cast<s16>(val);
}

if (m_current_coefficient >= 63)
{
m_current_coefficient = 64;
return true;
}

s32 val = (SignExtendN<10, s32>(static_cast<s32>(n & 0x3FF)) *
static_cast<s32>(ZeroExtend32(qt[m_current_coefficient])) * static_cast<s32>(m_current_q_scale) +
4) /
8;

if (m_current_q_scale == 0)
val = SignExtendN<10, s32>(static_cast<s32>(n & 0x3FF)) * 2;

val = std::clamp(val, -0x400, 0x3FF);
// val = val * static_cast<s32>(ZeroExtend32(scalezag[i]));
if (m_current_q_scale > 0)
blk[zagzig[m_current_coefficient]] = static_cast<s16>(val);
else if (m_current_q_scale == 0)
blk[m_current_coefficient] = static_cast<s16>(val);
}

return false;
Expand Down

0 comments on commit 83a031e

Please sign in to comment.