Commit 1105149f authored by Danillo Bracco Graziosi's avatar Danillo Bracco Graziosi Committed by David Flynn
Browse files

attr/m48918: use multiplicative inverse for quantisation

This commit exploits the use of fixed quantisation step sizes (due to
QP) to perform quantisation using multiplication by the reciprocal step
size.
parent 46efadca
......@@ -47,6 +47,7 @@ Quantizer::Quantizer(int qp)
{
int qpShift = qp / 6;
_stepSize = kQpStep[qp % 6] << qpShift;
_stepSizeRecip = kQpStepRecip[qp % 6] >> qpShift;
}
//============================================================================
......
......@@ -37,6 +37,8 @@
#include <array>
#include "constants.h"
namespace pcc {
struct AttributeParameterSet;
......@@ -64,6 +66,9 @@ public:
private:
// Quantisation step size
int _stepSize;
// Reciprocal stepsize for forward quantisation optimisation
int _stepSizeRecip;
};
//---------------------------------------------------------------------------
......@@ -71,12 +76,18 @@ private:
inline int64_t
Quantizer::quantize(int64_t x) const
{
const int64_t shift = _stepSize / 3;
// Forward quantisation avoids division by using the multiplicative inverse
// with 14 fractional bits.
int64_t fracBits = 14 + kFixedPointAttributeShift;
// NB, the folowing offsets quantizes with a different deadzone to the
// reconstruction function.
int64_t offset = (1ll << fracBits) / 3;
if (x >= 0) {
return (x + shift) / _stepSize;
return (x * _stepSizeRecip + offset) >> fracBits;
}
return -((shift - x) / _stepSize);
return -((offset - x * _stepSizeRecip) >> fracBits);
}
//---------------------------------------------------------------------------
......
......@@ -444,4 +444,7 @@ const uint32_t pcc::kMortonCode256X[256] = {
const int16_t pcc::kQpStep[6] = {161, 181, 203, 228, 256, 287};
const int32_t pcc::kQpStepRecip[6] = {26052, 23173, 20662,
18396, 16384, 14614};
//============================================================================
......@@ -102,6 +102,12 @@ extern const uint32_t kMortonCode256Z[256];
//============================================================================
// Base quantisation step sizes
extern const int16_t kQpStep[6];
// Reciprocal step size to avoid division during quantisation
extern const int32_t kQpStepRecip[6];
//============================================================================
} /* namespace pcc */
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