Fix some indentation and signedness mismatch

This commit is contained in:
Pavel Krajcevski 2012-11-07 15:23:07 -05:00
parent 53b8d4c9a9
commit b43373c0aa
3 changed files with 60 additions and 51 deletions

View file

@ -1478,12 +1478,11 @@ namespace BC7C
// implementation has an 4:1 compression ratio. // implementation has an 4:1 compression ratio.
void CompressImageBC7(const unsigned char *inBuf, unsigned char *outBuf, unsigned int width, unsigned int height) void CompressImageBC7(const unsigned char *inBuf, unsigned char *outBuf, unsigned int width, unsigned int height)
{ {
uint32 block[16];
BC7CompressionMode::MaxAnnealingIterations = min(BC7CompressionMode::kMaxAnnealingIterations, GetQualityLevel()); BC7CompressionMode::MaxAnnealingIterations = min(BC7CompressionMode::kMaxAnnealingIterations, GetQualityLevel());
for(int j = 0; j < height; j += 4) for(uint32 j = 0; j < height; j += 4)
{ {
for(int i = 0; i < width; i += 4) for(uint32 i = 0; i < width; i += 4)
{ {
// ExtractBlock(inBuf + i * 4, width, block); // ExtractBlock(inBuf + i * 4, width, block);
CompressBC7Block((const uint32 *)inBuf, outBuf); CompressBC7Block((const uint32 *)inBuf, outBuf);
@ -1521,12 +1520,11 @@ namespace BC7C
unsigned int height, unsigned int height,
BlockStatManager &statManager BlockStatManager &statManager
) { ) {
uint32 block[16];
BC7CompressionMode::MaxAnnealingIterations = min(BC7CompressionMode::kMaxAnnealingIterations, GetQualityLevel()); BC7CompressionMode::MaxAnnealingIterations = min(BC7CompressionMode::kMaxAnnealingIterations, GetQualityLevel());
for(int j = 0; j < height; j += 4) for(uint32 j = 0; j < height; j += 4)
{ {
for(int i = 0; i < width; i += 4) for(uint32 i = 0; i < width; i += 4)
{ {
// ExtractBlock(inBuf + i * 4, width, block); // ExtractBlock(inBuf + i * 4, width, block);
CompressBC7Block((const uint32 *)inBuf, outBuf, statManager); CompressBC7Block((const uint32 *)inBuf, outBuf, statManager);

View file

@ -39,7 +39,7 @@ public:
const EImageFileFormat m_FileFormat; const EImageFileFormat m_FileFormat;
static unsigned char *ReadFileData(const CHAR *filename); static unsigned char *ReadFileData(const CHAR *filename);
static bool WriteImageDataToFile(const uint8 *data, const uint32 dataSz, const CHAR *filename); static bool WriteImageDataToFile(const uint8 *data, const uint32 dataSz, const CHAR *filename);
static EImageFileFormat DetectFileFormat(const CHAR *filename); static EImageFileFormat DetectFileFormat(const CHAR *filename);
Image *LoadImage(const unsigned char *rawImageData) const; Image *LoadImage(const unsigned char *rawImageData) const;

View file

@ -5,6 +5,12 @@
#include <limits.h> #include <limits.h>
#include <assert.h> #include <assert.h>
///////////////////////////////////////////////////////////////////////////////
//
// Static helper functions
//
///////////////////////////////////////////////////////////////////////////////
template <typename T> template <typename T>
static inline T min(const T &a, const T &b) { static inline T min(const T &a, const T &b) {
return (a > b)? b : a; return (a > b)? b : a;
@ -15,6 +21,11 @@ static inline T abs(const T &a) {
return (a > 0)? a : -a; return (a > 0)? a : -a;
} }
template <typename T>
static inline T sad(const T &a, const T &b) {
return (a > b)? a - b : b - a;
}
void ReportError(const char *str) { void ReportError(const char *str) {
fprintf(stderr, "ImageLoader.cpp -- ERROR: %s\n", str); fprintf(stderr, "ImageLoader.cpp -- ERROR: %s\n", str);
} }
@ -59,8 +70,8 @@ unsigned int ImageLoader::GetChannelForPixel(uint32 x, uint32 y, uint32 ch) {
const uint32 val = data[pixelIdx]; const uint32 val = data[pixelIdx];
if(prec < 8) { if(prec < 8) {
uint32 ret = 0; int32 ret = 0;
for(uint32 precLeft = 8; precLeft > 0; precLeft -= min(prec, abs(prec - precLeft))) { for(uint32 precLeft = 8; precLeft > 0; precLeft -= min(prec, sad(prec, precLeft))) {
if(prec > precLeft) { if(prec > precLeft) {
const int toShift = prec - precLeft; const int toShift = prec - precLeft;
@ -77,7 +88,7 @@ unsigned int ImageLoader::GetChannelForPixel(uint32 x, uint32 y, uint32 ch) {
return ret; return ret;
} }
else if(prec > 8) { else if(prec > 8) {
const int toShift = prec - 8; const int32 toShift = prec - 8;
return val >> toShift; return val >> toShift;
} }
@ -113,59 +124,59 @@ bool ImageLoader::LoadImage() {
#endif #endif
int byteIdx = 0; int byteIdx = 0;
for(int i = 0; i < ah; i+=4) { for(uint32 i = 0; i < ah; i+=4) {
for(int j = 0; j < aw; j+= 4) { for(uint32 j = 0; j < aw; j+= 4) {
// For each block, visit the pixels in sequential order // For each block, visit the pixels in sequential order
for(int y = i; y < i+4; y++) { for(uint32 y = i; y < i+4; y++) {
for(int x = j; x < j+4; x++) { for(uint32 x = j; x < j+4; x++) {
if(y >= m_Height || x >= m_Width) { if(y >= m_Height || x >= m_Width) {
m_PixelData[byteIdx++] = 0; // r m_PixelData[byteIdx++] = 0; // r
m_PixelData[byteIdx++] = 0; // g m_PixelData[byteIdx++] = 0; // g
m_PixelData[byteIdx++] = 0; // b m_PixelData[byteIdx++] = 0; // b
m_PixelData[byteIdx++] = 0; // a m_PixelData[byteIdx++] = 0; // a
continue; continue;
} }
unsigned int redVal = GetChannelForPixel(x, y, 0); unsigned int redVal = GetChannelForPixel(x, y, 0);
if(redVal == INT_MAX) if(redVal == INT_MAX)
return false; return false;
unsigned int greenVal = redVal; unsigned int greenVal = redVal;
unsigned int blueVal = redVal; unsigned int blueVal = redVal;
if(GetGreenChannelPrecision() > 0) { if(GetGreenChannelPrecision() > 0) {
greenVal = GetChannelForPixel(x, y, 1); greenVal = GetChannelForPixel(x, y, 1);
if(greenVal == INT_MAX) if(greenVal == INT_MAX)
return false; return false;
} }
if(GetBlueChannelPrecision() > 0) { if(GetBlueChannelPrecision() > 0) {
blueVal = GetChannelForPixel(x, y, 2); blueVal = GetChannelForPixel(x, y, 2);
if(blueVal == INT_MAX) if(blueVal == INT_MAX)
return false; return false;
} }
unsigned int alphaVal = 0xFF; unsigned int alphaVal = 0xFF;
if(GetAlphaChannelPrecision() > 0) { if(GetAlphaChannelPrecision() > 0) {
alphaVal = GetChannelForPixel(x, y, 3); alphaVal = GetChannelForPixel(x, y, 3);
if(alphaVal == INT_MAX) if(alphaVal == INT_MAX)
return false; return false;
} }
// Red channel // Red channel
m_PixelData[byteIdx++] = redVal & 0xFF; m_PixelData[byteIdx++] = redVal & 0xFF;
// Green channel // Green channel
m_PixelData[byteIdx++] = greenVal & 0xFF; m_PixelData[byteIdx++] = greenVal & 0xFF;
// Blue channel // Blue channel
m_PixelData[byteIdx++] = blueVal & 0xFF; m_PixelData[byteIdx++] = blueVal & 0xFF;
// Alpha channel // Alpha channel
m_PixelData[byteIdx++] = alphaVal & 0xFF; m_PixelData[byteIdx++] = alphaVal & 0xFF;
} }
} }
} }
} }