From 4513708c95af671028b11f19ae12e963a0989bd4 Mon Sep 17 00:00:00 2001 From: AltoXorg Date: Wed, 10 Apr 2024 13:15:01 +0800 Subject: [PATCH] Fix CI texture depth when png export --- lib/n64graphics/n64graphics.c | 50 +++++++++++++++----------------- lib/n64graphics/n64graphics.h | 2 +- src/factories/TextureFactory.cpp | 2 +- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/lib/n64graphics/n64graphics.c b/lib/n64graphics/n64graphics.c index 9008bab..6dbcc22 100644 --- a/lib/n64graphics/n64graphics.c +++ b/lib/n64graphics/n64graphics.c @@ -823,31 +823,29 @@ const char* n64graphics_get_write_version(void) { /** * Converts binary ci8 + palette to a single .png */ -int convert_raw_to_ci8(unsigned char **png_output, int *size_output, uint8_t *texture, uint8_t *palette, int format, int width, int height, int depth) { -FILE *pal_fp; - uint8_t *pal; - uint8_t *raw_fmt; - rgba *imgr; - ia *imgi; - int pal_size; - int res; +int convert_raw_to_ci8(unsigned char **png_output, int *size_output, uint8_t *texture, uint8_t *palette, int format, int width, int height, int depth, int pal_depth) { + uint8_t *raw_fmt; + rgba *imgr; + ia *imgi; + int res; - raw_fmt = ci2raw(texture, palette, width, height, depth); - switch (format) { - case IMG_FORMAT_RGBA: - INFO("Converting raw to RGBA16\n"); - imgr = raw2rgba(raw_fmt, width, height, depth); - res = rgba2png(png_output, size_output, imgr, width, height); - break; - case IMG_FORMAT_IA: - INFO("Converting raw to IA16\n"); - imgi = raw2ia(raw_fmt, width, height, depth); - //res = ia2png(name, imgi, width, height); - break; - default: - //ERROR("Unsupported palette format: %s\n", format2str(&config.pal_format)); - return EXIT_FAILURE; - } - free(raw_fmt); - free(pal); + raw_fmt = ci2raw(texture, palette, width, height, depth); + switch (format) { + case IMG_FORMAT_RGBA: + INFO("Converting raw to RGBA%d\n", pal_depth); + imgr = raw2rgba(raw_fmt, width, height, pal_depth); + res = rgba2png(png_output, size_output, imgr, width, height); + free(imgr); + break; + case IMG_FORMAT_IA: + INFO("Converting raw to IA%d\n", pal_depth); + imgi = raw2ia(raw_fmt, width, height, pal_depth); + //res = ia2png(name, imgi, width, height); + free(imgi); + break; + default: + //ERROR("Unsupported palette format: %s\n", format2str(&config.pal_format)); + return EXIT_FAILURE; + } + free(raw_fmt); } \ No newline at end of file diff --git a/lib/n64graphics/n64graphics.h b/lib/n64graphics/n64graphics.h index 1488f79..98cbdcd 100644 --- a/lib/n64graphics/n64graphics.h +++ b/lib/n64graphics/n64graphics.h @@ -53,7 +53,7 @@ ia *raw2i(const uint8_t *raw, int width, int height, int depth); // N64 raw CI4/CI8 -> intermediate CI ci *raw2ci_torch(const uint8_t* raw, int width, int height, int depth); -int convert_raw_to_ci8(unsigned char **png_output, int *size_output, uint8_t *texture, uint8_t *palette, int format, int width, int height, int depth); +int convert_raw_to_ci8(unsigned char **png_output, int *size_output, uint8_t *texture, uint8_t *palette, int format, int width, int height, int depth, int pal_depth); int imgpal2rawci(uint8_t *rawci, const rgba *img, const rgba *pal, const uint8_t *wheel_mask, int raw_size, int ci_depth, int img_size, int pal_size); diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp index 5eb188d..d2166d4 100644 --- a/src/factories/TextureFactory.cpp +++ b/src/factories/TextureFactory.cpp @@ -260,7 +260,7 @@ ExportResult TextureModdingExporter::Export(std::ostream&write, std::shared_ptr< auto palettePtr = tlutTextureMap[tlut]; if (palettePtr) { - convert_raw_to_ci8(&raw, &size, texture->mBuffer.data(), (uint8_t *)palettePtr->mBuffer.data(), 0, texture->mWidth, texture->mHeight, palettePtr->mFormat.depth); + convert_raw_to_ci8(&raw, &size, texture->mBuffer.data(), (uint8_t *)palettePtr->mBuffer.data(), 0, texture->mWidth, texture->mHeight, texture->mFormat.depth, palettePtr->mFormat.depth); } else { auto symbol = GetSafeNode(node, "symbol");