Android色彩空间像素格式定义及设定

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 the
183     * following usage flags:
184     *    - GRALLOC_USAGE_HW_CAMERA_*
185     *    - GRALLOC_USAGE_SW_*
186     *    - GRALLOC_USAGE_RENDERSCRIPT
187     *
188     * When used with ANativeWindow, the dataSpace should be
189     * HAL_DATASPACE_ARBITRARY, as raw image sensor buffers require substantial
190     * extra metadata to define.
191     */
192    HAL_PIXEL_FORMAT_RAW16 = 0x20,
193
194    /*
195     * Android RAW10 format:
196     *
197     * This format is exposed outside of the camera HAL to applications.
198     *
199     * RAW10 is a single-channel, 10-bit per pixel, densely packed in each row,
200     * unprocessed format, usually representing raw Bayer-pattern images coming from
201     * an image sensor.
202     *
203     * In an image buffer with this format, starting from the first pixel of each
204     * row, each 4 consecutive pixels are packed into 5 bytes (40 bits). Each one
205     * of the first 4 bytes contains the top 8 bits of each pixel, The fifth byte
206     * contains the 2 least significant bits of the 4 pixels, the exact layout data
207     * for each 4 consecutive pixels is illustrated below (Pi[j] stands for the jth
208     * bit of the ith pixel):
209     *
210     *          bit 7                                     bit 0
211     *          =====|=====|=====|=====|=====|=====|=====|=====|
212     * Byte 0: |P0[9]|P0[8]|P0[7]|P0[6]|P0[5]|P0[4]|P0[3]|P0[2]|
213     *         |-----|-----|-----|-----|-----|-----|-----|-----|
214     * Byte 1: |P1[9]|P1[8]|P1[7]|P1[6]|P1[5]|P1[4]|P1[3]|P1[2]|
215     *         |-----|-----|-----|-----|-----|-----|-----|-----|
216     * Byte 2: |P2[9]|P2[8]|P2[7]|P2[6]|P2[5]|P2[4]|P2[3]|P2[2]|
217     *         |-----|-----|-----|-----|-----|-----|-----|-----|
218     * Byte 3: |P3[9]|P3[8]|P3[7]|P3[6]|P3[5]|P3[4]|P3[3]|P3[2]|
219     *         |-----|-----|-----|-----|-----|-----|-----|-----|
220     * Byte 4: |P3[1]|P3[0]|P2[1]|P2[0]|P1[1]|P1[0]|P0[1]|P0[0]|
221     *          ===============================================
222     *
223     * This format assumes
224     * - a width multiple of 4 pixels
225     * - an even height
226     * - a vertical stride equal to the height
227     * - strides are specified in bytes, not in pixels
228     *
229     *   size = stride * height
230     *
231     * When stride is equal to width * (10 / 8), there will be no padding bytes at
232     * the end of each row, the entire image data is densely packed. When stride is
233     * larger than width * (10 / 8), padding bytes will be present at the end of each
234     * row (including the last row).
235     *
236     * This format must be accepted by the gralloc module when used with the
237     * following usage flags:
238     *    - GRALLOC_USAGE_HW_CAMERA_*
239     *    - GRALLOC_USAGE_SW_*
240     *    - GRALLOC_USAGE_RENDERSCRIPT
241     *
242     * When used with ANativeWindow, the dataSpace field should be
243     * HAL_DATASPACE_ARBITRARY, as raw image sensor buffers require substantial
244     * extra metadata to define.
245     */
246    HAL_PIXEL_FORMAT_RAW10 = 0x25,
247
248    /*
249     * Android RAW12 format:
250     *
251     * This format is exposed outside of camera HAL to applications.
252     *
253     * RAW12 is a single-channel, 12-bit per pixel, densely packed in each row,
254     * unprocessed format, usually representing raw Bayer-pattern images coming from
255     * an image sensor.
256     *
257     * In an image buffer with this format, starting from the first pixel of each
258     * row, each two consecutive pixels are packed into 3 bytes (24 bits). The first
259     * and second byte contains the top 8 bits of first and second pixel. The third
260     * byte contains the 4 least significant bits of the two pixels, the exact layout
261     * data for each two consecutive pixels is illustrated below (Pi[j] stands for
262     * the jth bit of the ith pixel):
263     *
264     *           bit 7                                            bit 0
265     *          ======|======|======|======|======|======|======|======|
266     * Byte 0: |P0[11]|P0[10]|P0[ 9]|P0[ 8]|P0[ 7]|P0[ 6]|P0[ 5]|P0[ 4]|
267     *         |------|------|------|------|------|------|------|------|
268     * Byte 1: |P1[11]|P1[10]|P1[ 9]|P1[ 8]|P1[ 7]|P1[ 6]|P1[ 5]|P1[ 4]|
269     *         |------|------|------|------|------|------|------|------|
270     * Byte 2: |P1[ 3]|P1[ 2]|P1[ 1]|P1[ 0]|P0[ 3]|P0[ 2]|P0[ 1]|P0[ 0]|
271     *          =======================================================
272     *
273     * This format assumes:
274     * - a width multiple of 4 pixels
275     * - an even height
276     * - a vertical stride equal to the height
277     * - strides are specified in bytes, not in pixels
278     *
279     *   size = stride * height
280     *
281     * When stride is equal to width * (12 / 8), there will be no padding bytes at
282     * the end of each row, the entire image data is densely packed. When stride is
283     * larger than width * (12 / 8), padding bytes will be present at the end of
284     * each row (including the last row).
285     *
286     * This format must be accepted by the gralloc module when used with the
287     * following usage flags:
288     *    - GRALLOC_USAGE_HW_CAMERA_*
289     *    - GRALLOC_USAGE_SW_*
290     *    - GRALLOC_USAGE_RENDERSCRIPT
291     *
292     * When used with ANativeWindow, the dataSpace field should be
293     * HAL_DATASPACE_ARBITRARY, as raw image sensor buffers require substantial
294     * extra metadata to define.
295     */
296    HAL_PIXEL_FORMAT_RAW12 = 0x26,
297
298    /*
299     * Android opaque RAW format:
300     *
301     * This format is exposed outside of the camera HAL to applications.
302     *
303     * RAW_OPAQUE is a format for unprocessed raw image buffers coming from an
304     * image sensor. The actual structure of buffers of this format is
305     * implementation-dependent.
306     *
307     * This format must be accepted by the gralloc module when used with the
308     * following usage flags:
309     *    - GRALLOC_USAGE_HW_CAMERA_*
310     *    - GRALLOC_USAGE_SW_*
311     *    - GRALLOC_USAGE_RENDERSCRIPT
312     *
313     * When used with ANativeWindow, the dataSpace field should be
314     * HAL_DATASPACE_ARBITRARY, as raw image sensor buffers require substantial
315     * extra metadata to define.
316     */
317    HAL_PIXEL_FORMAT_RAW_OPAQUE = 0x24,
318
319    /*
320     * Android binary blob graphics buffer format:
321     *
322     * This format is used to carry task-specific data which does not have a
323     * standard image structure. The details of the format are left to the two
324     * endpoints.
325     *
326     * A typical use case is for transporting JPEG-compressed images from the
327     * Camera HAL to the framework or to applications.
328     *
329     * Buffers of this format must have a height of 1, and width equal to their
330     * size in bytes.
331     *
332     * When used with ANativeWindow, the mapping of the dataSpace field to
333     * buffer contents for BLOB is as follows:
334     *
335     *  dataSpace value               | Buffer contents
336     * -------------------------------+-----------------------------------------
337     *  HAL_DATASPACE_JFIF            | An encoded JPEG image
338     *  HAL_DATASPACE_DEPTH           | An android_depth_points buffer
339     *  Other                         | Unsupported
340     *
341     */
342    HAL_PIXEL_FORMAT_BLOB = 0x21,
343
344    /*
345     * Android format indicating that the choice of format is entirely up to the
346     * device-specific Gralloc implementation.
347     *
348     * The Gralloc implementation should examine the usage bits passed in when
349     * allocating a buffer with this format, and it should derive the pixel
350     * format from those usage flags.  This format will never be used with any
351     * of the GRALLOC_USAGE_SW_* usage flags.
352     *
353     * If a buffer of this format is to be used as an OpenGL ES texture, the
354     * framework will assume that sampling the texture will always return an
355     * alpha value of 1.0 (i.e. the buffer contains only opaque pixel values).
356     *
357     * When used with ANativeWindow, the dataSpace field describes the color
358     * space of the buffer.
359     */
360    HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED = 0x22,
361
362    /*
363     * Android flexible YCbCr 4:2:0 formats
364     *
365     * This format allows platforms to use an efficient YCbCr/YCrCb 4:2:0
366     * buffer layout, while still describing the general format in a
367     * layout-independent manner.  While called YCbCr, it can be
368     * used to describe formats with either chromatic ordering, as well as
369     * whole planar or semiplanar layouts.
370     *
371     * struct android_ycbcr (below) is the the struct used to describe it.
372     *
373     * This format must be accepted by the gralloc module when
374     * USAGE_SW_WRITE_* or USAGE_SW_READ_* are set.
375     *
376     * This format is locked for use by gralloc's (*lock_ycbcr) method, and
377     * locking with the (*lock) method will return an error.
378     *
379     * When used with ANativeWindow, the dataSpace field describes the color
380     * space of the buffer.
381     */
382    HAL_PIXEL_FORMAT_YCbCr_420_888 = 0x23,
383
384    /*
385     * Android flexible YCbCr 4:2:2 formats
386     *
387     * This format allows platforms to use an efficient YCbCr/YCrCb 4:2:2
388     * buffer layout, while still describing the general format in a
389     * layout-independent manner.  While called YCbCr, it can be
390     * used to describe formats with either chromatic ordering, as well as
391     * whole planar or semiplanar layouts.
392     *
393     * This format is currently only used by SW readable buffers
394     * produced by MediaCodecs, so the gralloc module can ignore this format.
395     */
396    HAL_PIXEL_FORMAT_YCbCr_422_888 = 0x27,
397
398    /*
399     * Android flexible YCbCr 4:4:4 formats
400     *
401     * This format allows platforms to use an efficient YCbCr/YCrCb 4:4:4
402     * buffer layout, while still describing the general format in a
403     * layout-independent manner.  While called YCbCr, it can be
404     * used to describe formats with either chromatic ordering, as well as
405     * whole planar or semiplanar layouts.
406     *
407     * This format is currently only used by SW readable buffers
408     * produced by MediaCodecs, so the gralloc module can ignore this format.
409     */
410    HAL_PIXEL_FORMAT_YCbCr_444_888 = 0x28,
411
412    /*
413     * Android flexible RGB 888 formats
414     *
415     * This format allows platforms to use an efficient RGB/BGR/RGBX/BGRX
416     * buffer layout, while still describing the general format in a
417     * layout-independent manner.  While called RGB, it can be
418     * used to describe formats with either color ordering and optional
419     * padding, as well as whole planar layout.
420     *
421     * This format is currently only used by SW readable buffers
422     * produced by MediaCodecs, so the gralloc module can ignore this format.
423     */
424    HAL_PIXEL_FORMAT_FLEX_RGB_888 = 0x29,
425
426    /*
427     * Android flexible RGBA 8888 formats
428     *
429     * This format allows platforms to use an efficient RGBA/BGRA/ARGB/ABGR
430     * buffer layout, while still describing the general format in a
431     * layout-independent manner.  While called RGBA, it can be
432     * used to describe formats with any of the component orderings, as
433     * well as whole planar layout.
434     *
435     * This format is currently only used by SW readable buffers
436     * produced by MediaCodecs, so the gralloc module can ignore this format.
437     */
438    HAL_PIXEL_FORMAT_FLEX_RGBA_8888 = 0x2A,
439
440    /* Legacy formats (deprecated), used by ImageFormat.java */
441    HAL_PIXEL_FORMAT_YCbCr_422_SP       = 0x10, // NV16
442    HAL_PIXEL_FORMAT_YCrCb_420_SP       = 0x11, // NV21
443    HAL_PIXEL_FORMAT_YCbCr_422_I        = 0x14, // YUY2
444} android_pixel_format_t;
445




