blob: 0c91891a592890f221ebf863322015fd71548536 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include <stdio.h>
#include <stdint.h>
int main(int argc, char **argv)
{
uint8_t color_value = 0;
uint8_t bits_read = 0;
uint8_t channels_read = 0;
int pixels_processed = 0;
int input;
/* http://netpbm.sourceforge.net/doc/ppm.html */
puts("P3");
puts("640 480");
puts("7");
while (1) {
input = getchar();
if (input == EOF)
break;
if (input != '1' && input != '0')
continue;
if (input == '1')
color_value |= 1 << (2 - bits_read);
if (++bits_read == 3) {
printf(" %d", color_value);
color_value = 0;
bits_read = 0;
if (++channels_read == 3) {
channels_read = 0;
putchar(++pixels_processed % 8 == 0 ?
'\n' : ' ');
}
}
}
return 0;
}
|