• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 // Note: ported from Chromium commit head: 3b7ce92816e2
5 // Note: only necessary functions are ported from video_types.h
6 
7 #ifndef VIDEO_PIXEL_FORMAT_H_
8 #define VIDEO_PIXEL_FORMAT_H_
9 
10 #include <string>
11 
12 namespace media {
13 
14 // Pixel formats roughly based on FOURCC labels, see:
15 // http://www.fourcc.org/rgb.php and http://www.fourcc.org/yuv.php
16 // Logged to UMA, so never reuse values. Leave gaps if necessary.
17 // Ordered as planar, semi-planar, YUV-packed, and RGB formats.
18 // When a VideoFrame is backed by native textures, VideoPixelFormat describes
19 // how those textures should be sampled and combined to produce the final
20 // pixels.
21 enum VideoPixelFormat {
22   PIXEL_FORMAT_UNKNOWN = 0,  // Unknown or unspecified format value.
23   PIXEL_FORMAT_I420 =
24       1,  // 12bpp YUV planar 1x1 Y, 2x2 UV samples, a.k.a. YU12.
25 
26   // Note: Chrome does not actually support YVU compositing, so you probably
27   // don't actually want to use this. See http://crbug.com/784627.
28   PIXEL_FORMAT_YV12 = 2,  // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
29 
30   PIXEL_FORMAT_I422 = 3,   // 16bpp YUV planar 1x1 Y, 2x1 UV samples.
31   PIXEL_FORMAT_I420A = 4,  // 20bpp YUVA planar 1x1 Y, 2x2 UV, 1x1 A samples.
32   PIXEL_FORMAT_I444 = 5,   // 24bpp YUV planar, no subsampling.
33   PIXEL_FORMAT_NV12 =
34       6,  // 12bpp with Y plane followed by a 2x2 interleaved UV plane.
35   PIXEL_FORMAT_NV21 =
36       7,  // 12bpp with Y plane followed by a 2x2 interleaved VU plane.
37   /* PIXEL_FORMAT_UYVY = 8,  Deprecated */
38   PIXEL_FORMAT_YUY2 =
39       9,  // 16bpp interleaved 1x1 Y, 2x1 U, 1x1 Y, 2x1 V samples.
40   PIXEL_FORMAT_ARGB = 10,   // 32bpp BGRA (byte-order), 1 plane.
41   PIXEL_FORMAT_XRGB = 11,   // 24bpp BGRX (byte-order), 1 plane.
42   PIXEL_FORMAT_RGB24 = 12,  // 24bpp BGR (byte-order), 1 plane.
43 
44   /* PIXEL_FORMAT_RGB32 = 13,  Deprecated */
45   PIXEL_FORMAT_MJPEG = 14,  // MJPEG compressed.
46   /* PIXEL_FORMAT_MT21 = 15,  Deprecated */
47 
48   // The P* in the formats below designates the number of bits per pixel
49   // component. I.e. P9 is 9-bits per pixel component, P10 is 10-bits per pixel
50   // component, etc.
51   PIXEL_FORMAT_YUV420P9 = 16,
52   PIXEL_FORMAT_YUV420P10 = 17,
53   PIXEL_FORMAT_YUV422P9 = 18,
54   PIXEL_FORMAT_YUV422P10 = 19,
55   PIXEL_FORMAT_YUV444P9 = 20,
56   PIXEL_FORMAT_YUV444P10 = 21,
57   PIXEL_FORMAT_YUV420P12 = 22,
58   PIXEL_FORMAT_YUV422P12 = 23,
59   PIXEL_FORMAT_YUV444P12 = 24,
60 
61   /* PIXEL_FORMAT_Y8 = 25, Deprecated */
62   PIXEL_FORMAT_Y16 = 26,  // single 16bpp plane.
63 
64   PIXEL_FORMAT_ABGR = 27,  // 32bpp RGBA (byte-order), 1 plane.
65   PIXEL_FORMAT_XBGR = 28,  // 24bpp RGBX (byte-order), 1 plane.
66 
67   PIXEL_FORMAT_P016LE = 29,  // 24bpp NV12, 16 bits per channel
68 
69   PIXEL_FORMAT_XR30 =
70       30,  // 32bpp BGRX, 10 bits per channel, 2 bits ignored, 1 plane
71   PIXEL_FORMAT_XB30 =
72       31,  // 32bpp RGBX, 10 bits per channel, 2 bits ignored, 1 plane
73 
74   PIXEL_FORMAT_BGRA = 32,  // 32bpp ARGB (byte-order), 1 plane.
75 
76   // Please update UMA histogram enumeration when adding new formats here.
77   PIXEL_FORMAT_MAX =
78       PIXEL_FORMAT_BGRA,  // Must always be equal to largest entry logged.
79 };
80 
81 // Returns the name of a Format as a string.
82 std::string VideoPixelFormatToString(VideoPixelFormat format);
83 
84 // Returns human readable fourcc string.
85 // If any of the four characters is non-printable, it outputs
86 // "0x<32-bit integer in hex>", e.g. FourccToString(0x66616b00) returns
87 // "0x66616b00".
88 std::string FourccToString(uint32_t fourcc);
89 
90 // Returns the number of significant bits per channel.
91 size_t BitDepth(VideoPixelFormat format);
92 
93 }  // namespace media
94 
95 #endif  // VIDEO_PIXEL_FORMAT_H_
96