3x8-bit RGB stored in 32-bit chunks
/system/core/libpixelflinger/include/pixelflinger/format.h
23enum GGLPixelFormat {
24    // these constants need to match those
25    // in graphics/PixelFormat.java, ui/PixelFormat.h, BlitHardware.h
26    GGL_PIXEL_FORMAT_UNKNOWN    =   0,
27    GGL_PIXEL_FORMAT_NONE       =   0,
28
29    GGL_PIXEL_FORMAT_RGBA_8888   =   1,  // 4x8-bit ARGB
30    GGL_PIXEL_FORMAT_RGBX_8888   =   2,  // 3x8-bit RGB stored in 32-bit chunks
31    GGL_PIXEL_FORMAT_RGB_888     =   3,  // 3x8-bit RGB
32    GGL_PIXEL_FORMAT_RGB_565     =   4,  // 16-bit RGB
33    GGL_PIXEL_FORMAT_BGRA_8888   =   5,  // 4x8-bit BGRA
34    GGL_PIXEL_FORMAT_RGBA_5551   =   6,  // 16-bit RGBA
35    GGL_PIXEL_FORMAT_RGBA_4444   =   7,  // 16-bit RGBA
36
37    GGL_PIXEL_FORMAT_A_8         =   8,  // 8-bit A
38    GGL_PIXEL_FORMAT_L_8         =   9,  // 8-bit L (R=G=B = L)
39    GGL_PIXEL_FORMAT_LA_88       = 0xA,  // 16-bit LA
40    GGL_PIXEL_FORMAT_RGB_332     = 0xB,  // 8-bit RGB (non paletted)
41
42    // reserved range. don't use.
43    GGL_PIXEL_FORMAT_RESERVED_10 = 0x10,
44    GGL_PIXEL_FORMAT_RESERVED_11 = 0x11,
45    GGL_PIXEL_FORMAT_RESERVED_12 = 0x12,
46    GGL_PIXEL_FORMAT_RESERVED_13 = 0x13,
47    GGL_PIXEL_FORMAT_RESERVED_14 = 0x14,
48    GGL_PIXEL_FORMAT_RESERVED_15 = 0x15,
49    GGL_PIXEL_FORMAT_RESERVED_16 = 0x16,
50    GGL_PIXEL_FORMAT_RESERVED_17 = 0x17,
51
52    // reserved/special formats
53    GGL_PIXEL_FORMAT_Z_16       =  0x18,
54    GGL_PIXEL_FORMAT_S_8        =  0x19,
55    GGL_PIXEL_FORMAT_SZ_24      =  0x1A,
56    GGL_PIXEL_FORMAT_SZ_8       =  0x1B,
57
58    // reserved range. don't use.
59    GGL_PIXEL_FORMAT_RESERVED_20 = 0x20,
60    GGL_PIXEL_FORMAT_RESERVED_21 = 0x21,
61};
62
85typedef struct {
86#ifdef __cplusplus
87    enum {
88        ALPHA   = GGL_INDEX_ALPHA,
89        RED     = GGL_INDEX_RED,
90        GREEN   = GGL_INDEX_GREEN,
91        BLUE    = GGL_INDEX_BLUE,
92        STENCIL = GGL_INDEX_STENCIL,
93        DEPTH   = GGL_INDEX_DEPTH,
94        LUMA    = GGL_INDEX_Y,
95        CHROMAB = GGL_INDEX_CB,
96        CHROMAR = GGL_INDEX_CR,
97    };
98    inline uint32_t mask(int i) const {
99            return ((1<<(c[i].h-c[i].l))-1)< 100    }
101    inline uint32_t bits(int i) const {
102            return c[i].h - c[i].l;
103    }
104#endif
105 uint8_t     size; // bytes per pixel
106    uint8_t     bitsPerPixel;
107    union {
108        struct {
109            uint8_t     ah; // alpha high bit position + 1
110            uint8_t     al; // alpha low bit position
111            uint8_t     rh; // red high bit position + 1
112            uint8_t     rl; // red low bit position
113            uint8_t     gh; // green high bit position + 1
114            uint8_t     gl; // green low bit position
115            uint8_t     bh; // blue high bit position + 1
116            uint8_t     bl; // blue low bit position
117        };
118        struct {
119            uint8_t h;
120            uint8_t l;
121        } __attribute__((__packed__)) c[4];
122    } __attribute__((__packed__));
123 uint16_t    components; // GGLFormatComponents
124} GGLFormat;
125






