Implemented the osg::Image::isImagTranslucent function.

This commit is contained in:
Robert Osfield 2005-02-10 15:52:18 +00:00
parent 3ce382fd45
commit ec8624f185

View File

@ -835,56 +835,63 @@ void Image::ensureValidSizeForTexturing(GLint maxTextureSize)
} }
} }
template <typename T>
bool _findLowerAlphaValueInRow(unsigned int num, T* data,T value, unsigned int delta)
{
for(unsigned int i=0;i<num;++i)
{
if (*data<value) return true;
data += delta;
}
return false;
}
bool Image::isImageTranslucent() const bool Image::isImageTranslucent() const
{ {
unsigned int offset = 0;
unsigned int delta = 1;
if (getPixelFormat()==GL_LUMINANCE_ALPHA) switch(_pixelFormat)
{ {
return true; case(GL_ALPHA):
offset = 0;
delta = 1;
// unfinished code so commenting out right now... break;
// switch(type) case(GL_LUMINANCE_ALPHA):
// { offset = 1;
// case(GL_BYTE): delta = 2;
// { break;
// int rowSizeInBytes = getRowSizeInBytes(); case(GL_RGBA):
// int imageSizeInBytes = getImageSizeInBytes(); offset = 3;
// delta = 4;
// for (int r=0;r<_r,++r) break;
// { case(GL_BGRA):
// for (int t=0;t<int _t,++t) offset = 3;
// { delta = 4;
// char* ptr = _data+r*getRowSizeInBytes()+image*getImageSizeInBytes(); break;
// for (int s=0;s<_s,++s) default:
// { return false;
//
// }
// }
// }
// break
// }
// case(GL_UNSIGNED_BYTE): return 8*computeNumComponents(format);
//
// case(GL_SHORT):
// case(GL_UNSIGNED_SHORT): return 16*computeNumComponents(format);
//
// case(GL_INT):
// case(GL_UNSIGNED_INT):
// case(GL_FLOAT): return 32*computeNumComponents(format);
//
// default: return 0;
// }
} }
else if (getPixelFormat()==GL_RGBA)
for(int ir=0;ir<r();++ir)
{ {
return true; for(int it=0;it<t();++it)
{
unsigned char* d = data(0,it,ir);
switch(_dataType)
{
case(GL_BYTE): return _findLowerAlphaValueInRow(s(), (char*)d +offset, (char)127, delta);
case(GL_UNSIGNED_BYTE): return _findLowerAlphaValueInRow(s(), (unsigned char*)d + offset, (unsigned char)255, delta);
case(GL_SHORT): return _findLowerAlphaValueInRow(s(), (short*)d + offset, (short)32767, delta);
case(GL_UNSIGNED_SHORT): return _findLowerAlphaValueInRow(s(), (unsigned short*)d + offset, (unsigned short)65535, delta);
case(GL_INT): return _findLowerAlphaValueInRow(s(), (int*)d + offset, (int)2147483647, delta);
case(GL_UNSIGNED_INT): return _findLowerAlphaValueInRow(s(), (unsigned int*)d + offset, (unsigned int)4294967295, delta);
case(GL_FLOAT): return _findLowerAlphaValueInRow(s(), (float*)d + offset, 1.0f, delta);
}
}
} }
return false; return false;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////