-istream &operator>>(istream &in, PixelFormat &fmt)
-{
- string word;
-
- in>>word;
- if(word=="COLOR_INDEX")
- fmt=COLOR_INDEX;
- else if(word=="STENCIL_INDEX")
- fmt=STENCIL_INDEX;
- else if(word=="DEPTH_COMPONENT")
- fmt=DEPTH_COMPONENT;
- else if(word=="RED")
- fmt=RED;
- else if(word=="GREEN")
- fmt=GREEN;
- else if(word=="BLUE")
- fmt=BLUE;
- else if(word=="ALPHA")
- fmt=ALPHA;
- else if(word=="RGB")
- fmt=RGB;
- else if(word=="RGBA")
- fmt=RGBA;
- else if(word=="BGR")
- fmt=BGR;
- else if(word=="BGRA")
- fmt=BGRA;
- else if(word=="LUMINANCE")
- fmt=LUMINANCE;
- else if(word=="LUMINANCE_ALPHA")
- fmt=LUMINANCE_ALPHA;
+void operator>>(const LexicalConverter &conv, PixelFormat &fmt)
+{
+ if(conv.get()=="STENCIL_INDEX")
+ fmt = STENCIL_INDEX;
+ else if(conv.get()=="DEPTH_COMPONENT")
+ fmt = DEPTH_COMPONENT;
+ else if(conv.get()=="RGB")
+ fmt = RGB;
+ else if(conv.get()=="RGBA")
+ fmt = RGBA;
+ else if(conv.get()=="BGR")
+ fmt = BGR;
+ else if(conv.get()=="BGRA")
+ fmt = BGRA;
+ else if(conv.get()=="SRGB")
+ fmt = SRGB;
+ else if(conv.get()=="SRGB_ALPHA")
+ fmt = SRGB_ALPHA;
+ else if(conv.get()=="LUMINANCE")
+ fmt = LUMINANCE;
+ else if(conv.get()=="LUMINANCE_ALPHA")
+ fmt = LUMINANCE_ALPHA;
+ else if(conv.get()=="SLUMINANCE")
+ fmt = SLUMINANCE;
+ else if(conv.get()=="SLUMINANCE_ALPHA")
+ fmt = SLUMINANCE_ALPHA;
+ else
+ throw lexical_error(format("conversion of '%s' to PixelFormat", conv.get()));
+}
+
+PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf)
+{
+ switch(pf)
+ {
+ case Graphics::LUMINANCE: return LUMINANCE;
+ case Graphics::LUMINANCE_ALPHA: return LUMINANCE_ALPHA;
+ case Graphics::RGB: return RGB;
+ case Graphics::RGBX:
+ case Graphics::RGBA: return RGBA;
+ case Graphics::BGR: return BGR;
+ case Graphics::BGRX:
+ case Graphics::BGRA: return BGRA;
+ default: throw invalid_argument("pixelformat_from_graphics");
+ }
+}
+
+PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat pf, bool srgb)
+{
+ PixelFormat result;
+ switch(pf)
+ {
+ case Graphics::RGBX:
+ case Graphics::BGR:
+ case Graphics::BGRX: result = RGB; break;
+ case Graphics::BGRA: result = RGBA; break;
+ default: result = pixelformat_from_graphics(pf);
+ }
+
+ if(srgb)
+ return get_srgb_pixelformat(result);