summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Companion.cpp9
-rw-r--r--src/factories/TextureFactory.cpp36
-rw-r--r--src/utils/Decompressor.cpp6
-rw-r--r--src/utils/Decompressor.h2
4 files changed, 43 insertions, 10 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp
index ba0df34..ae568ef 100644
--- a/src/Companion.cpp
+++ b/src/Companion.cpp
@@ -64,12 +64,14 @@ void Companion::ExtractNode(YAML::Node& node, std::string& name, SWrapper* binar
auto type = GetSafeNode<std::string>(node, "type");
std::transform(type.begin(), type.end(), type.begin(), ::toupper);
+ spdlog::set_pattern(regular);
if(node["offset"]) {
auto offset = node["offset"].as<uint32_t>();
- SPDLOG_INFO("[{}] Processing {} at 0x{:X}", type, name, offset);
+ SPDLOG_INFO("- [{}] Processing {} at 0x{:X}", type, name, offset);
} else {
- SPDLOG_INFO("[{}] Processing {}", type, name);
+ SPDLOG_INFO("- [{}] Processing {}", type, name);
}
+ spdlog::set_pattern(line);
auto factory = this->GetFactory(type);
if(!factory.has_value()){
@@ -97,6 +99,9 @@ void Companion::ExtractNode(YAML::Node& node, std::string& name, SWrapper* binar
std::replace(doutput.begin(), doutput.end(), '\\', '/');
this->gAssetDependencies[this->gCurrentFile][fst].second = true;
this->ExtractNode(snd.first, doutput, binary);
+ spdlog::set_pattern(regular);
+ SPDLOG_INFO("------------------------------------------------");
+ spdlog::set_pattern(line);
}
switch (this->gConfig.exporterType) {
diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp
index cb1b520..df81174 100644
--- a/src/factories/TextureFactory.cpp
+++ b/src/factories/TextureFactory.cpp
@@ -17,6 +17,32 @@ static const std::unordered_map <std::string, TextureType> gTextureTypes = {
{ "IA16", TextureType::GrayscaleAlpha16bpp },
};
+size_t CalculateTextureSize(TextureType type, uint32_t width, uint32_t height) {
+ switch (type) {
+ // 4 bytes per pixel
+ case TextureType::RGBA32bpp:
+ return width * height * 4;
+ // 2 bytes per pixel
+ case TextureType::RGBA16bpp:
+ case TextureType::GrayscaleAlpha16bpp:
+ return width * height * 2;
+ // 1 byte per pixel
+ case TextureType::Grayscale8bpp:
+ case TextureType::Palette8bpp:
+ case TextureType::GrayscaleAlpha8bpp:
+ // TODO: We need to validate this MegaMech
+ case TextureType::GrayscaleAlpha1bpp:
+ return width * height;
+ // 1/2 byte per pixel
+ case TextureType::Palette4bpp:
+ case TextureType::Grayscale4bpp:
+ case TextureType::GrayscaleAlpha4bpp:
+ return (width * height) / 2;
+ default:
+ return 0;
+ }
+}
+
std::vector<uint8_t> alloc_ia8_text_from_i1(uint16_t *in, int16_t width, int16_t height) {
int32_t inPos;
uint16_t bitMask;
@@ -110,7 +136,7 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui
auto format = GetSafeNode<std::string>(node, "format");
auto width = GetSafeNode<uint32_t>(node, "width");
auto height = GetSafeNode<uint32_t>(node, "height");
- auto size = GetSafeNode<uint32_t>(node, "size");
+ auto size = GetSafeNode<uint32_t>(node, "size", CalculateTextureSize(gTextureTypes.at(format), width, height));
auto offset = Decompressor::TranslateAddr(GetSafeNode<uint32_t>(node, "offset"));
if (format.empty()) {
@@ -126,7 +152,7 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui
TextureType type = gTextureTypes.at(format);
- auto [_, segment] = Decompressor::AutoDecode(node, buffer);
+ auto [_, segment] = Decompressor::AutoDecode(node, buffer, size);
std::vector<uint8_t> result;
if(type == TextureType::GrayscaleAlpha1bpp){
@@ -135,10 +161,12 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui
result = std::vector(segment.data, segment.data + segment.size);
}
- SPDLOG_INFO("Texture: {} {}x{} {}", format, width, height, size);
+ SPDLOG_INFO("Texture: {}", format);
+ SPDLOG_INFO("Width: {}", width);
+ SPDLOG_INFO("Height: {}", height);
+ SPDLOG_INFO("Size: {}", size);
SPDLOG_INFO("Offset: 0x{:X}", offset);
SPDLOG_INFO("Is Compressed: {}", Decompressor::IsCompressed(node) ? "true" : "false");
- SPDLOG_INFO("Size: {}", result.size());
if(result.size() == 0){
return std::nullopt;
diff --git a/src/utils/Decompressor.cpp b/src/utils/Decompressor.cpp
index 7de4338..a53177b 100644
--- a/src/utils/Decompressor.cpp
+++ b/src/utils/Decompressor.cpp
@@ -35,7 +35,7 @@ DataChunk* Decompressor::Decode(const std::vector<uint8_t>& buffer, const uint32
}
}
-DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>& buffer) {
+DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>& buffer, std::optional<size_t> manualSize) {
if(!node["offset"]){
throw std::runtime_error("Failed to find offset");
}
@@ -45,7 +45,7 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>
if(node["mio0"]){
const auto mio0 = node["mio0"].as<uint32_t>();
auto decoded = Decode(buffer, offset, CompressionType::MIO0);
- auto size = node["size"] ? node["size"].as<size_t>() : decoded->size - mio0;
+ auto size = node["size"] ? node["size"].as<size_t>() : manualSize.value_or(decoded->size - mio0);
return {
.root = decoded,
@@ -63,7 +63,7 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>
return {
.root = nullptr,
- .segment = { buffer.data() + offset, node["size"] ? node["size"].as<size_t>() : buffer.size() - offset }
+ .segment = { buffer.data() + offset, node["size"] ? node["size"].as<size_t>() : manualSize.value_or(buffer.size() - offset) }
};
}
diff --git a/src/utils/Decompressor.h b/src/utils/Decompressor.h
index 1bd5c05..4e3c298 100644
--- a/src/utils/Decompressor.h
+++ b/src/utils/Decompressor.h
@@ -26,7 +26,7 @@ struct DecompressedData {
class Decompressor {
public:
static DataChunk* Decode(const std::vector<uint8_t>& buffer, uint32_t offset, CompressionType type);
- static DecompressedData AutoDecode(YAML::Node& node, std::vector<uint8_t>& buffer);
+ static DecompressedData AutoDecode(YAML::Node& node, std::vector<uint8_t>& buffer, std::optional<size_t> size = std::nullopt);
static uint32_t TranslateAddr(uint32_t addr);
static bool IsSegmented(uint32_t addr);
static bool IsCompressed(YAML::Node& node);