Work in progress.
Merging squish into nvtt. Using squish only to find endpoints, do discrete refinement afterwards.
This commit is contained in:
@ -458,7 +458,8 @@ float ColorBlock::volume() const
|
||||
}*/
|
||||
|
||||
|
||||
void FloatColorBlock::init(const Image * img, uint x, uint y)
|
||||
|
||||
void ColorSet::init(const Image * img, uint x, uint y)
|
||||
{
|
||||
w = min(4U, img->width() - x);
|
||||
h = min(4U, img->height() - y);
|
||||
@ -485,15 +486,15 @@ void FloatColorBlock::init(const Image * img, uint x, uint y)
|
||||
}
|
||||
}
|
||||
|
||||
void FloatColorBlock::init(const FloatImage * img, uint x, uint y)
|
||||
void ColorSet::init(const FloatImage * img, uint x, uint y)
|
||||
{
|
||||
}
|
||||
|
||||
void FloatColorBlock::init(const uint * data, uint w, uint h, uint x, uint y)
|
||||
void ColorSet::init(const uint * data, uint w, uint h, uint x, uint y)
|
||||
{
|
||||
}
|
||||
|
||||
void FloatColorBlock::init(const float * data, uint w, uint h, uint x, uint y)
|
||||
void ColorSet::init(const float * data, uint w, uint h, uint x, uint y)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -26,21 +26,8 @@ namespace nv
|
||||
void swizzle(uint x, uint y, uint z, uint w); // 0=r, 1=g, 2=b, 3=a, 4=0xFF, 5=0
|
||||
|
||||
bool isSingleColor(Color32 mask = Color32(0xFF, 0xFF, 0xFF, 0x00)) const;
|
||||
//uint countUniqueColors() const;
|
||||
//Color32 averageColor() const;
|
||||
bool hasAlpha() const;
|
||||
|
||||
//void diameterRange(Color32 * start, Color32 * end) const;
|
||||
//void luminanceRange(Color32 * start, Color32 * end) const;
|
||||
//void boundsRange(Color32 * start, Color32 * end) const;
|
||||
//void boundsRangeAlpha(Color32 * start, Color32 * end) const;
|
||||
|
||||
//void sortColorsByAbsoluteValue();
|
||||
|
||||
//void computeRange(const Vector3 & axis, Color32 * start, Color32 * end) const;
|
||||
//void sortColors(const Vector3 & axis);
|
||||
|
||||
//float volume() const;
|
||||
|
||||
// Accessors
|
||||
const Color32 * colors() const;
|
||||
@ -93,19 +80,21 @@ namespace nv
|
||||
}
|
||||
|
||||
|
||||
struct FloatColorBlock
|
||||
struct ColorSet
|
||||
{
|
||||
FloatColorBlock() : w(4), h(4) {}
|
||||
FloatColorBlock(uint w, uint h) : w(w), h(h) {}
|
||||
ColorSet() : w(4), h(4) {}
|
||||
ColorSet(uint w, uint h) : w(w), h(h) {}
|
||||
|
||||
void init(const Image * img, uint x, uint y);
|
||||
void init(const FloatImage * img, uint x, uint y);
|
||||
void init(const uint * data, uint w, uint h, uint x, uint y);
|
||||
void init(const float * data, uint w, uint h, uint x, uint y);
|
||||
|
||||
Vector4 color(uint x, uint y) const { nvDebugCheck(x < w && y < h); return colors[y * 4 + x]; }
|
||||
Vector4 color(uint x, uint y) const { nvDebugCheck(x < w && y < h); return colors[y * 4 + x]; }
|
||||
Vector4 & color(uint x, uint y) { nvDebugCheck(x < w && y < h); return colors[y * 4 + x]; }
|
||||
|
||||
Vector4 color(uint i) const { nvDebugCheck(i < 16); return colors[i]; }
|
||||
Vector4 & color(uint i) { nvDebugCheck(i < 16); return colors[i]; }
|
||||
|
||||
Vector4 colors[16];
|
||||
uint w, h;
|
||||
|
@ -111,6 +111,9 @@ namespace nv
|
||||
float pixel(uint x, uint y, uint c) const;
|
||||
float & pixel(uint x, uint y, uint c);
|
||||
|
||||
float pixel(uint idx, uint c) const;
|
||||
float & pixel(uint idx, uint c);
|
||||
|
||||
float pixel(uint idx) const;
|
||||
float & pixel(uint idx);
|
||||
|
||||
@ -197,6 +200,24 @@ namespace nv
|
||||
return m_mem[(c * m_height + y) * m_width + x];
|
||||
}
|
||||
|
||||
/// Get pixel component.
|
||||
inline float FloatImage::pixel(uint idx, uint c) const
|
||||
{
|
||||
nvDebugCheck(m_mem != NULL);
|
||||
nvDebugCheck(idx < uint(m_width*m_height));
|
||||
nvDebugCheck(c < m_componentNum);
|
||||
return m_mem[c * m_height * m_width + idx];
|
||||
}
|
||||
|
||||
/// Get pixel component.
|
||||
inline float & FloatImage::pixel(uint idx, uint c)
|
||||
{
|
||||
nvDebugCheck(m_mem != NULL);
|
||||
nvDebugCheck(idx < uint(m_width*m_height));
|
||||
nvDebugCheck(c < m_componentNum);
|
||||
return m_mem[c * m_height * m_width + idx];
|
||||
}
|
||||
|
||||
/// Get pixel component.
|
||||
inline float FloatImage::pixel(uint idx) const
|
||||
{
|
||||
|
@ -97,6 +97,7 @@ namespace nv
|
||||
#endif // defined(HAVE_FREEIMAGE)
|
||||
|
||||
static FloatImage * loadFloatDDS(Stream & s);
|
||||
static bool saveFloatDDS(const char * fileName, Stream & s, const FloatImage * img, uint base_component, uint num_components);
|
||||
|
||||
} // ImageIO namespace
|
||||
} // nv namespace
|
||||
@ -264,6 +265,12 @@ bool nv::ImageIO::saveFloat(const char * fileName, Stream & s, const FloatImage
|
||||
return false;
|
||||
}
|
||||
|
||||
const char * extension = Path::extension(fileName);
|
||||
|
||||
if (strCaseCmp(extension, ".dds") == 0) {
|
||||
return saveFloatDDS(fileName, s, fimage, baseComponent, componentCount);
|
||||
}
|
||||
|
||||
#if defined(HAVE_FREEIMAGE)
|
||||
FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(fileName);
|
||||
if (fif != FIF_UNKNOWN && FreeImage_FIFSupportsWriting(fif)) {
|
||||
@ -1792,3 +1799,42 @@ FloatImage * nv::ImageIO::loadFloatDDS(Stream & s)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool nv::ImageIO::saveFloatDDS(const char * fileName, Stream & s, const FloatImage * img, uint base_component, uint num_components)
|
||||
{
|
||||
nvCheck(s.isSaving());
|
||||
nvCheck(!s.isError());
|
||||
|
||||
if (num_components != 4) return false;
|
||||
|
||||
static const uint D3DFMT_A16B16G16R16F = 113;
|
||||
|
||||
DDSHeader header;
|
||||
header.setTexture2D();
|
||||
header.setWidth(img->width());
|
||||
header.setHeight(img->height());
|
||||
header.setFormatCode(D3DFMT_A16B16G16R16F);
|
||||
// ...
|
||||
|
||||
s << header;
|
||||
|
||||
uint32 * r = (uint32 *)img->channel(base_component + 0);
|
||||
uint32 * g = (uint32 *)img->channel(base_component + 1);
|
||||
uint32 * b = (uint32 *)img->channel(base_component + 2);
|
||||
uint32 * a = (uint32 *)img->channel(base_component + 3);
|
||||
|
||||
const uint size = img->width() * img->height();
|
||||
for (uint i = 0; i < size; i++) {
|
||||
uint16 R = half_from_float( *r++ );
|
||||
uint16 G = half_from_float( *g++ );
|
||||
uint16 B = half_from_float( *b++ );
|
||||
uint16 A = half_from_float( *a++ );
|
||||
|
||||
s.serialize(&R, sizeof(uint16));
|
||||
s.serialize(&G, sizeof(uint16));
|
||||
s.serialize(&B, sizeof(uint16));
|
||||
s.serialize(&A, sizeof(uint16));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ namespace nv
|
||||
float result;
|
||||
int offset = 0;
|
||||
do {
|
||||
uint i = offset + f * (float(1 << inbits) - 1);
|
||||
uint i = offset + uint(f * (float(1 << inbits) - 1));
|
||||
i = convert(i, inbits, outbits);
|
||||
result = float(i) / (float(1 << outbits) - 1);
|
||||
offset++;
|
||||
|
Reference in New Issue
Block a user