Added automatic conversion of RGB to RGBA when doing REPLACE_ALPHA_WITH_LUMINANCE colour space conversion.

This commit is contained in:
Robert Osfield
2012-12-11 17:27:22 +00:00
parent d86849fc35
commit 68c1360c96

View File

@@ -636,7 +636,7 @@ struct ReplaceAlphaWithLuminanceOperator
inline void luminance(float&) const {}
inline void alpha(float&) const {}
inline void luminance_alpha(float& l,float& a) const { a= l; }
inline void luminance_alpha(float& l,float& a) const { a = l; }
inline void rgb(float&,float&,float&) const { }
inline void rgba(float& r,float& g,float& b,float& a) const { float l = (r+g+b)*0.3333333; a = l; }
};
@@ -660,12 +660,24 @@ osg::Image* colorSpaceConversion(ColorSpaceOperation op, osg::Image* image, cons
case (REPLACE_ALPHA_WITH_LUMINANCE):
{
OSG_NOTICE<<"doing conversion REPLACE_ALPHA_WITH_LUMINANCE"<<std::endl;
osg::modifyImage(image, ReplaceAlphaWithLuminanceOperator());
if (image->getPixelFormat()==GL_RGB || image->getPixelFormat()==GL_BGR)
{
osg::Image* newImage = new osg::Image;
newImage->allocateImage(image->s(), image->t(), image->r(), GL_RGBA, image->getDataType());
osg::copyImage(image, 0, 0, 0, image->s(), image->t(), image->r(),
newImage, 0, 0, 0, false);
osg::modifyImage(newImage, ReplaceAlphaWithLuminanceOperator());
return newImage;
}
else
{
osg::modifyImage(image, ReplaceAlphaWithLuminanceOperator());
}
return image;
}
case (REPLACE_RGB_WITH_LUMINANCE):
{
OSG_NOTICE<<"doing conversion REPLACE_ALPHA_WITH_LUMINANCE"<<std::endl;
OSG_NOTICE<<"doing conversion REPLACE_RGB_WITH_LUMINANCE"<<std::endl;
osg::Image* newImage = new osg::Image;
newImage->allocateImage(image->s(), image->t(), image->r(), GL_LUMINANCE, image->getDataType());
osg::copyImage(image, 0, 0, 0, image->s(), image->t(), image->r(),