]> git.tdb.fi Git - libs/gl.git/blob - source/core/pixelformat.h
71a8bd4c3de6c98994e618d3a382be4b9dbc1791
[libs/gl.git] / source / core / pixelformat.h
1 #ifndef MSP_GL_PIXELFORMAT_H_
2 #define MSP_GL_PIXELFORMAT_H_
3
4 #include <msp/graphics/image.h>
5 #include <msp/strings/lexicalcast.h>
6 #include "datatype.h"
7
8 namespace Msp {
9 namespace GL {
10
11 /**
12 Identifies the components of a pixel, without type information.  The values
13 are bitfields laid as follows:
14
15 _grs dccc
16  │││ │  └╴Number of components
17  │││ └───╴Depth flag
18  ││└─────╴Stencil flag
19  │└──────╴Reverse order flag
20  └───────╴Grayscale flag
21
22 This information is presented for internal documentation purposes only; it is
23 inadvisable for programs to rely on it.
24 */
25 enum PixelComponents
26 {
27         RED = 0x01,
28         RG = 0x02,
29         RGB = 0x03,
30         RGBA = 0x04,
31         DEPTH_COMPONENT = 0x09,
32         STENCIL_INDEX = 0x11,
33         BGR = 0x23,
34         BGRA = 0x24,
35         LUMINANCE = 0x41,
36         LUMINANCE_ALPHA = 0x42
37 };
38
39 /**
40 Identifies a pixel format, with components and type.  The values are bitfields
41 laid as follows:
42
43 tnfg ssss cccc cccc
44 ││││    │         └╴Components (see PixelComponents)
45 ││││    └──────────╴Size of one component (bytes)
46 │││└───────────────╴Signed flag
47 ││└────────────────╴Floating-point flag
48 │└─────────────────╴Normalized flag
49 └──────────────────╴sRGB flag
50
51 This information is presented for internal documentation purposes only; it is
52 inadvisable for programs to rely on it.
53 */
54 enum PixelFormat
55 {
56         NO_PIXELFORMAT = 0,
57         R8 = 0x4100|RED,
58         R16F = 0x3200|RED,
59         R32F = 0x3400|RED,
60         RG8 = 0x4100|RG,
61         RG16F = 0x3200|RG,
62         RG32F = 0x3400|RG,
63         RGB8 = 0x4100|RGB,
64         RGB16F = 0x3200|RGB,
65         RGB32F = 0x3400|RGB,
66         RGBA8 = 0x4100|RGBA,
67         RGBA16F = 0x3200|RGBA,
68         RGBA32F = 0x3400|RGBA,
69         SRGB8 = 0xC100|RGB,
70         SRGB8_ALPHA8 = 0xC100|RGBA,
71         BGR8 = 0x4100|BGR,
72         BGRA8 = 0x4100|BGRA,
73         SBGR8 = 0xC100|BGR,
74         SBGR8_ALPHA8 = 0xC100|BGRA,
75         LUMINANCE8 = 0x4100|LUMINANCE,
76         LUMINANCE8_ALPHA8 = 0x4100|LUMINANCE_ALPHA,
77         DEPTH_COMPONENT16 = 0x4200|DEPTH_COMPONENT,
78         DEPTH_COMPONENT24 = 0x4300|DEPTH_COMPONENT,
79         DEPTH_COMPONENT32 = 0x4400|DEPTH_COMPONENT,
80         DEPTH_COMPONENT32F = 0x3400|DEPTH_COMPONENT,
81         STENCIL_INDEX8 = 0x0100|STENCIL_INDEX
82 };
83
84 void operator>>(const LexicalConverter &, PixelComponents &);
85 void operator>>(const LexicalConverter &, PixelFormat &);
86
87 PixelComponents components_from_graphics(Graphics::PixelFormat);
88 PixelFormat pixelformat_from_image(const Graphics::Image &, bool = false);
89
90 PixelFormat make_pixelformat(PixelComponents, DataType, bool = false);
91 inline PixelComponents get_components(PixelFormat f) { return static_cast<PixelComponents>(f&0xFF); }
92 inline unsigned get_component_count(PixelComponents c) { return c&7; }
93 inline unsigned get_component_count(PixelFormat f) { return get_component_count(get_components(f)); }
94 inline DataType get_component_type(PixelFormat f) { return static_cast<DataType>((f&0xF00)>>8 | (f&0x3000)>>4); }
95 inline unsigned get_component_size(PixelFormat f) { return get_type_size(get_component_type(f)); }
96 inline bool is_srgb(PixelFormat f) { return f&0x8000; }
97 inline unsigned get_pixel_size(PixelFormat f) { return get_component_count(f)*get_type_size(get_component_type(f)); }
98
99 void require_pixelformat(PixelFormat);
100
101 } // namespace GL
102 } // namespace Msp
103
104 #include "pixelformat_backend.h"
105
106 #endif