From: Mikko Rasa Date: Thu, 30 Sep 2021 11:28:14 +0000 (+0300) Subject: Add an srgb flag to pixelformat_from_image X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=8b3e51aeff0e22d29a34772c77b8647108f58677 Add an srgb flag to pixelformat_from_image This simplifies the pixel format handling in the texture classes. --- diff --git a/source/core/pixelformat.cpp b/source/core/pixelformat.cpp index 270f27f7..1ee0cd09 100644 --- a/source/core/pixelformat.cpp +++ b/source/core/pixelformat.cpp @@ -106,10 +106,10 @@ PixelComponents components_from_graphics(Graphics::PixelFormat pf) } } -PixelFormat pixelformat_from_image(const Graphics::Image &image) +PixelFormat pixelformat_from_image(const Graphics::Image &image, bool srgb) { PixelComponents comp = components_from_graphics(image.get_format()); - return make_pixelformat(comp, UNSIGNED_BYTE); + return make_pixelformat(comp, UNSIGNED_BYTE, srgb); } PixelFormat make_pixelformat(PixelComponents comp, DataType type, bool srgb) diff --git a/source/core/pixelformat.h b/source/core/pixelformat.h index 2f603845..75651a8f 100644 --- a/source/core/pixelformat.h +++ b/source/core/pixelformat.h @@ -86,7 +86,7 @@ void operator>>(const LexicalConverter &, PixelComponents &); void operator>>(const LexicalConverter &, PixelFormat &); PixelComponents components_from_graphics(Graphics::PixelFormat); -PixelFormat pixelformat_from_image(const Graphics::Image &); +PixelFormat pixelformat_from_image(const Graphics::Image &, bool = false); PixelFormat make_pixelformat(PixelComponents, DataType, bool = false); inline PixelComponents get_components(PixelFormat f) { return static_cast(f&0xFF); } diff --git a/source/core/texture1d.cpp b/source/core/texture1d.cpp index 3fd1ae09..76ff946f 100644 --- a/source/core/texture1d.cpp +++ b/source/core/texture1d.cpp @@ -85,10 +85,7 @@ void Texture1D::image(const Graphics::Image &img, unsigned lv) if(img.get_height()!=1) throw incompatible_data("Texture1D::image"); - unsigned w = img.get_width(); - PixelFormat fmt = pixelformat_from_image(img); - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv); - + storage(pixelformat_from_image(img, use_srgb_format), img.get_width(), lv); image(0, img.get_pixels()); } diff --git a/source/core/texture2d.cpp b/source/core/texture2d.cpp index 31d70165..703b719a 100644 --- a/source/core/texture2d.cpp +++ b/source/core/texture2d.cpp @@ -120,11 +120,7 @@ void Texture2D::image(const Graphics::Image &img, unsigned lv) void Texture2D::image(const Graphics::Image &img, unsigned lv, bool from_buffer) { - unsigned w = img.get_width(); - unsigned h = img.get_height(); - PixelFormat fmt = pixelformat_from_image(img); - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, lv); - + storage(pixelformat_from_image(img, use_srgb_format), img.get_width(), img.get_height(), lv); image(0, from_buffer ? 0 : img.get_pixels()); } diff --git a/source/core/texture3d.cpp b/source/core/texture3d.cpp index 03a64f1c..b8e728cf 100644 --- a/source/core/texture3d.cpp +++ b/source/core/texture3d.cpp @@ -108,9 +108,7 @@ void Texture3D::image(const Graphics::Image &img, unsigned lv) unsigned d = h/w; h = w; - PixelFormat fmt = pixelformat_from_image(img); - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, h, d, lv); - + storage(pixelformat_from_image(img, use_srgb_format), w, h, d, lv); image(0, img.get_pixels()); } diff --git a/source/core/texturecube.cpp b/source/core/texturecube.cpp index 2a15eb1b..3f8eabb3 100644 --- a/source/core/texturecube.cpp +++ b/source/core/texturecube.cpp @@ -126,9 +126,7 @@ void TextureCube::image(TextureCubeFace face, const Graphics::Image &img) if(w!=h) throw incompatible_data("TextureCube::image"); - PixelFormat fmt = pixelformat_from_image(img); - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w); - + storage(pixelformat_from_image(img, use_srgb_format), w); image(face, 0, img.get_pixels()); } @@ -141,9 +139,8 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv) throw incompatible_data("TextureCube::image"); h /= 6; - PixelFormat fmt = pixelformat_from_image(img); if(size==0) - storage(make_pixelformat(get_components(fmt), get_component_type(fmt), use_srgb_format), w, lv); + storage(pixelformat_from_image(img, use_srgb_format), w, lv); else if(w!=size || h!=size) throw incompatible_data("TextureCube::image");