Skip to content

Commit

Permalink
Fix stuff after splupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
ethteck committed Jul 13, 2023
1 parent 852076d commit 15dfc48
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
5 changes: 4 additions & 1 deletion tools/build/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
DO_SHA1_CHECK = True

# Paths:
ROOT = Path(__file__).parent.parent.parent.relative_to(Path.cwd())
ROOT = Path(__file__).parent.parent.parent
if ROOT.is_absolute():
ROOT = ROOT.relative_to(Path.cwd())

BUILD_TOOLS = Path("tools/build")
YAY0_COMPRESS_TOOL = f"{BUILD_TOOLS}/yay0/Yay0compress"
CRC_TOOL = f"{BUILD_TOOLS}/rom/n64crc"
Expand Down
18 changes: 16 additions & 2 deletions tools/splat_ext/pm_map_data.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from math import ceil
import os, sys
from pathlib import Path
from typing import List
from segtypes.n64.segment import N64Segment
from util.n64.Yay0decompress import Yay0Decompressor
from util.color import unpack_color
from segtypes.n64.palette import iter_in_groups
from util import options
import png # type: ignore
Expand All @@ -30,6 +29,21 @@ def decode_null_terminated_ascii(data):
def parse_palette(data):
palette = []

# RRRRRGGG GGBBBBBA
def unpack_color(data):
s = int.from_bytes(data[0:2], byteorder="big")

r = (s >> 11) & 0x1F
g = (s >> 6) & 0x1F
b = (s >> 1) & 0x1F
a = (s & 1) * 0xFF

r = ceil(0xFF * (r / 31))
g = ceil(0xFF * (g / 31))
b = ceil(0xFF * (b / 31))

return r, g, b, a

for a, b in iter_in_groups(data, 2):
palette.append(unpack_color([a, b]))

Expand Down
26 changes: 24 additions & 2 deletions tools/splat_ext/tex_archives.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from dataclasses import dataclass
import os
from math import ceil
import struct
import json
from pathlib import Path

import png
import n64img.image
from util.color import unpack_color, pack_color
from segtypes.n64.palette import iter_in_groups

from sys import path
Expand All @@ -28,6 +27,21 @@ def decode_null_terminated_ascii(data):
def parse_palette(data):
palette = []

# RRRRRGGG GGBBBBBA
def unpack_color(data):
s = int.from_bytes(data[0:2], byteorder="big")

r = (s >> 11) & 0x1F
g = (s >> 6) & 0x1F
b = (s >> 1) & 0x1F
a = (s & 1) * 0xFF

r = ceil(0xFF * (r / 31))
g = ceil(0xFF * (g / 31))
b = ceil(0xFF * (b / 31))

return r, g, b, a

for a, b in iter_in_groups(data, 2):
palette.append(unpack_color([a, b]))

Expand Down Expand Up @@ -396,6 +410,14 @@ def read_json_img(self, img_data, tile_name, img_name):
return fmt_str, hwrap, vwrap

def get_img_file(self, fmt_str, img_file: str):
def pack_color(r, g, b, a):
r = r >> 3
g = g >> 3
b = b >> 3
a = a >> 7

return (r << 11) | (g << 6) | (b << 1) | a

(out_img, out_w, out_h) = Converter(
mode=fmt_str.lower(), infile=img_file, flip_y=True
).convert()
Expand Down

0 comments on commit 15dfc48

Please sign in to comment.