shithub: subpixelize

Download patch

ref: c575d9489e3157ff1fe5e85f0c91f920c0e75ab6
parent: 27ab378bba094b64ecd9e681ef30637cfbf3d9e8
author: sirjofri <sirjofri@sirjofri.de>
date: Tue Mar 3 16:40:01 EST 2026

adds unsubpixelize

--- a/mkfile
+++ b/mkfile
@@ -1,10 +1,9 @@
 </$objtype/mkfile
 
 BIN=/$objtype/bin
-TARG=subpixelize
-OFILES=subpixelize.$O
+TARG=subpixelize unsubpixelize
 
-</sys/src/cmd/mkone
+</sys/src/cmd/mkmany
 
-t:V: $O.out
-	$O.out < sand.bit > sandout.bit
+t:V: $O.subpixelize $O.unsubpixelize
+	diff sand.bit <{ $O.subpixelize < sand.bit | $O.unsubpixelize }
binary files a/sand.bit b/sand.bit differ
--- /dev/null
+++ b/unsubpixelize.c
@@ -1,0 +1,59 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <memdraw.h>
+
+static void
+transformpx(Memimage *src, Memimage *dst, Point p)
+{
+	uchar *s;
+	uchar *t;
+	int c;
+	
+	t = byteaddr(dst, p);
+	
+	c = p.x % 3;
+	p.x /= 3;
+	p.y /= 3;
+	
+	s = byteaddr(src, p);
+	
+	t[0] = t[1] = t[2] = s[2-c];
+}
+
+static void
+transform(Memimage *src, Memimage *dst)
+{
+	int x, y;
+	
+	for (y = dst->r.min.y; y < dst->r.max.y; y++)
+		for (x = dst->r.min.x; x < dst->r.max.x; x++)
+			transformpx(src, dst, Pt(x, y));
+}
+
+void
+main(void)
+{
+	Memimage *in, *out;
+	Rectangle r;
+	
+	if (memimageinit() < 0)
+		sysfatal("%r");
+	
+	in = readmemimage(0);
+	if (!in)
+		sysfatal("%r");
+	
+	r.min.x = in->r.min.x * 3;
+	r.min.y = in->r.min.y * 3;
+	r.max.x = in->r.max.x * 3;
+	r.max.y = in->r.max.y * 3;
+	
+	out = allocmemimage(r, RGB24);
+	if (!out)
+		sysfatal("%r");
+	
+	transform(in, out);
+	writememimage(1, out);
+	exits(nil);
+}
\ No newline at end of file
--