1 .. Permission is granted to copy, distribute and/or modify this
2 .. document under the terms of the GNU Free Documentation License,
3 .. Version 1.1 or any later version published by the Free Software
4 .. Foundation, with no Invariant Sections, no Front-Cover Texts
5 .. and no Back-Cover Texts. A copy of the license is included at
6 .. Documentation/userspace-api/media/fdl-appendix.rst.
8 .. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
14 (A video capture device is assumed; change
15 ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other devices; change target to
16 ``V4L2_SEL_TGT_COMPOSE_*`` family to configure composing area)
18 Example: Resetting the cropping parameters
19 ==========================================
23 struct v4l2_selection sel = {
24 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
25 .target = V4L2_SEL_TGT_CROP_DEFAULT,
27 ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
30 sel.target = V4L2_SEL_TGT_CROP;
31 ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
35 Setting a composing area on output of size of *at most* half of limit
36 placed at a center of a display.
38 Example: Simple downscaling
39 ===========================
43 struct v4l2_selection sel = {
44 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
45 .target = V4L2_SEL_TGT_COMPOSE_BOUNDS,
49 ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
52 /* setting smaller compose rectangle */
53 r.width = sel.r.width / 2;
54 r.height = sel.r.height / 2;
55 r.left = sel.r.width / 4;
56 r.top = sel.r.height / 4;
58 sel.target = V4L2_SEL_TGT_COMPOSE;
59 sel.flags = V4L2_SEL_FLAG_LE;
60 ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
64 A video output device is assumed; change ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
67 Example: Querying for scaling factors
68 =====================================
72 struct v4l2_selection compose = {
73 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
74 .target = V4L2_SEL_TGT_COMPOSE,
76 struct v4l2_selection crop = {
77 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
78 .target = V4L2_SEL_TGT_CROP,
80 double hscale, vscale;
82 ret = ioctl(fd, VIDIOC_G_SELECTION, &compose);
85 ret = ioctl(fd, VIDIOC_G_SELECTION, &crop);
89 /* computing scaling factors */
90 hscale = (double)compose.r.width / crop.r.width;
91 vscale = (double)compose.r.height / crop.r.height;