Merge changes from The Witness.

This commit is contained in:
Ignacio
2015-03-24 12:14:49 -07:00
parent 7e2a9d1adb
commit a083337473
57 changed files with 2061 additions and 916 deletions

View File

@ -632,13 +632,12 @@ void BlockCTX1::setIndices(int * idx)
/// Decode BC6 block.
void BlockBC6::decodeBlock(ColorSet * set) const
void BlockBC6::decodeBlock(Vector3 colors[16]) const
{
ZOH::Tile tile(4, 4);
ZOH::decompress((const char *)data, tile);
// Convert ZOH's tile struct back to NVTT's, and convert half to float.
set->allocate(4, 4);
// Convert ZOH's tile struct to Vector3, and convert half to float.
for (uint y = 0; y < 4; ++y)
{
for (uint x = 0; x < 4; ++x)
@ -646,13 +645,9 @@ void BlockBC6::decodeBlock(ColorSet * set) const
uint16 rHalf = ZOH::Tile::float2half(tile.data[y][x].x);
uint16 gHalf = ZOH::Tile::float2half(tile.data[y][x].y);
uint16 bHalf = ZOH::Tile::float2half(tile.data[y][x].z);
set->colors[y * 4 + x].x = to_float(rHalf);
set->colors[y * 4 + x].y = to_float(gHalf);
set->colors[y * 4 + x].z = to_float(bHalf);
set->colors[y * 4 + x].w = 1.0f;
// Set indices in case someone uses them
set->indices[y * 4 + x] = y * 4 + x;
colors[y * 4 + x].x = to_float(rHalf);
colors[y * 4 + x].y = to_float(gHalf);
colors[y * 4 + x].z = to_float(bHalf);
}
}
}

View File

@ -35,6 +35,7 @@ namespace nv
struct ColorSet;
struct AlphaBlock4x4;
class Stream;
class Vector3;
/// DXT1 block.
@ -219,7 +220,7 @@ namespace nv
struct BlockBC6
{
uint8 data[16]; // Not even going to try to write a union for this thing.
void decodeBlock(ColorSet * set) const;
void decodeBlock(Vector3 colors[16]) const;
};
/// BC7 block.

View File

@ -462,7 +462,7 @@ float ColorBlock::volume() const
return bounds.volume();
}*/
#if 0
void ColorSet::allocate(uint w, uint h)
{
nvDebugCheck(w <= 4 && h <= 4);
@ -680,6 +680,7 @@ bool ColorSet::hasAlpha() const
}
return false;
}
#endif // 0
void AlphaBlock4x4::init(uint8 a)
@ -707,7 +708,7 @@ void AlphaBlock4x4::init(const ColorBlock & src, uint channel)
void AlphaBlock4x4::init(const ColorSet & src, uint channel)
/*void AlphaBlock4x4::init(const ColorSet & src, uint channel)
{
nvCheck(channel >= 0 && channel < 4);
@ -727,12 +728,12 @@ void AlphaBlock4x4::initMaxRGB(const ColorSet & src, float threshold)
alpha[i] = unitFloatToFixed8(max(max(x, y), max(z, threshold)));
weights[i] = 1.0f;
}
}
}*/
void AlphaBlock4x4::initWeights(const ColorSet & src)
/*void AlphaBlock4x4::initWeights(const ColorSet & src)
{
for (int i = 0; i < 16; i++) {
weights[i] = src.weight(i);
}
}
}*/

View File

@ -81,7 +81,7 @@ namespace nv
return m_color[y * 4 + x];
}
/*
struct ColorSet
{
ColorSet() : colorCount(0), indexCount(0), w(0), h(0) {}
@ -124,6 +124,7 @@ namespace nv
float weights[16]; // @@ Add mask to indicate what color components are weighted?
int indices[16];
};
*/
/// Uncompressed 4x4 alpha block.
@ -131,10 +132,10 @@ namespace nv
{
void init(uint8 value);
void init(const ColorBlock & src, uint channel);
void init(const ColorSet & src, uint channel);
//void init(const ColorSet & src, uint channel);
void initMaxRGB(const ColorSet & src, float threshold);
void initWeights(const ColorSet & src);
//void initMaxRGB(const ColorSet & src, float threshold);
//void initWeights(const ColorSet & src);
uint8 alpha[4*4];
float weights[16];

View File

@ -31,6 +31,7 @@
#include "nvcore/Utils.h" // max
#include "nvcore/StdStream.h"
#include "nvmath/Vector.inl"
#include "nvmath/ftoi.h"
#include <string.h> // memset
@ -1395,20 +1396,20 @@ void DirectDrawSurface::readBlock(ColorBlock * rgba)
{
BlockBC6 block;
*stream << block;
ColorSet set;
block.decodeBlock(&set);
Vector3 colors[16];
block.decodeBlock(colors);
// Clamp to [0, 1] and round to 8-bit
for (int y = 0; y < 4; ++y)
{
for (int x = 0; x < 4; ++x)
{
Vector4 px = set.colors[y*4 + x];
Vector3 px = colors[y*4 + x];
rgba->color(x, y).setRGBA(
uint8(clamp(px.x, 0.0f, 1.0f) * 255.0f + 0.5f),
uint8(clamp(px.y, 0.0f, 1.0f) * 255.0f + 0.5f),
uint8(clamp(px.z, 0.0f, 1.0f) * 255.0f + 0.5f),
uint8(clamp(px.w, 0.0f, 1.0f) * 255.0f + 0.5f));
ftoi_round(clamp(px.x, 0.0f, 1.0f) * 255.0f),
ftoi_round(clamp(px.y, 0.0f, 1.0f) * 255.0f),
ftoi_round(clamp(px.z, 0.0f, 1.0f) * 255.0f),
0xFF);
}
}
}

