changeset 273:f233f0a012c9

miscprog: fbdump2ppm program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 Jan 2018 20:46:08 +0000
parents 8f08645901a0
children 81641d82ccc6
files .hgignore miscprog/Makefile miscprog/fbdump2ppm.c
diffstat 3 files changed, 65 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sat Jan 20 00:38:51 2018 +0000
+++ b/.hgignore	Sat Jan 20 20:46:08 2018 +0000
@@ -30,6 +30,7 @@
 ^miscprog/calextract$
 ^miscprog/cinitdump$
 ^miscprog/factdiff$
+^miscprog/fbdump2ppm$
 ^miscprog/ftmdump$
 ^miscprog/grokdsn$
 ^miscprog/imeibrute$
--- a/miscprog/Makefile	Sat Jan 20 00:38:51 2018 +0000
+++ b/miscprog/Makefile	Sat Jan 20 20:46:08 2018 +0000
@@ -1,8 +1,8 @@
 CC=	gcc
 CFLAGS=	-O2
-STD=	atsc calextract cinitdump factdiff ftmdump grokdsn memwrite-grep \
-	mokosrec2bin osmo2psi pirbattextr pircalextr pircksum pircksum2 \
-	rfcap-grep
+STD=	atsc calextract cinitdump factdiff fbdump2ppm ftmdump grokdsn \
+	memwrite-grep mokosrec2bin osmo2psi pirbattextr pircalextr pircksum \
+	pircksum2 rfcap-grep
 CRYPTO=	imeibrute pirimei
 PROGS=	${STD} ${CRYPTO}
 
@@ -18,6 +18,7 @@
 calextract:	calextract.c
 cinitdump:	cinitdump.c
 factdiff:	factdiff.c
+fbdump2ppm:	fbdump2ppm.c
 ftmdump:	ftmdump.c
 grokdsn:	grokdsn.c
 imeibrute:	imeibrute.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/miscprog/fbdump2ppm.c	Sat Jan 20 20:46:08 2018 +0000
@@ -0,0 +1,60 @@
+/*
+ * This program converts a dump of TI's R2D framebuffer (176x220 pix, 16-bit)
+ * captured via fc-memdump into PPM format for viewing.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define	NPIX	(176*220)
+
+FILE *inf, *outf;
+
+convert_pixel()
+{
+	int i, c;
+	u_char inb[2];
+	unsigned pix16, r, g, b;
+
+	for (i = 0; i < 2; i++) {
+		c = getc(inf);
+		if (c < 0) {
+			fprintf(stderr, "error: input is too short\n");
+			exit(1);
+		}
+		inb[i] = c;
+	}
+	pix16 = (inb[0] | (inb[1] << 8)) ^ 0xFFFF;
+	r = pix16 >> 11;
+	g = (pix16 >> 5) & 0x3F;
+	b = pix16 & 0x1F;
+	putc(r << 3, outf);
+	putc(g << 2, outf);
+	putc(b << 3, outf);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	unsigned n;
+
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s infile outfile\n", argv[0]);
+		exit(1);
+	}
+	inf = fopen(argv[1], "r");
+	if (!inf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	outf = fopen(argv[2], "w");
+	if (!outf) {
+		perror(argv[2]);
+		exit(1);
+	}
+	fprintf(outf, "P6\n176 220\n255\n");
+	for (n = 0; n < NPIX; n++)
+		convert_pixel();
+	exit(0);
+}