From Diane Delallée and Sukender, "1. Image.cpp

Failure to perform a vertical flip on S3TC-DXTC now simply leaves the original image instead of corrupting it.
Image.cpp was sometimes performing a "normal" (= for uncompressed images) vertical flip on S3TC-DXTC images, producing weird results.
Actually, code was trying a "DXTC vertical flip" and relied on the result to call a "normal vertical flip". But when the "DXTC v-flip" encounters an error, this is is not necessarily because the image is not S3TC (ex: unhandled image dimensions)!
So now the code simply does "if dxtc, then flip_dxtc; else flip_normal;".

Note from Robert Osfield, moved the isDXT function into the dxt_tool file and namespace.
This commit is contained in:
Robert Osfield
2013-05-28 11:25:13 +00:00
parent 81b6c82d9a
commit 39b9351153
3 changed files with 44 additions and 6 deletions

View File

@@ -1404,14 +1404,23 @@ void Image::flipVertical()
unsigned int rowSize = getRowSizeInBytes();
unsigned int rowStep = getRowStepInBytes();
const bool dxtc(dxtc_tool::isDXTC(_pixelFormat));
if (_mipmapData.empty())
{
// no mipmaps,
// so we can safely handle 3d textures
for(int r=0;r<_r;++r)
{
if (!dxtc_tool::VerticalFlip(_s,_t,_pixelFormat,data(0,0,r)))
if (dxtc)
{
if (!dxtc_tool::VerticalFlip(_s,_t,_pixelFormat,data(0,0,r)))
{
OSG_NOTICE << "Notice Image::flipVertical(): Vertical flip do not succeed" << std::endl;
}
}
else
{
if (isCompressed()) OSG_NOTICE << "Notice Image::flipVertical(): image is compressed but normal v-flip is used" << std::endl;
// its not a compressed image, so implement flip oursleves.
unsigned char* top = data(0,0,r);
unsigned char* bottom = top + (_t-1)*rowStep;
@@ -1422,8 +1431,16 @@ void Image::flipVertical()
}
else if (_r==1)
{
if (!dxtc_tool::VerticalFlip(_s,_t,_pixelFormat,_data))
if (dxtc)
{
if (!dxtc_tool::VerticalFlip(_s,_t,_pixelFormat,_data))
{
OSG_NOTICE << "Notice Image::flipVertical(): Vertical flip do not succeed" << std::endl;
}
}
else
{
if (isCompressed()) OSG_NOTICE << "Notice Image::flipVertical(): image is compressed but normal v-flip is used" << std::endl;
// its not a compressed image, so implement flip oursleves.
unsigned char* top = data(0,0,0);
unsigned char* bottom = top + (_t-1)*rowStep;
@@ -1441,7 +1458,14 @@ void Image::flipVertical()
t >>= 1;
if (s==0) s=1;
if (t==0) t=1;
if (!dxtc_tool::VerticalFlip(s,t,_pixelFormat,_data+_mipmapData[i]))
if (dxtc)
{
if (!dxtc_tool::VerticalFlip(s,t,_pixelFormat,_data+_mipmapData[i]))
{
OSG_NOTICE << "Notice Image::flipVertical(): Vertical flip do not succeed" << std::endl;
}
}
else
{
// its not a compressed image, so implement flip oursleves.
unsigned char* top = _data+_mipmapData[i];

View File

@@ -17,6 +17,7 @@ namespace dxtc_tool {
const size_t dxtc_pixels::BSIZE_ALPHA_DXT3 = 8;
const size_t dxtc_pixels::BSIZE_ALPHA_DXT5 = 8;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

View File

@@ -73,10 +73,9 @@
namespace dxtc_tool {
// C-like function wrappers
bool isDXTC(GLenum pixelFormat);
bool VerticalFlip(size_t Width, size_t Height, GLenum Format, void * pPixels);
bool CompressedImageTranslucent(size_t Width, size_t Height, GLenum Format, void * pPixels);
@@ -141,6 +140,20 @@ protected:
// C-Like Function Wrappers
//////////////////////////////////////////////////////////////////////
inline bool isDXTC(GLenum pixelFormat)
{
switch(pixelFormat)
{
case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT):
case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT):
return true;
default:
return false;
}
}
inline bool VerticalFlip(size_t Width, size_t Height, GLenum Format, void * pPixels) {
return (dxtc_pixels(Width, Height, Format, pPixels)).VFlip();
}