android7.1.1-- /system/core/libpixelflinger/format.cpp
19#include
21namespace android {22
23
23static GGLFormat const gPixelFormatInfos[] =
24{   //          Alpha    Red     Green   Blue
25    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
26    {  4, 32, {{32,24,   8, 0,  16, 8,  24,16 }}, GGL_RGBA },   // PIXEL_FORMAT_RGBA_8888
27    {  4, 24, {{ 0, 0,   8, 0,  16, 8,  24,16 }}, GGL_RGB  },   // PIXEL_FORMAT_RGBX_8888
28    {  3, 24, {{ 0, 0,   8, 0,  16, 8,  24,16 }}, GGL_RGB  },   // PIXEL_FORMAT_RGB_888
29    {  2, 16, {{ 0, 0,  16,11,  11, 5,   5, 0 }}, GGL_RGB  },   // PIXEL_FORMAT_RGB_565
30    {  4, 32, {{32,24,  24,16,  16, 8,   8, 0 }}, GGL_RGBA },   // PIXEL_FORMAT_BGRA_8888
31    {  2, 16, {{ 1, 0,  16,11,  11, 6,   6, 1 }}, GGL_RGBA },   // PIXEL_FORMAT_RGBA_5551
32    {  2, 16, {{ 4, 0,  16,12,  12, 8,   8, 4 }}, GGL_RGBA },   // PIXEL_FORMAT_RGBA_4444
33    {  1,  8, {{ 8, 0,   0, 0,   0, 0,   0, 0 }}, GGL_ALPHA},   // PIXEL_FORMAT_A8
34    {  1,  8, {{ 0, 0,   8, 0,   8, 0,   8, 0 }}, GGL_LUMINANCE},//PIXEL_FORMAT_L8
35    {  2, 16, {{16, 8,   8, 0,   8, 0,   8, 0 }}, GGL_LUMINANCE_ALPHA},// PIXEL_FORMAT_LA_88
36    {  1,  8, {{ 0, 0,   8, 5,   5, 2,   2, 0 }}, GGL_RGB  },   // PIXEL_FORMAT_RGB_332
37
38    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
39    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
40    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
41    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
42
43    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
44    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
45    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
46    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
47    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
48    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
49    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
50    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
51
52    {  2, 16, {{  0, 0, 16, 0,   0, 0,   0, 0 }}, GGL_DEPTH_COMPONENT},
53    {  1,  8, {{  8, 0,  0, 0,   0, 0,   0, 0 }}, GGL_STENCIL_INDEX  },
54    {  4, 24, {{  0, 0, 24, 0,   0, 0,   0, 0 }}, GGL_DEPTH_COMPONENT},
55    {  4,  8, {{ 32,24,  0, 0,   0, 0,   0, 0 }}, GGL_STENCIL_INDEX  },
56
57    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
58    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
59    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
60    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
61
62    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
63    {  0,  0, {{ 0, 0,   0, 0,   0, 0,   0, 0 }},        0 },   // PIXEL_FORMAT_NONE
64
65};
66
67}; // namespace android






