]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/pixelformat.cpp
Move swizzling modes to pixelformat.h
[libs/gl.git] / source / core / pixelformat.cpp
index 81379ef07062831a85fed2ee8fa1f925f34b450a..2ee5af7de6cf7f2d073fdeaa065a6218b4ac6c51 100644 (file)
@@ -98,6 +98,38 @@ PixelComponents components_from_graphics(Graphics::PixelFormat pf)
        }
 }
 
+PixelComponents swizzle_components(PixelComponents comp, ComponentSwizzle swiz)
+{
+       if(swiz==NO_SWIZZLE)
+               return comp;
+       else if(comp==RED && swiz==R_TO_LUMINANCE)
+               return LUMINANCE;
+       else if(comp==RG && swiz==RG_TO_LUMINANCE_ALPHA)
+               return LUMINANCE_ALPHA;
+       else if(comp==RGB && swiz==RGB_TO_BGR)
+               return BGR;
+       else if(comp==RGBA && swiz==RGB_TO_BGR)
+               return BGRA;
+       else
+               throw invalid_argument("swizzle_components");
+}
+
+PixelComponents unswizzle_components(PixelComponents comp, ComponentSwizzle swiz)
+{
+       if(swiz==NO_SWIZZLE)
+               return comp;
+       else if(comp==LUMINANCE && swiz==R_TO_LUMINANCE)
+               return RED;
+       else if(comp==LUMINANCE_ALPHA && swiz==RG_TO_LUMINANCE_ALPHA)
+               return RG;
+       else if(comp==BGR && swiz==RGB_TO_BGR)
+               return RGB;
+       else if(comp==BGRA && swiz==RGB_TO_BGR)
+               return RGBA;
+       else
+               throw invalid_argument("swizzle_components");
+}
+
 PixelFormat pixelformat_from_image(const Graphics::Image &image, bool srgb)
 {
        PixelComponents comp = components_from_graphics(image.get_format());