1dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
2dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Copyright (C) 2005 The Android Open Source Project
3dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
4dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
5dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * you may not use this file except in compliance with the License.
6dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * You may obtain a copy of the License at
7dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
8dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
9dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
10dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
11dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
12dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * See the License for the specific language governing permissions and
14dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * limitations under the License.
15dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
16dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
17dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifndef ANDROID_PIXELFLINGER_FORMAT_H
18dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define ANDROID_PIXELFLINGER_FORMAT_H
19dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
20dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <stdint.h>
21dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <sys/types.h>
22dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
23dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectenum GGLPixelFormat {
24dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // these constants need to match those
25dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // in graphics/PixelFormat.java, ui/PixelFormat.h, BlitHardware.h
26dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_UNKNOWN    =   0,
27dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_NONE       =   0,
28dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
29dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_RGBA_8888   =   1,  // 4x8-bit ARGB
30dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_RGBX_8888   =   2,  // 3x8-bit RGB stored in 32-bit chunks
31dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_RGB_888     =   3,  // 3x8-bit RGB
32dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_RGB_565     =   4,  // 16-bit RGB
33dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_BGRA_8888   =   5,  // 4x8-bit BGRA
34dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_RGBA_5551   =   6,  // 16-bit RGBA
35dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_RGBA_4444   =   7,  // 16-bit RGBA
36dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
37dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_A_8         =   8,  // 8-bit A
38dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_L_8         =   9,  // 8-bit L (R=G=B = L)
39dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_LA_88       = 0xA,  // 16-bit LA
40dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_RGB_332     = 0xB,  // 8-bit RGB (non paletted)
41dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
425dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    // reserved range. don't use.
435dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    GGL_PIXEL_FORMAT_RESERVED_10 = 0x10,
445dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    GGL_PIXEL_FORMAT_RESERVED_11 = 0x11,
455dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    GGL_PIXEL_FORMAT_RESERVED_12 = 0x12,
465dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    GGL_PIXEL_FORMAT_RESERVED_13 = 0x13,
475dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    GGL_PIXEL_FORMAT_RESERVED_14 = 0x14,
485dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    GGL_PIXEL_FORMAT_RESERVED_15 = 0x15,
495dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    GGL_PIXEL_FORMAT_RESERVED_16 = 0x16,
505dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    GGL_PIXEL_FORMAT_RESERVED_17 = 0x17,
51dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
52dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // reserved/special formats
53dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_Z_16       =  0x18,
54dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_S_8        =  0x19,
55dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_SZ_24      =  0x1A,
56dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_PIXEL_FORMAT_SZ_8       =  0x1B,
578e4f143d45722bf1e8584e84e55ff844b176c75aDima Zavin
585dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    // reserved range. don't use.
595dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    GGL_PIXEL_FORMAT_RESERVED_20 = 0x20,
605dca8493452e5b443e58b3316c7128a1de612fc1Mathias Agopian    GGL_PIXEL_FORMAT_RESERVED_21 = 0x21,
61dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};
62dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
63dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectenum GGLFormatComponents {
64dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	GGL_STENCIL_INDEX		= 0x1901,
65dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	GGL_DEPTH_COMPONENT		= 0x1902,
66dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	GGL_ALPHA				= 0x1906,
67dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	GGL_RGB					= 0x1907,
68dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	GGL_RGBA				= 0x1908,
69dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	GGL_LUMINANCE			= 0x1909,
70dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	GGL_LUMINANCE_ALPHA		= 0x190A,
71dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};
72dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
73dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectenum GGLFormatComponentIndex {
74dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_INDEX_ALPHA   = 0,
75dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_INDEX_RED     = 1,
76dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_INDEX_GREEN   = 2,
77dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_INDEX_BLUE    = 3,
78dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_INDEX_STENCIL = 0,
79dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_INDEX_DEPTH   = 1,
80dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_INDEX_Y       = 0,
81dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_INDEX_CB      = 1,
82dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGL_INDEX_CR      = 2,
83dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};
84dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
85dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projecttypedef struct {
86dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef __cplusplus
87dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    enum {
88dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        ALPHA   = GGL_INDEX_ALPHA,
89dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        RED     = GGL_INDEX_RED,
90dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        GREEN   = GGL_INDEX_GREEN,
91dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        BLUE    = GGL_INDEX_BLUE,
92dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        STENCIL = GGL_INDEX_STENCIL,
93dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        DEPTH   = GGL_INDEX_DEPTH,
94dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        LUMA    = GGL_INDEX_Y,
95dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        CHROMAB = GGL_INDEX_CB,
96dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        CHROMAR = GGL_INDEX_CR,
97dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    };
98dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    inline uint32_t mask(int i) const {
99dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            return ((1<<(c[i].h-c[i].l))-1)<<c[i].l;
100dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
101dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    inline uint32_t bits(int i) const {
102dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            return c[i].h - c[i].l;
103dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
104dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
105dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	uint8_t     size;	// bytes per pixel
106dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    uint8_t     bitsPerPixel;
107dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    union {
108dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        struct {
109dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            uint8_t     ah;		// alpha high bit position + 1
110dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            uint8_t     al;		// alpha low bit position
111dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            uint8_t     rh;		// red high bit position + 1
112dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            uint8_t     rl;		// red low bit position
113dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            uint8_t     gh;		// green high bit position + 1
114dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            uint8_t     gl;		// green low bit position
115dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            uint8_t     bh;		// blue high bit position + 1
116dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            uint8_t     bl;		// blue low bit position
117dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        };
118dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        struct {
119dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            uint8_t h;
120dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            uint8_t l;
121dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        } __attribute__((__packed__)) c[4];
122dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    } __attribute__((__packed__));
123dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	uint16_t    components;	// GGLFormatComponents
124dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project} GGLFormat;
125dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
126dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
127dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef __cplusplus
128dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectextern "C" const GGLFormat* gglGetPixelFormatTable(size_t* numEntries = 0);
129dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else
130dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectconst GGLFormat* gglGetPixelFormatTable(size_t* numEntries);
131dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
132dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
133dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
134dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ----------------------------------------------------------------------------
135dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
136dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif // ANDROID_PIXELFLINGER_FORMAT_H
137