"""The character concept sheet is composed without divider lines between panels.""" from __future__ import annotations import base64 import io import os import tempfile import unittest os.environ.setdefault("CONFIG_DIR", tempfile.mkdtemp(prefix="ttvc-refsheet-test-config-")) from PIL import Image import routes.conversation as conversation BG = (246, 242, 234) def _png(color): out = io.BytesIO() Image.new("RGB", (1536, 1024), color).save(out, format="PNG") return out.getvalue() class ComposeReferenceNoDividers(unittest.TestCase): def test_no_lines_between_panels(self): # Every panel is the same colour as the sheet background, so any pixel that differs is a drawn line. images = {k: _png(BG) for k in ("turnaround", "scene", "prop1", "prop2")} for props in (0, 1, 2): uri = conversation._compose_character_reference(images, props) img = Image.open(io.BytesIO(base64.b64decode(uri.split(",", 1)[1]))).convert("RGB") self.assertEqual(img.size, (1536, 1536)) self.assertEqual(img.getcolors(maxcolors=16), [(1536 * 1536, BG)], f"divider drawn with {props} props") class ComposeReferenceNoGutters(unittest.TestCase): def test_panels_are_flush(self): def solid(color, size): out = io.BytesIO() Image.new("RGB", size, color).save(out, format="PNG") return out.getvalue() red, green, blue = (200, 0, 0), (0, 200, 0), (0, 0, 200) for props in (0, 1, 2): scene_w = {0: 1536, 1: 1024, 2: 768}[props] tile_w = max(1, (1536 - scene_w) // 2 if props == 2 else 1536 - scene_w) images = {"turnaround": solid(red, (1536, 1024)), "scene": solid(green, (scene_w, 512)), "prop1": solid(blue, (tile_w, 512)), "prop2": solid(blue, (tile_w, 512))} uri = conversation._compose_character_reference(images, props) img = Image.open(io.BytesIO(base64.b64decode(uri.split(",", 1)[1]))).convert("RGB") colours = {c for _, c in img.getcolors(maxcolors=16)} self.assertNotIn(BG, colours, f"background gutter with {props} props") self.assertTrue(all(img.getpixel((x, 100)) == red for x in range(1536))) self.assertTrue(all(img.getpixel((x, 1023)) == red for x in range(1536))) self.assertEqual(img.getpixel((0, 1024)), green) if __name__ == "__main__": unittest.main()