From 9144db4de6fb669fd459ad1076cd16b41d8d0618 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Sat, 22 Mar 2014 19:25:21 -0400 Subject: [PATCH] Actually pass block coordinates to shape selection function --- BPTCEncoder/include/BPTCCompressor.h | 8 ++++++-- BPTCEncoder/src/Compressor.cpp | 22 ++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/BPTCEncoder/include/BPTCCompressor.h b/BPTCEncoder/include/BPTCCompressor.h index bfa8b67..423f28e 100755 --- a/BPTCEncoder/include/BPTCCompressor.h +++ b/BPTCEncoder/include/BPTCCompressor.h @@ -120,8 +120,8 @@ namespace BPTCC { // A shape selection function is one that selects a BPTC shape from a given // block position and pixel array. - typedef ShapeSelection - (*ShapeSelectionFn)(uint32 x, uint32 y, const uint32 pixels[16]); + typedef ShapeSelection (*ShapeSelectionFn) + (uint32 x, uint32 y, const uint32 pixels[16], const void *userData); // Compression parameters used to control the BPTC compressor. Each of the // values has a default, so this is not strictly required to perform @@ -136,6 +136,9 @@ namespace BPTCC { // every block mode is still available. ShapeSelectionFn m_ShapeSelectionFn; + // The user data passed to the shape selection function. + void *m_ShapeSelectionUserData; + // The block modes that the compressor will consider during compression. // This variable is a bit mask of EBlockMode values and by default contains // every mode. This setting can be used to further restrict the search space @@ -144,6 +147,7 @@ namespace BPTCC { CompressionSettings() : m_ShapeSelectionFn(NULL) + , m_ShapeSelectionUserData(NULL) , m_BlockModes(static_cast(0xFF)) { } }; diff --git a/BPTCEncoder/src/Compressor.cpp b/BPTCEncoder/src/Compressor.cpp index d3477bb..777d1cb 100755 --- a/BPTCEncoder/src/Compressor.cpp +++ b/BPTCEncoder/src/Compressor.cpp @@ -1493,10 +1493,12 @@ std::ostream &operator<<(const BlockLogger &bl, const T &v) { // Function prototypes static void CompressBC7Block( + const uint32 x, const uint32 y, const uint32 block[16], uint8 *outBuf, const CompressionSettings = CompressionSettings() ); static void CompressBC7Block( + const uint32 x, const uint32 y, const uint32 block[16], uint8 *outBuf, const BlockLogger &logStream, const CompressionSettings = CompressionSettings() ); @@ -1594,7 +1596,7 @@ void Compress(const FasTC::CompressionJob &cj, CompressionSettings settings) { uint32 block[16]; GetBlock(i, j, cj.Width(), inPixels, block); - CompressBC7Block(block, outBuf, settings); + CompressBC7Block(i, j, block, outBuf, settings); #ifndef NDEBUG const uint8 *inBlock = reinterpret_cast(block); @@ -1669,7 +1671,7 @@ void CompressAtomic(FasTC::CompressionJobList &cjl) { uint32 y = cj->YStart() + 4 * (blockIdx / (cj->Width() / 4)); const uint32 *inPixels = reinterpret_cast(cj->InBuf()); GetBlock(x, y, cj->Width(), inPixels, block); - CompressBC7Block(block, out); + CompressBC7Block(x, y, block, out); } if(TestAndSet(cjl.GetFinishedFlag(jobIdx)) == 0) { @@ -1699,9 +1701,9 @@ void CompressAtomic(FasTC::CompressionJobList &cjl) { if(logStream) { uint64 blockIdx = cj.CoordsToBlockIdx(i, j); - CompressBC7Block(block, outBuf, BlockLogger(blockIdx, *logStream), settings); + CompressBC7Block(i, j, block, outBuf, BlockLogger(blockIdx, *logStream), settings); } else { - CompressBC7Block(block, outBuf, settings); + CompressBC7Block(i, j, block, outBuf, settings); } #ifndef NDEBUG @@ -1775,8 +1777,9 @@ static uint32 kAlphaModes = static_cast(eBlockMode_Six) | static_cast(eBlockMode_Seven); -static ShapeSelection BoxSelection(uint32 x, uint32 y, - const uint32 pixels[16]) { +static ShapeSelection BoxSelection( + uint32, uint32, const uint32 pixels[16], const void * +) { ShapeSelection result; @@ -1897,7 +1900,8 @@ static void CompressClusters(ShapeSelection selection, const uint32 pixels[16], } } -static void CompressBC7Block(const uint32 block[16], uint8 *outBuf, +static void CompressBC7Block(const uint32 x, const uint32 y, + const uint32 block[16], uint8 *outBuf, const CompressionSettings settings) { // All a single color? if(AllOneColor(block)) { @@ -1930,7 +1934,8 @@ static void CompressBC7Block(const uint32 block[16], uint8 *outBuf, } assert(selectionFn); - ShapeSelection selection = selectionFn(0, 0, block); + ShapeSelection selection = + selectionFn(x, y, block, settings.m_ShapeSelectionUserData); selection.m_SelectedModes &= settings.m_BlockModes; assert(selection.m_SelectedModes); CompressClusters(selection, block, outBuf, NULL, NULL); @@ -2029,6 +2034,7 @@ static void PrintStat(const BlockLogger &lgr, const char *stat, const T &v) { // Compress a single block but collect statistics as well... static void CompressBC7Block( + const uint32 x, const uint32 y, const uint32 block[16], uint8 *outBuf, const BlockLogger &logStream, const CompressionSettings settings ) {