From 1b73dcaf7e22f4fa659b1f1c2159b9a7bb874cad Mon Sep 17 00:00:00 2001 From: castano Date: Fri, 16 Nov 2007 11:52:29 +0000 Subject: [PATCH] Add interface to specify color transformations. --- src/nvtt/InputOptions.cpp | 18 ++++++++++++++++++ src/nvtt/InputOptions.h | 8 +++++++- src/nvtt/nvtt.cpp | 8 ++++++++ src/nvtt/nvtt.h | 12 +++++++++++- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/nvtt/InputOptions.cpp b/src/nvtt/InputOptions.cpp index e6a04d2..4931311 100644 --- a/src/nvtt/InputOptions.cpp +++ b/src/nvtt/InputOptions.cpp @@ -83,6 +83,9 @@ void InputOptions::reset() m.inputGamma = 2.2f; m.outputGamma = 2.2f; + m.colorTransform = ColorTransform_None; + m.linearTransform = Matrix(identity); + m.generateMipmaps = false; m.maxLevel = -1; m.mipmapFilter = MipmapFilter_Box; @@ -258,3 +261,18 @@ 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. +void InputOptions::setLinearTransfrom(int channel, float w0, float w1, float w2, float w3) +{ + nvCheck(channel >= 0 && channel < 4); + + Vector4 w(w0, w1, w2, w3); + //m.linearTransform.setRow(channel, w); +} diff --git a/src/nvtt/InputOptions.h b/src/nvtt/InputOptions.h index fbd7899..31cec29 100644 --- a/src/nvtt/InputOptions.h +++ b/src/nvtt/InputOptions.h @@ -26,6 +26,7 @@ #include #include +#include #include #include "nvtt.h" @@ -58,7 +59,11 @@ namespace nvtt // Gamma conversion. float inputGamma; float outputGamma; - + + // Color transform. + ColorTransform colorTransform; + nv::Matrix linearTransform; + // Mipmap generation options. bool generateMipmaps; int maxLevel; @@ -73,6 +78,7 @@ namespace nvtt // Cone map options. bool convertToConeMap; + }; // Internal image structure. diff --git a/src/nvtt/nvtt.cpp b/src/nvtt/nvtt.cpp index e118d12..d08e3c7 100644 --- a/src/nvtt/nvtt.cpp +++ b/src/nvtt/nvtt.cpp @@ -459,6 +459,14 @@ bool nvtt::compress(const InputOptions & inputOptions, const OutputOptions & out img = toFixedImage(floatImage.ptr(), inputOptions.m); } + // @@ Where to do the color transform? + // - Color transform may not be linear, so we cannot do before computing mipmaps. + // - Should be done in linear space, that is, after gamma correction. + + // @@ Error! gamma correction is not performed when mipmap data provied. + + // @@ This code is too complicated, too prone to erros, and hard to understand. Must be simplified! + quantize(img, inputOptions.m, format); compressMipmap(img, outputOptions, compressionOptions.m); diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index 95d8fc8..c16ec54 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -139,7 +139,13 @@ namespace nvtt MipmapFilter_Kaiser, ///< Kaiser-windowed Sinc filter is the best downsampling filter. }; - + enum ColorTransform + { + ColorTransform_None, + ColorTransform_Linear, + ColorTransform_CoYCg, + ColorTransform_CoSCgY, + }; /// Input options. Specify format and layout of the input texture. struct InputOptions @@ -179,6 +185,10 @@ namespace nvtt NVTT_API void setNormalFilter(float small, float medium, float big, float large); NVTT_API void setNormalizeMipmaps(bool b); + // Set color transforms. + NVTT_API void setColorTransform(ColorTransform t); + NVTT_API void setLinearTransfrom(int channel, float w0, float w1, float w2, float w3); + //private: struct Private; Private & m;