Commit | Line | Data |
---|---|---|
5377d91f MH |
1 | .. -*- coding: utf-8; mode: rst -*- |
2 | ||
3 | ******** | |
4 | Examples | |
5 | ******** | |
6 | ||
7 | (A video capture device is assumed; change | |
8 | ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other devices; change target to | |
9 | ``V4L2_SEL_TGT_COMPOSE_*`` family to configure composing area) | |
10 | ||
11 | ||
12 | .. code-block:: c | |
dd96815f | 13 | :caption: Example 1.15. Resetting the cropping parameters |
5377d91f | 14 | |
0579e6e3 MCC |
15 | struct v4l2_selection sel = { |
16 | .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, | |
17 | .target = V4L2_SEL_TGT_CROP_DEFAULT, | |
18 | }; | |
19 | ret = ioctl(fd, VIDIOC_G_SELECTION, &sel); | |
20 | if (ret) | |
21 | exit(-1); | |
22 | sel.target = V4L2_SEL_TGT_CROP; | |
23 | ret = ioctl(fd, VIDIOC_S_SELECTION, &sel); | |
24 | if (ret) | |
25 | exit(-1); | |
5377d91f MH |
26 | |
27 | Setting a composing area on output of size of *at most* half of limit | |
28 | placed at a center of a display. | |
29 | ||
30 | ||
31 | .. code-block:: c | |
dd96815f | 32 | :caption: Example 1.16. Simple downscaling |
5377d91f | 33 | |
0579e6e3 MCC |
34 | struct v4l2_selection sel = { |
35 | .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, | |
36 | .target = V4L2_SEL_TGT_COMPOSE_BOUNDS, | |
37 | }; | |
38 | struct v4l2_rect r; | |
39 | ||
40 | ret = ioctl(fd, VIDIOC_G_SELECTION, &sel); | |
41 | if (ret) | |
42 | exit(-1); | |
43 | /* setting smaller compose rectangle */ | |
44 | r.width = sel.r.width / 2; | |
45 | r.height = sel.r.height / 2; | |
46 | r.left = sel.r.width / 4; | |
47 | r.top = sel.r.height / 4; | |
48 | sel.r = r; | |
49 | sel.target = V4L2_SEL_TGT_COMPOSE; | |
50 | sel.flags = V4L2_SEL_FLAG_LE; | |
51 | ret = ioctl(fd, VIDIOC_S_SELECTION, &sel); | |
52 | if (ret) | |
53 | exit(-1); | |
5377d91f MH |
54 | |
55 | A video output device is assumed; change ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` | |
56 | for other devices | |
57 | ||
58 | ||
59 | .. code-block:: c | |
dd96815f | 60 | :caption: Example 1.17. Querying for scaling factors |
5377d91f | 61 | |
0579e6e3 MCC |
62 | struct v4l2_selection compose = { |
63 | .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, | |
64 | .target = V4L2_SEL_TGT_COMPOSE, | |
65 | }; | |
66 | struct v4l2_selection crop = { | |
67 | .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, | |
68 | .target = V4L2_SEL_TGT_CROP, | |
69 | }; | |
70 | double hscale, vscale; | |
71 | ||
72 | ret = ioctl(fd, VIDIOC_G_SELECTION, &compose); | |
73 | if (ret) | |
74 | exit(-1); | |
75 | ret = ioctl(fd, VIDIOC_G_SELECTION, &crop); | |
76 | if (ret) | |
77 | exit(-1); | |
78 | ||
79 | /* computing scaling factors */ | |
80 | hscale = (double)compose.r.width / crop.r.width; | |
81 | vscale = (double)compose.r.height / crop.r.height; |