1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 Simple V4L2 grabber interactive example.
35 int main(int argc
, char *argv
[])
39 const char *v4l2_device
= "/dev/video0";
40 unsigned int w
= 640, h
= 480;
44 while ((opt
= getopt(argc
, argv
, "d:hH:W:l:")) != -1) {
56 gp_set_debug_level(atoi(optarg
));
59 printf("Usage; %s opts\n", argv
[0]);
60 printf("-d v4l2 device name (default is '/dev/video0'\n"
61 "-W output image width, default is 640\n"
62 "-H output image height, default is 480\n"
63 "-l sets GFXprim debug level (default is 0)\n"
64 "-h prints this help\n");
68 fprintf(stderr
, "Invalid paramter '%c'\n", opt
);
73 grabber
= gp_grabber_v4l2_init(v4l2_device
, w
, h
);
75 if (grabber
== NULL
) {
76 fprintf(stderr
, "Failed to initalize grabber '%s': %s\n",
77 v4l2_device
, strerror(errno
));
81 backend
= gp_x11_init(NULL
, 0, 0, grabber
->frame
->w
,
82 grabber
->frame
->h
, "V4L2", 0);
84 if (backend
== NULL
) {
85 gp_grabber_exit(grabber
);
89 if (gp_grabber_start(grabber
)) {
90 fprintf(stderr
, "Failed to start grabber\n");
91 gp_backend_exit(backend
);
92 gp_grabber_exit(grabber
);
96 printf("Press SPACE to change mode and Q to exit.\n");
99 if (gp_grabber_poll(grabber
) > 0) {
100 gp_pixmap
*res
, *img
= grabber
->frame
;
107 // gp_filter_edge_prewitt(img, &res, NULL, NULL);
108 gp_filter_edge_sobel(img
, &res
, NULL
, NULL
);
111 gp_filter_gaussian_blur(img
, img
, 1, 1, NULL
);
112 res
= gp_filter_floyd_steinberg_alloc(img
, GP_PIXEL_G2
, NULL
);
116 unsigned int c_x
= (backend
->pixmap
->w
- res
->w
) / 2;
117 unsigned int c_y
= (backend
->pixmap
->h
- res
->h
) / 2;
119 gp_blit_clipped(res
, 0, 0, res
->w
, res
->h
, backend
->pixmap
, c_x
, c_y
);
120 gp_backend_flip(backend
);
128 gp_backend_poll(backend
);
130 /* Read and parse events */
133 while (gp_backend_get_event(backend
, &ev
)) {
137 /* ignore key up events */
141 switch (ev
.val
.key
.key
) {
144 gp_backend_exit(backend
);
145 gp_grabber_exit(grabber
);
158 if (ev
.code
== GP_EV_SYS_RESIZE
) {
159 gp_backend_resize_ack(backend
);
160 gp_fill(backend
->pixmap
, 0);
167 gp_backend_exit(backend
);