Home | History | Annotate | Download | only in spec
      1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
      2 <HTML
      3 ><HEAD
      4 ><TITLE
      5 >Image Formats</TITLE
      6 ><META
      7 NAME="GENERATOR"
      8 CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
      9 REL="HOME"
     10 TITLE="Video for Linux Two API Specification"
     11 HREF="book1.htm"><LINK
     12 REL="PREVIOUS"
     13 TITLE="Streaming Parameters"
     14 HREF="x2009.htm"><LINK
     15 REL="NEXT"
     16 TITLE="Colorspaces"
     17 HREF="x2123.htm"></HEAD
     18 ><BODY
     19 CLASS="CHAPTER"
     20 BGCOLOR="#FFFFFF"
     21 TEXT="#000000"
     22 LINK="#0000FF"
     23 VLINK="#840084"
     24 ALINK="#0000FF"
     25 ><DIV
     26 CLASS="NAVHEADER"
     27 ><TABLE
     28 SUMMARY="Header navigation table"
     29 WIDTH="100%"
     30 BORDER="0"
     31 CELLPADDING="0"
     32 CELLSPACING="0"
     33 ><TR
     34 ><TH
     35 COLSPAN="3"
     36 ALIGN="center"
     37 >Video for Linux Two API Specification: Revision 0.24</TH
     38 ></TR
     39 ><TR
     40 ><TD
     41 WIDTH="10%"
     42 ALIGN="left"
     43 VALIGN="bottom"
     44 ><A
     45 HREF="x2009.htm"
     46 ACCESSKEY="P"
     47 >Prev</A
     48 ></TD
     49 ><TD
     50 WIDTH="80%"
     51 ALIGN="center"
     52 VALIGN="bottom"
     53 ></TD
     54 ><TD
     55 WIDTH="10%"
     56 ALIGN="right"
     57 VALIGN="bottom"
     58 ><A
     59 HREF="x2123.htm"
     60 ACCESSKEY="N"
     61 >Next</A
     62 ></TD
     63 ></TR
     64 ></TABLE
     65 ><HR
     66 ALIGN="LEFT"
     67 WIDTH="100%"></DIV
     68 ><DIV
     69 CLASS="CHAPTER"
     70 ><H1
     71 ><A
     72 NAME="PIXFMT"
     73 ></A
     74 >Chapter 2. Image Formats</H1
     75 ><DIV
     76 CLASS="TOC"
     77 ><DL
     78 ><DT
     79 ><B
     80 >Table of Contents</B
     81 ></DT
     82 ><DT
     83 >2.1. <A
     84 HREF="c2030.htm#AEN2113"
     85 >Standard Image Formats</A
     86 ></DT
     87 ><DT
     88 >2.2. <A
     89 HREF="x2123.htm"
     90 >Colorspaces</A
     91 ></DT
     92 ><DT
     93 >2.3. <A
     94 HREF="x2428.htm"
     95 >Indexed Format</A
     96 ></DT
     97 ><DT
     98 >2.4. <A
     99 HREF="x2490.htm"
    100 >RGB Formats</A
    101 ></DT
    102 ><DT
    103 >2.5. <A
    104 HREF="x3891.htm"
    105 >YUV Formats</A
    106 ></DT
    107 ><DT
    108 >2.6. <A
    109 HREF="x5634.htm"
    110 >Compressed Formats</A
    111 ></DT
    112 ><DT
    113 >2.7. <A
    114 HREF="x5665.htm"
    115 >Reserved Format Identifiers</A
    116 ></DT
    117 ></DL
    118 ></DIV
    119 ><P
    120 >The V4L2 API was primarily designed for devices exchanging
    121 image data with applications. The
    122 <CODE
    123 CLASS="STRUCTNAME"
    124 >v4l2_pix_format</CODE
    125 > structure defines the format
    126 and layout of an image in memory. Image formats are negotiated with
    127 the <A
    128 HREF="r10944.htm"
    129 ><CODE
    130 CLASS="CONSTANT"
    131 >VIDIOC_S_FMT</CODE
    132 ></A
    133 > ioctl. (The explanations here focus on video
    134 capturing and output, for overlay frame buffer formats see also
    135 <A
    136 HREF="r10595.htm"
    137 ><CODE
    138 CLASS="CONSTANT"
    139 >VIDIOC_G_FBUF</CODE
    140 ></A
    141 >.)</P
    142 ><DIV
    143 CLASS="TABLE"
    144 ><A
    145 NAME="V4L2-PIX-FORMAT"
    146 ></A
    147 ><P
    148 ><B
    149 >Table 2-1. struct <CODE
    150 CLASS="STRUCTNAME"
    151 >v4l2_pix_format</CODE
    152 ></B
    153 ></P
    154 ><TABLE
    155 BORDER="0"
    156 FRAME="void"
    157 WIDTH="100%"
    158 CLASS="CALSTABLE"
    159 ><COL
    160 WIDTH="25%"
    161 TITLE="C1"><COL
    162 WIDTH="25%"
    163 TITLE="C2"><COL
    164 WIDTH="50%"
    165 TITLE="C3"><TBODY
    166 VALIGN="TOP"
    167 ><TR
    168 ><TD
    169 >__u32</TD
    170 ><TD
    171 ><CODE
    172 CLASS="STRUCTFIELD"
    173 >width</CODE
    174 ></TD
    175 ><TD
    176 >Image width in pixels.</TD
    177 ></TR
    178 ><TR
    179 ><TD
    180 >__u32</TD
    181 ><TD
    182 ><CODE
    183 CLASS="STRUCTFIELD"
    184 >height</CODE
    185 ></TD
    186 ><TD
    187 >Image height in pixels.</TD
    188 ></TR
    189 ><TR
    190 ><TD
    191 COLSPAN="3"
    192 >Applications set these fields to
    193 request an image size, drivers return the closest possible values. In
    194 case of planar formats the <CODE
    195 CLASS="STRUCTFIELD"
    196 >width</CODE
    197 > and
    198 <CODE
    199 CLASS="STRUCTFIELD"
    200 >height</CODE
    201 > applies to the largest plane. To
    202 avoid ambiguities drivers must return values rounded up to a multiple
    203 of the scale factor of any smaller planes. For example when the image
    204 format is YUV 4:2:0, <CODE
    205 CLASS="STRUCTFIELD"
    206 >width</CODE
    207 > and
    208 <CODE
    209 CLASS="STRUCTFIELD"
    210 >height</CODE
    211 > must be multiples of two.</TD
    212 ></TR
    213 ><TR
    214 ><TD
    215 >__u32</TD
    216 ><TD
    217 ><CODE
    218 CLASS="STRUCTFIELD"
    219 >pixelformat</CODE
    220 ></TD
    221 ><TD
    222 >The pixel format or type of compression, set by the
    223 application. This is a little endian <A
    224 HREF="r8367.htm#V4L2-FOURCC"
    225 >four character code</A
    226 >. V4L2 defines
    227 standard RGB formats in <A
    228 HREF="r2492.htm#RGB-FORMATS"
    229 >Table 2-1</A
    230 >, YUV formats in <A
    231 HREF="x3891.htm"
    232 >Section 2.5</A
    233 >, and reserved codes in <A
    234 HREF="x5665.htm#RESERVED-FORMATS"
    235 >Table 2-8</A
    236 ></TD
    237 ></TR
    238 ><TR
    239 ><TD
    240 >enum&nbsp;<A
    241 HREF="x6386.htm#V4L2-FIELD"
    242 >v4l2_field</A
    243 ></TD
    244 ><TD
    245 ><CODE
    246 CLASS="STRUCTFIELD"
    247 >field</CODE
    248 ></TD
    249 ><TD
    250 >Video images are typically interlaced. Applications
    251 can request to capture or output only the top or bottom field, or both
    252 fields interlaced or sequentially stored in one buffer or alternating
    253 in separate buffers. Drivers return the actual field order selected.
    254 For details see <A
    255 HREF="x6386.htm"
    256 >Section 3.6</A
    257 >.</TD
    258 ></TR
    259 ><TR
    260 ><TD
    261 >__u32</TD
    262 ><TD
    263 ><CODE
    264 CLASS="STRUCTFIELD"
    265 >bytesperline</CODE
    266 ></TD
    267 ><TD
    268 >Distance in bytes between the leftmost pixels in two
    269 adjacent lines.</TD
    270 ></TR
    271 ><TR
    272 ><TD
    273 COLSPAN="3"
    274 ><P
    275 >Both applications and drivers
    276 can set this field to request padding bytes at the end of each line.
    277 Drivers however may ignore the value requested by the application,
    278 returning <CODE
    279 CLASS="STRUCTFIELD"
    280 >width</CODE
    281 > times bytes per pixel or a
    282 larger value required by the hardware. That implies applications can
    283 just set this field to zero to get a reasonable
    284 default.</P
    285 ><P
    286 >Video hardware may access padding bytes,
    287 therefore they must reside in accessible memory. Consider cases where
    288 padding bytes after the last line of an image cross a system page
    289 boundary. Input devices may write padding bytes, the value is
    290 undefined. Output devices ignore the contents of padding
    291 bytes.</P
    292 ><P
    293 >When the image format is planar the
    294 <CODE
    295 CLASS="STRUCTFIELD"
    296 >bytesperline</CODE
    297 > value applies to the largest
    298 plane and is divided by the same factor as the
    299 <CODE
    300 CLASS="STRUCTFIELD"
    301 >width</CODE
    302 > field for any smaller planes. For
    303 example the Cb and Cr planes of a YUV 4:2:0 image have half as many
    304 padding bytes following each line as the Y plane. To avoid ambiguities
    305 drivers must return a <CODE
    306 CLASS="STRUCTFIELD"
    307 >bytesperline</CODE
    308 > value
    309 rounded up to a multiple of the scale factor.</P
    310 ></TD
    311 ></TR
    312 ><TR
    313 ><TD
    314 >__u32</TD
    315 ><TD
    316 ><CODE
    317 CLASS="STRUCTFIELD"
    318 >sizeimage</CODE
    319 ></TD
    320 ><TD
    321 >Size in bytes of the buffer to hold a complete image,
    322 set by the driver. Usually this is
    323 <CODE
    324 CLASS="STRUCTFIELD"
    325 >bytesperline</CODE
    326 > times
    327 <CODE
    328 CLASS="STRUCTFIELD"
    329 >height</CODE
    330 >. When the image consists of variable
    331 length compressed data this is the maximum number of bytes required to
    332 hold an image.</TD
    333 ></TR
    334 ><TR
    335 ><TD
    336 >enum&nbsp;<A
    337 HREF="x2123.htm#V4L2-COLORSPACE"
    338 >v4l2_colorspace</A
    339 ></TD
    340 ><TD
    341 ><CODE
    342 CLASS="STRUCTFIELD"
    343 >colorspace</CODE
    344 ></TD
    345 ><TD
    346 >This information supplements the
    347 <CODE
    348 CLASS="STRUCTFIELD"
    349 >pixelformat</CODE
    350 > and must be set by the driver,
    351 see <A
    352 HREF="x2123.htm"
    353 >Section 2.2</A
    354 >.</TD
    355 ></TR
    356 ><TR
    357 ><TD
    358 >__u32</TD
    359 ><TD
    360 ><CODE
    361 CLASS="STRUCTFIELD"
    362 >priv</CODE
    363 ></TD
    364 ><TD
    365 >Reserved for custom (driver defined) additional
    366 information about formats. When not used drivers and applications must
    367 set this field to zero.</TD
    368 ></TR
    369 ></TBODY
    370 ></TABLE
    371 ></DIV
    372 ><DIV
    373 CLASS="SECTION"
    374 ><H1
    375 CLASS="SECTION"
    376 ><A
    377 NAME="AEN2113"
    378 >2.1. Standard Image Formats</A
    379 ></H1
    380 ><P
    381 >In order to exchange images between drivers and
    382 applications, it is necessary to have standard image data formats
    383 which both sides will interpret the same way. V4L2 includes several
    384 such formats, and this section is intended to be an unambiguous
    385 specification of the standard image data formats in V4L2.</P
    386 ><P
    387 >V4L2 drivers are not limited to these formats, however.
    388 Driver-specific formats are possible. In that case the application may
    389 depend on a codec to convert images to one of the standard formats
    390 when needed. But the data can still be stored and retrieved in the
    391 proprietary format. For example, a device may support a proprietary
    392 compressed format. Applications can still capture and save the data in
    393 the compressed format, saving much disk space, and later use a codec
    394 to convert the images to the X Windows screen format when the video is
    395 to be displayed.</P
    396 ><P
    397 >Even so, ultimately, some standard formats are needed, so
    398 the V4L2 specification would not be complete without well-defined
    399 standard formats.</P
    400 ><P
    401 >The V4L2 standard formats are mainly uncompressed formats. The
    402 pixels are always arranged in memory from left to right, and from top
    403 to bottom. The first byte of data in the image buffer is always for
    404 the leftmost pixel of the topmost row. Following that is the pixel
    405 immediately to its right, and so on until the end of the top row of
    406 pixels. Following the rightmost pixel of the row there may be zero or
    407 more bytes of padding to guarantee that each row of pixel data has a
    408 certain alignment. Following the pad bytes, if any, is data for the
    409 leftmost pixel of the second row from the top, and so on. The last row
    410 has just as many pad bytes after it as the other rows.</P
    411 ><P
    412 >In V4L2 each format has an identifier which looks like
    413 <CODE
    414 CLASS="CONSTANT"
    415 >PIX_FMT_XXX</CODE
    416 >, defined in the <A
    417 HREF="a16506.htm"
    418 >videodev.h</A
    419 > header file. These identifiers
    420 represent <A
    421 HREF="r8367.htm#V4L2-FOURCC"
    422 >four character codes</A
    423 >
    424 which are also listed below, however they are not the same as those
    425 used in the Windows world.</P
    426 ></DIV
    427 ></DIV
    428 ><DIV
    429 CLASS="NAVFOOTER"
    430 ><HR
    431 ALIGN="LEFT"
    432 WIDTH="100%"><TABLE
    433 SUMMARY="Footer navigation table"
    434 WIDTH="100%"
    435 BORDER="0"
    436 CELLPADDING="0"
    437 CELLSPACING="0"
    438 ><TR
    439 ><TD
    440 WIDTH="33%"
    441 ALIGN="left"
    442 VALIGN="top"
    443 ><A
    444 HREF="x2009.htm"
    445 ACCESSKEY="P"
    446 >Prev</A
    447 ></TD
    448 ><TD
    449 WIDTH="34%"
    450 ALIGN="center"
    451 VALIGN="top"
    452 ><A
    453 HREF="book1.htm"
    454 ACCESSKEY="H"
    455 >Home</A
    456 ></TD
    457 ><TD
    458 WIDTH="33%"
    459 ALIGN="right"
    460 VALIGN="top"
    461 ><A
    462 HREF="x2123.htm"
    463 ACCESSKEY="N"
    464 >Next</A
    465 ></TD
    466 ></TR
    467 ><TR
    468 ><TD
    469 WIDTH="33%"
    470 ALIGN="left"
    471 VALIGN="top"
    472 >Streaming Parameters</TD
    473 ><TD
    474 WIDTH="34%"
    475 ALIGN="center"
    476 VALIGN="top"
    477 >&nbsp;</TD
    478 ><TD
    479 WIDTH="33%"
    480 ALIGN="right"
    481 VALIGN="top"
    482 >Colorspaces</TD
    483 ></TR
    484 ></TABLE
    485 ></DIV
    486 ></BODY
    487 ></HTML
    488 >
    489