format.h revision 13f797da7f190e9ea52f2f3d235210b8a4963b21
1/*
2 * Copyright (C) 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_PIXELFLINGER_FORMAT_H
18#define ANDROID_PIXELFLINGER_FORMAT_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
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    // YCbCr formats (SP=semi-planar, P=planar)
43    GGL_PIXEL_FORMAT_YCbCr_422_SP= 0x10,
44    GGL_PIXEL_FORMAT_YCbCr_420_SP= 0x11,
45    GGL_PIXEL_FORMAT_YCbCr_422_P = 0x12,
46    GGL_PIXEL_FORMAT_YCbCr_420_P = 0x13,
47    GGL_PIXEL_FORMAT_YCbCr_422_I = 0x14,
48    GGL_PIXEL_FORMAT_YCbCr_420_I = 0x15,
49
50    // reserved/special formats
51    GGL_PIXEL_FORMAT_Z_16       =  0x18,
52    GGL_PIXEL_FORMAT_S_8        =  0x19,
53    GGL_PIXEL_FORMAT_SZ_24      =  0x1A,
54    GGL_PIXEL_FORMAT_SZ_8       =  0x1B,
55};
56
57enum GGLFormatComponents {
58	GGL_STENCIL_INDEX		= 0x1901,
59	GGL_DEPTH_COMPONENT		= 0x1902,
60	GGL_ALPHA				= 0x1906,
61	GGL_RGB					= 0x1907,
62	GGL_RGBA				= 0x1908,
63	GGL_LUMINANCE			= 0x1909,
64	GGL_LUMINANCE_ALPHA		= 0x190A,
65    GGL_Y_CB_CR_SP          = 0x8000,
66    GGL_Y_CB_CR             = GGL_Y_CB_CR_SP,
67    GGL_Y_CB_CR_P           = 0x8001,
68    GGL_Y_CB_CR_I           = 0x8002,
69};
70
71enum GGLFormatComponentIndex {
72    GGL_INDEX_ALPHA   = 0,
73    GGL_INDEX_RED     = 1,
74    GGL_INDEX_GREEN   = 2,
75    GGL_INDEX_BLUE    = 3,
76    GGL_INDEX_STENCIL = 0,
77    GGL_INDEX_DEPTH   = 1,
78    GGL_INDEX_Y       = 0,
79    GGL_INDEX_CB      = 1,
80    GGL_INDEX_CR      = 2,
81};
82
83typedef struct {
84#ifdef __cplusplus
85    enum {
86        ALPHA   = GGL_INDEX_ALPHA,
87        RED     = GGL_INDEX_RED,
88        GREEN   = GGL_INDEX_GREEN,
89        BLUE    = GGL_INDEX_BLUE,
90        STENCIL = GGL_INDEX_STENCIL,
91        DEPTH   = GGL_INDEX_DEPTH,
92        LUMA    = GGL_INDEX_Y,
93        CHROMAB = GGL_INDEX_CB,
94        CHROMAR = GGL_INDEX_CR,
95    };
96    inline uint32_t mask(int i) const {
97            return ((1<<(c[i].h-c[i].l))-1)<<c[i].l;
98    }
99    inline uint32_t bits(int i) const {
100            return c[i].h - c[i].l;
101    }
102#endif
103	uint8_t     size;	// bytes per pixel
104    uint8_t     bitsPerPixel;
105    union {
106        struct {
107            uint8_t     ah;		// alpha high bit position + 1
108            uint8_t     al;		// alpha low bit position
109            uint8_t     rh;		// red high bit position + 1
110            uint8_t     rl;		// red low bit position
111            uint8_t     gh;		// green high bit position + 1
112            uint8_t     gl;		// green low bit position
113            uint8_t     bh;		// blue high bit position + 1
114            uint8_t     bl;		// blue low bit position
115        };
116        struct {
117            uint8_t h;
118            uint8_t l;
119        } __attribute__((__packed__)) c[4];
120    } __attribute__((__packed__));
121	uint16_t    components;	// GGLFormatComponents
122} GGLFormat;
123
124
125#ifdef __cplusplus
126extern "C" const GGLFormat* gglGetPixelFormatTable(size_t* numEntries = 0);
127#else
128const GGLFormat* gglGetPixelFormatTable(size_t* numEntries);
129#endif
130
131
132// ----------------------------------------------------------------------------
133
134#endif // ANDROID_PIXELFLINGER_FORMAT_H
135