mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2025-01-08 22:05:37 +00:00
Merge branch 'ModularizeBPTC' into DecompressASTC
This commit is contained in:
commit
9eb6eb8692
|
@ -48,7 +48,7 @@ INCLUDE_DIRECTORIES(${FasTC_BINARY_DIR}/BPTCEncoder/include)
|
||||||
|
|
||||||
IF(NOT "" STREQUAL "${AVPCLLIB_ROOT}")
|
IF(NOT "" STREQUAL "${AVPCLLIB_ROOT}")
|
||||||
INCLUDE_DIRECTORIES(${AVPCLLIB_INCLUDE_DIR})
|
INCLUDE_DIRECTORIES(${AVPCLLIB_INCLUDE_DIR})
|
||||||
SET(FOUND_NVTT_BC7_EXPORT TRUE)
|
SET(FOUND_NVTT_BPTC_EXPORT TRUE)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
INCLUDE(CheckCXXSourceRuns)
|
INCLUDE(CheckCXXSourceRuns)
|
||||||
|
@ -58,9 +58,11 @@ IF( NOT HAS_INLINE_ASSEMBLY AND NOT HAS_INLINE_ASSEMBLY_WITH_FLAGS )
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
# Check to see whether or not our compiler supports atomic operations
|
# Check to see whether or not our compiler supports atomic operations
|
||||||
IF( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" )
|
IF( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
|
||||||
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" )
|
||||||
SET( COMPILER_CLANG True )
|
SET( COMPILER_CLANG True )
|
||||||
ELSEIF( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" )
|
ELSEIF( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
|
||||||
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" )
|
||||||
SET( COMPILER_GNU True )
|
SET( COMPILER_GNU True )
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
@ -97,19 +99,20 @@ IF( HAS_MSVC_ATOMICS OR HAS_GCC_ATOMICS )
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
CONFIGURE_FILE(
|
CONFIGURE_FILE(
|
||||||
"config/BC7Config.h.in"
|
"config/BPTCConfig.h.in"
|
||||||
"include/BC7Config.h"
|
"include/BPTCConfig.h"
|
||||||
)
|
)
|
||||||
|
|
||||||
SET( HEADERS
|
SET( HEADERS
|
||||||
src/BC7CompressionMode.h
|
config/BPTCConfig.h.in
|
||||||
src/BitStream.h
|
include/BPTCCompressor.h
|
||||||
|
src/CompressionMode.h
|
||||||
src/RGBAEndpoints.h
|
src/RGBAEndpoints.h
|
||||||
src/ParallelStage.h
|
src/ParallelStage.h
|
||||||
)
|
)
|
||||||
|
|
||||||
SET( SOURCES
|
SET( SOURCES
|
||||||
src/BC7Compressor.cpp
|
src/Compressor.cpp
|
||||||
src/RGBAEndpoints.cpp
|
src/RGBAEndpoints.cpp
|
||||||
src/ParallelStage.cpp
|
src/ParallelStage.cpp
|
||||||
)
|
)
|
||||||
|
@ -133,12 +136,12 @@ IF( HAS_SSE_41 )
|
||||||
SET( HEADERS
|
SET( HEADERS
|
||||||
${HEADERS}
|
${HEADERS}
|
||||||
src/RGBAEndpointsSIMD.h
|
src/RGBAEndpointsSIMD.h
|
||||||
src/BC7CompressionModeSIMD.h
|
src/CompressionModeSIMD.h
|
||||||
)
|
)
|
||||||
|
|
||||||
SET( SOURCES
|
SET( SOURCES
|
||||||
${SOURCES}
|
${SOURCES}
|
||||||
src/BC7CompressorSIMD.cpp
|
src/CompressorSIMD.cpp
|
||||||
src/RGBAEndpointsSIMD.cpp
|
src/RGBAEndpointsSIMD.cpp
|
||||||
)
|
)
|
||||||
ENDIF( HAS_SSE_41 )
|
ENDIF( HAS_SSE_41 )
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
/* FasTC
|
|
||||||
* Copyright (c) 2012 University of North Carolina at Chapel Hill. All rights reserved.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software and its documentation for educational,
|
|
||||||
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
|
|
||||||
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
|
|
||||||
* in all copies.
|
|
||||||
*
|
|
||||||
* Permission to incorporate this software into commercial products may be obtained by contacting the
|
|
||||||
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
|
||||||
*
|
|
||||||
* This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill.
|
|
||||||
* The software program and documentation are supplied "as is," without any accompanying services from the
|
|
||||||
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
|
|
||||||
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
|
|
||||||
* end-user understands that the program was developed for research purposes and is advised not to rely
|
|
||||||
* exclusively on the program for any reason.
|
|
||||||
*
|
|
||||||
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS BE LIABLE TO ANY PARTY FOR
|
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
|
|
||||||
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
|
||||||
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
|
||||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
|
||||||
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
|
|
||||||
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
|
||||||
*
|
|
||||||
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
|
||||||
*
|
|
||||||
* The authors may be contacted via:
|
|
||||||
*
|
|
||||||
* Pavel Krajcevski
|
|
||||||
* Dept of Computer Science
|
|
||||||
* 201 S Columbia St
|
|
||||||
* Frederick P. Brooks, Jr. Computer Science Bldg
|
|
||||||
* Chapel Hill, NC 27599-3175
|
|
||||||
* USA
|
|
||||||
*
|
|
||||||
* <http://gamma.cs.unc.edu/FasTC/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
// BC7Config.h.in -- This file contains variables that are introduced
|
|
||||||
// explicitly by the CMake build process.
|
|
||||||
|
|
||||||
// Do we have the proper popcnt instruction defined?
|
|
||||||
#cmakedefine NO_INLINE_ASSEMBLY
|
|
||||||
#cmakedefine HAS_SSE_POPCNT
|
|
||||||
#cmakedefine HAS_SSE_41
|
|
||||||
|
|
||||||
#cmakedefine HAS_ATOMICS
|
|
||||||
#cmakedefine HAS_GCC_ATOMICS
|
|
||||||
#cmakedefine HAS_MSVC_ATOMICS
|
|
||||||
|
|
||||||
#cmakedefine FOUND_NVTT_BC7_EXPORT
|
|
65
BPTCEncoder/config/BPTCConfig.h.in
Normal file
65
BPTCEncoder/config/BPTCConfig.h.in
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/* FasTC
|
||||||
|
* Copyright (c) 2014 University of North Carolina at Chapel Hill.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
|
* documentation for educational, research, and non-profit purposes, without
|
||||||
|
* fee, and without a written agreement is hereby granted, provided that the
|
||||||
|
* above copyright notice, this paragraph, and the following four paragraphs
|
||||||
|
* appear in all copies.
|
||||||
|
*
|
||||||
|
* Permission to incorporate this software into commercial products may be
|
||||||
|
* obtained by contacting the authors or the Office of Technology Development
|
||||||
|
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
||||||
|
*
|
||||||
|
* This software program and documentation are copyrighted by the University of
|
||||||
|
* North Carolina at Chapel Hill. The software program and documentation are
|
||||||
|
* supplied "as is," without any accompanying services from the University of
|
||||||
|
* North Carolina at Chapel Hill or the authors. The University of North
|
||||||
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
||||||
|
* the program will be uninterrupted or error-free. The end-user understands
|
||||||
|
* that the program was developed for research purposes and is advised not to
|
||||||
|
* rely exclusively on the program for any reason.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
||||||
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
||||||
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
|
||||||
|
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
|
*
|
||||||
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
||||||
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
||||||
|
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
|
||||||
|
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
|
||||||
|
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
*
|
||||||
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
||||||
|
*
|
||||||
|
* The authors may be contacted via:
|
||||||
|
*
|
||||||
|
* Pavel Krajcevski
|
||||||
|
* Dept of Computer Science
|
||||||
|
* 201 S Columbia St
|
||||||
|
* Frederick P. Brooks, Jr. Computer Science Bldg
|
||||||
|
* Chapel Hill, NC 27599-3175
|
||||||
|
* USA
|
||||||
|
*
|
||||||
|
* <http://gamma.cs.unc.edu/FasTC/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
// BPTCConfig.h.in -- This file contains variables that are introduced
|
||||||
|
// explicitly by the CMake build process.
|
||||||
|
|
||||||
|
// Do we have the proper popcnt instruction defined?
|
||||||
|
#cmakedefine NO_INLINE_ASSEMBLY
|
||||||
|
#cmakedefine HAS_SSE_POPCNT
|
||||||
|
#cmakedefine HAS_SSE_41
|
||||||
|
|
||||||
|
#cmakedefine HAS_ATOMICS
|
||||||
|
#cmakedefine HAS_GCC_ATOMICS
|
||||||
|
#cmakedefine HAS_MSVC_ATOMICS
|
||||||
|
|
||||||
|
#cmakedefine FOUND_NVTT_BC7_EXPORT
|
|
@ -1,5 +1,5 @@
|
||||||
/* FasTC
|
/* FasTC
|
||||||
* Copyright (c) 2012 University of North Carolina at Chapel Hill.
|
* Copyright (c) 2014 University of North Carolina at Chapel Hill.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software and its
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
|
@ -73,15 +73,15 @@
|
||||||
//
|
//
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef BPTCENCODER_INCLUDE_BC7COMPRESSOR_H_
|
#ifndef BPTCENCODER_INCLUDE_BPTCCOMPRESSOR_H_
|
||||||
#define BPTCENCODER_INCLUDE_BC7COMPRESSOR_H_
|
#define BPTCENCODER_INCLUDE_BPTCCOMPRESSOR_H_
|
||||||
|
|
||||||
#include "BC7Config.h"
|
#include "BPTCConfig.h"
|
||||||
#include "CompressionJob.h"
|
#include "CompressionJob.h"
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
namespace BC7C {
|
namespace BPTCC {
|
||||||
// This is the error metric that is applied to our error measurement algorithm
|
// This is the error metric that is applied to our error measurement algorithm
|
||||||
// in order to bias calculation towards results that are more in-line with
|
// in order to bias calculation towards results that are more in-line with
|
||||||
// how the Human Visual System works. Uniform error means that each color
|
// how the Human Visual System works. Uniform error means that each color
|
||||||
|
@ -112,7 +112,7 @@ namespace BC7C {
|
||||||
void SetQualityLevel(int q);
|
void SetQualityLevel(int q);
|
||||||
int GetQualityLevel();
|
int GetQualityLevel();
|
||||||
|
|
||||||
// Compress the image given as RGBA data to BC7 format. Width and Height are
|
// Compress the image given as RGBA data to BPTC format. Width and Height are
|
||||||
// the dimensions of the image in pixels.
|
// the dimensions of the image in pixels.
|
||||||
void Compress(const FasTC::CompressionJob &);
|
void Compress(const FasTC::CompressionJob &);
|
||||||
|
|
||||||
|
@ -123,10 +123,10 @@ namespace BC7C {
|
||||||
void CompressWithStats(const FasTC::CompressionJob &, std::ostream *logStream);
|
void CompressWithStats(const FasTC::CompressionJob &, std::ostream *logStream);
|
||||||
|
|
||||||
#ifdef HAS_SSE_41
|
#ifdef HAS_SSE_41
|
||||||
// Compress the image given as RGBA data to BC7 format using an algorithm
|
// Compress the image given as RGBA data to BPTC format using an algorithm
|
||||||
// optimized for SIMD enabled platforms. Width and Height are the dimensions
|
// optimized for SIMD enabled platforms. Width and Height are the dimensions
|
||||||
// of the image in pixels.
|
// of the image in pixels.
|
||||||
void CompressImageBC7SIMD(const unsigned char* inBuf, unsigned char* outBuf,
|
void CompressImageBPTCSIMD(const unsigned char* inBuf, unsigned char* outBuf,
|
||||||
unsigned int width, unsigned int height);
|
unsigned int width, unsigned int height);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ namespace BC7C {
|
||||||
void CompressAtomic(FasTC::CompressionJobList &);
|
void CompressAtomic(FasTC::CompressionJobList &);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FOUND_NVTT_BC7_EXPORT
|
#ifdef FOUND_NVTT_BPTC_EXPORT
|
||||||
// These functions take the same arguments as Compress and CompressWithStats,
|
// These functions take the same arguments as Compress and CompressWithStats,
|
||||||
// but they use the NVTT compressor if it was supplied to CMake.
|
// but they use the NVTT compressor if it was supplied to CMake.
|
||||||
void CompressNVTT(const FasTC::CompressionJob &);
|
void CompressNVTT(const FasTC::CompressionJob &);
|
||||||
|
@ -146,9 +146,9 @@ namespace BC7C {
|
||||||
std::ostream *logStream);
|
std::ostream *logStream);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Decompress the image given as BC7 data to R8G8B8A8 format. Width and Height
|
// Decompress the image given as BPTC data to R8G8B8A8 format. Width and Height
|
||||||
// are the dimensions of the image in pixels.
|
// are the dimensions of the image in pixels.
|
||||||
void Decompress(const FasTC::DecompressionJob &);
|
void Decompress(const FasTC::DecompressionJob &);
|
||||||
} // namespace BC7C
|
} // namespace BPTCC
|
||||||
|
|
||||||
#endif // BPTCENCODER_INCLUDE_BC7COMPRESSOR_H_
|
#endif // BPTCENCODER_INCLUDE_BPTCCOMPRESSOR_H_
|
|
@ -1,5 +1,5 @@
|
||||||
/* FasTC
|
/* FasTC
|
||||||
* Copyright (c) 2012 University of North Carolina at Chapel Hill.
|
* Copyright (c) 2014 University of North Carolina at Chapel Hill.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software and its
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
|
@ -73,13 +73,18 @@
|
||||||
//
|
//
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef BPTCENCODER_SRC_BC7COMPRESSIONMODE_H_
|
#ifndef BPTCENCODER_SRC_BPTCCOMPRESSIONMODE_H_
|
||||||
#define BPTCENCODER_SRC_BC7COMPRESSIONMODE_H_
|
#define BPTCENCODER_SRC_BPTCCOMPRESSIONMODE_H_
|
||||||
|
|
||||||
#include "RGBAEndpoints.h"
|
#include "RGBAEndpoints.h"
|
||||||
|
|
||||||
// Forward Declarations
|
namespace FasTC {
|
||||||
class BitStream;
|
class BitStream;
|
||||||
|
} // namespace FasTC
|
||||||
|
|
||||||
|
namespace BPTCC {
|
||||||
|
|
||||||
|
// Forward Declarations
|
||||||
struct VisitedState;
|
struct VisitedState;
|
||||||
const int kMaxEndpoints = 3;
|
const int kMaxEndpoints = 3;
|
||||||
|
|
||||||
|
@ -90,7 +95,7 @@ static const int kPBits[4][2] = {
|
||||||
{ 1, 1 }
|
{ 1, 1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
class BC7CompressionMode {
|
class CompressionMode {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -100,17 +105,41 @@ class BC7CompressionMode {
|
||||||
// This initializes the compression variables used in order to compress a list
|
// This initializes the compression variables used in order to compress a list
|
||||||
// of clusters. We can increase the speed a tad by specifying whether or not
|
// of clusters. We can increase the speed a tad by specifying whether or not
|
||||||
// the block is opaque or not.
|
// the block is opaque or not.
|
||||||
explicit BC7CompressionMode(int mode, bool opaque = true)
|
explicit CompressionMode(int mode, bool opaque = true)
|
||||||
: m_IsOpaque(opaque)
|
: m_IsOpaque(opaque)
|
||||||
, m_Attributes(&(kModeAttributes[mode]))
|
, m_Attributes(&(kModeAttributes[mode]))
|
||||||
, m_RotateMode(0)
|
, m_RotateMode(0)
|
||||||
, m_IndexMode(0)
|
, m_IndexMode(0)
|
||||||
{ }
|
{ }
|
||||||
~BC7CompressionMode() { }
|
~CompressionMode() { }
|
||||||
|
|
||||||
|
// These are all of the parameters required to define the data in a compressed
|
||||||
|
// BPTC block. The mode determines how these parameters will be translated
|
||||||
|
// into actual bits.
|
||||||
|
struct Params {
|
||||||
|
const uint16 m_ShapeIdx;
|
||||||
|
RGBAVector m_P1[kMaxNumSubsets], m_P2[kMaxNumSubsets];
|
||||||
|
uint8 m_Indices[kMaxNumSubsets][kMaxNumDataPoints];
|
||||||
|
uint8 m_AlphaIndices[kMaxNumDataPoints];
|
||||||
|
uint8 m_PbitCombo[kMaxNumSubsets];
|
||||||
|
int8 m_RotationMode, m_IndexMode;
|
||||||
|
explicit Params(uint32 shape)
|
||||||
|
: m_RotationMode(-1), m_IndexMode(-1), m_ShapeIdx(shape) {
|
||||||
|
memset(m_Indices, 0xFF, sizeof(m_Indices));
|
||||||
|
memset(m_AlphaIndices, 0xFF, sizeof(m_AlphaIndices));
|
||||||
|
memset(m_PbitCombo, 0xFF, sizeof(m_PbitCombo));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// This outputs the parameters to the given bitstream based on the current
|
||||||
|
// compression mode. The first argument is not const because the mode and
|
||||||
|
// the value of the first index determines whether or not the indices need to
|
||||||
|
// be swapped. The final output bits will always be a valid BPTC block.
|
||||||
|
void Pack(Params ¶ms, FasTC::BitStream &stream) const;
|
||||||
|
|
||||||
// This function compresses a group of clusters into the passed bitstream. The
|
// This function compresses a group of clusters into the passed bitstream. The
|
||||||
// size of the clusters array is determined by the BC7 compression mode.
|
// size of the clusters array is determined by the BC7 compression mode.
|
||||||
double Compress(BitStream &stream,
|
double Compress(FasTC::BitStream &stream,
|
||||||
const int shapeIdx, const RGBACluster *clusters);
|
const int shapeIdx, const RGBACluster *clusters);
|
||||||
|
|
||||||
// This switch controls the quality of the simulated annealing optimizer. We
|
// This switch controls the quality of the simulated annealing optimizer. We
|
||||||
|
@ -171,7 +200,7 @@ class BC7CompressionMode {
|
||||||
}
|
}
|
||||||
int GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
|
int GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
|
||||||
|
|
||||||
int GetNumberOfBitsPerIndex(int indexMode = -1) const {
|
int GetNumberOfBitsPerIndex(int8 indexMode = -1) const {
|
||||||
if(indexMode < 0) indexMode = m_IndexMode;
|
if(indexMode < 0) indexMode = m_IndexMode;
|
||||||
if(indexMode == 0)
|
if(indexMode == 0)
|
||||||
return m_Attributes->numBitsPerIndex;
|
return m_Attributes->numBitsPerIndex;
|
||||||
|
@ -179,7 +208,7 @@ class BC7CompressionMode {
|
||||||
return m_Attributes->numBitsPerAlpha;
|
return m_Attributes->numBitsPerAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetNumberOfBitsPerAlpha(int indexMode = -1) const {
|
int GetNumberOfBitsPerAlpha(int8 indexMode = -1) const {
|
||||||
if(indexMode < 0) indexMode = m_IndexMode;
|
if(indexMode < 0) indexMode = m_IndexMode;
|
||||||
if(indexMode == 0)
|
if(indexMode == 0)
|
||||||
return m_Attributes->numBitsPerAlpha;
|
return m_Attributes->numBitsPerAlpha;
|
||||||
|
@ -195,7 +224,7 @@ class BC7CompressionMode {
|
||||||
|
|
||||||
// This returns the proper error metric even if we have rotation bits set
|
// This returns the proper error metric even if we have rotation bits set
|
||||||
RGBAVector GetErrorMetric() const {
|
RGBAVector GetErrorMetric() const {
|
||||||
const float *w = BC7C::GetErrorMetric();
|
const float *w = BPTCC::GetErrorMetric();
|
||||||
switch(GetRotationMode()) {
|
switch(GetRotationMode()) {
|
||||||
default:
|
default:
|
||||||
case 0: return RGBAVector(w[0], w[1], w[2], w[3]);
|
case 0: return RGBAVector(w[0], w[1], w[2], w[3]);
|
||||||
|
@ -256,8 +285,8 @@ class BC7CompressionMode {
|
||||||
double OptimizeEndpointsForCluster(
|
double OptimizeEndpointsForCluster(
|
||||||
const RGBACluster &cluster,
|
const RGBACluster &cluster,
|
||||||
RGBAVector &p1, RGBAVector &p2,
|
RGBAVector &p1, RGBAVector &p2,
|
||||||
int *bestIndices,
|
uint8 *bestIndices,
|
||||||
int &bestPbitCombo
|
uint8 &bestPbitCombo
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
// This function performs the heuristic to choose the "best" neighboring
|
// This function performs the heuristic to choose the "best" neighboring
|
||||||
|
@ -285,28 +314,29 @@ class BC7CompressionMode {
|
||||||
// then we choose the best p-bit combo and return it as well.
|
// then we choose the best p-bit combo and return it as well.
|
||||||
double CompressSingleColor(const RGBAVector &p,
|
double CompressSingleColor(const RGBAVector &p,
|
||||||
RGBAVector &p1, RGBAVector &p2,
|
RGBAVector &p1, RGBAVector &p2,
|
||||||
int &bestPbitCombo) const;
|
uint8 &bestPbitCombo) const;
|
||||||
|
|
||||||
// Compress the cluster using a generalized cluster fit. This figures out the
|
// Compress the cluster using a generalized cluster fit. This figures out the
|
||||||
// proper endpoints assuming that we have no alpha.
|
// proper endpoints assuming that we have no alpha.
|
||||||
double CompressCluster(const RGBACluster &cluster,
|
double CompressCluster(const RGBACluster &cluster,
|
||||||
RGBAVector &p1, RGBAVector &p2,
|
RGBAVector &p1, RGBAVector &p2,
|
||||||
int *bestIndices, int &bestPbitCombo) const;
|
uint8 *bestIndices, uint8 &bestPbitCombo) const;
|
||||||
|
|
||||||
// Compress the non-opaque cluster using a generalized cluster fit, and place
|
// Compress the non-opaque cluster using a generalized cluster fit, and place
|
||||||
// the endpoints within p1 and p2. The color indices and alpha indices are
|
// the endpoints within p1 and p2. The color indices and alpha indices are
|
||||||
// computed as well.
|
// computed as well.
|
||||||
double CompressCluster(const RGBACluster &cluster,
|
double CompressCluster(const RGBACluster &cluster,
|
||||||
RGBAVector &p1, RGBAVector &p2,
|
RGBAVector &p1, RGBAVector &p2,
|
||||||
int *bestIndices, int *alphaIndices) const;
|
uint8 *bestIndices, uint8 *alphaIndices) const;
|
||||||
|
|
||||||
// This function takes two endpoints in the continuous domain (as floats) and
|
// This function takes two endpoints in the continuous domain (as floats) and
|
||||||
// clamps them to the nearest grid points based on the compression mode (and
|
// clamps them to the nearest grid points based on the compression mode (and
|
||||||
// possible pbit values)
|
// possible pbit values)
|
||||||
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2,
|
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2,
|
||||||
int &bestPBitCombo) const;
|
uint8 &bestPBitCombo) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const uint32 kBC7InterpolationValues[4][16][2];
|
extern const uint32 kInterpolationValues[4][16][2];
|
||||||
|
|
||||||
#endif // BPTCENCODER_SRC_BC7COMPRESSIONMODE_H_
|
} // namespace BPTCC {
|
||||||
|
#endif // BPTCENCODER_SRC_BPTCCOMPRESSIONMODE_H_
|
|
@ -73,13 +73,16 @@
|
||||||
//
|
//
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "BC7Compressor.h"
|
#include "BPTCCompressor.h"
|
||||||
#include "BC7CompressionMode.h"
|
#include "CompressionMode.h"
|
||||||
|
|
||||||
#include "TexCompTypes.h"
|
#include "TexCompTypes.h"
|
||||||
#include "BCLookupTables.h"
|
#include "BCLookupTables.h"
|
||||||
#include "RGBAEndpoints.h"
|
#include "RGBAEndpoints.h"
|
||||||
|
|
||||||
#include "BitStream.h"
|
#include "BitStream.h"
|
||||||
|
using FasTC::BitStream;
|
||||||
|
using FasTC::BitStreamReadOnly;
|
||||||
|
|
||||||
#ifdef HAS_MSVC_ATOMICS
|
#ifdef HAS_MSVC_ATOMICS
|
||||||
# include "Windows.h"
|
# include "Windows.h"
|
||||||
|
@ -302,7 +305,9 @@ static void insert(T* buf, int bufSz, T newVal, int idx = 0) {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static inline void swap(T &a, T &b) { T t = a; a = b; b = t; }
|
static inline void swap(T &a, T &b) { T t = a; a = b; b = t; }
|
||||||
|
|
||||||
const uint32 kBC7InterpolationValues[4][16][2] = {
|
namespace BPTCC {
|
||||||
|
|
||||||
|
const uint32 kInterpolationValues[4][16][2] = {
|
||||||
{ {64, 0}, {33, 31}, {0, 64}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
|
{ {64, 0}, {33, 31}, {0, 64}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
|
||||||
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} },
|
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} },
|
||||||
{ {64, 0}, {43, 21}, {21, 43}, {0, 64}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
|
{ {64, 0}, {43, 21}, {21, 43}, {0, 64}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
|
||||||
|
@ -313,45 +318,45 @@ const uint32 kBC7InterpolationValues[4][16][2] = {
|
||||||
{30, 34}, {26, 38}, {21, 43}, {17, 47}, {13, 51}, {9, 55}, {4, 60}, {0, 64}}
|
{30, 34}, {26, 38}, {21, 43}, {17, 47}, {13, 51}, {9, 55}, {4, 60}, {0, 64}}
|
||||||
};
|
};
|
||||||
|
|
||||||
int BC7CompressionMode::MaxAnnealingIterations = 50; // This is a setting.
|
int CompressionMode::MaxAnnealingIterations = 50; // This is a setting.
|
||||||
|
|
||||||
BC7CompressionMode::Attributes
|
CompressionMode::Attributes
|
||||||
BC7CompressionMode::kModeAttributes[kNumModes] = {
|
CompressionMode::kModeAttributes[kNumModes] = {
|
||||||
// Mode 0
|
// Mode 0
|
||||||
{ 0, 4, 3, 3, 0, 4, 0,
|
{ 0, 4, 3, 3, 0, 4, 0,
|
||||||
false, false, BC7CompressionMode::ePBitType_NotShared },
|
false, false, CompressionMode::ePBitType_NotShared },
|
||||||
|
|
||||||
// Mode 1
|
// Mode 1
|
||||||
{ 1, 6, 2, 3, 0, 6, 0,
|
{ 1, 6, 2, 3, 0, 6, 0,
|
||||||
false, false, BC7CompressionMode::ePBitType_Shared },
|
false, false, CompressionMode::ePBitType_Shared },
|
||||||
|
|
||||||
// Mode 2
|
// Mode 2
|
||||||
{ 2, 6, 3, 2, 0, 5, 0,
|
{ 2, 6, 3, 2, 0, 5, 0,
|
||||||
false, false, BC7CompressionMode::ePBitType_None },
|
false, false, CompressionMode::ePBitType_None },
|
||||||
|
|
||||||
// Mode 3
|
// Mode 3
|
||||||
{ 3, 6, 2, 2, 0, 7, 0,
|
{ 3, 6, 2, 2, 0, 7, 0,
|
||||||
false, false, BC7CompressionMode::ePBitType_NotShared },
|
false, false, CompressionMode::ePBitType_NotShared },
|
||||||
|
|
||||||
// Mode 4
|
// Mode 4
|
||||||
{ 4, 0, 1, 2, 3, 5, 6,
|
{ 4, 0, 1, 2, 3, 5, 6,
|
||||||
true, true, BC7CompressionMode::ePBitType_None },
|
true, true, CompressionMode::ePBitType_None },
|
||||||
|
|
||||||
// Mode 5
|
// Mode 5
|
||||||
{ 5, 0, 1, 2, 2, 7, 8,
|
{ 5, 0, 1, 2, 2, 7, 8,
|
||||||
true, false, BC7CompressionMode::ePBitType_None },
|
true, false, CompressionMode::ePBitType_None },
|
||||||
|
|
||||||
// Mode 6
|
// Mode 6
|
||||||
{ 6, 0, 1, 4, 0, 7, 7,
|
{ 6, 0, 1, 4, 0, 7, 7,
|
||||||
false, false, BC7CompressionMode::ePBitType_NotShared },
|
false, false, CompressionMode::ePBitType_NotShared },
|
||||||
|
|
||||||
// Mode 7
|
// Mode 7
|
||||||
{ 7, 6, 2, 2, 0, 5, 5,
|
{ 7, 6, 2, 2, 0, 5, 5,
|
||||||
false, false, BC7CompressionMode::ePBitType_NotShared },
|
false, false, CompressionMode::ePBitType_NotShared },
|
||||||
};
|
};
|
||||||
|
|
||||||
void BC7CompressionMode::ClampEndpointsToGrid(
|
void CompressionMode::ClampEndpointsToGrid(
|
||||||
RGBAVector &p1, RGBAVector &p2, int &bestPBitCombo
|
RGBAVector &p1, RGBAVector &p2, uint8 &bestPBitCombo
|
||||||
) const {
|
) const {
|
||||||
const int nPbitCombos = GetNumPbitCombos();
|
const int nPbitCombos = GetNumPbitCombos();
|
||||||
const bool hasPbits = nPbitCombos > 1;
|
const bool hasPbits = nPbitCombos > 1;
|
||||||
|
@ -390,13 +395,12 @@ void BC7CompressionMode::ClampEndpointsToGrid(
|
||||||
p2 = bp2;
|
p2 = bp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
double BC7CompressionMode::CompressSingleColor(
|
double CompressionMode::CompressSingleColor(
|
||||||
const RGBAVector &p, RGBAVector &p1, RGBAVector &p2,
|
const RGBAVector &p, RGBAVector &p1, RGBAVector &p2,
|
||||||
int &bestPbitCombo
|
uint8 &bestPbitCombo
|
||||||
) const {
|
) const {
|
||||||
const uint32 pixel = p.ToPixel();
|
const uint32 pixel = p.ToPixel();
|
||||||
float bestError = FLT_MAX;
|
float bestError = FLT_MAX;
|
||||||
bestPbitCombo = -1;
|
|
||||||
|
|
||||||
for(int pbi = 0; pbi < GetNumPbitCombos(); pbi++) {
|
for(int pbi = 0; pbi < GetNumPbitCombos(); pbi++) {
|
||||||
const int *pbitCombo = GetPBitCombo(pbi);
|
const int *pbitCombo = GetPBitCombo(pbi);
|
||||||
|
@ -448,9 +452,9 @@ double BC7CompressionMode::CompressSingleColor(
|
||||||
possValsL[i] |= (possValsL[i] >> nBits);
|
possValsL[i] |= (possValsL[i] >> nBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32 bpi = GetNumberOfBitsPerIndex() - 1;
|
const uint8 bpi = GetNumberOfBitsPerIndex() - 1;
|
||||||
const uint32 interpVal0 = kBC7InterpolationValues[bpi][1][0];
|
const uint32 interpVal0 = kInterpolationValues[bpi][1][0];
|
||||||
const uint32 interpVal1 = kBC7InterpolationValues[bpi][1][1];
|
const uint32 interpVal1 = kInterpolationValues[bpi][1][1];
|
||||||
|
|
||||||
// Find the closest interpolated val that to the given val...
|
// Find the closest interpolated val that to the given val...
|
||||||
uint32 bestChannelDist = 0xFF;
|
uint32 bestChannelDist = 0xFF;
|
||||||
|
@ -473,7 +477,7 @@ double BC7CompressionMode::CompressSingleColor(
|
||||||
dist[ci] = std::max(bestChannelDist, dist[ci]);
|
dist[ci] = std::max(bestChannelDist, dist[ci]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const float *errorWeights = BC7C::GetErrorMetric();
|
const float *errorWeights = BPTCC::GetErrorMetric();
|
||||||
float error = 0.0;
|
float error = 0.0;
|
||||||
for(uint32 i = 0; i < kNumColorChannels; i++) {
|
for(uint32 i = 0; i < kNumColorChannels; i++) {
|
||||||
float e = static_cast<float>(dist[i]) * errorWeights[i];
|
float e = static_cast<float>(dist[i]) * errorWeights[i];
|
||||||
|
@ -565,7 +569,7 @@ struct VisitedState {
|
||||||
int pBitCombo;
|
int pBitCombo;
|
||||||
};
|
};
|
||||||
|
|
||||||
void BC7CompressionMode::PickBestNeighboringEndpoints(
|
void CompressionMode::PickBestNeighboringEndpoints(
|
||||||
const RGBACluster &cluster,
|
const RGBACluster &cluster,
|
||||||
const RGBAVector &p1, const RGBAVector &p2, const int curPbitCombo,
|
const RGBAVector &p1, const RGBAVector &p2, const int curPbitCombo,
|
||||||
RGBAVector &np1, RGBAVector &np2, int &nPbitCombo,
|
RGBAVector &np1, RGBAVector &np2, int &nPbitCombo,
|
||||||
|
@ -645,9 +649,6 @@ void BC7CompressionMode::PickBestNeighboringEndpoints(
|
||||||
// the bytes interpreted as a float. This prevents two things: 1, a
|
// the bytes interpreted as a float. This prevents two things: 1, a
|
||||||
// division, and 2, a cast from an integer to a float.
|
// division, and 2, a cast from an integer to a float.
|
||||||
|
|
||||||
#define COMPILE_ASSERT(x) extern int __compile_assert_[static_cast<int>(x)];
|
|
||||||
COMPILE_ASSERT(RAND_MAX == 0x7FFF)
|
|
||||||
|
|
||||||
static inline float frand() {
|
static inline float frand() {
|
||||||
// RAND_MAX is 0x7FFF, which offers 15 bits
|
// RAND_MAX is 0x7FFF, which offers 15 bits
|
||||||
// of precision. Therefore, we move the bits
|
// of precision. Therefore, we move the bits
|
||||||
|
@ -663,7 +664,10 @@ static inline float frand() {
|
||||||
return fltUnion.flt - 1.0f;
|
return fltUnion.flt - 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BC7CompressionMode::AcceptNewEndpointError(
|
#define COMPILE_ASSERT(x) extern int __compile_assert_[static_cast<int>(x)];
|
||||||
|
COMPILE_ASSERT(RAND_MAX == 0x7FFF)
|
||||||
|
|
||||||
|
bool CompressionMode::AcceptNewEndpointError(
|
||||||
double newError, double oldError, float temp
|
double newError, double oldError, float temp
|
||||||
) const {
|
) const {
|
||||||
// Always accept better endpoints.
|
// Always accept better endpoints.
|
||||||
|
@ -677,11 +681,11 @@ bool BC7CompressionMode::AcceptNewEndpointError(
|
||||||
return r < p;
|
return r < p;
|
||||||
}
|
}
|
||||||
|
|
||||||
double BC7CompressionMode::OptimizeEndpointsForCluster(
|
double CompressionMode::OptimizeEndpointsForCluster(
|
||||||
const RGBACluster &cluster,
|
const RGBACluster &cluster,
|
||||||
RGBAVector &p1, RGBAVector &p2,
|
RGBAVector &p1, RGBAVector &p2,
|
||||||
int *bestIndices,
|
uint8 *bestIndices,
|
||||||
int &bestPbitCombo
|
uint8 &bestPbitCombo
|
||||||
) const {
|
) const {
|
||||||
|
|
||||||
const uint32 nBuckets = (1 << GetNumberOfBitsPerIndex());
|
const uint32 nBuckets = (1 << GetNumberOfBitsPerIndex());
|
||||||
|
@ -726,7 +730,7 @@ double BC7CompressionMode::OptimizeEndpointsForCluster(
|
||||||
|
|
||||||
float temp = static_cast<float>(energy) / static_cast<float>(maxEnergy-1);
|
float temp = static_cast<float>(energy) / static_cast<float>(maxEnergy-1);
|
||||||
|
|
||||||
int indices[kMaxNumDataPoints];
|
uint8 indices[kMaxNumDataPoints];
|
||||||
RGBAVector np1, np2;
|
RGBAVector np1, np2;
|
||||||
int nPbitCombo = 0;
|
int nPbitCombo = 0;
|
||||||
|
|
||||||
|
@ -771,11 +775,11 @@ double BC7CompressionMode::OptimizeEndpointsForCluster(
|
||||||
return bestError;
|
return bestError;
|
||||||
}
|
}
|
||||||
|
|
||||||
double BC7CompressionMode::CompressCluster(
|
double CompressionMode::CompressCluster(
|
||||||
const RGBACluster &cluster,
|
const RGBACluster &cluster,
|
||||||
RGBAVector &p1, RGBAVector &p2,
|
RGBAVector &p1, RGBAVector &p2,
|
||||||
int *bestIndices,
|
uint8 *bestIndices,
|
||||||
int *alphaIndices
|
uint8 *alphaIndices
|
||||||
) const {
|
) const {
|
||||||
assert(GetModeNumber() == 4 || GetModeNumber() == 5);
|
assert(GetModeNumber() == 4 || GetModeNumber() == 5);
|
||||||
assert(GetNumberOfSubsets() == 1);
|
assert(GetNumberOfSubsets() == 1);
|
||||||
|
@ -791,7 +795,7 @@ double BC7CompressionMode::CompressCluster(
|
||||||
"detected much earlier.");
|
"detected much earlier.");
|
||||||
|
|
||||||
const RGBAVector &p = cluster.GetPoint(0);
|
const RGBAVector &p = cluster.GetPoint(0);
|
||||||
int dummyPbit = 0;
|
uint8 dummyPbit = 0;
|
||||||
double bestErr = CompressSingleColor(p, p1, p2, dummyPbit);
|
double bestErr = CompressSingleColor(p, p1, p2, dummyPbit);
|
||||||
|
|
||||||
// We're assuming all indices will be index 1...
|
// We're assuming all indices will be index 1...
|
||||||
|
@ -838,7 +842,7 @@ double BC7CompressionMode::CompressCluster(
|
||||||
rgbCluster.AddPoint(v);
|
rgbCluster.AddPoint(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
int dummyPbit = 0;
|
uint8 dummyPbit = 0;
|
||||||
RGBAVector rgbp1, rgbp2;
|
RGBAVector rgbp1, rgbp2;
|
||||||
double rgbError = CompressCluster(
|
double rgbError = CompressCluster(
|
||||||
rgbCluster, rgbp1, rgbp2, bestIndices, dummyPbit
|
rgbCluster, rgbp1, rgbp2, bestIndices, dummyPbit
|
||||||
|
@ -851,7 +855,7 @@ double BC7CompressionMode::CompressCluster(
|
||||||
typedef tInterpPair tInterpLevel[16];
|
typedef tInterpPair tInterpLevel[16];
|
||||||
|
|
||||||
const tInterpLevel *interpVals =
|
const tInterpLevel *interpVals =
|
||||||
kBC7InterpolationValues + (GetNumberOfBitsPerAlpha() - 1);
|
kInterpolationValues + (GetNumberOfBitsPerAlpha() - 1);
|
||||||
|
|
||||||
const float weight = GetErrorMetric().a;
|
const float weight = GetErrorMetric().a;
|
||||||
|
|
||||||
|
@ -1062,11 +1066,11 @@ double BC7CompressionMode::CompressCluster(
|
||||||
return rgbError + alphaError;
|
return rgbError + alphaError;
|
||||||
}
|
}
|
||||||
|
|
||||||
double BC7CompressionMode::CompressCluster(
|
double CompressionMode::CompressCluster(
|
||||||
const RGBACluster &cluster,
|
const RGBACluster &cluster,
|
||||||
RGBAVector &p1, RGBAVector &p2,
|
RGBAVector &p1, RGBAVector &p2,
|
||||||
int *bestIndices,
|
uint8 *bestIndices,
|
||||||
int &bestPbitCombo
|
uint8 &bestPbitCombo
|
||||||
) const {
|
) const {
|
||||||
// If all the points are the same in the cluster, then we need to figure out
|
// If all the points are the same in the cluster, then we need to figure out
|
||||||
// what the best approximation to this point is....
|
// what the best approximation to this point is....
|
||||||
|
@ -1228,7 +1232,7 @@ double BC7CompressionMode::CompressCluster(
|
||||||
ClampEndpointsToGrid(p1, p2, bestPbitCombo);
|
ClampEndpointsToGrid(p1, p2, bestPbitCombo);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
int pBitCombo = bestPbitCombo;
|
uint8 pBitCombo = bestPbitCombo;
|
||||||
RGBAVector tp1 = p1, tp2 = p2;
|
RGBAVector tp1 = p1, tp2 = p2;
|
||||||
ClampEndpointsToGrid(tp1, tp2, pBitCombo);
|
ClampEndpointsToGrid(tp1, tp2, pBitCombo);
|
||||||
|
|
||||||
|
@ -1244,99 +1248,29 @@ double BC7CompressionMode::CompressCluster(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
double BC7CompressionMode::Compress(
|
void CompressionMode::Pack(Params ¶ms, BitStream &stream) const {
|
||||||
BitStream &stream, const int shapeIdx, const RGBACluster *clusters
|
|
||||||
) {
|
|
||||||
|
|
||||||
const int kModeNumber = GetModeNumber();
|
const int kModeNumber = GetModeNumber();
|
||||||
const int nPartitionBits = GetNumberOfPartitionBits();
|
const int nPartitionBits = GetNumberOfPartitionBits();
|
||||||
const int nSubsets = GetNumberOfSubsets();
|
const int nSubsets = GetNumberOfSubsets();
|
||||||
|
|
||||||
|
|
||||||
// Mode #
|
// Mode #
|
||||||
stream.WriteBits(1 << kModeNumber, kModeNumber + 1);
|
stream.WriteBits(1 << kModeNumber, kModeNumber + 1);
|
||||||
|
|
||||||
// Partition #
|
// Partition #
|
||||||
assert((((1 << nPartitionBits) - 1) & shapeIdx) == shapeIdx);
|
assert((((1 << nPartitionBits) - 1) & params.m_ShapeIdx) == params.m_ShapeIdx);
|
||||||
stream.WriteBits(shapeIdx, nPartitionBits);
|
stream.WriteBits(params.m_ShapeIdx, nPartitionBits);
|
||||||
|
|
||||||
RGBAVector p1[kMaxNumSubsets], p2[kMaxNumSubsets];
|
stream.WriteBits(params.m_RotationMode, m_Attributes->hasRotation? 2 : 0);
|
||||||
|
stream.WriteBits(params.m_IndexMode, m_Attributes->hasIdxMode? 1 : 0);
|
||||||
int bestIndices[kMaxNumSubsets][kMaxNumDataPoints];
|
|
||||||
memset(bestIndices, 0xFF, sizeof(bestIndices));
|
|
||||||
|
|
||||||
int bestAlphaIndices[kMaxNumDataPoints];
|
|
||||||
memset(bestAlphaIndices, 0xFF, sizeof(bestAlphaIndices));
|
|
||||||
|
|
||||||
int bestPbitCombo[kMaxNumSubsets] = { -1, -1, -1 };
|
|
||||||
int bestRotationMode = -1, bestIndexMode = -1;
|
|
||||||
|
|
||||||
double totalErr = 0.0;
|
|
||||||
for(int cidx = 0; cidx < nSubsets; cidx++) {
|
|
||||||
int indices[kMaxNumDataPoints] = {0};
|
|
||||||
|
|
||||||
if(m_Attributes->hasRotation) {
|
|
||||||
|
|
||||||
assert(nSubsets == 1);
|
|
||||||
|
|
||||||
int alphaIndices[kMaxNumDataPoints];
|
|
||||||
|
|
||||||
double bestError = DBL_MAX;
|
|
||||||
for(int rotMode = 0; rotMode < 4; rotMode++) {
|
|
||||||
|
|
||||||
SetRotationMode(rotMode);
|
|
||||||
const int nIdxModes = kModeNumber == 4? 2 : 1;
|
|
||||||
|
|
||||||
for(int idxMode = 0; idxMode < nIdxModes; idxMode++) {
|
|
||||||
|
|
||||||
SetIndexMode(idxMode);
|
|
||||||
|
|
||||||
RGBAVector v1, v2;
|
|
||||||
double error = CompressCluster(
|
|
||||||
clusters[cidx], v1, v2, indices, alphaIndices
|
|
||||||
);
|
|
||||||
|
|
||||||
if(error < bestError) {
|
|
||||||
bestError = error;
|
|
||||||
|
|
||||||
memcpy(bestIndices[cidx], indices, sizeof(indices));
|
|
||||||
memcpy(bestAlphaIndices, alphaIndices, sizeof(alphaIndices));
|
|
||||||
|
|
||||||
bestRotationMode = rotMode;
|
|
||||||
bestIndexMode = idxMode;
|
|
||||||
|
|
||||||
p1[cidx] = v1;
|
|
||||||
p2[cidx] = v2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
totalErr += bestError;
|
|
||||||
} else { // ! m_Attributes->hasRotation
|
|
||||||
// Compress this cluster
|
|
||||||
totalErr += CompressCluster(
|
|
||||||
clusters[cidx], p1[cidx], p2[cidx], indices, bestPbitCombo[cidx]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Map the indices to their proper position.
|
|
||||||
int idx = 0;
|
|
||||||
for(int i = 0; i < 16; i++) {
|
|
||||||
int subs = GetSubsetForIndex(i, shapeIdx, GetNumberOfSubsets());
|
|
||||||
if(subs == cidx) {
|
|
||||||
bestIndices[cidx][i] = indices[idx++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stream.WriteBits(bestRotationMode, m_Attributes->hasRotation? 2 : 0);
|
|
||||||
stream.WriteBits(bestIndexMode, m_Attributes->hasIdxMode? 1 : 0);
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
||||||
|
|
||||||
int nSet = 0;
|
int nSet = 0;
|
||||||
for(int j = 0; j < nSubsets; j++) {
|
for(int j = 0; j < nSubsets; j++) {
|
||||||
if(bestIndices[j][i] >= 0)
|
if(params.m_Indices[j][i] < 255)
|
||||||
nSet++;
|
nSet++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1353,14 +1287,14 @@ double BC7CompressionMode::Compress(
|
||||||
switch(GetPBitType()) {
|
switch(GetPBitType()) {
|
||||||
default:
|
default:
|
||||||
case ePBitType_None:
|
case ePBitType_None:
|
||||||
pixel1[i] = p1[i].ToPixel(qmask);
|
pixel1[i] = params.m_P1[i].ToPixel(qmask);
|
||||||
pixel2[i] = p2[i].ToPixel(qmask);
|
pixel2[i] = params.m_P2[i].ToPixel(qmask);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ePBitType_Shared:
|
case ePBitType_Shared:
|
||||||
case ePBitType_NotShared:
|
case ePBitType_NotShared:
|
||||||
pixel1[i] = p1[i].ToPixel(qmask, GetPBitCombo(bestPbitCombo[i])[0]);
|
pixel1[i] = params.m_P1[i].ToPixel(qmask, GetPBitCombo(params.m_PbitCombo[i])[0]);
|
||||||
pixel2[i] = p2[i].ToPixel(qmask, GetPBitCombo(bestPbitCombo[i])[1]);
|
pixel2[i] = params.m_P2[i].ToPixel(qmask, GetPBitCombo(params.m_PbitCombo[i])[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1369,28 +1303,28 @@ double BC7CompressionMode::Compress(
|
||||||
// we need to swap EVERYTHING.
|
// we need to swap EVERYTHING.
|
||||||
for(int sidx = 0; sidx < nSubsets; sidx++) {
|
for(int sidx = 0; sidx < nSubsets; sidx++) {
|
||||||
|
|
||||||
int anchorIdx = GetAnchorIndexForSubset(sidx, shapeIdx, nSubsets);
|
int anchorIdx = GetAnchorIndexForSubset(sidx, params.m_ShapeIdx, nSubsets);
|
||||||
assert(bestIndices[sidx][anchorIdx] != -1);
|
assert(params.m_Indices[sidx][anchorIdx] != 255);
|
||||||
|
|
||||||
const int nAlphaIndexBits = GetNumberOfBitsPerAlpha(bestIndexMode);
|
const int nAlphaIndexBits = GetNumberOfBitsPerAlpha(params.m_IndexMode);
|
||||||
const int nIndexBits = GetNumberOfBitsPerIndex(bestIndexMode);
|
const int nIndexBits = GetNumberOfBitsPerIndex(params.m_IndexMode);
|
||||||
if(bestIndices[sidx][anchorIdx] >> (nIndexBits - 1)) {
|
if(params.m_Indices[sidx][anchorIdx] >> (nIndexBits - 1)) {
|
||||||
uint32 t = pixel1[sidx]; pixel1[sidx] = pixel2[sidx]; pixel2[sidx] = t;
|
std::swap(pixel1[sidx], pixel2[sidx]);
|
||||||
|
|
||||||
int nIndexVals = 1 << nIndexBits;
|
int nIndexVals = 1 << nIndexBits;
|
||||||
for(int i = 0; i < 16; i++) {
|
for(int i = 0; i < 16; i++) {
|
||||||
bestIndices[sidx][i] = (nIndexVals - 1) - bestIndices[sidx][i];
|
params.m_Indices[sidx][i] = (nIndexVals - 1) - params.m_Indices[sidx][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
int nAlphaIndexVals = 1 << nAlphaIndexBits;
|
int nAlphaIndexVals = 1 << nAlphaIndexBits;
|
||||||
if(m_Attributes->hasRotation) {
|
if(m_Attributes->hasRotation) {
|
||||||
for(int i = 0; i < 16; i++) {
|
for(int i = 0; i < 16; i++) {
|
||||||
bestAlphaIndices[i] = (nAlphaIndexVals - 1) - bestAlphaIndices[i];
|
params.m_AlphaIndices[i] = (nAlphaIndexVals - 1) - params.m_AlphaIndices[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool rotated = (bestAlphaIndices[anchorIdx] >> (nAlphaIndexBits - 1)) > 0;
|
const bool rotated = (params.m_AlphaIndices[anchorIdx] >> (nAlphaIndexBits - 1)) > 0;
|
||||||
if(m_Attributes->hasRotation && rotated) {
|
if(m_Attributes->hasRotation && rotated) {
|
||||||
uint8 * bp1 = reinterpret_cast<uint8 *>(&pixel1[sidx]);
|
uint8 * bp1 = reinterpret_cast<uint8 *>(&pixel1[sidx]);
|
||||||
uint8 * bp2 = reinterpret_cast<uint8 *>(&pixel2[sidx]);
|
uint8 * bp2 = reinterpret_cast<uint8 *>(&pixel2[sidx]);
|
||||||
|
@ -1398,13 +1332,13 @@ double BC7CompressionMode::Compress(
|
||||||
|
|
||||||
int nAlphaIndexVals = 1 << nAlphaIndexBits;
|
int nAlphaIndexVals = 1 << nAlphaIndexBits;
|
||||||
for(int i = 0; i < 16; i++) {
|
for(int i = 0; i < 16; i++) {
|
||||||
bestAlphaIndices[i] = (nAlphaIndexVals - 1) - bestAlphaIndices[i];
|
params.m_AlphaIndices[i] = (nAlphaIndexVals - 1) - params.m_AlphaIndices[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(!(bestIndices[sidx][anchorIdx] >> (nIndexBits - 1)));
|
assert(!(params.m_Indices[sidx][anchorIdx] >> (nIndexBits - 1)));
|
||||||
assert(!m_Attributes->hasRotation ||
|
assert(!m_Attributes->hasRotation ||
|
||||||
!(bestAlphaIndices[anchorIdx] >> (nAlphaIndexBits - 1)));
|
!(params.m_AlphaIndices[anchorIdx] >> (nAlphaIndexBits - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the quantized values...
|
// Get the quantized values...
|
||||||
|
@ -1454,7 +1388,7 @@ double BC7CompressionMode::Compress(
|
||||||
// Write out the best pbits..
|
// Write out the best pbits..
|
||||||
if(GetPBitType() != ePBitType_None) {
|
if(GetPBitType() != ePBitType_None) {
|
||||||
for(int s = 0; s < nSubsets; s++) {
|
for(int s = 0; s < nSubsets; s++) {
|
||||||
const int *pbits = GetPBitCombo(bestPbitCombo[s]);
|
const int *pbits = GetPBitCombo(params.m_PbitCombo[s]);
|
||||||
stream.WriteBits(pbits[0], 1);
|
stream.WriteBits(pbits[0], 1);
|
||||||
if(GetPBitType() != ePBitType_Shared)
|
if(GetPBitType() != ePBitType_Shared)
|
||||||
stream.WriteBits(pbits[1], 1);
|
stream.WriteBits(pbits[1], 1);
|
||||||
|
@ -1463,14 +1397,14 @@ double BC7CompressionMode::Compress(
|
||||||
|
|
||||||
// If our index mode has changed, then we need to write the alpha indices
|
// If our index mode has changed, then we need to write the alpha indices
|
||||||
// first.
|
// first.
|
||||||
if(m_Attributes->hasIdxMode && bestIndexMode == 1) {
|
if(m_Attributes->hasIdxMode && params.m_IndexMode == 1) {
|
||||||
|
|
||||||
assert(m_Attributes->hasRotation);
|
assert(m_Attributes->hasRotation);
|
||||||
|
|
||||||
for(int i = 0; i < 16; i++) {
|
for(int i = 0; i < 16; i++) {
|
||||||
const int idx = bestAlphaIndices[i];
|
const int idx = params.m_AlphaIndices[i];
|
||||||
assert(GetAnchorIndexForSubset(0, shapeIdx, nSubsets) == 0);
|
assert(GetAnchorIndexForSubset(0, params.m_ShapeIdx, nSubsets) == 0);
|
||||||
assert(GetNumberOfBitsPerAlpha(bestIndexMode) == 2);
|
assert(GetNumberOfBitsPerAlpha(params.m_IndexMode) == 2);
|
||||||
assert(idx >= 0 && idx < (1 << 2));
|
assert(idx >= 0 && idx < (1 << 2));
|
||||||
assert(i != 0 ||
|
assert(i != 0 ||
|
||||||
!(idx >> 1) ||
|
!(idx >> 1) ||
|
||||||
|
@ -1479,10 +1413,10 @@ double BC7CompressionMode::Compress(
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 16; i++) {
|
for(int i = 0; i < 16; i++) {
|
||||||
const int idx = bestIndices[0][i];
|
const int idx = params.m_Indices[0][i];
|
||||||
assert(GetSubsetForIndex(i, shapeIdx, nSubsets) == 0);
|
assert(GetSubsetForIndex(i, params.m_ShapeIdx, nSubsets) == 0);
|
||||||
assert(GetAnchorIndexForSubset(0, shapeIdx, nSubsets) == 0);
|
assert(GetAnchorIndexForSubset(0, params.m_ShapeIdx, nSubsets) == 0);
|
||||||
assert(GetNumberOfBitsPerIndex(bestIndexMode) == 3);
|
assert(GetNumberOfBitsPerIndex(params.m_IndexMode) == 3);
|
||||||
assert(idx >= 0 && idx < (1 << 3));
|
assert(idx >= 0 && idx < (1 << 3));
|
||||||
assert(i != 0 ||
|
assert(i != 0 ||
|
||||||
!(idx >> 2) ||
|
!(idx >> 2) ||
|
||||||
|
@ -1491,10 +1425,10 @@ double BC7CompressionMode::Compress(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(int i = 0; i < 16; i++) {
|
for(int i = 0; i < 16; i++) {
|
||||||
const int subs = GetSubsetForIndex(i, shapeIdx, nSubsets);
|
const int subs = GetSubsetForIndex(i, params.m_ShapeIdx, nSubsets);
|
||||||
const int idx = bestIndices[subs][i];
|
const int idx = params.m_Indices[subs][i];
|
||||||
const int anchorIdx = GetAnchorIndexForSubset(subs, shapeIdx, nSubsets);
|
const int anchorIdx = GetAnchorIndexForSubset(subs, params.m_ShapeIdx, nSubsets);
|
||||||
const int nBitsForIdx = GetNumberOfBitsPerIndex(bestIndexMode);
|
const int nBitsForIdx = GetNumberOfBitsPerIndex(params.m_IndexMode);
|
||||||
assert(idx >= 0 && idx < (1 << nBitsForIdx));
|
assert(idx >= 0 && idx < (1 << nBitsForIdx));
|
||||||
assert(i != anchorIdx ||
|
assert(i != anchorIdx ||
|
||||||
!(idx >> (nBitsForIdx - 1)) ||
|
!(idx >> (nBitsForIdx - 1)) ||
|
||||||
|
@ -1504,9 +1438,9 @@ double BC7CompressionMode::Compress(
|
||||||
|
|
||||||
if(m_Attributes->hasRotation) {
|
if(m_Attributes->hasRotation) {
|
||||||
for(int i = 0; i < 16; i++) {
|
for(int i = 0; i < 16; i++) {
|
||||||
const int idx = bestAlphaIndices[i];
|
const int idx = params.m_AlphaIndices[i];
|
||||||
const int anchorIdx = 0;
|
const int anchorIdx = 0;
|
||||||
const int nBitsForIdx = GetNumberOfBitsPerAlpha(bestIndexMode);
|
const int nBitsForIdx = GetNumberOfBitsPerAlpha(params.m_IndexMode);
|
||||||
assert(idx >= 0 && idx < (1 << nBitsForIdx));
|
assert(idx >= 0 && idx < (1 << nBitsForIdx));
|
||||||
assert(i != anchorIdx ||
|
assert(i != anchorIdx ||
|
||||||
!(idx >> (nBitsForIdx - 1)) ||
|
!(idx >> (nBitsForIdx - 1)) ||
|
||||||
|
@ -1516,10 +1450,83 @@ double BC7CompressionMode::Compress(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(stream.GetBitsWritten() == 128);
|
assert(stream.GetBitsWritten() == 128);
|
||||||
|
}
|
||||||
|
|
||||||
|
double CompressionMode::Compress(
|
||||||
|
BitStream &stream, const int shapeIdx, const RGBACluster *clusters
|
||||||
|
) {
|
||||||
|
|
||||||
|
const int kModeNumber = GetModeNumber();
|
||||||
|
const int nPartitionBits = GetNumberOfPartitionBits();
|
||||||
|
const int nSubsets = GetNumberOfSubsets();
|
||||||
|
|
||||||
|
Params params(shapeIdx);
|
||||||
|
|
||||||
|
double totalErr = 0.0;
|
||||||
|
for(int cidx = 0; cidx < nSubsets; cidx++) {
|
||||||
|
uint8 indices[kMaxNumDataPoints] = {0};
|
||||||
|
|
||||||
|
if(m_Attributes->hasRotation) {
|
||||||
|
|
||||||
|
assert(nSubsets == 1);
|
||||||
|
|
||||||
|
uint8 alphaIndices[kMaxNumDataPoints];
|
||||||
|
|
||||||
|
double bestError = DBL_MAX;
|
||||||
|
for(int rotMode = 0; rotMode < 4; rotMode++) {
|
||||||
|
|
||||||
|
SetRotationMode(rotMode);
|
||||||
|
const int nIdxModes = kModeNumber == 4? 2 : 1;
|
||||||
|
|
||||||
|
for(int idxMode = 0; idxMode < nIdxModes; idxMode++) {
|
||||||
|
|
||||||
|
SetIndexMode(idxMode);
|
||||||
|
|
||||||
|
RGBAVector v1, v2;
|
||||||
|
double error = CompressCluster(
|
||||||
|
clusters[cidx], v1, v2, indices, alphaIndices
|
||||||
|
);
|
||||||
|
|
||||||
|
if(error < bestError) {
|
||||||
|
bestError = error;
|
||||||
|
|
||||||
|
memcpy(params.m_Indices[cidx], indices, sizeof(indices));
|
||||||
|
memcpy(params.m_AlphaIndices, alphaIndices, sizeof(alphaIndices));
|
||||||
|
|
||||||
|
params.m_RotationMode = rotMode;
|
||||||
|
params.m_IndexMode = idxMode;
|
||||||
|
|
||||||
|
params.m_P1[cidx] = v1;
|
||||||
|
params.m_P2[cidx] = v2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
totalErr += bestError;
|
||||||
|
} else { // ! m_Attributes->hasRotation
|
||||||
|
// Compress this cluster
|
||||||
|
totalErr += CompressCluster(
|
||||||
|
clusters[cidx],
|
||||||
|
params.m_P1[cidx], params.m_P2[cidx],
|
||||||
|
indices, params.m_PbitCombo[cidx]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Map the indices to their proper position.
|
||||||
|
int idx = 0;
|
||||||
|
for(int i = 0; i < 16; i++) {
|
||||||
|
int subs = GetSubsetForIndex(i, shapeIdx, GetNumberOfSubsets());
|
||||||
|
if(subs == cidx) {
|
||||||
|
params.m_Indices[cidx][i] = indices[idx++];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Pack(params, stream);
|
||||||
|
assert(stream.GetBitsWritten() == 128);
|
||||||
return totalErr;
|
return totalErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace BC7C {
|
|
||||||
static ErrorMetric gErrorMetric = eErrorMetric_Uniform;
|
static ErrorMetric gErrorMetric = eErrorMetric_Uniform;
|
||||||
void SetErrorMetric(ErrorMetric e) { gErrorMetric = e; }
|
void SetErrorMetric(ErrorMetric e) { gErrorMetric = e; }
|
||||||
|
|
||||||
|
@ -1559,8 +1566,8 @@ namespace BC7C {
|
||||||
static int gQualityLevel = 50;
|
static int gQualityLevel = 50;
|
||||||
void SetQualityLevel(int q) {
|
void SetQualityLevel(int q) {
|
||||||
gQualityLevel = std::max(0, q);
|
gQualityLevel = std::max(0, q);
|
||||||
const int kMaxIters = BC7CompressionMode::kMaxAnnealingIterations;
|
const int kMaxIters = CompressionMode::kMaxAnnealingIterations;
|
||||||
BC7CompressionMode::MaxAnnealingIterations =
|
CompressionMode::MaxAnnealingIterations =
|
||||||
std::min(kMaxIters, GetQualityLevel());
|
std::min(kMaxIters, GetQualityLevel());
|
||||||
}
|
}
|
||||||
int GetQualityLevel() { return gQualityLevel; }
|
int GetQualityLevel() { return gQualityLevel; }
|
||||||
|
@ -1796,7 +1803,7 @@ namespace BC7C {
|
||||||
uint8 tempBuf1[16];
|
uint8 tempBuf1[16];
|
||||||
BitStream tmpStream1(tempBuf1, 128, 0);
|
BitStream tmpStream1(tempBuf1, 128, 0);
|
||||||
double bestError =
|
double bestError =
|
||||||
BC7CompressionMode(1, opaque).Compress(tmpStream1, shapeIdx, clusters);
|
CompressionMode(1, opaque).Compress(tmpStream1, shapeIdx, clusters);
|
||||||
|
|
||||||
if(errors) errors[1] = bestError;
|
if(errors) errors[1] = bestError;
|
||||||
if(modeChosen) *modeChosen = 1;
|
if(modeChosen) *modeChosen = 1;
|
||||||
|
@ -1810,7 +1817,7 @@ namespace BC7C {
|
||||||
BitStream tmpStream3(tempBuf3, 128, 0);
|
BitStream tmpStream3(tempBuf3, 128, 0);
|
||||||
|
|
||||||
double error =
|
double error =
|
||||||
BC7CompressionMode(3, opaque).Compress(tmpStream3, shapeIdx, clusters);
|
CompressionMode(3, opaque).Compress(tmpStream3, shapeIdx, clusters);
|
||||||
|
|
||||||
if(errors) errors[3] = error;
|
if(errors) errors[3] = error;
|
||||||
if(error < bestError) {
|
if(error < bestError) {
|
||||||
|
@ -1829,7 +1836,7 @@ namespace BC7C {
|
||||||
BitStream tmpStream7(tempBuf7, 128, 0);
|
BitStream tmpStream7(tempBuf7, 128, 0);
|
||||||
|
|
||||||
error =
|
error =
|
||||||
BC7CompressionMode(7, opaque).Compress(tmpStream7, shapeIdx, clusters);
|
CompressionMode(7, opaque).Compress(tmpStream7, shapeIdx, clusters);
|
||||||
|
|
||||||
if(errors) errors[7] = error;
|
if(errors) errors[7] = error;
|
||||||
if(error < bestError) {
|
if(error < bestError) {
|
||||||
|
@ -1859,7 +1866,7 @@ namespace BC7C {
|
||||||
double error, bestError = DBL_MAX;;
|
double error, bestError = DBL_MAX;;
|
||||||
if(shapeIdx < 16) {
|
if(shapeIdx < 16) {
|
||||||
bestError =
|
bestError =
|
||||||
BC7CompressionMode(0, opaque).Compress(tmpStream0, shapeIdx, clusters);
|
CompressionMode(0, opaque).Compress(tmpStream0, shapeIdx, clusters);
|
||||||
|
|
||||||
if(errors) errors[0] = bestError;
|
if(errors) errors[0] = bestError;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1873,7 +1880,7 @@ namespace BC7C {
|
||||||
}
|
}
|
||||||
|
|
||||||
error =
|
error =
|
||||||
BC7CompressionMode(2, opaque).Compress(tmpStream2, shapeIdx, clusters);
|
CompressionMode(2, opaque).Compress(tmpStream2, shapeIdx, clusters);
|
||||||
|
|
||||||
if(errors) errors[2] = error;
|
if(errors) errors[2] = error;
|
||||||
if(error < bestError) {
|
if(error < bestError) {
|
||||||
|
@ -1945,7 +1952,7 @@ namespace BC7C {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float *w = BC7C::GetErrorMetric();
|
const float *w = BPTCC::GetErrorMetric();
|
||||||
|
|
||||||
double error = 0.0001;
|
double error = 0.0001;
|
||||||
#ifdef USE_PCA_FOR_SHAPE_ESTIMATION
|
#ifdef USE_PCA_FOR_SHAPE_ESTIMATION
|
||||||
|
@ -1971,7 +1978,7 @@ namespace BC7C {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float *w = BC7C::GetErrorMetric();
|
const float *w = BPTCC::GetErrorMetric();
|
||||||
|
|
||||||
double error = 0.0001;
|
double error = 0.0001;
|
||||||
#ifdef USE_PCA_FOR_SHAPE_ESTIMATION
|
#ifdef USE_PCA_FOR_SHAPE_ESTIMATION
|
||||||
|
@ -2080,7 +2087,7 @@ namespace BC7C {
|
||||||
uint8 tempBuf1[16], tempBuf2[16];
|
uint8 tempBuf1[16], tempBuf2[16];
|
||||||
|
|
||||||
BitStream tempStream1 (tempBuf1, 128, 0);
|
BitStream tempStream1 (tempBuf1, 128, 0);
|
||||||
BC7CompressionMode compressor(6, opaque);
|
CompressionMode compressor(6, opaque);
|
||||||
double best = compressor.Compress(tempStream1, 0, &blockCluster);
|
double best = compressor.Compress(tempStream1, 0, &blockCluster);
|
||||||
if(best == 0.0f) {
|
if(best == 0.0f) {
|
||||||
memcpy(outBuf, tempBuf1, 16);
|
memcpy(outBuf, tempBuf1, 16);
|
||||||
|
@ -2092,7 +2099,7 @@ namespace BC7C {
|
||||||
for(int mode = 4; mode <= 5; mode++) {
|
for(int mode = 4; mode <= 5; mode++) {
|
||||||
|
|
||||||
BitStream tempStream2(tempBuf2, 128, 0);
|
BitStream tempStream2(tempBuf2, 128, 0);
|
||||||
BC7CompressionMode compressorTry(mode, opaque);
|
CompressionMode compressorTry(mode, opaque);
|
||||||
|
|
||||||
double error = compressorTry.Compress(tempStream2, 0, &blockCluster);
|
double error = compressorTry.Compress(tempStream2, 0, &blockCluster);
|
||||||
if(error < best) {
|
if(error < best) {
|
||||||
|
@ -2148,7 +2155,7 @@ namespace BC7C {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float *w = BC7C::GetErrorMetric();
|
const float *w = BPTCC::GetErrorMetric();
|
||||||
|
|
||||||
const double err1 = c.QuantizedError(
|
const double err1 = c.QuantizedError(
|
||||||
Min, Max, 8, 0xFFFCFCFC, RGBAVector(w[0], w[1], w[2], w[3])
|
Min, Max, 8, 0xFFFCFCFC, RGBAVector(w[0], w[1], w[2], w[3])
|
||||||
|
@ -2196,7 +2203,7 @@ namespace BC7C {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float *w = BC7C::GetErrorMetric();
|
const float *w = BPTCC::GetErrorMetric();
|
||||||
const double err0 = 0.0001 + c.QuantizedError(
|
const double err0 = 0.0001 + c.QuantizedError(
|
||||||
Min, Max, 4, 0xFFF0F0F0, RGBAVector(w[0], w[1], w[2], w[3])
|
Min, Max, 4, 0xFFF0F0F0, RGBAVector(w[0], w[1], w[2], w[3])
|
||||||
);
|
);
|
||||||
|
@ -2236,7 +2243,7 @@ namespace BC7C {
|
||||||
static void UpdateErrorEstimate(double *estimates, uint32 mode, double est) {
|
static void UpdateErrorEstimate(double *estimates, uint32 mode, double est) {
|
||||||
assert(estimates);
|
assert(estimates);
|
||||||
assert(mode >= 0);
|
assert(mode >= 0);
|
||||||
assert(mode < BC7CompressionMode::kNumModes);
|
assert(mode < CompressionMode::kNumModes);
|
||||||
if(estimates[mode] == -1.0 || est < estimates[mode]) {
|
if(estimates[mode] == -1.0 || est < estimates[mode]) {
|
||||||
estimates[mode] = est;
|
estimates[mode] = est;
|
||||||
}
|
}
|
||||||
|
@ -2278,7 +2285,7 @@ namespace BC7C {
|
||||||
|
|
||||||
PrintStat(m_Logger, kBlockStatString[eBlockStat_Mode], *m_ModePtr);
|
PrintStat(m_Logger, kBlockStatString[eBlockStat_Mode], *m_ModePtr);
|
||||||
|
|
||||||
for(uint32 i = 0; i < BC7CompressionMode::kNumModes; i++) {
|
for(uint32 i = 0; i < CompressionMode::kNumModes; i++) {
|
||||||
|
|
||||||
PrintStat(m_Logger,
|
PrintStat(m_Logger,
|
||||||
kBlockStatString[eBlockStat_ModeZeroEstimate + i],
|
kBlockStatString[eBlockStat_ModeZeroEstimate + i],
|
||||||
|
@ -2291,12 +2298,12 @@ namespace BC7C {
|
||||||
};
|
};
|
||||||
|
|
||||||
int bestMode = 0;
|
int bestMode = 0;
|
||||||
double modeEstimate[BC7CompressionMode::kNumModes];
|
double modeEstimate[CompressionMode::kNumModes];
|
||||||
double modeError[BC7CompressionMode::kNumModes];
|
double modeError[CompressionMode::kNumModes];
|
||||||
|
|
||||||
// reset global variables...
|
// reset global variables...
|
||||||
bestMode = 0;
|
bestMode = 0;
|
||||||
for(uint32 i = 0; i < BC7CompressionMode::kNumModes; i++) {
|
for(uint32 i = 0; i < CompressionMode::kNumModes; i++) {
|
||||||
modeError[i] = modeEstimate[i] = -1.0;
|
modeError[i] = modeEstimate[i] = -1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2506,7 +2513,7 @@ namespace BC7C {
|
||||||
uint8 tempBuf1[16], tempBuf2[16];
|
uint8 tempBuf1[16], tempBuf2[16];
|
||||||
|
|
||||||
BitStream tempStream1 (tempBuf1, 128, 0);
|
BitStream tempStream1 (tempBuf1, 128, 0);
|
||||||
BC7CompressionMode compressor(6, opaque);
|
CompressionMode compressor(6, opaque);
|
||||||
double best = compressor.Compress(tempStream1, 0, &blockCluster);
|
double best = compressor.Compress(tempStream1, 0, &blockCluster);
|
||||||
modeError[6] = best;
|
modeError[6] = best;
|
||||||
bestMode = 6;
|
bestMode = 6;
|
||||||
|
@ -2520,7 +2527,7 @@ namespace BC7C {
|
||||||
for(int mode = 4; mode <= 5; mode++) {
|
for(int mode = 4; mode <= 5; mode++) {
|
||||||
|
|
||||||
BitStream tempStream2(tempBuf2, 128, 0);
|
BitStream tempStream2(tempBuf2, 128, 0);
|
||||||
BC7CompressionMode compressorTry(mode, opaque);
|
CompressionMode compressorTry(mode, opaque);
|
||||||
|
|
||||||
double error = compressorTry.Compress(tempStream2, 0, &blockCluster);
|
double error = compressorTry.Compress(tempStream2, 0, &blockCluster);
|
||||||
if(error < best) {
|
if(error < best) {
|
||||||
|
@ -2580,8 +2587,8 @@ namespace BC7C {
|
||||||
mode++;
|
mode++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BC7CompressionMode::Attributes *attrs =
|
const CompressionMode::Attributes *attrs =
|
||||||
BC7CompressionMode::GetAttributesForMode(mode);
|
CompressionMode::GetAttributesForMode(mode);
|
||||||
const uint32 nSubsets = attrs->numSubsets;
|
const uint32 nSubsets = attrs->numSubsets;
|
||||||
|
|
||||||
uint32 idxMode = 0;
|
uint32 idxMode = 0;
|
||||||
|
@ -2624,11 +2631,11 @@ namespace BC7C {
|
||||||
|
|
||||||
// Handle pbits
|
// Handle pbits
|
||||||
switch(attrs->pbitType) {
|
switch(attrs->pbitType) {
|
||||||
case BC7CompressionMode::ePBitType_None:
|
case CompressionMode::ePBitType_None:
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BC7CompressionMode::ePBitType_Shared:
|
case CompressionMode::ePBitType_Shared:
|
||||||
|
|
||||||
cp += 1;
|
cp += 1;
|
||||||
ap += 1;
|
ap += 1;
|
||||||
|
@ -2645,7 +2652,7 @@ namespace BC7C {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BC7CompressionMode::ePBitType_NotShared:
|
case CompressionMode::ePBitType_NotShared:
|
||||||
|
|
||||||
cp += 1;
|
cp += 1;
|
||||||
ap += 1;
|
ap += 1;
|
||||||
|
@ -2728,9 +2735,9 @@ namespace BC7C {
|
||||||
for(int ch = 0; ch < 4; ch++) {
|
for(int ch = 0; ch < 4; ch++) {
|
||||||
if(ch == 3 && nBitsPerAlpha > 0) {
|
if(ch == 3 && nBitsPerAlpha > 0) {
|
||||||
uint32 i0 =
|
uint32 i0 =
|
||||||
kBC7InterpolationValues[nBitsPerAlpha - 1][alphaIndices[i]][0];
|
kInterpolationValues[nBitsPerAlpha - 1][alphaIndices[i]][0];
|
||||||
uint32 i1 =
|
uint32 i1 =
|
||||||
kBC7InterpolationValues[nBitsPerAlpha - 1][alphaIndices[i]][1];
|
kInterpolationValues[nBitsPerAlpha - 1][alphaIndices[i]][1];
|
||||||
|
|
||||||
const uint32 ep1 = static_cast<uint32>(eps[subset][0][3]);
|
const uint32 ep1 = static_cast<uint32>(eps[subset][0][3]);
|
||||||
const uint32 ep2 = static_cast<uint32>(eps[subset][1][3]);
|
const uint32 ep2 = static_cast<uint32>(eps[subset][1][3]);
|
||||||
|
@ -2739,9 +2746,9 @@ namespace BC7C {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
uint32 i0 =
|
uint32 i0 =
|
||||||
kBC7InterpolationValues[nBitsPerColor - 1][colorIndices[i]][0];
|
kInterpolationValues[nBitsPerColor - 1][colorIndices[i]][0];
|
||||||
uint32 i1 =
|
uint32 i1 =
|
||||||
kBC7InterpolationValues[nBitsPerColor - 1][colorIndices[i]][1];
|
kInterpolationValues[nBitsPerColor - 1][colorIndices[i]][1];
|
||||||
|
|
||||||
const uint32 ep1 = static_cast<uint32>(eps[subset][0][ch]);
|
const uint32 ep1 = static_cast<uint32>(eps[subset][0][ch]);
|
||||||
const uint32 ep2 = static_cast<uint32>(eps[subset][1][ch]);
|
const uint32 ep2 = static_cast<uint32>(eps[subset][1][ch]);
|
||||||
|
@ -2794,4 +2801,5 @@ namespace BC7C {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace BC7C
|
|
||||||
|
} // namespace BPTCC
|
|
@ -47,7 +47,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
const BC7ParallelStage stage;
|
const BPTCParallelStage stage;
|
||||||
|
|
||||||
// This is the stream of data that will be used to read the block data.
|
// This is the stream of data that will be used to read the block data.
|
||||||
const unsigned char *const m_InBuf;
|
const unsigned char *const m_InBuf;
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
uint32 m_NumBlocks;
|
uint32 m_NumBlocks;
|
||||||
*/
|
*/
|
||||||
ParallelStage::ParallelStage(
|
ParallelStage::ParallelStage(
|
||||||
BC7ParallelStage stage,
|
BPTCParallelStage stage,
|
||||||
const unsigned char *inbuf,
|
const unsigned char *inbuf,
|
||||||
unsigned char *outbuf,
|
unsigned char *outbuf,
|
||||||
uint32 numBlocks,
|
uint32 numBlocks,
|
||||||
|
|
|
@ -1,30 +1,39 @@
|
||||||
/* FasTC
|
/* FasTC
|
||||||
* Copyright (c) 2012 University of North Carolina at Chapel Hill. All rights reserved.
|
* Copyright (c) 2014 University of North Carolina at Chapel Hill.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software and its documentation for educational,
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
|
* documentation for educational, research, and non-profit purposes, without
|
||||||
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
|
* fee, and without a written agreement is hereby granted, provided that the
|
||||||
* in all copies.
|
* above copyright notice, this paragraph, and the following four paragraphs
|
||||||
|
* appear in all copies.
|
||||||
*
|
*
|
||||||
* Permission to incorporate this software into commercial products may be obtained by contacting the
|
* Permission to incorporate this software into commercial products may be
|
||||||
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
* obtained by contacting the authors or the Office of Technology Development
|
||||||
|
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
||||||
*
|
*
|
||||||
* This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill.
|
* This software program and documentation are copyrighted by the University of
|
||||||
* The software program and documentation are supplied "as is," without any accompanying services from the
|
* North Carolina at Chapel Hill. The software program and documentation are
|
||||||
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
|
* supplied "as is," without any accompanying services from the University of
|
||||||
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
|
* North Carolina at Chapel Hill or the authors. The University of North
|
||||||
* end-user understands that the program was developed for research purposes and is advised not to rely
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
||||||
* exclusively on the program for any reason.
|
* the program will be uninterrupted or error-free. The end-user understands
|
||||||
|
* that the program was developed for research purposes and is advised not to
|
||||||
|
* rely exclusively on the program for any reason.
|
||||||
*
|
*
|
||||||
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS BE LIABLE TO ANY PARTY FOR
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
||||||
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
||||||
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
|
||||||
|
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
*
|
*
|
||||||
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
||||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
||||||
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
|
||||||
|
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
|
||||||
|
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*
|
*
|
||||||
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
||||||
|
@ -43,7 +52,7 @@
|
||||||
|
|
||||||
#include "TexCompTypes.h"
|
#include "TexCompTypes.h"
|
||||||
|
|
||||||
enum BC7ParallelStage {
|
enum BPTCParallelStage {
|
||||||
eParallelStage_Uniform,
|
eParallelStage_Uniform,
|
||||||
eParallelStage_Partitioned,
|
eParallelStage_Partitioned,
|
||||||
eParallelStage_Normal,
|
eParallelStage_Normal,
|
||||||
|
@ -54,7 +63,7 @@ enum BC7ParallelStage {
|
||||||
class ParallelStage {
|
class ParallelStage {
|
||||||
public:
|
public:
|
||||||
ParallelStage(
|
ParallelStage(
|
||||||
BC7ParallelStage stage,
|
BPTCParallelStage stage,
|
||||||
const unsigned char *inbuf,
|
const unsigned char *inbuf,
|
||||||
unsigned char *outbuf,
|
unsigned char *outbuf,
|
||||||
uint32 numBlocks,
|
uint32 numBlocks,
|
||||||
|
@ -66,7 +75,7 @@ class ParallelStage {
|
||||||
|
|
||||||
~ParallelStage();
|
~ParallelStage();
|
||||||
|
|
||||||
const BC7ParallelStage m_Stage;
|
const BPTCParallelStage m_Stage;
|
||||||
|
|
||||||
// Adds the block number to the list of blocks for this parallel stage
|
// Adds the block number to the list of blocks for this parallel stage
|
||||||
void AddBlock(uint32 blockNum);
|
void AddBlock(uint32 blockNum);
|
||||||
|
|
|
@ -1,30 +1,39 @@
|
||||||
/* FasTC
|
/* FasTC
|
||||||
* Copyright (c) 2012 University of North Carolina at Chapel Hill. All rights reserved.
|
* Copyright (c) 2014 University of North Carolina at Chapel Hill.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software and its documentation for educational,
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
|
* documentation for educational, research, and non-profit purposes, without
|
||||||
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
|
* fee, and without a written agreement is hereby granted, provided that the
|
||||||
* in all copies.
|
* above copyright notice, this paragraph, and the following four paragraphs
|
||||||
|
* appear in all copies.
|
||||||
*
|
*
|
||||||
* Permission to incorporate this software into commercial products may be obtained by contacting the
|
* Permission to incorporate this software into commercial products may be
|
||||||
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
* obtained by contacting the authors or the Office of Technology Development
|
||||||
|
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
||||||
*
|
*
|
||||||
* This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill.
|
* This software program and documentation are copyrighted by the University of
|
||||||
* The software program and documentation are supplied "as is," without any accompanying services from the
|
* North Carolina at Chapel Hill. The software program and documentation are
|
||||||
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
|
* supplied "as is," without any accompanying services from the University of
|
||||||
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
|
* North Carolina at Chapel Hill or the authors. The University of North
|
||||||
* end-user understands that the program was developed for research purposes and is advised not to rely
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
||||||
* exclusively on the program for any reason.
|
* the program will be uninterrupted or error-free. The end-user understands
|
||||||
|
* that the program was developed for research purposes and is advised not to
|
||||||
|
* rely exclusively on the program for any reason.
|
||||||
*
|
*
|
||||||
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS BE LIABLE TO ANY PARTY FOR
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
||||||
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
||||||
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
|
||||||
|
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
*
|
*
|
||||||
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
||||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
||||||
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
|
||||||
|
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
|
||||||
|
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*
|
*
|
||||||
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
||||||
|
@ -46,27 +55,28 @@
|
||||||
//
|
//
|
||||||
// This code has been modified significantly from the original.
|
// This code has been modified significantly from the original.
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright 2011 Intel Corporation
|
// Copyright 2011 Intel Corporation
|
||||||
// All Rights Reserved
|
// All Rights Reserved
|
||||||
//
|
//
|
||||||
// Permission is granted to use, copy, distribute and prepare derivative works of this
|
// Permission is granted to use, copy, distribute and prepare derivative works
|
||||||
// software for any purpose and without fee, provided, that the above copyright notice
|
// of this software for any purpose and without fee, provided, that the above
|
||||||
// and this statement appear in all copies. Intel makes no representations about the
|
// copyright notice and this statement appear in all copies. Intel makes no
|
||||||
// suitability of this software for any purpose. THIS SOFTWARE IS PROVIDED "AS IS."
|
// representations about the suitability of this software for any purpose. THIS
|
||||||
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
|
// SOFTWARE IS PROVIDED "AS IS." INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||||
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
|
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER
|
||||||
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
|
// INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR
|
||||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not
|
// INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE WARRANTIES OF
|
||||||
// assume any responsibility for any errors which may appear in this software nor any
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not assume
|
||||||
|
// any responsibility for any errors which may appear in this software nor any
|
||||||
// responsibility to update it.
|
// responsibility to update it.
|
||||||
//
|
//
|
||||||
//--------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "BC7Config.h"
|
#include "BPTCConfig.h"
|
||||||
#include "RGBAEndpoints.h"
|
#include "RGBAEndpoints.h"
|
||||||
#include "BC7Compressor.h"
|
#include "BPTCCompressor.h"
|
||||||
#include "BC7CompressionMode.h"
|
#include "CompressionMode.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -406,7 +416,11 @@ uint32 RGBACluster::GetPowerMethodIterations() {
|
||||||
return m_PowerMethodIterations;
|
return m_PowerMethodIterations;
|
||||||
}
|
}
|
||||||
|
|
||||||
double RGBACluster::QuantizedError(const RGBAVector &p1, const RGBAVector &p2, uint8 nBuckets, uint32 bitMask, const RGBAVector &errorMetricVec, const int pbits[2], int *indices) const {
|
double RGBACluster::QuantizedError(
|
||||||
|
const RGBAVector &p1, const RGBAVector &p2,
|
||||||
|
uint8 nBuckets, uint32 bitMask, const RGBAVector &errorMetricVec,
|
||||||
|
const int pbits[2], uint8 *indices
|
||||||
|
) const {
|
||||||
|
|
||||||
// nBuckets should be a power of two.
|
// nBuckets should be a power of two.
|
||||||
assert(nBuckets == 3 || !(nBuckets & (nBuckets - 1)));
|
assert(nBuckets == 3 || !(nBuckets & (nBuckets - 1)));
|
||||||
|
@ -415,7 +429,9 @@ double RGBACluster::QuantizedError(const RGBAVector &p1, const RGBAVector &p2, u
|
||||||
|
|
||||||
typedef uint32 tInterpPair[2];
|
typedef uint32 tInterpPair[2];
|
||||||
typedef tInterpPair tInterpLevel[16];
|
typedef tInterpPair tInterpLevel[16];
|
||||||
const tInterpLevel *interpVals = (nBuckets == 3)? kBC7InterpolationValues : kBC7InterpolationValues + (indexPrec - 1);
|
const tInterpLevel *interpVals =
|
||||||
|
(nBuckets == 3)? BPTCC::kInterpolationValues
|
||||||
|
: BPTCC::kInterpolationValues + (indexPrec - 1);
|
||||||
|
|
||||||
assert(indexPrec >= 2 && indexPrec <= 4);
|
assert(indexPrec >= 2 && indexPrec <= 4);
|
||||||
|
|
||||||
|
@ -441,7 +457,7 @@ double RGBACluster::QuantizedError(const RGBAVector &p1, const RGBAVector &p2, u
|
||||||
const uint8 *pb = (const uint8 *)(&pixel);
|
const uint8 *pb = (const uint8 *)(&pixel);
|
||||||
|
|
||||||
float minError = FLT_MAX;
|
float minError = FLT_MAX;
|
||||||
int bestBucket = -1;
|
uint8 bestBucket = 0;
|
||||||
for(int j = 0; j < nBuckets; j++) {
|
for(int j = 0; j < nBuckets; j++) {
|
||||||
|
|
||||||
uint32 interp0 = (*interpVals)[j][0];
|
uint32 interp0 = (*interpVals)[j][0];
|
||||||
|
|
|
@ -387,8 +387,12 @@ public:
|
||||||
Min = m_Min, Max = m_Max;
|
Min = m_Min, Max = m_Max;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the error if we were to quantize the colors right now with the given number of buckets and bit mask.
|
// Returns the error if we were to quantize the colors right now with the
|
||||||
double QuantizedError(const RGBAVector &p1, const RGBAVector &p2, uint8 nBuckets, uint32 bitMask, const RGBAVector &errorMetricVec, const int pbits[2] = NULL, int *indices = NULL) const;
|
// given number of buckets and bit mask.
|
||||||
|
double QuantizedError(
|
||||||
|
const RGBAVector &p1, const RGBAVector &p2,
|
||||||
|
uint8 nBuckets, uint32 bitMask, const RGBAVector &errorMetricVec,
|
||||||
|
const int pbits[2] = NULL, uint8 *indices = NULL) const;
|
||||||
|
|
||||||
// Returns the principal axis for this point cluster.
|
// Returns the principal axis for this point cluster.
|
||||||
double GetPrincipalEigenvalue();
|
double GetPrincipalEigenvalue();
|
||||||
|
|
|
@ -80,6 +80,7 @@ SET( SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
SET( HEADERS
|
SET( HEADERS
|
||||||
|
"include/BitStream.h"
|
||||||
"include/Color.h"
|
"include/Color.h"
|
||||||
"include/CompressionJob.h"
|
"include/CompressionJob.h"
|
||||||
"config/FasTCBaseConfig.h.in"
|
"config/FasTCBaseConfig.h.in"
|
||||||
|
|
|
@ -1,30 +1,39 @@
|
||||||
/* FasTC
|
/* FasTC
|
||||||
* Copyright (c) 2012 University of North Carolina at Chapel Hill. All rights reserved.
|
* Copyright (c) 2012 University of North Carolina at Chapel Hill.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software and its documentation for educational,
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
|
* documentation for educational, research, and non-profit purposes, without
|
||||||
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
|
* fee, and without a written agreement is hereby granted, provided that the
|
||||||
* in all copies.
|
* above copyright notice, this paragraph, and the following four paragraphs
|
||||||
|
* appear in all copies.
|
||||||
*
|
*
|
||||||
* Permission to incorporate this software into commercial products may be obtained by contacting the
|
* Permission to incorporate this software into commercial products may be
|
||||||
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
* obtained by contacting the authors or the Office of Technology Development
|
||||||
|
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
||||||
*
|
*
|
||||||
* This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill.
|
* This software program and documentation are copyrighted by the University of
|
||||||
* The software program and documentation are supplied "as is," without any accompanying services from the
|
* North Carolina at Chapel Hill. The software program and documentation are
|
||||||
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
|
* supplied "as is," without any accompanying services from the University of
|
||||||
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
|
* North Carolina at Chapel Hill or the authors. The University of North
|
||||||
* end-user understands that the program was developed for research purposes and is advised not to rely
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
||||||
* exclusively on the program for any reason.
|
* the program will be uninterrupted or error-free. The end-user understands
|
||||||
|
* that the program was developed for research purposes and is advised not to
|
||||||
|
* rely exclusively on the program for any reason.
|
||||||
*
|
*
|
||||||
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS BE LIABLE TO ANY PARTY FOR
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
||||||
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
||||||
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
|
||||||
|
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
*
|
*
|
||||||
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
||||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
||||||
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
|
||||||
|
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
|
||||||
|
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*
|
*
|
||||||
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
||||||
|
@ -46,25 +55,28 @@
|
||||||
//
|
//
|
||||||
// This code has been modified significantly from the original.
|
// This code has been modified significantly from the original.
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright 2011 Intel Corporation
|
// Copyright 2011 Intel Corporation
|
||||||
// All Rights Reserved
|
// All Rights Reserved
|
||||||
//
|
//
|
||||||
// Permission is granted to use, copy, distribute and prepare derivative works of this
|
// Permission is granted to use, copy, distribute and prepare derivative works
|
||||||
// software for any purpose and without fee, provided, that the above copyright notice
|
// of this software for any purpose and without fee, provided, that the above
|
||||||
// and this statement appear in all copies. Intel makes no representations about the
|
// copyright notice and this statement appear in all copies. Intel makes no
|
||||||
// suitability of this software for any purpose. THIS SOFTWARE IS PROVIDED "AS IS."
|
// representations about the suitability of this software for any purpose. THIS
|
||||||
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
|
// SOFTWARE IS PROVIDED "AS IS." INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||||
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
|
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER
|
||||||
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
|
// INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR
|
||||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not
|
// INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE WARRANTIES OF
|
||||||
// assume any responsibility for any errors which may appear in this software nor any
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not assume
|
||||||
|
// any responsibility for any errors which may appear in this software nor any
|
||||||
// responsibility to update it.
|
// responsibility to update it.
|
||||||
//
|
//
|
||||||
//--------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef __BITSTREAM_H__
|
#ifndef __BASE_INCLUDE_BITSTREAM_H__
|
||||||
#define __BITSTREAM_H__
|
#define __BASE_INCLUDE_BITSTREAM_H__
|
||||||
|
|
||||||
|
namespace FasTC {
|
||||||
|
|
||||||
class BitStream {
|
class BitStream {
|
||||||
public:
|
public:
|
||||||
|
@ -158,4 +170,7 @@ class BitStreamReadOnly {
|
||||||
const unsigned char *m_CurByte;
|
const unsigned char *m_CurByte;
|
||||||
int m_NextBit;
|
int m_NextBit;
|
||||||
};
|
};
|
||||||
#endif //__BITSTREAM_H__
|
|
||||||
|
} // namespace FasTC
|
||||||
|
|
||||||
|
#endif //__BASE_INCLUDE_BITSTREAM_H__
|
|
@ -1,30 +1,39 @@
|
||||||
/* FasTC
|
/* FasTC
|
||||||
* Copyright (c) 2012 University of North Carolina at Chapel Hill. All rights reserved.
|
* Copyright (c) 2014 University of North Carolina at Chapel Hill.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software and its documentation for educational,
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
|
* documentation for educational, research, and non-profit purposes, without
|
||||||
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
|
* fee, and without a written agreement is hereby granted, provided that the
|
||||||
* in all copies.
|
* above copyright notice, this paragraph, and the following four paragraphs
|
||||||
|
* appear in all copies.
|
||||||
*
|
*
|
||||||
* Permission to incorporate this software into commercial products may be obtained by contacting the
|
* Permission to incorporate this software into commercial products may be
|
||||||
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
* obtained by contacting the authors or the Office of Technology Development
|
||||||
|
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
||||||
*
|
*
|
||||||
* This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill.
|
* This software program and documentation are copyrighted by the University of
|
||||||
* The software program and documentation are supplied "as is," without any accompanying services from the
|
* North Carolina at Chapel Hill. The software program and documentation are
|
||||||
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
|
* supplied "as is," without any accompanying services from the University of
|
||||||
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
|
* North Carolina at Chapel Hill or the authors. The University of North
|
||||||
* end-user understands that the program was developed for research purposes and is advised not to rely
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
||||||
* exclusively on the program for any reason.
|
* the program will be uninterrupted or error-free. The end-user understands
|
||||||
|
* that the program was developed for research purposes and is advised not to
|
||||||
|
* rely exclusively on the program for any reason.
|
||||||
*
|
*
|
||||||
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS BE LIABLE TO ANY PARTY FOR
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
||||||
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
||||||
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
|
||||||
|
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
*
|
*
|
||||||
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
||||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
||||||
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
|
||||||
|
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
|
||||||
|
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*
|
*
|
||||||
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
||||||
|
@ -58,7 +67,7 @@ namespace FasTC {
|
||||||
|
|
||||||
// This structure defines a compression job. Here, width and height are the dimensions
|
// This structure defines a compression job. Here, width and height are the dimensions
|
||||||
// of the image in pixels. inBuf contains the R8G8B8A8 data that is to be compressed, and
|
// of the image in pixels. inBuf contains the R8G8B8A8 data that is to be compressed, and
|
||||||
// outBuf will contain the compressed BC7 data.
|
// outBuf will contain the compressed BPTC data.
|
||||||
//
|
//
|
||||||
// Implicit sizes:
|
// Implicit sizes:
|
||||||
// inBuf - (width * height * 4) bytes
|
// inBuf - (width * height * 4) bytes
|
||||||
|
@ -165,8 +174,8 @@ namespace FasTC {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// This struct mirrors that for a compression job, but is used to decompress a BC7 stream. Here, inBuf
|
// This struct mirrors that for a compression job, but is used to decompress a BPTC stream. Here, inBuf
|
||||||
// is a buffer of BC7 data, and outBuf is the destination where we will copy the decompressed R8G8B8A8 data
|
// is a buffer of BPTC data, and outBuf is the destination where we will copy the decompressed R8G8B8A8 data
|
||||||
class DecompressionJob {
|
class DecompressionJob {
|
||||||
private:
|
private:
|
||||||
const ECompressionFormat m_Format;
|
const ECompressionFormat m_Format;
|
||||||
|
|
|
@ -346,7 +346,7 @@ int main(int argc, char **argv) {
|
||||||
if(decompressedOutput[0] != '\0') {
|
if(decompressedOutput[0] != '\0') {
|
||||||
memcpy(basename, decompressedOutput, 256);
|
memcpy(basename, decompressedOutput, 256);
|
||||||
} else if(format == FasTC::eCompressionFormat_BPTC) {
|
} else if(format == FasTC::eCompressionFormat_BPTC) {
|
||||||
strcat(basename, "-bc7.png");
|
strcat(basename, "-bptc.png");
|
||||||
} else if(format == FasTC::eCompressionFormat_PVRTC) {
|
} else if(format == FasTC::eCompressionFormat_PVRTC) {
|
||||||
strcat(basename, "-pvrtc.png");
|
strcat(basename, "-pvrtc.png");
|
||||||
} else if(format == FasTC::eCompressionFormat_DXT1) {
|
} else if(format == FasTC::eCompressionFormat_DXT1) {
|
||||||
|
|
|
@ -1,30 +1,39 @@
|
||||||
# FasTC
|
# FasTC
|
||||||
# Copyright (c) 2012 University of North Carolina at Chapel Hill. All rights reserved.
|
# Copyright (c) 2014 University of North Carolina at Chapel Hill.
|
||||||
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Permission to use, copy, modify, and distribute this software and its documentation for educational,
|
# Permission to use, copy, modify, and distribute this software and its
|
||||||
# research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
|
# documentation for educational, research, and non-profit purposes, without
|
||||||
# provided that the above copyright notice, this paragraph, and the following four paragraphs appear
|
# fee, and without a written agreement is hereby granted, provided that the
|
||||||
# in all copies.
|
# above copyright notice, this paragraph, and the following four paragraphs
|
||||||
|
# appear in all copies.
|
||||||
#
|
#
|
||||||
# Permission to incorporate this software into commercial products may be obtained by contacting the
|
# Permission to incorporate this software into commercial products may be
|
||||||
# authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
# obtained by contacting the authors or the Office of Technology Development
|
||||||
|
# at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
||||||
#
|
#
|
||||||
# This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill.
|
# This software program and documentation are copyrighted by the University of
|
||||||
# The software program and documentation are supplied "as is," without any accompanying services from the
|
# North Carolina at Chapel Hill. The software program and documentation are
|
||||||
# University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
|
# supplied "as is," without any accompanying services from the University of
|
||||||
# and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
|
# North Carolina at Chapel Hill or the authors. The University of North
|
||||||
# end-user understands that the program was developed for research purposes and is advised not to rely
|
# Carolina at Chapel Hill and the authors do not warrant that the operation of
|
||||||
# exclusively on the program for any reason.
|
# the program will be uninterrupted or error-free. The end-user understands
|
||||||
|
# that the program was developed for research purposes and is advised not to
|
||||||
|
# rely exclusively on the program for any reason.
|
||||||
#
|
#
|
||||||
# IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS BE LIABLE TO ANY PARTY FOR
|
# IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
||||||
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
|
# AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
||||||
# USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
# OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
||||||
# AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
|
||||||
|
# AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
# DAMAGE.
|
||||||
#
|
#
|
||||||
# THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
# THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
||||||
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
# DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
# STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
||||||
# OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
# STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
|
||||||
|
# AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
|
||||||
|
# THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
# ENHANCEMENTS, OR MODIFICATIONS.
|
# ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
#
|
#
|
||||||
# Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
# Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
||||||
|
|
|
@ -1,30 +1,39 @@
|
||||||
/* FasTC
|
/* FasTC
|
||||||
* Copyright (c) 2012 University of North Carolina at Chapel Hill. All rights reserved.
|
* Copyright (c) 2014 University of North Carolina at Chapel Hill.
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software and its documentation for educational,
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
|
* documentation for educational, research, and non-profit purposes, without
|
||||||
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
|
* fee, and without a written agreement is hereby granted, provided that the
|
||||||
* in all copies.
|
* above copyright notice, this paragraph, and the following four paragraphs
|
||||||
|
* appear in all copies.
|
||||||
*
|
*
|
||||||
* Permission to incorporate this software into commercial products may be obtained by contacting the
|
* Permission to incorporate this software into commercial products may be
|
||||||
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
* obtained by contacting the authors or the Office of Technology Development
|
||||||
|
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
||||||
*
|
*
|
||||||
* This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill.
|
* This software program and documentation are copyrighted by the University of
|
||||||
* The software program and documentation are supplied "as is," without any accompanying services from the
|
* North Carolina at Chapel Hill. The software program and documentation are
|
||||||
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
|
* supplied "as is," without any accompanying services from the University of
|
||||||
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
|
* North Carolina at Chapel Hill or the authors. The University of North
|
||||||
* end-user understands that the program was developed for research purposes and is advised not to rely
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
||||||
* exclusively on the program for any reason.
|
* the program will be uninterrupted or error-free. The end-user understands
|
||||||
|
* that the program was developed for research purposes and is advised not to
|
||||||
|
* rely exclusively on the program for any reason.
|
||||||
*
|
*
|
||||||
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS BE LIABLE TO ANY PARTY FOR
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
||||||
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
||||||
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
|
||||||
|
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
* DAMAGE.
|
||||||
*
|
*
|
||||||
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
||||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
||||||
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
|
||||||
|
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
|
||||||
|
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*
|
*
|
||||||
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
||||||
|
@ -51,7 +60,7 @@
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
|
|
||||||
#include "TexCompTypes.h"
|
#include "TexCompTypes.h"
|
||||||
#include "BC7Compressor.h"
|
#include "BPTCCompressor.h"
|
||||||
#include "PVRTCCompressor.h"
|
#include "PVRTCCompressor.h"
|
||||||
#include "DXTCompressor.h"
|
#include "DXTCompressor.h"
|
||||||
#include "ETCCompressor.h"
|
#include "ETCCompressor.h"
|
||||||
|
@ -135,7 +144,7 @@ bool CompressedImage::DecompressImage(unsigned char *outBuf, unsigned int outBuf
|
||||||
|
|
||||||
case FasTC::eCompressionFormat_BPTC:
|
case FasTC::eCompressionFormat_BPTC:
|
||||||
{
|
{
|
||||||
BC7C::Decompress(dj);
|
BPTCC::Decompress(dj);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
|
|
||||||
#include "ETCCompressor.h"
|
#include "ETCCompressor.h"
|
||||||
#include "DXTCompressor.h"
|
#include "DXTCompressor.h"
|
||||||
#include "BC7Compressor.h"
|
#include "BPTCCompressor.h"
|
||||||
#include "CompressionFuncs.h"
|
#include "CompressionFuncs.h"
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
#include "ImageFile.h"
|
#include "ImageFile.h"
|
||||||
|
@ -104,12 +104,12 @@ static CompressionFuncWithStats ChooseFuncFromSettingsWithStats(const SCompress
|
||||||
|
|
||||||
case FasTC::eCompressionFormat_BPTC:
|
case FasTC::eCompressionFormat_BPTC:
|
||||||
{
|
{
|
||||||
#ifdef FOUND_NVTT_BC7_EXPORT
|
#ifdef FOUND_NVTT_BPTC_EXPORT
|
||||||
if(s.bUseNVTT)
|
if(s.bUseNVTT)
|
||||||
return BC7C::CompressNVTTWithStats;
|
return BPTCC::CompressNVTTWithStats;
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
return BC7C::CompressWithStats;
|
return BPTCC::CompressWithStats;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -135,19 +135,19 @@ static CompressionFunc ChooseFuncFromSettings(const SCompressionSettings &s) {
|
||||||
switch(s.format) {
|
switch(s.format) {
|
||||||
case FasTC::eCompressionFormat_BPTC:
|
case FasTC::eCompressionFormat_BPTC:
|
||||||
{
|
{
|
||||||
BC7C::SetQualityLevel(s.iQuality);
|
BPTCC::SetQualityLevel(s.iQuality);
|
||||||
#ifdef HAS_SSE_41
|
#ifdef HAS_SSE_41
|
||||||
if(s.bUseSIMD) {
|
if(s.bUseSIMD) {
|
||||||
return BC7C::CompressImageBC7SIMD;
|
return BPTCC::CompressImageBPTCSIMD;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FOUND_NVTT_BC7_EXPORT
|
#ifdef FOUND_NVTT_BPTC_EXPORT
|
||||||
if(s.bUseNVTT)
|
if(s.bUseNVTT)
|
||||||
return BC7C::CompressNVTT;
|
return BPTCC::CompressNVTT;
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
return BC7C::Compress;
|
return BPTCC::Compress;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -232,8 +232,8 @@ class AtomicThreadUnit : public TCCallable {
|
||||||
virtual ~AtomicThreadUnit() { }
|
virtual ~AtomicThreadUnit() { }
|
||||||
virtual void operator()() {
|
virtual void operator()() {
|
||||||
m_Barrier->Wait();
|
m_Barrier->Wait();
|
||||||
if(m_CmpFnc == BC7C::Compress) {
|
if(m_CmpFnc == BPTCC::Compress) {
|
||||||
BC7C::CompressAtomic(m_CompressionJobList);
|
BPTCC::CompressAtomic(m_CompressionJobList);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(!"I don't know what we're compressing...");
|
assert(!"I don't know what we're compressing...");
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ThreadGroup.h"
|
#include "ThreadGroup.h"
|
||||||
#include "BC7Compressor.h"
|
#include "BPTCCompressor.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "BC7Compressor.h"
|
#include "BPTCCompressor.h"
|
||||||
|
|
||||||
using FasTC::CompressionJob;
|
using FasTC::CompressionJob;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue