Skip to content
4 changes: 4 additions & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ const char* Config::hotkeyIniName(u32 _idx)
return "hkHdTexReload";
case Config::HotKey::hkHdTexToggle:
return "hkHdTexToggle";
case Config::HotKey::hkMipMap:
return "hkMipMap";
case Config::HotKey::hkTexCoordBounds:
return "hkTexCoordBounds";
case Config::HotKey::hkNativeResTexrects:
Expand Down Expand Up @@ -224,6 +226,8 @@ const char* Config::enabledHotkeyIniName(u32 _idx)
return "hkHdTexReloadEnabled";
case Config::HotKey::hkHdTexToggle:
return "hkHdTexToggleEnabled";
case Config::HotKey::hkMipMap:
return "hkMipMapEnabled";
case Config::HotKey::hkTexCoordBounds:
return "hkTexCoordBoundsEnabled";
case Config::HotKey::hkNativeResTexrects:
Expand Down
1 change: 1 addition & 0 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ struct Config
hkTexDump = 0,
hkHdTexReload,
hkHdTexToggle,
hkMipMap,
hkTexCoordBounds,
hkNativeResTexrects,
hkVsync,
Expand Down
117 changes: 77 additions & 40 deletions src/GLideNHQ/TxFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,83 +572,120 @@ TxFilter::hirestex(uint64 g64crc, Checksum r_crc64, uint16 *palette, N64FormatSi
}

uint64
TxFilter::checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
TxFilter::checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed)
{
if (_options & (HIRESTEXTURES_MASK|DUMP_TEX))
return TxUtil::checksum64(src, width, height, size, rowStride, palette);
return TxUtil::checksum64(src, width, height, size, rowStride, palette, seed);

return 0;
}

uint64
TxFilter::checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
TxFilter::checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed)
{
if (_options & (HIRESTEXTURES_MASK | DUMP_TEX))
return TxUtil::checksum64strong(src, width, height, size, rowStride, palette);
return TxUtil::checksum64strong(src, width, height, size, rowStride, palette, seed);

return 0;
}

tx_wstring
TxFilter::getTexDumpPath(boolean isStrongCrc)
{
if (_dumpPath.empty() || _ident.empty())
return tx_wstring();

tx_wstring path;
path.assign(_dumpPath);
path.append(wst("/"));
path.append(_ident);
isStrongCrc ? path.append(wst("/GLideNHQ_strong_crc")) : path.append(wst("/GLideNHQ"));
return path;
}

tx_wstring
TxFilter::getMipMapTexDumpPath(N64FormatSize n64FmtSz, Checksum detailedTileCRC, Checksum firstTileCRC, boolean isStrongCrc)
{
tx_wstring path = getTexDumpPath(isStrongCrc);
if (path.empty())
return path;

wchar_t wbuf[256];
if (detailedTileCRC._texture != 0u) {
tx_swprintf(wbuf, 256, wst("/%ls#%08X_detail"), _ident.c_str(), detailedTileCRC._texture);
path.append(wbuf);
}
if (firstTileCRC._texture != 0u) {
tx_swprintf(wbuf, 256, wst("/%ls#%08X_mipmap"), _ident.c_str(), firstTileCRC._texture);
path.append(wbuf);
}

return path;
}

boolean
TxFilter::dmptx(uint8 *src, int width, int height, int rowStridePixel,
ColorFormat gfmt, N64FormatSize n64FmtSz, Checksum r_crc64, boolean isStrongCrc)
TxFilter::dmptxImpl(uint8 *src, int width, int height, int rowStridePixel,
ColorFormat gfmt, N64FormatSize n64FmtSz, Checksum r_crc64, tx_wstring const& texDumpPath)
{
assert(gfmt != graphics::colorFormat::RGBA);
if (!_initialized)
return 0;

if (!(_options & DUMP_TEX))
if (!_initialized || !(_options & DUMP_TEX) || texDumpPath.empty())
return 0;

DBG_INFO(80, wst("gfmt = %02x n64fmt = %02x\n"), u32(gfmt), n64FmtSz._format);
DBG_INFO(80, wst("hirestex: r_crc64:%08X %08X\n"),
r_crc64._palette, r_crc64._texture);
r_crc64._palette, r_crc64._texture);

if (gfmt != graphics::internalcolorFormat::RGBA8) {
if (!_txQuantize->quantize(src, _tex1, rowStridePixel, height, gfmt, graphics::internalcolorFormat::RGBA8))
return 0;
src = _tex1;
}

if (!_dumpPath.empty() && !_ident.empty()) {
/* dump it to disk */
FILE *fp = nullptr;
tx_wstring tmpbuf;

/* create directories */
tmpbuf.assign(_dumpPath);
tmpbuf.append(wst("/"));
tmpbuf.append(_ident);
isStrongCrc ? tmpbuf.append(wst("/GLideNHQ_strong_crc")) : tmpbuf.append(wst("/GLideNHQ"));
if (!osal_path_existsW(tmpbuf.c_str()) && osal_mkdirp(tmpbuf.c_str()) != 0)
return 0;
/* dump it to disk */
FILE *fp = nullptr;
tx_wstring tmpbuf = texDumpPath;

if (n64FmtSz._format == 0x2) {
wchar_t wbuf[256];
tx_swprintf(wbuf, 256, wst("/%ls#%08X#%01X#%01X#%08X_ciByRGBA.png"), _ident.c_str(), r_crc64._texture, n64FmtSz._format, n64FmtSz._size, r_crc64._palette);
tmpbuf.append(wbuf);
} else {
wchar_t wbuf[256];
tx_swprintf(wbuf, 256, wst("/%ls#%08X#%01X#%01X_all.png"), _ident.c_str(), r_crc64._texture, n64FmtSz._format, n64FmtSz._size);
tmpbuf.append(wbuf);
}
/* create directories */
if (!osal_path_existsW(tmpbuf.c_str()) && osal_mkdirp(tmpbuf.c_str()) != 0)
return 0;

wchar_t wbuf[256];
if (n64FmtSz._format == 0x2)
tx_swprintf(wbuf, 256, wst("/%ls#%08X#%01X#%01X#%08X_ciByRGBA.png"), _ident.c_str(), r_crc64._texture, n64FmtSz._format, n64FmtSz._size, r_crc64._palette);
else
tx_swprintf(wbuf, 256, wst("/%ls#%08X#%01X#%01X_all.png"), _ident.c_str(), r_crc64._texture, n64FmtSz._format, n64FmtSz._size);
tmpbuf.append(wbuf);

#ifdef OS_WINDOWS
if ((fp = _wfopen(tmpbuf.c_str(), wst("wb"))) != nullptr) {
if ((fp = _wfopen(tmpbuf.c_str(), wst("wb"))) != nullptr) {
#else
char cbuf[MAX_PATH];
wcstombs(cbuf, tmpbuf.c_str(), MAX_PATH);
if ((fp = fopen(cbuf, "wb")) != nullptr) {
char cbuf[MAX_PATH];
wcstombs(cbuf, tmpbuf.c_str(), MAX_PATH);
if ((fp = fopen(cbuf, "wb")) != nullptr) {
#endif
_txImage->writePNG(src, fp, width, height, (rowStridePixel << 2), graphics::internalcolorFormat::RGBA8);
fclose(fp);
return 1;
}
_txImage->writePNG(src, fp, width, height, (rowStridePixel << 2), graphics::internalcolorFormat::RGBA8);
fclose(fp);
return 1;
}

return 0;
}

boolean
TxFilter::dmptx(uint8 *src, int width, int height, int rowStridePixel,
ColorFormat gfmt, N64FormatSize n64FmtSz, Checksum r_crc64, boolean isStrongCrc)
{
return dmptxImpl(src, width, height, rowStridePixel, gfmt, n64FmtSz, r_crc64, getTexDumpPath(isStrongCrc));
}

boolean
TxFilter::dmptxMipmap(uint8 *src, int width, int height, int rowStridePixel,
ColorFormat gfmt, N64FormatSize n64FmtSz, Checksum detailedTileCRC, Checksum firstTileCRC, Checksum tileCRC, boolean isStrongCrc)
{
tx_wstring path = getMipMapTexDumpPath(n64FmtSz, detailedTileCRC, firstTileCRC, isStrongCrc);
return dmptxImpl(src, width, height, rowStridePixel, gfmt, n64FmtSz, tileCRC, path);
}

boolean
TxFilter::reloadhirestex()
{
Expand Down
11 changes: 9 additions & 2 deletions src/GLideNHQ/TxFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class TxFilter
TxImage *_txImage;
boolean _initialized;
void clear();
tx_wstring getTexDumpPath(boolean isStrongCrc);
tx_wstring getMipMapTexDumpPath(N64FormatSize n64FmtSz, Checksum detailedTileCRC, Checksum firstTileCRC, boolean isStrongCrc);
boolean dmptxImpl(uint8 *src, int width, int height, int rowStridePixel,
ColorFormat gfmt, N64FormatSize n64FmtSz, Checksum r_crc64, tx_wstring const& texDumpPath);

public:
~TxFilter();
TxFilter(int maxwidth,
Expand All @@ -77,10 +82,12 @@ class TxFilter
uint16 *palette,
N64FormatSize n64FmtSz,
GHQTexInfo *info);
uint64 checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
uint64 checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
uint64 checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed);
uint64 checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed);
boolean dmptx(uint8 *src, int width, int height, int rowStridePixel,
ColorFormat gfmt, N64FormatSize n64FmtSz, Checksum r_crc64, boolean isStrongCrc);
boolean dmptxMipmap(uint8 *src, int width, int height, int rowStridePixel,
ColorFormat gfmt, N64FormatSize n64FmtSz, Checksum detailedTileCRC, Checksum firstTileCRC, Checksum tileCRC, boolean isStrongCrc);
boolean reloadhirestex();
void dumpcache();
};
Expand Down
18 changes: 14 additions & 4 deletions src/GLideNHQ/TxFilterExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ txfilter_hirestex(uint64 g64crc, Checksum r_crc64, uint16 *palette, N64FormatSiz
}

