blob: b99032e59ebe7e0e904d05ac2fc428d55dc5d52f [file] [log] [blame]
Markus Heiser5377d912016-06-30 15:18:56 +02001.. -*- coding: utf-8; mode: rst -*-
2
Mauro Carvalho Chehabaf4a4d02016-07-01 13:42:29 -03003.. _VIDIOC_G_CROP:
Markus Heiser5377d912016-06-30 15:18:56 +02004
5**********************************
6ioctl VIDIOC_G_CROP, VIDIOC_S_CROP
7**********************************
8
Mauro Carvalho Chehab15e7d612016-07-05 15:14:35 -03009Name
Mauro Carvalho Chehab586027c2016-07-05 07:58:48 -030010====
Markus Heiser5377d912016-06-30 15:18:56 +020011
Mauro Carvalho Chehab586027c2016-07-05 07:58:48 -030012VIDIOC_G_CROP - VIDIOC_S_CROP - Get or set the current cropping rectangle
Markus Heiser5377d912016-06-30 15:18:56 +020013
Mauro Carvalho Chehab15e7d612016-07-05 15:14:35 -030014
15Synopsis
Markus Heiser5377d912016-06-30 15:18:56 +020016========
17
Mauro Carvalho Chehab41d80462016-08-19 16:53:38 -030018.. c:function:: int ioctl( int fd, VIDIOC_G_CROP, struct v4l2_crop *argp )
19 :name: VIDIOC_G_CROP
Markus Heiser5377d912016-06-30 15:18:56 +020020
Mauro Carvalho Chehab41d80462016-08-19 16:53:38 -030021.. c:function:: int ioctl( int fd, VIDIOC_S_CROP, const struct v4l2_crop *argp )
22 :name: VIDIOC_S_CROP
Markus Heiser5377d912016-06-30 15:18:56 +020023
Mauro Carvalho Chehab586027c2016-07-05 07:58:48 -030024
Mauro Carvalho Chehab15e7d612016-07-05 15:14:35 -030025Arguments
Markus Heiser5377d912016-06-30 15:18:56 +020026=========
27
28``fd``
29 File descriptor returned by :ref:`open() <func-open>`.
30
Markus Heiser5377d912016-06-30 15:18:56 +020031``argp``
32
33
Mauro Carvalho Chehab15e7d612016-07-05 15:14:35 -030034Description
Markus Heiser5377d912016-06-30 15:18:56 +020035===========
36
37To query the cropping rectangle size and position applications set the
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -030038``type`` field of a :c:type:`struct v4l2_crop <v4l2_crop>` structure to the
Mauro Carvalho Chehab4e03cb72016-07-03 10:02:29 -030039respective buffer (stream) type and call the :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` ioctl
Markus Heiser5377d912016-06-30 15:18:56 +020040with a pointer to this structure. The driver fills the rest of the
Mauro Carvalho Chehabcdb4af02016-07-03 11:53:09 -030041structure or returns the ``EINVAL`` error code if cropping is not supported.
Markus Heiser5377d912016-06-30 15:18:56 +020042
43To change the cropping rectangle applications initialize the ``type``
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -030044and struct :c:type:`v4l2_rect` substructure named ``c`` of a
Mauro Carvalho Chehab2212ff22016-07-01 14:33:56 -030045v4l2_crop structure and call the :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` ioctl with a pointer
Markus Heiser5377d912016-06-30 15:18:56 +020046to this structure.
47
48Do 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``.
53
54The driver first adjusts the requested dimensions against hardware
55limits, i. e. the bounds given by the capture/output window, and it
56rounds to the closest possible values of horizontal and vertical offset,
57width and height. In particular the driver must round the vertical
58offset of the cropping rectangle to frame lines modulo two, such that
59the field order cannot be confused.
60
61Second the driver adjusts the image size (the opposite rectangle of the
62scaling process, source or target depending on the data direction) to
63the closest size possible while maintaining the current horizontal and
64vertical scaling factor.
65
66Finally the driver programs the hardware with the actual cropping and
Mauro Carvalho Chehab2212ff22016-07-01 14:33:56 -030067image parameters. :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` is a write-only ioctl, it does not
Markus Heiser5377d912016-06-30 15:18:56 +020068return the actual parameters. To query them applications must call
Mauro Carvalho Chehab4e03cb72016-07-03 10:02:29 -030069:ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and :ref:`VIDIOC_G_FMT`. When the
Markus Heiser5377d912016-06-30 15:18:56 +020070parameters are unsuitable the application may modify the cropping or
71image parameters and repeat the cycle until satisfactory parameters have
72been negotiated.
73
74When cropping is not supported then no parameters are changed and
Mauro Carvalho Chehabcdb4af02016-07-03 11:53:09 -030075:ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` returns the ``EINVAL`` error code.
Markus Heiser5377d912016-06-30 15:18:56 +020076
77
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -030078.. c:type:: v4l2_crop
Markus Heiser5377d912016-06-30 15:18:56 +020079
Mauro Carvalho Chehab5bd4bb72016-08-17 08:14:19 -030080.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
81
Markus Heiser5377d912016-06-30 15:18:56 +020082.. flat-table:: struct v4l2_crop
83 :header-rows: 0
84 :stub-columns: 0
85 :widths: 1 1 2
86
87
88 - .. row 1
89
90 - __u32
91
92 - ``type``
93
94 - Type of the data stream, set by the application. Only these types
Mauro Carvalho Chehab0579e6e2016-07-04 16:25:48 -030095 are valid here: ``V4L2_BUF_TYPE_VIDEO_CAPTURE``,
96 ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` and
97 ``V4L2_BUF_TYPE_VIDEO_OVERLAY``. See :ref:`v4l2-buf-type`.
Markus Heiser5377d912016-06-30 15:18:56 +020098
99 - .. row 2
100
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -0300101 - struct :c:type:`v4l2_rect`
Markus Heiser5377d912016-06-30 15:18:56 +0200102
103 - ``c``
104
105 - Cropping rectangle. The same co-ordinate system as for struct
Mauro Carvalho Chehabe8be7e92016-08-29 17:37:59 -0300106 :c:type:`v4l2_cropcap` ``bounds`` is used.
Markus Heiser5377d912016-06-30 15:18:56 +0200107
108
Mauro Carvalho Chehab15e7d612016-07-05 15:14:35 -0300109Return Value
Markus Heiser5377d912016-06-30 15:18:56 +0200110============
111
112On success 0 is returned, on error -1 and the ``errno`` variable is set
113appropriately. The generic error codes are described at the
114:ref:`Generic Error Codes <gen-errors>` chapter.
Hans Verkuil3f8d56b2016-07-20 09:39:42 -0300115
116ENODATA
117 Cropping is not supported for this input or output.