diff --git a/BPTCEncoder/src/RGBAEndpoints.cpp b/BPTCEncoder/src/RGBAEndpoints.cpp index 6a02713..0483d7a 100755 --- a/BPTCEncoder/src/RGBAEndpoints.cpp +++ b/BPTCEncoder/src/RGBAEndpoints.cpp @@ -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; diff --git a/Core/src/CompressedImage.cpp b/Core/src/CompressedImage.cpp index 3404aeb..9ab288a 100644 --- a/Core/src/CompressedImage.cpp +++ b/Core/src/CompressedImage.cpp @@ -5,6 +5,7 @@ #include #include +#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; diff --git a/Core/src/Image.cpp b/Core/src/Image.cpp index 66d516b..629188c 100644 --- a/Core/src/Image.cpp +++ b/Core/src/Image.cpp @@ -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; diff --git a/Core/src/TexComp.cpp b/Core/src/TexComp.cpp index a06951e..563ea0a 100644 --- a/Core/src/TexComp.cpp +++ b/Core/src/TexComp.cpp @@ -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; diff --git a/Core/src/WorkerQueue.cpp b/Core/src/WorkerQueue.cpp index f8a3c23..113fa09 100644 --- a/Core/src/WorkerQueue.cpp +++ b/Core/src/WorkerQueue.cpp @@ -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]; diff --git a/Core/src/WorkerQueue.h b/Core/src/WorkerQueue.h index 3a13546..42a885c 100644 --- a/Core/src/WorkerQueue.h +++ b/Core/src/WorkerQueue.h @@ -10,7 +10,7 @@ class WorkerQueue; #include "Thread.h" #include "StopWatch.h" -struct WorkerThread : public TCCallable { +class WorkerThread : public TCCallable { friend class WorkerQueue; public: diff --git a/IO/src/ImageFile.cpp b/IO/src/ImageFile.cpp index 6451bfc..bbb0576 100644 --- a/IO/src/ImageFile.cpp +++ b/IO/src/ImageFile.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "ImageWriter.h" #include "ImageLoader.h" @@ -32,10 +33,10 @@ static inline T abs(const T &a) { return a > 0? a : -a; } -template -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; diff --git a/IO/src/ImageLoaderPNG.cpp b/IO/src/ImageLoaderPNG.cpp index bfefedd..87bc0f2 100644 --- a/IO/src/ImageLoaderPNG.cpp +++ b/IO/src/ImageLoaderPNG.cpp @@ -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++]; } diff --git a/IO/src/ImageLoaderPNG.h b/IO/src/ImageLoaderPNG.h index 209f17e..ff361ce 100644 --- a/IO/src/ImageLoaderPNG.h +++ b/IO/src/ImageLoaderPNG.h @@ -11,7 +11,7 @@ class ImageLoaderPNG : public ImageLoader { virtual bool ReadData(); private: - unsigned int m_StreamPosition; + uint64 m_StreamPosition; friend class PNGStreamReader; }; diff --git a/IO/src/ImageWriterPNG.cpp b/IO/src/ImageWriterPNG.cpp index 3b97442..49fb3d2 100644 --- a/IO/src/ImageWriterPNG.cpp +++ b/IO/src/ImageWriterPNG.cpp @@ -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); diff --git a/IO/src/ImageWriterPNG.h b/IO/src/ImageWriterPNG.h index c5dda26..948f501 100644 --- a/IO/src/ImageWriterPNG.h +++ b/IO/src/ImageWriterPNG.h @@ -12,7 +12,7 @@ class ImageWriterPNG : public ImageWriter { virtual bool WriteImage(); private: - uint32 m_StreamPosition; + uint64 m_StreamPosition; uint32 m_TotalBytesWritten; friend class PNGStreamWriter; };