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