From e8b58e3fd0d96b5b906b49c8c522259e41cacf0f Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Wed, 17 Feb 2016 12:27:09 -0500 Subject: [PATCH] Fix some MSVC rot --- ASTCEncoder/test/CMakeLists.txt | 12 +----------- Base/include/FasTC/Image.h | 4 ++-- Base/src/Image.cpp | 34 ++++++++++++++++----------------- Base/test/TestImage.cpp | 23 +++++++++++++--------- CLTool/src/compare.cpp | 2 +- PVRTCEncoder/src/Compressor.cpp | 6 +++--- 6 files changed, 38 insertions(+), 43 deletions(-) diff --git a/ASTCEncoder/test/CMakeLists.txt b/ASTCEncoder/test/CMakeLists.txt index 4159140..3238a18 100644 --- a/ASTCEncoder/test/CMakeLists.txt +++ b/ASTCEncoder/test/CMakeLists.txt @@ -122,14 +122,4 @@ TARGET_LINK_LIBRARIES(${TEST_NAME} FasTCBase) TARGET_LINK_LIBRARIES(${TEST_NAME} FasTCIO) TARGET_LINK_LIBRARIES(${TEST_NAME} FasTCCore) -IF(MSVC) - ADD_TEST(${TEST_NAME} - ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR}/Debug/${TEST_NAME} - ) -ELSE() - ADD_TEST(${TEST_NAME} - ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME} - ) -ENDIF() +ADD_TEST(NAME ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${TEST_NAME}) \ No newline at end of file diff --git a/Base/include/FasTC/Image.h b/Base/include/FasTC/Image.h index 4723370..50dc215 100644 --- a/Base/include/FasTC/Image.h +++ b/Base/include/FasTC/Image.h @@ -133,8 +133,8 @@ namespace FasTC { Image *channelTwo, Image *channelThree); - extern void DiscreteCosineXForm(Image *img, int blockSize); - extern void InvDiscreteCosineXForm(Image *img, int blockSize); + extern void DiscreteCosineXForm(Image *img, uint32 blockSize); + extern void InvDiscreteCosineXForm(Image *img, uint32 blockSize); } // namespace FasTC #endif // __TEXCOMP_IMAGE_H__ diff --git a/Base/src/Image.cpp b/Base/src/Image.cpp index 8754392..34417a7 100644 --- a/Base/src/Image.cpp +++ b/Base/src/Image.cpp @@ -43,6 +43,9 @@ #include "FasTC/Image.h" +#define _USE_MATH_DEFINES +#include + #include #include #include @@ -50,9 +53,6 @@ #include #include -#define _USE_MATH_DEFINES -#include - #include "FasTC/Color.h" #include "FasTC/Pixel.h" #include "FasTC/IPixel.h" @@ -737,7 +737,7 @@ static void IDCT(Image *img) { if (u == 0 && v == 0) { idct /= N; } else if (u == 0 || v == 0) { - idct *= sqrt(2) / N; + idct *= sqrtf(2) / N; } else { idct *= 2 / N; } @@ -751,20 +751,20 @@ static void IDCT(Image *img) { *img = new_img; } -static void RunDCTBlockFn(Image *img, int blockSize, DCTBlockFn fn) { +static void RunDCTBlockFn(Image *img, uint32 blockSize, DCTBlockFn fn) { assert (NULL != fn); assert (0 < blockSize); - assert (static_cast(blockSize) < img->GetWidth()); - assert (static_cast(blockSize) < img->GetHeight()); + assert (blockSize < img->GetWidth()); + assert (blockSize < img->GetHeight()); Image block(blockSize, blockSize); - for (unsigned int j = 0; j < img->GetHeight(); j += blockSize) { - for (unsigned int i = 0; i < img->GetWidth(); i += blockSize) { + for (uint32 j = 0; j < img->GetHeight(); j += blockSize) { + for (uint32 i = 0; i < img->GetWidth(); i += blockSize) { // Populate block - for (int y = 0; y < blockSize; ++y) { - for (int x = 0; x < blockSize; ++x) { - IPixel xx = std::min(img->GetWidth() - 1, i + x); - IPixel yy = std::min(img->GetHeight() - 1, j + y); + for (uint32 y = 0; y < blockSize; ++y) { + for (uint32 x = 0; x < blockSize; ++x) { + uint32 xx = std::min(img->GetWidth() - 1, i + x); + uint32 yy = std::min(img->GetHeight() - 1, j + y); block(x, y) = (*img)(xx, yy); } } @@ -773,8 +773,8 @@ static void RunDCTBlockFn(Image *img, int blockSize, DCTBlockFn fn) { fn(&block); // Put it back in the original image - for (int y = 0; y < blockSize; ++y) { - for (int x = 0; x < blockSize; ++x) { + for (uint32 y = 0; y < blockSize; ++y) { + for (uint32 x = 0; x < blockSize; ++x) { if (i + x >= img->GetWidth()) { continue; } @@ -793,11 +793,11 @@ static void RunDCTBlockFn(Image *img, int blockSize, DCTBlockFn fn) { } } -void DiscreteCosineXForm(Image *img, int blockSize) { +void DiscreteCosineXForm(Image *img, uint32 blockSize) { RunDCTBlockFn(img, blockSize, DCT); } -void InvDiscreteCosineXForm(Image *img, int blockSize) { +void InvDiscreteCosineXForm(Image *img, uint32 blockSize) { RunDCTBlockFn(img, blockSize, IDCT); } diff --git a/Base/test/TestImage.cpp b/Base/test/TestImage.cpp index 419bca7..d099ceb 100644 --- a/Base/test/TestImage.cpp +++ b/Base/test/TestImage.cpp @@ -58,6 +58,7 @@ #include "Utils.h" #include +#include TEST(Image, NonSpecificConstructor) { FasTC::Pixel p; @@ -188,16 +189,20 @@ TEST(Image, SplitImage) { for(uint32 j = 0; j < h; j++) { for(uint32 i = 0; i < w; i++) { - EXPECT_EQ(i1(i, j), img(i, j).R()); - EXPECT_EQ(i2(i, j), img(i, j).G()); - EXPECT_EQ(i3(i, j), img(i, j).B()); + EXPECT_FLOAT_EQ(i1(i, j), img(i, j).R()); + EXPECT_FLOAT_EQ(i2(i, j), img(i, j).G()); + EXPECT_FLOAT_EQ(i3(i, j), img(i, j).B()); } } FasTC::Image img2(w, h); for(uint32 j = 0; j < h; j++) { for(uint32 i = 0; i < w; i++) { - img2(i, j) = FasTC::Color(j, i, i*j, 255); + const float r = static_cast(j); + const float g = static_cast(i); + const float b = static_cast(i*j); + const float a = 255.0f; + img2(i, j) = FasTC::Color(r, g, b, a); } } @@ -205,9 +210,9 @@ TEST(Image, SplitImage) { for(uint32 j = 0; j < h; j++) { for(uint32 i = 0; i < w; i++) { - EXPECT_EQ(i1(i, j), img2(i, j).R()); - EXPECT_EQ(i2(i, j), img2(i, j).G()); - EXPECT_EQ(i3(i, j), img2(i, j).B()); + EXPECT_FLOAT_EQ(i1(i, j), img2(i, j).R()); + EXPECT_FLOAT_EQ(i2(i, j), img2(i, j).G()); + EXPECT_FLOAT_EQ(i3(i, j), img2(i, j).B()); } } } @@ -247,7 +252,7 @@ TEST(Image, IDCT) { FasTC::Image img(w, h); for (uint32 j = 0; j < h; ++j) { for (uint32 i = 0; i < w; ++i) { - img(i, j) = static_cast(i + j); + img(i, j) = static_cast(i + j); } } @@ -260,7 +265,7 @@ TEST(Image, IDCT) { // First make sure they're different for (uint32 j = 0; j < h; ++j) { for (uint32 i = 0; i < w; ++i) { - EXPECT_NE(img(i, j), orig(i, j)); + EXPECT_PRED2(std::not_equal_to(), img(i, j), orig(i, j)); } } diff --git a/CLTool/src/compare.cpp b/CLTool/src/compare.cpp index f5d9670..aabcc52 100644 --- a/CLTool/src/compare.cpp +++ b/CLTool/src/compare.cpp @@ -71,7 +71,7 @@ void gen_random(char *s, const int len) { "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; - srand(time(NULL)); + srand(static_cast(time(NULL))); for (int i = 0; i < len; ++i) { s[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; } diff --git a/PVRTCEncoder/src/Compressor.cpp b/PVRTCEncoder/src/Compressor.cpp index fcf1149..31bccb0 100644 --- a/PVRTCEncoder/src/Compressor.cpp +++ b/PVRTCEncoder/src/Compressor.cpp @@ -459,7 +459,7 @@ namespace PVRTCC { neighbors[2] = &(labels[idxr(i+1, j+1)]); // Add bottom label - neighbors[3] = &(labels[idxr(i, j+1)]); + neighbors[3] = &(labels[idxr(i, j+1)]); // Add bottom left label neighbors[4] = &(labels[idxr(i-1, j+1)]); @@ -571,9 +571,9 @@ namespace PVRTCC { #endif // Average all of the values together now... FasTC::Color high, low; - Indexer localIdxr(4, 4); + Indexer localIdxr(4, 4); for(uint32 y = 0; y < localIdxr.GetHeight(); y++) - for(uint32 x = 0; x < localIdxr.GetWidth(); x++) { + for(uint32 x = 0; x < localIdxr.GetWidth(); x++) { uint32 idx = localIdxr(x, y); FasTC::Color c = blockColors[0][idx]; if(c.A() < 0.0f) {