From 7e2a9d1adb577da8343ce184a14297c0fe1bdf31 Mon Sep 17 00:00:00 2001 From: castano Date: Tue, 2 Dec 2014 20:23:21 +0000 Subject: [PATCH] osx fixes. Fix issue 211. --- cmake/OptimalOptions.cmake | 4 + configure | 2 +- src/CMakeLists.txt | 2 + src/{nvtt => }/bc6h/CMakeLists.txt | 4 +- src/{nvtt => }/bc6h/bits.h | 0 src/{nvtt => }/bc6h/shapes_two.h | 0 src/{nvtt => }/bc6h/tile.h | 0 src/{nvtt => }/bc6h/zoh.cpp | 0 src/{nvtt => }/bc6h/zoh.h | 0 src/{nvtt => }/bc6h/zoh_utils.cpp | 0 src/{nvtt => }/bc6h/zoh_utils.h | 0 src/{nvtt => }/bc6h/zohone.cpp | 0 src/{nvtt => }/bc6h/zohtwo.cpp | 0 src/{nvtt => }/bc7/CMakeLists.txt | 4 +- src/{nvtt => }/bc7/avpcl.cpp | 0 src/{nvtt => }/bc7/avpcl.h | 0 src/{nvtt => }/bc7/avpcl_mode0.cpp | 2 +- src/{nvtt => }/bc7/avpcl_mode1.cpp | 2 +- src/{nvtt => }/bc7/avpcl_mode2.cpp | 2 +- src/{nvtt => }/bc7/avpcl_mode3.cpp | 2 +- src/{nvtt => }/bc7/avpcl_mode4.cpp | 2 +- src/{nvtt => }/bc7/avpcl_mode5.cpp | 2 +- src/{nvtt => }/bc7/avpcl_mode6.cpp | 2 +- src/{nvtt => }/bc7/avpcl_mode7.cpp | 2 +- src/{nvtt => }/bc7/avpcl_utils.cpp | 0 src/{nvtt => }/bc7/avpcl_utils.h | 0 src/{nvtt => }/bc7/bits.h | 0 src/{nvtt => }/bc7/endpts.h | 0 src/{nvtt => }/bc7/shapes_three.h | 0 src/{nvtt => }/bc7/shapes_two.h | 0 src/{nvtt => }/bc7/tile.h | 0 src/nvimage/BlockDXT.cpp | 4 +- src/nvimage/CMakeLists.txt | 2 +- src/nvtt/CMakeLists.txt | 3 +- src/nvtt/CompressorDXT1.cpp | 98 +++- src/nvtt/CompressorDXT1.h | 19 +- src/nvtt/QuickCompressDXT.cpp | 108 +---- src/nvtt/tools/CMakeLists.txt | 4 +- src/nvtt/tools/compressdialog.cpp | 93 ---- src/nvtt/tools/compressdialog.h | 9 - src/nvtt/tools/compressdialog.ui | 738 ++--------------------------- src/nvtt/tools/thumbnailer.cpp | 2 +- 42 files changed, 174 insertions(+), 938 deletions(-) rename src/{nvtt => }/bc6h/CMakeLists.txt (92%) rename src/{nvtt => }/bc6h/bits.h (100%) rename src/{nvtt => }/bc6h/shapes_two.h (100%) rename src/{nvtt => }/bc6h/tile.h (100%) rename src/{nvtt => }/bc6h/zoh.cpp (100%) rename src/{nvtt => }/bc6h/zoh.h (100%) rename src/{nvtt => }/bc6h/zoh_utils.cpp (100%) rename src/{nvtt => }/bc6h/zoh_utils.h (100%) rename src/{nvtt => }/bc6h/zohone.cpp (100%) rename src/{nvtt => }/bc6h/zohtwo.cpp (100%) rename src/{nvtt => }/bc7/CMakeLists.txt (93%) rename src/{nvtt => }/bc7/avpcl.cpp (100%) rename src/{nvtt => }/bc7/avpcl.h (100%) rename src/{nvtt => }/bc7/avpcl_mode0.cpp (96%) rename src/{nvtt => }/bc7/avpcl_mode1.cpp (96%) rename src/{nvtt => }/bc7/avpcl_mode2.cpp (96%) rename src/{nvtt => }/bc7/avpcl_mode3.cpp (96%) rename src/{nvtt => }/bc7/avpcl_mode4.cpp (96%) rename src/{nvtt => }/bc7/avpcl_mode5.cpp (96%) rename src/{nvtt => }/bc7/avpcl_mode6.cpp (96%) rename src/{nvtt => }/bc7/avpcl_mode7.cpp (96%) rename src/{nvtt => }/bc7/avpcl_utils.cpp (100%) rename src/{nvtt => }/bc7/avpcl_utils.h (100%) rename src/{nvtt => }/bc7/bits.h (100%) rename src/{nvtt => }/bc7/endpts.h (100%) rename src/{nvtt => }/bc7/shapes_three.h (100%) rename src/{nvtt => }/bc7/shapes_two.h (100%) rename src/{nvtt => }/bc7/tile.h (100%) diff --git a/cmake/OptimalOptions.cmake b/cmake/OptimalOptions.cmake index 74fe80d..ac450c9 100644 --- a/cmake/OptimalOptions.cmake +++ b/cmake/OptimalOptions.cmake @@ -35,6 +35,10 @@ IF(CMAKE_COMPILER_IS_GNUCXX) # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk") # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk") # ENDIF(DARWIN) + IF(APPLE) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch i586 -arch x86_64 -msse3 -mmacosx-version-min=10.5") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch i586 -arch x86_64 -msse3 -mmacosx-version-min=10.5") + ENDIF(APPLE) IF(CMAKE_BUILD_TYPE STREQUAL "debug") ADD_DEFINITIONS(-D_DEBUG) diff --git a/configure b/configure index 579e78d..bb788ff 100755 --- a/configure +++ b/configure @@ -52,7 +52,7 @@ echo "-- Configuring nvidia-texture-tools "`cat VERSION` mkdir -p ./build-$build cd ./build-$build -$CMAKE .. -DNVTT_SHARED=1 -DCMAKE_BUILD_TYPE=$build -DCMAKE_INSTALL_PREFIX=$prefix -G "Unix Makefiles" || exit 1 +$CMAKE .. -DNVTT_SHARED=0 -DCMAKE_BUILD_TYPE=$build -DCMAKE_INSTALL_PREFIX=$prefix -G "Unix Makefiles" || exit 1 cd .. echo "" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5dc953e..d7f3bd4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,8 @@ SUBDIRS(nvmath) SUBDIRS(nvimage) SUBDIRS(nvthread) SUBDIRS(nvtt) +SUBDIRS(bc6h) +SUBDIRS(bc7) # OpenGL INCLUDE(FindOpenGL) diff --git a/src/nvtt/bc6h/CMakeLists.txt b/src/bc6h/CMakeLists.txt similarity index 92% rename from src/nvtt/bc6h/CMakeLists.txt rename to src/bc6h/CMakeLists.txt index 816b65e..635e0f3 100644 --- a/src/nvtt/bc6h/CMakeLists.txt +++ b/src/bc6h/CMakeLists.txt @@ -6,8 +6,8 @@ SET(BC6H_SRCS bits.h shapes_two.h tile.h - utils.cpp - utils.h + zoh_utils.cpp + zoh_utils.h zoh.cpp zoh.h zohone.cpp diff --git a/src/nvtt/bc6h/bits.h b/src/bc6h/bits.h similarity index 100% rename from src/nvtt/bc6h/bits.h rename to src/bc6h/bits.h diff --git a/src/nvtt/bc6h/shapes_two.h b/src/bc6h/shapes_two.h similarity index 100% rename from src/nvtt/bc6h/shapes_two.h rename to src/bc6h/shapes_two.h diff --git a/src/nvtt/bc6h/tile.h b/src/bc6h/tile.h similarity index 100% rename from src/nvtt/bc6h/tile.h rename to src/bc6h/tile.h diff --git a/src/nvtt/bc6h/zoh.cpp b/src/bc6h/zoh.cpp similarity index 100% rename from src/nvtt/bc6h/zoh.cpp rename to src/bc6h/zoh.cpp diff --git a/src/nvtt/bc6h/zoh.h b/src/bc6h/zoh.h similarity index 100% rename from src/nvtt/bc6h/zoh.h rename to src/bc6h/zoh.h diff --git a/src/nvtt/bc6h/zoh_utils.cpp b/src/bc6h/zoh_utils.cpp similarity index 100% rename from src/nvtt/bc6h/zoh_utils.cpp rename to src/bc6h/zoh_utils.cpp diff --git a/src/nvtt/bc6h/zoh_utils.h b/src/bc6h/zoh_utils.h similarity index 100% rename from src/nvtt/bc6h/zoh_utils.h rename to src/bc6h/zoh_utils.h diff --git a/src/nvtt/bc6h/zohone.cpp b/src/bc6h/zohone.cpp similarity index 100% rename from src/nvtt/bc6h/zohone.cpp rename to src/bc6h/zohone.cpp diff --git a/src/nvtt/bc6h/zohtwo.cpp b/src/bc6h/zohtwo.cpp similarity index 100% rename from src/nvtt/bc6h/zohtwo.cpp rename to src/bc6h/zohtwo.cpp diff --git a/src/nvtt/bc7/CMakeLists.txt b/src/bc7/CMakeLists.txt similarity index 93% rename from src/nvtt/bc7/CMakeLists.txt rename to src/bc7/CMakeLists.txt index 5806535..4126af7 100644 --- a/src/nvtt/bc7/CMakeLists.txt +++ b/src/bc7/CMakeLists.txt @@ -18,8 +18,8 @@ SET(BC7_SRCS shapes_three.h shapes_two.h tile.h - utils.cpp - utils.h) + avpcl_utils.cpp + avpcl_utils.h) ADD_LIBRARY(bc7 STATIC ${BC7_SRCS}) diff --git a/src/nvtt/bc7/avpcl.cpp b/src/bc7/avpcl.cpp similarity index 100% rename from src/nvtt/bc7/avpcl.cpp rename to src/bc7/avpcl.cpp diff --git a/src/nvtt/bc7/avpcl.h b/src/bc7/avpcl.h similarity index 100% rename from src/nvtt/bc7/avpcl.h rename to src/bc7/avpcl.h diff --git a/src/nvtt/bc7/avpcl_mode0.cpp b/src/bc7/avpcl_mode0.cpp similarity index 96% rename from src/nvtt/bc7/avpcl_mode0.cpp rename to src/bc7/avpcl_mode0.cpp index cc83ad2..443b7c8 100644 --- a/src/nvtt/bc7/avpcl_mode0.cpp +++ b/src/bc7/avpcl_mode0.cpp @@ -67,7 +67,7 @@ struct Pattern int transformed; // if 0, deltas are unsigned and no transform; otherwise, signed and transformed int mode; // associated mode value int modebits; // number of mode bits - char *encoding; // verilog description of encoding for this mode + const char *encoding; // verilog description of encoding for this mode }; #define NPATTERNS 1 diff --git a/src/nvtt/bc7/avpcl_mode1.cpp b/src/bc7/avpcl_mode1.cpp similarity index 96% rename from src/nvtt/bc7/avpcl_mode1.cpp rename to src/bc7/avpcl_mode1.cpp index f8d03dc..fa1f112 100644 --- a/src/nvtt/bc7/avpcl_mode1.cpp +++ b/src/bc7/avpcl_mode1.cpp @@ -61,7 +61,7 @@ struct Pattern int transformed; // if 0, deltas are unsigned and no transform; otherwise, signed and transformed int mode; // associated mode value int modebits; // number of mode bits - char *encoding; // verilog description of encoding for this mode + const char *encoding; // verilog description of encoding for this mode }; #define NPATTERNS 1 diff --git a/src/nvtt/bc7/avpcl_mode2.cpp b/src/bc7/avpcl_mode2.cpp similarity index 96% rename from src/nvtt/bc7/avpcl_mode2.cpp rename to src/bc7/avpcl_mode2.cpp index 1d903eb..2a03691 100644 --- a/src/nvtt/bc7/avpcl_mode2.cpp +++ b/src/bc7/avpcl_mode2.cpp @@ -57,7 +57,7 @@ struct Pattern int transformed; // if 0, deltas are unsigned and no transform; otherwise, signed and transformed int mode; // associated mode value int modebits; // number of mode bits - char *encoding; // verilog description of encoding for this mode + const char *encoding; // verilog description of encoding for this mode }; #define NPATTERNS 1 diff --git a/src/nvtt/bc7/avpcl_mode3.cpp b/src/bc7/avpcl_mode3.cpp similarity index 96% rename from src/nvtt/bc7/avpcl_mode3.cpp rename to src/bc7/avpcl_mode3.cpp index 282ac8a..9861582 100644 --- a/src/nvtt/bc7/avpcl_mode3.cpp +++ b/src/bc7/avpcl_mode3.cpp @@ -61,7 +61,7 @@ struct Pattern int transformed; // if 0, deltas are unsigned and no transform; otherwise, signed and transformed int mode; // associated mode value int modebits; // number of mode bits - char *encoding; // verilog description of encoding for this mode + const char *encoding; // verilog description of encoding for this mode }; #define NPATTERNS 1 diff --git a/src/nvtt/bc7/avpcl_mode4.cpp b/src/bc7/avpcl_mode4.cpp similarity index 96% rename from src/nvtt/bc7/avpcl_mode4.cpp rename to src/bc7/avpcl_mode4.cpp index 4be6d3a..fdb603e 100644 --- a/src/nvtt/bc7/avpcl_mode4.cpp +++ b/src/bc7/avpcl_mode4.cpp @@ -87,7 +87,7 @@ struct Pattern int transform_mode; // x0 means alpha channel not transformed, x1 otherwise. 0x rgb not transformed, 1x otherwise. int mode; // associated mode value int modebits; // number of mode bits - char *encoding; // verilog description of encoding for this mode + const char *encoding; // verilog description of encoding for this mode }; #define TRANSFORM_MODE_ALPHA 1 diff --git a/src/nvtt/bc7/avpcl_mode5.cpp b/src/bc7/avpcl_mode5.cpp similarity index 96% rename from src/nvtt/bc7/avpcl_mode5.cpp rename to src/bc7/avpcl_mode5.cpp index 02bcf3c..b091d20 100644 --- a/src/nvtt/bc7/avpcl_mode5.cpp +++ b/src/bc7/avpcl_mode5.cpp @@ -87,7 +87,7 @@ struct Pattern int transform_mode; // x0 means alpha channel not transformed, x1 otherwise. 0x rgb not transformed, 1x otherwise. int mode; // associated mode value int modebits; // number of mode bits - char *encoding; // verilog description of encoding for this mode + const char *encoding; // verilog description of encoding for this mode }; #define TRANSFORM_MODE_ALPHA 1 diff --git a/src/nvtt/bc7/avpcl_mode6.cpp b/src/bc7/avpcl_mode6.cpp similarity index 96% rename from src/nvtt/bc7/avpcl_mode6.cpp rename to src/bc7/avpcl_mode6.cpp index 01103ca..93fb9ff 100644 --- a/src/nvtt/bc7/avpcl_mode6.cpp +++ b/src/bc7/avpcl_mode6.cpp @@ -62,7 +62,7 @@ struct Pattern ChanBits chan[NCHANNELS_RGBA];// bit patterns used per channel int mode; // associated mode value int modebits; // number of mode bits - char *encoding; // verilog description of encoding for this mode + const char *encoding; // verilog description of encoding for this mode }; #define NPATTERNS 1 diff --git a/src/nvtt/bc7/avpcl_mode7.cpp b/src/bc7/avpcl_mode7.cpp similarity index 96% rename from src/nvtt/bc7/avpcl_mode7.cpp rename to src/bc7/avpcl_mode7.cpp index 6733e02..e808742 100644 --- a/src/nvtt/bc7/avpcl_mode7.cpp +++ b/src/bc7/avpcl_mode7.cpp @@ -61,7 +61,7 @@ struct Pattern int transformed; // if 0, deltas are unsigned and no transform; otherwise, signed and transformed int mode; // associated mode value int modebits; // number of mode bits - char *encoding; // verilog description of encoding for this mode + const char *encoding; // verilog description of encoding for this mode }; #define NPATTERNS 1 diff --git a/src/nvtt/bc7/avpcl_utils.cpp b/src/bc7/avpcl_utils.cpp similarity index 100% rename from src/nvtt/bc7/avpcl_utils.cpp rename to src/bc7/avpcl_utils.cpp diff --git a/src/nvtt/bc7/avpcl_utils.h b/src/bc7/avpcl_utils.h similarity index 100% rename from src/nvtt/bc7/avpcl_utils.h rename to src/bc7/avpcl_utils.h diff --git a/src/nvtt/bc7/bits.h b/src/bc7/bits.h similarity index 100% rename from src/nvtt/bc7/bits.h rename to src/bc7/bits.h diff --git a/src/nvtt/bc7/endpts.h b/src/bc7/endpts.h similarity index 100% rename from src/nvtt/bc7/endpts.h rename to src/bc7/endpts.h diff --git a/src/nvtt/bc7/shapes_three.h b/src/bc7/shapes_three.h similarity index 100% rename from src/nvtt/bc7/shapes_three.h rename to src/bc7/shapes_three.h diff --git a/src/nvtt/bc7/shapes_two.h b/src/bc7/shapes_two.h similarity index 100% rename from src/nvtt/bc7/shapes_two.h rename to src/bc7/shapes_two.h diff --git a/src/nvtt/bc7/tile.h b/src/bc7/tile.h similarity index 100% rename from src/nvtt/bc7/tile.h rename to src/bc7/tile.h diff --git a/src/nvimage/BlockDXT.cpp b/src/nvimage/BlockDXT.cpp index 42d8c05..17f1ef9 100644 --- a/src/nvimage/BlockDXT.cpp +++ b/src/nvimage/BlockDXT.cpp @@ -29,8 +29,8 @@ #include "nvmath/Half.h" #include "nvmath/Vector.inl" -#include "nvtt/bc6h/zoh.h" -#include "nvtt/bc7/avpcl.h" +#include "bc6h/zoh.h" +#include "bc7/avpcl.h" using namespace nv; diff --git a/src/nvimage/CMakeLists.txt b/src/nvimage/CMakeLists.txt index 029f962..db558d4 100644 --- a/src/nvimage/CMakeLists.txt +++ b/src/nvimage/CMakeLists.txt @@ -53,7 +53,7 @@ ELSE(NVIMAGE_SHARED) ADD_LIBRARY(nvimage ${IMAGE_SRCS}) ENDIF(NVIMAGE_SHARED) -TARGET_LINK_LIBRARIES(nvimage ${LIBS} nvcore nvmath posh) +TARGET_LINK_LIBRARIES(nvimage ${LIBS} nvcore nvmath posh bc6h bc7) INSTALL(TARGETS nvimage RUNTIME DESTINATION bin diff --git a/src/nvtt/CMakeLists.txt b/src/nvtt/CMakeLists.txt index 6cbee94..932eaf2 100644 --- a/src/nvtt/CMakeLists.txt +++ b/src/nvtt/CMakeLists.txt @@ -1,8 +1,6 @@ PROJECT(nvtt) ADD_SUBDIRECTORY(squish) -ADD_SUBDIRECTORY(bc6h) -ADD_SUBDIRECTORY(bc7) SET(NVTT_SRCS nvtt.h nvtt.cpp @@ -13,6 +11,7 @@ SET(NVTT_SRCS CompressorDX9.h CompressorDX9.cpp CompressorDX10.h CompressorDX10.cpp CompressorDX11.h CompressorDX11.cpp + CompressorDXT1.h CompressorDXT1.cpp CompressorRGB.h CompressorRGB.cpp Context.h Context.cpp QuickCompressDXT.h QuickCompressDXT.cpp diff --git a/src/nvtt/CompressorDXT1.cpp b/src/nvtt/CompressorDXT1.cpp index 62653f6..b5c4b54 100644 --- a/src/nvtt/CompressorDXT1.cpp +++ b/src/nvtt/CompressorDXT1.cpp @@ -15,6 +15,7 @@ #include "nvcore/Utils.h" // swap #include // memset +#include // FLT_MAX using namespace nv; @@ -80,14 +81,14 @@ static Color32 bitexpand_color16_to_color32(Color16 c16) { return c32; } -static Color32 bitexpand_color16_to_color32(int r, int g, int b) { +/*static Color32 bitexpand_color16_to_color32(int r, int g, int b) { Color32 c32; c32.b = (b << 3) | (b >> 2); c32.g = (g << 2) | (g >> 4); c32.r = (r << 3) | (r >> 2); c32.a = 0xFF; return c32; -} +}*/ static Color16 truncate_color32_to_color16(Color32 c32) { Color16 c16; @@ -97,14 +98,14 @@ static Color16 truncate_color32_to_color16(Color32 c32) { return c16; } -inline Vector3 r5g6b5_to_vector3(int r, int g, int b) +/*inline Vector3 r5g6b5_to_vector3(int r, int g, int b) { Vector3 c; c.x = float((r << 3) | (r >> 2)); c.y = float((g << 2) | (g >> 4)); c.z = float((b << 3) | (b >> 2)); return c; -} +}*/ inline Vector3 color_to_vector3(Color32 c) { @@ -711,3 +712,92 @@ float nv::compress_dxt1(const Vector3 input_colors[16], const float input_weight return error; } + + +// Once we have an index assignment we have colors grouped in 1-4 clusters. +// If 1 clusters -> Use optimal compressor. +// If 2 clusters -> Try: (0, 1), (1, 2), (0, 2), (0, 3) - [0, 1] +// If 3 clusters -> Try: (0, 1, 2), (0, 1, 3), (0, 2, 3) - [0, 1, 2] +// If 4 clusters -> Try: (0, 1, 2, 3) + +// @@ How do we do the initial index/cluster assignment? Use standard cluster fit. + + +// Least squares fitting of color end points for the given indices. @@ Take weights into account. +static bool optimize_end_points4(uint indices, const Vector3 * colors, const Vector3 * weights, int count, Vector3 * a, Vector3 * b) +{ + float alpha2_sum = 0.0f; + float beta2_sum = 0.0f; + float alphabeta_sum = 0.0f; + Vector3 alphax_sum(0.0f); + Vector3 betax_sum(0.0f); + + for (int i = 0; i < count; i++) + { + const uint bits = indices >> (2 * i); + + float beta = float(bits & 1); + if (bits & 2) beta = (1 + beta) / 3.0f; + float alpha = 1.0f - beta; + + alpha2_sum += alpha * alpha; + beta2_sum += beta * beta; + alphabeta_sum += alpha * beta; + alphax_sum += alpha * colors[i]; + betax_sum += beta * colors[i]; + } + + float denom = alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum; + if (equal(denom, 0.0f)) return false; + + float factor = 1.0f / denom; + + *a = saturate((alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor); + *b = saturate((betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor); + + return true; +} + + +// Least squares fitting of color end points for the given indices. @@ This does not support black/transparent index. @@ Take weights into account. +static bool optimize_end_points3(uint indices, const Vector3 * colors, const Vector3 * weights, int count, Vector3 * a, Vector3 * b) +{ + float alpha2_sum = 0.0f; + float beta2_sum = 0.0f; + float alphabeta_sum = 0.0f; + Vector3 alphax_sum(0.0f); + Vector3 betax_sum(0.0f); + + for (int i = 0; i < count; i++) + { + const uint bits = indices >> (2 * i); + + float beta = float(bits & 1); + if (bits & 2) beta = 0.5f; + float alpha = 1.0f - beta; + + alpha2_sum += alpha * alpha; + beta2_sum += beta * beta; + alphabeta_sum += alpha * beta; + alphax_sum += alpha * colors[i]; + betax_sum += beta * colors[i]; + } + + float denom = alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum; + if (equal(denom, 0.0f)) return false; + + float factor = 1.0f / denom; + + *a = saturate((alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor); + *b = saturate((betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor); + + return true; +} + +// @@ After optimization we need to round end points. Round in all possible directions, and pick best. + + + + + + diff --git a/src/nvtt/CompressorDXT1.h b/src/nvtt/CompressorDXT1.h index fb9d655..daf99ac 100644 --- a/src/nvtt/CompressorDXT1.h +++ b/src/nvtt/CompressorDXT1.h @@ -8,23 +8,6 @@ namespace nv { // All these functions return MSE. - // Optimal compressors: - /*float compress_dxt1_single_color_optimal(const Color32 & rgb, BlockDXT1 * output); - float compress_dxt1_single_color_optimal(const ColorBlock & input, BlockDXT1 * output); - float compress_dxt1_optimal(const ColorBlock & input, BlockDXT1 * output); - - - - // Brute force with restricted search space: - float compress_dxt1_bounding_box_exhaustive(const ColorBlock & input, BlockDXT1 * output); - float compress_dxt1_best_fit_line_exhaustive(const ColorBlock & input, BlockDXT1 * output); - - - // Fast least squres fitting compressors: - float compress_dxt1_least_squares_fit(const ColorBlock & input, BlockDXT1 * output); - float compress_dxt1_least_squares_fit_iterative(const ColorBlock & input, BlockDXT1 * output); - */ - float compress_dxt1_single_color_optimal(Color32 c, BlockDXT1 * output); float compress_dxt1_single_color_optimal(const Vector3 & color, BlockDXT1 * output); @@ -36,4 +19,4 @@ namespace nv { float compress_dxt1(const Vector3 colors[16], const float weights[16], const Vector3 & color_weights, BlockDXT1 * output); -} \ No newline at end of file +} diff --git a/src/nvtt/QuickCompressDXT.cpp b/src/nvtt/QuickCompressDXT.cpp index 69ee3de..8390610 100644 --- a/src/nvtt/QuickCompressDXT.cpp +++ b/src/nvtt/QuickCompressDXT.cpp @@ -35,6 +35,7 @@ #include "nvcore/Utils.h" // swap #include // memset +#include // FLT_MAX using namespace nv; using namespace QuickCompress; @@ -285,7 +286,7 @@ inline static uint computeIndices4(const ColorSet & set, Vector3::Arg maxColor, } swap(row0, row1); - memset(row1, 0, sizeof(row1)); + memset(row1, 0, sizeof(Vector3) * (4+2)); } return indices; @@ -866,108 +867,3 @@ void QuickCompress::outputBlock3(const ColorSet & set, const Vector3 & start, co //optimizeEndPoints3(set, block); } - - - - -inline Vector3 toVectorColor(int r, int g, int b) { - Vector3 c; - c.x = float((r << 3) | (r >> 2)); - c.y = float((g << 2) | (g >> 4)); - c.z = float((b << 3) | (b >> 2)); - return c; -} - -// Do an exhaustive search inside the bounding box. -void compress_dxt1_bounding_box_exhaustive(const ColorBlock & input, BlockDXT1 * output) -{ - int min_r = 255, min_g = 255, min_b = 255; - int max_r = 0, max_g = 0, max_b = 0; - - for (int i = 0; i < 16; i++) { - Color32 c = input.color(i); - min_r = min(min_r, int(c.r)); - max_r = max(max_r, int(c.r)); - min_g = min(min_g, int(c.g)); - max_g = max(max_g, int(c.g)); - min_b = min(min_b, int(c.b)); - max_b = max(max_b, int(c.b)); - } - - // Convert to 5:6:5 - min_r >>= 3; min_g >>= 2; min_b >>= 3; - max_r >>= 3; max_g >>= 2; max_b >>= 3; - - // Expand the box. - int range_r = max_r - min_r; - int range_g = max_g - min_g; - int range_b = max_b - min_b; - - min_r = max(0, min_r - (range_r + 1) / 1 - 1); - min_g = max(0, min_g - (range_g + 1) / 1 - 1); - min_b = max(0, min_b - (range_b + 1) / 1 - 1); - - max_r = min(31, max_r + (range_r + 1) / 2 + 1); - max_g = min(63, max_g + (range_g + 1) / 2 + 1); - max_b = min(31, max_b + (range_b + 1) / 2 + 1); - - int count = (max_r-min_r) + (max_g-min_g) + (max_b-min_b); - - Vector3 colors[16]; - extractColorBlockRGB(input, colors); - - - // @@ Use a single loop and remap index to box location? - float bestError = FLT_MAX; - Vector3 best0, best1; - bool threeColorMode; - - for(int r0 = min_r; r0 <= max_r; r0++) - for(int r1 = max_r; r1 >= r0; r1--) - for(int g0 = min_g; g0 <= max_g; g0++) - for(int g1 = max_g; g1 >= g0; g1--) - for(int b0 = min_b; b0 <= max_b; b0++) - for(int b1 = max_b; b1 >= b0; b1--) - { - Vector3 c0 = toVectorColor(r0, g0, b0); - Vector3 c1 = toVectorColor(r1, g1, b1); - - // Compute palette and evaluate error for these endpoints. - float error = evaluatePaletteError4(colors, c1, c0); - - if (error < bestError) { - bestError = error; - best0 = c1; // c0 > c1 - best1 = c0; - threeColorMode = false; - } - -#if 0 - error = evaluatePaletteError3(colors, /*maxColor=*/c1, /*minColor=*/c0); - - if (error < bestError) { - bestError = error; - best0 = c0; - best1 = c1; - threeColorMode = true; - } -#endif - } - - uint16 color0 = roundAndExpand(&best0); - uint16 color1 = roundAndExpand(&best1); - - if (threeColorMode) { - nvCheck(color0 <= color1); - output->col0 = Color16(color1); - output->col1 = Color16(color0); - output->indices = computeIndices3(colors, best0, best1); - } - else { - nvCheck(color0 >= color1); - output->col0 = Color16(color0); - output->col1 = Color16(color1); - output->indices = computeIndices4(colors, best0, best1); - } - -} diff --git a/src/nvtt/tools/CMakeLists.txt b/src/nvtt/tools/CMakeLists.txt index 02c6d46..2dcb728 100644 --- a/src/nvtt/tools/CMakeLists.txt +++ b/src/nvtt/tools/CMakeLists.txt @@ -66,8 +66,8 @@ IF(QT4_FOUND) QT4_WRAP_CPP(MOCS compressdialog.h) #QT4_ADD_RESOURCES(RCCS ui/configdialog.rc) - ADD_EXECUTABLE(nvtt-diag MACOSX_BUNDLE ${SRCS} ${UICS} ${MOCS}) - TARGET_LINK_LIBRARIES(nvtt-diag ${LIBS}) + #ADD_EXECUTABLE(nvtt-diag MACOSX_BUNDLE ${SRCS} ${UICS} ${MOCS}) + #TARGET_LINK_LIBRARIES(nvtt-diag ${LIBS}) ENDIF(QT4_FOUND) diff --git a/src/nvtt/tools/compressdialog.cpp b/src/nvtt/tools/compressdialog.cpp index c3b1d11..b48d698 100644 --- a/src/nvtt/tools/compressdialog.cpp +++ b/src/nvtt/tools/compressdialog.cpp @@ -17,23 +17,6 @@ int main(int argc, char *argv[]) CompressDialog::CompressDialog(const QString & fileName, QWidget *parent) : QDialog(parent) { ui.setupUi(this); - - //connect(ui.openButton, SIGNAL(clicked()), this, SLOT(openClicked())); - connect(ui.generateMipmapsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(generateMipmapsChanged(int))); - connect(ui.mipmapFilterComboBox, SIGNAL(activated(QString)), this, SLOT(mipmapFilterChanged(QString))); - //connect(ui.mipmapFilterSettings, SIGNAL(clicked()), this, SLOT(mipmapFilterSettingsShow())); - - connect(ui.formatComboBox, SIGNAL(activated(QString)), this, SLOT(formatChanged(QString))); - - - connect(ui.redSpinBox, SIGNAL(valueChanged(double)), this, SLOT(colorWeightChanged())); - connect(ui.greenSpinBox, SIGNAL(valueChanged(double)), this, SLOT(colorWeightChanged())); - connect(ui.blueSpinBox, SIGNAL(valueChanged(double)), this, SLOT(colorWeightChanged())); - connect(ui.uniformButton, SIGNAL(toggled(bool)), this, SLOT(uniformWeightToggled(bool))); - connect(ui.luminanceButton, SIGNAL(toggled(bool)), this, SLOT(luminanceWeightToggled(bool))); - - //connect(ui.rgbMapRadioButton, SIGNAL(toggled(bool)), this, SLOT(colorModeChanged())); - //connect(ui.normalMapRadioButton, SIGNAL(toggled(bool)), this, SLOT(normalMapModeChanged(bool))); } CompressDialog::~CompressDialog() @@ -46,79 +29,3 @@ void CompressDialog::openClicked() // @@ What is openButton? } - -void CompressDialog::generateMipmapsChanged(int state) -{ - Q_UNUSED(state); - - bool generateMipmapEnabled = ui.generateMipmapsCheckBox->isChecked(); - - ui.mipmapFilterLabel->setEnabled(generateMipmapEnabled); - ui.mipmapFilterComboBox->setEnabled(generateMipmapEnabled); - ui.limitMipmapsCheckBox->setEnabled(generateMipmapEnabled); - - bool enableFilterSettings = (ui.mipmapFilterComboBox->currentText() == "Kaiser"); - ui.mipmapFilterSettings->setEnabled(generateMipmapEnabled && enableFilterSettings); - - bool enableMaxLevel = ui.limitMipmapsCheckBox->isChecked(); - ui.maxLevelLabel->setEnabled(generateMipmapEnabled && enableMaxLevel); - ui.maxLevelSpinBox->setEnabled(generateMipmapEnabled && enableMaxLevel); -} - -void CompressDialog::mipmapFilterChanged(QString name) -{ - bool enableFilterSettings = (name == "Kaiser"); - ui.mipmapFilterSettings->setEnabled(enableFilterSettings); -} - -void CompressDialog::formatChanged(QString format) -{ - if (format == "Uncompressed") { - ui.formatOptions->setCurrentIndex(1); - } - else { - ui.formatOptions->setCurrentIndex(0); - } -} - -void CompressDialog::colorWeightChanged() -{ - double r = ui.redSpinBox->value(); - double g = ui.greenSpinBox->value(); - double b = ui.blueSpinBox->value(); - - bool uniform = (r == 1.0 && g == 1.0 && b == 1.0); - bool luminance = (r == 0.3 && g == 0.59 && b == 0.11); - - ui.uniformButton->setChecked(uniform); - ui.luminanceButton->setChecked(luminance); -} - -void CompressDialog::uniformWeightToggled(bool checked) -{ - if (checked) - { - ui.redSpinBox->setValue(1.0); - ui.greenSpinBox->setValue(1.0); - ui.blueSpinBox->setValue(1.0); - } -} - -void CompressDialog::luminanceWeightToggled(bool checked) -{ - if (checked) - { - ui.redSpinBox->setValue(0.3); - ui.greenSpinBox->setValue(0.59); - ui.blueSpinBox->setValue(0.11); - } -} - -void CompressDialog::normalMapModeChanged(bool checked) -{ - //ui.alphaModeGroupBox->setEnabled(!checked); - //ui.inputGammaSpinBox->setEnabled(!checked); - //ui.inputGammaLabel->setEnabled(!checked); - //ui.outputGammaSpinBox->setEnabled(!checked); - //ui.outputGammaLabel->setEnabled(!checked); -} diff --git a/src/nvtt/tools/compressdialog.h b/src/nvtt/tools/compressdialog.h index e17b948..8441c33 100644 --- a/src/nvtt/tools/compressdialog.h +++ b/src/nvtt/tools/compressdialog.h @@ -16,15 +16,6 @@ public: protected slots: void openClicked(); - void generateMipmapsChanged(int state); - void mipmapFilterChanged(QString name); - void formatChanged(QString format); - - void colorWeightChanged(); - void uniformWeightToggled(bool checked); - void luminanceWeightToggled(bool checked); - - void normalMapModeChanged(bool checked); private: diff --git a/src/nvtt/tools/compressdialog.ui b/src/nvtt/tools/compressdialog.ui index a850a29..91bc668 100644 --- a/src/nvtt/tools/compressdialog.ui +++ b/src/nvtt/tools/compressdialog.ui @@ -2,6 +2,14 @@ CompressDialog + + + 0 + 0 + 766 + 540 + + 280 @@ -11,12 +19,21 @@ Dialog - + + -1 + + + 8 + + + 8 + + 8 - - 10 + + 8 @@ -39,694 +56,41 @@ - - - - 0 - 0 - - - - QFrame::Box - - - QFrame::Sunken - - - 3 - - - - - 0 - 0 - 249 - 367 - - - - Image Info - - - - - - 0 - 0 - 249 - 367 - - - - Compression Options - - - - 2 + + + + + + + + + + + + + + + 24 - - 6 + + + + + + + 0 + 0 + - - - - - - - 0 - 0 - - - - Format: - - - Qt::PlainText - - - Qt::NoTextInteraction - - - - - - - - Uncompressed - - - - - BC1 (DXT1) - - - - - BC1a (DXT1a) - - - - - BC2 (DXT3) - - - - - BC3 (DXT5) - - - - - BC4 - - - - - BC5 - - - - - - - - - - - 0 - 0 - - - - 1 - - - - - 0 - - - 8 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - Color Weights - - - Qt::AlignHCenter - - - - 12 - - - - - - - Red - - - redSpinBox - - - - - - - 1.000000000000000 - - - 0.050000000000000 - - - 1.000000000000000 - - - - - - - - - - - Green - - - greenSpinBox - - - - - - - 1.000000000000000 - - - 0.050000000000000 - - - 1.000000000000000 - - - - - - - - - - - Blue - - - blueSpinBox - - - - - - - 1.000000000000000 - - - 0.050000000000000 - - - 1.000000000000000 - - - - - - - - - - - Uniform - - - true - - - true - - - - - - - Luminance - - - true - - - - - - - - - - - - - - 1 - - - 0 - - - - - - - - 0 - 0 - - - - - 16777215 - 24 - - - - Pixel Format: - - - Qt::PlainText - - - Qt::NoTextInteraction - - - - - - - 1 - - - - Custom - - - - - R8G8B8A8 - - - - - R5G6B5 - - - - - A1 - - - - - - - - - - - - Color Type: - - - - - - - - Fixed - - - - - Float - - - - - - - - - - - - Red Bits: - - - - - - - 32 - - - 8 - - - - - - - - - - - Green Bits: - - - - - - - 32 - - - 8 - - - - - - - - - - - Blue Bits: - - - - - - - 32 - - - 8 - - - - - - - - - - - Alpha Bits: - - - - - - - 32 - - - 8 - - - - - - - - - - - - - Dither Color - - - - - - - Dither Alpha - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - 0 - 0 - 249 - 367 - - - - Resize Options - - - - - - 0 - 0 - 241 - 357 - - - - Mipmap Options - - - - 2 + + Qt::Horizontal - - 6 + + QDialogButtonBox::Cancel|QDialogButtonBox::Save - - - - - 0 - 0 - - - - Generate mipmaps - - - true - - - - - - - 1 - - - - - - 0 - 0 - - - - - 16777215 - 26 - - - - Filter: - - - mipmapFilterComboBox - - - - - - - - 16777215 - 26 - - - - - Box - - - - - Triangle - - - - - Kaiser - - - - - - - - false - - - false - - - ... - - - Qt::ToolButtonTextOnly - - - - - - - - - - - - 0 - 0 - - - - Limit Mipmaps - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - - 0 - 0 - - - - &Max Level: - - - maxLevelSpinBox - - - - - - - false - - - - 0 - 0 - - - - - 80 - 16777215 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + diff --git a/src/nvtt/tools/thumbnailer.cpp b/src/nvtt/tools/thumbnailer.cpp index 7b9690a..1c8ab01 100644 --- a/src/nvtt/tools/thumbnailer.cpp +++ b/src/nvtt/tools/thumbnailer.cpp @@ -41,7 +41,7 @@ static bool loadImage(nv::Image & image, const char * fileName) { - if (nv::strCaseCmp(nv::Path::extension(fileName), ".dds") == 0) + if (nv::strCaseDiff(nv::Path::extension(fileName), ".dds") == 0) { nv::DirectDrawSurface dds(fileName); if (!dds.isValid())