Fix a lot of compiler warnings.

This commit is contained in:
Pavel Krajcevski 2013-01-28 16:30:04 -05:00
parent 28a55cc268
commit 5dd1fbbd48
7 changed files with 163 additions and 224 deletions

View file

@ -124,6 +124,7 @@ public:
private:
const double m_IsOpaque;
const Attributes *const m_Attributes;
int m_RotateMode;
@ -238,8 +239,6 @@ private:
double CompressCluster(const RGBACluster &cluster, RGBAVector &p1, RGBAVector &p2, int *bestIndices, int *alphaIndices) const;
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2, int &bestPBitCombo) const;
const double m_IsOpaque;
};
extern const uint32 kBC7InterpolationValues[4][16][2];

View file

@ -207,7 +207,7 @@ static inline T sad(const T &a, const T &b) {
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;
switch(nSubsets) {
@ -233,7 +233,7 @@ static int GetSubsetForIndex(int idx, const int shapeIdx, const int nSubsets) {
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;
switch(subset) {
@ -262,57 +262,15 @@ static int GetAnchorIndexForSubset(int subset, const int shapeIdx, const int nSu
return anchorIdx;
}
static int GetPointMaskForSubset(int subset, const int shapeIdx, const int nSubsets) {
int mask = 0xFFFF;
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;
template <typename T>
static T min(const T &a, const T &b) {
return (a < b)? a : b;
}
#ifndef min
#define min(a, b) (((a) > (b))? (b) : (a))
#endif
#ifndef max
#define max(a, b) (((a) > (b))? (a) : (b))
#endif
template <typename T>
static T max(const T &a, const T &b) {
return (a > b)? a : b;
}
template <typename T>
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; }
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}, {43, 21}, {21, 43}, {0, 64}, 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}, {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}, {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}, {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} }
};
@ -403,7 +361,7 @@ double BC7CompressionMode::CompressSingleColor(const RGBAVector &p, RGBAVector &
uint32 bestValI[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;
int nBits = ci == 3? GetAlphaChannelPrecision() : m_Attributes->colorChannelPrecision;
@ -467,7 +425,7 @@ double BC7CompressionMode::CompressSingleColor(const RGBAVector &p, RGBAVector &
bestDist = dist;
bestPbitCombo = pbi;
for(int ci = 0; ci < kNumColorChannels; ci++) {
for(uint32 ci = 0; ci < kNumColorChannels; ci++) {
p1.c[ci] = float(bestValI[ci]);
p2.c[ci] = float(bestValJ[ci]);
}
@ -609,7 +567,7 @@ void BC7CompressionMode::PickBestNeighboringEndpoints(const RGBACluster &cluster
else
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);
}
}
@ -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 {
const int nBuckets = (1 << GetNumberOfBitsPerIndex());
const int nPbitCombos = GetNumPbitCombos();
const uint32 qmask = GetQuantizationMask();
// 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 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(a1 == a2)
{
const uint8 step = 1 << (8-GetAlphaChannelPrecision());
const uint8 a1be = uint8(a1);
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.
if(GetModeNumber() == 5) {
@ -833,7 +787,7 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
assert(a1 == float(a1b));
assert(a2 == float(a2b));
for(int i = 0; i < kMaxNumDataPoints; i++)
for(uint32 i = 0; i < kMaxNumDataPoints; i++)
alphaIndices[i] = 0;
alphaError = 0.0;
@ -852,11 +806,11 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
}
if(m_IndexMode == 1) {
for(int i = 0; i < kMaxNumDataPoints; i++)
for(uint32 i = 0; i < kMaxNumDataPoints; i++)
alphaIndices[i] = 1;
}
else {
for(int i = 0; i < kMaxNumDataPoints; i++)
for(uint32 i = 0; i < kMaxNumDataPoints; i++)
alphaIndices[i] = 2;
}
@ -874,18 +828,18 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
float vals[1<<3];
memset(vals, 0, sizeof(vals));
int buckets[kMaxNumDataPoints];
uint32 buckets[kMaxNumDataPoints];
// 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);
}
// Assign each value to a bucket
for(int i = 0; i < kMaxNumDataPoints; i++) {
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
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]);
if(dist < minDist) {
minDist = dist;
@ -906,8 +860,8 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
memset(avg, 0, sizeof(avg));
// Calculate average of each cluster
for(int i = 0; i < nBuckets; i++) {
for(int j = 0; j < kMaxNumDataPoints; j++) {
for(uint32 i = 0; i < nBuckets; i++) {
for(uint32 j = 0; j < kMaxNumDataPoints; j++) {
if(buckets[j] == i) {
avg[i] += alphaVals[j];
@ -921,7 +875,7 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
// Did we change anything?
fixed = true;
for(int i = 0; i < nBuckets; i++) {
for(uint32 i = 0; i < nBuckets; i++) {
fixed = fixed && (avg[i] == vals[i]);
}
@ -929,10 +883,10 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
memcpy(vals, avg, sizeof(vals));
// Reassign each value to a bucket
for(int i = 0; i < kMaxNumDataPoints; i++) {
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
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]);
if(dist < minDist) {
minDist = dist;
@ -945,7 +899,7 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
// Do least squares fit of vals.
float asq = 0.0, bsq = 0.0, ab = 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 b = float(i) / float(nBuckets - 1);
@ -974,14 +928,14 @@ double BC7CompressionMode::CompressCluster(const RGBACluster &cluster, RGBAVecto
// Compute error
alphaError = 0.0;
for(int i = 0; i < kMaxNumDataPoints; i++) {
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
uint8 val = uint8(alphaVals[i]);
float minError = FLT_MAX;
int bestBucket = -1;
for(int j = 0; j < nBuckets; j++) {
for(uint32 j = 0; j < nBuckets; j++) {
uint32 interp0 = (*interpVals)[j][0];
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];
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 nPbitCombos = GetNumPbitCombos();
const uint32 qmask = GetQuantizationMask();
#if 1
RGBAVector avg = cluster.GetTotal() / float(cluster.GetNumPoints());
@ -1452,7 +1404,6 @@ namespace BC7C
ErrorMetric GetErrorMetricEnum() { return gErrorMetric; }
// 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, 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(
int shapeIdx,
const RGBACluster *clusters,
@ -1712,7 +1652,7 @@ namespace BC7C
static void PopulateTwoClustersForShape(const RGBACluster &points, int shapeIdx, RGBACluster *clusters) {
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);
@ -1728,7 +1668,7 @@ namespace BC7C
}
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);
@ -1813,7 +1753,7 @@ namespace BC7C
bool opaque = true;
bool transparent = true;
for(int i = 0; i < kMaxNumDataPoints; i++) {
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
RGBAVector p = RGBAVector(i, block[i]);
blockCluster.AddPoint(p);
if(fabs(p.a - 255.0f) > 1e-10)
@ -1836,7 +1776,7 @@ namespace BC7C
int bestShapeIdx[2] = { -1, -1 };
RGBACluster bestClusters[2][3];
for(int i = 0; i < kNumShapes2; i++)
for(unsigned int i = 0; i < kNumShapes2; i++)
{
RGBACluster clusters[2];
PopulateTwoClustersForShape(blockCluster, i, clusters);
@ -1863,7 +1803,7 @@ namespace BC7C
// There are not 3 subset blocks that support alpha, so only check these
// if the entire block is opaque.
if(opaque) {
for(int i = 0; i < kNumShapes3; i++) {
for(unsigned int i = 0; i < kNumShapes3; i++) {
RGBACluster clusters[3];
PopulateThreeClustersForShape(blockCluster, i, clusters);
@ -2108,7 +2048,7 @@ namespace BC7C
bool opaque = true;
bool transparent = true;
for(int i = 0; i < kMaxNumDataPoints; i++) {
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
RGBAVector p = RGBAVector(i, block[i]);
blockCluster.AddPoint(p);
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
// 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 };
int bestShapeIdx[2] = { -1, -1 };
RGBACluster bestClusters[2][3];
for(int i = 0; i < kNumShapes2; i++)
for(unsigned int i = 0; i < kNumShapes2; i++)
{
RGBACluster clusters[2];
PopulateTwoClustersForShape(blockCluster, i, clusters);
@ -2230,7 +2169,7 @@ namespace BC7C
// There are not 3 subset blocks that support alpha, so only check these
// if the entire block is opaque.
if(opaque) {
for(int i = 0; i < kNumShapes3; i++) {
for(unsigned int i = 0; i < kNumShapes3; i++) {
RGBACluster clusters[3];
PopulateThreeClustersForShape(blockCluster, i, clusters);
@ -2467,7 +2406,7 @@ namespace BC7C
int nBitsPerColor = 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);
int idx = 0;
@ -2485,7 +2424,7 @@ namespace BC7C
memcpy(alphaIndices, colorIndices, sizeof(alphaIndices));
}
else {
for(int i = 0; i < kMaxNumDataPoints; i++) {
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
uint32 subset = GetSubsetForIndex(i, shapeIdx, nSubsets);
int idx = 0;
@ -2499,7 +2438,7 @@ namespace BC7C
}
if(idxMode) {
for(int i = 0; i < kMaxNumDataPoints; i++) {
for(uint32 i = 0; i < kMaxNumDataPoints; i++) {
swap(alphaIndices[i], colorIndices[i]);
}
@ -2510,7 +2449,7 @@ namespace BC7C
assert(strm.GetBitsRead() == 128);
// 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);
uint32 &pixel = outBuf[i];

View file

@ -473,7 +473,6 @@ static unsigned char Optimal7CompressBC7Mode5[256][2] = {
}
OutputDebugString(tableEntryStr);
}
*/
static unsigned char Optimal5CompressDXT1[256][2][3] = {
{ { 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 } }
};
*/
static unsigned char Optimal6CompressDXT1[256][2][3] = {
{ { 0, 0x00, 0x00 }, { 1, 0x00, 0x00 } },

View file

@ -67,97 +67,97 @@
#define __BITSTREAM_H__
class BitStream {
public:
BitStream(unsigned char *ptr, int nBits, int start_offset) :
m_BitsWritten(0),
m_NumBits(nBits),
m_NumBytes((nBits + start_offset + 7) >> 3),
m_CurByte(ptr),
m_NextBit(start_offset % 8),
done(false)
{ }
public:
BitStream(unsigned char *ptr, int nBits, int start_offset) :
m_BitsWritten(0),
m_NumBits(nBits),
m_NumBytes((nBits + start_offset + 7) >> 3),
m_CurByte(ptr),
m_NextBit(start_offset % 8),
done(false)
{ }
int GetBitsWritten() const { return m_BitsWritten; }
int GetBitsWritten() const { return m_BitsWritten; }
~BitStream() { }
void WriteBitsR(unsigned int val, unsigned int nBits) {
for(unsigned int i = 0; i < nBits; i++) {
WriteBit((val >> (nBits - i - 1)) & 1);
}
}
~BitStream() { }
void WriteBitsR(unsigned int val, unsigned int nBits) {
for(unsigned int i = 0; i < nBits; i++) {
WriteBit((val >> (nBits - i - 1)) & 1);
}
}
void WriteBits(unsigned int val, unsigned int nBits) {
for(unsigned int i = 0; i < nBits; i++) {
WriteBit((val >> i) & 1);
}
}
void WriteBits(unsigned int val, unsigned int nBits) {
for(unsigned int i = 0; i < nBits; i++) {
WriteBit((val >> i) & 1);
}
}
private:
void WriteBit(int b) {
private:
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
*m_CurByte &= ~mask;
// clear the bit
*m_CurByte &= ~mask;
// Write the bit, if necessary
if(b) *m_CurByte |= mask;
// Write the bit, if necessary
if(b) *m_CurByte |= mask;
// Next byte?
if(m_NextBit >= 8) {
m_CurByte += 1;
m_NextBit = 0;
}
// Next byte?
if(m_NextBit >= 8) {
m_CurByte += 1;
m_NextBit = 0;
}
done = done || ++m_BitsWritten >= m_NumBits;
}
done = done || ++m_BitsWritten >= m_NumBits;
}
int m_BitsWritten;
int m_NextBit;
const int m_NumBytes;
const int m_NumBits;
unsigned char *m_CurByte;
int m_BitsWritten;
const int m_NumBits;
const int m_NumBytes;
unsigned char *m_CurByte;
int m_NextBit;
bool done;
bool done;
};
class BitStreamReadOnly {
public:
BitStreamReadOnly(const unsigned char *ptr) :
m_BitsRead(0),
m_CurByte(ptr),
m_NextBit(0)
{ }
public:
BitStreamReadOnly(const unsigned char *ptr) :
m_BitsRead(0),
m_CurByte(ptr),
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++;
while(m_NextBit >= 8) {
m_NextBit -= 8;
m_CurByte++;
}
int bit = *m_CurByte >> m_NextBit++;
while(m_NextBit >= 8) {
m_NextBit -= 8;
m_CurByte++;
}
m_BitsRead++;
return bit & 1;
}
m_BitsRead++;
return bit & 1;
}
unsigned int ReadBits(unsigned int nBits) {
unsigned int ret = 0;
for(unsigned int i = 0; i < nBits; i++) {
ret |= (ReadBit() & 1) << i;
}
return ret;
}
unsigned int ReadBits(unsigned int nBits) {
unsigned int ret = 0;
for(unsigned int i = 0; i < nBits; i++) {
ret |= (ReadBit() & 1) << i;
}
return ret;
}
private:
int m_BitsRead;
int m_NextBit;
const unsigned char *m_CurByte;
private:
int m_BitsRead;
const unsigned char *m_CurByte;
int m_NextBit;
};
#endif //__BITSTREAM_H__

View file

@ -347,7 +347,7 @@ void RGBACluster::AddPoint(const RGBAVector &p) {
m_DataPoints[m_NumPoints++] = p;
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_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];
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 dist = sad(pb[k], ip);
errorVec.c[k] = kFloatConversion[dist] * metric.c[k];
@ -548,13 +548,12 @@ static uint32 PowerIteration(const RGBAMatrix &mat, RGBADir &eigVec, double &eig
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);
RGBAVector avg (0.0f);
for(int i = 0; i < nPts; i++) {
for(uint32 i = 0; i < nPts; i++) {
avg += pts[i];
}
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...
RGBAVector toPts[kMaxNumDataPoints];
RGBAVector toPtsMax(-FLT_MAX);
for(int i = 0; i < nPts; i++) {
for(uint32 i = 0; i < nPts; i++) {
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]);
}
}
// Generate a list of unique points...
RGBAVector upts[kMaxNumDataPoints];
int uptsIdx = 0;
for(int i = 0; i < nPts; i++) {
uint32 uptsIdx = 0;
for(uint32 i = 0; i < nPts; i++) {
bool hasPt = false;
for(int j = 0; j < uptsIdx; j++) {
for(uint32 j = 0; j < uptsIdx; j++) {
if(upts[j] == pts[i])
hasPt = true;
}
@ -597,7 +596,7 @@ uint32 GetPrincipalAxis(int nPts, const RGBAVector *pts, RGBADir &axis, double &
RGBADir dir (upts[1] - upts[0]);
bool collinear = true;
for(int i = 2; i < nPts; i++) {
for(uint32 i = 2; i < nPts; i++) {
RGBAVector v = (upts[i] - upts[0]);
if(fabs(fabs(v*dir) - v.Length()) > 1e-7) {
collinear = false;
@ -614,11 +613,11 @@ uint32 GetPrincipalAxis(int nPts, const RGBAVector *pts, RGBADir &axis, double &
RGBAMatrix covMatrix;
// Compute covariance.
for(int i = 0; i < kNumColorChannels; i++) {
for(int j = 0; j <= i; j++) {
for(uint32 i = 0; i < kNumColorChannels; i++) {
for(uint32 j = 0; j <= i; j++) {
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];
}
@ -639,7 +638,7 @@ uint32 GetPrincipalAxis(int nPts, const RGBAVector *pts, RGBADir &axis, double &
);
bool allZero = true;
for(int i = 0; i < 16; i++) {
for(uint32 i = 0; i < 16; i++) {
if(fabs(reduced[i]) > 0.0005) {
allZero = false;
}

View file

@ -72,8 +72,8 @@
#include <cfloat>
#include <cstring>
static const int kNumColorChannels = 4;
static const int kMaxNumDataPoints = 16;
static const uint32 kNumColorChannels = 4;
static const uint32 kMaxNumDataPoints = 16;
class RGBAVector {
@ -236,63 +236,63 @@ public:
RGBAMatrix operator +(const RGBAMatrix &p) const {
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);
}
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;
}
RGBAMatrix operator -(const RGBAMatrix &p) const {
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);
}
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;
}
RGBAMatrix operator /(const float s) const {
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);
}
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;
}
RGBAMatrix operator *(const float s) const {
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);
}
RGBAMatrix operator *(const double s) const {
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);
}
friend RGBAMatrix operator *(const float s, const RGBAMatrix &p) {
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);
}
friend RGBAMatrix operator *(const double s, const RGBAMatrix &p) {
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);
}
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;
}
@ -306,7 +306,7 @@ public:
friend bool operator ==(const RGBAMatrix &rhs, const RGBAMatrix &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)
return false;
return true;
@ -355,6 +355,7 @@ public:
m_Min(c.m_Min),
m_Max(c.m_Max),
m_PrincipalAxisCached(c.m_PrincipalAxisCached),
m_PrincipalEigenvalue(c.m_PrincipalEigenvalue),
m_SecondEigenvalue(c.m_SecondEigenvalue),
m_PowerMethodIterations(c.m_PowerMethodIterations),
m_PrincipalAxis(c.m_PrincipalAxis)
@ -408,14 +409,14 @@ private:
// The points in the cluster.
RGBAVector m_DataPoints[kMaxNumDataPoints];
RGBAVector m_Min, m_Max;
int m_PointBitString;
RGBAVector m_Min, m_Max;
bool m_PrincipalAxisCached;
double m_PrincipalEigenvalue;
double m_SecondEigenvalue;
uint32 m_PowerMethodIterations;
RGBADir m_PrincipalAxis;
bool m_PrincipalAxisCached;
};
extern uint8 QuantizeChannel(const uint8 val, const uint8 mask, const int pBit = -1);

View file

@ -60,6 +60,7 @@ class ReferenceCounter {
DecRefCount();
m_ReferenceCount = other.m_ReferenceCount;
IncRefCount();
return *this;
}
uint32 GetRefCount() const {