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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -107,14 +107,14 @@ bool ImageLoaderPNG::ReadData() {
m_RedChannelPrecision = bitDepth;
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);
unsigned int rowOffset = i * m_Width;
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++];
}
@ -131,14 +131,14 @@ bool ImageLoaderPNG::ReadData() {
m_BlueChannelPrecision = bitDepth;
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);
unsigned int rowOffset = i * m_Width;
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_GreenData[rowOffset + j] = rowData[byteIdx++];
m_BlueData[rowOffset + j] = rowData[byteIdx++];
@ -158,14 +158,14 @@ bool ImageLoaderPNG::ReadData() {
m_AlphaChannelPrecision = bitDepth;
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);
unsigned int rowOffset = i * m_Width;
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_GreenData[rowOffset + j] = rowData[byteIdx++];
m_BlueData[rowOffset + j] = rowData[byteIdx++];
@ -182,14 +182,14 @@ bool ImageLoaderPNG::ReadData() {
m_AlphaChannelPrecision = bitDepth;
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);
unsigned int rowOffset = i * m_Width;
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_AlphaData[rowOffset + j] = rowData[byteIdx++];
}

View file

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

View file

@ -82,13 +82,13 @@ bool ImageWriterPNG::WriteImage() {
/* Initialize rows of PNG. */
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);
row_pointers[y] = row;
for (int x = 0; x < m_Width; ++x) {
for(int ch = 0; ch < 4; ch++) {
for (uint32 x = 0; x < m_Width; ++x) {
for(uint32 ch = 0; ch < 4; ch++) {
*row++ = GetChannelForPixel(x, y, ch);
}
}
@ -98,7 +98,7 @@ bool ImageWriterPNG::WriteImage() {
png_set_rows (png_ptr, info_ptr, row_pointers);
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);

View file

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