162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci.. c:namespace:: V4L
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci.. _VIDIOC_CROPCAP:
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci********************
762306a36Sopenharmony_ciioctl VIDIOC_CROPCAP
862306a36Sopenharmony_ci********************
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciName
1162306a36Sopenharmony_ci====
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciVIDIOC_CROPCAP - Information about the video cropping and scaling abilities
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciSynopsis
1662306a36Sopenharmony_ci========
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_CROPCAP
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_CROPCAP, struct v4l2_cropcap *argp)``
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciArguments
2362306a36Sopenharmony_ci=========
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci``fd``
2662306a36Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci``argp``
2962306a36Sopenharmony_ci    Pointer to struct :c:type:`v4l2_cropcap`.
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciDescription
3262306a36Sopenharmony_ci===========
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ciApplications use this function to query the cropping limits, the pixel
3562306a36Sopenharmony_ciaspect of images and to calculate scale factors. They set the ``type``
3662306a36Sopenharmony_cifield of a v4l2_cropcap structure to the respective buffer (stream)
3762306a36Sopenharmony_citype and call the :ref:`VIDIOC_CROPCAP` ioctl with a pointer to this
3862306a36Sopenharmony_cistructure. Drivers fill the rest of the structure. The results are
3962306a36Sopenharmony_ciconstant except when switching the video standard. Remember this switch
4062306a36Sopenharmony_cican occur implicit when switching the video input or output.
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ciThis ioctl must be implemented for video capture or output devices that
4362306a36Sopenharmony_cisupport cropping and/or scaling and/or have non-square pixels, and for
4462306a36Sopenharmony_cioverlay devices.
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci.. c:type:: v4l2_cropcap
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci.. flat-table:: struct v4l2_cropcap
5162306a36Sopenharmony_ci    :header-rows:  0
5262306a36Sopenharmony_ci    :stub-columns: 0
5362306a36Sopenharmony_ci    :widths:       1 1 2
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci    * - __u32
5662306a36Sopenharmony_ci      - ``type``
5762306a36Sopenharmony_ci      - Type of the data stream, set by the application. Only these types
5862306a36Sopenharmony_ci	are valid here: ``V4L2_BUF_TYPE_VIDEO_CAPTURE``, ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``,
5962306a36Sopenharmony_ci	``V4L2_BUF_TYPE_VIDEO_OUTPUT``, ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`` and
6062306a36Sopenharmony_ci	``V4L2_BUF_TYPE_VIDEO_OVERLAY``. See :c:type:`v4l2_buf_type` and the note below.
6162306a36Sopenharmony_ci    * - struct :ref:`v4l2_rect <v4l2-rect-crop>`
6262306a36Sopenharmony_ci      - ``bounds``
6362306a36Sopenharmony_ci      - Defines the window within capturing or output is possible, this
6462306a36Sopenharmony_ci	may exclude for example the horizontal and vertical blanking
6562306a36Sopenharmony_ci	areas. The cropping rectangle cannot exceed these limits. Width
6662306a36Sopenharmony_ci	and height are defined in pixels, the driver writer is free to
6762306a36Sopenharmony_ci	choose origin and units of the coordinate system in the analog
6862306a36Sopenharmony_ci	domain.
6962306a36Sopenharmony_ci    * - struct :ref:`v4l2_rect <v4l2-rect-crop>`
7062306a36Sopenharmony_ci      - ``defrect``
7162306a36Sopenharmony_ci      - Default cropping rectangle, it shall cover the "whole picture".
7262306a36Sopenharmony_ci	Assuming pixel aspect 1/1 this could be for example a 640 × 480
7362306a36Sopenharmony_ci	rectangle for NTSC, a 768 × 576 rectangle for PAL and SECAM
7462306a36Sopenharmony_ci	centered over the active picture area. The same coordinate system
7562306a36Sopenharmony_ci	as for ``bounds`` is used.
7662306a36Sopenharmony_ci    * - struct :c:type:`v4l2_fract`
7762306a36Sopenharmony_ci      - ``pixelaspect``
7862306a36Sopenharmony_ci      - This is the pixel aspect (y / x) when no scaling is applied, the
7962306a36Sopenharmony_ci	ratio of the actual sampling frequency and the frequency required
8062306a36Sopenharmony_ci	to get square pixels.
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci	When cropping coordinates refer to square pixels, the driver sets
8362306a36Sopenharmony_ci	``pixelaspect`` to 1/1. Other common values are 54/59 for PAL and
8462306a36Sopenharmony_ci	SECAM, 11/10 for NTSC sampled according to [:ref:`itu601`].
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci.. note::
8762306a36Sopenharmony_ci   Unfortunately in the case of multiplanar buffer types
8862306a36Sopenharmony_ci   (``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``)
8962306a36Sopenharmony_ci   this API was messed up with regards to how the :c:type:`v4l2_cropcap` ``type`` field
9062306a36Sopenharmony_ci   should be filled in. Some drivers only accepted the ``_MPLANE`` buffer type while
9162306a36Sopenharmony_ci   other drivers only accepted a non-multiplanar buffer type (i.e. without the
9262306a36Sopenharmony_ci   ``_MPLANE`` at the end).
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci   Starting with kernel 4.13 both variations are allowed.
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci.. _v4l2-rect-crop:
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci.. flat-table:: struct v4l2_rect
10262306a36Sopenharmony_ci    :header-rows:  0
10362306a36Sopenharmony_ci    :stub-columns: 0
10462306a36Sopenharmony_ci    :widths:       1 1 2
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci    * - __s32
10762306a36Sopenharmony_ci      - ``left``
10862306a36Sopenharmony_ci      - Horizontal offset of the top, left corner of the rectangle, in
10962306a36Sopenharmony_ci	pixels.
11062306a36Sopenharmony_ci    * - __s32
11162306a36Sopenharmony_ci      - ``top``
11262306a36Sopenharmony_ci      - Vertical offset of the top, left corner of the rectangle, in
11362306a36Sopenharmony_ci	pixels.
11462306a36Sopenharmony_ci    * - __u32
11562306a36Sopenharmony_ci      - ``width``
11662306a36Sopenharmony_ci      - Width of the rectangle, in pixels.
11762306a36Sopenharmony_ci    * - __u32
11862306a36Sopenharmony_ci      - ``height``
11962306a36Sopenharmony_ci      - Height of the rectangle, in pixels.
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ciReturn Value
12262306a36Sopenharmony_ci============
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
12562306a36Sopenharmony_ciappropriately. The generic error codes are described at the
12662306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ciEINVAL
12962306a36Sopenharmony_ci    The struct :c:type:`v4l2_cropcap` ``type`` is
13062306a36Sopenharmony_ci    invalid.
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ciENODATA
13362306a36Sopenharmony_ci    Cropping is not supported for this input or output.
134