View File

@ -10,7 +10,7 @@
using namespace nv;
float nv::rmsColorError(const FloatImage * img, const FloatImage * ref, bool alphaWeight)
float nv::rmsColorError(const FloatImage * ref, const FloatImage * img, bool alphaWeight)
{
if (!sameLayout(img, ref)) {
return FLT_MAX;
@ -23,31 +23,31 @@ float nv::rmsColorError(const FloatImage * img, const FloatImage * ref, bool alp
const uint count = img->pixelCount();
for (uint i = 0; i < count; i++)
{
float r0 = img->pixel(i + count * 0);
float g0 = img->pixel(i + count * 1);
float b0 = img->pixel(i + count * 2);
//float a0 = img->pixel(i + count * 3);
float r1 = ref->pixel(i + count * 0);
float g1 = ref->pixel(i + count * 1);
float b1 = ref->pixel(i + count * 2);
float a1 = ref->pixel(i + count * 3);
float r0 = ref->pixel(i + count * 0);
float g0 = ref->pixel(i + count * 1);
float b0 = ref->pixel(i + count * 2);
float a0 = ref->pixel(i + count * 3);
float r1 = img->pixel(i + count * 0);
float g1 = img->pixel(i + count * 1);
float b1 = img->pixel(i + count * 2);
//float a1 = img->pixel(i + count * 3);
float r = r0 - r1;
float g = g0 - g1;
float b = b0 - b1;
float a = 1;
if (alphaWeight) a = a1;
if (alphaWeight) a = a0 * a0; // @@ a0*a1 or a0*a0 ?
mse += r * r * a;
mse += g * g * a;
mse += b * b * a;
mse += (r * r) * a;
mse += (g * g) * a;
mse += (b * b) * a;
}
return float(sqrt(mse / count));
}
float nv::rmsAlphaError(const FloatImage * img, const FloatImage * ref)
float nv::rmsAlphaError(const FloatImage * ref, const FloatImage * img)
{
if (!sameLayout(img, ref)) {
return FLT_MAX;
@ -71,7 +71,7 @@ float nv::rmsAlphaError(const FloatImage * img, const FloatImage * ref)
}
float nv::averageColorError(const FloatImage * img, const FloatImage * ref, bool alphaWeight)
float nv::averageColorError(const FloatImage * ref, const FloatImage * img, bool alphaWeight)
{
if (!sameLayout(img, ref)) {
return FLT_MAX;
@ -108,7 +108,7 @@ float nv::averageColorError(const FloatImage * img, const FloatImage * ref, bool
return float(mae / count);
}
float nv::averageAlphaError(const FloatImage * img, const FloatImage * ref)
float nv::averageAlphaError(const FloatImage * ref, const FloatImage * img)
{
if (img == NULL || ref == NULL || img->width() != ref->width() || img->height() != ref->height()) {
return FLT_MAX;

View File

@ -6,15 +6,15 @@ namespace nv
{
class FloatImage;
float rmsColorError(const FloatImage * img, const FloatImage * ref, bool alphaWeight);
float rmsAlphaError(const FloatImage * img, const FloatImage * ref);
float rmsColorError(const FloatImage * ref, const FloatImage * img, bool alphaWeight);
float rmsAlphaError(const FloatImage * ref, const FloatImage * img);
float cieLabError(const FloatImage * img, const FloatImage * ref);
float cieLab94Error(const FloatImage * img, const FloatImage * ref);
float spatialCieLabError(const FloatImage * img, const FloatImage * ref);
float cieLabError(const FloatImage * ref, const FloatImage * img);
float cieLab94Error(const FloatImage * ref, const FloatImage * img);
float spatialCieLabError(const FloatImage * ref, const FloatImage * img);
float averageColorError(const FloatImage * img, const FloatImage * ref, bool alphaWeight);
float averageAlphaError(const FloatImage * img, const FloatImage * ref);
float averageColorError(const FloatImage * ref, const FloatImage * img, bool alphaWeight);
float averageAlphaError(const FloatImage * ref, const FloatImage * img);
float averageAngularError(const FloatImage * img0, const FloatImage * img1);
float rmsAngularError(const FloatImage * img0, const FloatImage * img1);