format.h revision 4f6e8d7a00cbeda1e70cc15be9c4af1018bdad53
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_RGBA_5551   =   6,  // 16-bit RGBA
34    GGL_PIXEL_FORMAT_RGBA_4444   =   7,  // 16-bit RGBA
35
36    GGL_PIXEL_FORMAT_A_8         =   8,  // 8-bit A
37    GGL_PIXEL_FORMAT_L_8         =   9,  // 8-bit L (R=G=B = L)
38    GGL_PIXEL_FORMAT_LA_88       = 0xA,  // 16-bit LA
39    GGL_PIXEL_FORMAT_RGB_332     = 0xB,  // 8-bit RGB (non paletted)
40
41    // YCbCr formats
42    GGL_PIXEL_FORMAT_YCbCr_422_SP= 0x10,
43    GGL_PIXEL_FORMAT_YCbCr_420_SP= 0x11,
44
45    // reserved/special formats
46    GGL_PIXEL_FORMAT_Z_16       =  0x18,
47    GGL_PIXEL_FORMAT_S_8        =  0x19,
48    GGL_PIXEL_FORMAT_SZ_24      =  0x1A,
49    GGL_PIXEL_FORMAT_SZ_8       =  0x1B,
50};
51
52enum GGLFormatComponents {
53	GGL_STENCIL_INDEX		= 0x1901,
54	GGL_DEPTH_COMPONENT		= 0x1902,
55	GGL_ALPHA				= 0x1906,
56	GGL_RGB					= 0x1907,
57	GGL_RGBA				= 0x1908,
58	GGL_LUMINANCE			= 0x1909,
59	GGL_LUMINANCE_ALPHA		= 0x190A,
60	GGL_Y_CB_CR             = 0x8000,
61};
62
63enum GGLFormatComponentIndex {
64    GGL_INDEX_ALPHA   = 0,
65    GGL_INDEX_RED     = 1,
66    GGL_INDEX_GREEN   = 2,
67    GGL_INDEX_BLUE    = 3,
68    GGL_INDEX_STENCIL = 0,
69    GGL_INDEX_DEPTH   = 1,
70    GGL_INDEX_Y       = 0,
71    GGL_INDEX_CB      = 1,
72    GGL_INDEX_CR      = 2,
73};
74
75typedef struct {
76#ifdef __cplusplus
77    enum {
78        ALPHA   = GGL_INDEX_ALPHA,
79        RED     = GGL_INDEX_RED,
80        GREEN   = GGL_INDEX_GREEN,
81        BLUE    = GGL_INDEX_BLUE,
82        STENCIL = GGL_INDEX_STENCIL,
83        DEPTH   = GGL_INDEX_DEPTH,
84        LUMA    = GGL_INDEX_Y,
85        CHROMAB = GGL_INDEX_CB,
86        CHROMAR = GGL_INDEX_CR,
87    };
88    inline uint32_t mask(int i) const {
89            return ((1<<(c[i].h-c[i].l))-1)<<c[i].l;
90    }
91    inline uint32_t bits(int i) const {
92            return c[i].h - c[i].l;
93    }
94#endif
95	uint8_t     size;	// bytes per pixel
96    uint8_t     bitsPerPixel;
97    union {
98        struct {
99            uint8_t     ah;		// alpha high bit position + 1
100            uint8_t     al;		// alpha low bit position
101            uint8_t     rh;		// red high bit position + 1
102            uint8_t     rl;		// red low bit position
103            uint8_t     gh;		// green high bit position + 1
104            uint8_t     gl;		// green low bit position
105            uint8_t     bh;		// blue high bit position + 1
106            uint8_t     bl;		// blue low bit position
107        };
108        struct {
109            uint8_t h;
110            uint8_t l;
111        } __attribute__((__packed__)) c[4];
112    } __attribute__((__packed__));
113	uint16_t    components;	// GGLFormatComponents
114} GGLFormat;
115
116
117#ifdef __cplusplus
118extern "C" const GGLFormat* gglGetPixelFormatTable(size_t* numEntries = 0);
119#else
120const GGLFormat* gglGetPixelFormatTable(size_t* numEntries);
121#endif
122
123
124// ----------------------------------------------------------------------------
125
126#endif // ANDROID_PIXELFLINGER_FORMAT_H
127