diff --git a/src/nvimage/ImageIO.cpp b/src/nvimage/ImageIO.cpp index 53b1da2..d6ead0f 100644 --- a/src/nvimage/ImageIO.cpp +++ b/src/nvimage/ImageIO.cpp @@ -563,7 +563,7 @@ bool nv::ImageIO::saveFreeImage(FREE_IMAGE_FORMAT fif, Stream & s, const Image * if (tags != NULL) { -#pragma message(NV_FILE_LINE "TODO: Save image metadata") +#pragma NV_MESSAGE("TODO: Save image metadata") //FreeImage_SetMetadata( } diff --git a/src/nvtt/Context.cpp b/src/nvtt/Context.cpp index 8fc6174..bf15a01 100644 --- a/src/nvtt/Context.cpp +++ b/src/nvtt/Context.cpp @@ -1463,7 +1463,7 @@ CompressorInterface * Compressor::Private::chooseGpuCompressor(const Compression } else if (compressionOptions.format == Format_DXT1a) { -#pragma message(NV_FILE_LINE "TODO: Implement CUDA DXT1a compressor.") +#pragma NV_MESSAGE("TODO: Implement CUDA DXT1a compressor.") } else if (compressionOptions.format == Format_DXT1n) { diff --git a/src/nvtt/TexImage.cpp b/src/nvtt/TexImage.cpp index c4f8fa7..a23f26a 100644 --- a/src/nvtt/TexImage.cpp +++ b/src/nvtt/TexImage.cpp @@ -999,6 +999,54 @@ void TexImage::scaleAlphaToCoverage(float coverage, float alphaRef/*= 0.5f*/) } } +bool TexImage::normalizeRange(float * rangeMin, float * rangeMax) +{ + Vector2 range(FLT_MAX, -FLT_MAX); + + // Compute range. + foreach (i, m->imageArray) { + FloatImage * img = m->imageArray[i]; + if (img == NULL) continue; + + const uint count = img->count(); + for (uint p = 0; p < count; p++) { + float c = img->pixel(p); + + if (c < range.x) range.x = c; + if (c > range.y) range.y = c; + } + } + + if (range.x == range.y) { + // Single color image. + return false; + } + + *rangeMin = range.x; + *rangeMax = range.y; + + const float scale = 1.0f / (range.y - range.x); + const float bias = range.x * scale; + + if (scale == 1.0f && bias == 0.0f) { + // Already normalized. + return true; + } + + detach(); + + // Scale to range. + foreach (i, m->imageArray) { + FloatImage * img = m->imageArray[i]; + if (img == NULL) continue; + + img->scaleBias(0, 4, scale, bias); + //img->clamp(0, 4, 0.0f, 1.0f); + } + + return true; +} + // Set normal map options. void TexImage::toNormalMap(float sm, float medium, float big, float large) diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index 3fbc1dc..99bc778 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -444,6 +444,7 @@ namespace nvtt NVTT_API void setBorder(float r, float g, float b, float a); NVTT_API void fill(float r, float g, float b, float a); NVTT_API void scaleAlphaToCoverage(float coverage, float alphaRef = 0.5f); + NVTT_API bool normalizeRange(float * rangeMin, float * rangeMax); // Set normal map options. NVTT_API void toNormalMap(float sm, float medium, float big, float large); diff --git a/src/nvtt/tests/testsuite.cpp b/src/nvtt/tests/testsuite.cpp index 8f77fa9..07dc30f 100644 --- a/src/nvtt/tests/testsuite.cpp +++ b/src/nvtt/tests/testsuite.cpp @@ -373,8 +373,8 @@ int main(int argc, char *argv[]) printf(" 1: \tWaterloo.\n"); printf(" 2: \tEpic.\n"); printf(" 3: \tFarbrausch.\n"); - printf(" 4: \Lugaru.\n"); - printf(" 5: \Quake 3.\n"); + printf(" 4: \tLugaru.\n"); + printf(" 5: \tQuake 3.\n"); printf(" -dec x \tDecompressor.\n"); printf(" 0: \tReference.\n"); printf(" 1: \tNVIDIA.\n");