<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>Chapter 2. Image Formats</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API" /><link rel="up" href="pt01.html" title="Part I. Video for Linux Two API Specification" /><link rel="prev" href="ch01s12.html" title="Streaming Parameters" /><link rel="next" href="ch02s02.html" title="Colorspaces" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 2. Image Formats</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch01s12.html">Prev</a> </td><th width="60%" align="center">Part I. Video for Linux Two API Specification</th><td width="20%" align="right"> <a accesskey="n" href="ch02s02.html">Next</a></td></tr></table><hr /></div><div class="chapter" title="Chapter 2. Image Formats"><div class="titlepage"><div><div><h2 class="title"><a id="pixfmt"></a>Chapter 2. Image Formats</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="ch02.html#id2601583">Standard Image Formats</a></span></dt><dt><span class="section"><a href="ch02s02.html">Colorspaces</a></span></dt><dt><span class="section"><a href="ch02s03.html">Indexed Format</a></span></dt><dt><span class="section"><a href="ch02s04.html">RGB Formats</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="re01.html">Packed RGB formats</a></span><span class="refpurpose"> — Packed RGB formats</span></dt><dt><span class="refentrytitle"><a href="re02.html">V4L2_PIX_FMT_SBGGR8 ('BA81')</a></span><span class="refpurpose"> — Bayer RGB format</span></dt><dt><span class="refentrytitle"><a href="re03.html">V4L2_PIX_FMT_SGBRG8 ('GBRG')</a></span><span class="refpurpose"> — Bayer RGB format</span></dt><dt><span class="refentrytitle"><a href="re04.html">V4L2_PIX_FMT_SGRBG8 ('GRBG')</a></span><span class="refpurpose"> — Bayer RGB format</span></dt><dt><span class="refentrytitle"><a href="re05.html">V4L2_PIX_FMT_SBGGR16 ('BYR2')</a></span><span class="refpurpose"> — Bayer RGB format</span></dt></dl></dd><dt><span class="section"><a href="ch02s05.html">YUV Formats</a></span></dt><dd><dl><dt><span class="refentrytitle"><a href="re06.html">Packed YUV formats</a></span><span class="refpurpose"> — Packed YUV formats</span></dt><dt><span class="refentrytitle"><a href="re07.html">V4L2_PIX_FMT_GREY ('GREY')</a></span><span class="refpurpose"> — Grey-scale image</span></dt><dt><span class="refentrytitle"><a href="re08.html">V4L2_PIX_FMT_Y16 ('Y16 ')</a></span><span class="refpurpose"> — Grey-scale image</span></dt><dt><span class="refentrytitle"><a href="re09.html">V4L2_PIX_FMT_YUYV ('YUYV')</a></span><span class="refpurpose"> — Packed format with ½ horizontal chroma resolution, also known as YUV 4:2:2</span></dt><dt><span class="refentrytitle"><a href="re10.html">V4L2_PIX_FMT_UYVY ('UYVY')</a></span><span class="refpurpose"> — Variation of <code class="constant">V4L2_PIX_FMT_YUYV</code> with different order of samples in memory</span></dt><dt><span class="refentrytitle"><a href="re11.html">V4L2_PIX_FMT_YVYU ('YVYU')</a></span><span class="refpurpose"> — Variation of <code class="constant">V4L2_PIX_FMT_YUYV</code> with different order of samples in memory</span></dt><dt><span class="refentrytitle"><a href="re12.html">V4L2_PIX_FMT_VYUY ('VYUY')</a></span><span class="refpurpose"> — Variation of <code class="constant">V4L2_PIX_FMT_YUYV</code> with different order of samples in memory</span></dt><dt><span class="refentrytitle"><a href="re13.html">V4L2_PIX_FMT_Y41P ('Y41P')</a></span><span class="refpurpose"> — Format with ¼ horizontal chroma resolution, also known as YUV 4:1:1</span></dt><dt><span class="refentrytitle"><a href="re14.html">V4L2_PIX_FMT_YVU420 ('YV12'), V4L2_PIX_FMT_YUV420 ('YU12')</a></span><span class="refpurpose"> — Planar formats with ½ horizontal and vertical chroma resolution, also known as YUV 4:2:0</span></dt><dt><span class="refentrytitle"><a href="re15.html">V4L2_PIX_FMT_YVU410 ('YVU9'), V4L2_PIX_FMT_YUV410 ('YUV9')</a></span><span class="refpurpose"> — Planar formats with ¼ horizontal and vertical chroma resolution, also known as YUV 4:1:0</span></dt><dt><span class="refentrytitle"><a href="re16.html">V4L2_PIX_FMT_YUV422P ('422P')</a></span><span class="refpurpose"> — Format with ½ horizontal chroma resolution, also known as YUV 4:2:2. Planar layout as opposed to <code class="constant">V4L2_PIX_FMT_YUYV</code></span></dt><dt><span class="refentrytitle"><a href="re17.html">V4L2_PIX_FMT_YUV411P ('411P')</a></span><span class="refpurpose"> — Format with ¼ horizontal chroma resolution, also known as YUV 4:1:1. Planar layout as opposed to <code class="constant">V4L2_PIX_FMT_Y41P</code></span></dt><dt><span class="refentrytitle"><a href="re18.html">V4L2_PIX_FMT_NV12 ('NV12'), V4L2_PIX_FMT_NV21 ('NV21')</a></span><span class="refpurpose"> — Formats with ½ horizontal and vertical chroma resolution, also known as YUV 4:2:0. One luminance and one chrominance plane with alternating chroma samples as opposed to <code class="constant">V4L2_PIX_FMT_YVU420</code></span></dt><dt><span class="refentrytitle"><a href="re19.html">V4L2_PIX_FMT_NV16 ('NV16'), V4L2_PIX_FMT_NV61 ('NV61')</a></span><span class="refpurpose"> — Formats with ½ horizontal chroma resolution, also known as YUV 4:2:2. One luminance and one chrominance plane with alternating chroma samples as opposed to <code class="constant">V4L2_PIX_FMT_YVU420</code></span></dt></dl></dd><dt><span class="section"><a href="ch02s06.html">Compressed Formats</a></span></dt><dt><span class="section"><a href="ch02s07.html">Reserved Format Identifiers</a></span></dt></dl></div><p>The V4L2 API was primarily designed for devices exchanging image data with applications. The <span class="structname">v4l2_pix_format</span> structure defines the format and layout of an image in memory. Image formats are negotiated with the <a class="link" href="re41.html" title="ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT"><code class="constant">VIDIOC_S_FMT</code></a> ioctl. (The explanations here focus on video capturing and output, for overlay frame buffer formats see also <a class="link" href="re40.html" title="ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF"><code class="constant">VIDIOC_G_FBUF</code></a>.)</p><div class="table"><a id="v4l2-pix-format"></a><p class="title"><b>Table 2.1. struct <span class="structname">v4l2_pix_format</span></b></p><div class="table-contents"><table summary="struct v4l2_pix_format" width="100%" border="0"><colgroup><col /><col /><col /></colgroup><tbody valign="top"><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>width</code></em></td><td valign="top">Image width in pixels.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>height</code></em></td><td valign="top">Image height in pixels.</td></tr><tr><td colspan="3" valign="top">Applications set these fields to request an image size, drivers return the closest possible values. In case of planar formats the <em class="structfield"><code>width</code></em> and <em class="structfield"><code>height</code></em> applies to the largest plane. To avoid ambiguities drivers must return values rounded up to a multiple of the scale factor of any smaller planes. For example when the image format is YUV 4:2:0, <em class="structfield"><code>width</code></em> and <em class="structfield"><code>height</code></em> must be multiples of two.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>pixelformat</code></em></td><td valign="top">The pixel format or type of compression, set by the application. This is a little endian <a class="link" href="re28.html#v4l2-fourcc">four character code</a>. V4L2 defines standard RGB formats in <a class="xref" href="re01.html#rgb-formats" title="Table 2.4. Packed RGB Image Formats">Table 2.4, “Packed RGB Image Formats”</a>, YUV formats in <a class="xref" href="ch02s05.html" title="YUV Formats">the section called “YUV Formats”</a>, and reserved codes in <a class="xref" href="ch02s07.html#reserved-formats" title="Table 2.8. Reserved Image Formats">Table 2.8, “Reserved Image Formats”</a></td></tr><tr><td valign="top">enum <a class="link" href="ch03s06.html#v4l2-field" title="Table 3.8. enum v4l2_field">v4l2_field</a></td><td valign="top"><em class="structfield"><code>field</code></em></td><td valign="top">Video images are typically interlaced. Applications can request to capture or output only the top or bottom field, or both fields interlaced or sequentially stored in one buffer or alternating in separate buffers. Drivers return the actual field order selected. For details see <a class="xref" href="ch03s06.html" title="Field Order">the section called “Field Order”</a>.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>bytesperline</code></em></td><td valign="top">Distance in bytes between the leftmost pixels in two adjacent lines.</td></tr><tr><td colspan="3" valign="top"><p>Both applications and drivers can set this field to request padding bytes at the end of each line. Drivers however may ignore the value requested by the application, returning <em class="structfield"><code>width</code></em> times bytes per pixel or a larger value required by the hardware. That implies applications can just set this field to zero to get a reasonable default.</p><p>Video hardware may access padding bytes, therefore they must reside in accessible memory. Consider cases where padding bytes after the last line of an image cross a system page boundary. Input devices may write padding bytes, the value is undefined. Output devices ignore the contents of padding bytes.</p><p>When the image format is planar the <em class="structfield"><code>bytesperline</code></em> value applies to the largest plane and is divided by the same factor as the <em class="structfield"><code>width</code></em> field for any smaller planes. For example the Cb and Cr planes of a YUV 4:2:0 image have half as many padding bytes following each line as the Y plane. To avoid ambiguities drivers must return a <em class="structfield"><code>bytesperline</code></em> value rounded up to a multiple of the scale factor.</p></td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>sizeimage</code></em></td><td valign="top">Size in bytes of the buffer to hold a complete image, set by the driver. Usually this is <em class="structfield"><code>bytesperline</code></em> times <em class="structfield"><code>height</code></em>. When the image consists of variable length compressed data this is the maximum number of bytes required to hold an image.</td></tr><tr><td valign="top">enum <a class="link" href="ch02s02.html#v4l2-colorspace" title="Table 2.2. enum v4l2_colorspace">v4l2_colorspace</a></td><td valign="top"><em class="structfield"><code>colorspace</code></em></td><td valign="top">This information supplements the <em class="structfield"><code>pixelformat</code></em> and must be set by the driver, see <a class="xref" href="ch02s02.html" title="Colorspaces">the section called “Colorspaces”</a>.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>priv</code></em></td><td valign="top">Reserved for custom (driver defined) additional information about formats. When not used drivers and applications must set this field to zero.</td></tr></tbody></table></div></div><br class="table-break" /><div class="section" title="Standard Image Formats"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2601583"></a>Standard Image Formats</h2></div></div></div><p>In order to exchange images between drivers and applications, it is necessary to have standard image data formats which both sides will interpret the same way. V4L2 includes several such formats, and this section is intended to be an unambiguous specification of the standard image data formats in V4L2.</p><p>V4L2 drivers are not limited to these formats, however. Driver-specific formats are possible. In that case the application may depend on a codec to convert images to one of the standard formats when needed. But the data can still be stored and retrieved in the proprietary format. For example, a device may support a proprietary compressed format. Applications can still capture and save the data in the compressed format, saving much disk space, and later use a codec to convert the images to the X Windows screen format when the video is to be displayed.</p><p>Even so, ultimately, some standard formats are needed, so the V4L2 specification would not be complete without well-defined standard formats.</p><p>The V4L2 standard formats are mainly uncompressed formats. The pixels are always arranged in memory from left to right, and from top to bottom. The first byte of data in the image buffer is always for the leftmost pixel of the topmost row. Following that is the pixel immediately to its right, and so on until the end of the top row of pixels. Following the rightmost pixel of the row there may be zero or more bytes of padding to guarantee that each row of pixel data has a certain alignment. Following the pad bytes, if any, is data for the leftmost pixel of the second row from the top, and so on. The last row has just as many pad bytes after it as the other rows.</p><p>In V4L2 each format has an identifier which looks like <code class="constant">PIX_FMT_XXX</code>, defined in the <a class="link" href="apb.html" title="Appendix B. Video For Linux Two Header File">videodev.h</a> header file. These identifiers represent <a class="link" href="re28.html#v4l2-fourcc">four character codes</a> which are also listed below, however they are not the same as those used in the Windows world.</p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch01s12.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="pt01.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Streaming Parameters </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Colorspaces</td></tr></table></div></body></html>