1 #include <msp/gl/extensions/arb_texture_float.h>
2 #include <msp/gl/extensions/ext_bgra.h>
3 #include <msp/strings/format.h>
4 #include "pixelformat.h"
11 void operator>>(const LexicalConverter &conv, PixelFormat &fmt)
13 if(conv.get()=="COLOR_INDEX")
15 else if(conv.get()=="STENCIL_INDEX")
17 else if(conv.get()=="DEPTH_COMPONENT")
18 fmt = DEPTH_COMPONENT;
19 else if(conv.get()=="RED")
21 else if(conv.get()=="GREEN")
23 else if(conv.get()=="BLUE")
25 else if(conv.get()=="ALPHA")
27 else if(conv.get()=="RGB")
29 else if(conv.get()=="RGBA")
31 else if(conv.get()=="BGR")
33 else if(conv.get()=="BGRA")
35 else if(conv.get()=="SRGB")
37 else if(conv.get()=="SRGB_ALPHA")
39 else if(conv.get()=="LUMINANCE")
41 else if(conv.get()=="LUMINANCE_ALPHA")
42 fmt = LUMINANCE_ALPHA;
43 else if(conv.get()=="SLUMINANCE")
45 else if(conv.get()=="SLUMINANCE_ALPHA")
46 fmt = SLUMINANCE_ALPHA;
48 throw lexical_error(format("conversion of '%s' to PixelFormat", conv.get()));
51 PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
55 case Graphics::COLOR_INDEX: return COLOR_INDEX;
56 case Graphics::LUMINANCE: return LUMINANCE;
57 case Graphics::LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
58 case Graphics::RGB: return RGB;
60 case Graphics::RGBA: return RGBA;
61 case Graphics::BGR: return BGR;
63 case Graphics::BGRA: return BGRA;
64 default: throw invalid_argument("pixelformat_from_graphics");
68 PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat pf)
74 case Graphics::BGRX: return RGB;
75 case Graphics::BGRA: return RGBA;
76 default: return pixelformat_from_graphics(pf);
80 PixelFormat get_base_pixelformat(PixelFormat pf)
88 case SRGB8: return RGB;
93 case SRGB8_ALPHA8: return RGBA;
98 case SLUMINANCE8: return LUMINANCE;
99 case LUMINANCE_ALPHA8:
100 case LUMINANCE_ALPHA16F:
101 case LUMINANCE_ALPHA32F:
102 case SLUMINANCE_ALPHA:
103 case SLUMINANCE8_ALPHA8: return LUMINANCE_ALPHA;
108 PixelFormat get_srgb_pixelformat(PixelFormat pf)
112 case RGB: return SRGB;
113 case RGBA: return SRGB_ALPHA;
114 case RGB8: return SRGB8;
115 case RGBA8: return SRGB8_ALPHA8;
116 case LUMINANCE: return SLUMINANCE;
117 case LUMINANCE8: return SLUMINANCE8;
118 case LUMINANCE_ALPHA: return SLUMINANCE_ALPHA;
119 case LUMINANCE_ALPHA8: return SLUMINANCE8_ALPHA8;
124 unsigned get_component_count(PixelFormat pf)
126 switch(get_base_pixelformat(pf))
130 case DEPTH_COMPONENT:
137 case LUMINANCE_ALPHA:
138 case SLUMINANCE_ALPHA:
147 throw invalid_argument("get_component_count");
151 unsigned get_component_size(PixelFormat pf)
158 case LUMINANCE_ALPHA16F:
163 case LUMINANCE_ALPHA32F:
170 unsigned get_pixel_size(PixelFormat pf)
172 return get_component_count(pf)*get_component_size(pf);
175 void require_pixelformat(PixelFormat pf)
185 case LUMINANCE_ALPHA16F:
186 case LUMINANCE_ALPHA32F:
187 { static Require _req(ARB_texture_float); }
195 case SLUMINANCE_ALPHA:
196 case SLUMINANCE8_ALPHA8:
197 { static Require _req(EXT_texture_sRGB); }
201 { static Require _req(EXT_bgra); }