Block should be lightweight so don't store palette.

This commit is contained in:
King_DuckZ 2020-03-20 14:58:36 +01:00
parent 905e6be0c4
commit c5987d882d
3 changed files with 8 additions and 4 deletions

View file

@ -41,7 +41,7 @@ public:
static constexpr std::size_t size() { return FrameSize * 64; }
const std::vector<uint8_t>& palette() const { return m_icon_palette; }
std::vector<uint8_t> palette() const;
bool has_magic() const;
IconDisplayFlag icon_display_flag() const;
int block_count() const;
@ -49,7 +49,6 @@ public:
std::string title() const;
private:
std::vector<uint8_t> m_icon_palette;
std::size_t m_index;
data_type* m_begin;
};

View file

@ -67,7 +67,6 @@ namespace {
template <bool Const>
BasicBlock<Const>::BasicBlock (data_type* beg, std::size_t index) :
m_icon_palette(extract_palette(beg, beg + size())),
m_index(index),
m_begin(beg)
{
@ -97,6 +96,12 @@ auto BasicBlock<Const>::frame(unsigned int idx) const -> const data_type* {
return this->begin() + FrameSize * idx;
}
template <bool Const>
std::vector<uint8_t> BasicBlock<Const>::palette() const {
const auto ptr = frame(0);
return extract_palette(ptr, ptr + FrameSize);
}
template <bool Const>
bool BasicBlock<Const>::has_magic() const {
const constexpr uint16_t magic = ('S' << 8) | 'C'; //0x5343 "SC"

View file

@ -119,7 +119,7 @@ namespace {
std::vector<std::vector<char>> icon_fetch (const psx::ConstBlock& block, int width, int height) {
const constexpr int in_height = 16, in_width = 16;
const bool scale = (in_width != width or in_height != height);
const std::vector<uint8_t>& palette = block.palette();
const std::vector<uint8_t> palette = block.palette();
assert(palette.size() == 16 * 4);
const int32_t palette_padded_size = (not scale) * (((palette.size() * CHAR_BIT + 31) bitand ~31) / CHAR_BIT);
assert(palette.size() == static_cast<std::size_t>(palette_padded_size) or scale);