18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci.. c:namespace:: V4L
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci.. _VIDIOC_G_CROP:
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci**********************************
78c2ecf20Sopenharmony_ciioctl VIDIOC_G_CROP, VIDIOC_S_CROP
88c2ecf20Sopenharmony_ci**********************************
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciName
118c2ecf20Sopenharmony_ci====
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciVIDIOC_G_CROP - VIDIOC_S_CROP - Get or set the current cropping rectangle
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciSynopsis
168c2ecf20Sopenharmony_ci========
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_G_CROP
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_G_CROP, struct v4l2_crop *argp)``
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_S_CROP
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_S_CROP, const struct v4l2_crop *argp)``
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciArguments
278c2ecf20Sopenharmony_ci=========
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci``fd``
308c2ecf20Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci``argp``
338c2ecf20Sopenharmony_ci    Pointer to struct :c:type:`v4l2_crop`.
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciDescription
368c2ecf20Sopenharmony_ci===========
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciTo query the cropping rectangle size and position applications set the
398c2ecf20Sopenharmony_ci``type`` field of a struct :c:type:`v4l2_crop` structure to the
408c2ecf20Sopenharmony_cirespective buffer (stream) type and call the :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` ioctl
418c2ecf20Sopenharmony_ciwith a pointer to this structure. The driver fills the rest of the
428c2ecf20Sopenharmony_cistructure or returns the ``EINVAL`` error code if cropping is not supported.
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciTo change the cropping rectangle applications initialize the ``type``
458c2ecf20Sopenharmony_ciand struct :c:type:`v4l2_rect` substructure named ``c`` of a
468c2ecf20Sopenharmony_civ4l2_crop structure and call the :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` ioctl with a pointer
478c2ecf20Sopenharmony_cito this structure.
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciThe driver first adjusts the requested dimensions against hardware
508c2ecf20Sopenharmony_cilimits, i. e. the bounds given by the capture/output window, and it
518c2ecf20Sopenharmony_cirounds to the closest possible values of horizontal and vertical offset,
528c2ecf20Sopenharmony_ciwidth and height. In particular the driver must round the vertical
538c2ecf20Sopenharmony_cioffset of the cropping rectangle to frame lines modulo two, such that
548c2ecf20Sopenharmony_cithe field order cannot be confused.
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciSecond the driver adjusts the image size (the opposite rectangle of the
578c2ecf20Sopenharmony_ciscaling process, source or target depending on the data direction) to
588c2ecf20Sopenharmony_cithe closest size possible while maintaining the current horizontal and
598c2ecf20Sopenharmony_civertical scaling factor.
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciFinally the driver programs the hardware with the actual cropping and
628c2ecf20Sopenharmony_ciimage parameters. :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` is a write-only ioctl, it does not
638c2ecf20Sopenharmony_cireturn the actual parameters. To query them applications must call
648c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and :ref:`VIDIOC_G_FMT`. When the
658c2ecf20Sopenharmony_ciparameters are unsuitable the application may modify the cropping or
668c2ecf20Sopenharmony_ciimage parameters and repeat the cycle until satisfactory parameters have
678c2ecf20Sopenharmony_cibeen negotiated.
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciWhen cropping is not supported then no parameters are changed and
708c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` returns the ``EINVAL`` error code.
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci.. c:type:: v4l2_crop
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci.. flat-table:: struct v4l2_crop
778c2ecf20Sopenharmony_ci    :header-rows:  0
788c2ecf20Sopenharmony_ci    :stub-columns: 0
798c2ecf20Sopenharmony_ci    :widths:       1 1 2
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci    * - __u32
828c2ecf20Sopenharmony_ci      - ``type``
838c2ecf20Sopenharmony_ci      - Type of the data stream, set by the application. Only these types
848c2ecf20Sopenharmony_ci	are valid here: ``V4L2_BUF_TYPE_VIDEO_CAPTURE``, ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``,
858c2ecf20Sopenharmony_ci	``V4L2_BUF_TYPE_VIDEO_OUTPUT``, ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`` and
868c2ecf20Sopenharmony_ci	``V4L2_BUF_TYPE_VIDEO_OVERLAY``. See :c:type:`v4l2_buf_type` and the note below.
878c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_rect`
888c2ecf20Sopenharmony_ci      - ``c``
898c2ecf20Sopenharmony_ci      - Cropping rectangle. The same co-ordinate system as for struct
908c2ecf20Sopenharmony_ci	:c:type:`v4l2_cropcap` ``bounds`` is used.
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci.. note::
938c2ecf20Sopenharmony_ci   Unfortunately in the case of multiplanar buffer types
948c2ecf20Sopenharmony_ci   (``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``)
958c2ecf20Sopenharmony_ci   this API was messed up with regards to how the :c:type:`v4l2_crop` ``type`` field
968c2ecf20Sopenharmony_ci   should be filled in. Some drivers only accepted the ``_MPLANE`` buffer type while
978c2ecf20Sopenharmony_ci   other drivers only accepted a non-multiplanar buffer type (i.e. without the
988c2ecf20Sopenharmony_ci   ``_MPLANE`` at the end).
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci   Starting with kernel 4.13 both variations are allowed.
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ciReturn Value
1038c2ecf20Sopenharmony_ci============
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
1068c2ecf20Sopenharmony_ciappropriately. The generic error codes are described at the
1078c2ecf20Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ciENODATA
1108c2ecf20Sopenharmony_ci    Cropping is not supported for this input or output.
111