shithub: imgtools

Download patch

ref: a8fcdbe57c250d325d48563bf17886d85e13af42
parent: f93909b95a5ec11c13bea21d8f024264714f7e57
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Jan 20 06:40:45 EST 2021

rename convert to iconv

--- a/README.md
+++ b/README.md
@@ -1,12 +1,13 @@
 # imgtools
 
-Some random image-related tools.
+Some random image-related tools.  Usually they are drop-in
+replacements where possible.
 
-## convert
+## iconv
 
 Converts a Plan 9 image from one format to another.  For example,
-`convert -c rgb16 <a.img >b.img` will convert `a.img` to RGB16 and
-save it as `b.img`.
+`iconv -c rgb16 <a.img >b.img` will convert `a.img` to RGB16 and save
+it as `b.img`.
 
 "Channels" (`-c` argument) are defined at `/sys/include/draw.h:133`.
 `rgb16`, `RGB16`, `r5g6b5` and `R5G6B5` mean the same thing
--- a/convert.c
+++ /dev/null
@@ -1,72 +1,0 @@
-#include <u.h>
-#include <libc.h>
-#include <draw.h>
-#include <memdraw.h>
-
-static struct {
-	char *name[2];
-	ulong chan;
-}chans[] = {
-	{{"grey1", "k1"}, GREY1},
-	{{"grey2", "k2"}, GREY2},
-	{{"grey4", "k4"}, GREY4},
-	{{"grey8", "k8"}, GREY8},
-	{{"cmap8", "m8"}, CMAP8},
-	{{"rgb15", "x1r5g5b5"}, RGB15},
-	{{"rgb16", "r5g6b5"}, RGB16},
-	{{"rgb24", "r8g8b8"}, RGB24},
-	{{"rgba32", "r8g8b8a8"}, RGBA32},
-	{{"argb32", "a8r8g8b8"}, ARGB32},
-	{{"xrgb32", "x8r8g8b8"}, XRGB32},
-	{{"bgr24", "b8g8r8"}, BGR24},
-	{{"abgr32", "a8b8g8r8"}, ABGR32},
-	{{"xbgr32", "x8b8g8r8"}, XBGR32},
-};
-
-static void
-usage(void)
-{
-	fprint(2, "usage: %s [-c CHAN]\n", argv0);
-	exits("usage");
-}
-
-void
-main(int argc, char **argv)
-{
-	Memimage *a, *b;
-	char *s;
-	int ci;
-
-	ci = -1;
-	ARGBEGIN{
-	case 'c':
-		s = EARGF(usage());
-		for(ci = 0;
-		    ci < nelem(chans) &&
-		    cistrcmp(chans[ci].name[0], s) != 0 &&
-		    cistrcmp(chans[ci].name[1], s) != 0;
-		    ci++)
-		;
-		if(ci >= nelem(chans)){
-			fprint(2, "invalid chan %s\n", s);
-			sysfatal("chan");
-		}
-		break;
-	default:
-		usage();
-	}ARGEND
-
-	memimageinit();
-	if((a = readmemimage(0)) == nil)
-		sysfatal("memory");
-	if(ci >= 0 && a->chan != chans[ci].chan){
-		if((b = allocmemimage(a->r, chans[ci].chan)) == nil)
-			sysfatal("memory");
-		memimagedraw(b, a->r, a, ZP, nil, ZP, S);
-		freememimage(a);
-		a = b;
-	}
-	writememimage(1, a);
-
-	exits(nil);
-}
--- /dev/null
+++ b/iconv.c
@@ -1,0 +1,72 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <memdraw.h>
+
+static struct {
+	char *name[2];
+	ulong chan;
+}chans[] = {
+	{{"grey1", "k1"}, GREY1},
+	{{"grey2", "k2"}, GREY2},
+	{{"grey4", "k4"}, GREY4},
+	{{"grey8", "k8"}, GREY8},
+	{{"cmap8", "m8"}, CMAP8},
+	{{"rgb15", "x1r5g5b5"}, RGB15},
+	{{"rgb16", "r5g6b5"}, RGB16},
+	{{"rgb24", "r8g8b8"}, RGB24},
+	{{"rgba32", "r8g8b8a8"}, RGBA32},
+	{{"argb32", "a8r8g8b8"}, ARGB32},
+	{{"xrgb32", "x8r8g8b8"}, XRGB32},
+	{{"bgr24", "b8g8r8"}, BGR24},
+	{{"abgr32", "a8b8g8r8"}, ABGR32},
+	{{"xbgr32", "x8b8g8r8"}, XBGR32},
+};
+
+static void
+usage(void)
+{
+	fprint(2, "usage: %s [-c CHAN]\n", argv0);
+	exits("usage");
+}
+
+void
+main(int argc, char **argv)
+{
+	Memimage *a, *b;
+	char *s;
+	int ci;
+
+	ci = -1;
+	ARGBEGIN{
+	case 'c':
+		s = EARGF(usage());
+		for(ci = 0;
+		    ci < nelem(chans) &&
+		    cistrcmp(chans[ci].name[0], s) != 0 &&
+		    cistrcmp(chans[ci].name[1], s) != 0;
+		    ci++)
+		;
+		if(ci >= nelem(chans)){
+			fprint(2, "invalid chan %s\n", s);
+			sysfatal("chan");
+		}
+		break;
+	default:
+		usage();
+	}ARGEND
+
+	memimageinit();
+	if((a = readmemimage(0)) == nil)
+		sysfatal("memory");
+	if(ci >= 0 && a->chan != chans[ci].chan){
+		if((b = allocmemimage(a->r, chans[ci].chan)) == nil)
+			sysfatal("memory");
+		memimagedraw(b, a->r, a, ZP, nil, ZP, S);
+		freememimage(a);
+		a = b;
+	}
+	writememimage(1, a);
+
+	exits(nil);
+}
--- a/mkfile
+++ b/mkfile
@@ -2,7 +2,7 @@
 
 MAN=/sys/man/1
 CFLAGS=$CFLAGS -p
-TARG=resample convert
+TARG=iconv resample
 BIN=/$objtype/bin
 HFILES=stb_image_resize.h
 UPDATE=$HFILES