0001 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
0002
0003 ********
0004 Examples
0005 ********
0006
0007 (A video capture device is assumed; change
0008 ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other devices; change target to
0009 ``V4L2_SEL_TGT_COMPOSE_*`` family to configure composing area)
0010
0011 Example: Resetting the cropping parameters
0012 ==========================================
0013
0014 .. code-block:: c
0015
0016 struct v4l2_selection sel = {
0017 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
0018 .target = V4L2_SEL_TGT_CROP_DEFAULT,
0019 };
0020 ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
0021 if (ret)
0022 exit(-1);
0023 sel.target = V4L2_SEL_TGT_CROP;
0024 ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
0025 if (ret)
0026 exit(-1);
0027
0028 Setting a composing area on output of size of *at most* half of limit
0029 placed at a center of a display.
0030
0031 Example: Simple downscaling
0032 ===========================
0033
0034 .. code-block:: c
0035
0036 struct v4l2_selection sel = {
0037 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
0038 .target = V4L2_SEL_TGT_COMPOSE_BOUNDS,
0039 };
0040 struct v4l2_rect r;
0041
0042 ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
0043 if (ret)
0044 exit(-1);
0045 /* setting smaller compose rectangle */
0046 r.width = sel.r.width / 2;
0047 r.height = sel.r.height / 2;
0048 r.left = sel.r.width / 4;
0049 r.top = sel.r.height / 4;
0050 sel.r = r;
0051 sel.target = V4L2_SEL_TGT_COMPOSE;
0052 sel.flags = V4L2_SEL_FLAG_LE;
0053 ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
0054 if (ret)
0055 exit(-1);
0056
0057 A video output device is assumed; change ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
0058 for other devices
0059
0060 Example: Querying for scaling factors
0061 =====================================
0062
0063 .. code-block:: c
0064
0065 struct v4l2_selection compose = {
0066 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
0067 .target = V4L2_SEL_TGT_COMPOSE,
0068 };
0069 struct v4l2_selection crop = {
0070 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
0071 .target = V4L2_SEL_TGT_CROP,
0072 };
0073 double hscale, vscale;
0074
0075 ret = ioctl(fd, VIDIOC_G_SELECTION, &compose);
0076 if (ret)
0077 exit(-1);
0078 ret = ioctl(fd, VIDIOC_G_SELECTION, &crop);
0079 if (ret)
0080 exit(-1);
0081
0082 /* computing scaling factors */
0083 hscale = (double)compose.r.width / crop.r.width;
0084 vscale = (double)compose.r.height / crop.r.height;