annotate lunalcd/ppmtocmd.c @ 165:7a4e8d23ab3a

eeproms/icestick: programming for Lattice Icestick
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 30 Jul 2023 18:10:51 +0000
parents 09d26f19a2c2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <stdio.h>
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <ctype.h>
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 static char *ppm_filename;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 static FILE *ppmfile;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 static int ppm_is_ascii; /* P3 format instead of P6 */
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 /*
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * This function reads one ASCII-encoded integer from a PPM file.
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * It handles the white space and comment rules of the PPM format.
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 */
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static int
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 ppm_get_ascii_number()
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 int accum, c;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 do {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 c = getc(ppmfile);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (c < 0) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 badeof: fprintf(stderr, "%s: unexpected EOF\n", ppm_filename);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (c == '#') {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 do
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 c = getc(ppmfile);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 while (c >= 0 && c != '\n');
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (c != '\n')
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 goto badeof;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 } while (isspace(c));
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (!isdigit(c)) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 fprintf(stderr,
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 "%s: unexpected data where a number was expected\n",
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 ppm_filename);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 for (accum = c - '0'; ; ) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 c = getc(ppmfile);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (c < 0 || isspace(c))
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 break;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (!isdigit(c)) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 fprintf(stderr,
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 "%s: bad character in the middle of a number\n",
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 ppm_filename);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 accum = accum * 10 + c - '0';
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return accum;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 /*
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 * This function reads and parses the PPM header of our input file.
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 */
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 static int
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 ppm_read_header()
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 int magic1, magic2;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 int rd;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 magic1 = getc(ppmfile);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 magic2 = getc(ppmfile);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (magic1 == 'P' && magic2 == '3')
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 ppm_is_ascii = 1;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 else if (magic1 == 'P' && magic2 == '6')
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 ppm_is_ascii = 0;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 else {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 fprintf(stderr, "%s: P3 or P6 format expected\n", ppm_filename);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 rd = ppm_get_ascii_number();
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (rd < 0)
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (rd != 176) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 fprintf(stderr, "%s: width is not 176\n", ppm_filename);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 rd = ppm_get_ascii_number();
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (rd < 0)
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (rd != 220) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 fprintf(stderr, "%s: height is not 220\n", ppm_filename);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 rd = ppm_get_ascii_number();
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (rd < 0)
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (rd != 255) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 fprintf(stderr, "%s: maxval is not 255\n", ppm_filename);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 return(0);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 /*
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 * This function reads a single R, G or B value from a PPM file.
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 */
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 static int
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 ppm_get_pixval()
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 int c;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 if (ppm_is_ascii)
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 return ppm_get_ascii_number();
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 c = getc(ppmfile);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 if (c < 0) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 fprintf(stderr, "%s: EOF while reading binary pixel data\n",
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 ppm_filename);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 return c;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 static int
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 ppm_get_rgb()
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 int r, g, b;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 r = ppm_get_pixval();
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 if (r < 0)
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 g = ppm_get_pixval();
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 if (g < 0)
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 b = ppm_get_pixval();
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 if (b < 0)
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 return(-1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 /* convert to 5:6:5 */
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 r >>= 3;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 g >>= 2;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 b >>= 3;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 return (r << 11) | (g << 5) | b;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 main(argc, argv)
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 char **argv;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 int rc;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 unsigned n;
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 if (argc != 3) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 fprintf(stderr, "usage: %s ppmfile output-mode\n", argv[0]);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 exit(1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 ppm_filename = argv[1];
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 ppmfile = fopen(ppm_filename, "r");
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 if (!ppmfile) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 perror(ppm_filename);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 exit(1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 rc = ppm_read_header();
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 if (rc < 0)
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 exit(1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 set_output_mode(argv[2]);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 write_ir(0x20);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 write_dr(0);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 write_ir(0x21);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 write_dr(0);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 write_ir(0x22);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 bulk_wd_prep();
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 for (n = 0; n < 176*220; n++) {
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 rc = ppm_get_rgb();
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 if (rc < 0)
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 exit(1);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 bulk_wd(rc);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 }
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 exit(0);
09d26f19a2c2 lunalcd: ppmtocmd program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 }