From 39b9351153a0498037ab4b1285efba7d813bf52c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 28 May 2013 11:25:13 +0000 Subject: [PATCH] =?UTF-8?q?From=20Diane=20Delall=C3=A9e=20and=20Sukender,?= =?UTF-8?q?=20"1.=20Image.cpp=20Failure=20to=20perform=20a=20vertical=20fl?= =?UTF-8?q?ip=20on=20S3TC-DXTC=20now=20simply=20leaves=20the=20original=20?= =?UTF-8?q?image=20instead=20of=20corrupting=20it.=20Image.cpp=20was=20som?= =?UTF-8?q?etimes=20performing=20a=20"normal"=20(=3D=20for=20uncompressed?= =?UTF-8?q?=20images)=20vertical=20flip=20on=20S3TC-DXTC=20images,=20produ?= =?UTF-8?q?cing=20weird=20results.=20Actually,=20code=20was=20trying=20a?= =?UTF-8?q?=20"DXTC=20vertical=20flip"=20and=20relied=20on=20the=20result?= =?UTF-8?q?=20to=20call=20a=20"normal=20vertical=20flip".=20But=20when=20t?= =?UTF-8?q?he=20"DXTC=20v-flip"=20encounters=20an=20error,=20this=20is=20i?= =?UTF-8?q?s=20not=20necessarily=20because=20the=20image=20is=20not=20S3TC?= =?UTF-8?q?=20(ex:=20unhandled=20image=20dimensions)!=20So=20now=20the=20c?= =?UTF-8?q?ode=20simply=20does=20"if=20dxtc,=20then=20flip=5Fdxtc;=20else?= =?UTF-8?q?=20flip=5Fnormal;".?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note from Robert Osfield, moved the isDXT function into the dxt_tool file and namespace. --- src/osg/Image.cpp | 30 +++++++++++++++++++++++++++--- src/osg/dxtctool.cpp | 1 + src/osg/dxtctool.h | 19 ++++++++++++++++--- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index 92f1ad496..65f2ad3ab 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -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]; diff --git a/src/osg/dxtctool.cpp b/src/osg/dxtctool.cpp index 2e4628c8d..7e486972a 100644 --- a/src/osg/dxtctool.cpp +++ b/src/osg/dxtctool.cpp @@ -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 ////////////////////////////////////////////////////////////////////// diff --git a/src/osg/dxtctool.h b/src/osg/dxtctool.h index 9251064ac..5d5f252d5 100644 --- a/src/osg/dxtctool.h +++ b/src/osg/dxtctool.h @@ -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(); }