mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2025-01-09 16:25:32 +00:00
Add comments to BC7CompressionMode.h
This commit is contained in:
parent
a19f83d123
commit
921c3e9f16
|
@ -83,14 +83,24 @@ static const int kPBits[4][2] = {
|
||||||
// Abstract class that outlines all of the different settings for BC7 compression modes
|
// 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.
|
// Note that at the moment, we only support modes 0-3, so we don't deal with alpha channels.
|
||||||
class BC7CompressionMode {
|
class BC7CompressionMode {
|
||||||
public:
|
|
||||||
|
public:
|
||||||
|
|
||||||
static const uint32 kMaxNumSubsets = 3;
|
static const uint32 kMaxNumSubsets = 3;
|
||||||
static const uint32 kNumModes = 8;
|
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() { }
|
~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);
|
double Compress(BitStream &stream, const int shapeIdx, const RGBACluster *clusters);
|
||||||
|
|
||||||
// This switch controls the quality of the simulated annealing optimizer. We will not make
|
// 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 int MaxAnnealingIterations; // This is a setting
|
||||||
static const int kMaxAnnealingIterations = 256; // This is a limit
|
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 {
|
enum EPBitType {
|
||||||
ePBitType_Shared,
|
ePBitType_Shared,
|
||||||
ePBitType_NotShared,
|
ePBitType_NotShared,
|
||||||
ePBitType_None
|
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 {
|
static struct Attributes {
|
||||||
int modeNumber;
|
int modeNumber;
|
||||||
int numPartitionBits;
|
int numPartitionBits;
|
||||||
|
@ -118,12 +132,13 @@ public:
|
||||||
EPBitType pbitType;
|
EPBitType pbitType;
|
||||||
} kModeAttributes[kNumModes];
|
} kModeAttributes[kNumModes];
|
||||||
|
|
||||||
|
// This returns the above attributes structure for the given mode.
|
||||||
static const Attributes *GetAttributesForMode(int mode) {
|
static const Attributes *GetAttributesForMode(int mode) {
|
||||||
if(mode < 0 || mode >= 8) return NULL;
|
if(mode < 0 || mode >= 8) return NULL;
|
||||||
return &kModeAttributes[mode];
|
return &kModeAttributes[mode];
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const double m_IsOpaque;
|
const double m_IsOpaque;
|
||||||
const Attributes *const m_Attributes;
|
const Attributes *const m_Attributes;
|
||||||
|
@ -135,8 +150,8 @@ private:
|
||||||
void SetRotationMode(int mode) { m_RotateMode = mode; }
|
void SetRotationMode(int mode) { m_RotateMode = mode; }
|
||||||
|
|
||||||
int GetRotationMode() const { return m_Attributes->hasRotation? m_RotateMode : 0; }
|
int GetRotationMode() const { return m_Attributes->hasRotation? m_RotateMode : 0; }
|
||||||
|
|
||||||
int GetModeNumber() const { return m_Attributes->modeNumber; }
|
int GetModeNumber() const { return m_Attributes->modeNumber; }
|
||||||
|
|
||||||
int GetNumberOfPartitionBits() const { return m_Attributes->numPartitionBits; }
|
int GetNumberOfPartitionBits() const { return m_Attributes->numPartitionBits; }
|
||||||
int GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
|
int GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
|
||||||
|
|
||||||
|
@ -162,6 +177,7 @@ private:
|
||||||
return m_Attributes->alphaChannelPrecision;
|
return m_Attributes->alphaChannelPrecision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 = BC7C::GetErrorMetric();
|
||||||
switch(GetRotationMode()) {
|
switch(GetRotationMode()) {
|
||||||
|
@ -175,6 +191,9 @@ private:
|
||||||
|
|
||||||
EPBitType GetPBitType() const { return m_Attributes->pbitType; }
|
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 {
|
unsigned int GetQuantizationMask() const {
|
||||||
const int maskSeed = 0x80000000;
|
const int maskSeed = 0x80000000;
|
||||||
const uint32 alphaPrec = GetAlphaChannelPrecision();
|
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(
|
double OptimizeEndpointsForCluster(
|
||||||
const RGBACluster &cluster,
|
const RGBACluster &cluster,
|
||||||
RGBAVector &p1, RGBAVector &p2,
|
RGBAVector &p1, RGBAVector &p2,
|
||||||
|
@ -221,6 +243,9 @@ private:
|
||||||
int &bestPbitCombo
|
int &bestPbitCombo
|
||||||
) const;
|
) 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(
|
void PickBestNeighboringEndpoints(
|
||||||
const RGBACluster &cluster,
|
const RGBACluster &cluster,
|
||||||
const RGBAVector &p1, const RGBAVector &p2,
|
const RGBAVector &p1, const RGBAVector &p2,
|
||||||
|
@ -232,12 +257,27 @@ private:
|
||||||
float stepSz = 1.0f
|
float stepSz = 1.0f
|
||||||
) const;
|
) 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;
|
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;
|
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;
|
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;
|
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;
|
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2, int &bestPBitCombo) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue