41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
#include <algorithm>
|
|
|
|
#include "PaletteDecoder.hh"
|
|
#include "exceptions.hh"
|
|
|
|
PaletteDecoder::PaletteDecoder(Resource const& res)
|
|
: iff_(res)
|
|
{
|
|
auto& root = iff_.getRoot();
|
|
if (!root.isForm())
|
|
throw FormatException{"Root node not FORM"};
|
|
|
|
auto& rootForm = dynamic_cast<IffFile::Form const&>(root);
|
|
if (rootForm.getSubtype() != "PALT")
|
|
throw FormatException{"Root form not PALT"};
|
|
|
|
for (auto paltIt = rootForm.childrenBegin();paltIt != rootForm.childrenEnd();++paltIt) {
|
|
if (paltIt->getType() == "INFO") {
|
|
} else if (paltIt->getType() == "PALT") {
|
|
std::transform(paltIt->begin()+4, paltIt->begin()+772,
|
|
palette_.begin(),
|
|
[](const char& in) -> uint8_t {return (in << 2) | ((in >> 6)&0x3);});
|
|
uint8_t min = 0xff, max = 0;
|
|
for (auto it = paltIt->begin()+4;it != paltIt->end();++it) {
|
|
if (*it == 0xff)
|
|
continue;
|
|
min = std::min(min, *it);
|
|
max = std::max(max, *it);
|
|
}
|
|
|
|
printf("palt value range %hhu..%hhu\n", min, max);
|
|
} else if (paltIt->getType() == "BLWH") {
|
|
auto dstIt = palette_.begin();
|
|
for (auto it = paltIt->begin()+4;it != paltIt->end();++it) {
|
|
*dstIt = *dstIt * ((*it << 2) | ((*it >> 6)&0x3)) / 255u;
|
|
++dstIt;
|
|
}
|
|
}
|
|
}
|
|
}
|