1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-08-18 13:00:23 +00:00

git subrepo pull --force tools/ZAPD (#1251)

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "f54f2fa96"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "f54f2fa96"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"
This commit is contained in:
louist103 2022-06-02 18:48:52 -04:00 committed by GitHub
parent 0a95d17aa8
commit 5015af4c57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 3382 additions and 3094 deletions

View file

@ -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);
@ -350,34 +417,42 @@ void ZTexture::DeclareReferences([[maybe_unused]] const std::string& prefix)
void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath)
{
textureData.ReadPng(pngFilePath);
width = textureData.GetWidth();
height = textureData.GetHeight();
textureDataRaw.clear();
textureDataRaw.resize(ALIGN8(GetRawDataSize()));
switch (format)
{
case TextureType::RGBA16bpp:
PrepareRawDataRGBA16(pngFilePath);
PrepareRawDataRGBA16();
break;
case TextureType::RGBA32bpp:
PrepareRawDataRGBA32(pngFilePath);
PrepareRawDataRGBA32();
break;
case TextureType::Grayscale4bpp:
PrepareRawDataGrayscale4(pngFilePath);
PrepareRawDataGrayscale4();
break;
case TextureType::Grayscale8bpp:
PrepareRawDataGrayscale8(pngFilePath);
PrepareRawDataGrayscale8();
break;
case TextureType::GrayscaleAlpha4bpp:
PrepareRawDataGrayscaleAlpha4(pngFilePath);
PrepareRawDataGrayscaleAlpha4();
break;
case TextureType::GrayscaleAlpha8bpp:
PrepareRawDataGrayscaleAlpha8(pngFilePath);
PrepareRawDataGrayscaleAlpha8();
break;
case TextureType::GrayscaleAlpha16bpp:
PrepareRawDataGrayscaleAlpha16(pngFilePath);
PrepareRawDataGrayscaleAlpha16();
break;
case TextureType::Palette4bpp:
PrepareRawDataPalette4(pngFilePath);
PrepareRawDataPalette4();
break;
case TextureType::Palette8bpp:
PrepareRawDataPalette8(pngFilePath);
PrepareRawDataPalette8();
break;
case TextureType::Error:
HANDLE_ERROR_PROCESS(WarningType::InvalidPNG, "Input PNG file has invalid format type", "");
@ -385,15 +460,8 @@ void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath)
}
}
void ZTexture::PrepareRawDataRGBA16(const fs::path& rgbaPath)
void ZTexture::PrepareRawDataRGBA16()
{
textureData.ReadPng(rgbaPath);
width = textureData.GetWidth();
height = textureData.GetHeight();
textureDataRaw.clear();
textureDataRaw.resize(GetRawDataSize());
for (uint16_t y = 0; y < height; y++)
{
for (uint16_t x = 0; x < width; x++)
@ -415,15 +483,8 @@ void ZTexture::PrepareRawDataRGBA16(const fs::path& rgbaPath)
}
}
void ZTexture::PrepareRawDataRGBA32(const fs::path& rgbaPath)
void ZTexture::PrepareRawDataRGBA32()
{
textureData.ReadPng(rgbaPath);
width = textureData.GetWidth();
height = textureData.GetHeight();
textureDataRaw.clear();
textureDataRaw.resize(GetRawDataSize());
for (uint16_t y = 0; y < height; y++)
{
for (uint16_t x = 0; x < width; x++)
@ -439,15 +500,8 @@ void ZTexture::PrepareRawDataRGBA32(const fs::path& rgbaPath)
}
}
void ZTexture::PrepareRawDataGrayscale4(const fs::path& grayPath)
void ZTexture::PrepareRawDataGrayscale4()
{
textureData.ReadPng(grayPath);
width = textureData.GetWidth();
height = textureData.GetHeight();
textureDataRaw.clear();
textureDataRaw.resize(GetRawDataSize());
for (uint16_t y = 0; y < height; y++)
{
for (uint16_t x = 0; x < width; x += 2)
@ -461,15 +515,8 @@ void ZTexture::PrepareRawDataGrayscale4(const fs::path& grayPath)
}
}
void ZTexture::PrepareRawDataGrayscale8(const fs::path& grayPath)
void ZTexture::PrepareRawDataGrayscale8()
{
textureData.ReadPng(grayPath);
width = textureData.GetWidth();
height = textureData.GetHeight();
textureDataRaw.clear();
textureDataRaw.resize(GetRawDataSize());
for (uint16_t y = 0; y < height; y++)
{
for (uint16_t x = 0; x < width; x++)
@ -481,15 +528,8 @@ void ZTexture::PrepareRawDataGrayscale8(const fs::path& grayPath)
}
}
void ZTexture::PrepareRawDataGrayscaleAlpha4(const fs::path& grayAlphaPath)
void ZTexture::PrepareRawDataGrayscaleAlpha4()
{
textureData.ReadPng(grayAlphaPath);
width = textureData.GetWidth();
height = textureData.GetHeight();
textureDataRaw.clear();
textureDataRaw.resize(GetRawDataSize());
for (uint16_t y = 0; y < height; y++)
{
for (uint16_t x = 0; x < width; x += 2)
@ -514,15 +554,8 @@ void ZTexture::PrepareRawDataGrayscaleAlpha4(const fs::path& grayAlphaPath)
}
}
void ZTexture::PrepareRawDataGrayscaleAlpha8(const fs::path& grayAlphaPath)
void ZTexture::PrepareRawDataGrayscaleAlpha8()
{
textureData.ReadPng(grayAlphaPath);
width = textureData.GetWidth();
height = textureData.GetHeight();
textureDataRaw.clear();
textureDataRaw.resize(GetRawDataSize());
for (uint16_t y = 0; y < height; y++)
{
for (uint16_t x = 0; x < width; x++)
@ -538,15 +571,8 @@ void ZTexture::PrepareRawDataGrayscaleAlpha8(const fs::path& grayAlphaPath)
}
}
void ZTexture::PrepareRawDataGrayscaleAlpha16(const fs::path& grayAlphaPath)
void ZTexture::PrepareRawDataGrayscaleAlpha16()
{
textureData.ReadPng(grayAlphaPath);
width = textureData.GetWidth();
height = textureData.GetHeight();
textureDataRaw.clear();
textureDataRaw.resize(GetRawDataSize());
for (uint16_t y = 0; y < height; y++)
{
for (uint16_t x = 0; x < width; x++)
@ -563,15 +589,8 @@ void ZTexture::PrepareRawDataGrayscaleAlpha16(const fs::path& grayAlphaPath)
}
}
void ZTexture::PrepareRawDataPalette4(const fs::path& palPath)
void ZTexture::PrepareRawDataPalette4()
{
textureData.ReadPng(palPath);
width = textureData.GetWidth();
height = textureData.GetHeight();
textureDataRaw.clear();
textureDataRaw.resize(GetRawDataSize());
for (uint16_t y = 0; y < height; y++)
{
for (uint16_t x = 0; x < width; x += 2)
@ -586,15 +605,8 @@ void ZTexture::PrepareRawDataPalette4(const fs::path& palPath)
}
}
void ZTexture::PrepareRawDataPalette8(const fs::path& palPath)
void ZTexture::PrepareRawDataPalette8()
{
textureData.ReadPng(palPath);
width = textureData.GetWidth();
height = textureData.GetHeight();
textureDataRaw.clear();
textureDataRaw.resize(GetRawDataSize());
for (uint16_t y = 0; y < height; y++)
{
for (uint16_t x = 0; x < width; x++)
@ -926,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