From: Mikko Rasa Date: Thu, 27 Oct 2016 07:06:16 +0000 (+0300) Subject: Move srgb handling to storage_pixelformat_from_graphics X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e079d5a878e83dc0baffcec66a57659c885cd593;p=libs%2Fgl.git Move srgb handling to storage_pixelformat_from_graphics --- diff --git a/source/pixelformat.cpp b/source/pixelformat.cpp index cd3bb2aa..679c6467 100644 --- a/source/pixelformat.cpp +++ b/source/pixelformat.cpp @@ -54,16 +54,22 @@ PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf) } } -PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat pf) +PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat pf, bool srgb) { + PixelFormat result; switch(pf) { case Graphics::RGBX: case Graphics::BGR: - case Graphics::BGRX: return RGB; - case Graphics::BGRA: return RGBA; - default: return pixelformat_from_graphics(pf); + 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); + else + return result; } PixelFormat get_base_pixelformat(PixelFormat pf) diff --git a/source/pixelformat.h b/source/pixelformat.h index 0fa6609a..7a562cc9 100644 --- a/source/pixelformat.h +++ b/source/pixelformat.h @@ -49,7 +49,7 @@ enum PixelFormat void operator>>(const LexicalConverter &, PixelFormat &); PixelFormat pixelformat_from_graphics(Graphics::PixelFormat); -PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat); +PixelFormat storage_pixelformat_from_graphics(Graphics::PixelFormat, bool = false); PixelFormat get_base_pixelformat(PixelFormat); PixelFormat get_srgb_pixelformat(PixelFormat); diff --git a/source/texture2d.cpp b/source/texture2d.cpp index 64ad124f..d435a356 100644 --- a/source/texture2d.cpp +++ b/source/texture2d.cpp @@ -118,12 +118,7 @@ void Texture2D::image(const Graphics::Image &img, bool srgb, bool from_buffer) unsigned h = img.get_height(); PixelFormat fmt = pixelformat_from_graphics(img.get_format()); if(width==0) - { - PixelFormat f = storage_pixelformat_from_graphics(img.get_format()); - if(srgb) - f = get_srgb_pixelformat(f); - storage(f, w, h); - } + storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, h); else if(w!=width || h!=height) throw incompatible_data("Texture2D::image"); diff --git a/source/texturecube.cpp b/source/texturecube.cpp index 24d02f40..576f1c71 100644 --- a/source/texturecube.cpp +++ b/source/texturecube.cpp @@ -86,10 +86,7 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool s if(w!=h) throw incompatible_data("TextureCube::image"); - PixelFormat f = storage_pixelformat_from_graphics(img.get_format()); - if(srgb) - f = get_srgb_pixelformat(f); - storage(f, w); + storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w); } else if(w!=size || h!=size) throw incompatible_data("TextureCube::image");