comparison 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
comparison
equal deleted inserted replaced
272:8f08645901a0 273:f233f0a012c9
1 /*
2 * This program converts a dump of TI's R2D framebuffer (176x220 pix, 16-bit)
3 * captured via fc-memdump into PPM format for viewing.
4 */
5
6 #include <sys/types.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #define NPIX (176*220)
11
12 FILE *inf, *outf;
13
14 convert_pixel()
15 {
16 int i, c;
17 u_char inb[2];
18 unsigned pix16, r, g, b;
19
20 for (i = 0; i < 2; i++) {
21 c = getc(inf);
22 if (c < 0) {
23 fprintf(stderr, "error: input is too short\n");
24 exit(1);
25 }
26 inb[i] = c;
27 }
28 pix16 = (inb[0] | (inb[1] << 8)) ^ 0xFFFF;
29 r = pix16 >> 11;
30 g = (pix16 >> 5) & 0x3F;
31 b = pix16 & 0x1F;
32 putc(r << 3, outf);
33 putc(g << 2, outf);
34 putc(b << 3, outf);
35 }
36
37 main(argc, argv)
38 char **argv;
39 {
40 unsigned n;
41
42 if (argc != 3) {
43 fprintf(stderr, "usage: %s infile outfile\n", argv[0]);
44 exit(1);
45 }
46 inf = fopen(argv[1], "r");
47 if (!inf) {
48 perror(argv[1]);
49 exit(1);
50 }
51 outf = fopen(argv[2], "w");
52 if (!outf) {
53 perror(argv[2]);
54 exit(1);
55 }
56 fprintf(outf, "P6\n176 220\n255\n");
57 for (n = 0; n < NPIX; n++)
58 convert_pixel();
59 exit(0);
60 }