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/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) {