mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 19:24:06 +00:00
[dep_quant.c] Small refactor
This commit is contained in:
parent
64d34f8559
commit
2912db5fca
213
src/dep_quant.c
213
src/dep_quant.c
|
@ -547,7 +547,11 @@ static void depquant_state_init(depquant_state* state, uint32_t sig_frac_bits[2]
|
||||||
state->m_sbbFracBits[1] = 0;
|
state->m_sbbFracBits[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE void checkRdCostSkipSbbZeroOut(Decision * decision, const all_depquant_states * const state, int decision_id, int skip_offset) {
|
static INLINE void checkRdCostSkipSbbZeroOut(
|
||||||
|
Decision* decision,
|
||||||
|
const all_depquant_states* const state,
|
||||||
|
int decision_id,
|
||||||
|
int skip_offset) {
|
||||||
int64_t rdCost = state->m_rdCost[decision_id + skip_offset] + state->m_sbbFracBits[decision_id + skip_offset][0];
|
int64_t rdCost = state->m_rdCost[decision_id + skip_offset] + state->m_sbbFracBits[decision_id + skip_offset][0];
|
||||||
decision->rdCost[decision_id] = rdCost;
|
decision->rdCost[decision_id] = rdCost;
|
||||||
decision->absLevel[decision_id] = 0;
|
decision->absLevel[decision_id] = 0;
|
||||||
|
@ -569,77 +573,64 @@ static void checkRdCosts(
|
||||||
int64_t rdCostA = state->m_rdCost[state_offset] + pqDataA->deltaDist[pqA];
|
int64_t rdCostA = state->m_rdCost[state_offset] + pqDataA->deltaDist[pqA];
|
||||||
int64_t rdCostB = state->m_rdCost[state_offset] + pqDataA->deltaDist[pqB];
|
int64_t rdCostB = state->m_rdCost[state_offset] + pqDataA->deltaDist[pqB];
|
||||||
int64_t rdCostZ = state->m_rdCost[state_offset];
|
int64_t rdCostZ = state->m_rdCost[state_offset];
|
||||||
if (state->m_remRegBins[state_offset] >= 4)
|
if (state->m_remRegBins[state_offset] >= 4) {
|
||||||
{
|
if (pqDataA->absLevel[pqA] < 4) {
|
||||||
if (pqDataA->absLevel[pqA] < 4)
|
|
||||||
{
|
|
||||||
rdCostA += state->m_coeffFracBits[state_offset][pqDataA->absLevel[pqA]];
|
rdCostA += state->m_coeffFracBits[state_offset][pqDataA->absLevel[pqA]];
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
const coeff_t value = (pqDataA->absLevel[pqA] - 4) >> 1;
|
const coeff_t value = (pqDataA->absLevel[pqA] - 4) >> 1;
|
||||||
rdCostA +=
|
rdCostA +=
|
||||||
state->m_coeffFracBits[state_offset][pqDataA->absLevel[pqA] - (value << 1)] + goRiceTab[value < RICEMAX ? value : RICEMAX - 1];
|
state->m_coeffFracBits[state_offset][pqDataA->absLevel[pqA] - (value << 1)] + goRiceTab[
|
||||||
|
value < RICEMAX ? value : RICEMAX - 1];
|
||||||
}
|
}
|
||||||
if (pqDataA->absLevel[pqB] < 4)
|
if (pqDataA->absLevel[pqB] < 4) {
|
||||||
{
|
|
||||||
rdCostB += state->m_coeffFracBits[state_offset][pqDataA->absLevel[pqB]];
|
rdCostB += state->m_coeffFracBits[state_offset][pqDataA->absLevel[pqB]];
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
const coeff_t value = (pqDataA->absLevel[pqB] - 4) >> 1;
|
const coeff_t value = (pqDataA->absLevel[pqB] - 4) >> 1;
|
||||||
rdCostB +=
|
rdCostB +=
|
||||||
state->m_coeffFracBits[state_offset][pqDataA->absLevel[pqB] - (value << 1)] + goRiceTab[value < RICEMAX ? value : RICEMAX - 1];
|
state->m_coeffFracBits[state_offset][pqDataA->absLevel[pqB] - (value << 1)] + goRiceTab[
|
||||||
|
value < RICEMAX ? value : RICEMAX - 1];
|
||||||
}
|
}
|
||||||
if (spt == SCAN_ISCSBB)
|
if (spt == SCAN_ISCSBB) {
|
||||||
{
|
|
||||||
rdCostA += state->m_sigFracBits[state_offset][1];
|
rdCostA += state->m_sigFracBits[state_offset][1];
|
||||||
rdCostB += state->m_sigFracBits[state_offset][1];
|
rdCostB += state->m_sigFracBits[state_offset][1];
|
||||||
rdCostZ += state->m_sigFracBits[state_offset][0];
|
rdCostZ += state->m_sigFracBits[state_offset][0];
|
||||||
}
|
}
|
||||||
else if (spt == SCAN_SOCSBB)
|
else if (spt == SCAN_SOCSBB) {
|
||||||
{
|
|
||||||
rdCostA += state->m_sbbFracBits[state_offset][1] + state->m_sigFracBits[state_offset][1];
|
rdCostA += state->m_sbbFracBits[state_offset][1] + state->m_sigFracBits[state_offset][1];
|
||||||
rdCostB += state->m_sbbFracBits[state_offset][1] + state->m_sigFracBits[state_offset][1];
|
rdCostB += state->m_sbbFracBits[state_offset][1] + state->m_sigFracBits[state_offset][1];
|
||||||
rdCostZ += state->m_sbbFracBits[state_offset][1] + state->m_sigFracBits[state_offset][0];
|
rdCostZ += state->m_sbbFracBits[state_offset][1] + state->m_sigFracBits[state_offset][0];
|
||||||
}
|
}
|
||||||
else if (state->m_numSigSbb[state_offset])
|
else if (state->m_numSigSbb[state_offset]) {
|
||||||
{
|
|
||||||
rdCostA += state->m_sigFracBits[state_offset][1];
|
rdCostA += state->m_sigFracBits[state_offset][1];
|
||||||
rdCostB += state->m_sigFracBits[state_offset][1];
|
rdCostB += state->m_sigFracBits[state_offset][1];
|
||||||
rdCostZ += state->m_sigFracBits[state_offset][0];
|
rdCostZ += state->m_sigFracBits[state_offset][0];
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
rdCostZ = decisions->rdCost[decisionA];
|
rdCostZ = decisions->rdCost[decisionA];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
rdCostA += (1 << SCALE_BITS) + goRiceTab[pqDataA->absLevel[pqA] <= state->m_goRiceZero[state_offset]
|
||||||
rdCostA +=
|
|
||||||
(1 << SCALE_BITS) + goRiceTab[pqDataA->absLevel[pqA] <= state->m_goRiceZero[state_offset]
|
|
||||||
? pqDataA->absLevel[pqA] - 1
|
? pqDataA->absLevel[pqA] - 1
|
||||||
: (pqDataA->absLevel[pqA] < RICEMAX ? pqDataA->absLevel[pqA] : RICEMAX - 1)];
|
: (pqDataA->absLevel[pqA] < RICEMAX ? pqDataA->absLevel[pqA] : RICEMAX - 1)];
|
||||||
rdCostB +=
|
rdCostB += (1 << SCALE_BITS) + goRiceTab[pqDataA->absLevel[pqB] <= state->m_goRiceZero[state_offset]
|
||||||
(1 << SCALE_BITS) + goRiceTab[pqDataA->absLevel[pqB] <= state->m_goRiceZero[state_offset]
|
|
||||||
? pqDataA->absLevel[pqB] - 1
|
? pqDataA->absLevel[pqB] - 1
|
||||||
: (pqDataA->absLevel[pqB] < RICEMAX ? pqDataA->absLevel[pqB] : RICEMAX - 1)];
|
: (pqDataA->absLevel[pqB] < RICEMAX ? pqDataA->absLevel[pqB] : RICEMAX - 1)];
|
||||||
rdCostZ += goRiceTab[state->m_goRiceZero[state_offset]];
|
rdCostZ += goRiceTab[state->m_goRiceZero[state_offset]];
|
||||||
}
|
}
|
||||||
if (rdCostA < decisions->rdCost[decisionA])
|
if (rdCostA < decisions->rdCost[decisionA]) {
|
||||||
{
|
|
||||||
decisions->rdCost[decisionA] = rdCostA;
|
decisions->rdCost[decisionA] = rdCostA;
|
||||||
decisions->absLevel[decisionA] = pqDataA->absLevel[pqA];
|
decisions->absLevel[decisionA] = pqDataA->absLevel[pqA];
|
||||||
decisions->prevId[decisionA] = state->m_stateId[state_offset];
|
decisions->prevId[decisionA] = state->m_stateId[state_offset];
|
||||||
}
|
}
|
||||||
if (rdCostZ < decisions->rdCost[decisionA])
|
if (rdCostZ < decisions->rdCost[decisionA]) {
|
||||||
{
|
|
||||||
decisions->rdCost[decisionA] = rdCostZ;
|
decisions->rdCost[decisionA] = rdCostZ;
|
||||||
decisions->absLevel[decisionA] = 0;
|
decisions->absLevel[decisionA] = 0;
|
||||||
decisions->prevId[decisionA] = state->m_stateId[state_offset];
|
decisions->prevId[decisionA] = state->m_stateId[state_offset];
|
||||||
}
|
}
|
||||||
if (rdCostB < decisions->rdCost[decisionB])
|
if (rdCostB < decisions->rdCost[decisionB]) {
|
||||||
{
|
|
||||||
decisions->rdCost[decisionB] = rdCostB;
|
decisions->rdCost[decisionB] = rdCostB;
|
||||||
decisions->absLevel[decisionB] = pqDataA->absLevel[pqB];
|
decisions->absLevel[decisionB] = pqDataA->absLevel[pqB];
|
||||||
decisions->prevId[decisionB] = state->m_stateId[state_offset];
|
decisions->prevId[decisionB] = state->m_stateId[state_offset];
|
||||||
|
@ -661,17 +652,15 @@ static INLINE void checkRdCostStart(const depquant_state* const state, int32_t l
|
||||||
decision_id)
|
decision_id)
|
||||||
{
|
{
|
||||||
int64_t rdCost = pqData->deltaDist[decision_id] + lastOffset;
|
int64_t rdCost = pqData->deltaDist[decision_id] + lastOffset;
|
||||||
if (pqData->absLevel[decision_id] < 4)
|
if (pqData->absLevel[decision_id] < 4) {
|
||||||
{
|
|
||||||
rdCost += state->m_coeffFracBits[pqData->absLevel[decision_id]];
|
rdCost += state->m_coeffFracBits[pqData->absLevel[decision_id]];
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
const coeff_t value = (pqData->absLevel[decision_id] - 4) >> 1;
|
const coeff_t value = (pqData->absLevel[decision_id] - 4) >> 1;
|
||||||
rdCost += state->m_coeffFracBits[pqData->absLevel[decision_id] - (value << 1)] + g_goRiceBits[state->m_goRicePar][value < RICEMAX ? value : RICEMAX - 1];
|
rdCost += state->m_coeffFracBits[pqData->absLevel[decision_id] - (value << 1)]
|
||||||
|
+ g_goRiceBits[state->m_goRicePar][value < RICEMAX ? value : RICEMAX - 1];
|
||||||
}
|
}
|
||||||
if (rdCost < decisions->rdCost[decision_id])
|
if (rdCost < decisions->rdCost[decision_id]) {
|
||||||
{
|
|
||||||
decisions->rdCost[decision_id] = rdCost;
|
decisions->rdCost[decision_id] = rdCost;
|
||||||
decisions->absLevel[decision_id] = pqData->absLevel[decision_id];
|
decisions->absLevel[decision_id] = pqData->absLevel[decision_id];
|
||||||
decisions->prevId[decision_id] = -1;
|
decisions->prevId[decision_id] = -1;
|
||||||
|
@ -721,14 +710,12 @@ static void xDecide(
|
||||||
{
|
{
|
||||||
memcpy(decisions, &startDec, sizeof(Decision));
|
memcpy(decisions, &startDec, sizeof(Decision));
|
||||||
|
|
||||||
if (zeroOut)
|
if (zeroOut) {
|
||||||
{
|
if (spt == SCAN_EOCSBB) {
|
||||||
if (spt == SCAN_EOCSBB)
|
|
||||||
{
|
|
||||||
checkRdCostSkipSbbZeroOut(decisions, all_states, 0, skip_offset);
|
checkRdCostSkipSbbZeroOut(decisions, all_states, 0, skip_offset);
|
||||||
checkRdCostSkipSbbZeroOut(decisions, all_states, 1, skip_offset);
|
checkRdCostSkipSbbZeroOut(decisions, all_states, 1, skip_offset);
|
||||||
checkRdCostSkipSbbZeroOut(decisions, all_states,2, skip_offset);
|
checkRdCostSkipSbbZeroOut(decisions, all_states, 2, skip_offset);
|
||||||
checkRdCostSkipSbbZeroOut(decisions, all_states,3, skip_offset);
|
checkRdCostSkipSbbZeroOut(decisions, all_states, 3, skip_offset);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -739,12 +726,11 @@ static void xDecide(
|
||||||
checkRdCosts(all_states, spt, &pqData, decisions, 2, 0, prev_offset + 1);
|
checkRdCosts(all_states, spt, &pqData, decisions, 2, 0, prev_offset + 1);
|
||||||
checkRdCosts(all_states, spt, &pqData, decisions, 1, 3, prev_offset + 2);
|
checkRdCosts(all_states, spt, &pqData, decisions, 1, 3, prev_offset + 2);
|
||||||
checkRdCosts(all_states, spt, &pqData, decisions, 3, 1, prev_offset + 3);
|
checkRdCosts(all_states, spt, &pqData, decisions, 3, 1, prev_offset + 3);
|
||||||
if (spt == SCAN_EOCSBB)
|
if (spt == SCAN_EOCSBB) {
|
||||||
{
|
|
||||||
checkRdCostSkipSbb(all_states, decisions, 0, skip_offset);
|
checkRdCostSkipSbb(all_states, decisions, 0, skip_offset);
|
||||||
checkRdCostSkipSbb(all_states, decisions, 1, skip_offset);
|
checkRdCostSkipSbb(all_states, decisions, 1, skip_offset);
|
||||||
checkRdCostSkipSbb(all_states, decisions,2, skip_offset);
|
checkRdCostSkipSbb(all_states, decisions, 2, skip_offset);
|
||||||
checkRdCostSkipSbb(all_states, decisions,3, skip_offset);
|
checkRdCostSkipSbb(all_states, decisions, 3, skip_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkRdCostStart(m_startState, lastOffset, &pqData, decisions, 0);
|
checkRdCostStart(m_startState, lastOffset, &pqData, decisions, 0);
|
||||||
|
@ -755,24 +741,19 @@ static void xDecide(
|
||||||
static INLINE unsigned templateAbsCompare(coeff_t sum)
|
static INLINE unsigned templateAbsCompare(coeff_t sum)
|
||||||
{
|
{
|
||||||
int rangeIdx = 0;
|
int rangeIdx = 0;
|
||||||
if (sum < g_riceT[0])
|
if (sum < g_riceT[0]) {
|
||||||
{
|
|
||||||
rangeIdx = 0;
|
rangeIdx = 0;
|
||||||
}
|
}
|
||||||
else if (sum < g_riceT[1])
|
else if (sum < g_riceT[1]) {
|
||||||
{
|
|
||||||
rangeIdx = 1;
|
rangeIdx = 1;
|
||||||
}
|
}
|
||||||
else if (sum < g_riceT[2])
|
else if (sum < g_riceT[2]) {
|
||||||
{
|
|
||||||
rangeIdx = 2;
|
rangeIdx = 2;
|
||||||
}
|
}
|
||||||
else if (sum < g_riceT[3])
|
else if (sum < g_riceT[3]) {
|
||||||
{
|
|
||||||
rangeIdx = 3;
|
rangeIdx = 3;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
rangeIdx = 4;
|
rangeIdx = 4;
|
||||||
}
|
}
|
||||||
return g_riceShift[rangeIdx];
|
return g_riceShift[rangeIdx];
|
||||||
|
@ -869,30 +850,27 @@ static INLINE void updateStateEOS(
|
||||||
all_depquant_states* state = &ctxs->m_allStates;
|
all_depquant_states* state = &ctxs->m_allStates;
|
||||||
int curr_state_offset = ctxs->m_curr_state_offset + decision_id;
|
int curr_state_offset = ctxs->m_curr_state_offset + decision_id;
|
||||||
state->m_rdCost[curr_state_offset] = decisions->rdCost[decision_id];
|
state->m_rdCost[curr_state_offset] = decisions->rdCost[decision_id];
|
||||||
if (decisions->prevId[decision_id] > -2)
|
if (decisions->prevId[decision_id] > -2) {
|
||||||
{
|
|
||||||
int prvState = -1;
|
int prvState = -1;
|
||||||
if (decisions->prevId[decision_id] >= 4)
|
if (decisions->prevId[decision_id] >= 4) {
|
||||||
{
|
|
||||||
prvState = ctxs->m_skip_state_offset + (decisions->prevId[decision_id] - 4);
|
prvState = ctxs->m_skip_state_offset + (decisions->prevId[decision_id] - 4);
|
||||||
state->m_numSigSbb[curr_state_offset] = 0;
|
state->m_numSigSbb[curr_state_offset] = 0;
|
||||||
memset(state->m_absLevelsAndCtxInit[curr_state_offset], 0, 16 * sizeof(uint8_t));
|
memset(state->m_absLevelsAndCtxInit[curr_state_offset], 0, 16 * sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
else if (decisions->prevId[decision_id] >= 0)
|
else if (decisions->prevId[decision_id] >= 0) {
|
||||||
{
|
|
||||||
prvState = ctxs->m_prev_state_offset + decisions->prevId[decision_id];
|
prvState = ctxs->m_prev_state_offset + decisions->prevId[decision_id];
|
||||||
state->m_numSigSbb[curr_state_offset] = state->m_numSigSbb[prvState] + !!decisions->absLevel[decision_id];
|
state->m_numSigSbb[curr_state_offset] = state->m_numSigSbb[prvState] + !!decisions->absLevel[decision_id];
|
||||||
memcpy(state->m_absLevelsAndCtxInit[curr_state_offset], state->m_absLevelsAndCtxInit[prvState], 16 * sizeof(uint8_t));
|
memcpy(state->m_absLevelsAndCtxInit[curr_state_offset], state->m_absLevelsAndCtxInit[prvState], 16 * sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
state->m_numSigSbb[curr_state_offset] = 1;
|
state->m_numSigSbb[curr_state_offset] = 1;
|
||||||
memset(state->m_absLevelsAndCtxInit[curr_state_offset], 0, 16 * sizeof(uint8_t));
|
memset(state->m_absLevelsAndCtxInit[curr_state_offset], 0, 16 * sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
uint8_t* temp = (uint8_t*)(&state->m_absLevelsAndCtxInit[curr_state_offset][scan_pos & 15]);
|
uint8_t* temp = (uint8_t*)(&state->m_absLevelsAndCtxInit[curr_state_offset][scan_pos & 15]);
|
||||||
*temp = (uint8_t)MIN(255, decisions->absLevel[decision_id]);
|
*temp = (uint8_t)MIN(255, decisions->absLevel[decision_id]);
|
||||||
|
|
||||||
update_common_context(ctxs, state->m_commonCtx, scan_pos, cg_pos, width_in_sbb, height_in_sbb, next_sbb_right,next_sbb_below, prvState, ctxs->m_curr_state_offset + decision_id);
|
update_common_context(ctxs, state->m_commonCtx, scan_pos, cg_pos, width_in_sbb, height_in_sbb, next_sbb_right,
|
||||||
|
next_sbb_below, prvState, ctxs->m_curr_state_offset + decision_id);
|
||||||
|
|
||||||
coeff_t tinit = state->m_absLevelsAndCtxInit[curr_state_offset][8 + ((scan_pos - 1) & 15)];
|
coeff_t tinit = state->m_absLevelsAndCtxInit[curr_state_offset][8 + ((scan_pos - 1) & 15)];
|
||||||
coeff_t sumNum = tinit & 7;
|
coeff_t sumNum = tinit & 7;
|
||||||
|
@ -901,7 +879,8 @@ static INLINE void updateStateEOS(
|
||||||
state->m_sigFracBits[curr_state_offset][0] = state->m_sigFracBitsArray[curr_state_offset][sigCtxOffsetNext + MIN((sumAbs1 + 1) >> 1, 3)][0];
|
state->m_sigFracBits[curr_state_offset][0] = state->m_sigFracBitsArray[curr_state_offset][sigCtxOffsetNext + MIN((sumAbs1 + 1) >> 1, 3)][0];
|
||||||
state->m_sigFracBits[curr_state_offset][1] = state->m_sigFracBitsArray[curr_state_offset][sigCtxOffsetNext + MIN((sumAbs1 + 1) >> 1, 3)][1];
|
state->m_sigFracBits[curr_state_offset][1] = state->m_sigFracBitsArray[curr_state_offset][sigCtxOffsetNext + MIN((sumAbs1 + 1) >> 1, 3)][1];
|
||||||
|
|
||||||
memcpy(state->m_coeffFracBits[curr_state_offset], state->m_gtxFracBitsArray[gtxCtxOffsetNext + (sumGt1 < 4 ? sumGt1 : 4)], sizeof(state->m_coeffFracBits[0]));
|
memcpy(state->m_coeffFracBits[curr_state_offset],
|
||||||
|
state->m_gtxFracBitsArray[gtxCtxOffsetNext + (sumGt1 < 4 ? sumGt1 : 4)], sizeof(state->m_coeffFracBits[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,10 +898,8 @@ static INLINE void updateState(
|
||||||
all_depquant_states* state = &ctxs->m_allStates;
|
all_depquant_states* state = &ctxs->m_allStates;
|
||||||
int state_id = ctxs->m_curr_state_offset + decision_id;
|
int state_id = ctxs->m_curr_state_offset + decision_id;
|
||||||
state->m_rdCost[state_id] = decisions->rdCost[decision_id];
|
state->m_rdCost[state_id] = decisions->rdCost[decision_id];
|
||||||
if (decisions->prevId[decision_id] > -2)
|
if (decisions->prevId[decision_id] > -2) {
|
||||||
{
|
if (decisions->prevId[decision_id] >= 0) {
|
||||||
if (decisions->prevId[decision_id] >= 0)
|
|
||||||
{
|
|
||||||
const int prvState = ctxs->m_prev_state_offset + decisions->prevId[decision_id];
|
const int prvState = ctxs->m_prev_state_offset + decisions->prevId[decision_id];
|
||||||
state->m_numSigSbb[state_id] = (state->m_numSigSbb[prvState]) + !!decisions->absLevel[decision_id];
|
state->m_numSigSbb[state_id] = (state->m_numSigSbb[prvState]) + !!decisions->absLevel[decision_id];
|
||||||
state->m_refSbbCtxId[state_id] = state->m_refSbbCtxId[prvState];
|
state->m_refSbbCtxId[state_id] = state->m_refSbbCtxId[prvState];
|
||||||
|
@ -930,54 +907,50 @@ static INLINE void updateState(
|
||||||
state->m_sbbFracBits[state_id][1] = state->m_sbbFracBits[prvState][1];
|
state->m_sbbFracBits[state_id][1] = state->m_sbbFracBits[prvState][1];
|
||||||
state->m_remRegBins[state_id] = state->m_remRegBins[prvState] - 1;
|
state->m_remRegBins[state_id] = state->m_remRegBins[prvState] - 1;
|
||||||
state->m_goRicePar[state_id] = state->m_goRicePar[prvState];
|
state->m_goRicePar[state_id] = state->m_goRicePar[prvState];
|
||||||
if (state->m_remRegBins[state_id] >= 4)
|
if (state->m_remRegBins[state_id] >= 4) {
|
||||||
{
|
state->m_remRegBins[state_id] -= (decisions->absLevel[decision_id] < 2
|
||||||
state->m_remRegBins[state_id] -= (decisions->absLevel[decision_id] < 2 ? (unsigned)decisions->absLevel[decision_id] : 3);
|
? (unsigned)decisions->absLevel[decision_id]
|
||||||
|
: 3);
|
||||||
}
|
}
|
||||||
memcpy(state->m_absLevelsAndCtxInit[state_id], state->m_absLevelsAndCtxInit[prvState], 48 * sizeof(uint8_t));
|
memcpy(state->m_absLevelsAndCtxInit[state_id], state->m_absLevelsAndCtxInit[prvState], 48 * sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
state->m_numSigSbb[state_id] = 1;
|
state->m_numSigSbb[state_id] = 1;
|
||||||
state->m_refSbbCtxId[state_id] = -1;
|
state->m_refSbbCtxId[state_id] = -1;
|
||||||
int ctxBinSampleRatio = 28; //(scanInfo.chType == CHANNEL_TYPE_LUMA) ? MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_LUMA : MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_CHROMA;
|
int ctxBinSampleRatio = 28;
|
||||||
state->m_remRegBins[state_id] = (state->effWidth * state->effHeight * ctxBinSampleRatio) / 16 - (decisions->absLevel[decision_id] < 2 ? (unsigned)decisions->absLevel[decision_id] : 3);
|
//(scanInfo.chType == CHANNEL_TYPE_LUMA) ? MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_LUMA : MAX_TU_LEVEL_CTX_CODED_BIN_CONSTRAINT_CHROMA;
|
||||||
|
state->m_remRegBins[state_id] = (state->effWidth * state->effHeight * ctxBinSampleRatio) / 16 - (
|
||||||
|
decisions->absLevel[decision_id] < 2 ? (unsigned)decisions->absLevel[decision_id] : 3);
|
||||||
memset(state->m_absLevelsAndCtxInit[state_id], 0, 48 * sizeof(uint8_t));
|
memset(state->m_absLevelsAndCtxInit[state_id], 0, 48 * sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* levels = (uint8_t*)(state->m_absLevelsAndCtxInit[state_id]);
|
uint8_t* levels = (uint8_t*)(state->m_absLevelsAndCtxInit[state_id]);
|
||||||
levels[scan_pos & 15] = (uint8_t)MIN(255, decisions->absLevel[decision_id]);
|
levels[scan_pos & 15] = (uint8_t)MIN(255, decisions->absLevel[decision_id]);
|
||||||
|
|
||||||
if (state->m_remRegBins[state_id] >= 4)
|
if (state->m_remRegBins[state_id] >= 4) {
|
||||||
{
|
|
||||||
coeff_t tinit = state->m_absLevelsAndCtxInit[state_id][8 + ((scan_pos - 1) & 15)];
|
coeff_t tinit = state->m_absLevelsAndCtxInit[state_id][8 + ((scan_pos - 1) & 15)];
|
||||||
coeff_t sumAbs1 = (tinit >> 3) & 31;
|
coeff_t sumAbs1 = (tinit >> 3) & 31;
|
||||||
coeff_t sumNum = tinit & 7;
|
coeff_t sumNum = tinit & 7;
|
||||||
#define UPDATE(k) {coeff_t t=levels[next_nb_info_ssb.inPos[k]]; sumAbs1+=MIN(4+(t&1),t); sumNum+=!!t; }
|
#define UPDATE(k) {coeff_t t=levels[next_nb_info_ssb.inPos[k]]; sumAbs1+=MIN(4+(t&1),t); sumNum+=!!t; }
|
||||||
if (numIPos == 1)
|
if (numIPos == 1) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
}
|
}
|
||||||
else if (numIPos == 2)
|
else if (numIPos == 2) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
}
|
}
|
||||||
else if (numIPos == 3)
|
else if (numIPos == 3) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
UPDATE(2);
|
UPDATE(2);
|
||||||
}
|
}
|
||||||
else if (numIPos == 4)
|
else if (numIPos == 4) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
UPDATE(2);
|
UPDATE(2);
|
||||||
UPDATE(3);
|
UPDATE(3);
|
||||||
}
|
}
|
||||||
else if (numIPos == 5)
|
else if (numIPos == 5) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
UPDATE(2);
|
UPDATE(2);
|
||||||
|
@ -986,37 +959,35 @@ static INLINE void updateState(
|
||||||
}
|
}
|
||||||
#undef UPDATE
|
#undef UPDATE
|
||||||
coeff_t sumGt1 = sumAbs1 - sumNum;
|
coeff_t sumGt1 = sumAbs1 - sumNum;
|
||||||
state->m_sigFracBits[state_id][0] = state->m_sigFracBitsArray[state_id][sigCtxOffsetNext + MIN((sumAbs1 + 1) >> 1, 3)][0];
|
state->m_sigFracBits[state_id][0] = state->m_sigFracBitsArray[state_id][sigCtxOffsetNext + MIN(
|
||||||
state->m_sigFracBits[state_id][1] = state->m_sigFracBitsArray[state_id][sigCtxOffsetNext + MIN((sumAbs1 + 1) >> 1, 3)][1];
|
(sumAbs1 + 1) >> 1, 3)][0];
|
||||||
memcpy(state->m_coeffFracBits[state_id], state->m_gtxFracBitsArray[gtxCtxOffsetNext + (sumGt1 < 4 ? sumGt1 : 4)], sizeof(state->m_coeffFracBits[0]));
|
state->m_sigFracBits[state_id][1] = state->m_sigFracBitsArray[state_id][sigCtxOffsetNext + MIN(
|
||||||
|
(sumAbs1 + 1) >> 1, 3)][1];
|
||||||
|
memcpy(state->m_coeffFracBits[state_id], state->m_gtxFracBitsArray[gtxCtxOffsetNext + (sumGt1 < 4 ? sumGt1 : 4)],
|
||||||
|
sizeof(state->m_coeffFracBits[0]));
|
||||||
|
|
||||||
|
|
||||||
coeff_t sumAbs = state->m_absLevelsAndCtxInit[state_id][8 + ((scan_pos - 1) & 15)] >> 8;
|
coeff_t sumAbs = state->m_absLevelsAndCtxInit[state_id][8 + ((scan_pos - 1) & 15)] >> 8;
|
||||||
#define UPDATE(k) {coeff_t t=levels[next_nb_info_ssb.inPos[k]]; sumAbs+=t; }
|
#define UPDATE(k) {coeff_t t=levels[next_nb_info_ssb.inPos[k]]; sumAbs+=t; }
|
||||||
if (numIPos == 1)
|
if (numIPos == 1) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
}
|
}
|
||||||
else if (numIPos == 2)
|
else if (numIPos == 2) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
}
|
}
|
||||||
else if (numIPos == 3)
|
else if (numIPos == 3) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
UPDATE(2);
|
UPDATE(2);
|
||||||
}
|
}
|
||||||
else if (numIPos == 4)
|
else if (numIPos == 4) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
UPDATE(2);
|
UPDATE(2);
|
||||||
UPDATE(3);
|
UPDATE(3);
|
||||||
}
|
}
|
||||||
else if (numIPos == 5)
|
else if (numIPos == 5) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
UPDATE(2);
|
UPDATE(2);
|
||||||
|
@ -1024,48 +995,40 @@ static INLINE void updateState(
|
||||||
UPDATE(4);
|
UPDATE(4);
|
||||||
}
|
}
|
||||||
#undef UPDATE
|
#undef UPDATE
|
||||||
if (extRiceFlag)
|
if (extRiceFlag) {
|
||||||
{
|
|
||||||
unsigned currentShift = templateAbsCompare(sumAbs);
|
unsigned currentShift = templateAbsCompare(sumAbs);
|
||||||
sumAbs = sumAbs >> currentShift;
|
sumAbs = sumAbs >> currentShift;
|
||||||
int sumAll = MAX(MIN(31, (int)sumAbs - (int)baseLevel), 0);
|
int sumAll = MAX(MIN(31, (int)sumAbs - (int)baseLevel), 0);
|
||||||
state->m_goRicePar[state_id] = g_goRiceParsCoeff[sumAll];
|
state->m_goRicePar[state_id] = g_goRiceParsCoeff[sumAll];
|
||||||
state->m_goRicePar[state_id] += currentShift;
|
state->m_goRicePar[state_id] += currentShift;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
int sumAll = MAX(MIN(31, (int)sumAbs - 4 * 5), 0);
|
int sumAll = MAX(MIN(31, (int)sumAbs - 4 * 5), 0);
|
||||||
state->m_goRicePar[state_id] = g_goRiceParsCoeff[sumAll];
|
state->m_goRicePar[state_id] = g_goRiceParsCoeff[sumAll];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
coeff_t sumAbs = (state->m_absLevelsAndCtxInit[state_id][8 + ((scan_pos - 1) & 15)]) >> 8;
|
coeff_t sumAbs = (state->m_absLevelsAndCtxInit[state_id][8 + ((scan_pos - 1) & 15)]) >> 8;
|
||||||
#define UPDATE(k) {coeff_t t=levels[next_nb_info_ssb.inPos[k]]; sumAbs+=t; }
|
#define UPDATE(k) {coeff_t t=levels[next_nb_info_ssb.inPos[k]]; sumAbs+=t; }
|
||||||
if (numIPos == 1)
|
if (numIPos == 1) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
}
|
}
|
||||||
else if (numIPos == 2)
|
else if (numIPos == 2) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
}
|
}
|
||||||
else if (numIPos == 3)
|
else if (numIPos == 3) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
UPDATE(2);
|
UPDATE(2);
|
||||||
}
|
}
|
||||||
else if (numIPos == 4)
|
else if (numIPos == 4) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
UPDATE(2);
|
UPDATE(2);
|
||||||
UPDATE(3);
|
UPDATE(3);
|
||||||
}
|
}
|
||||||
else if (numIPos == 5)
|
else if (numIPos == 5) {
|
||||||
{
|
|
||||||
UPDATE(0);
|
UPDATE(0);
|
||||||
UPDATE(1);
|
UPDATE(1);
|
||||||
UPDATE(2);
|
UPDATE(2);
|
||||||
|
@ -1073,16 +1036,14 @@ static INLINE void updateState(
|
||||||
UPDATE(4);
|
UPDATE(4);
|
||||||
}
|
}
|
||||||
#undef UPDATE
|
#undef UPDATE
|
||||||
if (extRiceFlag)
|
if (extRiceFlag) {
|
||||||
{
|
|
||||||
unsigned currentShift = templateAbsCompare(sumAbs);
|
unsigned currentShift = templateAbsCompare(sumAbs);
|
||||||
sumAbs = sumAbs >> currentShift;
|
sumAbs = sumAbs >> currentShift;
|
||||||
sumAbs = MIN(31, sumAbs);
|
sumAbs = MIN(31, sumAbs);
|
||||||
state->m_goRicePar[state_id] = g_goRiceParsCoeff[sumAbs];
|
state->m_goRicePar[state_id] = g_goRiceParsCoeff[sumAbs];
|
||||||
state->m_goRicePar[state_id] += currentShift;
|
state->m_goRicePar[state_id] += currentShift;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
sumAbs = MIN(31, sumAbs);
|
sumAbs = MIN(31, sumAbs);
|
||||||
state->m_goRicePar[state_id] = g_goRiceParsCoeff[sumAbs];
|
state->m_goRicePar[state_id] = g_goRiceParsCoeff[sumAbs];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue