1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>ioctl VIDIOC_G_CROP, VIDIOC_S_CROP</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API"><link rel="up" href="user-func.html" title="Appendix A. Function Reference"><link rel="prev" href="vidioc-g-audioout.html" title="ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT"><link rel="next" href="vidioc-g-ctrl.html" title="ioctl VIDIOC_G_CTRL, VIDIOC_S_CTRL"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">ioctl VIDIOC_G_CROP, VIDIOC_S_CROP</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="vidioc-g-audioout.html">Prev</a> </td><th width="60%" align="center">Appendix A. Function Reference</th><td width="20%" align="right"> <a accesskey="n" href="vidioc-g-ctrl.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="vidioc-g-crop"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>VIDIOC_G_CROP, VIDIOC_S_CROP — Get or set the current cropping rectangle</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">ioctl</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">request</var>, </td></tr><tr><td> </td><td>struct v4l2_crop *<var class="pdparam">argp</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">ioctl</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">request</var>, </td></tr><tr><td> </td><td>const struct v4l2_crop *<var class="pdparam">argp</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idp1113758852"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>fd</code></em></span></dt><dd><p>File descriptor returned by <a class="link" href="func-open.html" title="V4L2 open()"><code class="function">open()</code></a>.</p></dd><dt><span class="term"><em class="parameter"><code>request</code></em></span></dt><dd><p>VIDIOC_G_CROP, VIDIOC_S_CROP</p></dd><dt><span class="term"><em class="parameter"><code>argp</code></em></span></dt><dd><p></p></dd></dl></div></div><div class="refsect1"><a name="idp1113762956"></a><h2>Description</h2><p>To query the cropping rectangle size and position 2applications set the <em class="structfield"><code>type</code></em> field of a 3<span class="structname">v4l2_crop</span> structure to the respective buffer 4(stream) type and call the <code class="constant">VIDIOC_G_CROP</code> ioctl 5with a pointer to this structure. The driver fills the rest of the 6structure or returns the <span class="errorcode">EINVAL</span> error code if cropping is not supported.</p><p>To change the cropping rectangle applications initialize the 7<em class="structfield"><code>type</code></em> and struct <a class="link" href="overlay.html#v4l2-rect" title="Table 4.3. struct v4l2_rect">v4l2_rect</a> substructure named 8<em class="structfield"><code>c</code></em> of a v4l2_crop structure and call the 9<code class="constant">VIDIOC_S_CROP</code> ioctl with a pointer to this 10structure.</p><p>Do not use the multiplanar buffer types. Use <code class="constant">V4L2_BUF_TYPE_VIDEO_CAPTURE</code> 11instead of <code class="constant">V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE</code> 12and use <code class="constant">V4L2_BUF_TYPE_VIDEO_OUTPUT</code> instead of 13<code class="constant">V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE</code>.</p><p>The driver first adjusts the requested dimensions against 14hardware limits, i. e. the bounds given by the capture/output window, 15and it rounds to the closest possible values of horizontal and 16vertical offset, width and height. In particular the driver must round 17the vertical offset of the cropping rectangle to frame lines modulo 18two, such that the field order cannot be confused.</p><p>Second the driver adjusts the image size (the opposite 19rectangle of the scaling process, source or target depending on the 20data direction) to the closest size possible while maintaining the 21current horizontal and vertical scaling factor.</p><p>Finally the driver programs the hardware with the actual 22cropping and image parameters. <code class="constant">VIDIOC_S_CROP</code> is a 23write-only ioctl, it does not return the actual parameters. To query 24them applications must call <code class="constant">VIDIOC_G_CROP</code> and 25<a class="link" href="vidioc-g-fmt.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT"><code class="constant">VIDIOC_G_FMT</code></a>. When the parameters are unsuitable the application may 26modify the cropping or image parameters and repeat the cycle until 27satisfactory parameters have been negotiated.</p><p>When cropping is not supported then no parameters are 28changed and <code class="constant">VIDIOC_S_CROP</code> returns the 29<span class="errorcode">EINVAL</span> error code.</p><div class="table"><a name="v4l2-crop"></a><p class="title"><b>Table A.55. struct <span class="structname">v4l2_crop</span></b></p><div class="table-contents"><table summary="struct v4l2_crop" width="100%" border="0"><colgroup><col class="c1"><col class="c2"><col class="c3"></colgroup><tbody valign="top"><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>type</code></em></td><td valign="top">Type of the data stream, set by the application. 30Only these types are valid here: <code class="constant">V4L2_BUF_TYPE_VIDEO_CAPTURE</code>, 31<code class="constant">V4L2_BUF_TYPE_VIDEO_OUTPUT</code> and 32<code class="constant">V4L2_BUF_TYPE_VIDEO_OVERLAY</code>. See <a class="xref" href="buffer.html#v4l2-buf-type" title="Table 3.3. enum v4l2_buf_type">Table 3.3, “enum v4l2_buf_type”</a>.</td></tr><tr><td valign="top">struct <a class="link" href="overlay.html#v4l2-rect" title="Table 4.3. struct v4l2_rect">v4l2_rect</a></td><td valign="top"><em class="structfield"><code>c</code></em></td><td valign="top">Cropping rectangle. The same co-ordinate system as 33for struct <a class="link" href="vidioc-cropcap.html#v4l2-cropcap" title="Table A.2. struct v4l2_cropcap">v4l2_cropcap</a> <em class="structfield"><code>bounds</code></em> is used.</td></tr></tbody></table></div></div><br class="table-break"></div><div class="refsect1"><a name="idp1113777772"></a><h2>Return Value</h2><p>On success <span class="returnvalue">0</span> is returned, on error <span class="returnvalue">-1</span> and the <code class="varname">errno</code> variable is set appropriately. The generic error codes are described at the <a class="link" href="gen_errors.html#gen-errors" title="Table 19.1. Generic error codes">Generic Error Codes</a> chapter.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="vidioc-g-audioout.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="user-func.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="vidioc-g-ctrl.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> ioctl VIDIOC_G_CTRL, VIDIOC_S_CTRL</td></tr></table></div></body></html> 34