162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci.. c:namespace:: V4L 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci.. _VIDIOC_G_CROP: 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci********************************** 762306a36Sopenharmony_ciioctl VIDIOC_G_CROP, VIDIOC_S_CROP 862306a36Sopenharmony_ci********************************** 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciName 1162306a36Sopenharmony_ci==== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciVIDIOC_G_CROP - VIDIOC_S_CROP - Get or set the current cropping rectangle 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciSynopsis 1662306a36Sopenharmony_ci======== 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_G_CROP 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_G_CROP, struct v4l2_crop *argp)`` 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci.. c:macro:: VIDIOC_S_CROP 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_S_CROP, const struct v4l2_crop *argp)`` 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciArguments 2762306a36Sopenharmony_ci========= 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci``fd`` 3062306a36Sopenharmony_ci File descriptor returned by :c:func:`open()`. 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci``argp`` 3362306a36Sopenharmony_ci Pointer to struct :c:type:`v4l2_crop`. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciDescription 3662306a36Sopenharmony_ci=========== 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciTo query the cropping rectangle size and position applications set the 3962306a36Sopenharmony_ci``type`` field of a struct :c:type:`v4l2_crop` structure to the 4062306a36Sopenharmony_cirespective buffer (stream) type and call the :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` ioctl 4162306a36Sopenharmony_ciwith a pointer to this structure. The driver fills the rest of the 4262306a36Sopenharmony_cistructure or returns the ``EINVAL`` error code if cropping is not supported. 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ciTo change the cropping rectangle applications initialize the ``type`` 4562306a36Sopenharmony_ciand struct :c:type:`v4l2_rect` substructure named ``c`` of a 4662306a36Sopenharmony_civ4l2_crop structure and call the :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` ioctl with a pointer 4762306a36Sopenharmony_cito this structure. 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciThe driver first adjusts the requested dimensions against hardware 5062306a36Sopenharmony_cilimits, i. e. the bounds given by the capture/output window, and it 5162306a36Sopenharmony_cirounds to the closest possible values of horizontal and vertical offset, 5262306a36Sopenharmony_ciwidth and height. In particular the driver must round the vertical 5362306a36Sopenharmony_cioffset of the cropping rectangle to frame lines modulo two, such that 5462306a36Sopenharmony_cithe field order cannot be confused. 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciSecond the driver adjusts the image size (the opposite rectangle of the 5762306a36Sopenharmony_ciscaling process, source or target depending on the data direction) to 5862306a36Sopenharmony_cithe closest size possible while maintaining the current horizontal and 5962306a36Sopenharmony_civertical scaling factor. 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciFinally the driver programs the hardware with the actual cropping and 6262306a36Sopenharmony_ciimage parameters. :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` is a write-only ioctl, it does not 6362306a36Sopenharmony_cireturn the actual parameters. To query them applications must call 6462306a36Sopenharmony_ci:ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and :ref:`VIDIOC_G_FMT`. When the 6562306a36Sopenharmony_ciparameters are unsuitable the application may modify the cropping or 6662306a36Sopenharmony_ciimage parameters and repeat the cycle until satisfactory parameters have 6762306a36Sopenharmony_cibeen negotiated. 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciWhen cropping is not supported then no parameters are changed and 7062306a36Sopenharmony_ci:ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` returns the ``EINVAL`` error code. 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci.. c:type:: v4l2_crop 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci.. flat-table:: struct v4l2_crop 7762306a36Sopenharmony_ci :header-rows: 0 7862306a36Sopenharmony_ci :stub-columns: 0 7962306a36Sopenharmony_ci :widths: 1 1 2 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci * - __u32 8262306a36Sopenharmony_ci - ``type`` 8362306a36Sopenharmony_ci - Type of the data stream, set by the application. Only these types 8462306a36Sopenharmony_ci are valid here: ``V4L2_BUF_TYPE_VIDEO_CAPTURE``, ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``, 8562306a36Sopenharmony_ci ``V4L2_BUF_TYPE_VIDEO_OUTPUT``, ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`` and 8662306a36Sopenharmony_ci ``V4L2_BUF_TYPE_VIDEO_OVERLAY``. See :c:type:`v4l2_buf_type` and the note below. 8762306a36Sopenharmony_ci * - struct :c:type:`v4l2_rect` 8862306a36Sopenharmony_ci - ``c`` 8962306a36Sopenharmony_ci - Cropping rectangle. The same co-ordinate system as for struct 9062306a36Sopenharmony_ci :c:type:`v4l2_cropcap` ``bounds`` is used. 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci.. note:: 9362306a36Sopenharmony_ci Unfortunately in the case of multiplanar buffer types 9462306a36Sopenharmony_ci (``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``) 9562306a36Sopenharmony_ci this API was messed up with regards to how the :c:type:`v4l2_crop` ``type`` field 9662306a36Sopenharmony_ci should be filled in. Some drivers only accepted the ``_MPLANE`` buffer type while 9762306a36Sopenharmony_ci other drivers only accepted a non-multiplanar buffer type (i.e. without the 9862306a36Sopenharmony_ci ``_MPLANE`` at the end). 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci Starting with kernel 4.13 both variations are allowed. 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ciReturn Value 10362306a36Sopenharmony_ci============ 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set 10662306a36Sopenharmony_ciappropriately. The generic error codes are described at the 10762306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter. 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ciENODATA 11062306a36Sopenharmony_ci Cropping is not supported for this input or output. 111