Merge branch 'master' into DecompressASTC

This commit is contained in:
Pavel Krajcevski 2014-09-25 16:50:43 -04:00
commit c0d7607998
16 changed files with 65 additions and 39 deletions

View file

@ -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;

View file

@ -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<char *>(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;

View file

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

View file

@ -79,9 +79,10 @@
#include "CompressionMode.h"
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cfloat>
#ifndef min
template <typename T>
@ -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<uint8>(log(static_cast<float>(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<int32>(pct * static_cast<float>(nBuckets-1) + 0.7);
#else
const float pct = ((pt - uqp1) * uqpdir) / uqplsq;
int32 j1 = floor(pct * static_cast<float>(nBuckets-1));
int32 j2 = ceil(pct * static_cast<float>(nBuckets-1));
int32 j1 = static_cast<int32>(floor(pct * static_cast<float>(nBuckets-1)));
int32 j2 = static_cast<int32>(ceil(pct * static_cast<float>(nBuckets-1)));
j1 = std::min(std::max(0, j1), nBuckets - 1);
j2 = std::min(j2, nBuckets - 1);
#endif

View file

@ -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<uint8>((m_Bits >> bitPos) & 1);
}
IntType operator()(uint32 start, uint32 end) {

View file

@ -55,7 +55,7 @@ namespace FasTC {
int numIterations = 0;
VectorBase<T, N> b;
T norm = 1.0/sqrt(static_cast<T>(N));
T norm = static_cast<T>(1.0)/sqrt(static_cast<T>(N));
for(int i = 0; i < N; i++)
b[i] = norm;

View file

@ -316,6 +316,11 @@ double Image<PixelType>::ComputeSSIM(Image<PixelType> *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<IPixel> mu1 = FilterValid(img1, filterSz, filterSigma);
Image<IPixel> mu2 = FilterValid(img2, filterSz, filterSigma);

View file

@ -82,7 +82,7 @@ TEST(Pixel, FourWideConstructor) {
EXPECT_EQ(depth[i], 8);
}
FasTC::Pixel q(static_cast<uint16>(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);

View file

@ -14,6 +14,7 @@
// algorithms used in this code.
#include "DXTCompressor.h"
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <cstring>
@ -45,8 +46,9 @@ namespace DXTC
uint8 *outBuf = cj.OutBuf() + startBlock * kBlockSz;
const uint32 *inPixels = reinterpret_cast<const uint32 *>(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<const uint32 *>(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;
}
}

View file

@ -52,6 +52,7 @@
#include "rg_etc1.h"
#include "ETCCompressor.h"
#include <algorithm>
#include <cstring>
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) {

View file

@ -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;
}

View file

@ -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} )

View file

@ -51,3 +51,4 @@
*/
#cmakedefine PVRTEXLIB_FOUND
#cmakedefine DEBUG_PVRTC_DECODER

View file

@ -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 <typename T>
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

View file

@ -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

View file

@ -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<uint8 *>(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