1 .. SPDX-License-Identifier: GFDL-1.1-no-invari 1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2 2 3 ******** 3 ******** 4 Examples 4 Examples 5 ******** 5 ******** 6 6 7 (A video capture device is assumed; change 7 (A video capture device is assumed; change 8 ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other devi 8 ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other devices; change target to 9 ``V4L2_SEL_TGT_COMPOSE_*`` family to configure 9 ``V4L2_SEL_TGT_COMPOSE_*`` family to configure composing area) 10 10 11 Example: Resetting the cropping parameters 11 Example: Resetting the cropping parameters 12 ========================================== 12 ========================================== 13 13 14 .. code-block:: c 14 .. code-block:: c 15 15 16 struct v4l2_selection sel = { 16 struct v4l2_selection sel = { 17 .type = V4L2_BUF_TYPE_VIDEO_CAPTUR 17 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, 18 .target = V4L2_SEL_TGT_CROP_DEFAUL 18 .target = V4L2_SEL_TGT_CROP_DEFAULT, 19 }; 19 }; 20 ret = ioctl(fd, VIDIOC_G_SELECTION, &s 20 ret = ioctl(fd, VIDIOC_G_SELECTION, &sel); 21 if (ret) 21 if (ret) 22 exit(-1); 22 exit(-1); 23 sel.target = V4L2_SEL_TGT_CROP; 23 sel.target = V4L2_SEL_TGT_CROP; 24 ret = ioctl(fd, VIDIOC_S_SELECTION, &s 24 ret = ioctl(fd, VIDIOC_S_SELECTION, &sel); 25 if (ret) 25 if (ret) 26 exit(-1); 26 exit(-1); 27 27 28 Setting a composing area on output of size of 28 Setting a composing area on output of size of *at most* half of limit 29 placed at a center of a display. 29 placed at a center of a display. 30 30 31 Example: Simple downscaling 31 Example: Simple downscaling 32 =========================== 32 =========================== 33 33 34 .. code-block:: c 34 .. code-block:: c 35 35 36 struct v4l2_selection sel = { 36 struct v4l2_selection sel = { 37 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT 37 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, 38 .target = V4L2_SEL_TGT_COMPOSE_BOU 38 .target = V4L2_SEL_TGT_COMPOSE_BOUNDS, 39 }; 39 }; 40 struct v4l2_rect r; 40 struct v4l2_rect r; 41 41 42 ret = ioctl(fd, VIDIOC_G_SELECTION, &s 42 ret = ioctl(fd, VIDIOC_G_SELECTION, &sel); 43 if (ret) 43 if (ret) 44 exit(-1); 44 exit(-1); 45 /* setting smaller compose rectangle * 45 /* setting smaller compose rectangle */ 46 r.width = sel.r.width / 2; 46 r.width = sel.r.width / 2; 47 r.height = sel.r.height / 2; 47 r.height = sel.r.height / 2; 48 r.left = sel.r.width / 4; 48 r.left = sel.r.width / 4; 49 r.top = sel.r.height / 4; 49 r.top = sel.r.height / 4; 50 sel.r = r; 50 sel.r = r; 51 sel.target = V4L2_SEL_TGT_COMPOSE; 51 sel.target = V4L2_SEL_TGT_COMPOSE; 52 sel.flags = V4L2_SEL_FLAG_LE; 52 sel.flags = V4L2_SEL_FLAG_LE; 53 ret = ioctl(fd, VIDIOC_S_SELECTION, &s 53 ret = ioctl(fd, VIDIOC_S_SELECTION, &sel); 54 if (ret) 54 if (ret) 55 exit(-1); 55 exit(-1); 56 56 57 A video output device is assumed; change ``V4L 57 A video output device is assumed; change ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` 58 for other devices 58 for other devices 59 59 60 Example: Querying for scaling factors 60 Example: Querying for scaling factors 61 ===================================== 61 ===================================== 62 62 63 .. code-block:: c 63 .. code-block:: c 64 64 65 struct v4l2_selection compose = { 65 struct v4l2_selection compose = { 66 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT 66 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, 67 .target = V4L2_SEL_TGT_COMPOSE, 67 .target = V4L2_SEL_TGT_COMPOSE, 68 }; 68 }; 69 struct v4l2_selection crop = { 69 struct v4l2_selection crop = { 70 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT 70 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, 71 .target = V4L2_SEL_TGT_CROP, 71 .target = V4L2_SEL_TGT_CROP, 72 }; 72 }; 73 double hscale, vscale; 73 double hscale, vscale; 74 74 75 ret = ioctl(fd, VIDIOC_G_SELECTION, &c 75 ret = ioctl(fd, VIDIOC_G_SELECTION, &compose); 76 if (ret) 76 if (ret) 77 exit(-1); 77 exit(-1); 78 ret = ioctl(fd, VIDIOC_G_SELECTION, &c 78 ret = ioctl(fd, VIDIOC_G_SELECTION, &crop); 79 if (ret) 79 if (ret) 80 exit(-1); 80 exit(-1); 81 81 82 /* computing scaling factors */ 82 /* computing scaling factors */ 83 hscale = (double)compose.r.width / cro 83 hscale = (double)compose.r.width / crop.r.width; 84 vscale = (double)compose.r.height / cr 84 vscale = (double)compose.r.height / crop.r.height;
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.