2020-08-26 15:03:09 +08:00
|
|
|
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
|
2018-08-30 22:15:26 +08:00
|
|
|
|
2016-06-30 21:18:56 +08:00
|
|
|
********
|
|
|
|
Examples
|
|
|
|
********
|
|
|
|
|
|
|
|
(A video capture device is assumed; change
|
|
|
|
``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other devices; change target to
|
|
|
|
``V4L2_SEL_TGT_COMPOSE_*`` family to configure composing area)
|
|
|
|
|
2016-07-10 19:22:19 +08:00
|
|
|
Example: Resetting the cropping parameters
|
|
|
|
==========================================
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
.. code-block:: c
|
|
|
|
|
2016-07-05 03:25:48 +08:00
|
|
|
struct v4l2_selection sel = {
|
|
|
|
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
|
|
|
|
.target = V4L2_SEL_TGT_CROP_DEFAULT,
|
|
|
|
};
|
|
|
|
ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
|
|
|
|
if (ret)
|
|
|
|
exit(-1);
|
|
|
|
sel.target = V4L2_SEL_TGT_CROP;
|
|
|
|
ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
|
|
|
|
if (ret)
|
|
|
|
exit(-1);
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
Setting a composing area on output of size of *at most* half of limit
|
|
|
|
placed at a center of a display.
|
|
|
|
|
2016-07-10 19:22:19 +08:00
|
|
|
Example: Simple downscaling
|
|
|
|
===========================
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
.. code-block:: c
|
|
|
|
|
2016-07-05 03:25:48 +08:00
|
|
|
struct v4l2_selection sel = {
|
|
|
|
.type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
|
|
|
|
.target = V4L2_SEL_TGT_COMPOSE_BOUNDS,
|
|
|
|
};
|
|
|
|
struct v4l2_rect r;
|
|
|
|
|
|
|
|
ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
|
|
|
|
if (ret)
|
|
|
|
exit(-1);
|
|
|
|
/* setting smaller compose rectangle */
|
|
|
|
r.width = sel.r.width / 2;
|
|
|
|
r.height = sel.r.height / 2;
|
|
|
|
r.left = sel.r.width / 4;
|
|
|
|
r.top = sel.r.height / 4;
|
|
|
|
sel.r = r;
|
|
|
|
sel.target = V4L2_SEL_TGT_COMPOSE;
|
|
|
|
sel.flags = V4L2_SEL_FLAG_LE;
|
|
|
|
ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
|
|
|
|
if (ret)
|
|
|
|
exit(-1);
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
A video output device is assumed; change ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
|
|
|
|
for other devices
|
|
|
|
|
2016-07-10 19:22:19 +08:00
|
|
|
Example: Querying for scaling factors
|
|
|
|
=====================================
|
2016-06-30 21:18:56 +08:00
|
|
|
|
|
|
|
.. code-block:: c
|
|
|
|
|
2016-07-05 03:25:48 +08:00
|
|
|
struct v4l2_selection compose = {
|
|
|
|
.type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
|
|
|
|
.target = V4L2_SEL_TGT_COMPOSE,
|
|
|
|
};
|
|
|
|
struct v4l2_selection crop = {
|
|
|
|
.type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
|
|
|
|
.target = V4L2_SEL_TGT_CROP,
|
|
|
|
};
|
|
|
|
double hscale, vscale;
|
|
|
|
|
|
|
|
ret = ioctl(fd, VIDIOC_G_SELECTION, &compose);
|
|
|
|
if (ret)
|
|
|
|
exit(-1);
|
|
|
|
ret = ioctl(fd, VIDIOC_G_SELECTION, &crop);
|
|
|
|
if (ret)
|
|
|
|
exit(-1);
|
|
|
|
|
|
|
|
/* computing scaling factors */
|
|
|
|
hscale = (double)compose.r.width / crop.r.width;
|
|
|
|
vscale = (double)compose.r.height / crop.r.height;
|