changeset 961:813287f7169c

fc-rgbconv utility written and added
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Fri, 06 Nov 2015 19:31:42 +0000
parents 120148429b9f
children f4da3071dd61
files .hgignore miscutil/Makefile miscutil/fc-rgbconv.c
diffstat 3 files changed, 82 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Nov 06 17:42:00 2015 +0000
+++ b/.hgignore	Fri Nov 06 19:31:42 2015 +0000
@@ -24,6 +24,7 @@
 ^loadtools/fc-loadtool$
 ^loadtools/fc-xram$
 
+^miscutil/fc-rgbconv$
 ^miscutil/fc-serterm$
 ^miscutil/imei-luhn$
 
--- a/miscutil/Makefile	Fri Nov 06 17:42:00 2015 +0000
+++ b/miscutil/Makefile	Fri Nov 06 19:31:42 2015 +0000
@@ -1,12 +1,15 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	fc-serterm imei-luhn
+PROGS=	fc-rgbconv fc-serterm imei-luhn
 INSTBIN=/usr/local/bin
 
 all:	${PROGS}
 
 SERTERM_OBJS=	fc-serterm.o openport.o ttypassthru.o
 
+fc-rgbconv:	fc-rgbconv.c
+	${CC} ${CFLAGS} -o $@ $@.c
+
 fc-serterm:	${SERTERM_OBJS}
 	${CC} ${CFLAGS} -o $@ ${SERTERM_OBJS}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/miscutil/fc-rgbconv.c	Fri Nov 06 19:31:42 2015 +0000
@@ -0,0 +1,77 @@
+/*
+ * This utility is an aid for phone UI development.  The color LCDs in the
+ * phones targeted by FreeCalypso implement 16-bit color in RGB 5:6:5 format,
+ * but these 16-bit color words are not particularly intuitive in raw hex form.
+ * In contrast, a 24-bit RGB 8:8:8 color given in RRGGBB hex form is quite
+ * intuitive, at least to those who understand RGB.
+ *
+ * This utility performs the conversion.  It takes a single command line
+ * argument that must be either 4 or 6 hex digits.  If the argument is 4 hex
+ * digits, it is interpreted as RGB 5:6:5 and converted into RGB 8:8:8.
+ * If the argument is 6 hex digits, it is interpreted as RGB 8:8:8 and
+ * converted into RGB 5:6:5.  The output of the conversion is emitted on
+ * stdout as 4 or 6 hex digits.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+is_arg_all_hex(str)
+	char *str;
+{
+	char *cp;
+	int c;
+
+	for (cp = str; c = *cp++; )
+		if (!isxdigit(c))
+			return(0);
+	return(1);
+}
+
+convert_565_to_888(in)
+	unsigned in;
+{
+	unsigned r, g, b;
+
+	r = in >> 11;
+	g = (in >> 5) & 0x3F;
+	b = in & 0x1F;
+	printf("%02X%02X%02X\n", r << 3, g << 2, b << 3);
+}
+
+convert_888_to_565(in)
+	unsigned in;
+{
+	unsigned r, g, b;
+
+	r = (in >> 16) >> 3;
+	g = ((in >> 8) & 0xFF) >> 2;
+	b = (in & 0xFF) >> 3;
+	printf("%04X\n", (r << 11) | (g << 5) | b);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	unsigned in;
+
+	if (argc != 2) {
+usage:		fprintf(stderr,
+		    "please specify one 4-digit or 6-digit hex RGB value\n");
+		exit(1);
+	}
+	if (!is_arg_all_hex(argv[1]))
+		goto usage;
+	in = strtoul(argv[1], 0, 16);
+	switch (strlen(argv[1])) {
+	case 4:
+		convert_565_to_888(in);
+		exit(0);
+	case 6:
+		convert_888_to_565(in);
+		exit(0);
+	}
+	goto usage;
+}