Rev Author Line No. Line
1109 kaklik 1 #include <stdlib.h>
2 #include <string.h>
3 #include <assert.h>
4 #include <time.h>
5 #include <iostream>
6 #include <CImg.h>
7  
8 using namespace cimg_library;
9  
10 void read(void *p, int s)
11 {
12 while (s) {
13 int r = fread(p, sizeof(unsigned char), s, stdin);
14 p += r;
15 s -= r;
16 }
17 }
18  
19 int catch_ffs()
20 {
21 int i = 0;
22 int x;
23 unsigned char c;
24 unsigned char buffer[4];
25  
26 for (x = 0; x < 4; x++)
27 buffer[x] = 0;
28  
29 while (1) {
30 read(&c, 1);
31  
32 buffer[i % 4] = c;
33  
34 i++;
35  
36 if (buffer[0] == 0xff
37 && buffer[1] == 0xff
38 && buffer[2] == 0xff
39 && buffer[3] == 0xff) {
40 return i;
41 }
42 }
43  
44 return -1;
45 }
46  
47 int main(int argc, char **argv) {
48 char buffer[900];
49 CImg<unsigned char> image(120, 120, 1, 1);
50  
51 CImgDisplay display(image, "omview");
52  
53 fprintf(stderr, "waiting for initial synchronization... ");
54 fflush(stderr);
55 catch_ffs();
56 fprintf(stderr, "done\n");
57  
58 while (!display.is_closed()) {
59 read(buffer, 900);
60  
61 assert(catch_ffs() == 4);
62  
63 cimg_forXY(image, x, y) { image(x, y) = buffer[(y >> 2) * 30 + (x >> 2)] * 4; }
64  
65 image.display(display);
66  
67 fprintf(stderr, "new frame\n");
68 }
69  
70 return 0;
71 }