X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fpixelformat.cpp;h=6e7621882fef8eae4e595cd07e004a34b8e567bf;hp=81379ef07062831a85fed2ee8fa1f925f34b450a;hb=HEAD;hpb=160e9eea29bd10034733d59507fa1bcca36be401 diff --git a/source/core/pixelformat.cpp b/source/core/pixelformat.cpp index 81379ef0..6e762188 100644 --- a/source/core/pixelformat.cpp +++ b/source/core/pixelformat.cpp @@ -98,6 +98,46 @@ 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 if(comp==RGBA && swiz==RGBA_TO_RGB) + return RGB; + else if(comp==BGRA && swiz==RGBA_TO_RGB) + return BGR; + 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 if(comp==RGB && swiz==RGBA_TO_RGB) + return RGBA; + else if(comp==BGR && swiz==RGBA_TO_RGB) + return BGRA; + else + throw invalid_argument("swizzle_components"); +} + PixelFormat pixelformat_from_image(const Graphics::Image &image, bool srgb) { PixelComponents comp = components_from_graphics(image.get_format());