1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 254f38fcaSMauro Carvalho Chehab 354f38fcaSMauro Carvalho Chehab************* 454f38fcaSMauro Carvalho ChehabConfiguration 554f38fcaSMauro Carvalho Chehab************* 654f38fcaSMauro Carvalho Chehab 754f38fcaSMauro Carvalho ChehabApplications can use the :ref:`selection API <VIDIOC_G_SELECTION>` to 854f38fcaSMauro Carvalho Chehabselect an area in a video signal or a buffer, and to query for default 954f38fcaSMauro Carvalho Chehabsettings and hardware limits. 1054f38fcaSMauro Carvalho Chehab 1154f38fcaSMauro Carvalho ChehabVideo hardware can have various cropping, composing and scaling 1254f38fcaSMauro Carvalho Chehablimitations. It may only scale up or down, support only discrete scaling 1354f38fcaSMauro Carvalho Chehabfactors, or have different scaling abilities in the horizontal and 1454f38fcaSMauro Carvalho Chehabvertical directions. Also it may not support scaling at all. At the same 1554f38fcaSMauro Carvalho Chehabtime the cropping/composing rectangles may have to be aligned, and both 1654f38fcaSMauro Carvalho Chehabthe source and the sink may have arbitrary upper and lower size limits. 1754f38fcaSMauro Carvalho ChehabTherefore, as usual, drivers are expected to adjust the requested 1854f38fcaSMauro Carvalho Chehabparameters and return the actual values selected. An application can 1954f38fcaSMauro Carvalho Chehabcontrol the rounding behaviour using 2054f38fcaSMauro Carvalho Chehab:ref:`constraint flags <v4l2-selection-flags>`. 2154f38fcaSMauro Carvalho Chehab 2254f38fcaSMauro Carvalho Chehab 2354f38fcaSMauro Carvalho ChehabConfiguration of video capture 2454f38fcaSMauro Carvalho Chehab============================== 2554f38fcaSMauro Carvalho Chehab 2654f38fcaSMauro Carvalho ChehabSee figure :ref:`sel-targets-capture` for examples of the selection 2754f38fcaSMauro Carvalho Chehabtargets available for a video capture device. It is recommended to 2854f38fcaSMauro Carvalho Chehabconfigure the cropping targets before to the composing targets. 2954f38fcaSMauro Carvalho Chehab 3054f38fcaSMauro Carvalho ChehabThe range of coordinates of the top left corner, width and height of 3154f38fcaSMauro Carvalho Chehabareas that can be sampled is given by the ``V4L2_SEL_TGT_CROP_BOUNDS`` 3254f38fcaSMauro Carvalho Chehabtarget. It is recommended for the driver developers to put the top/left 3354f38fcaSMauro Carvalho Chehabcorner at position ``(0,0)``. The rectangle's coordinates are expressed 3454f38fcaSMauro Carvalho Chehabin pixels. 3554f38fcaSMauro Carvalho Chehab 3654f38fcaSMauro Carvalho ChehabThe top left corner, width and height of the source rectangle, that is 3754f38fcaSMauro Carvalho Chehabthe area actually sampled, is given by the ``V4L2_SEL_TGT_CROP`` target. 3854f38fcaSMauro Carvalho ChehabIt uses the same coordinate system as ``V4L2_SEL_TGT_CROP_BOUNDS``. The 3954f38fcaSMauro Carvalho Chehabactive cropping area must lie completely inside the capture boundaries. 4054f38fcaSMauro Carvalho ChehabThe driver may further adjust the requested size and/or position 4154f38fcaSMauro Carvalho Chehabaccording to hardware limitations. 4254f38fcaSMauro Carvalho Chehab 4354f38fcaSMauro Carvalho ChehabEach capture device has a default source rectangle, given by the 4454f38fcaSMauro Carvalho Chehab``V4L2_SEL_TGT_CROP_DEFAULT`` target. This rectangle shall cover what the 4554f38fcaSMauro Carvalho Chehabdriver writer considers the complete picture. Drivers shall set the 4654f38fcaSMauro Carvalho Chehabactive crop rectangle to the default when the driver is first loaded, 4754f38fcaSMauro Carvalho Chehabbut not later. 4854f38fcaSMauro Carvalho Chehab 4954f38fcaSMauro Carvalho ChehabThe composing targets refer to a memory buffer. The limits of composing 5054f38fcaSMauro Carvalho Chehabcoordinates are obtained using ``V4L2_SEL_TGT_COMPOSE_BOUNDS``. All 5154f38fcaSMauro Carvalho Chehabcoordinates are expressed in pixels. The rectangle's top/left corner 5254f38fcaSMauro Carvalho Chehabmust be located at position ``(0,0)``. The width and height are equal to 5354f38fcaSMauro Carvalho Chehabthe image size set by :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`. 5454f38fcaSMauro Carvalho Chehab 5554f38fcaSMauro Carvalho ChehabThe part of a buffer into which the image is inserted by the hardware is 5654f38fcaSMauro Carvalho Chehabcontrolled by the ``V4L2_SEL_TGT_COMPOSE`` target. The rectangle's 5754f38fcaSMauro Carvalho Chehabcoordinates are also expressed in the same coordinate system as the 5854f38fcaSMauro Carvalho Chehabbounds rectangle. The composing rectangle must lie completely inside 5954f38fcaSMauro Carvalho Chehabbounds rectangle. The driver must adjust the composing rectangle to fit 6054f38fcaSMauro Carvalho Chehabto the bounding limits. Moreover, the driver can perform other 6154f38fcaSMauro Carvalho Chehabadjustments according to hardware limitations. The application can 6254f38fcaSMauro Carvalho Chehabcontrol rounding behaviour using 6354f38fcaSMauro Carvalho Chehab:ref:`constraint flags <v4l2-selection-flags>`. 6454f38fcaSMauro Carvalho Chehab 6554f38fcaSMauro Carvalho ChehabFor capture devices the default composing rectangle is queried using 6654f38fcaSMauro Carvalho Chehab``V4L2_SEL_TGT_COMPOSE_DEFAULT``. It is usually equal to the bounding 6754f38fcaSMauro Carvalho Chehabrectangle. 6854f38fcaSMauro Carvalho Chehab 6954f38fcaSMauro Carvalho ChehabThe part of a buffer that is modified by the hardware is given by 7054f38fcaSMauro Carvalho Chehab``V4L2_SEL_TGT_COMPOSE_PADDED``. It contains all pixels defined using 7154f38fcaSMauro Carvalho Chehab``V4L2_SEL_TGT_COMPOSE`` plus all padding data modified by hardware 7254f38fcaSMauro Carvalho Chehabduring insertion process. All pixels outside this rectangle *must not* 7354f38fcaSMauro Carvalho Chehabbe changed by the hardware. The content of pixels that lie inside the 7454f38fcaSMauro Carvalho Chehabpadded area but outside active area is undefined. The application can 7554f38fcaSMauro Carvalho Chehabuse the padded and active rectangles to detect where the rubbish pixels 7654f38fcaSMauro Carvalho Chehabare located and remove them if needed. 7754f38fcaSMauro Carvalho Chehab 7854f38fcaSMauro Carvalho Chehab 7954f38fcaSMauro Carvalho ChehabConfiguration of video output 8054f38fcaSMauro Carvalho Chehab============================= 8154f38fcaSMauro Carvalho Chehab 8254f38fcaSMauro Carvalho ChehabFor output devices targets and ioctls are used similarly to the video 8354f38fcaSMauro Carvalho Chehabcapture case. The *composing* rectangle refers to the insertion of an 8454f38fcaSMauro Carvalho Chehabimage into a video signal. The cropping rectangles refer to a memory 8554f38fcaSMauro Carvalho Chehabbuffer. It is recommended to configure the composing targets before to 8654f38fcaSMauro Carvalho Chehabthe cropping targets. 8754f38fcaSMauro Carvalho Chehab 8854f38fcaSMauro Carvalho ChehabThe cropping targets refer to the memory buffer that contains an image 8954f38fcaSMauro Carvalho Chehabto be inserted into a video signal or graphical screen. The limits of 9054f38fcaSMauro Carvalho Chehabcropping coordinates are obtained using ``V4L2_SEL_TGT_CROP_BOUNDS``. 9154f38fcaSMauro Carvalho ChehabAll coordinates are expressed in pixels. The top/left corner is always 9254f38fcaSMauro Carvalho Chehabpoint ``(0,0)``. The width and height is equal to the image size 9354f38fcaSMauro Carvalho Chehabspecified using :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. 9454f38fcaSMauro Carvalho Chehab 9554f38fcaSMauro Carvalho ChehabThe top left corner, width and height of the source rectangle, that is 9654f38fcaSMauro Carvalho Chehabthe area from which image date are processed by the hardware, is given 97*4d06867eSRandy Dunlapby the ``V4L2_SEL_TGT_CROP``. Its coordinates are expressed in the 9854f38fcaSMauro Carvalho Chehabsame coordinate system as the bounds rectangle. The active cropping area 9954f38fcaSMauro Carvalho Chehabmust lie completely inside the crop boundaries and the driver may 10054f38fcaSMauro Carvalho Chehabfurther adjust the requested size and/or position according to hardware 10154f38fcaSMauro Carvalho Chehablimitations. 10254f38fcaSMauro Carvalho Chehab 10354f38fcaSMauro Carvalho ChehabFor output devices the default cropping rectangle is queried using 10454f38fcaSMauro Carvalho Chehab``V4L2_SEL_TGT_CROP_DEFAULT``. It is usually equal to the bounding 10554f38fcaSMauro Carvalho Chehabrectangle. 10654f38fcaSMauro Carvalho Chehab 10754f38fcaSMauro Carvalho ChehabThe part of a video signal or graphics display where the image is 10854f38fcaSMauro Carvalho Chehabinserted by the hardware is controlled by ``V4L2_SEL_TGT_COMPOSE`` 10954f38fcaSMauro Carvalho Chehabtarget. The rectangle's coordinates are expressed in pixels. The 11054f38fcaSMauro Carvalho Chehabcomposing rectangle must lie completely inside the bounds rectangle. The 11154f38fcaSMauro Carvalho Chehabdriver must adjust the area to fit to the bounding limits. Moreover, the 11254f38fcaSMauro Carvalho Chehabdriver can perform other adjustments according to hardware limitations. 11354f38fcaSMauro Carvalho Chehab 11454f38fcaSMauro Carvalho ChehabThe device has a default composing rectangle, given by the 11554f38fcaSMauro Carvalho Chehab``V4L2_SEL_TGT_COMPOSE_DEFAULT`` target. This rectangle shall cover what 11654f38fcaSMauro Carvalho Chehabthe driver writer considers the complete picture. It is recommended for 11754f38fcaSMauro Carvalho Chehabthe driver developers to put the top/left corner at position ``(0,0)``. 11854f38fcaSMauro Carvalho ChehabDrivers shall set the active composing rectangle to the default one when 11954f38fcaSMauro Carvalho Chehabthe driver is first loaded. 12054f38fcaSMauro Carvalho Chehab 12154f38fcaSMauro Carvalho ChehabThe devices may introduce additional content to video signal other than 12254f38fcaSMauro Carvalho Chehaban image from memory buffers. It includes borders around an image. 12354f38fcaSMauro Carvalho ChehabHowever, such a padded area is driver-dependent feature not covered by 12454f38fcaSMauro Carvalho Chehabthis document. Driver developers are encouraged to keep padded rectangle 12554f38fcaSMauro Carvalho Chehabequal to active one. The padded target is accessed by the 12654f38fcaSMauro Carvalho Chehab``V4L2_SEL_TGT_COMPOSE_PADDED`` identifier. It must contain all pixels 12754f38fcaSMauro Carvalho Chehabfrom the ``V4L2_SEL_TGT_COMPOSE`` target. 12854f38fcaSMauro Carvalho Chehab 12954f38fcaSMauro Carvalho Chehab 13054f38fcaSMauro Carvalho ChehabScaling control 13154f38fcaSMauro Carvalho Chehab=============== 13254f38fcaSMauro Carvalho Chehab 13354f38fcaSMauro Carvalho ChehabAn application can detect if scaling is performed by comparing the width 13454f38fcaSMauro Carvalho Chehaband the height of rectangles obtained using ``V4L2_SEL_TGT_CROP`` and 13554f38fcaSMauro Carvalho Chehab``V4L2_SEL_TGT_COMPOSE`` targets. If these are not equal then the 13654f38fcaSMauro Carvalho Chehabscaling is applied. The application can compute the scaling ratios using 13754f38fcaSMauro Carvalho Chehabthese values. 138