fix: a film is cut into parts where its own pixels are clear, never through the art when it can be helped (#136)
Some checks failed
Build and deploy / Validate source (push) Successful in 9s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
Some checks failed
Build and deploy / Validate source (push) Successful in 9s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
The layout sees a ready sheet as one piece, so a part was cut at its length, through the artwork. Where no gap between pieces is near the limit, the film is read there: the cut falls in the middle of the nearest clear band of 3 mm, else of the widest clear band (#83's packed sheets have 2 mm between rows), else on the row with the least ink. A part is never shorter than half the limit, and the render limit allows one part more. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -60,13 +60,16 @@ STREAMED = ('.png', '.pdf')
|
||||
|
||||
|
||||
def render_seconds(item):
|
||||
"""The render limit of one item: RENDER_SECONDS for each part of its film."""
|
||||
"""The render limit of one item: RENDER_SECONDS for each part of its
|
||||
film, and one more for a film in parts: a cut moved back to a clear band
|
||||
(#136) can leave one part more than the layout alone counts."""
|
||||
production = item.get('production') or {}
|
||||
try:
|
||||
parts = len(part_cuts(production)) - 1 if production.get('placements') else 1
|
||||
except (KeyError, TypeError, ValueError, ArithmeticError):
|
||||
parts = 1
|
||||
return RENDER_SECONDS * max(1, parts)
|
||||
parts = max(1, parts)
|
||||
return RENDER_SECONDS * (parts + 1 if parts > 1 else 1)
|
||||
|
||||
|
||||
def generated_identity(order_id):
|
||||
|
||||
@@ -21,8 +21,9 @@ holds a whole sheet: the film is composed and written in bands of rows.
|
||||
|
||||
A layout longer than 15 m leaves as parts of up to 15 m (Dropstar,
|
||||
2026-10-30), DTF-7-item-1-p3.png, each with its footer saying which part it
|
||||
is. Loose artwork is cut where no piece crosses; a finished sheet is cut
|
||||
between copies when it can be, and through the artwork when not.
|
||||
is. Loose artwork is cut where no piece crosses; a finished sheet between
|
||||
copies, or else in a clear band of its own pixels, and through the artwork
|
||||
only when it has none (#136).
|
||||
"""
|
||||
import io
|
||||
import math
|
||||
@@ -389,8 +390,16 @@ class Piece:
|
||||
|
||||
# ---- Parts and footer -------------------------------------------------------
|
||||
|
||||
def part_cuts(production, part_cm=None):
|
||||
"""Where the film is cut into parts, in cm from its top: [0, ..., height]."""
|
||||
# A cut needs this much clear film: it then falls in the middle of it.
|
||||
CLEAR_CUT_CM = Decimal('0.3')
|
||||
|
||||
|
||||
def part_cuts(production, part_cm=None, clear=None):
|
||||
"""Where the film is cut into parts, in cm from its top: [0, ..., height].
|
||||
A cut falls in a gap between pieces; where the layout has none, as inside
|
||||
a ready sheet (one piece to it), `clear(from_cm, to_cm)` finds a clear band
|
||||
in the film's own pixels, so no artwork is cut in two (Marcus, 2026-11-27,
|
||||
#136). Only without one either is the cut at the part's length."""
|
||||
limit = Decimal(str(part_cm or PART_CM))
|
||||
height = Decimal(str(production['height_cm']))
|
||||
spans = [(Decimal(str(p['y_cm'])), Decimal(str(p['y_cm'])) + Decimal(str(p['length_cm'])))
|
||||
@@ -401,11 +410,46 @@ def part_cuts(production, part_cm=None):
|
||||
free = [end for _, end in spans
|
||||
if start + limit - CUT_SEARCH_CM <= end <= start + limit
|
||||
and not any(top < end < bottom for top, bottom in spans)]
|
||||
cuts.append(max(free) if free else start + limit)
|
||||
# The search never goes back past half a part: no part comes out short.
|
||||
found = clear(max(start + limit / 2, start + limit - CUT_SEARCH_CM), start + limit) if clear and not free else None
|
||||
cuts.append(max(free) if free else found if found and found > start else start + limit)
|
||||
cuts.append(height)
|
||||
return cuts
|
||||
|
||||
|
||||
def clear_band(pieces, width, from_cm, to_cm):
|
||||
"""Where to cut the film between the two, in cm, so the artwork suffers
|
||||
least (Marcus, 2026-11-27, #136): the middle of the clear band of at least
|
||||
CLEAR_CUT_CM nearest `to_cm`; else of the widest clear band there is (a
|
||||
sheet packed edge to edge may have only 2 mm between rows); else the row
|
||||
with the least ink. None when the stretch is empty of rows."""
|
||||
top = px(from_cm)
|
||||
ink_rows, amounts = [], []
|
||||
for _, band in film_bands(pieces, top, px(to_cm), width):
|
||||
ink = band.getchannel('A').point(lambda a: 255 if a > 8 else 0)
|
||||
ink_rows.extend(ink.getprojection()[1])
|
||||
amounts.extend(ink.resize((1, ink.height), Image.BOX).tobytes())
|
||||
if not ink_rows:
|
||||
return None
|
||||
runs, end = [], None # (length, last row, first row), clear rows only
|
||||
for row in range(len(ink_rows) - 1, -2, -1):
|
||||
if row >= 0 and not ink_rows[row]:
|
||||
end = row if end is None else end
|
||||
continue
|
||||
if end is not None:
|
||||
runs.append((end - row, end, row + 1))
|
||||
end = None
|
||||
to_cm_of = lambda row: Decimal(top + row) / Decimal(str(PX_PER_CM))
|
||||
need = px(CLEAR_CUT_CM)
|
||||
wide = [run for run in runs if run[0] >= need]
|
||||
if wide or runs:
|
||||
# runs go from the bottom up: the first wide one is the nearest the limit.
|
||||
length, last, first = wide[0] if wide else max(runs, key=lambda run: (run[0], run[1]))
|
||||
return to_cm_of((first + last) // 2)
|
||||
least = min(amounts)
|
||||
return to_cm_of(max(row for row, amount in enumerate(amounts) if amount == least))
|
||||
|
||||
|
||||
def proof_cut(height_cm, limit_cm, fraction=None):
|
||||
"""A proof's window, in cm from the film's top: `limit_cm` centred on the
|
||||
thinnest stroke (fraction 0 at the top, 1 at the bottom), clamped inside
|
||||
@@ -591,6 +635,10 @@ def render(item, files, out_dir, prefix, footer=None, part_cm=None, tiles=False,
|
||||
vector = {index for index, source in enumerate(sources) if source.pdf}
|
||||
lowest = check_layout(item, [source.size for source in sources], vector, proof=bool(limit_cm))
|
||||
width = px(production['film_width_cm'])
|
||||
|
||||
def laid_out():
|
||||
return sorted((Piece(placement, sources[placement['source_index']])
|
||||
for placement in production['placements']), key=lambda piece: piece.y)
|
||||
windows = None
|
||||
if limit_cm:
|
||||
# A proof: the finest stroke's window and samples of the other
|
||||
@@ -601,9 +649,16 @@ def render(item, files, out_dir, prefix, footer=None, part_cm=None, tiles=False,
|
||||
film_scan(production, pictures))
|
||||
cuts = [windows[0][0], windows[-1][1]]
|
||||
else:
|
||||
cuts = part_cuts(production, part_cm)
|
||||
pieces = sorted((Piece(placement, sources[placement['source_index']])
|
||||
for placement in production['placements']), key=lambda piece: piece.y)
|
||||
def clear(from_cm, to_cm):
|
||||
# Read on pieces of its own: the film is read forward only.
|
||||
scanned = laid_out()
|
||||
try:
|
||||
return clear_band(scanned, width, from_cm, to_cm)
|
||||
finally:
|
||||
for piece in scanned:
|
||||
piece.close()
|
||||
cuts = part_cuts(production, part_cm, clear)
|
||||
pieces = laid_out()
|
||||
count = len(cuts) - 1
|
||||
parts, manifests = [], []
|
||||
for number in range(count):
|
||||
|
||||
Reference in New Issue
Block a user