blob: 61160b6be4f6c9a06c725ee777f68e1d27c3db13 [file] [log] [blame]
Markus Heiser5377d912016-06-30 15:18:56 +02001.. -*- coding: utf-8; mode: rst -*-
2
3********
4Examples
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
13
14 struct v4l2_selection sel = {
15 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
16 .target = V4L2_SEL_TGT_CROP_DEFAULT,
17 };
18 ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
19 if (ret)
20 exit(-1);
21 sel.target = V4L2_SEL_TGT_CROP;
22 ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
23 if (ret)
24 exit(-1);
25
26Setting a composing area on output of size of *at most* half of limit
27placed at a center of a display.
28
29
30.. code-block:: c
31
32 struct v4l2_selection sel = {
33 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
34 .target = V4L2_SEL_TGT_COMPOSE_BOUNDS,
35 };
36 struct v4l2_rect r;
37
38 ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
39 if (ret)
40 exit(-1);
41 /* setting smaller compose rectangle */
42 r.width = sel.r.width / 2;
43 r.height = sel.r.height / 2;
44 r.left = sel.r.width / 4;
45 r.top = sel.r.height / 4;
46 sel.r = r;
47 sel.target = V4L2_SEL_TGT_COMPOSE;
48 sel.flags = V4L2_SEL_FLAG_LE;
49 ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
50 if (ret)
51 exit(-1);
52
53A video output device is assumed; change ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
54for other devices
55
56
57.. code-block:: c
58
59 struct v4l2_selection compose = {
60 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
61 .target = V4L2_SEL_TGT_COMPOSE,
62 };
63 struct v4l2_selection crop = {
64 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
65 .target = V4L2_SEL_TGT_CROP,
66 };
67 double hscale, vscale;
68
69 ret = ioctl(fd, VIDIOC_G_SELECTION, &compose);
70 if (ret)
71 exit(-1);
72 ret = ioctl(fd, VIDIOC_G_SELECTION, &crop);
73 if (ret)
74 exit(-1);
75
76 /* computing scaling factors */
77 hscale = (double)compose.r.width / crop.r.width;
78 vscale = (double)compose.r.height / crop.r.height;
79
80
81
82
83.. ------------------------------------------------------------------------------
84.. This file was automatically converted from DocBook-XML with the dbxml
85.. library (https://github.com/return42/sphkerneldoc). The origin XML comes
86.. from the linux kernel, refer to:
87..
88.. * https://github.com/torvalds/linux/tree/master/Documentation/DocBook
89.. ------------------------------------------------------------------------------