From 1f07ea6ecc2a0e062ce68673052aa1cc9d88c1a9 Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Thu, 28 Oct 2021 07:16:01 -0700 Subject: [PATCH] MDEC: EOB is optional for complete blocks --- src/core/mdec.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/core/mdec.cpp b/src/core/mdec.cpp index d9b157342..6b31171c0 100644 --- a/src/core/mdec.cpp +++ b/src/core/mdec.cpp @@ -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(n & 0x3FF)) * + static_cast(ZeroExtend32(qt[m_current_coefficient])) * static_cast(m_current_q_scale) + + 4) / + 8; + + if (m_current_q_scale == 0) + val = SignExtendN<10, s32>(static_cast(n & 0x3FF)) * 2; + + val = std::clamp(val, -0x400, 0x3FF); + if (m_current_q_scale > 0) + blk[zagzig[m_current_coefficient]] = static_cast(val); + else if (m_current_q_scale == 0) + blk[m_current_coefficient] = static_cast(val); + } + + if (m_current_coefficient >= 63) { m_current_coefficient = 64; return true; } - - s32 val = (SignExtendN<10, s32>(static_cast(n & 0x3FF)) * - static_cast(ZeroExtend32(qt[m_current_coefficient])) * static_cast(m_current_q_scale) + - 4) / - 8; - - if (m_current_q_scale == 0) - val = SignExtendN<10, s32>(static_cast(n & 0x3FF)) * 2; - - val = std::clamp(val, -0x400, 0x3FF); - // val = val * static_cast(ZeroExtend32(scalezag[i])); - if (m_current_q_scale > 0) - blk[zagzig[m_current_coefficient]] = static_cast(val); - else if (m_current_q_scale == 0) - blk[m_current_coefficient] = static_cast(val); } return false;