Commit a96dda0c authored by ChenJiafeng's avatar ChenJiafeng Committed by David Flynn
Browse files

attr/m50669: adjust context derivation for zerorun

This adoption implements a different context selection method for the
isOne syntax element in attribute coding.
parent d96e5851
......@@ -61,7 +61,7 @@ struct PCCResidualsDecoder {
void stop();
int decodePredMode(int max);
int decodeZeroCnt(int max);
uint32_t decodeSymbol(int k1, int k2);
uint32_t decodeSymbol(int k1, int k2, int k3);
void decode(uint32_t values[3]);
uint32_t decode();
};
......@@ -129,15 +129,15 @@ PCCResidualsDecoder::decodeZeroCnt(int maxMode)
//----------------------------------------------------------------------------
uint32_t
PCCResidualsDecoder::decodeSymbol(int k1, int k2)
PCCResidualsDecoder::decodeSymbol(int k1, int k2, int k3)
{
if (arithmeticDecoder.decode(binaryModelIsZero[k1]))
return 0u;
if (arithmeticDecoder.decode(binaryModelIsOne[k1]))
if (arithmeticDecoder.decode(binaryModelIsOne[k2]))
return 1u;
uint32_t value = symbolCoder[k2].decode(&arithmeticDecoder);
uint32_t value = symbolCoder[k3].decode(&arithmeticDecoder);
if (value == kAttributeResidualAlphabetSize) {
value +=
arithmeticDecoder.decodeExpGolomb(0, binaryModel0, binaryModelDiff[k1]);
......@@ -151,11 +151,13 @@ PCCResidualsDecoder::decodeSymbol(int k1, int k2)
void
PCCResidualsDecoder::decode(uint32_t value[3])
{
value[0] = decodeSymbol(0, 0);
value[0] = decodeSymbol(0, 0, 0);
int b0 = value[0] == 0;
value[1] = decodeSymbol(1 + b0, 1);
int b1 = value[1] == 0;
value[2] = decodeSymbol(3 + (b0 << 1) + b1, 1);
int b1 = value[0] <= 1;
value[1] = decodeSymbol(1 + b0, 1 + b1, 1);
int b2 = value[1] == 0;
int b3 = value[1] <= 1;
value[2] = decodeSymbol(3 + (b0 << 1) + b2, 3 + (b1 << 1) + b3, 1);
int d = (value[0] == value[1] && value[0] == value[2]);
for (int k = 0; k < 3; k++) {
......@@ -168,7 +170,7 @@ PCCResidualsDecoder::decode(uint32_t value[3])
uint32_t
PCCResidualsDecoder::decode()
{
return decodeSymbol(0, 0) + 1;
return decodeSymbol(0, 0, 0) + 1;
}
//============================================================================
......
......@@ -65,7 +65,7 @@ struct PCCResidualsEncoder {
int stop();
void encodePredMode(int value, int max);
void encodeZeroCnt(int value, int max);
void encodeSymbol(uint32_t value, int k1, int k2);
void encodeSymbol(uint32_t value, int k1, int k2, int k3);
void encode(uint32_t value0, uint32_t value1, uint32_t value2);
void encode(uint32_t value);
};
......@@ -133,7 +133,7 @@ PCCResidualsEncoder::encodeZeroCnt(int mode, int maxMode)
//----------------------------------------------------------------------------
void
PCCResidualsEncoder::encodeSymbol(uint32_t value, int k1, int k2)
PCCResidualsEncoder::encodeSymbol(uint32_t value, int k1, int k2, int k3)
{
bool isZero = value == 0;
arithmeticEncoder.encode(isZero, binaryModelIsZero[k1]);
......@@ -142,17 +142,17 @@ PCCResidualsEncoder::encodeSymbol(uint32_t value, int k1, int k2)
}
bool isOne = value == 1;
arithmeticEncoder.encode(isOne, binaryModelIsOne[k1]);
arithmeticEncoder.encode(isOne, binaryModelIsOne[k2]);
if (isOne) {
return;
}
value -= 2;
if (value < kAttributeResidualAlphabetSize) {
symbolCoder[k2].encode(value, &arithmeticEncoder);
symbolCoder[k3].encode(value, &arithmeticEncoder);
} else {
int alphabetSize = kAttributeResidualAlphabetSize;
symbolCoder[k2].encode(alphabetSize, &arithmeticEncoder);
symbolCoder[k3].encode(alphabetSize, &arithmeticEncoder);
arithmeticEncoder.encodeExpGolomb(
value - alphabetSize, 0, binaryModel0, binaryModelDiff[k1]);
}
......@@ -169,11 +169,13 @@ PCCResidualsEncoder::encode(uint32_t value0, uint32_t value1, uint32_t value2)
value2--;
}
int b0 = value0 == 0;
int b1 = value1 == 0;
encodeSymbol(value0, 0, 0);
encodeSymbol(value1, 1 + b0, 1);
encodeSymbol(value2, 3 + (b0 << 1) + b1, 1);
int b0 = (value0 == 0);
int b1 = (value0 <= 1);
int b2 = (value1 == 0);
int b3 = (value1 <= 1);
encodeSymbol(value0, 0, 0, 0);
encodeSymbol(value1, 1 + b0, 1 + b1, 1);
encodeSymbol(value2, 3 + (b0 << 1) + b2, 3 + (b1 << 1) + b3, 1);
}
//----------------------------------------------------------------------------
......@@ -181,7 +183,7 @@ PCCResidualsEncoder::encode(uint32_t value0, uint32_t value1, uint32_t value2)
void
PCCResidualsEncoder::encode(uint32_t value)
{
encodeSymbol(value - 1, 0, 0);
encodeSymbol(value - 1, 0, 0, 0);
}
//============================================================================
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment