162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci********
462306a36Sopenharmony_ciExamples
562306a36Sopenharmony_ci********
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci(A video capture device is assumed; change
862306a36Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other devices; change target to
962306a36Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE_*`` family to configure composing area)
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ciExample: Resetting the cropping parameters
1262306a36Sopenharmony_ci==========================================
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci.. code-block:: c
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci	struct v4l2_selection sel = {
1762306a36Sopenharmony_ci	    .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
1862306a36Sopenharmony_ci	    .target = V4L2_SEL_TGT_CROP_DEFAULT,
1962306a36Sopenharmony_ci	};
2062306a36Sopenharmony_ci	ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
2162306a36Sopenharmony_ci	if (ret)
2262306a36Sopenharmony_ci	    exit(-1);
2362306a36Sopenharmony_ci	sel.target = V4L2_SEL_TGT_CROP;
2462306a36Sopenharmony_ci	ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
2562306a36Sopenharmony_ci	if (ret)
2662306a36Sopenharmony_ci	    exit(-1);
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ciSetting a composing area on output of size of *at most* half of limit
2962306a36Sopenharmony_ciplaced at a center of a display.
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciExample: Simple downscaling
3262306a36Sopenharmony_ci===========================
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci.. code-block:: c
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci	struct v4l2_selection sel = {
3762306a36Sopenharmony_ci	    .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
3862306a36Sopenharmony_ci	    .target = V4L2_SEL_TGT_COMPOSE_BOUNDS,
3962306a36Sopenharmony_ci	};
4062306a36Sopenharmony_ci	struct v4l2_rect r;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
4362306a36Sopenharmony_ci	if (ret)
4462306a36Sopenharmony_ci	    exit(-1);
4562306a36Sopenharmony_ci	/* setting smaller compose rectangle */
4662306a36Sopenharmony_ci	r.width = sel.r.width / 2;
4762306a36Sopenharmony_ci	r.height = sel.r.height / 2;
4862306a36Sopenharmony_ci	r.left = sel.r.width / 4;
4962306a36Sopenharmony_ci	r.top = sel.r.height / 4;
5062306a36Sopenharmony_ci	sel.r = r;
5162306a36Sopenharmony_ci	sel.target = V4L2_SEL_TGT_COMPOSE;
5262306a36Sopenharmony_ci	sel.flags = V4L2_SEL_FLAG_LE;
5362306a36Sopenharmony_ci	ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
5462306a36Sopenharmony_ci	if (ret)
5562306a36Sopenharmony_ci	    exit(-1);
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ciA video output device is assumed; change ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
5862306a36Sopenharmony_cifor other devices
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciExample: Querying for scaling factors
6162306a36Sopenharmony_ci=====================================
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci.. code-block:: c
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci	struct v4l2_selection compose = {
6662306a36Sopenharmony_ci	    .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
6762306a36Sopenharmony_ci	    .target = V4L2_SEL_TGT_COMPOSE,
6862306a36Sopenharmony_ci	};
6962306a36Sopenharmony_ci	struct v4l2_selection crop = {
7062306a36Sopenharmony_ci	    .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
7162306a36Sopenharmony_ci	    .target = V4L2_SEL_TGT_CROP,
7262306a36Sopenharmony_ci	};
7362306a36Sopenharmony_ci	double hscale, vscale;
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci	ret = ioctl(fd, VIDIOC_G_SELECTION, &compose);
7662306a36Sopenharmony_ci	if (ret)
7762306a36Sopenharmony_ci	    exit(-1);
7862306a36Sopenharmony_ci	ret = ioctl(fd, VIDIOC_G_SELECTION, &crop);
7962306a36Sopenharmony_ci	if (ret)
8062306a36Sopenharmony_ci	    exit(-1);
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci	/* computing scaling factors */
8362306a36Sopenharmony_ci	hscale = (double)compose.r.width / crop.r.width;
8462306a36Sopenharmony_ci	vscale = (double)compose.r.height / crop.r.height;
85