18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci******** 48c2ecf20Sopenharmony_ciExamples 58c2ecf20Sopenharmony_ci******** 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci(A video capture device is assumed; change 88c2ecf20Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other devices; change target to 98c2ecf20Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE_*`` family to configure composing area) 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciExample: Resetting the cropping parameters 128c2ecf20Sopenharmony_ci========================================== 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci.. code-block:: c 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci struct v4l2_selection sel = { 178c2ecf20Sopenharmony_ci .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, 188c2ecf20Sopenharmony_ci .target = V4L2_SEL_TGT_CROP_DEFAULT, 198c2ecf20Sopenharmony_ci }; 208c2ecf20Sopenharmony_ci ret = ioctl(fd, VIDIOC_G_SELECTION, &sel); 218c2ecf20Sopenharmony_ci if (ret) 228c2ecf20Sopenharmony_ci exit(-1); 238c2ecf20Sopenharmony_ci sel.target = V4L2_SEL_TGT_CROP; 248c2ecf20Sopenharmony_ci ret = ioctl(fd, VIDIOC_S_SELECTION, &sel); 258c2ecf20Sopenharmony_ci if (ret) 268c2ecf20Sopenharmony_ci exit(-1); 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ciSetting a composing area on output of size of *at most* half of limit 298c2ecf20Sopenharmony_ciplaced at a center of a display. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciExample: Simple downscaling 328c2ecf20Sopenharmony_ci=========================== 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci.. code-block:: c 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci struct v4l2_selection sel = { 378c2ecf20Sopenharmony_ci .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, 388c2ecf20Sopenharmony_ci .target = V4L2_SEL_TGT_COMPOSE_BOUNDS, 398c2ecf20Sopenharmony_ci }; 408c2ecf20Sopenharmony_ci struct v4l2_rect r; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci ret = ioctl(fd, VIDIOC_G_SELECTION, &sel); 438c2ecf20Sopenharmony_ci if (ret) 448c2ecf20Sopenharmony_ci exit(-1); 458c2ecf20Sopenharmony_ci /* setting smaller compose rectangle */ 468c2ecf20Sopenharmony_ci r.width = sel.r.width / 2; 478c2ecf20Sopenharmony_ci r.height = sel.r.height / 2; 488c2ecf20Sopenharmony_ci r.left = sel.r.width / 4; 498c2ecf20Sopenharmony_ci r.top = sel.r.height / 4; 508c2ecf20Sopenharmony_ci sel.r = r; 518c2ecf20Sopenharmony_ci sel.target = V4L2_SEL_TGT_COMPOSE; 528c2ecf20Sopenharmony_ci sel.flags = V4L2_SEL_FLAG_LE; 538c2ecf20Sopenharmony_ci ret = ioctl(fd, VIDIOC_S_SELECTION, &sel); 548c2ecf20Sopenharmony_ci if (ret) 558c2ecf20Sopenharmony_ci exit(-1); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ciA video output device is assumed; change ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` 588c2ecf20Sopenharmony_cifor other devices 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciExample: Querying for scaling factors 618c2ecf20Sopenharmony_ci===================================== 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci.. code-block:: c 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci struct v4l2_selection compose = { 668c2ecf20Sopenharmony_ci .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, 678c2ecf20Sopenharmony_ci .target = V4L2_SEL_TGT_COMPOSE, 688c2ecf20Sopenharmony_ci }; 698c2ecf20Sopenharmony_ci struct v4l2_selection crop = { 708c2ecf20Sopenharmony_ci .type = V4L2_BUF_TYPE_VIDEO_OUTPUT, 718c2ecf20Sopenharmony_ci .target = V4L2_SEL_TGT_CROP, 728c2ecf20Sopenharmony_ci }; 738c2ecf20Sopenharmony_ci double hscale, vscale; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci ret = ioctl(fd, VIDIOC_G_SELECTION, &compose); 768c2ecf20Sopenharmony_ci if (ret) 778c2ecf20Sopenharmony_ci exit(-1); 788c2ecf20Sopenharmony_ci ret = ioctl(fd, VIDIOC_G_SELECTION, &crop); 798c2ecf20Sopenharmony_ci if (ret) 808c2ecf20Sopenharmony_ci exit(-1); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci /* computing scaling factors */ 838c2ecf20Sopenharmony_ci hscale = (double)compose.r.width / crop.r.width; 848c2ecf20Sopenharmony_ci vscale = (double)compose.r.height / crop.r.height; 85