diff --git a/BPTCEncoder/src/BC7Compressor.cpp b/BPTCEncoder/src/BC7Compressor.cpp index 8a2a4f0..3c65f79 100755 --- a/BPTCEncoder/src/BC7Compressor.cpp +++ b/BPTCEncoder/src/BC7Compressor.cpp @@ -1402,7 +1402,7 @@ double BC7CompressionMode::Compress( } } - const bool rotated = bestAlphaIndices[anchorIdx] >> (nAlphaIndexBits - 1); + const bool rotated = (bestAlphaIndices[anchorIdx] >> (nAlphaIndexBits - 1)) > 0; if(m_Attributes->hasRotation && rotated) { uint8 * bp1 = reinterpret_cast(&pixel1[sidx]); uint8 * bp2 = reinterpret_cast(&pixel2[sidx]); @@ -1660,8 +1660,8 @@ namespace BC7C { double gdiff = sad(unCompData[k+1], inBuf[k+1]); double bdiff = sad(unCompData[k+2], inBuf[k+2]); double adiff = sad(unCompData[k+3], inBuf[k+3]); - const float asrc = static_cast(inBuf[k+3]); - const float adst = static_cast(unCompData[k+3]); + const double asrc = static_cast(inBuf[k+3]); + const double adst = static_cast(unCompData[k+3]); double avga = ((asrc + adst)*0.5)/255.0; diffSum += (rdiff + gdiff + bdiff + adiff) * avga; } @@ -2581,7 +2581,7 @@ namespace BC7C { assert(idxMode < 2); assert(rotMode < 4); - assert(shapeIdx < ((mode == 0)? 16 : 64)); + assert(shapeIdx < ((mode == 0)? 16U : 64U)); uint32 cp = attrs->colorChannelPrecision; const uint32 shift = 8 - cp; diff --git a/Base/src/Image.cpp b/Base/src/Image.cpp index 4e75758..498fb3a 100644 --- a/Base/src/Image.cpp +++ b/Base/src/Image.cpp @@ -139,7 +139,7 @@ double Image::ComputePSNR(Image *other) { const unsigned char *pixelDataRaw = ourData + i; const unsigned char *pixelDataUncomp = otherData + i; - float r[4], u[4]; + double r[4], u[4]; for(uint32 c = 0; c < 4; c++) { if(c == 3) { r[c] = pixelDataRaw[c] / 255.0; diff --git a/CLTool/src/clwin32.cpp b/CLTool/src/clwin32.cpp index 2f37c24..81d83dc 100644 --- a/CLTool/src/clwin32.cpp +++ b/CLTool/src/clwin32.cpp @@ -40,13 +40,18 @@ * * */ -#include -#include -#include + +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include +#include +#include #include #include -#include "BlockStats.h" +#include "ThreadSafeStreambuf.h" #include "TexComp.h" #include "ImageFile.h" #include "Image.h" @@ -211,15 +216,18 @@ int _tmain(int argc, _TCHAR* argv[]) return 1; } - Image img (*file.GetImage()) + Image img (*file.GetImage()); if(format == eCompressionFormat_PVRTC) { img.SetBlockStreamOrder(false); } - int numBlocks = (img.GetWidth() * img.GetHeight())/16; - BlockStatManager *statManager = NULL; + std::ofstream logFile; + ThreadSafeStreambuf streamBuf(std::cout); + std::ostream logStream(&streamBuf); if(bSaveLog) { - statManager = new BlockStatManager(numBlocks); + char logname[256]; + sprintf(logname, "%s.log", basename); + logFile.open(logname); } SCompressionSettings settings; @@ -230,15 +238,15 @@ int _tmain(int argc, _TCHAR* argv[]) settings.iQuality = quality; settings.iNumCompressions = numCompressions; settings.iJobSize = numJobs; - settings.pStatManager = statManager; + settings.logStream = &logStream; - CompressedImage *ci = img->Compress(settings); + CompressedImage *ci = CompressImage(&img, settings); if(NULL == ci) { fprintf(stderr, "Error compressing image!\n"); return 1; } - double PSNR = img->ComputePSNR(*ci); + double PSNR = img.ComputePSNR(ci); if(PSNR > 0.0) { fprintf(stdout, "PSNR: %.3f\n", PSNR); } @@ -246,12 +254,6 @@ int _tmain(int argc, _TCHAR* argv[]) fprintf(stderr, "Error computing PSNR\n"); } - if(bSaveLog) { - strcat_s(basename, ".log"); - statManager->ToFile(basename); - basename[strlen(basename) - 4] = '\0'; - } - if(format == eCompressionFormat_BPTC) { strcat_s(basename, "-bc7.png"); } else if(format == eCompressionFormat_PVRTC) { @@ -263,8 +265,8 @@ int _tmain(int argc, _TCHAR* argv[]) // Cleanup delete ci; - if(statManager) - delete statManager; + if(bSaveLog) + logFile.close(); return 0; } diff --git a/IO/src/ImageLoaderPNG.cpp b/IO/src/ImageLoaderPNG.cpp index 04a4ecc..62c2de5 100644 --- a/IO/src/ImageLoaderPNG.cpp +++ b/IO/src/ImageLoaderPNG.cpp @@ -134,7 +134,7 @@ bool ImageLoaderPNG::ReadData() { } const int numPixels = m_Width * m_Height; - png_uint_32 bpr = png_get_rowbytes(png_ptr, info_ptr); + png_size_t bpr = png_get_rowbytes(png_ptr, info_ptr); png_bytep rowData = new png_byte[bpr]; switch(colorType) { diff --git a/IO/src/ImageWriterPNG.cpp b/IO/src/ImageWriterPNG.cpp index c8bef79..d9d1344 100644 --- a/IO/src/ImageWriterPNG.cpp +++ b/IO/src/ImageWriterPNG.cpp @@ -77,7 +77,7 @@ public: unsigned char *stream = &(writer.m_RawFileData[writer.m_StreamPosition]); memcpy(stream, outBytes, byteCountToWrite); - writer.m_StreamPosition += byteCountToWrite; + writer.m_StreamPosition += static_cast(byteCountToWrite); } static void FlushStream(png_structp png_ptr) { /* Do nothing... */ } diff --git a/PVRTCEncoder/src/Image.cpp b/PVRTCEncoder/src/Image.cpp index e91176c..0de9335 100644 --- a/PVRTCEncoder/src/Image.cpp +++ b/PVRTCEncoder/src/Image.cpp @@ -50,6 +50,11 @@ * */ +#if _MSC_VER +# define _CRT_SECURE_NO_WARNINGS +# define snprintf _snprintf +#endif + #include "Image.h" #include @@ -58,11 +63,6 @@ #include #include -#if _MSC_VER -# define _CRT_SECURE_NO_WARNINGS -# define snprintf _snprintf -#endif - #include "Pixel.h" #include "../../Base/include/Image.h" @@ -287,7 +287,7 @@ void Image::ContentAwareDownscale(uint32 xtimes, uint32 ytimes, float g = a * ConvertChannelToFloat(m_Pixels[i].G(), bitDepth[2]); float b = a * ConvertChannelToFloat(m_Pixels[i].B(), bitDepth[3]); - I[i] = r * 0.21 + g * 0.71 + b * 0.07; + I[i] = r * 0.21f + g * 0.71f + b * 0.07f; } // Use central differences to calculate Ix, Iy, Ixx, Iyy... diff --git a/PVRTCEncoder/src/Pixel.cpp b/PVRTCEncoder/src/Pixel.cpp index c4bfe86..8ea763d 100644 --- a/PVRTCEncoder/src/Pixel.cpp +++ b/PVRTCEncoder/src/Pixel.cpp @@ -175,7 +175,7 @@ namespace PVRTCC { uint16 v = static_cast(val); v = (v + (1 << (bitsWasted - 1))) >> bitsWasted; v = ::std::min(::std::max(0, v), (1 << newDepth) - 1); - return v; + return static_cast(v); } }