Add comments to BC7CompressionMode.h

This commit is contained in:
Pavel Krajcevski 2013-03-20 23:27:17 -04:00
parent a19f83d123
commit 921c3e9f16

View File

@ -83,14 +83,24 @@ static const int kPBits[4][2] = {
// Abstract class that outlines all of the different settings for BC7 compression modes
// Note that at the moment, we only support modes 0-3, so we don't deal with alpha channels.
class BC7CompressionMode {
public:
static const uint32 kMaxNumSubsets = 3;
static const uint32 kNumModes = 8;
explicit BC7CompressionMode(int mode, bool opaque = true) : m_IsOpaque(opaque), m_Attributes(&(kModeAttributes[mode])), m_RotateMode(0), m_IndexMode(0) { }
// 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 the block is opaque or not.
explicit BC7CompressionMode(int mode, bool opaque = true)
: m_IsOpaque(opaque)
, m_Attributes(&(kModeAttributes[mode]))
, m_RotateMode(0)
, m_IndexMode(0)
{ }
~BC7CompressionMode() { }
// This function compresses a group of clusters into the passed bitstream. The size of the
// clusters array is determined by the BC7 compression mode.
double Compress(BitStream &stream, const int shapeIdx, const RGBACluster *clusters);
// This switch controls the quality of the simulated annealing optimizer. We will not make
@ -99,12 +109,16 @@ public:
static int MaxAnnealingIterations; // This is a setting
static const int kMaxAnnealingIterations = 256; // This is a limit
// P-bits are low-order bits that are shared across color channels. This enum says whether or not
// both endpoints share a p-bit or whether or not they even have a p-bit.
enum EPBitType {
ePBitType_Shared,
ePBitType_NotShared,
ePBitType_None
};
// These are all the per-mode attributes that can be set. They are specified in a table
// and we access them through the private m_Attributes variable.
static struct Attributes {
int modeNumber;
int numPartitionBits;
@ -118,6 +132,7 @@ public:
EPBitType pbitType;
} kModeAttributes[kNumModes];
// This returns the above attributes structure for the given mode.
static const Attributes *GetAttributesForMode(int mode) {
if(mode < 0 || mode >= 8) return NULL;
return &kModeAttributes[mode];
@ -135,8 +150,8 @@ private:
void SetRotationMode(int mode) { m_RotateMode = mode; }
int GetRotationMode() const { return m_Attributes->hasRotation? m_RotateMode : 0; }
int GetModeNumber() const { return m_Attributes->modeNumber; }
int GetNumberOfPartitionBits() const { return m_Attributes->numPartitionBits; }
int GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
@ -162,6 +177,7 @@ private:
return m_Attributes->alphaChannelPrecision;
}
// This returns the proper error metric even if we have rotation bits set
RGBAVector GetErrorMetric() const {
const float *w = BC7C::GetErrorMetric();
switch(GetRotationMode()) {
@ -175,6 +191,9 @@ private:
EPBitType GetPBitType() const { return m_Attributes->pbitType; }
// This function creates an integer that represents the maximum values in each
// channel. We can use this to figure out the proper endpoint values for a given
// mode.
unsigned int GetQuantizationMask() const {
const int maskSeed = 0x80000000;
const uint32 alphaPrec = GetAlphaChannelPrecision();
@ -214,6 +233,9 @@ private:
}
}
// This performs simulated annealing on the endpoints p1 and p2 based on the
// current MaxAnnealingIterations. This is set by calling the function
// SetQualityLevel
double OptimizeEndpointsForCluster(
const RGBACluster &cluster,
RGBAVector &p1, RGBAVector &p2,
@ -221,6 +243,9 @@ private:
int &bestPbitCombo
) const;
// This function performs the heuristic to choose the "best" neighboring
// endpoints to p1 and p2 based on the compression mode (index precision,
// endpoint precision etc)
void PickBestNeighboringEndpoints(
const RGBACluster &cluster,
const RGBAVector &p1, const RGBAVector &p2,
@ -232,12 +257,27 @@ private:
float stepSz = 1.0f
) const;
// This is used by simulated annealing to determine whether or not the newError
// (from the neighboring endpoints) is sufficient to continue the annealing process
// from these new endpoints based on how good the oldError was, and how long we've
// been annealing (temp)
bool AcceptNewEndpointError(double newError, double oldError, float temp) const;
// This function figures out the best compression for the single color p, and places
// the endpoints in p1 and p2. If the compression mode supports p-bits, then we
// choose the best p-bit combo and return it as well.
double CompressSingleColor(const RGBAVector &p, RGBAVector &p1, RGBAVector &p2, int &bestPbitCombo) const;
// Compress the cluster using a generalized cluster fit. This figures out the proper endpoints
// assuming that we have no alpha.
double CompressCluster(const RGBACluster &cluster, RGBAVector &p1, RGBAVector &p2, int *bestIndices, int &bestPbitCombo) const;
// 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 computed as well.
double CompressCluster(const RGBACluster &cluster, RGBAVector &p1, RGBAVector &p2, int *bestIndices, int *alphaIndices) const;
// 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 possible pbit values)
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2, int &bestPBitCombo) const;
};