From 4456b7169c68ded59eabf47c53f3cbf412fc164c Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Thu, 17 Jul 2025 10:48:00 +1000 Subject: [PATCH] Improve /scripts/segdefs*.py to allow multiple outlines, revert /scripts/to_mono.py to a 50% threshold so that we can see the pad names in /8085 --- scripts/segdefs.py | 19 ++++++++++++++++--- scripts/segdefs_nets.py | 19 ++++++++++++++++--- scripts/to_mono.py | 2 +- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/scripts/segdefs.py b/scripts/segdefs.py index 0b9cf7c..da549a0 100755 --- a/scripts/segdefs.py +++ b/scripts/segdefs.py @@ -109,9 +109,22 @@ for colour in sorted(colours): for _, _, colour1, coords in segments: if colour1 == colour: - x, y = coords[-1] - move_to(x, y) - for x, y in coords: + # there may be a bug with repeated first coordinate in some versions? + assert segments[1] != segments[0] + # track first coordinate of outline (repeats to close and start new) + coord0 = None + for coord in coords: + x, y = coord + if coord0 is None: + coord0 = coord + move_to(x, y) + else: + if coord == coord0: + coord = None + line_to(x, y) + # if first coordinate was not repeated then close outline implicitly + if coord0 is not None: + x, y = coord0 line_to(x, y) flush_edges() PIL.Image.fromarray(image).save(f'{colour:d}.png') diff --git a/scripts/segdefs_nets.py b/scripts/segdefs_nets.py index 482c305..d733498 100755 --- a/scripts/segdefs_nets.py +++ b/scripts/segdefs_nets.py @@ -126,9 +126,22 @@ for net in sorted(nets.keys()): for segment in nets[net]: _, _, colour, coords = segments[segment] if colour in colours: - x, y = coords[-1] - move_to(x, y) - for x, y in coords: + # there may be a bug with repeated first coordinate in some versions? + assert segments[1] != segments[0] + # track first coordinate of outline (repeats to close and start new) + coord0 = None + for coord in coords: + x, y = coord + if coord0 is None: + coord0 = coord + move_to(x, y) + else: + if coord == coord0: + coord = None + line_to(x, y) + # if first coordinate was not repeated then close outline implicitly + if coord0 is not None: + x, y = coord0 line_to(x, y) flush_edges() images.append(image) diff --git a/scripts/to_mono.py b/scripts/to_mono.py index e4b2b3f..4867abc 100755 --- a/scripts/to_mono.py +++ b/scripts/to_mono.py @@ -25,7 +25,7 @@ image = numpy.array(image) #print('dtype', image.dtype) assert len(image.shape) == 3 and image.dtype == numpy.uint8 -image = image != 0 +image = image >= 0x80 if image.shape[2] == 2 or image.shape[2] == 4: image = image[:, :, :-1] & image[:, :, -1:] PIL.Image.fromarray(numpy.any(image, 2)).save(image_out) -- 2.34.1