]> git.tdb.fi Git - libs/gl.git/commitdiff
Add an srgb flag to pixelformat_from_image
authorMikko Rasa <tdb@tdb.fi>
Thu, 30 Sep 2021 11:28:14 +0000 (14:28 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 30 Sep 2021 11:52:00 +0000 (14:52 +0300)
This simplifies the pixel format handling in the texture classes.

source/core/pixelformat.cpp
source/core/pixelformat.h
source/core/texture1d.cpp
source/core/texture2d.cpp
source/core/texture3d.cpp
source/core/texturecube.cpp

index 270f27f7dc2e4fe9e608471c37ebf015830a3f9a..1ee0cd09dcf0458fe5d010e61aca1c2d6c8a8813 100644 (file)
@@ -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)
index 2f6038459bb7b345d610a1875cfa9e91a5cce38f..75651a8f872edfb93c6ab4849b54455f5867063f 100644 (file)
@@ -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<PixelComponents>(f&0xFF); }
index 3fd1ae0955e88c1d432219506fe960db9e4ecdd2..76ff946fc45959f58af87dfa93851c5c2f0a3327 100644 (file)
@@ -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());
 }
 
index 31d7016574b17ecdf3200d587f781d940914d21e..703b719a211f6390c78f35aacfe9f12a9c07701b 100644 (file)
@@ -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());
 }
 
index 03a64f1cf83abdf8b4de758f8f1c2a44075b74a8..b8e728cfa7ad3a9c64e13ee972996140c5eb864e 100644 (file)
@@ -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());
 }
 
index 2a15eb1bec3359a3f665e4d48c4f62392644b41f..3f8eabb3ed8a31b86d2ad236d34cf1095ce285f4 100644 (file)
@@ -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");