Android Camera默认输出的就是NV21格式。对android的像素格式进行了整理,有利于加深了对色彩空间的理解。
android 像素格式定义:
/system/core/include/system/graphics.h
45typedef enum android_pixel_format {
46 /*
47 * "linear" color pixel formats:
48 *
49 * When used with ANativeWindow, the dataSpace field describes the color
50 * space of the buffer.
51 *
52 * The color space determines, for example, if the formats are linear or
53 * gamma-corrected; or whether any special operations are performed when
54 * reading or writing into a buffer in one of these formats.
55 */
56 HAL_PIXEL_FORMAT_RGBA_8888 = 1,
57 HAL_PIXEL_FORMAT_RGBX_8888 = 2,
58 HAL_PIXEL_FORMAT_RGB_888 = 3,
59 HAL_PIXEL_FORMAT_RGB_565 = 4,
60 HAL_PIXEL_FORMAT_BGRA_8888 = 5,
61
62 /*
63 * 0x100 - 0x1FF
64 *
65 * This range is reserved for pixel formats that are specific to the HAL
66 * implementation. Implementations can use any value in this range to
67 * communicate video pixel formats between their HAL modules. These formats
68 * must not have an alpha channel. Additionally, an EGLimage created from a
69 * gralloc buffer of one of these formats must be supported for use with the
70 * GL_OES_EGL_image_external OpenGL ES extension.
71 */
72
73 /*
74 * Android YUV format:
75 *
76 * This format is exposed outside of the HAL to software decoders and
77 * applications. EGLImageKHR must support it in conjunction with the
78 * OES_EGL_image_external extension.
79 *
80 * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
81 * by (W/2) x (H/2) Cr and Cb planes.
82 *
83 * This format assumes
84 * - an even width
85 * - an even height
86 * - a horizontal stride multiple of 16 pixels
87 * - a vertical stride equal to the height
88 *
89 * y_size = stride * height
90 * c_stride = ALIGN(stride/2, 16)
91 * c_size = c_stride * height/2
92 * size = y_size + c_size * 2
93 * cr_offset = y_size
94 * cb_offset = y_size + c_size
95 *
96 * When used with ANativeWindow, the dataSpace field describes the color
97 * space of the buffer.
98 */
99 HAL_PIXEL_FORMAT_YV12 = 0x32315659, // YCrCb 4:2:0 Planar
100
101
102 /*
103 * Android Y8 format:
104 *
105 * This format is exposed outside of the HAL to the framework.
106 * The expected gralloc usage flags are SW_* and HW_CAMERA_*,
107 * and no other HW_ flags will be used.
108 *
109 * Y8 is a YUV planar format comprised of a WxH Y plane,
110 * with each pixel being represented by 8 bits.
111 *
112 * It is equivalent to just the Y plane from YV12.
113 *
114 * This format assumes
115 * - an even width
116 * - an even height
117 * - a horizontal stride multiple of 16 pixels
118 * - a vertical stride equal to the height
119 *
120 * size = stride * height
121 *
122 * When used with ANativeWindow, the dataSpace field describes the color
123 * space of the buffer.
124 */
125 HAL_PIXEL_FORMAT_Y8 = 0x20203859,
126
127 /*
128 * Android Y16 format:
129 *
130 * This format is exposed outside of the HAL to the framework.
131 * The expected gralloc usage flags are SW_* and HW_CAMERA_*,
132 * and no other HW_ flags will be used.
133 *
134 * Y16 is a YUV planar format comprised of a WxH Y plane,
135 * with each pixel being represented by 16 bits.
136 *
137 * It is just like Y8, but has double the bits per pixel (little endian).
138 *
139 * This format assumes
140 * - an even width
141 * - an even height
142 * - a horizontal stride multiple of 16 pixels
143 * - a vertical stride equal to the height
144 * - strides are specified in pixels, not in bytes
145 *
146 * size = stride * height * 2
147 *
148 * When used with ANativeWindow, the dataSpace field describes the color
149 * space of the buffer, except that dataSpace field
150 * HAL_DATASPACE_DEPTH indicates that this buffer contains a depth
151 * image where each sample is a distance value measured by a depth camera,
152 * plus an associated confidence value.
153 */
154 HAL_PIXEL_FORMAT_Y16 = 0x20363159,
155
156 /*
157 * Android RAW sensor format:
158 *
159 * This format is exposed outside of the camera HAL to applications.
160 *
161 * RAW16 is a single-channel, 16-bit, little endian format, typically
162 * representing raw Bayer-pattern images from an image sensor, with minimal
163 * processing.
164 *
165 * The exact pixel layout of the data in the buffer is sensor-dependent, and
166 * needs to be queried from the camera device.
167 *
168 * Generally, not all 16 bits are used; more common values are 10 or 12
169 * bits. If not all bits are used, the lower-order bits are filled first.
170 * All parameters to interpret the raw data (black and white points,
171 * color space, etc) must be queried from the camera device.
172 *
173 * This format assumes
174 * - an even width
175 * - an even height
176 * - a horizontal stride multiple of 16 pixels
177 * - a vertical stride equal to the height
178 * - strides are specified in pixels, not in bytes
179 *
180 * size = stride * height * 2
181 *
182 * This format must be accepted by the gralloc module when used with
android 像素格式定义:
/system/core/include/system/graphics.h
45typedef enum android_pixel_format {
46 /*
47 * "linear" color pixel formats:
48 *
49 * When used with ANativeWindow, the dataSpace field describes the color
50 * space of the buffer.
51 *
52 * The color space determines, for example, if the formats are linear or
53 * gamma-corrected; or whether any special operations are performed when
54 * reading or writing into a buffer in one of these formats.
55 */
56 HAL_PIXEL_FORMAT_RGBA_8888 = 1,
57 HAL_PIXEL_FORMAT_RGBX_8888 = 2,
58 HAL_PIXEL_FORMAT_RGB_888 = 3,
59 HAL_PIXEL_FORMAT_RGB_565 = 4,
60 HAL_PIXEL_FORMAT_BGRA_8888 = 5,
61
62 /*
63 * 0x100 - 0x1FF
64 *
65 * This range is reserved for pixel formats that are specific to the HAL
66 * implementation. Implementations can use any value in this range to
67 * communicate video pixel formats between their HAL modules. These formats
68 * must not have an alpha channel. Additionally, an EGLimage created from a
69 * gralloc buffer of one of these formats must be supported for use with the
70 * GL_OES_EGL_image_external OpenGL ES extension.
71 */
72
73 /*
74 * Android YUV format:
75 *
76 * This format is exposed outside of the HAL to software decoders and
77 * applications. EGLImageKHR must support it in conjunction with the
78 * OES_EGL_image_external extension.
79 *
80 * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
81 * by (W/2) x (H/2) Cr and Cb planes.
82 *
83 * This format assumes
84 * - an even width
85 * - an even height
86 * - a horizontal stride multiple of 16 pixels
87 * - a vertical stride equal to the height
88 *
89 * y_size = stride * height
90 * c_stride = ALIGN(stride/2, 16)
91 * c_size = c_stride * height/2
92 * size = y_size + c_size * 2
93 * cr_offset = y_size
94 * cb_offset = y_size + c_size
95 *
96 * When used with ANativeWindow, the dataSpace field describes the color
97 * space of the buffer.
98 */
99 HAL_PIXEL_FORMAT_YV12 = 0x32315659, // YCrCb 4:2:0 Planar
100
101
102 /*
103 * Android Y8 format:
104 *
105 * This format is exposed outside of the HAL to the framework.
106 * The expected gralloc usage flags are SW_* and HW_CAMERA_*,
107 * and no other HW_ flags will be used.
108 *
109 * Y8 is a YUV planar format comprised of a WxH Y plane,
110 * with each pixel being represented by 8 bits.
111 *
112 * It is equivalent to just the Y plane from YV12.
113 *
114 * This format assumes
115 * - an even width
116 * - an even height
117 * - a horizontal stride multiple of 16 pixels
118 * - a vertical stride equal to the height
119 *
120 * size = stride * height
121 *
122 * When used with ANativeWindow, the dataSpace field describes the color
123 * space of the buffer.
124 */
125 HAL_PIXEL_FORMAT_Y8 = 0x20203859,
126
127 /*
128 * Android Y16 format:
129 *
130 * This format is exposed outside of the HAL to the framework.
131 * The expected gralloc usage flags are SW_* and HW_CAMERA_*,
132 * and no other HW_ flags will be used.
133 *
134 * Y16 is a YUV planar format comprised of a WxH Y plane,
135 * with each pixel being represented by 16 bits.
136 *
137 * It is just like Y8, but has double the bits per pixel (little endian).
138 *
139 * This format assumes
140 * - an even width
141 * - an even height
142 * - a horizontal stride multiple of 16 pixels
143 * - a vertical stride equal to the height
144 * - strides are specified in pixels, not in bytes
145 *
146 * size = stride * height * 2
147 *
148 * When used with ANativeWindow, the dataSpace field describes the color
149 * space of the buffer, except that dataSpace field
150 * HAL_DATASPACE_DEPTH indicates that this buffer contains a depth
151 * image where each sample is a distance value measured by a depth camera,
152 * plus an associated confidence value.
153 */
154 HAL_PIXEL_FORMAT_Y16 = 0x20363159,
155
156 /*
157 * Android RAW sensor format:
158 *
159 * This format is exposed outside of the camera HAL to applications.
160 *
161 * RAW16 is a single-channel, 16-bit, little endian format, typically
162 * representing raw Bayer-pattern images from an image sensor, with minimal
163 * processing.
164 *
165 * The exact pixel layout of the data in the buffer is sensor-dependent, and
166 * needs to be queried from the camera device.
167 *
168 * Generally, not all 16 bits are used; more common values are 10 or 12
169 * bits. If not all bits are used, the lower-order bits are filled first.
170 * All parameters to interpret the raw data (black and white points,
171 * color space, etc) must be queried from the camera device.
172 *
173 * This format assumes
174 * - an even width
175 * - an even height
176 * - a horizontal stride multiple of 16 pixels
177 * - a vertical stride equal to the height
178 * - strides are specified in pixels, not in bytes
179 *
180 * size = stride * height * 2
181 *
182 * This format must be accepted by the gralloc module when used with