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-2012 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 Simple V4L2 grabber interactive example.
33 #include <backends/GP_X11.h>
35 int main(int argc
, char *argv
[])
39 const char *v4l2_device
= "/dev/video0";
40 unsigned int w
= 320, h
= 240;
44 /* Turn on debug messages */
45 //GP_SetDebugLevel(10);
47 while ((opt
= getopt(argc
, argv
, "d:hH:W:l:")) != -1) {
59 GP_SetDebugLevel(atoi(optarg
));
62 printf("Usage; %s opts\n", argv
[0]);
63 printf("-d v4l2 device name (default is '/dev/video0'\n"
64 "-W output image width, default is 640\n"
65 "-H output image height, default is 480\n"
66 "-l sets GFXprim debug level (default is 0)\n"
67 "-h prints this help\n");
71 fprintf(stderr
, "Invalid paramter '%c'\n", opt
);
76 grabber
= GP_GrabberV4L2Init(v4l2_device
, w
, h
);
78 if (grabber
== NULL
) {
79 fprintf(stderr
, "Failed to initalize grabber '%s': %s\n",
80 v4l2_device
, strerror(errno
));
84 backend
= GP_BackendX11Init(NULL
, 0, 0, grabber
->frame
->w
,
85 grabber
->frame
->h
, "V4L2", 0);
87 if (backend
== NULL
) {
88 GP_GrabberExit(grabber
);
92 if (GP_GrabberStart(grabber
)) {
93 fprintf(stderr
, "Failed to start grabber\n");
94 GP_BackendExit(backend
);
95 GP_GrabberExit(grabber
);
99 printf("Press SPACE to change mode and Q to exit.\n");
102 if (GP_GrabberPoll(grabber
) > 0) {
103 GP_Context
*res
, *img
= grabber
->frame
;
110 GP_FilterEdgePrewitt(img
, &res
, NULL
, NULL
);
111 // GP_FilterEdgeSobel(img, &res, NULL, NULL);
114 GP_FilterGaussianBlur(img
, img
, 1, 1, NULL
);
115 res
= GP_FilterFloydSteinberg_RGB888_Alloc(img
, GP_PIXEL_G2
, NULL
);
119 GP_Blit_Clipped(res
, 0, 0, res
->w
, res
->h
, backend
->context
, 0, 0);
120 GP_BackendFlip(backend
);
128 GP_BackendPoll(backend
);
130 /* Read and parse events */
133 while (GP_EventGet(&ev
)) {
137 /* ignore key up events */
141 switch (ev
.val
.key
.key
) {
144 GP_BackendExit(backend
);
145 GP_GrabberExit(grabber
);
160 GP_BackendExit(backend
);