TAPI uint64 TAPIENTRY
txfilter_checksum(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
txfilter_checksum(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed)
{
if (txFilter)
return txFilter->checksum64(src, width, height, size, rowStride, palette);
return txFilter->checksum64(src, width, height, size, rowStride, palette, seed);

return 0;
}

TAPI uint64 TAPIENTRY
txfilter_checksum_strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
txfilter_checksum_strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed)
{
if (txFilter)
return txFilter->checksum64strong(src, width, height, size, rowStride, palette);
return txFilter->checksum64strong(src, width, height, size, rowStride, palette, seed);

return 0;
}
Expand All @@ -111,6 +111,16 @@ txfilter_dmptx_strong(uint8 *src, int width, int height, int rowStridePixel, uin
return 0;
}

TAPI boolean TAPIENTRY
txfilter_dmptx_mipmap(uint8 *src, int width, int height, int rowStridePixel, uint16 gfmt, N64FormatSize n64FmtSz,
Checksum detailedTileCRC, Checksum firstTileCRC, Checksum tileCRC, boolean isStrongCRC)
{
if (txFilter)
return txFilter->dmptxMipmap(src, width, height, rowStridePixel, ColorFormat(u32(gfmt)), n64FmtSz, detailedTileCRC, firstTileCRC, tileCRC, isStrongCRC);

return 0;
}

TAPI boolean TAPIENTRY
txfilter_reloadhirestex()
{
Expand Down
8 changes: 6 additions & 2 deletions src/GLideNHQ/TxFilterExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,21 @@ TAPI boolean TAPIENTRY
txfilter_hirestex(uint64 g64crc, Checksum r_crc64, uint16 *palette, N64FormatSize n64FmtSz, GHQTexInfo *info);

TAPI uint64 TAPIENTRY
txfilter_checksum(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
txfilter_checksum(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed);

TAPI uint64 TAPIENTRY
txfilter_checksum_strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
txfilter_checksum_strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed);

TAPI boolean TAPIENTRY
txfilter_dmptx(uint8 *src, int width, int height, int rowStridePixel, uint16 gfmt, N64FormatSize n64FmtSz, Checksum r_crc64);

TAPI boolean TAPIENTRY
txfilter_dmptx_strong(uint8 *src, int width, int height, int rowStridePixel, uint16 gfmt, N64FormatSize n64FmtSz, Checksum r_crc64);

TAPI boolean TAPIENTRY
txfilter_dmptx_mipmap(uint8 *src, int width, int height, int rowStridePixel, uint16 gfmt, N64FormatSize n64FmtSz,
Checksum detailedTileCRC, Checksum firstTileCRC, Checksum tileCRC, boolean isStrongCRC);

TAPI boolean TAPIENTRY
txfilter_reloadhirestex();

Expand Down
Loading