diff --git a/src/nvimage/FloatImage.cpp b/src/nvimage/FloatImage.cpp index 0fcea3c..c6d3cbb 100644 --- a/src/nvimage/FloatImage.cpp +++ b/src/nvimage/FloatImage.cpp @@ -242,7 +242,7 @@ void FloatImage::exponentiate(uint base_component, uint num, float power) } /// Apply linear transform. -void FloatImage::transform(uint base_component, const Matrix & m) +void FloatImage::transform(uint base_component, const Matrix & m, Vector4::Arg offset) { nvCheck(base_component + 4 <= m_componentNum); @@ -255,7 +255,7 @@ void FloatImage::transform(uint base_component, const Matrix & m) for (uint i = 0; i < size; i++) { - Vector4 color = nv::transform(m, Vector4(*r, *g, *b, *a)); + Vector4 color = nv::transform(m, Vector4(*r, *g, *b, *a)) + offset; *r++ = color.x(); *g++ = color.y(); @@ -267,14 +267,19 @@ void FloatImage::transform(uint base_component, const Matrix & m) void FloatImage::swizzle(uint base_component, uint r, uint g, uint b, uint a) { nvCheck(base_component + 4 <= m_componentNum); + nvCheck(r < 7 && g < 7 && b < 7 && a < 7); const uint size = m_width * m_height; - float * c[4]; + float consts[] = { 1.0f, 0.0f, -1.0f }; + float * c[7]; c[0] = this->channel(base_component + 0); c[1] = this->channel(base_component + 1); c[2] = this->channel(base_component + 2); c[3] = this->channel(base_component + 3); + c[4] = consts; + c[5] = consts + 1; + c[6] = consts + 2; for (uint i = 0; i < size; i++) { diff --git a/src/nvimage/FloatImage.h b/src/nvimage/FloatImage.h index 9ef6f55..6eaf238 100644 --- a/src/nvimage/FloatImage.h +++ b/src/nvimage/FloatImage.h @@ -63,7 +63,7 @@ public: NVIMAGE_API void toGamma(uint base_component, uint num, float gamma = 2.2f); NVIMAGE_API void exponentiate(uint base_component, uint num, float power); - NVIMAGE_API void transform(uint base_component, const Matrix & m); + NVIMAGE_API void transform(uint base_component, const Matrix & m, Vector4::Arg offset); NVIMAGE_API void swizzle(uint base_component, uint r, uint g, uint b, uint a); NVIMAGE_API FloatImage * fastDownSample() const; diff --git a/src/nvtt/Compressor.cpp b/src/nvtt/Compressor.cpp index d2a22a0..be7de90 100644 --- a/src/nvtt/Compressor.cpp +++ b/src/nvtt/Compressor.cpp @@ -665,7 +665,13 @@ void Compressor::Private::processInputImage(Mipmap & mipmap, const InputOptions: FloatImage * image = mipmap.asFloatImage(); nvDebugCheck(image != NULL); - image->transform(0, inputOptions.linearTransform); + Vector4 offset( + inputOptions.colorOffsets[0], + inputOptions.colorOffsets[1], + inputOptions.colorOffsets[2], + inputOptions.colorOffsets[3]); + + image->transform(0, inputOptions.linearTransform, offset); } else if (inputOptions.colorTransform == ColorTransform_Swizzle) { diff --git a/src/nvtt/InputOptions.cpp b/src/nvtt/InputOptions.cpp index 82a23ec..38659f7 100644 --- a/src/nvtt/InputOptions.cpp +++ b/src/nvtt/InputOptions.cpp @@ -103,6 +103,8 @@ void InputOptions::reset() m.colorTransform = ColorTransform_None; m.linearTransform = Matrix(identity); + for (int i = 0; i < 4; i++) m.colorOffsets[i] = 0; + for (int i = 0; i < 4; i++) m.swizzleTransform[i] = i; m.generateMipmaps = true; m.maxLevel = -1; @@ -344,16 +346,27 @@ void InputOptions::setLinearTransform(int channel, float w0, float w1, float w2, { nvCheck(channel >= 0 && channel < 4); - Vector4 w(w0, w1, w2, w3); - //m.linearTransform.setRow(channel, w); + m.linearTransform(0, channel) = w0; + m.linearTransform(1, channel) = w1; + m.linearTransform(2, channel) = w2; + m.linearTransform(3, channel) = w3; +} + +void InputOptions::setLinearTransform(int channel, float w0, float w1, float w2, float w3, float offset) +{ + nvCheck(channel >= 0 && channel < 4); + + setLinearTransform(channel, w0, w1, w2, w3); + + m.colorOffsets[channel] = offset; } void InputOptions::setSwizzleTransform(int x, int y, int z, int w) { - nvCheck(x >= 0 && x < 3); - nvCheck(y >= 0 && y < 3); - nvCheck(z >= 0 && z < 3); - nvCheck(w >= 0 && w < 3); + nvCheck(x >= 0 && x <= 6); + nvCheck(y >= 0 && y <= 6); + nvCheck(z >= 0 && z <= 6); + nvCheck(w >= 0 && w <= 6); m.swizzleTransform[0] = x; m.swizzleTransform[1] = y; diff --git a/src/nvtt/InputOptions.h b/src/nvtt/InputOptions.h index 4906173..444a7ca 100644 --- a/src/nvtt/InputOptions.h +++ b/src/nvtt/InputOptions.h @@ -57,6 +57,7 @@ namespace nvtt // Color transform. ColorTransform colorTransform; nv::Matrix linearTransform; + float colorOffsets[4]; uint swizzleTransform[4]; // Mipmap generation options. diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index 7363a24..3cfcd35 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -220,9 +220,10 @@ namespace nvtt NVTT_API void setNormalFilter(float sm, float medium, float big, float large); NVTT_API void setNormalizeMipmaps(bool b); - // Set color transforms. @@ Not implemented! + // Set color transforms. NVTT_API void setColorTransform(ColorTransform t); NVTT_API void setLinearTransform(int channel, float w0, float w1, float w2, float w3); + NVTT_API void setLinearTransform(int channel, float w0, float w1, float w2, float w3, float offset); NVTT_API void setSwizzleTransform(int x, int y, int z, int w); // Set resizing options.