feat: the proof samples the file's colours too, up to 30 cm (Marcus, 2026-11-26)
Some checks failed
Some checks failed
The proof keeps its 15 cm window on the finest stroke and adds 5 cm samples of the colours that window lacks (12 hues, grey, white, black), 1 cm of clear film between them, up to 30 cm. The colours are read from the small picture the Site sends of each file, so a long film is scanned in a moment; without pictures (a proof cut from a prepared final) it stays the stroke window. #100's proof caught only its white art. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""A free proof is a 15 cm window around the measured fine stroke, not the top."""
|
||||
"""A free proof is a 15 cm window around the measured fine stroke, not the top,
|
||||
and samples of the colours that window lacks, up to 30 cm (Marcus, 2026-11-26)."""
|
||||
import io
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -28,38 +29,78 @@ def item(height_cm=30, fraction='0.75'):
|
||||
}
|
||||
|
||||
|
||||
RED, BLUE, GREEN = (220, 30, 60, 255), (30, 60, 220, 255), (40, 180, 70, 255)
|
||||
|
||||
|
||||
def cm(value):
|
||||
return round(value * PX_CM)
|
||||
|
||||
|
||||
def picture(path):
|
||||
"""The small picture the Site sends of a file: WebP within 480 x 720 px."""
|
||||
with Image.open(path) as image:
|
||||
image.thumbnail((480, 720))
|
||||
out = io.BytesIO()
|
||||
image.save(out, 'WEBP', quality=80)
|
||||
return out.getvalue()
|
||||
|
||||
|
||||
class ProofRenderTests(unittest.TestCase):
|
||||
def _sheet(self, folder):
|
||||
height = round(30 * PX_CM)
|
||||
width = round(20 * PX_CM)
|
||||
image = Image.new('RGBA', (width, height), (220, 30, 60, 255))
|
||||
ImageDraw.Draw(image).rectangle((0, height // 2, width - 1, height - 1),
|
||||
fill=(30, 60, 220, 255))
|
||||
def _sheet(self, folder, bands, height_cm=30):
|
||||
"""A 20 cm wide sheet painted in [(from_cm, colour)] bands."""
|
||||
image = Image.new('RGBA', (cm(20), cm(height_cm)), bands[0][1])
|
||||
draw = ImageDraw.Draw(image)
|
||||
for start, colour in bands[1:]:
|
||||
draw.rectangle((0, cm(start), cm(20) - 1, cm(height_cm) - 1), fill=colour)
|
||||
path = Path(folder) / 'sheet.png'
|
||||
image.save(path, 'PNG', dpi=(300, 300))
|
||||
return str(path)
|
||||
|
||||
def test_the_window_follows_the_finest_stroke(self):
|
||||
def proof(self, bands, height_cm=30, fraction='0.75'):
|
||||
with tempfile.TemporaryDirectory() as source, tempfile.TemporaryDirectory() as out:
|
||||
sheet = self._sheet(source)
|
||||
parts, detail = render(item(), {0: (sheet, 'sheet.png')}, out, 'proof',
|
||||
limit_cm=15, proof_fraction='0.75')
|
||||
sheet = self._sheet(source, bands, height_cm)
|
||||
parts, detail = render(item(height_cm, fraction), {0: (sheet, 'sheet.png')}, out, 'proof',
|
||||
limit_cm=15, proof_fraction=fraction, pictures={0: picture(sheet)})
|
||||
self.assertEqual(len(parts), 1)
|
||||
self.assertEqual(detail['parts'][0]['from_cm'], '15')
|
||||
with Image.open(parts[0][0]) as proof:
|
||||
self.assertEqual(proof.width, round(20 * PX_CM))
|
||||
self.assertLessEqual(abs(proof.height - round(15 * PX_CM)), 1)
|
||||
# The bottom half is blue: the window covered 15 to 30 cm.
|
||||
self.assertEqual(proof.getpixel((proof.width // 2, round(5 * PX_CM))), (30, 60, 220, 255))
|
||||
with Image.open(parts[0][0]) as image:
|
||||
return image.convert('RGBA'), detail
|
||||
|
||||
def test_the_top_is_still_the_default_without_a_measure(self):
|
||||
def test_the_window_follows_the_finest_stroke_and_samples_the_rest(self):
|
||||
# The stroke is in the blue half: its 15 cm window, then a 5 cm red
|
||||
# sample from above, 1 cm of clear film between them.
|
||||
image, detail = self.proof([(0, RED), (15, BLUE)])
|
||||
self.assertEqual(detail['proof_windows'], [['0', '5'], ['15', '30']])
|
||||
self.assertEqual(image.width, cm(20))
|
||||
self.assertLessEqual(abs(image.height - cm(21)), 2)
|
||||
self.assertEqual(image.getpixel((image.width // 2, cm(2))), RED)
|
||||
self.assertEqual(image.getpixel((image.width // 2, cm(5.5)))[3], 0)
|
||||
self.assertEqual(image.getpixel((image.width // 2, cm(10))), BLUE)
|
||||
|
||||
def test_the_top_is_still_the_window_without_a_measure(self):
|
||||
image, detail = self.proof([(0, RED), (15, BLUE)], fraction=None)
|
||||
self.assertEqual(detail['proof_windows'][0], ['0', '15'])
|
||||
self.assertEqual(image.getpixel((image.width // 2, cm(5))), RED)
|
||||
self.assertEqual(image.getpixel((image.width // 2, cm(18))), BLUE)
|
||||
|
||||
def test_without_pictures_the_proof_is_the_stroke_window(self):
|
||||
with tempfile.TemporaryDirectory() as source, tempfile.TemporaryDirectory() as out:
|
||||
sheet = self._sheet(source)
|
||||
parts, detail = render(item(fraction=None), {0: (sheet, 'sheet.png')}, out, 'proof',
|
||||
limit_cm=15)
|
||||
self.assertEqual(detail['parts'][0]['from_cm'], '0')
|
||||
with Image.open(parts[0][0]) as proof:
|
||||
self.assertEqual(proof.getpixel((proof.width // 2, round(5 * PX_CM))), (220, 30, 60, 255))
|
||||
sheet = self._sheet(source, [(0, RED), (15, BLUE)])
|
||||
_, detail = render(item(), {0: (sheet, 'sheet.png')}, out, 'proof', limit_cm=15, proof_fraction='0.75')
|
||||
self.assertEqual(detail['proof_windows'], [['15', '30']])
|
||||
|
||||
def test_one_colour_keeps_the_15_cm_proof(self):
|
||||
image, detail = self.proof([(0, BLUE)])
|
||||
self.assertEqual(detail['proof_windows'], [['15', '30']])
|
||||
self.assertLessEqual(abs(image.height - cm(15)), 1)
|
||||
|
||||
def test_every_colour_within_30_cm(self):
|
||||
# Red, blue and green in a 100 cm sheet, the stroke in the blue.
|
||||
image, detail = self.proof([(0, RED), (30, BLUE), (60, GREEN)], height_cm=100, fraction='0.45')
|
||||
windows = [(float(a), float(b)) for a, b in detail['proof_windows']]
|
||||
self.assertEqual(len(windows), 3)
|
||||
self.assertLessEqual(sum(b - a for a, b in windows) + 1 * (len(windows) - 1), 30)
|
||||
colours = {image.getpixel((image.width // 2, y)) for y in range(0, image.height, cm(1))}
|
||||
self.assertTrue({RED, BLUE, GREEN} <= colours, colours)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user