diff --git a/ASTCEncoder/src/Decompressor.cpp b/ASTCEncoder/src/Decompressor.cpp index afcb0fb..5b2f1cf 100644 --- a/ASTCEncoder/src/Decompressor.cpp +++ b/ASTCEncoder/src/Decompressor.cpp @@ -605,7 +605,7 @@ namespace ASTCC { uint32 Ds = (1024 + (blockWidth/2)) / (blockWidth - 1); uint32 Dt = (1024 + (blockHeight/2)) / (blockHeight - 1); - for(uint32 plane = 0; plane < (params.m_bDualPlane? 2 : 1); plane++) + for(uint32 plane = 0; plane < (params.m_bDualPlane? 2U : 1U); plane++) for(uint32 t = 0; t < blockHeight; t++) for(uint32 s = 0; s < blockWidth; s++) { uint32 cs = Ds * s; diff --git a/BPTCEncoder/src/CompressNVTT.cpp b/BPTCEncoder/src/CompressNVTT.cpp index e07bda1..d7737e9 100644 --- a/BPTCEncoder/src/CompressNVTT.cpp +++ b/BPTCEncoder/src/CompressNVTT.cpp @@ -112,17 +112,16 @@ namespace BPTCC { uint8 *outBuf = cj.OutBuf() + cj.CoordsToBlockIdx(cj.XStart(), cj.YStart()) * kBlockSz; uint32 startX = cj.XStart(); - bool done = false; - - for(uint32 j = cj.YStart(); !done; j += 4) { - for(uint32 i = startX; !done && i < cj.Width(); i += 4) { + const uint32 endY = std::min(cj.YEnd(), cj.Height() - 4); + for(uint32 j = cj.YStart(); j <= endY; j += 4) { + const uint32 endX = j == cj.YEnd()? cj.XEnd() : cj.Width(); + for(uint32 i = startX; i < endX; i += 4) { Tile block(4, 4); GetBlock(i, j, cj.Width(), inPixels, block); AVPCL::compress(block, reinterpret_cast(outBuf), NULL); outBuf += kBlockSz; - done = i+4 >= cj.XEnd() && j+(i+4 == cj.Width()? 4 : 0) >= cj.YEnd(); } startX = 0; } @@ -173,9 +172,10 @@ namespace BPTCC { uint8 *outBuf = cj.OutBuf() + cj.CoordsToBlockIdx(cj.XStart(), cj.YStart()) * kBlockSz; uint32 startX = cj.XStart(); - bool done = false; - for(uint32 j = cj.YStart(); !done; j += 4) { - for(uint32 i = startX; !done && i < cj.Width(); i += 4) { + const uint32 endY = std::min(cj.YEnd(), cj.Height() - 4); + for(uint32 j = cj.YStart(); j <= endY; j += 4) { + const uint32 endX = j == cj.YEnd()? cj.XEnd() : cj.Width(); + for(uint32 i = startX; i < endX; i += 4) { Tile block(4, 4); GetBlock(i, j, cj.Width(), inPixels, block); @@ -197,7 +197,6 @@ namespace BPTCC { } outBuf += 16; - done = i+4 >= cj.XEnd() && j+(i+4 == cj.Width()? 4 : 0) >= cj.YEnd(); } startX = 0; diff --git a/BPTCEncoder/src/Compressor.cpp b/BPTCEncoder/src/Compressor.cpp index 0d2ff6b..2c8d928 100755 --- a/BPTCEncoder/src/Compressor.cpp +++ b/BPTCEncoder/src/Compressor.cpp @@ -1572,8 +1572,9 @@ void Compress(const FasTC::CompressionJob &cj, CompressionSettings settings) { const uint32 kBlockSz = GetBlockSize(FasTC::eCompressionFormat_BPTC); uint8 *outBuf = cj.OutBuf() + cj.CoordsToBlockIdx(cj.XStart(), cj.YStart()) * kBlockSz; + const uint32 endY = std::min(cj.YEnd(), cj.Height() - 4); uint32 startX = cj.XStart(); - for(uint32 j = cj.YStart(); j <= cj.YEnd(); j += 4) { + for(uint32 j = cj.YStart(); j <= endY; j += 4) { const uint32 endX = j == cj.YEnd()? cj.XEnd() : cj.Width(); for(uint32 i = startX; i < endX; i += 4) { diff --git a/BPTCEncoder/src/RGBAEndpoints.cpp b/BPTCEncoder/src/RGBAEndpoints.cpp index f5aa349..18041da 100755 --- a/BPTCEncoder/src/RGBAEndpoints.cpp +++ b/BPTCEncoder/src/RGBAEndpoints.cpp @@ -79,9 +79,10 @@ #include "CompressionMode.h" #include +#include +#include #include #include -#include #ifndef min template @@ -228,7 +229,7 @@ double RGBACluster::QuantizedError( ) const { // nBuckets should be a power of two. - const uint8 indexPrec = log2(nBuckets); + const uint8 indexPrec = static_cast(log(static_cast(nBuckets))/log(2.0f)); assert(!(nBuckets & (nBuckets - 1))); assert(indexPrec >= 2 && indexPrec <= 4); @@ -293,8 +294,8 @@ double RGBACluster::QuantizedError( const int32 j2 = static_cast(pct * static_cast(nBuckets-1) + 0.7); #else const float pct = ((pt - uqp1) * uqpdir) / uqplsq; - int32 j1 = floor(pct * static_cast(nBuckets-1)); - int32 j2 = ceil(pct * static_cast(nBuckets-1)); + int32 j1 = static_cast(floor(pct * static_cast(nBuckets-1))); + int32 j2 = static_cast(ceil(pct * static_cast(nBuckets-1))); j1 = std::min(std::max(0, j1), nBuckets - 1); j2 = std::min(j2, nBuckets - 1); #endif diff --git a/Base/include/Bits.h b/Base/include/Bits.h index e593b8e..58138d9 100644 --- a/Base/include/Bits.h +++ b/Base/include/Bits.h @@ -70,8 +70,8 @@ namespace FasTC { public: explicit Bits(IntType &v) : m_Bits(v) { } - bool operator[](uint32 bitPos) { - return (m_Bits >> bitPos) & 1; + uint8 operator[](uint32 bitPos) { + return static_cast((m_Bits >> bitPos) & 1); } IntType operator()(uint32 start, uint32 end) { diff --git a/Base/include/MatrixSquare.h b/Base/include/MatrixSquare.h index 3270981..c11fb33 100644 --- a/Base/include/MatrixSquare.h +++ b/Base/include/MatrixSquare.h @@ -55,7 +55,7 @@ namespace FasTC { int numIterations = 0; VectorBase b; - T norm = 1.0/sqrt(static_cast(N)); + T norm = static_cast(1.0)/sqrt(static_cast(N)); for(int i = 0; i < N; i++) b[i] = norm; diff --git a/Base/src/Image.cpp b/Base/src/Image.cpp index ea18b36..7240e7a 100644 --- a/Base/src/Image.cpp +++ b/Base/src/Image.cpp @@ -316,6 +316,11 @@ double Image::ComputeSSIM(Image *other) { const uint32 filterSz = 11; const double filterSigma = 1.5; + if(img1.GetWidth() < filterSz || img1.GetHeight() < filterSz || + img2.GetWidth() < filterSz || img2.GetHeight() < filterSz) { + return -1.0; + } + Image mu1 = FilterValid(img1, filterSz, filterSigma); Image mu2 = FilterValid(img2, filterSz, filterSigma); diff --git a/Base/test/TestPixel.cpp b/Base/test/TestPixel.cpp index 59c50da..71a3be3 100644 --- a/Base/test/TestPixel.cpp +++ b/Base/test/TestPixel.cpp @@ -82,7 +82,7 @@ TEST(Pixel, FourWideConstructor) { EXPECT_EQ(depth[i], 8); } - FasTC::Pixel q(static_cast(1 << 16), 6, -2, 5, 4); + FasTC::Pixel q(0, 6, -2, 5, 4); EXPECT_EQ(q.R(), 6); EXPECT_EQ(q.G(), -2); EXPECT_EQ(q.B(), 5); diff --git a/DXTEncoder/src/DXTCompressor.cpp b/DXTEncoder/src/DXTCompressor.cpp index c98bc80..2f1ccd1 100755 --- a/DXTEncoder/src/DXTCompressor.cpp +++ b/DXTEncoder/src/DXTCompressor.cpp @@ -14,6 +14,7 @@ // algorithms used in this code. #include "DXTCompressor.h" +#include #include #include #include @@ -45,8 +46,9 @@ namespace DXTC uint8 *outBuf = cj.OutBuf() + startBlock * kBlockSz; const uint32 *inPixels = reinterpret_cast(cj.InBuf()); + uint32 endY = std::min(cj.YEnd(), cj.Height() - 4); uint32 startX = cj.XStart(); - for(uint32 j = cj.YStart(); j <= cj.YEnd(); j += 4) { + for(uint32 j = cj.YStart(); j <= endY; j += 4) { const uint32 endX = j == cj.YEnd()? cj.XEnd() : cj.Width(); for(uint32 i = startX; i < endX; i += 4) { @@ -75,10 +77,11 @@ namespace DXTC uint8 *outBuf = cj.OutBuf() + startBlock * kBlockSz; const uint32 *inPixels = reinterpret_cast(cj.InBuf()); + uint32 endY = std::min(cj.YEnd(), cj.Height() - 4); uint32 startX = cj.XStart(); - bool done = false; - for(uint32 j = cj.YStart(); !done; j += 4) { - for(uint32 i = startX; !done && i < cj.Width(); i += 4) { + for(uint32 j = cj.YStart(); j <= endY; j += 4) { + const uint32 endX = j == cj.YEnd()? cj.XEnd() : cj.Width(); + for(uint32 i = startX; i < endX; i += 4) { const uint32 kOffset = j*cj.Width() + i; ExtractBlock(inPixels + kOffset, cj.Width(), block); @@ -89,8 +92,8 @@ namespace DXTC EmitWord(outBuf, ColorTo565(maxColor)); EmitWord(outBuf, ColorTo565(minColor)); EmitColorIndices(block, outBuf, minColor, maxColor); - done = i+4 >= cj.XEnd() && j+(i+4 == cj.Width()? 4 : 0) >= cj.YEnd(); } + startX = 0; } } diff --git a/ETCEncoder/src/Compressor.cpp b/ETCEncoder/src/Compressor.cpp index 90b4596..5afbb14 100644 --- a/ETCEncoder/src/Compressor.cpp +++ b/ETCEncoder/src/Compressor.cpp @@ -52,6 +52,7 @@ #include "rg_etc1.h" #include "ETCCompressor.h" +#include #include namespace ETCC { @@ -62,11 +63,13 @@ namespace ETCC { params.m_quality = rg_etc1::cLowQuality; rg_etc1::pack_etc1_block_init(); - const uint32 kBlockSz = GetBlockSize(FasTC::eCompressionFormat_ETC1); + uint32 kBlockSz = GetBlockSize(FasTC::eCompressionFormat_ETC1); const uint32 startBlock = cj.CoordsToBlockIdx(cj.XStart(), cj.YStart()); uint8 *outBuf = cj.OutBuf() + startBlock * kBlockSz; + + const uint32 endY = std::min(cj.YEnd(), cj.Height() - 4); uint32 startX = cj.XStart(); - for(uint32 j = cj.YStart(); j <= cj.YEnd(); j += 4) { + for(uint32 j = cj.YStart(); j <= endY; j += 4) { const uint32 endX = j == cj.YEnd()? cj.XEnd() : cj.Width(); for(uint32 i = startX; i < endX; i += 4) { diff --git a/IO/src/ImageFile.cpp b/IO/src/ImageFile.cpp index a8619fd..36298c1 100644 --- a/IO/src/ImageFile.cpp +++ b/IO/src/ImageFile.cpp @@ -131,7 +131,7 @@ ImageFile::~ImageFile() { } if(m_FileData) { - delete m_FileData; + delete [] m_FileData; m_FileData = NULL; } } @@ -144,7 +144,7 @@ bool ImageFile::Load() { } if(m_FileData) { - delete m_FileData; + delete [] m_FileData; m_FileData = NULL; } diff --git a/PVRTCEncoder/CMakeLists.txt b/PVRTCEncoder/CMakeLists.txt index 555c1dd..026222b 100644 --- a/PVRTCEncoder/CMakeLists.txt +++ b/PVRTCEncoder/CMakeLists.txt @@ -68,6 +68,8 @@ SET( SOURCES src/PVRTCImage.cpp ) +OPTION(DEBUG_PVRTC_DECODER "Output intermediate images during PVRTC decoding." OFF) + CONFIGURE_FILE( "config/PVRTCDefines.h.in" "include/PVRTCDefines.h" @@ -87,7 +89,9 @@ ADD_LIBRARY( PVRTCEncoder ) TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCBase ) -TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCIO ) +IF( DEBUG_PVRTC_DECODER ) + TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCIO ) +ENDIF( DEBUG_PVRTC_DECODER ) IF( PVRTEXLIB_FOUND ) TARGET_LINK_LIBRARIES( PVRTCEncoder ${PVRTEXLIB_LIBRARIES} ) diff --git a/PVRTCEncoder/config/PVRTCDefines.h.in b/PVRTCEncoder/config/PVRTCDefines.h.in index 9aabc8d..d5aaa5f 100644 --- a/PVRTCEncoder/config/PVRTCDefines.h.in +++ b/PVRTCEncoder/config/PVRTCDefines.h.in @@ -51,3 +51,4 @@ */ #cmakedefine PVRTEXLIB_FOUND +#cmakedefine DEBUG_PVRTC_DECODER diff --git a/PVRTCEncoder/src/PVRTCImage.cpp b/PVRTCEncoder/src/PVRTCImage.cpp index 2300176..a3c1f2d 100644 --- a/PVRTCEncoder/src/PVRTCImage.cpp +++ b/PVRTCEncoder/src/PVRTCImage.cpp @@ -66,7 +66,9 @@ #include "Pixel.h" using FasTC::Pixel; -#include "../../IO/include/ImageFile.h" +#ifdef DEBUG_PVRTC_DECODER +# include "../../IO/include/ImageFile.h" +#endif template inline T Clamp(const T &v, const T &a, const T &b) { @@ -540,6 +542,7 @@ uint32 Image::GetPixelIndex(int32 i, int32 j, EWrapMode wrapMode) const { return idx; } +#ifdef DEBUG_PVRTC_DECODER void Image::DebugOutput(const char *filename) const { uint32 *outPixels = new uint32[GetWidth() * GetHeight()]; const uint8 fullDepth[4] = { 8, 8, 8, 8 }; @@ -561,5 +564,8 @@ void Image::DebugOutput(const char *filename) const { ::ImageFile imgFile(debugFilename, eFileFormat_PNG, img); imgFile.Write(); } +#else +void Image::DebugOutput(const char *filename) const { } +#endif // DEBUG_PVRTC_DECODER } // namespace PVRTCC diff --git a/PVRTCEncoder/test/CMakeLists.txt b/PVRTCEncoder/test/CMakeLists.txt index a399ee8..74190e0 100644 --- a/PVRTCEncoder/test/CMakeLists.txt +++ b/PVRTCEncoder/test/CMakeLists.txt @@ -56,6 +56,11 @@ INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/PVRTCEncoder/src) INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/Base/include ) INCLUDE_DIRECTORIES(${FasTC_BINARY_DIR}/Base/include ) +IF( DEBUG_PVRTC_DECODER ) + INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/Core/include ) + INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/IO/include ) +ENDIF( DEBUG_PVRTC_DECODER ) + INCLUDE_DIRECTORIES(${FasTC_SOURCE_DIR}/GTest/include) SET(TESTS diff --git a/PVRTCEncoder/test/DecompTestPVR.cpp b/PVRTCEncoder/test/DecompTestPVR.cpp index af909d9..599ac0f 100644 --- a/PVRTCEncoder/test/DecompTestPVR.cpp +++ b/PVRTCEncoder/test/DecompTestPVR.cpp @@ -60,12 +60,10 @@ #include "TestUtils.h" -// #define OUTPUT_DEBUG_IMAGE - -#ifdef OUTPUT_DEBUG_IMAGE -# include "Core/include/Image.h" -# include "IO/include/ImageFile.h" -#endif // OUTPUT_DEBUG_IMAGE +#ifdef DEBUG_PVRTC_DECODER +# include "Image.h" +# include "ImageFile.h" +#endif // DEBUG_PVRTC_DECODER class ImageTester { public: @@ -88,7 +86,7 @@ class ImageTester { uint8 *outBuf = reinterpret_cast(outPixels); FasTC::DecompressionJob dcj(fmt, data, outBuf, w, h); -#ifdef OUTPUT_DEBUG_IMAGE +#ifdef DEBUG_PVRTC_DECODER PVRTCC::Decompress(dcj, PVRTCC::eWrapMode_Wrap, true); #else PVRTCC::Decompress(dcj, PVRTCC::eWrapMode_Wrap); @@ -106,10 +104,10 @@ class ImageTester { EXPECT_EQ(PixelPrinter(libPixels[i]), PixelPrinter(outPixels[i])); } -#ifdef OUTPUT_DEBUG_IMAGE +#ifdef DEBUG_PVRTC_DECODER char dbgfname[256]; snprintf(dbgfname, sizeof(dbgfname), "Debug%s.png", filename); - ::ImageFile imgFile(dbgfname, eFileFormat_PNG, ::Image(w, h, outPixels)); + ImageFile imgFile(dbgfname, eFileFormat_PNG, FasTC::Image<>(w, h, outPixels)); imgFile.Write(); #endif // OUTPUT_DEBUG_IMAGE