FreeCalypso > hg > freecalypso-hwlab
annotate lcdtest/showppm.c @ 151:d515cfbb3f39
fc-simtool: hex string parsing: add minimum length parameter
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Feb 2021 00:18:30 +0000 |
parents | 1d8c499711f1 |
children |
rev | line source |
---|---|
17
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <stdio.h> |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <ctype.h> |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdlib.h> |
19
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
4 #include <unistd.h> |
17
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 char *ppm_filename; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 FILE *ppmfile; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 int ppm_is_ascii; /* P3 format instead of P6 */ |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 /* |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * This function reads one ASCII-encoded integer from a PPM file. |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * It handles the white space and comment rules of the PPM format. |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 */ |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 static int |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 ppm_get_ascii_number() |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int accum, c; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 do { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 c = getc(ppmfile); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (c < 0) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 badeof: fprintf(stderr, "%s: unexpected EOF\n", ppm_filename); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (c == '#') { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 do |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 c = getc(ppmfile); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 while (c >= 0 && c != '\n'); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (c != '\n') |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 goto badeof; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } while (isspace(c)); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (!isdigit(c)) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fprintf(stderr, |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 "%s: unexpected data where a number was expected\n", |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 ppm_filename); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 for (accum = c - '0'; ; ) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 c = getc(ppmfile); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (c < 0 || isspace(c)) |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 break; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (!isdigit(c)) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 fprintf(stderr, |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 "%s: bad character in the middle of a number\n", |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 ppm_filename); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 accum = accum * 10 + c - '0'; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return accum; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 /* |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 * This function reads and parses the PPM header of our input file. |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 */ |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 static int |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 ppm_read_header() |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 int magic1, magic2; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 int rd; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 magic1 = getc(ppmfile); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 magic2 = getc(ppmfile); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 if (magic1 == 'P' && magic2 == '3') |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 ppm_is_ascii = 1; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 else if (magic1 == 'P' && magic2 == '6') |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 ppm_is_ascii = 0; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 else { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 fprintf(stderr, "%s: P3 or P6 format expected\n", ppm_filename); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 rd = ppm_get_ascii_number(); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (rd < 0) |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (rd != 176) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 fprintf(stderr, "%s: width is not 176\n", ppm_filename); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 rd = ppm_get_ascii_number(); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (rd < 0) |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (rd != 220) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 fprintf(stderr, "%s: height is not 220\n", ppm_filename); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 rd = ppm_get_ascii_number(); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (rd < 0) |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (rd != 255) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 fprintf(stderr, "%s: maxval is not 255\n", ppm_filename); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 return(0); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 /* |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 * This function reads a single R, G or B value from a PPM file. |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 */ |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 static int |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 ppm_get_pixval() |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 int c; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 if (ppm_is_ascii) |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 return ppm_get_ascii_number(); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 c = getc(ppmfile); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 if (c < 0) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 fprintf(stderr, "%s: EOF while reading binary pixel data\n", |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 ppm_filename); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 return c; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 static int |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 ppm_get_rgb() |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 int r, g, b; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 r = ppm_get_pixval(); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 if (r < 0) |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 g = ppm_get_pixval(); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 if (g < 0) |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 b = ppm_get_pixval(); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 if (b < 0) |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 /* convert to 5:6:5 */ |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 r >>= 3; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 g >>= 2; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 b >>= 3; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 return (r << 11) | (g << 5) | b; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 cmd_show(argc, argv) |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 char **argv; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 int rc; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 unsigned n; |
21
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
142 u_char ftbuf[176*220*6+3], *dp; |
17
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 ppm_filename = argv[1]; |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 ppmfile = fopen(ppm_filename, "r"); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 if (!ppmfile) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 perror(ppm_filename); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 rc = ppm_read_header(); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if (rc < 0) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 fclose(ppmfile); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 write_ir(0x20); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 write_dr(0); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 write_ir(0x21); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 write_dr(0); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 write_ir(0x22); |
21
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
160 /* GPIO setup */ |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
161 dp = ftbuf; |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
162 *dp++ = 0x82; |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
163 *dp++ = 0x03; |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
164 *dp++ = 0x03; |
17
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 for (n = 0; n < 176*220; n++) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 rc = ppm_get_rgb(); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 if (rc < 0) { |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 fclose(ppmfile); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 return(-1); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 } |
21
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
171 /* upper byte */ |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
172 *dp++ = 0x92; |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
173 *dp++ = 0; /* dummy addr */ |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
174 *dp++ = rc >> 8; |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
175 /* lower byte */ |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
176 *dp++ = 0x92; |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
177 *dp++ = 0; /* dummy addr */ |
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
178 *dp++ = rc; |
17
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 } |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 fclose(ppmfile); |
21
1d8c499711f1
lcdtest PPM display: sending the picture all at once is much faster
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
181 do_ftdi_write(ftbuf, sizeof ftbuf); |
17
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 return(0); |
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 } |
19
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
184 |
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
185 cmd_cd(argc, argv) |
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
186 char **argv; |
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
187 { |
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
188 if (chdir(argv[1]) < 0) { |
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
189 perror(argv[1]); |
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
190 return(-1); |
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
191 } |
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
192 return(0); |
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
193 } |