forked from cirosantilli/cpp-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
take_pictures_docs_min.c
52 lines (46 loc) · 1.1 KB
/
take_pictures_docs_min.c
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
46
47
48
49
50
51
52
/* Minimization of take_pictures_docs.c */
#include <stdio.h>
#include <stdlib.h>
#include "common_v4l2.h"
static void save_ppm(
unsigned int i,
unsigned int x_res,
unsigned int y_res,
size_t data_lenght,
char *data
) {
FILE *fout;
char out_name[256];
sprintf(out_name, "out%03d.ppm", i);
fout = fopen(out_name, "w");
if (!fout) {
perror("error: fopen");
exit(EXIT_FAILURE);
}
fprintf(fout, "P6\n%d %d 255\n", x_res, y_res);
fwrite(data, data_lenght, 1, fout);
fclose(fout);
}
int main(void) {
CommonV4l2 common_v4l2;
char *dev_name = "/dev/video0";
struct buffer *buffers;
unsigned int
i,
x_res = 640,
y_res = 480
;
CommonV4l2_init(&common_v4l2, dev_name, x_res, y_res);
for (i = 0; i < 20; i++) {
CommonV4l2_updateImage(&common_v4l2);
save_ppm(
i,
x_res,
y_res,
CommonV4l2_getImageSize(&common_v4l2),
CommonV4l2_getImage(&common_v4l2)
);
}
CommonV4l2_deinit(&common_v4l2);
return EXIT_SUCCESS;
}