mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 23:28:38 +00:00
fix(tools): read all pages of a selected animation dictionary
Targeted decoding capped the input stream list before the page grouper could resolve the count declared by the dictionary.
This commit is contained in:
@ -633,6 +633,28 @@ class ArchiveTest(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, "no clip dictionary"):
|
||||
anim_clips.decode_one(self.rpf, self.offsets[3], 2)
|
||||
|
||||
def test_decode_prints_track_values_from_a_six_page_dictionary(self) -> None:
|
||||
data = bytearray(two_sequence_dictionary("six-pages@dict"))
|
||||
page_map = struct.unpack_from("<Q", data, 8)[0] - SYSTEM
|
||||
data[page_map + 8] = 6
|
||||
pages = [data[i:i + 256] for i in range(0, 5 * 256, 256)] + [data[5 * 256:]]
|
||||
self.assertTrue(all(len(page) >= 64 for page in pages))
|
||||
path = os.path.join(self.tmp.name, "six-pages.rpf")
|
||||
root, *_ = write_rpf(path, pages)
|
||||
_, summary = anim_clips.scan(path)
|
||||
self.assertEqual(summary["pages"], {"6": 1})
|
||||
self.assertEqual(summary["counts"]["animations_decoded"], 1)
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-I", TOOL, path, "--decode", str(root), "--frames", "3"],
|
||||
capture_output=True, text=True, check=False,
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
animation = json.loads(result.stdout)["packs"][0]["animations"][0]
|
||||
self.assertEqual(animation["decoded_frames"], NF)
|
||||
self.assertEqual(animation["decoded"]["2"], [[1.0, 2.0, 3.0]] * 3)
|
||||
self.assertEqual(animation["decoded"]["4"], [[0.0], [1.5], [3.0]])
|
||||
|
||||
def test_budget_rejects_nan_and_negative(self):
|
||||
for value in ("nan", "-1"):
|
||||
r = subprocess.run(
|
||||
|
||||
@ -550,12 +550,13 @@ def segment(rows, k):
|
||||
return rows[k]["offset"], rows[k]["stored"], False
|
||||
|
||||
|
||||
def group(m, rows):
|
||||
def group(m, rows, *, first_row_only: bool = False):
|
||||
"""-> ([(root index, [stream indices or gap pages])], unresolved count by reason, gap pages by kind). A
|
||||
dictionary takes the page map's system page count of back-to-back streams. When the last page is not the next
|
||||
listed stream, the bytes right after the stream are tried (`_gap_page`); otherwise the root is reported."""
|
||||
listed stream, the bytes right after the stream are tried (`_gap_page`); otherwise the root is reported.
|
||||
With first_row_only, later rows supply continuation pages but cannot start other dictionaries."""
|
||||
out, unresolved, taken, gaps = [], collections.Counter(), set(), collections.Counter()
|
||||
for i, row in enumerate(rows):
|
||||
for i, row in enumerate(rows[:1] if first_row_only else rows):
|
||||
if i in taken or row["signature"] != "zero-prefix":
|
||||
continue
|
||||
data = _inflate(m, row)
|
||||
@ -803,7 +804,7 @@ def scan(path, start=None, limit=None, jobs=1, progress=None, budget=None):
|
||||
def decode_one(path, offset, frames):
|
||||
rows, _walk = anim_index.scan_rpf(path, offset, 64 << 20)
|
||||
with open(path, "rb") as fh, mmap.mmap(fh.fileno(), 0, access=mmap.ACCESS_READ) as m:
|
||||
groups, _unresolved, _gaps = group(m, rows[:4])
|
||||
groups, _unresolved, _gaps = group(m, rows, first_row_only=True)
|
||||
if not groups or rows[groups[0][0]]["offset"] != offset:
|
||||
raise ValueError(f"no clip dictionary starts at 0x{offset:x}")
|
||||
with open(path, "rb") as fh:
|
||||
|
||||
Reference in New Issue
Block a user