Merge changes from The Witness.
This commit is contained in:
@ -218,6 +218,18 @@ unsigned int CompressionOptions::d3d9Format() const
|
||||
if (bitcount <= 32) {
|
||||
return nv::findD3D9Format(bitcount, rmask, gmask, bmask, amask);
|
||||
}
|
||||
else {
|
||||
//if (m.rsize == 16 && m.gsize == 16 && m.bsize == 0 && m.asize == 0) return D3DFMT_G16R16;
|
||||
if (m.rsize == 16 && m.gsize == 16 && m.bsize == 16 && m.asize == 16) return D3DFMT_A16B16G16R16;
|
||||
}
|
||||
}
|
||||
else if (m.pixelType == PixelType_Float) {
|
||||
if (m.rsize == 16 && m.gsize == 0 && m.bsize == 0 && m.asize == 0) return D3DFMT_R16F;
|
||||
if (m.rsize == 32 && m.gsize == 0 && m.bsize == 0 && m.asize == 0) return D3DFMT_R32F;
|
||||
if (m.rsize == 16 && m.gsize == 16 && m.bsize == 0 && m.asize == 0) return D3DFMT_G16R16F;
|
||||
if (m.rsize == 32 && m.gsize == 32 && m.bsize == 0 && m.asize == 0) return D3DFMT_G32R32F;
|
||||
if (m.rsize == 16 && m.gsize == 16 && m.bsize == 16 && m.asize == 16) return D3DFMT_A16B16G16R16F;
|
||||
if (m.rsize == 32 && m.gsize == 32 && m.bsize == 32 && m.asize == 32) return D3DFMT_A32B32G32R32F;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -149,6 +149,11 @@ int Compressor::estimateSize(const TexImage & tex, int mipmapCount, const Compre
|
||||
|
||||
|
||||
// Raw API.
|
||||
bool Compressor::outputHeader(TextureType type, int w, int h, int d, int mipmapCount, bool isNormalMap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
{
|
||||
return m.outputHeader(type, w, h, d, mipmapCount, isNormalMap, compressionOptions.m, outputOptions.m);
|
||||
}
|
||||
|
||||
bool Compressor::compress(int w, int h, int d, int face, int mipmap, const float * rgba, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
{
|
||||
return m.compress(AlphaMode_None, w, h, d, face, mipmap, rgba, compressionOptions.m, outputOptions.m);
|
||||
|
@ -285,19 +285,40 @@ float TexImage::alphaTestCoverage(float alphaRef/*= 0.5*/) const
|
||||
return m->image->alphaTestCoverage(alphaRef, 3);
|
||||
}
|
||||
|
||||
float TexImage::average(int channel) const
|
||||
float TexImage::average(int channel, int alpha_channel/*= -1*/, float gamma /*= 2.2f*/) const
|
||||
{
|
||||
if (m->image == NULL) return 0.0f;
|
||||
|
||||
const uint count = m->image->width() * m->image->height();
|
||||
|
||||
float sum = 0.0f;
|
||||
const float * c = m->image->channel(channel);
|
||||
|
||||
const uint count = m->image->width() * m->image->height();
|
||||
for (uint i = 0; i < count; i++) {
|
||||
sum += c[i];
|
||||
float denom;
|
||||
|
||||
if (alpha_channel == -1) {
|
||||
for (uint i = 0; i < count; i++) {
|
||||
sum += powf(c[i], gamma);
|
||||
}
|
||||
|
||||
denom = float(count);
|
||||
}
|
||||
else {
|
||||
float alpha_sum = 0.0f;
|
||||
const float * a = m->image->channel(alpha_channel);
|
||||
|
||||
for (uint i = 0; i < count; i++) {
|
||||
sum += powf(c[i], gamma) * a[i];
|
||||
alpha_sum += a[i];
|
||||
}
|
||||
|
||||
denom = alpha_sum;
|
||||
}
|
||||
|
||||
return sum / count;
|
||||
// Avoid division by zero.
|
||||
if (denom == 0.0f) return 0.0f;
|
||||
|
||||
return sum / denom;
|
||||
}
|
||||
|
||||
const float * TexImage::data() const
|
||||
@ -1047,6 +1068,33 @@ void TexImage::scaleAlphaToCoverage(float coverage, float alphaRef/*= 0.5f*/)
|
||||
m->image->scaleAlphaToCoverage(coverage, alphaRef, 3);
|
||||
}
|
||||
|
||||
/*bool TexImage::normalizeRange(float * rangeMin, float * rangeMax)
|
||||
{
|
||||
if (m->image == NULL) return false;
|
||||
|
||||
range(0, rangeMin, rangeMax);
|
||||
|
||||
if (*rangeMin == *rangeMax) {
|
||||
// Single color image.
|
||||
return false;
|
||||
}
|
||||
|
||||
const float scale = 1.0f / (*rangeMax - *rangeMin);
|
||||
const float bias = *rangeMin * scale;
|
||||
|
||||
if (range.x == 0.0f && range.y == 1.0f) {
|
||||
// Already normalized.
|
||||
return true;
|
||||
}
|
||||
|
||||
detach();
|
||||
|
||||
// Scale to range.
|
||||
img->scaleBias(0, 4, scale, bias);
|
||||
//img->clamp(0, 4, 0.0f, 1.0f);
|
||||
|
||||
return true;
|
||||
}*/
|
||||
|
||||
// Ideally you should compress/quantize the RGB and M portions independently.
|
||||
// Once you have M quantized, you would compute the corresponding RGB and quantize that.
|
||||
|
@ -27,7 +27,6 @@
|
||||
|
||||
#include "nvtt.h"
|
||||
|
||||
#include "nvcore/Array.h"
|
||||
#include "nvcore/RefCounted.h"
|
||||
#include "nvcore/Ptr.h"
|
||||
|
||||
|
@ -380,6 +380,7 @@ namespace nvtt
|
||||
NVTT_API int estimateSize(const TexImage & tex, int mipmapCount, const CompressionOptions & compressionOptions) const;
|
||||
|
||||
// Raw API.
|
||||
NVTT_API bool outputHeader(TextureType type, int w, int h, int d, int mipmapCount, bool isNormalMap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
||||
NVTT_API bool compress(int w, int h, int d, int face, int mipmap, const float * rgba, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
||||
NVTT_API int estimateSize(int w, int h, int d, int mipmapCount, const CompressionOptions & compressionOptions) const;
|
||||
};
|
||||
@ -419,7 +420,7 @@ namespace nvtt
|
||||
NVTT_API bool isNormalMap() const;
|
||||
NVTT_API int countMipmaps() const;
|
||||
NVTT_API float alphaTestCoverage(float alphaRef = 0.5) const;
|
||||
NVTT_API float average(int channel) const;
|
||||
NVTT_API float average(int channel, int alpha_channel = -1, float gamma = 2.2f) const;
|
||||
NVTT_API const float * data() const;
|
||||
NVTT_API void histogram(int channel, float rangeMin, float rangeMax, int binCount, int * binPtr) const;
|
||||
NVTT_API void range(int channel, float * rangeMin, float * rangeMax);
|
||||
@ -454,6 +455,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);
|
||||
NVTT_API void toRGBM(float range = 1.0f, float threshold = 0.0f);
|
||||
NVTT_API void fromRGBM(float range = 1.0f);
|
||||
NVTT_API void toYCoCg();
|
||||
|
Reference in New Issue
Block a user