Commit 3465fa34 authored by Khaled Mammou's avatar Khaled Mammou Committed by David Flynn
Browse files

hls: fix signalling of 64-bit dist2 values

This commit fixes an error in the hls: dist2 is capable of being a
64-bit value and must not be signalled as 32-bit.
parent ef31aa90
......@@ -66,9 +66,17 @@ public:
void writeUe(uint32_t value);
// NB: probably best to think twice before using this method
void writeUe64(uint64_t value);
template<typename T>
void writeUe(const T& value)
{
// Avoid accidental truncation
constexpr bool use_writeUe64 =
std::is_same<uint64_t, T>::value || std::is_same<int64_t, T>::value;
static_assert(!use_writeUe64, "use explicit writeUe64()");
writeUe(uint32_t(value));
}
......@@ -161,6 +169,18 @@ BitWriter<OutputIt>::writeUe(uint32_t value)
//----------------------------------------------------------------------------
template<class OutputIt>
void
BitWriter<OutputIt>::writeUe64(uint64_t value)
{
value++;
int len = ilog2(value);
writeUn(len, 0);
writeUn(len + 1, value);
}
//----------------------------------------------------------------------------
template<class OutputIt>
void
BitWriter<OutputIt>::writeSe(int32_t value)
......
......@@ -109,6 +109,22 @@ ceilpow2(uint32_t x)
return x + 1;
}
//---------------------------------------------------------------------------
// Round @x up to next power of two.
//
inline uint64_t
ceilpow2(uint64_t x)
{
x--;
x = x | (x >> 1);
x = x | (x >> 2);
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >> 16);
x = x | (x >> 32);
return x + 1;
}
//---------------------------------------------------------------------------
// Compute \left\floor \text{log}_2(x) \right\floor.
// NB: ilog2(0) = -1.
......@@ -120,6 +136,17 @@ ilog2(uint32_t x)
return popcnt(x) - 1;
}
//---------------------------------------------------------------------------
// Compute \left\floor \text{log}_2(x) \right\floor.
// NB: ilog2(0) = -1.
inline int
ilog2(uint64_t x)
{
x = ceilpow2(x + 1) - 1;
return popcnt(uint32_t(x >> 32)) + popcnt(uint32_t(x)) - 1;
}
//---------------------------------------------------------------------------
// Compute \left\ceil \text{log}_2(x) \right\ceil.
// NB: ceillog2(0) = 32.
......
......@@ -301,7 +301,7 @@ inline void
PCCBuildLevelOfDetail2(
const PCCPointSet3& pointCloud,
const int levelOfDetailCount,
const std::vector<int>& dist2,
const std::vector<int64_t>& dist2,
std::vector<uint32_t>& numberOfPointsPerLOD,
std::vector<uint32_t>& indexes)
{
......@@ -412,7 +412,7 @@ inline void
PCCBuildLevelOfDetail(
const PCCPointSet3& pointCloud,
const int levelOfDetailCount,
const std::vector<int>& dist2,
const std::vector<int64_t>& dist2,
std::vector<uint32_t>& numberOfPointsPerLOD,
std::vector<uint32_t>& indexes)
{
......
......@@ -239,7 +239,7 @@ struct AttributeParameterSet {
// NB: derived from num_detail_levels_minus1
int numDetailLevels;
std::vector<int> dist2;
std::vector<int64_t> dist2;
// NB: these parameters are shared by raht and lift
std::vector<int> quant_step_size_luma;
......
......@@ -253,7 +253,8 @@ write(const AttributeParameterSet& aps)
int num_detail_levels_minus1 = aps.numDetailLevels - 1;
bs.writeUe(num_detail_levels_minus1);
for (int idx = 0; idx <= num_detail_levels_minus1; idx++) {
bs.writeUe(aps.dist2[idx]);
// todo(??): is this an appropriate encoding?
bs.writeUe64(aps.dist2[idx]);
bs.writeUe(aps.quant_step_size_luma[idx]);
if (chroma_quant_steps_present_flag)
bs.writeUe(aps.quant_step_size_chroma[idx]);
......
Supports Markdown
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