Fix a bunch of compiler warnings.

This commit is contained in:
Pavel Krajcevski 2012-11-07 17:10:26 -05:00
parent 05e6ca0bc9
commit 680625d03e
11 changed files with 41 additions and 31 deletions

View file

@ -457,7 +457,7 @@ static uint32 PowerIteration(const RGBAMatrix &mat, RGBADir &eigVec, double &eig
for(int nTries = 0; nTries < 3; nTries++) { for(int nTries = 0; nTries < 3; nTries++) {
// !SPEED! Find eigenvectors by using the power method. This is good because the // !SPEED! Find eigenvectors by using the power method. This is good because the
// matrix is only 4x4, which allows us to use SIMD... // matrix is only 4x4, which allows us to use SIMD...
RGBAVector b = RGBAVector(rand()); RGBAVector b = RGBAVector(float(rand()));
assert(b.Length() > 0); assert(b.Length() > 0);
b /= b.Length(); b /= b.Length();
@ -480,7 +480,7 @@ static uint32 PowerIteration(const RGBAMatrix &mat, RGBADir &eigVec, double &eig
} }
eigVal = newB.Length(); eigVal = newB.Length();
newB /= eigVal; newB /= float(eigVal);
if(fabs(1.0f - (b * newB)) < 1e-5) if(fabs(1.0f - (b * newB)) < 1e-5)
fixed = true; fixed = true;

View file

@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include "TexCompTypes.h"
#include "BC7Compressor.h" #include "BC7Compressor.h"
CompressedImage::CompressedImage() CompressedImage::CompressedImage()
@ -66,7 +67,7 @@ CompressedImage::~CompressedImage() {
bool CompressedImage::DecompressImage(unsigned char *outBuf, unsigned int outBufSz) const { bool CompressedImage::DecompressImage(unsigned char *outBuf, unsigned int outBufSz) const {
// First make sure that we have enough data // First make sure that we have enough data
int dataSz = 0; uint32 dataSz = 0;
switch(m_Format) { switch(m_Format) {
case eCompressionFormat_DXT1: dataSz = m_DataSz * 8; break; case eCompressionFormat_DXT1: dataSz = m_DataSz * 8; break;
case eCompressionFormat_DXT5: dataSz = m_DataSz * 4; break; case eCompressionFormat_DXT5: dataSz = m_DataSz * 4; break;

View file

@ -75,7 +75,7 @@ double Image::ComputePSNR(const CompressedImage &ci) const {
const double wb = 1.0; const double wb = 1.0;
double MSE = 0.0; double MSE = 0.0;
for(int i = 0; i < imageSz; i+=4) { for(uint32 i = 0; i < imageSz; i+=4) {
const unsigned char *pixelDataRaw = m_PixelData + i; const unsigned char *pixelDataRaw = m_PixelData + i;
const unsigned char *pixelDataUncomp = unCompData + i; const unsigned char *pixelDataUncomp = unCompData + i;

View file

@ -225,7 +225,7 @@ bool CompressImageData(
} }
// Allocate data based on the compression method // Allocate data based on the compression method
int cmpDataSzNeeded = 0; uint32 cmpDataSzNeeded = 0;
switch(settings.format) { switch(settings.format) {
case eCompressionFormat_DXT1: cmpDataSzNeeded = dataSz / 8; case eCompressionFormat_DXT1: cmpDataSzNeeded = dataSz / 8;
case eCompressionFormat_DXT5: cmpDataSzNeeded = dataSz / 4; case eCompressionFormat_DXT5: cmpDataSzNeeded = dataSz / 4;

View file

@ -148,7 +148,7 @@ void WorkerQueue::Run() {
// Spawn a bunch of threads... // Spawn a bunch of threads...
TCLock lock(m_Mutex); TCLock lock(m_Mutex);
for(int i = 0; i < m_NumThreads; i++) { for(uint32 i = 0; i < m_NumThreads; i++) {
m_Workers[i] = new WorkerThread(this, i); m_Workers[i] = new WorkerThread(this, i);
m_ThreadHandles[m_ActiveThreads] = new TCThread(*m_Workers[i]); m_ThreadHandles[m_ActiveThreads] = new TCThread(*m_Workers[i]);
m_ActiveThreads++; m_ActiveThreads++;
@ -168,7 +168,7 @@ void WorkerQueue::Run() {
m_StopWatch.Stop(); m_StopWatch.Stop();
// Join them all together.. // Join them all together..
for(int i = 0; i < m_NumThreads; i++) { for(uint32 i = 0; i < m_NumThreads; i++) {
m_ThreadHandles[i]->Join(); m_ThreadHandles[i]->Join();
delete m_ThreadHandles[i]; delete m_ThreadHandles[i];
delete m_Workers[i]; delete m_Workers[i];

View file

@ -10,7 +10,7 @@ class WorkerQueue;
#include "Thread.h" #include "Thread.h"
#include "StopWatch.h" #include "StopWatch.h"
struct WorkerThread : public TCCallable { class WorkerThread : public TCCallable {
friend class WorkerQueue; friend class WorkerQueue;
public: public:

View file

@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
#include <assert.h> #include <assert.h>
#include <algorithm>
#include "ImageWriter.h" #include "ImageWriter.h"
#include "ImageLoader.h" #include "ImageLoader.h"
@ -32,10 +33,10 @@ static inline T abs(const T &a) {
return a > 0? a : -a; return a > 0? a : -a;
} }
template <typename T> //!HACK!
static inline T min(const T &a, const T &b) { #ifdef _MSC_VER
return (a < b)? a : b; #define strncpy strncpy_s
} #endif
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// //
@ -113,7 +114,7 @@ bool ImageFile::Write() {
return false; return false;
} }
WriteImageDataToFile(writer->GetRawFileData(), writer->GetRawFileDataSz(), m_Filename); WriteImageDataToFile(writer->GetRawFileData(), uint32(writer->GetRawFileDataSz()), m_Filename);
delete writer; delete writer;
return true; return true;
@ -154,13 +155,13 @@ Image *ImageFile::LoadImage(const unsigned char *rawImageData) const {
EImageFileFormat ImageFile::DetectFileFormat(const CHAR *filename) { EImageFileFormat ImageFile::DetectFileFormat(const CHAR *filename) {
int len = strlen(filename); size_t len = strlen(filename);
if(len >= 256) { if(len >= 256) {
// !FIXME! Report Error... // !FIXME! Report Error...
return kNumImageFileFormats; return kNumImageFileFormats;
} }
int dotPos = len - 1; size_t dotPos = len - 1;
while(dotPos >= 0 && filename[dotPos--] != '.'); while(dotPos >= 0 && filename[dotPos--] != '.');
@ -199,8 +200,16 @@ unsigned char *ImageFile::ReadFileData(const CHAR *filename) {
assert(fstr.Tell() == 0); assert(fstr.Tell() == 0);
// Read all of the data // Read all of the data
int32 bytesRead = fstr.Read(rawData, fileSize); uint64 totalBytesRead = 0;
if(bytesRead != fileSize) { uint64 totalBytesLeft = fileSize;
uint32 bytesToRead = uint32(std::min(totalBytesLeft, uint64(1 << 31)));
int32 bytesRead;
while((bytesRead = fstr.Read(rawData, uint32(fileSize))) >= 0) {
totalBytesRead += bytesRead;
totalBytesLeft -= bytesRead;
}
if(totalBytesRead != fileSize) {
assert(!"We didn't read as much data as we thought we had!"); assert(!"We didn't read as much data as we thought we had!");
fprintf(stderr, "Internal error: Incorrect file size assumption\n"); fprintf(stderr, "Internal error: Incorrect file size assumption\n");
return 0; return 0;

View file

@ -107,14 +107,14 @@ bool ImageLoaderPNG::ReadData() {
m_RedChannelPrecision = bitDepth; m_RedChannelPrecision = bitDepth;
m_RedData = new unsigned char[numPixels]; m_RedData = new unsigned char[numPixels];
for(int i = 0; i < m_Height; i++) { for(uint32 i = 0; i < m_Height; i++) {
png_read_row(png_ptr, rowData, NULL); png_read_row(png_ptr, rowData, NULL);
unsigned int rowOffset = i * m_Width; unsigned int rowOffset = i * m_Width;
unsigned int byteIdx = 0; unsigned int byteIdx = 0;
for(int j = 0; j < m_Width; j++) { for(uint32 j = 0; j < m_Width; j++) {
m_RedData[rowOffset + j] = rowData[byteIdx++]; m_RedData[rowOffset + j] = rowData[byteIdx++];
} }
@ -131,14 +131,14 @@ bool ImageLoaderPNG::ReadData() {
m_BlueChannelPrecision = bitDepth; m_BlueChannelPrecision = bitDepth;
m_BlueData = new unsigned char[numPixels]; m_BlueData = new unsigned char[numPixels];
for(int i = 0; i < m_Height; i++) { for(uint32 i = 0; i < m_Height; i++) {
png_read_row(png_ptr, rowData, NULL); png_read_row(png_ptr, rowData, NULL);
unsigned int rowOffset = i * m_Width; unsigned int rowOffset = i * m_Width;
unsigned int byteIdx = 0; unsigned int byteIdx = 0;
for(int j = 0; j < m_Width; j++) { for(uint32 j = 0; j < m_Width; j++) {
m_RedData[rowOffset + j] = rowData[byteIdx++]; m_RedData[rowOffset + j] = rowData[byteIdx++];
m_GreenData[rowOffset + j] = rowData[byteIdx++]; m_GreenData[rowOffset + j] = rowData[byteIdx++];
m_BlueData[rowOffset + j] = rowData[byteIdx++]; m_BlueData[rowOffset + j] = rowData[byteIdx++];
@ -158,14 +158,14 @@ bool ImageLoaderPNG::ReadData() {
m_AlphaChannelPrecision = bitDepth; m_AlphaChannelPrecision = bitDepth;
m_AlphaData = new unsigned char[numPixels]; m_AlphaData = new unsigned char[numPixels];
for(int i = 0; i < m_Height; i++) { for(uint32 i = 0; i < m_Height; i++) {
png_read_row(png_ptr, rowData, NULL); png_read_row(png_ptr, rowData, NULL);
unsigned int rowOffset = i * m_Width; unsigned int rowOffset = i * m_Width;
unsigned int byteIdx = 0; unsigned int byteIdx = 0;
for(int j = 0; j < m_Width; j++) { for(uint32 j = 0; j < m_Width; j++) {
m_RedData[rowOffset + j] = rowData[byteIdx++]; m_RedData[rowOffset + j] = rowData[byteIdx++];
m_GreenData[rowOffset + j] = rowData[byteIdx++]; m_GreenData[rowOffset + j] = rowData[byteIdx++];
m_BlueData[rowOffset + j] = rowData[byteIdx++]; m_BlueData[rowOffset + j] = rowData[byteIdx++];
@ -182,14 +182,14 @@ bool ImageLoaderPNG::ReadData() {
m_AlphaChannelPrecision = bitDepth; m_AlphaChannelPrecision = bitDepth;
m_AlphaData = new unsigned char[numPixels]; m_AlphaData = new unsigned char[numPixels];
for(int i = 0; i < m_Height; i++) { for(uint32 i = 0; i < m_Height; i++) {
png_read_row(png_ptr, rowData, NULL); png_read_row(png_ptr, rowData, NULL);
unsigned int rowOffset = i * m_Width; unsigned int rowOffset = i * m_Width;
unsigned int byteIdx = 0; unsigned int byteIdx = 0;
for(int j = 0; j < m_Width; j++) { for(uint32 j = 0; j < m_Width; j++) {
m_RedData[rowOffset + j] = rowData[byteIdx++]; m_RedData[rowOffset + j] = rowData[byteIdx++];
m_AlphaData[rowOffset + j] = rowData[byteIdx++]; m_AlphaData[rowOffset + j] = rowData[byteIdx++];
} }

View file

@ -11,7 +11,7 @@ class ImageLoaderPNG : public ImageLoader {
virtual bool ReadData(); virtual bool ReadData();
private: private:
unsigned int m_StreamPosition; uint64 m_StreamPosition;
friend class PNGStreamReader; friend class PNGStreamReader;
}; };

View file

@ -82,13 +82,13 @@ bool ImageWriterPNG::WriteImage() {
/* Initialize rows of PNG. */ /* Initialize rows of PNG. */
row_pointers = (png_byte **)png_malloc (png_ptr, m_Height * sizeof (png_byte *)); row_pointers = (png_byte **)png_malloc (png_ptr, m_Height * sizeof (png_byte *));
for (int y = 0; y < m_Height; ++y) { for (uint32 y = 0; y < m_Height; ++y) {
png_byte *row = (png_byte *)png_malloc (png_ptr, sizeof (uint8) * m_Width * pixel_size); png_byte *row = (png_byte *)png_malloc (png_ptr, sizeof (uint8) * m_Width * pixel_size);
row_pointers[y] = row; row_pointers[y] = row;
for (int x = 0; x < m_Width; ++x) { for (uint32 x = 0; x < m_Width; ++x) {
for(int ch = 0; ch < 4; ch++) { for(uint32 ch = 0; ch < 4; ch++) {
*row++ = GetChannelForPixel(x, y, ch); *row++ = GetChannelForPixel(x, y, ch);
} }
} }
@ -98,7 +98,7 @@ bool ImageWriterPNG::WriteImage() {
png_set_rows (png_ptr, info_ptr, row_pointers); png_set_rows (png_ptr, info_ptr, row_pointers);
png_write_png (png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); png_write_png (png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
for (int y = 0; y < m_Height; y++) { for (uint32 y = 0; y < m_Height; y++) {
png_free (png_ptr, row_pointers[y]); png_free (png_ptr, row_pointers[y]);
} }
png_free (png_ptr, row_pointers); png_free (png_ptr, row_pointers);

View file

@ -12,7 +12,7 @@ class ImageWriterPNG : public ImageWriter {
virtual bool WriteImage(); virtual bool WriteImage();
private: private:
uint32 m_StreamPosition; uint64 m_StreamPosition;
uint32 m_TotalBytesWritten; uint32 m_TotalBytesWritten;
friend class PNGStreamWriter; friend class PNGStreamWriter;
}; };