mirror of https://github.com/pmret/papermario.git
Pause segment images (#235)
* splat update incoming * git subrepo pull --force tools/splat subrepo: subdir: "tools/splat" merged: "90fae1a829" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "90fae1a829" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596"
This commit is contained in:
parent
ca08ab9072
commit
896639da49
|
@ -263,7 +263,7 @@ async def main():
|
||||||
# KMC gcc doesn't support input on stdin, so a temp file has to be made for the preprocessor output
|
# KMC gcc doesn't support input on stdin, so a temp file has to be made for the preprocessor output
|
||||||
n.rule("cc_kmc",
|
n.rule("cc_kmc",
|
||||||
command=f"bash -o pipefail -c '{cpp} -Iver/$version/build/include -Iinclude -Iinclude/PR -Isrc -D _LANGUAGE_C -D _FINALROM -D VERSION=$version -ffreestanding -DF3DEX_GBI_2 -D_MIPS_SZLONG=32 {args.cflags} -MD -MF $out.d $in -o $out.i && export WINEPATH=tools/kmc/BIN && wine exew32 gcc -O3 -c -G0 -mgp32 -mfp32 -mips3 $out.i -o $out' && {cross}strip $out -N $in",
|
command=f"bash -o pipefail -c '{cpp} -Iver/$version/build/include -Iinclude -Iinclude/PR -Isrc -D _LANGUAGE_C -D _FINALROM -D VERSION=$version -ffreestanding -DF3DEX_GBI_2 -D_MIPS_SZLONG=32 {args.cflags} -MD -MF $out.d $in -o $out.i && export WINEPATH=tools/kmc/BIN && wine exew32 gcc -O3 -c -G0 -mgp32 -mfp32 -mips3 $out.i -o $out' && {cross}strip $out -N $in",
|
||||||
description="dsl $in",
|
description="kmc $in",
|
||||||
depfile="$out.d",
|
depfile="$out.d",
|
||||||
deps="gcc")
|
deps="gcc")
|
||||||
n.newline()
|
n.newline()
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
[subrepo]
|
[subrepo]
|
||||||
remote = https://github.com/ethteck/splat.git
|
remote = https://github.com/ethteck/splat.git
|
||||||
branch = master
|
branch = master
|
||||||
commit = db0b6f0cba3e07edac25fdb38ae30d2bd52044ca
|
commit = 90fae1a8294eb42912717db587ff070474a307f8
|
||||||
parent = b97c4c139cd95cda596c9ee5097ccd1efa37185a
|
parent = 886a779bdb282646459e9f58c65454fbf6a6dfda
|
||||||
method = merge
|
method = merge
|
||||||
cmdver = 0.4.3
|
cmdver = 0.4.3
|
||||||
|
|
|
@ -2,7 +2,7 @@ from segtypes.n64.ci8 import N64SegCi8
|
||||||
|
|
||||||
class N64SegCi4(N64SegCi8):
|
class N64SegCi4(N64SegCi8):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_image(data, width, height):
|
def parse_image(data, width, height, flip_h=False, flip_v=False):
|
||||||
img_data = bytearray()
|
img_data = bytearray()
|
||||||
|
|
||||||
for i in range(width * height // 2):
|
for i in range(width * height // 2):
|
||||||
|
|
|
@ -16,7 +16,7 @@ class N64SegCi8(N64SegRgba16):
|
||||||
|
|
||||||
data = rom_bytes[self.rom_start: self.rom_end]
|
data = rom_bytes[self.rom_start: self.rom_end]
|
||||||
|
|
||||||
self.image = self.parse_image(data, self.width, self.height)
|
self.image = self.__class__.parse_image(data, self.width, self.height, self.flip_horizontal, self.flip_vertical)
|
||||||
|
|
||||||
def postsplit(self, segments):
|
def postsplit(self, segments):
|
||||||
palettes = [seg for seg in segments if seg.type ==
|
palettes = [seg for seg in segments if seg.type ==
|
||||||
|
@ -51,7 +51,7 @@ class N64SegCi8(N64SegRgba16):
|
||||||
f"No unnamed palette for {self.name}; wrote image data to {self.path}")
|
f"No unnamed palette for {self.name}; wrote image data to {self.path}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_image(data, width, height):
|
def parse_image(data, width, height, flip_h=False, flip_v=False):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def max_length(self):
|
def max_length(self):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from segtypes.n64.rgba16 import N64SegRgba16
|
||||||
import sys
|
import sys
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
|
@ -8,6 +9,12 @@ import png
|
||||||
from capstone import *
|
from capstone import *
|
||||||
from capstone.mips import *
|
from capstone.mips import *
|
||||||
from segtypes.n64.ci4 import N64SegCi4
|
from segtypes.n64.ci4 import N64SegCi4
|
||||||
|
from segtypes.n64.ci8 import N64SegCi8
|
||||||
|
from segtypes.n64.i4 import N64SegI4
|
||||||
|
from segtypes.n64.i8 import N64SegI8
|
||||||
|
from segtypes.n64.ia4 import N64SegIa4
|
||||||
|
from segtypes.n64.ia8 import N64SegIa8
|
||||||
|
from segtypes.n64.ia16 import N64SegIa16
|
||||||
from segtypes.n64.palette import N64SegPalette
|
from segtypes.n64.palette import N64SegPalette
|
||||||
from segtypes.n64.segment import N64Segment
|
from segtypes.n64.segment import N64Segment
|
||||||
from segtypes.segment import Segment
|
from segtypes.segment import Segment
|
||||||
|
@ -126,6 +133,18 @@ class Subsegment():
|
||||||
return PaletteSubsegment
|
return PaletteSubsegment
|
||||||
elif typ == "rgba32":
|
elif typ == "rgba32":
|
||||||
return RGBA32Subsegment
|
return RGBA32Subsegment
|
||||||
|
elif typ == "rgba16":
|
||||||
|
return RGBA16Subsegment
|
||||||
|
elif typ == "i4":
|
||||||
|
return I4Subsegment
|
||||||
|
elif typ == "i8":
|
||||||
|
return I8Subsegment
|
||||||
|
elif typ == "ia4":
|
||||||
|
return Ia4Subsegment
|
||||||
|
elif typ == "ia8":
|
||||||
|
return Ia8Subsegment
|
||||||
|
elif typ == "ia16":
|
||||||
|
return Ia16Subsegment
|
||||||
elif typ == "linker":
|
elif typ == "linker":
|
||||||
return LinkerSubsegment
|
return LinkerSubsegment
|
||||||
else:
|
else:
|
||||||
|
@ -295,6 +314,96 @@ class RGBA32Subsegment(Subsegment):
|
||||||
with open(generic_out_path, "wb") as f:
|
with open(generic_out_path, "wb") as f:
|
||||||
w.write_array(f, image)
|
w.write_array(f, image)
|
||||||
|
|
||||||
|
class RGBA16Subsegment(Subsegment):
|
||||||
|
def should_run(self):
|
||||||
|
return super().should_run() or options.mode_active("img")
|
||||||
|
|
||||||
|
def split_inner(self, segment, rom_bytes, base_path, generic_out_path):
|
||||||
|
img_bytes = rom_bytes[self.rom_start : self.rom_end]
|
||||||
|
width, height = self.args
|
||||||
|
image = N64SegRgba16.parse_image(img_bytes, width, height)
|
||||||
|
|
||||||
|
w = png.Writer(width, height, greyscale=False, alpha=True)
|
||||||
|
|
||||||
|
Path(generic_out_path).parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(generic_out_path, "wb") as f:
|
||||||
|
w.write_array(f, image)
|
||||||
|
|
||||||
|
class I4Subsegment(Subsegment):
|
||||||
|
def should_run(self):
|
||||||
|
return super().should_run() or options.mode_active("img")
|
||||||
|
|
||||||
|
def split_inner(self, segment, rom_bytes, base_path, generic_out_path):
|
||||||
|
img_bytes = rom_bytes[self.rom_start : self.rom_end]
|
||||||
|
width, height = self.args
|
||||||
|
image = N64SegI4.parse_image(img_bytes, width, height)
|
||||||
|
|
||||||
|
w = png.Writer(width, height, greyscale=True, alpha=False)
|
||||||
|
|
||||||
|
Path(generic_out_path).parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(generic_out_path, "wb") as f:
|
||||||
|
w.write_array(f, image)
|
||||||
|
|
||||||
|
class I8Subsegment(Subsegment):
|
||||||
|
def should_run(self):
|
||||||
|
return super().should_run() or options.mode_active("img")
|
||||||
|
|
||||||
|
def split_inner(self, segment, rom_bytes, base_path, generic_out_path):
|
||||||
|
img_bytes = rom_bytes[self.rom_start : self.rom_end]
|
||||||
|
width, height = self.args
|
||||||
|
image = N64SegI8.parse_image(img_bytes, width, height)
|
||||||
|
|
||||||
|
w = png.Writer(width, height, greyscale=True, alpha=False)
|
||||||
|
|
||||||
|
Path(generic_out_path).parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(generic_out_path, "wb") as f:
|
||||||
|
w.write_array(f, image)
|
||||||
|
|
||||||
|
class Ia4Subsegment(Subsegment):
|
||||||
|
def should_run(self):
|
||||||
|
return super().should_run() or options.mode_active("img")
|
||||||
|
|
||||||
|
def split_inner(self, segment, rom_bytes, base_path, generic_out_path):
|
||||||
|
img_bytes = rom_bytes[self.rom_start : self.rom_end]
|
||||||
|
width, height = self.args
|
||||||
|
image = N64SegIa4.parse_image(img_bytes, width, height)
|
||||||
|
|
||||||
|
w = png.Writer(width, height, greyscale=True, alpha=True)
|
||||||
|
|
||||||
|
Path(generic_out_path).parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(generic_out_path, "wb") as f:
|
||||||
|
w.write_array(f, image)
|
||||||
|
|
||||||
|
class Ia8Subsegment(Subsegment):
|
||||||
|
def should_run(self):
|
||||||
|
return super().should_run() or options.mode_active("img")
|
||||||
|
|
||||||
|
def split_inner(self, segment, rom_bytes, base_path, generic_out_path):
|
||||||
|
img_bytes = rom_bytes[self.rom_start : self.rom_end]
|
||||||
|
width, height = self.args
|
||||||
|
image = N64SegIa8.parse_image(img_bytes, width, height)
|
||||||
|
|
||||||
|
w = png.Writer(width, height, greyscale=True, alpha=True)
|
||||||
|
|
||||||
|
Path(generic_out_path).parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(generic_out_path, "wb") as f:
|
||||||
|
w.write_array(f, image)
|
||||||
|
|
||||||
|
class Ia16Subsegment(Subsegment):
|
||||||
|
def should_run(self):
|
||||||
|
return super().should_run() or options.mode_active("img")
|
||||||
|
|
||||||
|
def split_inner(self, segment, rom_bytes, base_path, generic_out_path):
|
||||||
|
img_bytes = rom_bytes[self.rom_start : self.rom_end]
|
||||||
|
width, height = self.args
|
||||||
|
image = N64SegIa16.parse_image(img_bytes, width, height)
|
||||||
|
|
||||||
|
w = png.Writer(width, height, greyscale=True, alpha=True)
|
||||||
|
|
||||||
|
Path(generic_out_path).parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(generic_out_path, "wb") as f:
|
||||||
|
w.write_array(f, image)
|
||||||
|
|
||||||
class N64SegCode(N64Segment):
|
class N64SegCode(N64Segment):
|
||||||
palettes = {}
|
palettes = {}
|
||||||
|
|
||||||
|
@ -1050,7 +1159,10 @@ class N64SegCode(N64Segment):
|
||||||
width, height = sub.args
|
width, height = sub.args
|
||||||
|
|
||||||
for palette in self.palettes[sub.name]:
|
for palette in self.palettes[sub.name]:
|
||||||
|
if sub.type == "ci4":
|
||||||
image = N64SegCi4.parse_image(img_bytes, width, height)
|
image = N64SegCi4.parse_image(img_bytes, width, height)
|
||||||
|
elif sub.type == "ci8":
|
||||||
|
image = N64SegCi8.parse_image(img_bytes, width, height)
|
||||||
|
|
||||||
w = png.Writer(width, height, palette=palette.palette)
|
w = png.Writer(width, height, palette=palette.palette)
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,13 @@ from math import ceil
|
||||||
|
|
||||||
class N64SegI4(N64SegRgba16):
|
class N64SegI4(N64SegRgba16):
|
||||||
def png_writer(self):
|
def png_writer(self):
|
||||||
return png.Writer(self.width, self.height, greyscale = True)
|
return png.Writer(self.width, self.height, greyscale=True)
|
||||||
|
|
||||||
def parse_image(self, data):
|
@staticmethod
|
||||||
|
def parse_image(data, width, height, flip_h=False, flip_v=False):
|
||||||
img = bytearray()
|
img = bytearray()
|
||||||
|
|
||||||
for x, y, i in self.iter_image_indexes(0.5, 1):
|
for x, y, i in N64SegRgba16.iter_image_indexes(width, height, 0.5, 1, flip_h, flip_v):
|
||||||
b = data[i]
|
b = data[i]
|
||||||
|
|
||||||
i1 = (b >> 4) & 0xF
|
i1 = (b >> 4) & 0xF
|
||||||
|
|
|
@ -2,7 +2,8 @@ from segtypes.n64.i4 import N64SegI4
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
class N64SegI8(N64SegI4):
|
class N64SegI8(N64SegI4):
|
||||||
def parse_image(self, data):
|
@staticmethod
|
||||||
|
def parse_image(data, width, height, flip_h=False, flip_v=False):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def max_length(self):
|
def max_length(self):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from segtypes.n64.ia4 import N64SegIa4
|
from segtypes.n64.ia4 import N64SegIa4
|
||||||
|
|
||||||
class N64SegIa8(N64SegIa4):
|
class N64SegIa16(N64SegIa4):
|
||||||
def parse_image(self, data):
|
def parse_image(self, data):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,13 @@ from math import ceil
|
||||||
|
|
||||||
class N64SegIa4(N64SegRgba16):
|
class N64SegIa4(N64SegRgba16):
|
||||||
def png_writer(self):
|
def png_writer(self):
|
||||||
return png.Writer(self.width, self.height, greyscale = True, alpha = True)
|
return png.Writer(self.width, self.height, greyscale=True, alpha=True)
|
||||||
|
|
||||||
def parse_image(self, data):
|
@staticmethod
|
||||||
|
def parse_image(data, width, height, flip_h=False, flip_v=False):
|
||||||
img = bytearray()
|
img = bytearray()
|
||||||
|
|
||||||
for x, y, i in self.iter_image_indexes(0.5, 1):
|
for x, y, i in N64SegRgba16.iter_image_indexes(width, height, 0.5, 1, flip_h, flip_v):
|
||||||
b = data[i]
|
b = data[i]
|
||||||
|
|
||||||
h = (b >> 4) & 0xF
|
h = (b >> 4) & 0xF
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
from segtypes.n64.ia4 import N64SegIa4
|
from segtypes.n64.ia4 import N64SegIa4
|
||||||
|
from segtypes.n64.rgba16 import N64SegRgba16
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
class N64SegIa8(N64SegIa4):
|
class N64SegIa8(N64SegIa4):
|
||||||
def parse_image(self, data):
|
@staticmethod
|
||||||
|
def parse_image(data, width, height, flip_h=False, flip_v=False):
|
||||||
img = bytearray()
|
img = bytearray()
|
||||||
|
|
||||||
for x, y, i in self.iter_image_indexes():
|
for x, y, i in N64SegRgba16.iter_image_indexes(width, height, flip_h=flip_h, flip_v=flip_v):
|
||||||
b = data[i]
|
b = data[i]
|
||||||
|
|
||||||
i = (b >> 4) & 0xF
|
i = (b >> 4) & 0xF
|
||||||
|
|
|
@ -37,14 +37,15 @@ class N64SegRgba16(N64Segment):
|
||||||
def flip_horizontal(self):
|
def flip_horizontal(self):
|
||||||
return self.flip == "both" or self.flip.startswith("h") or self.flip == "x"
|
return self.flip == "both" or self.flip.startswith("h") or self.flip == "x"
|
||||||
|
|
||||||
def iter_image_indexes(self, bytes_per_x=1, bytes_per_y=1):
|
@staticmethod
|
||||||
w = int(self.width * bytes_per_x)
|
def iter_image_indexes(width, height, bytes_per_x=1, bytes_per_y=1, flip_h=False, flip_v=False):
|
||||||
h = int(self.height * bytes_per_y)
|
w = int(width * bytes_per_x)
|
||||||
|
h = int(height * bytes_per_y)
|
||||||
|
|
||||||
xrange = range(w - ceil(bytes_per_x), -1, -ceil(bytes_per_x)
|
xrange = range(w - ceil(bytes_per_x), -1, -ceil(bytes_per_x)
|
||||||
) if self.flip_horizontal else range(0, w, ceil(bytes_per_x))
|
) if flip_h else range(0, w, ceil(bytes_per_x))
|
||||||
yrange = range(h - ceil(bytes_per_y), -1, -ceil(bytes_per_y)
|
yrange = range(h - ceil(bytes_per_y), -1, -ceil(bytes_per_y)
|
||||||
) if self.flip_vertical else range(0, h, ceil(bytes_per_y))
|
) if flip_v else range(0, h, ceil(bytes_per_y))
|
||||||
|
|
||||||
for y in yrange:
|
for y in yrange:
|
||||||
for x in xrange:
|
for x in xrange:
|
||||||
|
@ -61,17 +62,18 @@ class N64SegRgba16(N64Segment):
|
||||||
|
|
||||||
w = self.png_writer()
|
w = self.png_writer()
|
||||||
with open(path, "wb") as f:
|
with open(path, "wb") as f:
|
||||||
w.write_array(f, self.parse_image(data))
|
w.write_array(f, self.parse_image(data, self.width, self.height, self.flip_horizontal, self.flip_vertical))
|
||||||
|
|
||||||
self.log(f"Wrote {self.name} to {path}")
|
self.log(f"Wrote {self.name} to {path}")
|
||||||
|
|
||||||
def png_writer(self):
|
def png_writer(self):
|
||||||
return png.Writer(self.width, self.height, greyscale=False, alpha=True)
|
return png.Writer(self.width, self.height, greyscale=False, alpha=True)
|
||||||
|
|
||||||
def parse_image(self, data):
|
@staticmethod
|
||||||
|
def parse_image(data, width, height, flip_h=False, flip_v=False):
|
||||||
img = bytearray()
|
img = bytearray()
|
||||||
|
|
||||||
for x, y, i in self.iter_image_indexes(2, 1):
|
for x, y, i in N64SegRgba16.iter_image_indexes(width, height, 2, 1, flip_h, flip_v):
|
||||||
img += bytes(unpack_color(data[i:]))
|
img += bytes(unpack_color(data[i:]))
|
||||||
|
|
||||||
return img
|
return img
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from segtypes.n64.rgba16 import N64SegRgba16
|
from segtypes.n64.rgba16 import N64SegRgba16
|
||||||
|
|
||||||
class N64SegRgba32(N64SegRgba16):
|
class N64SegRgba32(N64SegRgba16):
|
||||||
def parse_image(self, data):
|
@staticmethod
|
||||||
|
def parse_image(data, width, height, flip_h=False, flip_v=False):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def max_length(self):
|
def max_length(self):
|
||||||
|
|
Loading…
Reference in New Issue