1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-08-16 12:02:50 +00:00

Update ZAPD (#1569)

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "094e79734"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "094e79734"
git-subrepo:
  version:  "0.4.6"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "110b9eb"

* Add EnumData.xml where some names are now externalized

* Remove legacy typedefs for zapd, no longer needed!
This commit is contained in:
Dragorn421 2023-10-25 03:36:10 +02:00 committed by GitHub
parent 503f6d86d5
commit 4e55168eaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
97 changed files with 4225 additions and 2328 deletions

View file

@ -137,31 +137,31 @@ void ZTexture::ParseRawData()
switch (format)
{
case TextureType::RGBA16bpp:
PrepareBitmapRGBA16();
ConvertN64ToBitmap_RGBA16();
break;
case TextureType::RGBA32bpp:
PrepareBitmapRGBA32();
ConvertN64ToBitmap_RGBA32();
break;
case TextureType::Grayscale4bpp:
PrepareBitmapGrayscale4();
ConvertN64ToBitmap_Grayscale4();
break;
case TextureType::Grayscale8bpp:
PrepareBitmapGrayscale8();
ConvertN64ToBitmap_Grayscale8();
break;
case TextureType::GrayscaleAlpha4bpp:
PrepareBitmapGrayscaleAlpha4();
ConvertN64ToBitmap_GrayscaleAlpha4();
break;
case TextureType::GrayscaleAlpha8bpp:
PrepareBitmapGrayscaleAlpha8();
ConvertN64ToBitmap_GrayscaleAlpha8();
break;
case TextureType::GrayscaleAlpha16bpp:
PrepareBitmapGrayscaleAlpha16();
ConvertN64ToBitmap_GrayscaleAlpha16();
break;
case TextureType::Palette4bpp:
PrepareBitmapPalette4();
ConvertN64ToBitmap_Palette4();
break;
case TextureType::Palette8bpp:
PrepareBitmapPalette8();
ConvertN64ToBitmap_Palette8();
break;
case TextureType::Error:
HANDLE_ERROR_RESOURCE(WarningType::InvalidAttributeValue, parent, this, rawDataIndex,
@ -212,10 +212,10 @@ void ZTexture::ParseRawDataLate()
}
}
void ZTexture::PrepareBitmapRGBA16()
void ZTexture::ConvertN64ToBitmap_RGBA16()
{
textureData.InitEmptyRGBImage(width, height, true);
auto parentRawData = parent->GetRawData();
const auto& parentRawData = parent->GetRawData();
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x++)
@ -227,15 +227,16 @@ void ZTexture::PrepareBitmapRGBA16()
uint8_t b = (data & 0x003E) >> 1;
uint8_t alpha = data & 0x01;
textureData.SetRGBPixel(y, x, r * 8, g * 8, b * 8, alpha * 255);
textureData.SetRGBPixel(y, x, (r << 3) | (r >> 2), (g << 3) | (g >> 2),
(b << 3) | (b >> 2), alpha * 255);
}
}
}
void ZTexture::PrepareBitmapRGBA32()
void ZTexture::ConvertN64ToBitmap_RGBA32()
{
textureData.InitEmptyRGBImage(width, height, true);
auto parentRawData = parent->GetRawData();
const auto& parentRawData = parent->GetRawData();
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x++)
@ -251,10 +252,10 @@ void ZTexture::PrepareBitmapRGBA32()
}
}
void ZTexture::PrepareBitmapGrayscale4()
void ZTexture::ConvertN64ToBitmap_Grayscale4()
{
textureData.InitEmptyRGBImage(width, height, false);
auto parentRawData = parent->GetRawData();
const auto& parentRawData = parent->GetRawData();
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x += 2)
@ -269,16 +270,16 @@ void ZTexture::PrepareBitmapGrayscale4()
else
grayscale = (parentRawData.at(pos) & 0x0F) << 4;
textureData.SetGrayscalePixel(y, x + i, grayscale);
textureData.SetGrayscalePixel(y, x + i, (grayscale << 4) | grayscale);
}
}
}
}
void ZTexture::PrepareBitmapGrayscale8()
void ZTexture::ConvertN64ToBitmap_Grayscale8()
{
textureData.InitEmptyRGBImage(width, height, false);
auto parentRawData = parent->GetRawData();
const auto& parentRawData = parent->GetRawData();
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x++)
@ -290,10 +291,10 @@ void ZTexture::PrepareBitmapGrayscale8()
}
}
void ZTexture::PrepareBitmapGrayscaleAlpha4()
void ZTexture::ConvertN64ToBitmap_GrayscaleAlpha4()
{
textureData.InitEmptyRGBImage(width, height, true);
auto parentRawData = parent->GetRawData();
const auto& parentRawData = parent->GetRawData();
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x += 2)
@ -308,8 +309,9 @@ void ZTexture::PrepareBitmapGrayscaleAlpha4()
else
data = parentRawData.at(pos) & 0x0F;
uint8_t grayscale = ((data & 0x0E) >> 1) * 32;
uint8_t alpha = (data & 0x01) * 255;
uint8_t grayscale = data & 0b1110;
grayscale = (grayscale << 4) | (grayscale << 1) | (grayscale >> 2);
uint8_t alpha = (data & 0x01) ? 255 : 0;
textureData.SetGrayscalePixel(y, x + i, grayscale, alpha);
}
@ -317,27 +319,32 @@ void ZTexture::PrepareBitmapGrayscaleAlpha4()
}
}
void ZTexture::PrepareBitmapGrayscaleAlpha8()
void ZTexture::ConvertN64ToBitmap_GrayscaleAlpha8()
{
textureData.InitEmptyRGBImage(width, height, true);
auto parentRawData = parent->GetRawData();
const auto& parentRawData = parent->GetRawData();
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x++)
{
size_t pos = rawDataIndex + ((y * width) + x) * 1;
uint8_t grayscale = parentRawData.at(pos) & 0xF0;
uint8_t alpha = (parentRawData.at(pos) & 0x0F) << 4;
uint8_t pixel = parentRawData.at(pos);
uint8_t data = (pixel >> 4) & 0xF;
data = (data << 4) | data;
uint8_t grayscale = data;
uint8_t alpha = (pixel & 0xF);
alpha = (alpha << 4) | alpha;
textureData.SetGrayscalePixel(y, x, grayscale, alpha);
}
}
}
void ZTexture::PrepareBitmapGrayscaleAlpha16()
void ZTexture::ConvertN64ToBitmap_GrayscaleAlpha16()
{
textureData.InitEmptyRGBImage(width, height, true);
auto parentRawData = parent->GetRawData();
const auto& parentRawData = parent->GetRawData();
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x++)
@ -351,10 +358,10 @@ void ZTexture::PrepareBitmapGrayscaleAlpha16()
}
}
void ZTexture::PrepareBitmapPalette4()
void ZTexture::ConvertN64ToBitmap_Palette4()
{
textureData.InitEmptyPaletteImage(width, height);
auto parentRawData = parent->GetRawData();
const auto& parentRawData = parent->GetRawData();
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x += 2)
@ -375,10 +382,10 @@ void ZTexture::PrepareBitmapPalette4()
}
}
void ZTexture::PrepareBitmapPalette8()
void ZTexture::ConvertN64ToBitmap_Palette8()
{
textureData.InitEmptyPaletteImage(width, height);
auto parentRawData = parent->GetRawData();
const auto& parentRawData = parent->GetRawData();
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < width; x++)
@ -428,31 +435,31 @@ void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath)
switch (format)
{
case TextureType::RGBA16bpp:
PrepareRawDataRGBA16();
ConvertBitmapToN64_RGBA16();
break;
case TextureType::RGBA32bpp:
PrepareRawDataRGBA32();
ConvertBitmapToN64_RGBA32();
break;
case TextureType::Grayscale4bpp:
PrepareRawDataGrayscale4();
ConvertBitmapToN64_Grayscale4();
break;
case TextureType::Grayscale8bpp:
PrepareRawDataGrayscale8();
ConvertBitmapToN64_Grayscale8();
break;
case TextureType::GrayscaleAlpha4bpp:
PrepareRawDataGrayscaleAlpha4();
ConvertBitmapToN64_GrayscaleAlpha4();
break;
case TextureType::GrayscaleAlpha8bpp:
PrepareRawDataGrayscaleAlpha8();
ConvertBitmapToN64_GrayscaleAlpha8();
break;
case TextureType::GrayscaleAlpha16bpp:
PrepareRawDataGrayscaleAlpha16();
ConvertBitmapToN64_GrayscaleAlpha16();
break;
case TextureType::Palette4bpp:
PrepareRawDataPalette4();
ConvertBitmapToN64_Palette4();
break;
case TextureType::Palette8bpp:
PrepareRawDataPalette8();
ConvertBitmapToN64_Palette8();
break;
case TextureType::Error:
HANDLE_ERROR_PROCESS(WarningType::InvalidPNG, "Input PNG file has invalid format type", "");
@ -460,7 +467,7 @@ void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath)
}
}
void ZTexture::PrepareRawDataRGBA16()
void ZTexture::ConvertBitmapToN64_RGBA16()
{
for (uint16_t y = 0; y < height; y++)
{
@ -469,13 +476,13 @@ void ZTexture::PrepareRawDataRGBA16()
size_t pos = ((y * width) + x) * 2;
RGBAPixel pixel = textureData.GetPixel(y, x);
uint8_t r = pixel.r / 8;
uint8_t g = pixel.g / 8;
uint8_t b = pixel.b / 8;
uint8_t r = pixel.r >> 3;
uint8_t g = pixel.g >> 3;
uint8_t b = pixel.b >> 3;
uint8_t alphaBit = pixel.a != 0;
uint16_t data = (r << 11) + (g << 6) + (b << 1) + alphaBit;
uint16_t data = (r << 11) | (g << 6) | (b << 1) | alphaBit;
textureDataRaw[pos + 0] = (data & 0xFF00) >> 8;
textureDataRaw[pos + 1] = (data & 0x00FF);
@ -483,7 +490,7 @@ void ZTexture::PrepareRawDataRGBA16()
}
}
void ZTexture::PrepareRawDataRGBA32()
void ZTexture::ConvertBitmapToN64_RGBA32()
{
for (uint16_t y = 0; y < height; y++)
{
@ -500,7 +507,7 @@ void ZTexture::PrepareRawDataRGBA32()
}
}
void ZTexture::PrepareRawDataGrayscale4()
void ZTexture::ConvertBitmapToN64_Grayscale4()
{
for (uint16_t y = 0; y < height; y++)
{
@ -515,7 +522,7 @@ void ZTexture::PrepareRawDataGrayscale4()
}
}
void ZTexture::PrepareRawDataGrayscale8()
void ZTexture::ConvertBitmapToN64_Grayscale8()
{
for (uint16_t y = 0; y < height; y++)
{
@ -528,7 +535,7 @@ void ZTexture::PrepareRawDataGrayscale8()
}
}
void ZTexture::PrepareRawDataGrayscaleAlpha4()
void ZTexture::ConvertBitmapToN64_GrayscaleAlpha4()
{
for (uint16_t y = 0; y < height; y++)
{
@ -544,9 +551,9 @@ void ZTexture::PrepareRawDataGrayscaleAlpha4()
uint8_t alphaBit = pixel.a != 0;
if (i == 0)
data |= (((cR / 32) << 1) + alphaBit) << 4;
data = (((cR >> 5) << 1) | alphaBit) << 4;
else
data |= ((cR / 32) << 1) + alphaBit;
data |= ((cR >> 5) << 1) | alphaBit;
}
textureDataRaw[pos] = data;
@ -554,7 +561,7 @@ void ZTexture::PrepareRawDataGrayscaleAlpha4()
}
}
void ZTexture::PrepareRawDataGrayscaleAlpha8()
void ZTexture::ConvertBitmapToN64_GrayscaleAlpha8()
{
for (uint16_t y = 0; y < height; y++)
{
@ -563,15 +570,15 @@ void ZTexture::PrepareRawDataGrayscaleAlpha8()
size_t pos = ((y * width) + x) * 1;
RGBAPixel pixel = textureData.GetPixel(y, x);
uint8_t r = pixel.r;
uint8_t a = pixel.a;
uint8_t r = (pixel.r >> 4) & 0xF;
uint8_t a = (pixel.a >> 4) & 0xF;
textureDataRaw[pos] = ((r / 16) << 4) + (a / 16);
textureDataRaw[pos] = (r << 4) | a;
}
}
}
void ZTexture::PrepareRawDataGrayscaleAlpha16()
void ZTexture::ConvertBitmapToN64_GrayscaleAlpha16()
{
for (uint16_t y = 0; y < height; y++)
{
@ -589,7 +596,7 @@ void ZTexture::PrepareRawDataGrayscaleAlpha16()
}
}
void ZTexture::PrepareRawDataPalette4()
void ZTexture::ConvertBitmapToN64_Palette4()
{
for (uint16_t y = 0; y < height; y++)
{
@ -605,7 +612,7 @@ void ZTexture::PrepareRawDataPalette4()
}
}
void ZTexture::PrepareRawDataPalette8()
void ZTexture::ConvertBitmapToN64_Palette8()
{
for (uint16_t y = 0; y < height; y++)
{
@ -770,10 +777,10 @@ Declaration* ZTexture::DeclareVar(const std::string& prefix,
auto filepath = Globals::Instance->outputPath / fs::path(auxOutName).stem();
if (dWordAligned)
incStr =
StringHelper::Sprintf("%s.%s.inc.c", filepath.c_str(), GetExternalExtension().c_str());
incStr = StringHelper::Sprintf("%s.%s.inc.c", filepath.string().c_str(),
GetExternalExtension().c_str());
else
incStr = StringHelper::Sprintf("%s.u32.%s.inc.c", filepath.c_str(),
incStr = StringHelper::Sprintf("%s.u32.%s.inc.c", filepath.string().c_str(),
GetExternalExtension().c_str());
if (!Globals::Instance->cfg.texturePool.empty())
@ -785,18 +792,31 @@ Declaration* ZTexture::DeclareVar(const std::string& prefix,
if (poolEntry != Globals::Instance->cfg.texturePool.end())
{
if (dWordAligned)
incStr = StringHelper::Sprintf("%s.%s.inc.c", poolEntry->second.path.c_str(),
GetExternalExtension().c_str());
incStr =
StringHelper::Sprintf("%s.%s.inc.c", poolEntry->second.path.string().c_str(),
GetExternalExtension().c_str());
else
incStr = StringHelper::Sprintf("%s.u32.%s.inc.c", poolEntry->second.path.c_str(),
incStr = StringHelper::Sprintf("%s.u32.%s.inc.c",
poolEntry->second.path.string().c_str(),
GetExternalExtension().c_str());
}
}
size_t texSizeDivisor = (dWordAligned) ? 8 : 4;
Declaration* decl = parent->AddDeclarationIncludeArray(rawDataIndex, incStr, GetRawDataSize(),
GetSourceTypeName(), auxName,
GetRawDataSize() / texSizeDivisor);
Declaration* decl;
if (parent->makeDefines)
{
decl = parent->AddDeclarationIncludeArray(rawDataIndex, incStr, GetRawDataSize(),
GetSourceTypeName(), auxName, GetHeaderDefines(),
GetRawDataSize() / texSizeDivisor);
}
else
{
decl = parent->AddDeclarationIncludeArray(rawDataIndex, incStr, GetRawDataSize(),
GetSourceTypeName(), auxName,
GetRawDataSize() / texSizeDivisor);
}
decl->staticConf = staticConf;
return decl;
}
@ -827,6 +847,17 @@ std::string ZTexture::GetBodySourceCode() const
return sourceOutput;
}
std::string ZTexture::GetHeaderDefines() const
{
std::string definePrefix = StringHelper::camelCaseTo_SCREAMING_SNAKE_CASE(name.c_str(), true);
std::string ret = StringHelper::Sprintf("#define %s_WIDTH %d\n", definePrefix.c_str(), width);
ret += StringHelper::Sprintf("#define %s_HEIGHT %d\n", definePrefix.c_str(), height);
ret += StringHelper::Sprintf("#define %s_SIZE 0x%zX\n", definePrefix.c_str(), GetRawDataSize());
return ret;
}
bool ZTexture::IsExternalResource() const
{
return true;
@ -844,7 +875,7 @@ std::string ZTexture::GetSourceTypeName() const
void ZTexture::CalcHash()
{
auto parentRawData = parent->GetRawData();
const auto& parentRawData = parent->GetRawData();
hash = CRC32B(parentRawData.data() + rawDataIndex, GetRawDataSize());
}