18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci************* 48c2ecf20Sopenharmony_ciConfiguration 58c2ecf20Sopenharmony_ci************* 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciApplications can use the :ref:`selection API <VIDIOC_G_SELECTION>` to 88c2ecf20Sopenharmony_ciselect an area in a video signal or a buffer, and to query for default 98c2ecf20Sopenharmony_cisettings and hardware limits. 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciVideo hardware can have various cropping, composing and scaling 128c2ecf20Sopenharmony_cilimitations. It may only scale up or down, support only discrete scaling 138c2ecf20Sopenharmony_cifactors, or have different scaling abilities in the horizontal and 148c2ecf20Sopenharmony_civertical directions. Also it may not support scaling at all. At the same 158c2ecf20Sopenharmony_citime the cropping/composing rectangles may have to be aligned, and both 168c2ecf20Sopenharmony_cithe source and the sink may have arbitrary upper and lower size limits. 178c2ecf20Sopenharmony_ciTherefore, as usual, drivers are expected to adjust the requested 188c2ecf20Sopenharmony_ciparameters and return the actual values selected. An application can 198c2ecf20Sopenharmony_cicontrol the rounding behaviour using 208c2ecf20Sopenharmony_ci:ref:`constraint flags <v4l2-selection-flags>`. 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciConfiguration of video capture 248c2ecf20Sopenharmony_ci============================== 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciSee figure :ref:`sel-targets-capture` for examples of the selection 278c2ecf20Sopenharmony_citargets available for a video capture device. It is recommended to 288c2ecf20Sopenharmony_ciconfigure the cropping targets before to the composing targets. 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ciThe range of coordinates of the top left corner, width and height of 318c2ecf20Sopenharmony_ciareas that can be sampled is given by the ``V4L2_SEL_TGT_CROP_BOUNDS`` 328c2ecf20Sopenharmony_citarget. It is recommended for the driver developers to put the top/left 338c2ecf20Sopenharmony_cicorner at position ``(0,0)``. The rectangle's coordinates are expressed 348c2ecf20Sopenharmony_ciin pixels. 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ciThe top left corner, width and height of the source rectangle, that is 378c2ecf20Sopenharmony_cithe area actually sampled, is given by the ``V4L2_SEL_TGT_CROP`` target. 388c2ecf20Sopenharmony_ciIt uses the same coordinate system as ``V4L2_SEL_TGT_CROP_BOUNDS``. The 398c2ecf20Sopenharmony_ciactive cropping area must lie completely inside the capture boundaries. 408c2ecf20Sopenharmony_ciThe driver may further adjust the requested size and/or position 418c2ecf20Sopenharmony_ciaccording to hardware limitations. 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciEach capture device has a default source rectangle, given by the 448c2ecf20Sopenharmony_ci``V4L2_SEL_TGT_CROP_DEFAULT`` target. This rectangle shall cover what the 458c2ecf20Sopenharmony_cidriver writer considers the complete picture. Drivers shall set the 468c2ecf20Sopenharmony_ciactive crop rectangle to the default when the driver is first loaded, 478c2ecf20Sopenharmony_cibut not later. 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ciThe composing targets refer to a memory buffer. The limits of composing 508c2ecf20Sopenharmony_cicoordinates are obtained using ``V4L2_SEL_TGT_COMPOSE_BOUNDS``. All 518c2ecf20Sopenharmony_cicoordinates are expressed in pixels. The rectangle's top/left corner 528c2ecf20Sopenharmony_cimust be located at position ``(0,0)``. The width and height are equal to 538c2ecf20Sopenharmony_cithe image size set by :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`. 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciThe part of a buffer into which the image is inserted by the hardware is 568c2ecf20Sopenharmony_cicontrolled by the ``V4L2_SEL_TGT_COMPOSE`` target. The rectangle's 578c2ecf20Sopenharmony_cicoordinates are also expressed in the same coordinate system as the 588c2ecf20Sopenharmony_cibounds rectangle. The composing rectangle must lie completely inside 598c2ecf20Sopenharmony_cibounds rectangle. The driver must adjust the composing rectangle to fit 608c2ecf20Sopenharmony_cito the bounding limits. Moreover, the driver can perform other 618c2ecf20Sopenharmony_ciadjustments according to hardware limitations. The application can 628c2ecf20Sopenharmony_cicontrol rounding behaviour using 638c2ecf20Sopenharmony_ci:ref:`constraint flags <v4l2-selection-flags>`. 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ciFor capture devices the default composing rectangle is queried using 668c2ecf20Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE_DEFAULT``. It is usually equal to the bounding 678c2ecf20Sopenharmony_cirectangle. 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciThe part of a buffer that is modified by the hardware is given by 708c2ecf20Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE_PADDED``. It contains all pixels defined using 718c2ecf20Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE`` plus all padding data modified by hardware 728c2ecf20Sopenharmony_ciduring insertion process. All pixels outside this rectangle *must not* 738c2ecf20Sopenharmony_cibe changed by the hardware. The content of pixels that lie inside the 748c2ecf20Sopenharmony_cipadded area but outside active area is undefined. The application can 758c2ecf20Sopenharmony_ciuse the padded and active rectangles to detect where the rubbish pixels 768c2ecf20Sopenharmony_ciare located and remove them if needed. 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ciConfiguration of video output 808c2ecf20Sopenharmony_ci============================= 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ciFor output devices targets and ioctls are used similarly to the video 838c2ecf20Sopenharmony_cicapture case. The *composing* rectangle refers to the insertion of an 848c2ecf20Sopenharmony_ciimage into a video signal. The cropping rectangles refer to a memory 858c2ecf20Sopenharmony_cibuffer. It is recommended to configure the composing targets before to 868c2ecf20Sopenharmony_cithe cropping targets. 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ciThe cropping targets refer to the memory buffer that contains an image 898c2ecf20Sopenharmony_cito be inserted into a video signal or graphical screen. The limits of 908c2ecf20Sopenharmony_cicropping coordinates are obtained using ``V4L2_SEL_TGT_CROP_BOUNDS``. 918c2ecf20Sopenharmony_ciAll coordinates are expressed in pixels. The top/left corner is always 928c2ecf20Sopenharmony_cipoint ``(0,0)``. The width and height is equal to the image size 938c2ecf20Sopenharmony_cispecified using :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ciThe top left corner, width and height of the source rectangle, that is 968c2ecf20Sopenharmony_cithe area from which image date are processed by the hardware, is given 978c2ecf20Sopenharmony_ciby the ``V4L2_SEL_TGT_CROP``. Its coordinates are expressed in in the 988c2ecf20Sopenharmony_cisame coordinate system as the bounds rectangle. The active cropping area 998c2ecf20Sopenharmony_cimust lie completely inside the crop boundaries and the driver may 1008c2ecf20Sopenharmony_cifurther adjust the requested size and/or position according to hardware 1018c2ecf20Sopenharmony_cilimitations. 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ciFor output devices the default cropping rectangle is queried using 1048c2ecf20Sopenharmony_ci``V4L2_SEL_TGT_CROP_DEFAULT``. It is usually equal to the bounding 1058c2ecf20Sopenharmony_cirectangle. 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ciThe part of a video signal or graphics display where the image is 1088c2ecf20Sopenharmony_ciinserted by the hardware is controlled by ``V4L2_SEL_TGT_COMPOSE`` 1098c2ecf20Sopenharmony_citarget. The rectangle's coordinates are expressed in pixels. The 1108c2ecf20Sopenharmony_cicomposing rectangle must lie completely inside the bounds rectangle. The 1118c2ecf20Sopenharmony_cidriver must adjust the area to fit to the bounding limits. Moreover, the 1128c2ecf20Sopenharmony_cidriver can perform other adjustments according to hardware limitations. 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ciThe device has a default composing rectangle, given by the 1158c2ecf20Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE_DEFAULT`` target. This rectangle shall cover what 1168c2ecf20Sopenharmony_cithe driver writer considers the complete picture. It is recommended for 1178c2ecf20Sopenharmony_cithe driver developers to put the top/left corner at position ``(0,0)``. 1188c2ecf20Sopenharmony_ciDrivers shall set the active composing rectangle to the default one when 1198c2ecf20Sopenharmony_cithe driver is first loaded. 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ciThe devices may introduce additional content to video signal other than 1228c2ecf20Sopenharmony_cian image from memory buffers. It includes borders around an image. 1238c2ecf20Sopenharmony_ciHowever, such a padded area is driver-dependent feature not covered by 1248c2ecf20Sopenharmony_cithis document. Driver developers are encouraged to keep padded rectangle 1258c2ecf20Sopenharmony_ciequal to active one. The padded target is accessed by the 1268c2ecf20Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE_PADDED`` identifier. It must contain all pixels 1278c2ecf20Sopenharmony_cifrom the ``V4L2_SEL_TGT_COMPOSE`` target. 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ciScaling control 1318c2ecf20Sopenharmony_ci=============== 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ciAn application can detect if scaling is performed by comparing the width 1348c2ecf20Sopenharmony_ciand the height of rectangles obtained using ``V4L2_SEL_TGT_CROP`` and 1358c2ecf20Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE`` targets. If these are not equal then the 1368c2ecf20Sopenharmony_ciscaling is applied. The application can compute the scaling ratios using 1378c2ecf20Sopenharmony_cithese values. 138