]> git.tdb.fi Git - libs/gl.git/blob - source/pixelformat.cpp
Drop Id tags and copyright notices from files
[libs/gl.git] / source / pixelformat.cpp
1 #include "except.h"
2 #include "pixelformat.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GL {
8
9 istream &operator>>(istream &in, PixelFormat &fmt)
10 {
11         string word;
12
13         in>>word;
14         if(word=="COLOR_INDEX")
15                 fmt = COLOR_INDEX;
16         else if(word=="STENCIL_INDEX")
17                 fmt = STENCIL_INDEX;
18         else if(word=="DEPTH_COMPONENT")
19                 fmt = DEPTH_COMPONENT;
20         else if(word=="RED")
21                 fmt = RED;
22         else if(word=="GREEN")
23                 fmt = GREEN;
24         else if(word=="BLUE")
25                 fmt = BLUE;
26         else if(word=="ALPHA")
27                 fmt = ALPHA;
28         else if(word=="RGB")
29                 fmt = RGB;
30         else if(word=="RGBA")
31                 fmt = RGBA;
32         else if(word=="BGR")
33                 fmt = BGR;
34         else if(word=="BGRA")
35                 fmt = BGRA;
36         else if(word=="LUMINANCE")
37                 fmt = LUMINANCE;
38         else if(word=="LUMINANCE_ALPHA")
39                 fmt = LUMINANCE_ALPHA;
40         else
41                 in.setstate(ios_base::failbit);
42
43         return in;
44 }
45
46 PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
47 {
48         switch(pf)
49         {
50         case Graphics::COLOR_INDEX: return COLOR_INDEX;
51         case Graphics::LUMINANCE: return LUMINANCE;
52         case Graphics::LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
53         case Graphics::RGB: return RGB;
54         case Graphics::RGBA: return RGBA;
55         case Graphics::BGR: return BGR;
56         case Graphics::BGRA: return BGRA;
57         default: throw InvalidParameterValue("Unknown Graphics::PixelFormat");
58         }
59 }
60
61 PixelFormat get_base_pixelformat(PixelFormat pf)
62 {
63         switch(pf)
64         {
65         case RGB8:
66         case RGB16F:
67         case RGB32F: return RGB;
68         case RGBA8:
69         case RGBA16F:
70         case RGBA32F: return RGBA;
71         case LUMINANCE8:
72         case LUMINANCE16F:
73         case LUMINANCE32F: return LUMINANCE;
74         case LUMINANCE_ALPHA8:
75         case LUMINANCE_ALPHA16F:
76         case LUMINANCE_ALPHA32F: return LUMINANCE_ALPHA;
77         default: return pf;
78         }
79 }
80
81 } // namespace GL
82 } // namespace Msp