FreeCalypso > hg > freecalypso-reveng
view miscprog/fbdump2ppm.c @ 273:f233f0a012c9
miscprog: fbdump2ppm program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 20 Jan 2018 20:46:08 +0000 |
parents | |
children | 81641d82ccc6 |
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. */ #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); }