view miscprog/fbdump2ppm.c @ 355:e77d478e3724

fluid-mnf/fluid.[ch]: arg_uart_flowcontrol[] removed
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 13 Mar 2020 19:59:27 +0000
parents 81641d82ccc6
children
line wrap: on
line source

/*
 * This program converts a dump of TI's R2D framebuffer (176x220 pix, 16-bit)
 * captured via fc-memdump into PPM format for viewing.
 *
 * TI's R2D code adds an extra 32-bit word to each horizontal line in its
 * framebuffer representation, hence one needs to capture 0x131F0 bytes
 * (178*2*220 instead of 176*2*220), and we treat the image as being
 * 178x220 pixels for simplicity.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>

#define	NPIX	(178*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\n178 220\n255\n");
	for (n = 0; n < NPIX; n++)
		convert_pixel();
	exit(0);
}