OSDN Git Service

Wu-ish lines.
authorSimon Forman <sforman@hushmail.com>
Tue, 28 Feb 2023 03:27:32 +0000 (19:27 -0800)
committerSimon Forman <sforman@hushmail.com>
Tue, 28 Feb 2023 03:27:32 +0000 (19:27 -0800)
implementations/uvm-ncc/graphics.h
implementations/uvm-ncc/neat_wu_lines.py [new file with mode: 0644]
implementations/uvm-ncc/wu_demo.png [new file with mode: 0644]
implementations/uvm-ncc/wu_lines.py [new file with mode: 0644]

index 4b6a6bf..2514bf5 100644 (file)
@@ -161,9 +161,3 @@ carefree_wu_line(u32* dest, size_t dest_stride, u64 x, u64 y, u64 w, u64 h, u32
        }
 }
 
-
-
-
-
-
-
diff --git a/implementations/uvm-ncc/neat_wu_lines.py b/implementations/uvm-ncc/neat_wu_lines.py
new file mode 100644 (file)
index 0000000..9157da2
--- /dev/null
@@ -0,0 +1,44 @@
+from PIL import Image, ImageDraw
+
+
+def draw_wu_line(draw, x, y, w, h):
+    # Without loss of generality only lines in the first oc
+    assert(w > 0 and h > 0 and w > h)
+    k = 0xffff * h // w
+    print(bin(k), hex(k), k)
+    x1 = x + w - 1
+    y1 = y + h - 1
+    print(x1, y1)
+    d = 0
+    while x1 > x:
+        draw.point([(x, y), (x1, y1)], fill=(0, 0, 0, 0xff - (d >> 8)))
+        draw.point([(x, y + 1), (x1, y1 - 1)], fill=(0, 0, 0,         d >> 8))
+        x += 1
+        x1 -= 1
+        if d + k >= 0xFFFF:
+            d = k - (0xFFFF - d)
+            y += 1
+            y1 -= 1
+        else:
+            d += k
+    if x1 == x:
+        if y1 == y:
+            points = [(x, y)]
+            alpha = 0xff
+        else:
+            points = [(x, y), (x, y1)]
+            alpha = 0x7f
+        draw.point(points, fill=(0, 0, 0, alpha))
+
+size = 100, 50
+im = Image.new('RGBA', size)
+d = ImageDraw.Draw(im, 'RGBA')
+
+#draw_wu_line(d, 0, 0, *size)
+
+for w in range(51, 100):
+    draw_wu_line(d, 0, 0, w, 50)
+
+base = Image.new('RGBA', size, (0xff, 0xff, 0xff, 0xff))
+base.alpha_composite(im)
+base.save('wu_demo.png')
diff --git a/implementations/uvm-ncc/wu_demo.png b/implementations/uvm-ncc/wu_demo.png
new file mode 100644 (file)
index 0000000..6ca818e
Binary files /dev/null and b/implementations/uvm-ncc/wu_demo.png differ
diff --git a/implementations/uvm-ncc/wu_lines.py b/implementations/uvm-ncc/wu_lines.py
new file mode 100644 (file)
index 0000000..ed3fe15
--- /dev/null
@@ -0,0 +1,38 @@
+from PIL import Image, ImageDraw
+
+
+def draw_wu_line(draw, x, y, w, h):
+    # Without loss of generality only lines in the first oc
+    assert w > 0 and h > 0 and w > h
+    k = 0xffff * h // w
+    d = k >> 1
+    while w > 0:
+        w -= 1
+        intensity = d >> 8
+        draw.point([(x, y    )], fill=(0, 0, 0, 0xff - intensity))
+        draw.point([(x, y + 1)], fill=(0, 0, 0,        intensity))
+        x += 1
+        if d + k >= 0xFFFF:
+            d = k - (0xFFFF - d)
+            y += 1
+        else:
+            d += k
+
+size = 100, 50
+im = Image.new('RGBA', size)
+d = ImageDraw.Draw(im, 'RGBA')
+
+# Diagonal line
+#draw_wu_line(d, 0, 0, *size)
+
+# Nearly 45 degrees.
+#draw_wu_line(d, 0, 0, 51, 50)
+
+# Nearly horizontal line.
+#draw_wu_line(d, 0, 0, 100, 5)
+
+draw_wu_line(d, 0, 0, 100, 33)
+
+base = Image.new('RGBA', size, (0xff, 0xff, 0xff, 0xff))
+base.alpha_composite(im)
+base.save('wu_demo.png')