2015-08-11 23:32:02 +00:00
|
|
|
#ifndef _DNACOMMON_ANIMBITSTREAM_HPP_
|
|
|
|
#define _DNACOMMON_ANIMBITSTREAM_HPP_
|
|
|
|
|
|
|
|
#include "DNACommon.hpp"
|
2016-09-11 18:38:44 +00:00
|
|
|
#include <cmath>
|
2015-08-11 23:32:02 +00:00
|
|
|
|
2016-02-13 09:02:47 +00:00
|
|
|
namespace DataSpec
|
2015-08-11 23:32:02 +00:00
|
|
|
{
|
|
|
|
namespace DNAANIM
|
|
|
|
{
|
|
|
|
|
|
|
|
union Value
|
|
|
|
{
|
|
|
|
atVec3f v3;
|
|
|
|
atVec4f v4;
|
|
|
|
Value(atVec3f v) : v3(v) {}
|
|
|
|
Value(atVec4f v) : v4(v) {}
|
|
|
|
Value(float x, float y, float z)
|
|
|
|
{
|
|
|
|
v3.vec[0] = x;
|
|
|
|
v3.vec[1] = y;
|
|
|
|
v3.vec[2] = z;
|
|
|
|
v4.vec[3] = 0.0;
|
|
|
|
}
|
2015-08-13 21:29:07 +00:00
|
|
|
Value(float w, float x, float y, float z)
|
|
|
|
{
|
|
|
|
v4.vec[0] = w;
|
|
|
|
v4.vec[1] = x;
|
|
|
|
v4.vec[2] = y;
|
|
|
|
v4.vec[3] = z;
|
|
|
|
}
|
2015-08-11 23:32:02 +00:00
|
|
|
};
|
|
|
|
struct QuantizedValue
|
|
|
|
{
|
2016-08-26 22:23:59 +00:00
|
|
|
atInt32 v[4];
|
|
|
|
atInt32& operator[] (size_t idx)
|
2015-08-11 23:32:02 +00:00
|
|
|
{return v[idx];}
|
2016-08-26 22:23:59 +00:00
|
|
|
const atInt32& operator[] (size_t idx) const
|
2015-08-11 23:32:02 +00:00
|
|
|
{return v[idx];}
|
2016-09-10 05:39:47 +00:00
|
|
|
|
|
|
|
int qFrom(const QuantizedValue& other, size_t idx) const
|
|
|
|
{
|
|
|
|
atInt32 delta = std::abs(v[idx] - other.v[idx]);
|
|
|
|
if (delta == 0)
|
|
|
|
return 1;
|
2016-09-11 18:38:44 +00:00
|
|
|
return int(std::ceil(std::log2(delta))) + 1;
|
2016-09-10 05:39:47 +00:00
|
|
|
}
|
2015-08-11 23:32:02 +00:00
|
|
|
};
|
|
|
|
struct QuantizedRot
|
|
|
|
{
|
|
|
|
QuantizedValue v;
|
|
|
|
bool w;
|
|
|
|
};
|
|
|
|
struct Channel
|
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
enum class Type
|
2015-08-11 23:32:02 +00:00
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
Rotation,
|
|
|
|
Translation,
|
|
|
|
Scale,
|
|
|
|
KfHead,
|
|
|
|
RotationMP3
|
2015-08-11 23:32:02 +00:00
|
|
|
} type;
|
2016-04-08 03:30:00 +00:00
|
|
|
atInt32 id = -1;
|
2015-08-11 23:32:02 +00:00
|
|
|
QuantizedValue i = {};
|
2015-09-26 03:12:08 +00:00
|
|
|
atUint8 q[4] = {};
|
2015-08-11 23:32:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
size_t ComputeBitstreamSize(size_t keyFrameCount, const std::vector<Channel>& channels);
|
|
|
|
|
|
|
|
class BitstreamReader
|
|
|
|
{
|
|
|
|
size_t m_bitCur;
|
2016-08-26 22:23:59 +00:00
|
|
|
atInt32 dequantize(const atUint8* data, atUint8 q);
|
2015-08-13 21:29:07 +00:00
|
|
|
bool dequantizeBit(const atUint8* data);
|
2015-08-11 23:32:02 +00:00
|
|
|
public:
|
|
|
|
std::vector<std::vector<Value>>
|
|
|
|
read(const atUint8* data,
|
|
|
|
size_t keyFrameCount,
|
|
|
|
const std::vector<Channel>& channels,
|
|
|
|
atUint32 rotDiv,
|
2016-08-26 22:23:59 +00:00
|
|
|
float transMult,
|
|
|
|
float scaleMult);
|
2015-08-11 23:32:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BitstreamWriter
|
|
|
|
{
|
|
|
|
size_t m_bitCur;
|
2016-08-26 22:23:59 +00:00
|
|
|
void quantize(atUint8* data, atUint8 q, atInt32 val);
|
2015-08-13 21:29:07 +00:00
|
|
|
void quantizeBit(atUint8* data, bool val);
|
2015-08-11 23:32:02 +00:00
|
|
|
public:
|
|
|
|
std::unique_ptr<atUint8[]>
|
|
|
|
write(const std::vector<std::vector<Value>>& chanKeys,
|
|
|
|
size_t keyFrameCount, std::vector<Channel>& channels,
|
2016-08-26 22:23:59 +00:00
|
|
|
atUint32 quantRange,
|
2015-08-11 23:32:02 +00:00
|
|
|
atUint32& rotDivOut,
|
|
|
|
float& transMultOut,
|
2016-08-26 22:23:59 +00:00
|
|
|
float& scaleMultOut,
|
2015-08-11 23:32:02 +00:00
|
|
|
size_t& sizeOut);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _DNACOMMON_ANIMBITSTREAM_HPP_
|