Add shape_mono_to_grey.py (similar to shape_versions.py), make some shapes grey
authorNick Downing <nick@ndcode.org>
Wed, 22 Jun 2022 16:35:32 +0000 (02:35 +1000)
committerNick Downing <nick@ndcode.org>
Wed, 22 Jun 2022 16:59:26 +0000 (02:59 +1000)
disasm/shape_dhgr.png
disasm/shape_mono_to_grey.py [new file with mode: 0755]
disasm/star_blazer.asm.patch

index f42745a..afa8bfe 100644 (file)
Binary files a/disasm/shape_dhgr.png and b/disasm/shape_dhgr.png differ
diff --git a/disasm/shape_mono_to_grey.py b/disasm/shape_mono_to_grey.py
new file mode 100755 (executable)
index 0000000..6ab7e28
--- /dev/null
@@ -0,0 +1,108 @@
+#!/usr/bin/env python3
+
+import numpy
+import sys
+import PIL.Image
+
+EXIT_SUCCESS = 0
+EXIT_FAILURE = 1
+
+PITCH_X = 256
+PITCH_Y = 64
+
+# see palette.py
+PALETTE = numpy.array(
+  [
+    [0x00, 0x00, 0x00],
+    [0xbc, 0x00, 0x89],
+    [0x00, 0x00, 0xbc],
+    [0xbc, 0x00, 0xe1],
+    [0x00, 0xbc, 0x89],
+    [0x80, 0x80, 0x80], #[0xbc, 0xbc, 0xbc],
+    [0x00, 0xbc, 0xe1],
+    [0xbc, 0xbc, 0xff],
+    [0xbc, 0xbc, 0x00],
+    [0xff, 0xbc, 0x89],
+    [0xc0, 0xc0, 0xc0], #[0xbc, 0xbc, 0xbc],
+    [0xff, 0xbc, 0xe1],
+    [0xbc, 0xff, 0x89],
+    [0xff, 0xff, 0xbc],
+    [0xbc, 0xff, 0xe1],
+    [0xff, 0xff, 0xff],
+  ],
+  numpy.uint8
+)
+
+if len(sys.argv) < 3:
+  print(f'usage: {sys.argv[0]:s} in.png out.png')
+  sys.exit(EXIT_FAILURE)
+in_png = sys.argv[1]
+out_png = sys.argv[2]
+
+image_in_pil = PIL.Image.open(in_png)
+assert image_in_pil.mode == 'P'
+image_in = numpy.frombuffer(
+  image_in_pil.tobytes(),
+  dtype = numpy.uint8
+).reshape((image_in_pil.size[1], image_in_pil.size[0]))
+
+image_out = numpy.zeros((PITCH_Y * 32, PITCH_X * 8), numpy.uint8)
+assert image_out.shape == image_in.shape
+
+for i in range(0x100):
+  j = i & 7
+  k = i >> 3
+  x = j * PITCH_X
+  y = k * PITCH_Y
+  bg = 0xa if (j ^ k) & 1 else 5
+  image_out[y:y + PITCH_Y, x:x + PITCH_X] = bg
+
+  shape = image_in[y:y + PITCH_Y, x:x + PITCH_X]
+  xs = shape.shape[1]
+  while xs:
+    if numpy.any(shape[:, xs - 1] != bg):
+      break
+    xs -= 1
+  else:
+    continue
+  ys = shape.shape[0]
+  while ys:
+    if numpy.any(shape[ys - 1, :] != bg):
+      break
+    ys -= 1
+  else:
+    continue
+  shape = shape[:ys, :xs]
+
+  # only mono input is accepted, convert to bool
+  shape = (
+    (
+      shape >>
+        (numpy.arange(xs, dtype = numpy.int32) & 3)[numpy.newaxis, :]
+    ) & 1
+  ).astype(bool)
+
+  # shrink by one pixel
+  shape = numpy.logical_and(shape[:, :-1], shape[:, 1:])
+  xs -= 1
+
+  # expand by 2 pixels
+  shape1 = numpy.zeros((ys, xs + 4), bool)
+  shape1[:, 2:-2] = shape
+  shape = numpy.logical_or(shape1[:, :-2], shape1[:, 2:])
+  xs += 2
+
+  # for now just lop off overflow
+  shape = shape[:, :-1]
+  xs -= 1
+
+  image_out[y:y + ys, x:x + xs] = shape * 0xf
+
+image_out_pil = PIL.Image.new(
+  'P',
+  (image_out.shape[1], image_out.shape[0]),
+  None
+)
+image_out_pil.frombytes(image_out.tobytes())
+image_out_pil.putpalette(list(PALETTE.reshape((0x30,))))
+image_out_pil.save(out_png)
index c28f6e5..e2f0e1e 100644 (file)
@@ -1,5 +1,5 @@
---- star_blazer.asm0   2022-06-23 01:03:48.956054878 +1000
-+++ star_blazer.asm    2022-06-23 01:32:47.040072683 +1000
+--- star_blazer.asm0   2022-06-23 01:40:42.064077549 +1000
++++ star_blazer.asm    2022-06-23 02:23:58.492104148 +1000
 @@ -1,3 +1,8 @@
 +ALIGN = 0
 +DHGR = 1
 +      adc     #0x01                   ; 1f32 -> 1f33 -> 1f35 r c=0 d=0
 +      sta     object1080_velocity_x_hi + 0x50 ; 1f33 -> 1f35 -> 1f38 r
 +      rts                             ; 1f35 -> 1f38 -> 15df r s=f9
-+      .ds     0xa000 - 0x4000 - (. - data0_start)
++      .ds     0xa180 - 0x4000 - (. - data0_start)
 +barr_1f80:
 +      .db     0x43                    ; 1f80 r
 +      .db     0x02                    ; 1f81 r