From f35cca8b0b96f1700220ec3ec0f93de40e9453e2 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Fri, 5 Feb 2021 10:02:53 +0000 Subject: [PATCH] build images --- configure.py | 26 +++++++++++++++++++++++--- src/battle/item/coconut/coconut.c | 4 ++-- src/battle/item/coconut/coconut.h | 3 +++ tools/convert_image.py | 1 + tools/splat/segtypes/n64/ci8.py | 4 ++-- tools/splat/segtypes/n64/code.py | 6 ++++-- tools/splat/segtypes/segment.py | 4 ++++ 7 files changed, 39 insertions(+), 9 deletions(-) diff --git a/configure.py b/configure.py index 506e92ca77..6ce0dabb5f 100755 --- a/configure.py +++ b/configure.py @@ -31,6 +31,7 @@ def obj(path: str): def read_splat(splat_config: str): import argparse import yaml + from segtypes.n64.code import N64SegCode # Load config with open(splat_config) as f: @@ -52,6 +53,17 @@ def read_splat(splat_config: str): objects.add(path) segments[path] = segment + if isinstance(segment, N64SegCode): + for split_file in segment.files: + if split_file["subtype"] in ["ci4", "palette"]: + path = os.path.join( + "src", + split_file["name"] + "." + segment.get_ext(split_file["subtype"]) + ) + + if path in segments: + segments[path] = split_file + # note: `objects` lacks .o extensions return objects, segments @@ -102,13 +114,11 @@ def build_image(f: str, segment): out = "$builddir/" + path + "." + img_type + ".png" flags = "" - """ if img_type != "palette": if segment.flip_horizontal: flags += "--flip-x" if segment.flip_vertical: flags += "--flip-y" - """ n.build(out, "img", path + ".png", implicit="tools/convert_image.py", variables={ "img_type": img_type, @@ -413,7 +423,17 @@ async def main(): elif f.endswith(".s"): n.build(obj(f), "as", f) elif f.endswith(".png"): - build_image(f, segment) + if isinstance(segment, dict): + # image within a code section + out = "$builddir/" + f + ".bin" + n.build(out, "img", f, implicit="tools/convert_image.py", variables={ + "img_type": segment["subtype"], + "img_flags": "", + }) + + n.build("$builddir/" + f + ".o", "bin", out) + else: + build_image(f, segment) elif f == "sprite/npc": # combine sprites n.build(f"$builddir/{f}.bin", "npc_sprites", npc_sprite_yay0s, implicit="tools/compile_npc_sprites.py") diff --git a/src/battle/item/coconut/coconut.c b/src/battle/item/coconut/coconut.c index 6256c55b66..b77d05b80c 100644 --- a/src/battle/item/coconut/coconut.c +++ b/src/battle/item/coconut/coconut.c @@ -15,8 +15,8 @@ Gfx D_802A1A60_7303C0[] = { gsDPSetTextureFilter(G_TF_AVERAGE), gsDPSetTextureConvert(G_TC_FILT), gsDPSetTextureLUT(G_TT_RGBA16), - gsDPLoadTLUT_pal16(0, &D_802A1A00_730360), - gsDPLoadTextureTile_4b(&D_802A1800_730160, G_IM_FMT_CI, 32, 0, 0, 0, 31, 31, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD), + gsDPLoadTLUT_pal16(0, &battle_item_coconut_coconut_png), + gsDPLoadTextureTile_4b(&battle_item_coconut_coconut_png, G_IM_FMT_CI, 32, 0, 0, 0, 31, 31, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD), gsSPClearGeometryMode(G_LIGHTING), gsSPClearGeometryMode(G_SHADING_SMOOTH), gsSPVertex(&D_802A1A20_730380, 4, 0), diff --git a/src/battle/item/coconut/coconut.h b/src/battle/item/coconut/coconut.h index 045a6ac453..88662054f4 100644 --- a/src/battle/item/coconut/coconut.h +++ b/src/battle/item/coconut/coconut.h @@ -7,6 +7,9 @@ #undef NAMESPACE #define NAMESPACE battle_item_coconut +Script D_802A1240_72F960; +Script D_802A1670_72FFD0; + ApiStatus func_802A1000_72F720(ScriptInstance* script, s32 isInitialCall); ApiStatus func_802A11D4_72F8F4(ScriptInstance* script, s32 isInitialCall); diff --git a/tools/convert_image.py b/tools/convert_image.py index d9fc14a4d7..3af7c35735 100755 --- a/tools/convert_image.py +++ b/tools/convert_image.py @@ -83,6 +83,7 @@ class Converter(): for row in reversed_if(img.read()[2], self.flip_y): for a, b in iter_in_groups(row, 2): byte = (a << 4) | b + byte = byte & 0xFF f.write(byte.to_bytes(1, byteorder="big")) elif self.mode == "palette": img.preamble(True) diff --git a/tools/splat/segtypes/n64/ci8.py b/tools/splat/segtypes/n64/ci8.py index 483a45683b..626d259b19 100644 --- a/tools/splat/segtypes/n64/ci8.py +++ b/tools/splat/segtypes/n64/ci8.py @@ -18,7 +18,7 @@ class N64SegCi8(N64SegRgba16): if self.compressed: data = Yay0decompress.decompress_yay0(data) - self.image = N64SegCi8.parse_image(data) + self.image = type(self).parse_image(data, self.width, self.height) def postsplit(self, segments): palettes = [seg for seg in segments if seg.type == @@ -53,7 +53,7 @@ class N64SegCi8(N64SegRgba16): f"No unnamed palette for {self.name}; wrote image data to {self.path}") @staticmethod - def parse_image(data): + def parse_image(data, width, height): return data def max_length(self): diff --git a/tools/splat/segtypes/n64/code.py b/tools/splat/segtypes/n64/code.py index fba4ed89ea..bc0d4db0cc 100644 --- a/tools/splat/segtypes/n64/code.py +++ b/tools/splat/segtypes/n64/code.py @@ -849,7 +849,7 @@ class N64SegCode(N64Segment): split_file["name"] + "." + self.get_ext(split_file["subtype"]) ) - if file_type == "ci4": + if file_type == "ci4" and (file_type in self.options["modes"] or "all" in self.options["modes"] or "img" in self.options["modes"]): from segtypes.n64.ci4 import N64SegCi4 width, height = split_file["args"] @@ -862,6 +862,8 @@ class N64SegCode(N64Segment): # TODO other image types + # TODO write orphaned palettes + @staticmethod def get_subdir(subtype): if subtype in ["c", ".data", ".rodata", ".bss", "i4", "i8", "ia4", "ia8", "ia16", "rgba16", "rgba32", "ci4", "ci8", "palette"]: @@ -879,7 +881,7 @@ class N64SegCode(N64Segment): elif subtype == "bin": return "bin" elif subtype in ["i4", "i8", "ia4", "ia8", "ia16", "rgba16", "rgba32", "ci4", "ci8", "palette"]: - return subtype + ".png" + return "png" return subtype @staticmethod diff --git a/tools/splat/segtypes/segment.py b/tools/splat/segtypes/segment.py index 924ab98782..8a8d3d5d83 100644 --- a/tools/splat/segtypes/segment.py +++ b/tools/splat/segtypes/segment.py @@ -1,6 +1,7 @@ from pathlib import Path, PurePath from util import log import os +import re default_subalign = 16 @@ -138,6 +139,9 @@ class Segment: f"SPLAT_BEGIN_SEG({tmp_sect_name}, 0x{start:X}, 0x{tmp_vram:X}, {subalign_str})\n" ) + path_cname = re.sub(r"[^0-9a-zA-Z_]", "_", path) + s += f" {path_cname} = .;\n" + path = PurePath(subdir) / PurePath(path) path = path.with_suffix(".o" if replace_ext else path.suffix + ".o")