mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2025-01-23 09:41:10 +00:00
Fix a lot of compiler warnings.
This commit is contained in:
parent
28a55cc268
commit
5dd1fbbd48
|
@ -124,6 +124,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
const double m_IsOpaque;
|
||||||
const Attributes *const m_Attributes;
|
const Attributes *const m_Attributes;
|
||||||
|
|
||||||
int m_RotateMode;
|
int m_RotateMode;
|
||||||
|
@ -238,8 +239,6 @@ private:
|
||||||
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;
|
||||||
|
|
||||||
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2, int &bestPBitCombo) const;
|
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2, int &bestPBitCombo) const;
|
||||||
|
|
||||||
const double m_IsOpaque;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const uint32 kBC7InterpolationValues[4][16][2];
|
extern const uint32 kBC7InterpolationValues[4][16][2];
|
||||||
|
|
|
@ -207,7 +207,7 @@ static inline T sad(const T &a, const T &b) {
|
||||||
return (a > b)? a - b : b - a;
|
return (a > b)? a - b : b - a;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetSubsetForIndex(int idx, const int shapeIdx, const int nSubsets) {
|
static uint8 GetSubsetForIndex(int idx, const int shapeIdx, const int nSubsets) {
|
||||||
int subset = 0;
|
int subset = 0;
|
||||||
|
|
||||||
switch(nSubsets) {
|
switch(nSubsets) {
|
||||||
|
@ -233,7 +233,7 @@ static int GetSubsetForIndex(int idx, const int shapeIdx, const int nSubsets) {
|
||||||
return subset;
|
return subset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetAnchorIndexForSubset(int subset, const int shapeIdx, const int nSubsets) {
|
static uint32 GetAnchorIndexForSubset(int subset, const int shapeIdx, const int nSubsets) {
|
||||||
|
|
||||||
int anchorIdx = 0;
|
int anchorIdx = 0;
|
||||||
switch(subset) {
|
switch(subset) {
|
||||||
|
@ -262,57 +262,15 @@ static int GetAnchorIndexForSubset(int subset, const int shapeIdx, const int nSu
|
||||||
return anchorIdx;
|
return anchorIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetPointMaskForSubset(int subset, const int shapeIdx, const int nSubsets) {
|
template <typename T>
|
||||||
int mask = 0xFFFF;
|
static T min(const T &a, const T &b) {
|
||||||
|
return (a < b)? a : b;
|
||||||
assert(subset < nSubsets);
|
|
||||||
|
|
||||||
switch(nSubsets) {
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
mask = (subset)? kShapeMask2[shapeIdx] : ~(kShapeMask2[shapeIdx]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
{
|
|
||||||
switch(subset) {
|
|
||||||
default:
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
mask = ~(kShapeMask3[shapeIdx][0]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
mask = ~(~(kShapeMask3[shapeIdx][0]) | kShapeMask3[shapeIdx][1]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
mask = kShapeMask3[shapeIdx][1];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef min
|
template <typename T>
|
||||||
#define min(a, b) (((a) > (b))? (b) : (a))
|
static T max(const T &a, const T &b) {
|
||||||
#endif
|
return (a > b)? a : b;
|
||||||
|
}
|
||||||
#ifndef max
|
|
||||||
#define max(a, b) (((a) > (b))? (a) : (b))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void insert(T* buf, int bufSz, T newVal, int idx = 0) {
|
static void insert(T* buf, int bufSz, T newVal, int idx = 0) {
|
||||||
|
@ -327,9 +285,9 @@ 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] = {
|
const uint32 kBC7InterpolationValues[4][16][2] = {
|
||||||
{ {64, 0}, {33, 31}, {0, 64}, 0, 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} },
|
||||||
{ {64, 0}, {43, 21}, {21, 43}, {0, 64}, 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}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} },
|
||||||
{ {64, 0}, {55, 9}, {46, 18}, {37, 27}, {27, 37}, {18, 46}, {9, 55}, {0, 64}, 0, 0, 0, 0, 0, 0, 0, 0 },
|
{ {64, 0}, {55, 9}, {46, 18}, {37, 27}, {27, 37}, {18, 46}, {9, 55}, {0, 64}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} },
|
||||||
{ {64, 0}, {60, 4}, {55, 9}, {51, 13}, {47, 17}, {43, 21}, {38, 26}, {34, 30}, {30, 34}, {26, 38}, {21, 43}, {17, 47}, {13, 51}, {9, 55}, {4, 60}, {0, 64} }
|
{ {64, 0}, {60, 4}, {55, 9}, {51, 13}, {47, 17}, {43, 21}, {38, 26}, {34, 30}, {30, 34}, {26, 38}, {21, 43}, {17, 47}, {13, 51}, {9, 55}, {4, 60}, {0, 64} }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -403,7 +361,7 @@ double BC7CompressionMode::CompressSingleColor(const RGBAVector &p, RGBAVector &
|
||||||
uint32 bestValI[kNumColorChannels] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
|
uint32 bestValI[kNumColorChannels] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
|
||||||
uint32 bestValJ[kNumColorChannels] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
|
uint32 bestValJ[kNumColorChannels] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
|
||||||
|
|
||||||
for(int ci = 0; ci < kNumColorChannels; ci++) {
|
for(uint32 ci = 0; ci < kNumColorChannels; ci++) {
|
||||||
|
|
||||||
const uint8 val = (pixel >> (ci * 8)) & 0xFF;
|
const uint8 val = (pixel >> (ci * 8)) & 0xFF;
|
||||||
int nBits = ci == 3? GetAlphaChannelPrecision() : m_Attributes->colorChannelPrecision;
|
int nBits = ci == 3? GetAlphaChannelPrecision() : m_Attributes->colorChannelPrecision;
|
||||||
|
@ -467,7 +425,7 @@ double BC7CompressionMode::CompressSingleColor(const RGBAVector &p, RGBAVector &
|
||||||
bestDist = dist;
|
bestDist = dist;
|
||||||
bestPbitCombo = pbi;
|
bestPbitCombo = pbi;
|
||||||
|
|
||||||
for(int ci = 0; ci < kNumColorChannels; ci++) {
|
for(uint32 ci = 0; ci < kNumColorChannels; ci++) {
|
||||||
p1.c[ci] = float(bestValI[ci]);
|
p1.c[ci] = float(bestValI[ci]);
|
||||||
p2.c[ci] = float(bestValJ[ci]);
|
p2.c[ci] = float(bestValJ[ci]);
|
||||||
}
|
}
|
||||||
|
@ -609,7 +567,7 @@ void BC7CompressionMode::PickBestNeighboringEndpoints(const RGBACluster &cluster
|
||||||
else
|
else
|
||||||
ChangePointForDirWithoutPbitChange(np, fastrand() % 16, step);
|
ChangePointForDirWithoutPbitChange(np, fastrand() % 16, step);
|
||||||
|
|
||||||
for(int i = 0; i < kNumColorChannels; i++) {
|
for(uint32 i = 0; i < kNumColorChannels; i++) {
|
||||||
np.c[i] = min(max(np.c[i], 0.0f), 255.0f);
|
np.c[i] = min(max(np.c[i], 0.0f), 255.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -662,7 +620,6 @@ bool BC7CompressionMode::AcceptNewEndpointError(double newError, double oldError
|
||||||
double BC7CompressionMode::OptimizeEndpointsForCluster(const RGBACluster &cluster, RGBAVector &p1, RGBAVector &p2, int *bestIndices, int &bestPbitCombo) const {
|
double BC7CompressionMode::OptimizeEndpointsForCluster(const RGBACluster &cluster, RGBAVector &p1, RGBAVector &p2, int *bestIndices, int &bestPbitCombo) const {
|
||||||
|
|
||||||
const int nBuckets = (1 << GetNumberOfBitsPerIndex());
|
const int nBuckets = (1 << GetNumberOfBitsPerIndex());
|
||||||
const int nPbitCombos = GetNumPbitCombos();
|
|
||||||
const uint32 qmask = GetQuantizationMask();
|
const uint32 qmask = GetQuantizationMask();
|
||||||
|
|
||||||
// Here we use simulated annealing to traverse the space of clusters to find the best possible endpoints.
|
// Here we use simulated annealing to traverse the space of clusters to find the best possible endpoints.
|
||||||
|
@ -816,16 +773,13 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
const tInterpLevel *interpVals = kBC7InterpolationValues + (GetNumberOfBitsPerAlpha() - 1);
|
const tInterpLevel *interpVals = kBC7InterpolationValues + (GetNumberOfBitsPerAlpha() - 1);
|
||||||
const float weight = GetErrorMetric().a;
|
const float weight = GetErrorMetric().a;
|
||||||
|
|
||||||
const int nBuckets = (1 << GetNumberOfBitsPerAlpha());
|
const uint32 nBuckets = (1 << GetNumberOfBitsPerAlpha());
|
||||||
|
|
||||||
// If they're the same, then we can get them exactly.
|
// If they're the same, then we can get them exactly.
|
||||||
if(a1 == a2)
|
if(a1 == a2)
|
||||||
{
|
{
|
||||||
const uint8 step = 1 << (8-GetAlphaChannelPrecision());
|
|
||||||
const uint8 a1be = uint8(a1);
|
const uint8 a1be = uint8(a1);
|
||||||
const uint8 a2be = uint8(a2);
|
const uint8 a2be = uint8(a2);
|
||||||
const uint8 a1b = ::QuantizeChannel(a1be, (((char)0x80) >> (GetAlphaChannelPrecision() - 1)));
|
|
||||||
const uint8 a2b = ::QuantizeChannel(a2be, (((char)0x80) >> (GetAlphaChannelPrecision() - 1)));
|
|
||||||
|
|
||||||
// Mode 5 has 8 bits of precision for alpha.
|
// Mode 5 has 8 bits of precision for alpha.
|
||||||
if(GetModeNumber() == 5) {
|
if(GetModeNumber() == 5) {
|
||||||
|
@ -833,7 +787,7 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
assert(a1 == float(a1b));
|
assert(a1 == float(a1b));
|
||||||
assert(a2 == float(a2b));
|
assert(a2 == float(a2b));
|
||||||
|
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++)
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++)
|
||||||
alphaIndices[i] = 0;
|
alphaIndices[i] = 0;
|
||||||
|
|
||||||
alphaError = 0.0;
|
alphaError = 0.0;
|
||||||
|
@ -852,11 +806,11 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_IndexMode == 1) {
|
if(m_IndexMode == 1) {
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++)
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++)
|
||||||
alphaIndices[i] = 1;
|
alphaIndices[i] = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++)
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++)
|
||||||
alphaIndices[i] = 2;
|
alphaIndices[i] = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -874,18 +828,18 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
float vals[1<<3];
|
float vals[1<<3];
|
||||||
memset(vals, 0, sizeof(vals));
|
memset(vals, 0, sizeof(vals));
|
||||||
|
|
||||||
int buckets[kMaxNumDataPoints];
|
uint32 buckets[kMaxNumDataPoints];
|
||||||
|
|
||||||
// Figure out initial positioning.
|
// Figure out initial positioning.
|
||||||
for(int i = 0; i < nBuckets; i++) {
|
for(uint32 i = 0; i < nBuckets; i++) {
|
||||||
vals[i] = alphaMin + (float(i)/float(nBuckets-1)) * (alphaMax - alphaMin);
|
vals[i] = alphaMin + (float(i)/float(nBuckets-1)) * (alphaMax - alphaMin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign each value to a bucket
|
// Assign each value to a bucket
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
|
||||||
|
|
||||||
float minDist = 255.0f;
|
float minDist = 255.0f;
|
||||||
for(int j = 0; j < nBuckets; j++) {
|
for(uint32 j = 0; j < nBuckets; j++) {
|
||||||
float dist = fabs(alphaVals[i] - vals[j]);
|
float dist = fabs(alphaVals[i] - vals[j]);
|
||||||
if(dist < minDist) {
|
if(dist < minDist) {
|
||||||
minDist = dist;
|
minDist = dist;
|
||||||
|
@ -906,8 +860,8 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
memset(avg, 0, sizeof(avg));
|
memset(avg, 0, sizeof(avg));
|
||||||
|
|
||||||
// Calculate average of each cluster
|
// Calculate average of each cluster
|
||||||
for(int i = 0; i < nBuckets; i++) {
|
for(uint32 i = 0; i < nBuckets; i++) {
|
||||||
for(int j = 0; j < kMaxNumDataPoints; j++) {
|
for(uint32 j = 0; j < kMaxNumDataPoints; j++) {
|
||||||
|
|
||||||
if(buckets[j] == i) {
|
if(buckets[j] == i) {
|
||||||
avg[i] += alphaVals[j];
|
avg[i] += alphaVals[j];
|
||||||
|
@ -921,7 +875,7 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
|
|
||||||
// Did we change anything?
|
// Did we change anything?
|
||||||
fixed = true;
|
fixed = true;
|
||||||
for(int i = 0; i < nBuckets; i++) {
|
for(uint32 i = 0; i < nBuckets; i++) {
|
||||||
fixed = fixed && (avg[i] == vals[i]);
|
fixed = fixed && (avg[i] == vals[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -929,10 +883,10 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
memcpy(vals, avg, sizeof(vals));
|
memcpy(vals, avg, sizeof(vals));
|
||||||
|
|
||||||
// Reassign each value to a bucket
|
// Reassign each value to a bucket
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
|
||||||
|
|
||||||
float minDist = 255.0f;
|
float minDist = 255.0f;
|
||||||
for(int j = 0; j < nBuckets; j++) {
|
for(uint32 j = 0; j < nBuckets; j++) {
|
||||||
float dist = fabs(alphaVals[i] - vals[j]);
|
float dist = fabs(alphaVals[i] - vals[j]);
|
||||||
if(dist < minDist) {
|
if(dist < minDist) {
|
||||||
minDist = dist;
|
minDist = dist;
|
||||||
|
@ -945,7 +899,7 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
// Do least squares fit of vals.
|
// Do least squares fit of vals.
|
||||||
float asq = 0.0, bsq = 0.0, ab = 0.0;
|
float asq = 0.0, bsq = 0.0, ab = 0.0;
|
||||||
float ax(0.0), bx(0.0);
|
float ax(0.0), bx(0.0);
|
||||||
for(int i = 0; i < nBuckets; i++) {
|
for(uint32 i = 0; i < nBuckets; i++) {
|
||||||
float a = float(nBuckets - 1 - i) / float(nBuckets - 1);
|
float a = float(nBuckets - 1 - i) / float(nBuckets - 1);
|
||||||
float b = float(i) / float(nBuckets - 1);
|
float b = float(i) / float(nBuckets - 1);
|
||||||
|
|
||||||
|
@ -974,14 +928,14 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
|
|
||||||
// Compute error
|
// Compute error
|
||||||
alphaError = 0.0;
|
alphaError = 0.0;
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
|
||||||
|
|
||||||
uint8 val = uint8(alphaVals[i]);
|
uint8 val = uint8(alphaVals[i]);
|
||||||
|
|
||||||
float minError = FLT_MAX;
|
float minError = FLT_MAX;
|
||||||
int bestBucket = -1;
|
int bestBucket = -1;
|
||||||
|
|
||||||
for(int j = 0; j < nBuckets; j++) {
|
for(uint32 j = 0; j < nBuckets; j++) {
|
||||||
uint32 interp0 = (*interpVals)[j][0];
|
uint32 interp0 = (*interpVals)[j][0];
|
||||||
uint32 interp1 = (*interpVals)[j][1];
|
uint32 interp1 = (*interpVals)[j][1];
|
||||||
|
|
||||||
|
@ -1000,7 +954,7 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < kNumColorChannels; i++) {
|
for(uint32 i = 0; i < kNumColorChannels; i++) {
|
||||||
p1.c[i] = (i == (kNumColorChannels-1))? a1 : rgbp1.c[i];
|
p1.c[i] = (i == (kNumColorChannels-1))? a1 : rgbp1.c[i];
|
||||||
p2.c[i] = (i == (kNumColorChannels-1))? a2 : rgbp2.c[i];
|
p2.c[i] = (i == (kNumColorChannels-1))? a2 : rgbp2.c[i];
|
||||||
}
|
}
|
||||||
|
@ -1025,8 +979,6 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
|
||||||
}
|
}
|
||||||
|
|
||||||
const int nBuckets = (1 << GetNumberOfBitsPerIndex());
|
const int nBuckets = (1 << GetNumberOfBitsPerIndex());
|
||||||
const int nPbitCombos = GetNumPbitCombos();
|
|
||||||
const uint32 qmask = GetQuantizationMask();
|
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
RGBAVector avg = cluster.GetTotal() / float(cluster.GetNumPoints());
|
RGBAVector avg = cluster.GetTotal() / float(cluster.GetNumPoints());
|
||||||
|
@ -1452,7 +1404,6 @@ namespace BC7C
|
||||||
ErrorMetric GetErrorMetricEnum() { return gErrorMetric; }
|
ErrorMetric GetErrorMetricEnum() { return gErrorMetric; }
|
||||||
|
|
||||||
// Function prototypes
|
// Function prototypes
|
||||||
static void ExtractBlock(const uint8* inPtr, int width, uint32* colorBlock);
|
|
||||||
static void CompressBC7Block(const uint32 *block, uint8 *outBuf);
|
static void CompressBC7Block(const uint32 *block, uint8 *outBuf);
|
||||||
static void CompressBC7Block(const uint32 *block, uint8 *outBuf, BlockStatManager &statManager);
|
static void CompressBC7Block(const uint32 *block, uint8 *outBuf, BlockStatManager &statManager);
|
||||||
|
|
||||||
|
@ -1599,17 +1550,6 @@ namespace BC7C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract a 4 by 4 block of pixels from inPtr and store it in colorBlock. The width parameter
|
|
||||||
// specifies the size of the image in pixels.
|
|
||||||
static void ExtractBlock(const uint8* inPtr, int width, uint32* colorBlock)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < 4; j++)
|
|
||||||
{
|
|
||||||
memcpy(&colorBlock[j * 4], inPtr, 4 * 4);
|
|
||||||
inPtr += width * 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static double CompressTwoClusters(
|
static double CompressTwoClusters(
|
||||||
int shapeIdx,
|
int shapeIdx,
|
||||||
const RGBACluster *clusters,
|
const RGBACluster *clusters,
|
||||||
|
@ -1712,7 +1652,7 @@ namespace BC7C
|
||||||
|
|
||||||
static void PopulateTwoClustersForShape(const RGBACluster &points, int shapeIdx, RGBACluster *clusters) {
|
static void PopulateTwoClustersForShape(const RGBACluster &points, int shapeIdx, RGBACluster *clusters) {
|
||||||
const uint16 shape = kShapeMask2[shapeIdx];
|
const uint16 shape = kShapeMask2[shapeIdx];
|
||||||
for(int pt = 0; pt < kMaxNumDataPoints; pt++) {
|
for(uint32 pt = 0; pt < kMaxNumDataPoints; pt++) {
|
||||||
|
|
||||||
const RGBAVector &p = points.GetPoint(pt);
|
const RGBAVector &p = points.GetPoint(pt);
|
||||||
|
|
||||||
|
@ -1728,7 +1668,7 @@ namespace BC7C
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PopulateThreeClustersForShape(const RGBACluster &points, int shapeIdx, RGBACluster *clusters) {
|
static void PopulateThreeClustersForShape(const RGBACluster &points, int shapeIdx, RGBACluster *clusters) {
|
||||||
for(int pt = 0; pt < kMaxNumDataPoints; pt++) {
|
for(uint32 pt = 0; pt < kMaxNumDataPoints; pt++) {
|
||||||
|
|
||||||
const RGBAVector &p = points.GetPoint(pt);
|
const RGBAVector &p = points.GetPoint(pt);
|
||||||
|
|
||||||
|
@ -1813,7 +1753,7 @@ namespace BC7C
|
||||||
bool opaque = true;
|
bool opaque = true;
|
||||||
bool transparent = true;
|
bool transparent = true;
|
||||||
|
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
|
||||||
RGBAVector p = RGBAVector(i, block[i]);
|
RGBAVector p = RGBAVector(i, block[i]);
|
||||||
blockCluster.AddPoint(p);
|
blockCluster.AddPoint(p);
|
||||||
if(fabs(p.a - 255.0f) > 1e-10)
|
if(fabs(p.a - 255.0f) > 1e-10)
|
||||||
|
@ -1836,7 +1776,7 @@ namespace BC7C
|
||||||
int bestShapeIdx[2] = { -1, -1 };
|
int bestShapeIdx[2] = { -1, -1 };
|
||||||
RGBACluster bestClusters[2][3];
|
RGBACluster bestClusters[2][3];
|
||||||
|
|
||||||
for(int i = 0; i < kNumShapes2; i++)
|
for(unsigned int i = 0; i < kNumShapes2; i++)
|
||||||
{
|
{
|
||||||
RGBACluster clusters[2];
|
RGBACluster clusters[2];
|
||||||
PopulateTwoClustersForShape(blockCluster, i, clusters);
|
PopulateTwoClustersForShape(blockCluster, i, clusters);
|
||||||
|
@ -1863,7 +1803,7 @@ namespace BC7C
|
||||||
// There are not 3 subset blocks that support alpha, so only check these
|
// There are not 3 subset blocks that support alpha, so only check these
|
||||||
// if the entire block is opaque.
|
// if the entire block is opaque.
|
||||||
if(opaque) {
|
if(opaque) {
|
||||||
for(int i = 0; i < kNumShapes3; i++) {
|
for(unsigned int i = 0; i < kNumShapes3; i++) {
|
||||||
|
|
||||||
RGBACluster clusters[3];
|
RGBACluster clusters[3];
|
||||||
PopulateThreeClustersForShape(blockCluster, i, clusters);
|
PopulateThreeClustersForShape(blockCluster, i, clusters);
|
||||||
|
@ -2108,7 +2048,7 @@ namespace BC7C
|
||||||
bool opaque = true;
|
bool opaque = true;
|
||||||
bool transparent = true;
|
bool transparent = true;
|
||||||
|
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
|
||||||
RGBAVector p = RGBAVector(i, block[i]);
|
RGBAVector p = RGBAVector(i, block[i]);
|
||||||
blockCluster.AddPoint(p);
|
blockCluster.AddPoint(p);
|
||||||
if(fabs(p.a - 255.0f) > 1e-10)
|
if(fabs(p.a - 255.0f) > 1e-10)
|
||||||
|
@ -2163,12 +2103,11 @@ namespace BC7C
|
||||||
|
|
||||||
// First we must figure out which shape to use. To do this, simply
|
// First we must figure out which shape to use. To do this, simply
|
||||||
// see which shape has the smallest sum of minimum bounding spheres.
|
// see which shape has the smallest sum of minimum bounding spheres.
|
||||||
double estimates[2] = { -1.0, -1.0 };
|
|
||||||
double bestError[2] = { DBL_MAX, DBL_MAX };
|
double bestError[2] = { DBL_MAX, DBL_MAX };
|
||||||
int bestShapeIdx[2] = { -1, -1 };
|
int bestShapeIdx[2] = { -1, -1 };
|
||||||
RGBACluster bestClusters[2][3];
|
RGBACluster bestClusters[2][3];
|
||||||
|
|
||||||
for(int i = 0; i < kNumShapes2; i++)
|
for(unsigned int i = 0; i < kNumShapes2; i++)
|
||||||
{
|
{
|
||||||
RGBACluster clusters[2];
|
RGBACluster clusters[2];
|
||||||
PopulateTwoClustersForShape(blockCluster, i, clusters);
|
PopulateTwoClustersForShape(blockCluster, i, clusters);
|
||||||
|
@ -2230,7 +2169,7 @@ namespace BC7C
|
||||||
// There are not 3 subset blocks that support alpha, so only check these
|
// There are not 3 subset blocks that support alpha, so only check these
|
||||||
// if the entire block is opaque.
|
// if the entire block is opaque.
|
||||||
if(opaque) {
|
if(opaque) {
|
||||||
for(int i = 0; i < kNumShapes3; i++) {
|
for(unsigned int i = 0; i < kNumShapes3; i++) {
|
||||||
|
|
||||||
RGBACluster clusters[3];
|
RGBACluster clusters[3];
|
||||||
PopulateThreeClustersForShape(blockCluster, i, clusters);
|
PopulateThreeClustersForShape(blockCluster, i, clusters);
|
||||||
|
@ -2467,7 +2406,7 @@ namespace BC7C
|
||||||
int nBitsPerColor = attrs->numBitsPerIndex;
|
int nBitsPerColor = attrs->numBitsPerIndex;
|
||||||
|
|
||||||
uint32 idxPrec = attrs->numBitsPerIndex;
|
uint32 idxPrec = attrs->numBitsPerIndex;
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
|
||||||
uint32 subset = GetSubsetForIndex(i, shapeIdx, nSubsets);
|
uint32 subset = GetSubsetForIndex(i, shapeIdx, nSubsets);
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
@ -2485,7 +2424,7 @@ namespace BC7C
|
||||||
memcpy(alphaIndices, colorIndices, sizeof(alphaIndices));
|
memcpy(alphaIndices, colorIndices, sizeof(alphaIndices));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
|
||||||
uint32 subset = GetSubsetForIndex(i, shapeIdx, nSubsets);
|
uint32 subset = GetSubsetForIndex(i, shapeIdx, nSubsets);
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
@ -2499,7 +2438,7 @@ namespace BC7C
|
||||||
}
|
}
|
||||||
|
|
||||||
if(idxMode) {
|
if(idxMode) {
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
|
||||||
swap(alphaIndices[i], colorIndices[i]);
|
swap(alphaIndices[i], colorIndices[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2510,7 +2449,7 @@ namespace BC7C
|
||||||
assert(strm.GetBitsRead() == 128);
|
assert(strm.GetBitsRead() == 128);
|
||||||
|
|
||||||
// Get final colors by interpolating...
|
// Get final colors by interpolating...
|
||||||
for(int i = 0; i < kMaxNumDataPoints; i++) {
|
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
|
||||||
|
|
||||||
const uint32 subset = GetSubsetForIndex(i, shapeIdx, nSubsets);
|
const uint32 subset = GetSubsetForIndex(i, shapeIdx, nSubsets);
|
||||||
uint32 &pixel = outBuf[i];
|
uint32 &pixel = outBuf[i];
|
||||||
|
|
|
@ -473,7 +473,6 @@ static unsigned char Optimal7CompressBC7Mode5[256][2] = {
|
||||||
}
|
}
|
||||||
OutputDebugString(tableEntryStr);
|
OutputDebugString(tableEntryStr);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
static unsigned char Optimal5CompressDXT1[256][2][3] = {
|
static unsigned char Optimal5CompressDXT1[256][2][3] = {
|
||||||
{ { 0, 0x00, 0x00 }, { 1, 0x00, 0x00 } },
|
{ { 0, 0x00, 0x00 }, { 1, 0x00, 0x00 } },
|
||||||
{ { 0, 0x00, 0x00 }, { 1, 0x00, 0x00 } },
|
{ { 0, 0x00, 0x00 }, { 1, 0x00, 0x00 } },
|
||||||
|
@ -732,6 +731,7 @@ static unsigned char Optimal5CompressDXT1[256][2][3] = {
|
||||||
{ { 0, 0x1f, 0x1f }, { 1, 0x1f, 0x1f } },
|
{ { 0, 0x1f, 0x1f }, { 1, 0x1f, 0x1f } },
|
||||||
{ { 0, 0x1f, 0x1f }, { 1, 0x1f, 0x1f } }
|
{ { 0, 0x1f, 0x1f }, { 1, 0x1f, 0x1f } }
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
static unsigned char Optimal6CompressDXT1[256][2][3] = {
|
static unsigned char Optimal6CompressDXT1[256][2][3] = {
|
||||||
{ { 0, 0x00, 0x00 }, { 1, 0x00, 0x00 } },
|
{ { 0, 0x00, 0x00 }, { 1, 0x00, 0x00 } },
|
||||||
|
|
|
@ -67,97 +67,97 @@
|
||||||
#define __BITSTREAM_H__
|
#define __BITSTREAM_H__
|
||||||
|
|
||||||
class BitStream {
|
class BitStream {
|
||||||
public:
|
public:
|
||||||
BitStream(unsigned char *ptr, int nBits, int start_offset) :
|
BitStream(unsigned char *ptr, int nBits, int start_offset) :
|
||||||
m_BitsWritten(0),
|
m_BitsWritten(0),
|
||||||
m_NumBits(nBits),
|
m_NumBits(nBits),
|
||||||
m_NumBytes((nBits + start_offset + 7) >> 3),
|
m_NumBytes((nBits + start_offset + 7) >> 3),
|
||||||
m_CurByte(ptr),
|
m_CurByte(ptr),
|
||||||
m_NextBit(start_offset % 8),
|
m_NextBit(start_offset % 8),
|
||||||
done(false)
|
done(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
int GetBitsWritten() const { return m_BitsWritten; }
|
int GetBitsWritten() const { return m_BitsWritten; }
|
||||||
|
|
||||||
~BitStream() { }
|
~BitStream() { }
|
||||||
void WriteBitsR(unsigned int val, unsigned int nBits) {
|
void WriteBitsR(unsigned int val, unsigned int nBits) {
|
||||||
for(unsigned int i = 0; i < nBits; i++) {
|
for(unsigned int i = 0; i < nBits; i++) {
|
||||||
WriteBit((val >> (nBits - i - 1)) & 1);
|
WriteBit((val >> (nBits - i - 1)) & 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteBits(unsigned int val, unsigned int nBits) {
|
void WriteBits(unsigned int val, unsigned int nBits) {
|
||||||
for(unsigned int i = 0; i < nBits; i++) {
|
for(unsigned int i = 0; i < nBits; i++) {
|
||||||
WriteBit((val >> i) & 1);
|
WriteBit((val >> i) & 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void WriteBit(int b) {
|
void WriteBit(int b) {
|
||||||
|
|
||||||
if(done) return;
|
if(done) return;
|
||||||
|
|
||||||
const unsigned int mask = 1 << m_NextBit++;
|
const unsigned int mask = 1 << m_NextBit++;
|
||||||
|
|
||||||
// clear the bit
|
// clear the bit
|
||||||
*m_CurByte &= ~mask;
|
*m_CurByte &= ~mask;
|
||||||
|
|
||||||
// Write the bit, if necessary
|
// Write the bit, if necessary
|
||||||
if(b) *m_CurByte |= mask;
|
if(b) *m_CurByte |= mask;
|
||||||
|
|
||||||
// Next byte?
|
// Next byte?
|
||||||
if(m_NextBit >= 8) {
|
if(m_NextBit >= 8) {
|
||||||
m_CurByte += 1;
|
m_CurByte += 1;
|
||||||
m_NextBit = 0;
|
m_NextBit = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
done = done || ++m_BitsWritten >= m_NumBits;
|
done = done || ++m_BitsWritten >= m_NumBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_BitsWritten;
|
int m_BitsWritten;
|
||||||
int m_NextBit;
|
const int m_NumBits;
|
||||||
const int m_NumBytes;
|
const int m_NumBytes;
|
||||||
const int m_NumBits;
|
unsigned char *m_CurByte;
|
||||||
unsigned char *m_CurByte;
|
int m_NextBit;
|
||||||
|
|
||||||
bool done;
|
bool done;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BitStreamReadOnly {
|
class BitStreamReadOnly {
|
||||||
public:
|
public:
|
||||||
BitStreamReadOnly(const unsigned char *ptr) :
|
BitStreamReadOnly(const unsigned char *ptr) :
|
||||||
m_BitsRead(0),
|
m_BitsRead(0),
|
||||||
m_CurByte(ptr),
|
m_CurByte(ptr),
|
||||||
m_NextBit(0)
|
m_NextBit(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
int GetBitsRead() const { return m_BitsRead; }
|
int GetBitsRead() const { return m_BitsRead; }
|
||||||
|
|
||||||
~BitStreamReadOnly() { }
|
~BitStreamReadOnly() { }
|
||||||
|
|
||||||
int ReadBit() {
|
int ReadBit() {
|
||||||
|
|
||||||
int bit = *m_CurByte >> m_NextBit++;
|
int bit = *m_CurByte >> m_NextBit++;
|
||||||
while(m_NextBit >= 8) {
|
while(m_NextBit >= 8) {
|
||||||
m_NextBit -= 8;
|
m_NextBit -= 8;
|
||||||
m_CurByte++;
|
m_CurByte++;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_BitsRead++;
|
m_BitsRead++;
|
||||||
return bit & 1;
|
return bit & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ReadBits(unsigned int nBits) {
|
unsigned int ReadBits(unsigned int nBits) {
|
||||||
unsigned int ret = 0;
|
unsigned int ret = 0;
|
||||||
for(unsigned int i = 0; i < nBits; i++) {
|
for(unsigned int i = 0; i < nBits; i++) {
|
||||||
ret |= (ReadBit() & 1) << i;
|
ret |= (ReadBit() & 1) << i;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_BitsRead;
|
int m_BitsRead;
|
||||||
int m_NextBit;
|
const unsigned char *m_CurByte;
|
||||||
const unsigned char *m_CurByte;
|
int m_NextBit;
|
||||||
};
|
};
|
||||||
#endif //__BITSTREAM_H__
|
#endif //__BITSTREAM_H__
|
||||||
|
|
|
@ -347,7 +347,7 @@ void RGBACluster::AddPoint(const RGBAVector &p) {
|
||||||
m_DataPoints[m_NumPoints++] = p;
|
m_DataPoints[m_NumPoints++] = p;
|
||||||
m_PointBitString |= 1 << p.GetIdx();
|
m_PointBitString |= 1 << p.GetIdx();
|
||||||
|
|
||||||
for(int i = 0; i < kNumColorChannels; i++) {
|
for(uint32 i = 0; i < kNumColorChannels; i++) {
|
||||||
m_Min.c[i] = min(p.c[i], m_Min.c[i]);
|
m_Min.c[i] = min(p.c[i], m_Min.c[i]);
|
||||||
m_Max.c[i] = max(p.c[i], m_Max.c[i]);
|
m_Max.c[i] = max(p.c[i], m_Max.c[i]);
|
||||||
}
|
}
|
||||||
|
@ -449,7 +449,7 @@ double RGBACluster::QuantizedError(const RGBAVector &p1, const RGBAVector &p2, u
|
||||||
uint32 interp1 = (*interpVals)[j][1];
|
uint32 interp1 = (*interpVals)[j][1];
|
||||||
|
|
||||||
RGBAVector errorVec (0.0f);
|
RGBAVector errorVec (0.0f);
|
||||||
for(int k = 0; k < kNumColorChannels; k++) {
|
for(uint32 k = 0; k < kNumColorChannels; k++) {
|
||||||
const uint8 ip = (((uint32(pqp1[k]) * interp0) + (uint32(pqp2[k]) * interp1) + 32) >> 6) & 0xFF;
|
const uint8 ip = (((uint32(pqp1[k]) * interp0) + (uint32(pqp2[k]) * interp1) + 32) >> 6) & 0xFF;
|
||||||
const uint8 dist = sad(pb[k], ip);
|
const uint8 dist = sad(pb[k], ip);
|
||||||
errorVec.c[k] = kFloatConversion[dist] * metric.c[k];
|
errorVec.c[k] = kFloatConversion[dist] * metric.c[k];
|
||||||
|
@ -548,13 +548,12 @@ static uint32 PowerIteration(const RGBAMatrix &mat, RGBADir &eigVec, double &eig
|
||||||
return numIterations;
|
return numIterations;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 GetPrincipalAxis(int nPts, const RGBAVector *pts, RGBADir &axis, double &eigOne, double *eigTwo) {
|
uint32 GetPrincipalAxis(uint32 nPts, const RGBAVector *pts, RGBADir &axis, double &eigOne, double *eigTwo) {
|
||||||
|
|
||||||
assert(nPts > 0);
|
|
||||||
assert(nPts <= kMaxNumDataPoints);
|
assert(nPts <= kMaxNumDataPoints);
|
||||||
|
|
||||||
RGBAVector avg (0.0f);
|
RGBAVector avg (0.0f);
|
||||||
for(int i = 0; i < nPts; i++) {
|
for(uint32 i = 0; i < nPts; i++) {
|
||||||
avg += pts[i];
|
avg += pts[i];
|
||||||
}
|
}
|
||||||
avg /= float(nPts);
|
avg /= float(nPts);
|
||||||
|
@ -562,21 +561,21 @@ uint32 GetPrincipalAxis(int nPts, const RGBAVector *pts, RGBADir &axis, double &
|
||||||
// We use these vectors for calculating the covariance matrix...
|
// We use these vectors for calculating the covariance matrix...
|
||||||
RGBAVector toPts[kMaxNumDataPoints];
|
RGBAVector toPts[kMaxNumDataPoints];
|
||||||
RGBAVector toPtsMax(-FLT_MAX);
|
RGBAVector toPtsMax(-FLT_MAX);
|
||||||
for(int i = 0; i < nPts; i++) {
|
for(uint32 i = 0; i < nPts; i++) {
|
||||||
toPts[i] = pts[i] - avg;
|
toPts[i] = pts[i] - avg;
|
||||||
|
|
||||||
for(int j = 0; j < kNumColorChannels; j++) {
|
for(uint32 j = 0; j < kNumColorChannels; j++) {
|
||||||
toPtsMax.c[j] = max(toPtsMax.c[j], toPts[i].c[j]);
|
toPtsMax.c[j] = max(toPtsMax.c[j], toPts[i].c[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a list of unique points...
|
// Generate a list of unique points...
|
||||||
RGBAVector upts[kMaxNumDataPoints];
|
RGBAVector upts[kMaxNumDataPoints];
|
||||||
int uptsIdx = 0;
|
uint32 uptsIdx = 0;
|
||||||
for(int i = 0; i < nPts; i++) {
|
for(uint32 i = 0; i < nPts; i++) {
|
||||||
|
|
||||||
bool hasPt = false;
|
bool hasPt = false;
|
||||||
for(int j = 0; j < uptsIdx; j++) {
|
for(uint32 j = 0; j < uptsIdx; j++) {
|
||||||
if(upts[j] == pts[i])
|
if(upts[j] == pts[i])
|
||||||
hasPt = true;
|
hasPt = true;
|
||||||
}
|
}
|
||||||
|
@ -597,7 +596,7 @@ uint32 GetPrincipalAxis(int nPts, const RGBAVector *pts, RGBADir &axis, double &
|
||||||
|
|
||||||
RGBADir dir (upts[1] - upts[0]);
|
RGBADir dir (upts[1] - upts[0]);
|
||||||
bool collinear = true;
|
bool collinear = true;
|
||||||
for(int i = 2; i < nPts; i++) {
|
for(uint32 i = 2; i < nPts; i++) {
|
||||||
RGBAVector v = (upts[i] - upts[0]);
|
RGBAVector v = (upts[i] - upts[0]);
|
||||||
if(fabs(fabs(v*dir) - v.Length()) > 1e-7) {
|
if(fabs(fabs(v*dir) - v.Length()) > 1e-7) {
|
||||||
collinear = false;
|
collinear = false;
|
||||||
|
@ -614,11 +613,11 @@ uint32 GetPrincipalAxis(int nPts, const RGBAVector *pts, RGBADir &axis, double &
|
||||||
RGBAMatrix covMatrix;
|
RGBAMatrix covMatrix;
|
||||||
|
|
||||||
// Compute covariance.
|
// Compute covariance.
|
||||||
for(int i = 0; i < kNumColorChannels; i++) {
|
for(uint32 i = 0; i < kNumColorChannels; i++) {
|
||||||
for(int j = 0; j <= i; j++) {
|
for(uint32 j = 0; j <= i; j++) {
|
||||||
|
|
||||||
float sum = 0.0;
|
float sum = 0.0;
|
||||||
for(int k = 0; k < nPts; k++) {
|
for(uint32 k = 0; k < nPts; k++) {
|
||||||
sum += toPts[k].c[i] * toPts[k].c[j];
|
sum += toPts[k].c[i] * toPts[k].c[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,7 +638,7 @@ uint32 GetPrincipalAxis(int nPts, const RGBAVector *pts, RGBADir &axis, double &
|
||||||
);
|
);
|
||||||
|
|
||||||
bool allZero = true;
|
bool allZero = true;
|
||||||
for(int i = 0; i < 16; i++) {
|
for(uint32 i = 0; i < 16; i++) {
|
||||||
if(fabs(reduced[i]) > 0.0005) {
|
if(fabs(reduced[i]) > 0.0005) {
|
||||||
allZero = false;
|
allZero = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,8 +72,8 @@
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
static const int kNumColorChannels = 4;
|
static const uint32 kNumColorChannels = 4;
|
||||||
static const int kMaxNumDataPoints = 16;
|
static const uint32 kMaxNumDataPoints = 16;
|
||||||
|
|
||||||
class RGBAVector {
|
class RGBAVector {
|
||||||
|
|
||||||
|
@ -236,63 +236,63 @@ public:
|
||||||
|
|
||||||
RGBAMatrix operator +(const RGBAMatrix &p) const {
|
RGBAMatrix operator +(const RGBAMatrix &p) const {
|
||||||
float newm[kNumColorChannels*kNumColorChannels];
|
float newm[kNumColorChannels*kNumColorChannels];
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = m[i] + p.m[i];
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = m[i] + p.m[i];
|
||||||
return RGBAMatrix(newm);
|
return RGBAMatrix(newm);
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBAMatrix &operator +=(const RGBAMatrix &p) {
|
RGBAMatrix &operator +=(const RGBAMatrix &p) {
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) m[i] += p.m[i];
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) m[i] += p.m[i];
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBAMatrix operator -(const RGBAMatrix &p) const {
|
RGBAMatrix operator -(const RGBAMatrix &p) const {
|
||||||
float newm[kNumColorChannels*kNumColorChannels];
|
float newm[kNumColorChannels*kNumColorChannels];
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = m[i] - p.m[i];
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = m[i] - p.m[i];
|
||||||
return RGBAMatrix(newm);
|
return RGBAMatrix(newm);
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBAMatrix &operator -=(const RGBAMatrix &p) {
|
RGBAMatrix &operator -=(const RGBAMatrix &p) {
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) m[i] -= p.m[i];
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) m[i] -= p.m[i];
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBAMatrix operator /(const float s) const {
|
RGBAMatrix operator /(const float s) const {
|
||||||
float newm[kNumColorChannels*kNumColorChannels];
|
float newm[kNumColorChannels*kNumColorChannels];
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = m[i] / s;
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = m[i] / s;
|
||||||
return RGBAMatrix(newm);
|
return RGBAMatrix(newm);
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBAMatrix &operator /=(const float s) {
|
RGBAMatrix &operator /=(const float s) {
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) m[i] /= s;
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) m[i] /= s;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBAMatrix operator *(const float s) const {
|
RGBAMatrix operator *(const float s) const {
|
||||||
float newm[kNumColorChannels*kNumColorChannels];
|
float newm[kNumColorChannels*kNumColorChannels];
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = m[i] * s;
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = m[i] * s;
|
||||||
return RGBAMatrix(newm);
|
return RGBAMatrix(newm);
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBAMatrix operator *(const double s) const {
|
RGBAMatrix operator *(const double s) const {
|
||||||
float newm[kNumColorChannels*kNumColorChannels];
|
float newm[kNumColorChannels*kNumColorChannels];
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = float(double(m[i]) * s);
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = float(double(m[i]) * s);
|
||||||
return RGBAMatrix(newm);
|
return RGBAMatrix(newm);
|
||||||
}
|
}
|
||||||
|
|
||||||
friend RGBAMatrix operator *(const float s, const RGBAMatrix &p) {
|
friend RGBAMatrix operator *(const float s, const RGBAMatrix &p) {
|
||||||
float newm[kNumColorChannels*kNumColorChannels];
|
float newm[kNumColorChannels*kNumColorChannels];
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = p.m[i] * s;
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = p.m[i] * s;
|
||||||
return RGBAMatrix(newm);
|
return RGBAMatrix(newm);
|
||||||
}
|
}
|
||||||
|
|
||||||
friend RGBAMatrix operator *(const double s, const RGBAMatrix &p) {
|
friend RGBAMatrix operator *(const double s, const RGBAMatrix &p) {
|
||||||
float newm[kNumColorChannels*kNumColorChannels];
|
float newm[kNumColorChannels*kNumColorChannels];
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = float(double(p.m[i]) * s);
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) newm[i] = float(double(p.m[i]) * s);
|
||||||
return RGBAMatrix(newm);
|
return RGBAMatrix(newm);
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBAMatrix &operator *=(const float s) {
|
RGBAMatrix &operator *=(const float s) {
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++) m[i] *= s;
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++) m[i] *= s;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ public:
|
||||||
|
|
||||||
friend bool operator ==(const RGBAMatrix &rhs, const RGBAMatrix &lhs) {
|
friend bool operator ==(const RGBAMatrix &rhs, const RGBAMatrix &lhs) {
|
||||||
const RGBAMatrix d = rhs - lhs;
|
const RGBAMatrix d = rhs - lhs;
|
||||||
for(int i = 0; i < kNumColorChannels*kNumColorChannels; i++)
|
for(uint32 i = 0; i < kNumColorChannels*kNumColorChannels; i++)
|
||||||
if(d.m[i] > 1e-10)
|
if(d.m[i] > 1e-10)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -355,6 +355,7 @@ public:
|
||||||
m_Min(c.m_Min),
|
m_Min(c.m_Min),
|
||||||
m_Max(c.m_Max),
|
m_Max(c.m_Max),
|
||||||
m_PrincipalAxisCached(c.m_PrincipalAxisCached),
|
m_PrincipalAxisCached(c.m_PrincipalAxisCached),
|
||||||
|
m_PrincipalEigenvalue(c.m_PrincipalEigenvalue),
|
||||||
m_SecondEigenvalue(c.m_SecondEigenvalue),
|
m_SecondEigenvalue(c.m_SecondEigenvalue),
|
||||||
m_PowerMethodIterations(c.m_PowerMethodIterations),
|
m_PowerMethodIterations(c.m_PowerMethodIterations),
|
||||||
m_PrincipalAxis(c.m_PrincipalAxis)
|
m_PrincipalAxis(c.m_PrincipalAxis)
|
||||||
|
@ -408,14 +409,14 @@ private:
|
||||||
// The points in the cluster.
|
// The points in the cluster.
|
||||||
RGBAVector m_DataPoints[kMaxNumDataPoints];
|
RGBAVector m_DataPoints[kMaxNumDataPoints];
|
||||||
|
|
||||||
RGBAVector m_Min, m_Max;
|
|
||||||
int m_PointBitString;
|
int m_PointBitString;
|
||||||
|
RGBAVector m_Min, m_Max;
|
||||||
|
|
||||||
|
bool m_PrincipalAxisCached;
|
||||||
double m_PrincipalEigenvalue;
|
double m_PrincipalEigenvalue;
|
||||||
double m_SecondEigenvalue;
|
double m_SecondEigenvalue;
|
||||||
uint32 m_PowerMethodIterations;
|
uint32 m_PowerMethodIterations;
|
||||||
RGBADir m_PrincipalAxis;
|
RGBADir m_PrincipalAxis;
|
||||||
bool m_PrincipalAxisCached;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern uint8 QuantizeChannel(const uint8 val, const uint8 mask, const int pBit = -1);
|
extern uint8 QuantizeChannel(const uint8 val, const uint8 mask, const int pBit = -1);
|
||||||
|
|
|
@ -60,6 +60,7 @@ class ReferenceCounter {
|
||||||
DecRefCount();
|
DecRefCount();
|
||||||
m_ReferenceCount = other.m_ReferenceCount;
|
m_ReferenceCount = other.m_ReferenceCount;
|
||||||
IncRefCount();
|
IncRefCount();
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 GetRefCount() const {
|
uint32 GetRefCount() const {
|
||||||
|
|
Loading…
Reference in a new issue