]> git.tdb.fi Git - libs/gl.git/blob - source/pixelformat.cpp
Use the lexical_cast framework instead of istreams
[libs/gl.git] / source / pixelformat.cpp
1 #include <msp/strings/format.h>
2 #include "pixelformat.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GL {
8
9 void operator>>(const LexicalConverter &conv, PixelFormat &fmt)
10 {
11         if(conv.get()=="COLOR_INDEX")
12                 fmt = COLOR_INDEX;
13         else if(conv.get()=="STENCIL_INDEX")
14                 fmt = STENCIL_INDEX;
15         else if(conv.get()=="DEPTH_COMPONENT")
16                 fmt = DEPTH_COMPONENT;
17         else if(conv.get()=="RED")
18                 fmt = RED;
19         else if(conv.get()=="GREEN")
20                 fmt = GREEN;
21         else if(conv.get()=="BLUE")
22                 fmt = BLUE;
23         else if(conv.get()=="ALPHA")
24                 fmt = ALPHA;
25         else if(conv.get()=="RGB")
26                 fmt = RGB;
27         else if(conv.get()=="RGBA")
28                 fmt = RGBA;
29         else if(conv.get()=="BGR")
30                 fmt = BGR;
31         else if(conv.get()=="BGRA")
32                 fmt = BGRA;
33         else if(conv.get()=="LUMINANCE")
34                 fmt = LUMINANCE;
35         else if(conv.get()=="LUMINANCE_ALPHA")
36                 fmt = LUMINANCE_ALPHA;
37         else
38                 throw lexical_error(format("conversion of '%s' to PixelFormat", conv.get()));
39 }
40
41 PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
42 {
43         switch(pf)
44         {
45         case Graphics::COLOR_INDEX: return COLOR_INDEX;
46         case Graphics::LUMINANCE: return LUMINANCE;
47         case Graphics::LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
48         case Graphics::RGB: return RGB;
49         case Graphics::RGBA: return RGBA;
50         case Graphics::BGR: return BGR;
51         case Graphics::BGRA: return BGRA;
52         default: throw invalid_argument("pixelformat_from_graphics");
53         }
54 }
55
56 PixelFormat get_base_pixelformat(PixelFormat pf)
57 {
58         switch(pf)
59         {
60         case RGB8:
61         case RGB16F:
62         case RGB32F: return RGB;
63         case RGBA8:
64         case RGBA16F:
65         case RGBA32F: return RGBA;
66         case LUMINANCE8:
67         case LUMINANCE16F:
68         case LUMINANCE32F: return LUMINANCE;
69         case LUMINANCE_ALPHA8:
70         case LUMINANCE_ALPHA16F:
71         case LUMINANCE_ALPHA32F: return LUMINANCE_ALPHA;
72         default: return pf;
73         }
74 }
75
76 } // namespace GL
77 } // namespace Msp