//扫描/dev/graphics/和/dev/下的fd设备
/hardware/libhardware/modules/gralloc/framebuffer.cpp
3static int mapFrameBuffer(struct private_module_t* module)
304{
305    pthread_mutex_lock(&module->lock);
306    int err = mapFrameBufferLocked(module);
307    pthread_mutex_unlock(&module->lock);
308    return err;
309}


142int mapFrameBufferLocked(struct private_module_t* module)
143{
144    // already initialized...
145    if (module->framebuffer) {
146        return 0;
147    }
148
149    char const * const device_template[] = {
150            "/dev/graphics/fb%u",
151            "/dev/fb%u",
152            0 };
153
154    int fd = -1;
155    int i=0;
156    char name[64];
157
158    while ((fd==-1) && device_template[i]) {
159        snprintf(name, 64, device_template[i], 0);
160        fd = open(name, O_RDWR, 0);
161        i++;
162    }
。。。


//设置系统的采用的像素格式
322int fb_device_open(hw_module_t const* module, const char* name,
323        hw_device_t** device)
324{
325    int status = -EINVAL;
326    if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
327        /* initialize our state here */
328        fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev));
329        memset(dev, 0, sizeof(*dev));
330
331        /* initialize the procs */
332        dev->device.common.tag = HARDWARE_DEVICE_TAG;
333        dev->device.common.version = 0;
334        dev->device.common.module = const_cast(module);
335        dev->device.common.close = fb_close;
336        dev->device.setSwapInterval = fb_setSwapInterval;
337        dev->device.post            = fb_post;
338        dev->device.setUpdateRect = 0;
339
340        private_module_t* m = (private_module_t*)module;
341        status = mapFrameBuffer(m);
342        if (status >= 0) {
343            int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3);
344            int format = (m->info.bits_per_pixel == 32)
345                         ? (m->info.red.offset ? HAL_PIXEL_FORMAT_BGRA_8888 : HAL_PIXEL_FORMAT_RGBX_8888)
346                         : HAL_PIXEL_FORMAT_RGB_565;
347            const_cast(dev->device.flags) = 0;
348            const_cast(dev->device.width) = m->info.xres;
349            const_cast(dev->device.height) = m->info.yres;
350            const_cast(dev->device.stride) = stride;
351            const_cast(dev->device.format) = format;
352            const_cast(dev->device.xdpi) = m->xdpi;
353            const_cast(dev->device.ydpi) = m->ydpi;
354            const_cast(dev->device.fps) = m->fps;
355            const_cast(dev->device.minSwapInterval) = 1;
356            const_cast(dev->device.maxSwapInterval) = 1;
357            *device = &dev->device.common;
358        }
359    }
360    return status;
361}

你可能感兴趣的:(音视频)