summaryrefslogtreecommitdiff
path: root/ZAPD/ZTexture.cpp
diff options
context:
space:
mode:
authorlouist103 <35883445+louist103@users.noreply.github.com>2022-06-02 13:20:36 -0400
committerGitHub <noreply@github.com>2022-06-02 13:20:36 -0400
commitf54f2fa96bfc476a15fcc3ebcd6124bc19164fcd (patch)
tree1f3eff4a540daef6a8679ba2b78c4580185d73dd /ZAPD/ZTexture.cpp
parent87cb648b4311d20673452111edaf4d38a5290c28 (diff)
Extract palette data from external file (#249)
* WIP * Done * Fix * Fixes * More fixes * Fixes for backgrounds. * Roman's fixes and format. * Update docs and use tinyxml function for validation. * Update docs/zapd_extraction_xml_reference.md Co-authored-by: EllipticEllipsis <elliptic.ellipsis@gmail.com> * move tlut texture data to stack variable Co-authored-by: EllipticEllipsis <elliptic.ellipsis@gmail.com>
Diffstat (limited to 'ZAPD/ZTexture.cpp')
-rw-r--r--ZAPD/ZTexture.cpp69
1 files changed, 68 insertions, 1 deletions
diff --git a/ZAPD/ZTexture.cpp b/ZAPD/ZTexture.cpp
index a9cb539..74b7c7d 100644
--- a/ZAPD/ZTexture.cpp
+++ b/ZAPD/ZTexture.cpp
@@ -17,11 +17,15 @@ ZTexture::ZTexture(ZFile* nParent) : ZResource(nParent)
width = 0;
height = 0;
dWordAligned = true;
+ splitTlut = false;
RegisterRequiredAttribute("Width");
RegisterRequiredAttribute("Height");
RegisterRequiredAttribute("Format");
RegisterOptionalAttribute("TlutOffset");
+ RegisterOptionalAttribute("ExternalTlut");
+ RegisterOptionalAttribute("ExternalTlutOffset");
+ RegisterOptionalAttribute("SplitTlut");
}
void ZTexture::ExtractFromBinary(uint32_t nRawDataIndex, int32_t nWidth, int32_t nHeight,
@@ -56,6 +60,7 @@ void ZTexture::ParseXML(tinyxml2::XMLElement* reader)
std::string widthXml = registeredAttributes.at("Width").value;
std::string heightXml = registeredAttributes.at("Height").value;
+ std::string SplitTlutXml = registeredAttributes.at("SplitTlut").value;
if (!StringHelper::HasOnlyDigits(widthXml))
{
@@ -72,6 +77,27 @@ void ZTexture::ParseXML(tinyxml2::XMLElement* reader)
errorHeader, "");
}
+ if (!registeredAttributes.at("ExternalTlut").wasSet &&
+ registeredAttributes.at("SplitTlut").wasSet)
+ {
+ std::string errorHeader =
+ StringHelper::Sprintf("SplitTlut set without using an external tlut");
+ HANDLE_WARNING_RESOURCE(WarningType::InvalidAttributeValue, parent, this, rawDataIndex,
+ errorHeader, "");
+ }
+
+ if (!SplitTlutXml.empty())
+ {
+ if (!tinyxml2::XMLUtil::ToBool(SplitTlutXml.c_str(), &splitTlut))
+ {
+ std::string errorHeader = StringHelper::Sprintf(
+ "Invalid value passed to SplitTlut: '%s'. Valid values are true, false, 1, 0",
+ SplitTlutXml.c_str());
+ HANDLE_ERROR_RESOURCE(WarningType::InvalidAttributeValue, parent, this, rawDataIndex,
+ errorHeader, "");
+ }
+ }
+
width = StringHelper::StrToL(widthXml);
height = StringHelper::StrToL(heightXml);
@@ -145,6 +171,47 @@ void ZTexture::ParseRawData()
}
}
+void ZTexture::ParseRawDataLate()
+{
+ if (registeredAttributes["ExternalTlut"].wasSet)
+ {
+ const std::string externPalette = registeredAttributes["ExternalTlut"].value;
+ for (const auto& file : Globals::Instance->files)
+ {
+ if (file->GetName() == externPalette)
+ {
+ offset_t palOffset = 0;
+ if (registeredAttributes["ExternalTlutOffset"].wasSet)
+ {
+ palOffset =
+ StringHelper::StrToL(registeredAttributes["ExternalTlutOffset"].value, 16);
+ }
+ else
+ {
+ HANDLE_WARNING_RESOURCE(
+ WarningType::MissingOffsets, parent, this, rawDataIndex,
+ StringHelper::Sprintf(
+ "No ExternalTlutOffset Given. Assuming offset of 0x0"),
+ "");
+ }
+ for (const auto& res : file->resources)
+ {
+ if (res->GetRawDataIndex() == palOffset)
+ {
+ ZTexture* palette = (ZTexture*)res;
+ ZTexture tlutTemp(file);
+
+ tlut = &tlutTemp;
+ tlut->ExtractFromBinary(palOffset, palette->width, palette->height,
+ TextureType::RGBA16bpp, true);
+ SetTlut(tlut);
+ }
+ }
+ }
+ }
+ }
+}
+
void ZTexture::PrepareBitmapRGBA16()
{
textureData.InitEmptyRGBImage(width, height, true);
@@ -871,7 +938,7 @@ void ZTexture::SetTlut(ZTexture* nTlut)
assert(nTlut->isPalette);
tlut = nTlut;
- textureData.SetPalette(tlut->textureData);
+ textureData.SetPalette(tlut->textureData, splitTlut ? 128 : 0);
}
bool ZTexture::HasTlut() const