mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 23:30:04 +00:00
Raster Data Packet RLE decoding to levels
This commit is contained in:
parent
0b761185a0
commit
5b32118626
2 changed files with 31 additions and 1 deletions
|
|
@ -37,6 +37,8 @@ public:
|
||||||
uint16_t number_of_rows() const;
|
uint16_t number_of_rows() const;
|
||||||
uint16_t packaging_descriptor() const;
|
uint16_t packaging_descriptor() const;
|
||||||
|
|
||||||
|
const std::vector<uint8_t>& level(uint16_t r) const;
|
||||||
|
|
||||||
size_t data_size() const override;
|
size_t data_size() const override;
|
||||||
|
|
||||||
bool Parse(std::istream& is) override;
|
bool Parse(std::istream& is) override;
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,9 @@ public:
|
||||||
{
|
{
|
||||||
uint16_t numberOfBytes_;
|
uint16_t numberOfBytes_;
|
||||||
std::vector<uint8_t> data_;
|
std::vector<uint8_t> data_;
|
||||||
|
std::vector<uint8_t> level_;
|
||||||
|
|
||||||
Row() : numberOfBytes_ {0}, data_ {} {}
|
Row() : numberOfBytes_ {0}, data_ {}, level_ {} {}
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit RasterDataPacketImpl() :
|
explicit RasterDataPacketImpl() :
|
||||||
|
|
@ -120,6 +121,11 @@ uint16_t RasterDataPacket::packaging_descriptor() const
|
||||||
return p->packagingDescriptor_;
|
return p->packagingDescriptor_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<uint8_t>& RasterDataPacket::level(uint16_t r) const
|
||||||
|
{
|
||||||
|
return p->row_[r].level_;
|
||||||
|
}
|
||||||
|
|
||||||
size_t RasterDataPacket::data_size() const
|
size_t RasterDataPacket::data_size() const
|
||||||
{
|
{
|
||||||
return p->dataSize_;
|
return p->dataSize_;
|
||||||
|
|
@ -212,6 +218,28 @@ bool RasterDataPacket::Parse(std::istream& is)
|
||||||
{
|
{
|
||||||
row.data_.pop_back();
|
row.data_.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unpack the levels from the Run Length Encoded data
|
||||||
|
uint16_t binCount =
|
||||||
|
std::accumulate(row.data_.cbegin(),
|
||||||
|
row.data_.cend(),
|
||||||
|
0,
|
||||||
|
[](const uint16_t& a, const uint8_t& b) -> uint16_t
|
||||||
|
{ return a + (b >> 4); });
|
||||||
|
|
||||||
|
row.level_.resize(binCount);
|
||||||
|
|
||||||
|
uint16_t b = 0;
|
||||||
|
for (auto it = row.data_.cbegin(); it != row.data_.cend(); it++)
|
||||||
|
{
|
||||||
|
uint8_t run = *it >> 4;
|
||||||
|
uint8_t level = *it & 0x0f;
|
||||||
|
|
||||||
|
for (int i = 0; i < run && b < binCount; i++)
|
||||||
|
{
|
||||||
|
row.level_[b++] = level;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue