Fix HD atlas sampling and protected terrain joins
Add rational atlas cells and bounded authenticated Original-detail retention with standalone synthetic regression checks. Rebuild Linux and Windows runtimes; validate all 5384 supplied frames and preserve three exact 1080p regression controls.
This commit is contained in:
1 parent
ef8a649e03
commit
a073f73f3a
14 files changed
+1086
-40
No files matched your search
@@ -1,8 +1,57 @@
|
||||
"""Strict optional HD presentation metadata; source fidelity requires peer review."""
|
||||
import struct
|
||||
from fractions import Fraction
|
||||
|
||||
FRAME_KEYS = {"frame", "file", "logical_width", "logical_height", "origin",
|
||||
"source_sha256", "crop", "preserve_reserved_coverage", "native_nearest_cues", "original_detail_cells"}
|
||||
"source_sha256", "crop", "atlas_grid", "preserve_reserved_coverage", "native_nearest_cues", "original_detail_cells"}
|
||||
|
||||
def validate_atlas_grid(frame):
|
||||
grid = frame.get("atlas_grid")
|
||||
if grid is None:
|
||||
return None
|
||||
if type(grid) is not dict or set(grid) != {"columns", "rows", "column", "row"}:
|
||||
raise ValueError("atlas_grid needs exactly columns/rows/column/row")
|
||||
if any(type(value) is not int or not 0 <= value < 2**32 for value in grid.values()):
|
||||
raise ValueError("atlas_grid fields must be u32 integers")
|
||||
if frame.get("crop") is not None:
|
||||
raise ValueError("atlas_grid and crop are mutually exclusive")
|
||||
if grid["columns"] == 0 or grid["rows"] == 0 or grid["columns"] * grid["rows"] > 16384:
|
||||
raise ValueError("atlas_grid axes or cell count invalid")
|
||||
if grid["column"] >= grid["columns"] or grid["row"] >= grid["rows"]:
|
||||
raise ValueError("atlas_grid cell is outside its declared axes")
|
||||
return grid
|
||||
|
||||
def atlas_grid_geometry(frame, width, height):
|
||||
"""Exact equal bounds and a bounded, uniform resident2x–4x canvas."""
|
||||
grid = validate_atlas_grid(frame)
|
||||
if grid is None:
|
||||
return None
|
||||
if any(type(value) is not int or value <= 0 for value in [width, height]):
|
||||
raise ValueError("invalid atlas dimensions")
|
||||
lw, lh = frame["logical_width"], frame["logical_height"]
|
||||
if any(type(value) is not int or not 0 < value < 2**32 for value in [lw, lh]):
|
||||
raise ValueError("invalid logical dimensions")
|
||||
cols, rows = grid["columns"], grid["rows"]
|
||||
if width * lh * rows != height * lw * cols:
|
||||
raise ValueError("rational atlas cell aspect differs from original canvas")
|
||||
if width < 2 * cols * lw or height < 2 * rows * lh:
|
||||
raise ValueError("rational atlas cell needs at least twice the logical resolution")
|
||||
factor = min(width // (cols * lw), height // (rows * lh), 4)
|
||||
left, right = Fraction(width * grid["column"], cols), Fraction(width * (grid["column"] + 1), cols)
|
||||
top, bottom = Fraction(height * grid["row"], rows), Fraction(height * (grid["row"] + 1), rows)
|
||||
floor = lambda value: value.numerator // value.denominator
|
||||
ceil = lambda value: -(-value.numerator // value.denominator)
|
||||
return dict(bounds=(left, top, right, bottom),
|
||||
pixels=(floor(left), floor(top), ceil(right), ceil(bottom)),
|
||||
resident=(lw * factor, lh * factor))
|
||||
|
||||
LEGACY_RETAINED_POLICY = "retained-original-details-v2-painted0255"
|
||||
EXTENDED_RETAINED_POLICY = "retained-original-details-v3-max128-quarter-painted0255"
|
||||
|
||||
def retained_review_version_ok(version, retained_details):
|
||||
"""The old declaration cannot authorize a new longer list; old bytes stay valid."""
|
||||
return version == EXTENDED_RETAINED_POLICY or (version == LEGACY_RETAINED_POLICY
|
||||
and all(len(cells) <= 64 for cells in retained_details.values()))
|
||||
|
||||
def _indices(payload):
|
||||
if len(payload) < 20:
|
||||
@@ -40,6 +89,7 @@ def _indices(payload):
|
||||
def validate_frame_policy(frame, source_payload=None):
|
||||
if set(frame) - FRAME_KEYS:
|
||||
raise ValueError("unknown HD frame fields")
|
||||
validate_atlas_grid(frame)
|
||||
if type(frame.get("preserve_reserved_coverage", False)) is not bool:
|
||||
raise ValueError("preserve_reserved_coverage must be a boolean")
|
||||
cues = frame.get("native_nearest_cues", [])
|
||||
@@ -68,8 +118,8 @@ def validate_frame_policy(frame, source_payload=None):
|
||||
raise ValueError("native nearest cue must be an ordinary original source cell")
|
||||
|
||||
details = frame.get("original_detail_cells", [])
|
||||
if type(details) is not list or len(details) > 64:
|
||||
raise ValueError("original_detail_cells must contain at most64 Source cells")
|
||||
if type(details) is not list or len(details) > 128:
|
||||
raise ValueError("original_detail_cells must contain at most128 Source cells")
|
||||
previous = None
|
||||
for cell in details:
|
||||
if type(cell) is not list or len(cell) != 2 or any(type(n) is not int or not 0 <= n < 2**32 for n in cell):
|
||||
@@ -86,3 +136,8 @@ def validate_frame_policy(frame, source_payload=None):
|
||||
raise ValueError("Original detail canvas differs from Source")
|
||||
if any(not 0 <= indices[y * width + x] < 256 for x, y in details):
|
||||
raise ValueError("Original details select painted Source indices0–255 only")
|
||||
|
||||
# Metadata-only preparation can check structure, not claim Source density.
|
||||
# Runtime, audit and extended registrar approval supply actual payloads.
|
||||
if len(details) > 64 and len(details) * 4 > sum(0 <= p <= 255 for p in indices):
|
||||
raise ValueError("65..128 Original details may retain at most one quarter of painted Source")
|
||||
Reference in new issue
Block a user