• 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 ANDROID_V4L2_CODEC2_COMMON_VIDEO_PIXEL_FORMAT_H
8 #define ANDROID_V4L2_CODEC2_COMMON_VIDEO_PIXEL_FORMAT_H
9 
10 #include <string>
11 
12 #include "ui/Size.h"
13 
14 namespace android {
15 
16 // Pixel formats roughly based on FOURCC labels, see:
17 // http://www.fourcc.org/rgb.php and http://www.fourcc.org/yuv.php
18 enum class VideoPixelFormat {
19     I420,    // 12bpp YUV planar 1x1 Y, 2x2 UV samples, a.k.a. YU12.
20     YV12,    // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
21     I422,    // 16bpp YUV planar 1x1 Y, 2x1 UV samples.
22     I420A,   // 20bpp YUVA planar 1x1 Y, 2x2 UV, 1x1 A samples.
23     I444,    // 24bpp YUV planar, no subsampling.
24     NV12,    // 12bpp with Y plane followed by a 2x2 interleaved UV plane.
25     NV21,    // 12bpp with Y plane followed by a 2x2 interleaved VU plane.
26     YUY2,    // 16bpp interleaved 1x1 Y, 2x1 U, 1x1 Y, 2x1 V samples.
27     ARGB,    // 32bpp BGRA (byte-order), 1 plane.
28     XRGB,    // 24bpp BGRX (byte-order), 1 plane.
29     RGB24,   // 24bpp BGR (byte-order), 1 plane.
30     MJPEG,   // MJPEG compressed.
31     Y16,     // single 16bpp plane.
32     ABGR,    // 32bpp RGBA (byte-order), 1 plane.
33     XBGR,    // 24bpp RGBX (byte-order), 1 plane.
34     P016LE,  // 24bpp NV12, 16 bits per channel
35     XR30,    // 32bpp BGRX, 10 bits per channel, 2 bits ignored, 1 plane
36     XB30,    // 32bpp RGBX, 10 bits per channel, 2 bits ignored, 1 plane
37     BGRA,    // 32bpp ARGB (byte-order), 1 plane.
38     // The P* in the formats below designates the number of bits per pixel component. I.e. P9 is
39     // 9-bits per pixel component, P10 is 10-bits per pixel component, etc.
40     YUV420P9,
41     YUV420P10,
42     YUV422P9,
43     YUV422P10,
44     YUV444P9,
45     YUV444P10,
46     YUV420P12,
47     YUV422P12,
48     YUV444P12,
49     UNKNOWN,  // Unknown or unspecified format value.
50 };
51 
52 // Returns the name of a Format as a string.
53 std::string videoPixelFormatToString(VideoPixelFormat format);
54 
55 // Returns human readable fourcc string. If any of the four characters is non-printable, it outputs
56 // "0x<32-bit integer in hex>", e.g. FourccToString(0x66616b00) returns "0x66616b00".
57 std::string fourccToString(uint32_t fourcc);
58 
59 // Returns the number of significant bits per channel.
60 size_t bitDepth(VideoPixelFormat format);
61 
62 // Returns the number of planes for the |format|.
63 size_t numPlanes(VideoPixelFormat format);
64 
65 // Returns required allocation size for a (tightly packed) frame of the given coded size and format.
66 size_t allocationSize(VideoPixelFormat format, const android::ui::Size& coded_size);
67 
68 // Returns the plane Size (in bytes) for a plane of the given coded size and format.
69 android::ui::Size planeSize(VideoPixelFormat format, size_t plane,
70                             const android::ui::Size& coded_size);
71 
72 // Returns horizontal bits per pixel for given |plane| and |format|.
73 int planeHorizontalBitsPerPixel(VideoPixelFormat format, size_t plane);
74 
75 // Returns bits per pixel for given |plane| and |format|.
76 int planeBitsPerPixel(VideoPixelFormat format, size_t plane);
77 
78 // Returns the number of bytes per element for given |plane| and |format|.
79 int bytesPerElement(VideoPixelFormat format, size_t plane);
80 
81 // Returns true if |plane| is a valid plane index for the given |format|.
82 bool isValidPlane(VideoPixelFormat format, size_t plane);
83 
84 // Returns the pixel size of each subsample for a given |plane| and |format|.
85 // E.g. 2x2 for the U-plane in I420.
86 android::ui::Size SampleSize(VideoPixelFormat format, size_t plane);
87 
88 }  // namespace android
89 
90 #endif  // ANDROID_V4L2_CODEC2_COMMON_VIDEO_PIXEL_FORMAT_H
91