1 .. -*- coding: utf-8; mode: rst -*-
5 **********************************
6 ioctl VIDIOC_G_CROP, VIDIOC_S_CROP
7 **********************************
12 VIDIOC_G_CROP - VIDIOC_S_CROP - Get or set the current cropping rectangle
18 .. c:function:: int ioctl( int fd, VIDIOC_G_CROP, struct v4l2_crop *argp )
21 .. c:function:: int ioctl( int fd, VIDIOC_S_CROP, const struct v4l2_crop *argp )
29 File descriptor returned by :ref:`open() <func-open>`.
37 To query the cropping rectangle size and position applications set the
38 ``type`` field of a struct :c:type:`v4l2_crop` structure to the
39 respective buffer (stream) type and call the :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` ioctl
40 with a pointer to this structure. The driver fills the rest of the
41 structure or returns the ``EINVAL`` error code if cropping is not supported.
43 To change the cropping rectangle applications initialize the ``type``
44 and struct :c:type:`v4l2_rect` substructure named ``c`` of a
45 v4l2_crop structure and call the :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` ioctl with a pointer
48 Do not use the multiplanar buffer types. Use
49 ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` instead of
50 ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and use
51 ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` instead of
52 ``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``.
54 The driver first adjusts the requested dimensions against hardware
55 limits, i. e. the bounds given by the capture/output window, and it
56 rounds to the closest possible values of horizontal and vertical offset,
57 width and height. In particular the driver must round the vertical
58 offset of the cropping rectangle to frame lines modulo two, such that
59 the field order cannot be confused.
61 Second the driver adjusts the image size (the opposite rectangle of the
62 scaling process, source or target depending on the data direction) to
63 the closest size possible while maintaining the current horizontal and
64 vertical scaling factor.
66 Finally the driver programs the hardware with the actual cropping and
67 image parameters. :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` is a write-only ioctl, it does not
68 return the actual parameters. To query them applications must call
69 :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and :ref:`VIDIOC_G_FMT`. When the
70 parameters are unsuitable the application may modify the cropping or
71 image parameters and repeat the cycle until satisfactory parameters have
74 When cropping is not supported then no parameters are changed and
75 :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` returns the ``EINVAL`` error code.
80 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
82 .. flat-table:: struct v4l2_crop
89 - Type of the data stream, set by the application. Only these types
90 are valid here: ``V4L2_BUF_TYPE_VIDEO_CAPTURE``,
91 ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` and
92 ``V4L2_BUF_TYPE_VIDEO_OVERLAY``. See :c:type:`v4l2_buf_type`.
93 * - struct :c:type:`v4l2_rect`
95 - Cropping rectangle. The same co-ordinate system as for struct
96 :c:type:`v4l2_cropcap` ``bounds`` is used.
102 On success 0 is returned, on error -1 and the ``errno`` variable is set
103 appropriately. The generic error codes are described at the
104 :ref:`Generic Error Codes <gen-errors>` chapter.
107 Cropping is not supported for this input or output.