1 #ifndef MSP_GL_PIXELFORMAT_H_
2 #define MSP_GL_PIXELFORMAT_H_
4 #include <msp/graphics/image.h>
5 #include <msp/strings/lexicalcast.h>
12 Identifies the components of a pixel, without type information.
14 The values are bitfields laid as follows:
17 │││ │ └╴Number of components
20 │└──────╴Reverse order flag
21 └───────╴Grayscale flag
23 This information is presented for internal documentation purposes only; it is
24 inadvisable for applications to rely on it.
32 DEPTH_COMPONENT = 0x09,
37 LUMINANCE_ALPHA = 0x42
41 Describes a mapping from one set of components to another.
47 RG_TO_LUMINANCE_ALPHA,
53 Identifies a pixel format, with components and type.
55 The values are bitfields laid as follows:
58 ││││ │ └╴Components (see PixelComponents)
59 ││││ └──────────╴Size of one component (bytes)
60 │││└───────────────╴Signed flag
61 ││└────────────────╴Floating-point flag
62 │└─────────────────╴Normalized flag
63 └──────────────────╴sRGB flag
65 This information is presented for internal documentation purposes only; it is
66 inadvisable for applications to rely on it.
81 RGBA16F = 0x3200|RGBA,
82 RGBA32F = 0x3400|RGBA,
84 SRGB8_ALPHA8 = 0xC100|RGBA,
88 SBGR8_ALPHA8 = 0xC100|BGRA,
89 LUMINANCE8 = 0x4100|LUMINANCE,
90 LUMINANCE8_ALPHA8 = 0x4100|LUMINANCE_ALPHA,
91 DEPTH_COMPONENT16 = 0x4200|DEPTH_COMPONENT,
92 DEPTH_COMPONENT24 = 0x4300|DEPTH_COMPONENT,
93 DEPTH_COMPONENT32 = 0x4400|DEPTH_COMPONENT,
94 DEPTH_COMPONENT32F = 0x3400|DEPTH_COMPONENT,
95 STENCIL_INDEX8 = 0x0100|STENCIL_INDEX
98 void operator>>(const LexicalConverter &, PixelComponents &);
99 void operator>>(const LexicalConverter &, PixelFormat &);
101 PixelComponents components_from_graphics(Graphics::PixelFormat);
102 PixelFormat pixelformat_from_image(const Graphics::Image &, bool = false);
104 ComponentSwizzle get_required_swizzle(PixelComponents);
105 PixelComponents swizzle_components(PixelComponents, ComponentSwizzle);
106 PixelComponents unswizzle_components(PixelComponents, ComponentSwizzle);
108 PixelFormat make_pixelformat(PixelComponents, DataType, bool = false);
109 inline PixelComponents get_components(PixelFormat f) { return static_cast<PixelComponents>(f&0xFF); }
110 inline unsigned get_component_count(PixelComponents c) { return c&7; }
111 inline unsigned get_component_count(PixelFormat f) { return get_component_count(get_components(f)); }
112 inline DataType get_component_type(PixelFormat f) { return static_cast<DataType>((f&0xF00)>>8 | (f&0x3000)>>4); }
113 inline unsigned get_component_size(PixelFormat f) { return get_type_size(get_component_type(f)); }
114 inline bool is_srgb(PixelFormat f) { return f&0x8000; }
115 inline unsigned get_pixel_size(PixelFormat f) { return get_component_count(f)*get_type_size(get_component_type(f)); }
117 void require_pixelformat(PixelFormat);
122 #include "pixelformat_backend.h"