Merge git://www.linux-watchdog.org/linux-watchdog
[deliverable/linux.git] / Documentation / media / uapi / v4l / vidioc-g-crop.rst
CommitLineData
5377d91f
MH
1.. -*- coding: utf-8; mode: rst -*-
2
af4a4d0d 3.. _VIDIOC_G_CROP:
5377d91f
MH
4
5**********************************
6ioctl VIDIOC_G_CROP, VIDIOC_S_CROP
7**********************************
8
15e7d615 9Name
586027ce 10====
5377d91f 11
586027ce 12VIDIOC_G_CROP - VIDIOC_S_CROP - Get or set the current cropping rectangle
5377d91f 13
15e7d615
MCC
14
15Synopsis
5377d91f
MH
16========
17
b7e67f6c 18.. cpp:function:: int ioctl( int fd, int request, struct v4l2_crop *argp )
5377d91f 19
b7e67f6c 20.. cpp:function:: int ioctl( int fd, int request, const struct v4l2_crop *argp )
5377d91f 21
586027ce 22
15e7d615 23Arguments
5377d91f
MH
24=========
25
26``fd``
27 File descriptor returned by :ref:`open() <func-open>`.
28
29``request``
30 VIDIOC_G_CROP, VIDIOC_S_CROP
31
32``argp``
33
34
15e7d615 35Description
5377d91f
MH
36===========
37
38To query the cropping rectangle size and position applications set the
acf309a2 39``type`` field of a :ref:`struct v4l2_crop <v4l2-crop>` structure to the
4e03cb76 40respective buffer (stream) type and call the :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` ioctl
5377d91f 41with a pointer to this structure. The driver fills the rest of the
cdb4af0f 42structure or returns the ``EINVAL`` error code if cropping is not supported.
5377d91f
MH
43
44To change the cropping rectangle applications initialize the ``type``
45and struct :ref:`v4l2_rect <v4l2-rect>` substructure named ``c`` of a
2212ff25 46v4l2_crop structure and call the :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` ioctl with a pointer
5377d91f
MH
47to this structure.
48
49Do not use the multiplanar buffer types. Use
50``V4L2_BUF_TYPE_VIDEO_CAPTURE`` instead of
51``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`` and use
52``V4L2_BUF_TYPE_VIDEO_OUTPUT`` instead of
53``V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE``.
54
55The driver first adjusts the requested dimensions against hardware
56limits, i. e. the bounds given by the capture/output window, and it
57rounds to the closest possible values of horizontal and vertical offset,
58width and height. In particular the driver must round the vertical
59offset of the cropping rectangle to frame lines modulo two, such that
60the field order cannot be confused.
61
62Second the driver adjusts the image size (the opposite rectangle of the
63scaling process, source or target depending on the data direction) to
64the closest size possible while maintaining the current horizontal and
65vertical scaling factor.
66
67Finally the driver programs the hardware with the actual cropping and
2212ff25 68image parameters. :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` is a write-only ioctl, it does not
5377d91f 69return the actual parameters. To query them applications must call
4e03cb76 70:ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and :ref:`VIDIOC_G_FMT`. When the
5377d91f
MH
71parameters are unsuitable the application may modify the cropping or
72image parameters and repeat the cycle until satisfactory parameters have
73been negotiated.
74
75When cropping is not supported then no parameters are changed and
cdb4af0f 76:ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` returns the ``EINVAL`` error code.
5377d91f
MH
77
78
79.. _v4l2-crop:
80
81.. flat-table:: struct v4l2_crop
82 :header-rows: 0
83 :stub-columns: 0
84 :widths: 1 1 2
85
86
87 - .. row 1
88
89 - __u32
90
91 - ``type``
92
93 - Type of the data stream, set by the application. Only these types
0579e6e3
MCC
94 are valid here: ``V4L2_BUF_TYPE_VIDEO_CAPTURE``,
95 ``V4L2_BUF_TYPE_VIDEO_OUTPUT`` and
96 ``V4L2_BUF_TYPE_VIDEO_OVERLAY``. See :ref:`v4l2-buf-type`.
5377d91f
MH
97
98 - .. row 2
99
100 - struct :ref:`v4l2_rect <v4l2-rect>`
101
102 - ``c``
103
104 - Cropping rectangle. The same co-ordinate system as for struct
0579e6e3 105 :ref:`v4l2_cropcap <v4l2-cropcap>` ``bounds`` is used.
5377d91f
MH
106
107
15e7d615 108Return Value
5377d91f
MH
109============
110
111On success 0 is returned, on error -1 and the ``errno`` variable is set
112appropriately. The generic error codes are described at the
113:ref:`Generic Error Codes <gen-errors>` chapter.
This page took 0.166202 seconds and 5 git commands to generate.