From 1e33823b12c455aefe31e3395134faa8dd3cc569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Tue, 6 Feb 2018 06:10:40 +0100 Subject: [PATCH 1/3] ABI: Restore InputOptions::setTextureLayout(TextureType, int, int, int) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Although adding a method argument with default argument keeps API compatibility, it changes the function type. Use function overloading instead and implement the old one as a wrapper to the extended one, supplying the default argument. Fixes part of https://github.com/castano/nvidia-texture-tools/issues/259 Signed-off-by: Stefan Brüns --- src/nvtt/InputOptions.cpp | 9 ++++++++- src/nvtt/nvtt.h | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/nvtt/InputOptions.cpp b/src/nvtt/InputOptions.cpp index 8179799..ba3934e 100644 --- a/src/nvtt/InputOptions.cpp +++ b/src/nvtt/InputOptions.cpp @@ -124,7 +124,14 @@ void InputOptions::reset() // Setup the input image. -void InputOptions::setTextureLayout(TextureType type, int width, int height, int depth /*= 1*/, int arraySize /*= 1*/) +// Overload for ABI compatibility +void InputOptions::setTextureLayout(TextureType type, int width, int height, int depth /*= 1*/) +{ + setTextureLayout(type, width, height, depth, 1); +} + +// Setup the input image. +void InputOptions::setTextureLayout(TextureType type, int width, int height, int depth, int arraySize) { // Validate arguments. nvCheck(width >= 0); diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index d86a503..6a5a8a3 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -290,7 +290,9 @@ namespace nvtt NVTT_API void reset(); // Setup input layout. - NVTT_API void setTextureLayout(TextureType type, int w, int h, int d = 1, int arraySize = 1); + // Overload for ABI compatibility + NVTT_API void setTextureLayout(TextureType type, int w, int h, int d = 1 /*, arraysize = 1 */); + NVTT_API void setTextureLayout(TextureType type, int w, int h, int d, int arraySize); NVTT_API void resetTextureLayout(); // Set mipmap data. Copies the data. From 80ca02930a0ec5835bc202c6a0aeffb98f6383cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Tue, 6 Feb 2018 06:21:28 +0100 Subject: [PATCH 2/3] ABI: restore InputOptions::setLinearTransform(...) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The linear transform has never been implemented, so just add as a stub for API/ABI compatibility. Fixes part of https://github.com/castano/nvidia-texture-tools/issues/259 Signed-off-by: Stefan Brüns --- src/nvtt/InputOptions.cpp | 6 ++++++ src/nvtt/nvtt.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/nvtt/InputOptions.cpp b/src/nvtt/InputOptions.cpp index ba3934e..04861cd 100644 --- a/src/nvtt/InputOptions.cpp +++ b/src/nvtt/InputOptions.cpp @@ -337,6 +337,12 @@ void InputOptions::setNormalizeMipmaps(bool normalize) m.normalizeMipmaps = normalize; } +// Set linear transform for the given channel. +// Stub for ABI compatibily, never implemented +void InputOptions::setLinearTransform(int, float, float, float, float) +{ +} + void InputOptions::setMaxExtents(int e) { nvDebugCheck(e > 0); diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index 6a5a8a3..b3b6166 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -322,6 +322,9 @@ namespace nvtt NVTT_API void setNormalFilter(float sm, float medium, float big, float large); NVTT_API void setNormalizeMipmaps(bool b); + // Set color transforms. + NVTT_API void setLinearTransform(int channel, float w0, float w1, float w2, float w3); + // Set resizing options. NVTT_API void setMaxExtents(int d); NVTT_API void setRoundMode(RoundMode mode); From a52f9cee0695a2f518fa199d899ca89c241b6b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Tue, 6 Feb 2018 06:32:29 +0100 Subject: [PATCH 3/3] ABI/API: Restore InputOptions::setColorTransform(ColorTransform) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only colortransform actually implemented was the transform from RGB to YCoCG (ColorTransform_YCoCg). Restore the full enum for API compatibility, and allow the transform to be specified using InputOptions::setColortransform. Fixes part of https://github.com/castano/nvidia-texture-tools/issues/259 Signed-off-by: Stefan Brüns --- src/nvtt/Context.cpp | 5 +++++ src/nvtt/InputOptions.cpp | 8 ++++++++ src/nvtt/InputOptions.h | 3 +++ src/nvtt/nvtt.h | 12 ++++++++++++ 4 files changed, 28 insertions(+) diff --git a/src/nvtt/Context.cpp b/src/nvtt/Context.cpp index 37c201b..d5a9944 100644 --- a/src/nvtt/Context.cpp +++ b/src/nvtt/Context.cpp @@ -277,6 +277,11 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c // Resize input. img.resize(w, h, d, ResizeFilter_Box); + // Apply color transform. + if (inputOptions.colorTransform == ColorTransform_YCoCg) { + img.toYCoCg(); + } + nvtt::Surface tmp = img; if (!img.isNormalMap()) { tmp.toGamma(inputOptions.outputGamma); diff --git a/src/nvtt/InputOptions.cpp b/src/nvtt/InputOptions.cpp index 04861cd..95af5e6 100644 --- a/src/nvtt/InputOptions.cpp +++ b/src/nvtt/InputOptions.cpp @@ -104,6 +104,8 @@ void InputOptions::reset() m.inputGamma = 2.2f; m.outputGamma = 2.2f; + m.colorTransform = ColorTransform_None; + m.generateMipmaps = true; m.maxLevel = -1; m.mipmapFilter = MipmapFilter_Box; @@ -337,6 +339,12 @@ void InputOptions::setNormalizeMipmaps(bool normalize) m.normalizeMipmaps = normalize; } +// Set color transform. +void InputOptions::setColorTransform(ColorTransform t) +{ + m.colorTransform = t; +} + // Set linear transform for the given channel. // Stub for ABI compatibily, never implemented void InputOptions::setLinearTransform(int, float, float, float, float) diff --git a/src/nvtt/InputOptions.h b/src/nvtt/InputOptions.h index b28c8fb..c8c9073 100644 --- a/src/nvtt/InputOptions.h +++ b/src/nvtt/InputOptions.h @@ -55,6 +55,9 @@ namespace nvtt float inputGamma; float outputGamma; + // Color transform. + ColorTransform colorTransform; + // Mipmap generation options. bool generateMipmaps; int maxLevel; diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index b3b6166..049dad9 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -249,6 +249,17 @@ namespace nvtt ResizeFilter_Mitchell, }; + // Color transformation. + // deprecated since 2.1.0 + enum ColorTransform + { + ColorTransform_None, + ColorTransform_Linear, + ColorTransform_Swizzle, + ColorTransform_YCoCg, + ColorTransform_ScaledYCoCg, + }; + // Extents rounding mode. enum RoundMode { @@ -323,6 +334,7 @@ namespace nvtt NVTT_API void setNormalizeMipmaps(bool b); // Set color transforms. + NVTT_API void setColorTransform(ColorTransform t); NVTT_API void setLinearTransform(int channel, float w0, float w1, float w2, float w3); // Set resizing options.