FreeCalypso > hg > freecalypso-reveng
annotate miscprog/fbdump2ppm.c @ 317:c71e3156170a
frbl/reconst: boot.c passes compilation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 04 Mar 2020 23:58:05 +0000 |
parents | 81641d82ccc6 |
children |
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. |
274
81641d82ccc6
fbdump2ppm: adjust for R2D's extra 32-bit word
Mychaela Falconia <falcon@freecalypso.org>
parents:
273
diff
changeset
|
4 * |
81641d82ccc6
fbdump2ppm: adjust for R2D's extra 32-bit word
Mychaela Falconia <falcon@freecalypso.org>
parents:
273
diff
changeset
|
5 * TI's R2D code adds an extra 32-bit word to each horizontal line in its |
81641d82ccc6
fbdump2ppm: adjust for R2D's extra 32-bit word
Mychaela Falconia <falcon@freecalypso.org>
parents:
273
diff
changeset
|
6 * framebuffer representation, hence one needs to capture 0x131F0 bytes |
81641d82ccc6
fbdump2ppm: adjust for R2D's extra 32-bit word
Mychaela Falconia <falcon@freecalypso.org>
parents:
273
diff
changeset
|
7 * (178*2*220 instead of 176*2*220), and we treat the image as being |
81641d82ccc6
fbdump2ppm: adjust for R2D's extra 32-bit word
Mychaela Falconia <falcon@freecalypso.org>
parents:
273
diff
changeset
|
8 * 178x220 pixels for simplicity. |
273
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 |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <sys/types.h> |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdio.h> |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdlib.h> |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
274
81641d82ccc6
fbdump2ppm: adjust for R2D's extra 32-bit word
Mychaela Falconia <falcon@freecalypso.org>
parents:
273
diff
changeset
|
15 #define NPIX (178*220) |
273
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 FILE *inf, *outf; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 convert_pixel() |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 int i, c; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 u_char inb[2]; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 unsigned pix16, r, g, b; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 for (i = 0; i < 2; i++) { |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 c = getc(inf); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (c < 0) { |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(stderr, "error: input is too short\n"); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(1); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 inb[i] = c; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 pix16 = (inb[0] | (inb[1] << 8)) ^ 0xFFFF; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 r = pix16 >> 11; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 g = (pix16 >> 5) & 0x3F; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 b = pix16 & 0x1F; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 putc(r << 3, outf); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 putc(g << 2, outf); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 putc(b << 3, outf); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
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 main(argc, argv) |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 char **argv; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 { |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 unsigned n; |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (argc != 3) { |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 fprintf(stderr, "usage: %s infile outfile\n", argv[0]); |
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 inf = fopen(argv[1], "r"); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (!inf) { |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 perror(argv[1]); |
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 outf = fopen(argv[2], "w"); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (!outf) { |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 perror(argv[2]); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 exit(1); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
274
81641d82ccc6
fbdump2ppm: adjust for R2D's extra 32-bit word
Mychaela Falconia <falcon@freecalypso.org>
parents:
273
diff
changeset
|
61 fprintf(outf, "P6\n178 220\n255\n"); |
273
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 for (n = 0; n < NPIX; n++) |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 convert_pixel(); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 exit(0); |
f233f0a012c9
miscprog: fbdump2ppm program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |