162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci************* 462306a36Sopenharmony_ciConfiguration 562306a36Sopenharmony_ci************* 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciApplications can use the :ref:`selection API <VIDIOC_G_SELECTION>` to 862306a36Sopenharmony_ciselect an area in a video signal or a buffer, and to query for default 962306a36Sopenharmony_cisettings and hardware limits. 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciVideo hardware can have various cropping, composing and scaling 1262306a36Sopenharmony_cilimitations. It may only scale up or down, support only discrete scaling 1362306a36Sopenharmony_cifactors, or have different scaling abilities in the horizontal and 1462306a36Sopenharmony_civertical directions. Also it may not support scaling at all. At the same 1562306a36Sopenharmony_citime the cropping/composing rectangles may have to be aligned, and both 1662306a36Sopenharmony_cithe source and the sink may have arbitrary upper and lower size limits. 1762306a36Sopenharmony_ciTherefore, as usual, drivers are expected to adjust the requested 1862306a36Sopenharmony_ciparameters and return the actual values selected. An application can 1962306a36Sopenharmony_cicontrol the rounding behaviour using 2062306a36Sopenharmony_ci:ref:`constraint flags <v4l2-selection-flags>`. 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ciConfiguration of video capture 2462306a36Sopenharmony_ci============================== 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciSee figure :ref:`sel-targets-capture` for examples of the selection 2762306a36Sopenharmony_citargets available for a video capture device. It is recommended to 2862306a36Sopenharmony_ciconfigure the cropping targets before to the composing targets. 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ciThe range of coordinates of the top left corner, width and height of 3162306a36Sopenharmony_ciareas that can be sampled is given by the ``V4L2_SEL_TGT_CROP_BOUNDS`` 3262306a36Sopenharmony_citarget. It is recommended for the driver developers to put the top/left 3362306a36Sopenharmony_cicorner at position ``(0,0)``. The rectangle's coordinates are expressed 3462306a36Sopenharmony_ciin pixels. 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ciThe top left corner, width and height of the source rectangle, that is 3762306a36Sopenharmony_cithe area actually sampled, is given by the ``V4L2_SEL_TGT_CROP`` target. 3862306a36Sopenharmony_ciIt uses the same coordinate system as ``V4L2_SEL_TGT_CROP_BOUNDS``. The 3962306a36Sopenharmony_ciactive cropping area must lie completely inside the capture boundaries. 4062306a36Sopenharmony_ciThe driver may further adjust the requested size and/or position 4162306a36Sopenharmony_ciaccording to hardware limitations. 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ciEach capture device has a default source rectangle, given by the 4462306a36Sopenharmony_ci``V4L2_SEL_TGT_CROP_DEFAULT`` target. This rectangle shall cover what the 4562306a36Sopenharmony_cidriver writer considers the complete picture. Drivers shall set the 4662306a36Sopenharmony_ciactive crop rectangle to the default when the driver is first loaded, 4762306a36Sopenharmony_cibut not later. 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciThe composing targets refer to a memory buffer. The limits of composing 5062306a36Sopenharmony_cicoordinates are obtained using ``V4L2_SEL_TGT_COMPOSE_BOUNDS``. All 5162306a36Sopenharmony_cicoordinates are expressed in pixels. The rectangle's top/left corner 5262306a36Sopenharmony_cimust be located at position ``(0,0)``. The width and height are equal to 5362306a36Sopenharmony_cithe image size set by :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`. 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ciThe part of a buffer into which the image is inserted by the hardware is 5662306a36Sopenharmony_cicontrolled by the ``V4L2_SEL_TGT_COMPOSE`` target. The rectangle's 5762306a36Sopenharmony_cicoordinates are also expressed in the same coordinate system as the 5862306a36Sopenharmony_cibounds rectangle. The composing rectangle must lie completely inside 5962306a36Sopenharmony_cibounds rectangle. The driver must adjust the composing rectangle to fit 6062306a36Sopenharmony_cito the bounding limits. Moreover, the driver can perform other 6162306a36Sopenharmony_ciadjustments according to hardware limitations. The application can 6262306a36Sopenharmony_cicontrol rounding behaviour using 6362306a36Sopenharmony_ci:ref:`constraint flags <v4l2-selection-flags>`. 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ciFor capture devices the default composing rectangle is queried using 6662306a36Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE_DEFAULT``. It is usually equal to the bounding 6762306a36Sopenharmony_cirectangle. 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciThe part of a buffer that is modified by the hardware is given by 7062306a36Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE_PADDED``. It contains all pixels defined using 7162306a36Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE`` plus all padding data modified by hardware 7262306a36Sopenharmony_ciduring insertion process. All pixels outside this rectangle *must not* 7362306a36Sopenharmony_cibe changed by the hardware. The content of pixels that lie inside the 7462306a36Sopenharmony_cipadded area but outside active area is undefined. The application can 7562306a36Sopenharmony_ciuse the padded and active rectangles to detect where the rubbish pixels 7662306a36Sopenharmony_ciare located and remove them if needed. 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ciConfiguration of video output 8062306a36Sopenharmony_ci============================= 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ciFor output devices targets and ioctls are used similarly to the video 8362306a36Sopenharmony_cicapture case. The *composing* rectangle refers to the insertion of an 8462306a36Sopenharmony_ciimage into a video signal. The cropping rectangles refer to a memory 8562306a36Sopenharmony_cibuffer. It is recommended to configure the composing targets before to 8662306a36Sopenharmony_cithe cropping targets. 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ciThe cropping targets refer to the memory buffer that contains an image 8962306a36Sopenharmony_cito be inserted into a video signal or graphical screen. The limits of 9062306a36Sopenharmony_cicropping coordinates are obtained using ``V4L2_SEL_TGT_CROP_BOUNDS``. 9162306a36Sopenharmony_ciAll coordinates are expressed in pixels. The top/left corner is always 9262306a36Sopenharmony_cipoint ``(0,0)``. The width and height is equal to the image size 9362306a36Sopenharmony_cispecified using :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ciThe top left corner, width and height of the source rectangle, that is 9662306a36Sopenharmony_cithe area from which image date are processed by the hardware, is given 9762306a36Sopenharmony_ciby the ``V4L2_SEL_TGT_CROP``. Its coordinates are expressed in the 9862306a36Sopenharmony_cisame coordinate system as the bounds rectangle. The active cropping area 9962306a36Sopenharmony_cimust lie completely inside the crop boundaries and the driver may 10062306a36Sopenharmony_cifurther adjust the requested size and/or position according to hardware 10162306a36Sopenharmony_cilimitations. 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ciFor output devices the default cropping rectangle is queried using 10462306a36Sopenharmony_ci``V4L2_SEL_TGT_CROP_DEFAULT``. It is usually equal to the bounding 10562306a36Sopenharmony_cirectangle. 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ciThe part of a video signal or graphics display where the image is 10862306a36Sopenharmony_ciinserted by the hardware is controlled by ``V4L2_SEL_TGT_COMPOSE`` 10962306a36Sopenharmony_citarget. The rectangle's coordinates are expressed in pixels. The 11062306a36Sopenharmony_cicomposing rectangle must lie completely inside the bounds rectangle. The 11162306a36Sopenharmony_cidriver must adjust the area to fit to the bounding limits. Moreover, the 11262306a36Sopenharmony_cidriver can perform other adjustments according to hardware limitations. 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ciThe device has a default composing rectangle, given by the 11562306a36Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE_DEFAULT`` target. This rectangle shall cover what 11662306a36Sopenharmony_cithe driver writer considers the complete picture. It is recommended for 11762306a36Sopenharmony_cithe driver developers to put the top/left corner at position ``(0,0)``. 11862306a36Sopenharmony_ciDrivers shall set the active composing rectangle to the default one when 11962306a36Sopenharmony_cithe driver is first loaded. 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ciThe devices may introduce additional content to video signal other than 12262306a36Sopenharmony_cian image from memory buffers. It includes borders around an image. 12362306a36Sopenharmony_ciHowever, such a padded area is driver-dependent feature not covered by 12462306a36Sopenharmony_cithis document. Driver developers are encouraged to keep padded rectangle 12562306a36Sopenharmony_ciequal to active one. The padded target is accessed by the 12662306a36Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE_PADDED`` identifier. It must contain all pixels 12762306a36Sopenharmony_cifrom the ``V4L2_SEL_TGT_COMPOSE`` target. 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ciScaling control 13162306a36Sopenharmony_ci=============== 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ciAn application can detect if scaling is performed by comparing the width 13462306a36Sopenharmony_ciand the height of rectangles obtained using ``V4L2_SEL_TGT_CROP`` and 13562306a36Sopenharmony_ci``V4L2_SEL_TGT_COMPOSE`` targets. If these are not equal then the 13662306a36Sopenharmony_ciscaling is applied. The application can compute the scaling ratios using 13762306a36Sopenharmony_cithese values. 138