X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fpixelformat.cpp;h=2ee5af7de6cf7f2d073fdeaa065a6218b4ac6c51;hb=8e58fc4da8443cb67fe4cd70d6f68de2be73011d;hp=81379ef07062831a85fed2ee8fa1f925f34b450a;hpb=160e9eea29bd10034733d59507fa1bcca36be401;p=libs%2Fgl.git diff --git a/source/core/pixelformat.cpp b/source/core/pixelformat.cpp index 81379ef0..2ee5af7d 100644 --- a/source/core/pixelformat.cpp +++ b/source/core/pixelformat.cpp @@ -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());