Fix format.
This commit is contained in:
parent
c3bc24b165
commit
f233188963
@ -37,7 +37,7 @@
|
|||||||
using namespace nv;
|
using namespace nv;
|
||||||
|
|
||||||
#if !defined(MAKEFOURCC)
|
#if !defined(MAKEFOURCC)
|
||||||
# define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||||
(uint(uint8(ch0)) | (uint(uint8(ch1)) << 8) | \
|
(uint(uint8(ch0)) | (uint(uint8(ch1)) << 8) | \
|
||||||
(uint(uint8(ch2)) << 16) | (uint(uint8(ch3)) << 24 ))
|
(uint(uint8(ch2)) << 16) | (uint(uint8(ch3)) << 24 ))
|
||||||
#endif
|
#endif
|
||||||
@ -129,7 +129,7 @@ namespace
|
|||||||
static const uint DDPF_PALETTEINDEXED8 = 0x00000020U;
|
static const uint DDPF_PALETTEINDEXED8 = 0x00000020U;
|
||||||
static const uint DDPF_LUMINANCE = 0x00020000U;
|
static const uint DDPF_LUMINANCE = 0x00020000U;
|
||||||
static const uint DDPF_ALPHAPREMULT = 0x00008000U;
|
static const uint DDPF_ALPHAPREMULT = 0x00008000U;
|
||||||
static const uint DDPF_NORMAL = 0x80000000U; // @@ Custom nv flag.
|
static const uint DDPF_NORMAL = 0x80000000U; // @@ Custom nv flag.
|
||||||
|
|
||||||
// DX10 formats.
|
// DX10 formats.
|
||||||
enum DXGI_FORMAT
|
enum DXGI_FORMAT
|
||||||
@ -410,10 +410,10 @@ namespace nv
|
|||||||
s.serialize(&pf.gmask, sizeof(pf.gmask));
|
s.serialize(&pf.gmask, sizeof(pf.gmask));
|
||||||
s.serialize(&pf.bmask, sizeof(pf.bmask));
|
s.serialize(&pf.bmask, sizeof(pf.bmask));
|
||||||
s.serialize(&pf.amask, sizeof(pf.amask));
|
s.serialize(&pf.amask, sizeof(pf.amask));
|
||||||
// s << pf.rmask;
|
// s << pf.rmask;
|
||||||
// s << pf.gmask;
|
// s << pf.gmask;
|
||||||
// s << pf.bmask;
|
// s << pf.bmask;
|
||||||
// s << pf.amask;
|
// s << pf.amask;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,7 +538,7 @@ DDSHeader::DDSHeader()
|
|||||||
|
|
||||||
// Store version information on the reserved header attributes.
|
// Store version information on the reserved header attributes.
|
||||||
this->reserved[9] = MAKEFOURCC('N', 'V', 'T', 'T');
|
this->reserved[9] = MAKEFOURCC('N', 'V', 'T', 'T');
|
||||||
this->reserved[10] = (2 << 16) | (1 << 8) | (0); // major.minor.revision
|
this->reserved[10] = (2 << 16) | (1 << 8) | (0); // major.minor.revision
|
||||||
|
|
||||||
this->pf.size = 32;
|
this->pf.size = 32;
|
||||||
this->pf.flags = 0;
|
this->pf.flags = 0;
|
||||||
@ -686,7 +686,7 @@ void DDSHeader::setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask
|
|||||||
if (gmask == 0 && bmask == 0)
|
if (gmask == 0 && bmask == 0)
|
||||||
{
|
{
|
||||||
this->pf.flags = DDPF_LUMINANCE;
|
this->pf.flags = DDPF_LUMINANCE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->pf.flags = DDPF_RGB;
|
this->pf.flags = DDPF_RGB;
|
||||||
|
@ -39,59 +39,59 @@
|
|||||||
|
|
||||||
struct MyOutputHandler : public nvtt::OutputHandler
|
struct MyOutputHandler : public nvtt::OutputHandler
|
||||||
{
|
{
|
||||||
MyOutputHandler(const char * name) : total(0), progress(0), percentage(0), stream(new nv::StdOutputStream(name)) {}
|
MyOutputHandler(const char * name) : total(0), progress(0), percentage(0), stream(new nv::StdOutputStream(name)) {}
|
||||||
virtual ~MyOutputHandler() { delete stream; }
|
virtual ~MyOutputHandler() { delete stream; }
|
||||||
|
|
||||||
void setTotal(int64 t)
|
void setTotal(int64 t)
|
||||||
{
|
{
|
||||||
total = t + 128;
|
total = t + 128;
|
||||||
}
|
}
|
||||||
void setDisplayProgress(bool b)
|
void setDisplayProgress(bool b)
|
||||||
{
|
{
|
||||||
verbose = b;
|
verbose = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void beginImage(int size, int width, int height, int depth, int face, int miplevel)
|
virtual void beginImage(int size, int width, int height, int depth, int face, int miplevel)
|
||||||
{
|
{
|
||||||
// ignore.
|
// ignore.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output data.
|
// Output data.
|
||||||
virtual bool writeData(const void * data, int size)
|
virtual bool writeData(const void * data, int size)
|
||||||
{
|
{
|
||||||
nvDebugCheck(stream != NULL);
|
nvDebugCheck(stream != NULL);
|
||||||
stream->serialize(const_cast<void *>(data), size);
|
stream->serialize(const_cast<void *>(data), size);
|
||||||
|
|
||||||
progress += size;
|
progress += size;
|
||||||
int p = int((100 * progress) / total);
|
int p = int((100 * progress) / total);
|
||||||
if (verbose && p != percentage)
|
if (verbose && p != percentage)
|
||||||
{
|
{
|
||||||
nvCheck(p >= 0);
|
nvCheck(p >= 0);
|
||||||
|
|
||||||
percentage = p;
|
percentage = p;
|
||||||
printf("\r%d%%", percentage);
|
printf("\r%d%%", percentage);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64 total;
|
int64 total;
|
||||||
int64 progress;
|
int64 progress;
|
||||||
int percentage;
|
int percentage;
|
||||||
bool verbose;
|
bool verbose;
|
||||||
nv::StdOutputStream * stream;
|
nv::StdOutputStream * stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MyErrorHandler : public nvtt::ErrorHandler
|
struct MyErrorHandler : public nvtt::ErrorHandler
|
||||||
{
|
{
|
||||||
virtual void error(nvtt::Error e)
|
virtual void error(nvtt::Error e)
|
||||||
{
|
{
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
nvDebugBreak();
|
nvDebugBreak();
|
||||||
#endif
|
#endif
|
||||||
printf("Error: '%s'\n", nvtt::errorString(e));
|
printf("Error: '%s'\n", nvtt::errorString(e));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -100,475 +100,475 @@ struct MyErrorHandler : public nvtt::ErrorHandler
|
|||||||
// Set color to normal map conversion options.
|
// Set color to normal map conversion options.
|
||||||
void setColorToNormalMap(nvtt::InputOptions & inputOptions)
|
void setColorToNormalMap(nvtt::InputOptions & inputOptions)
|
||||||
{
|
{
|
||||||
inputOptions.setNormalMap(false);
|
inputOptions.setNormalMap(false);
|
||||||
inputOptions.setConvertToNormalMap(true);
|
inputOptions.setConvertToNormalMap(true);
|
||||||
inputOptions.setHeightEvaluation(1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f, 0.0f);
|
inputOptions.setHeightEvaluation(1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f, 0.0f);
|
||||||
//inputOptions.setNormalFilter(1.0f, 0, 0, 0);
|
//inputOptions.setNormalFilter(1.0f, 0, 0, 0);
|
||||||
//inputOptions.setNormalFilter(0.0f, 0, 0, 1);
|
//inputOptions.setNormalFilter(0.0f, 0, 0, 1);
|
||||||
inputOptions.setGamma(1.0f, 1.0f);
|
inputOptions.setGamma(1.0f, 1.0f);
|
||||||
inputOptions.setNormalizeMipmaps(true);
|
inputOptions.setNormalizeMipmaps(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set options for normal maps.
|
// Set options for normal maps.
|
||||||
void setNormalMap(nvtt::InputOptions & inputOptions)
|
void setNormalMap(nvtt::InputOptions & inputOptions)
|
||||||
{
|
{
|
||||||
inputOptions.setNormalMap(true);
|
inputOptions.setNormalMap(true);
|
||||||
inputOptions.setConvertToNormalMap(false);
|
inputOptions.setConvertToNormalMap(false);
|
||||||
inputOptions.setGamma(1.0f, 1.0f);
|
inputOptions.setGamma(1.0f, 1.0f);
|
||||||
inputOptions.setNormalizeMipmaps(true);
|
inputOptions.setNormalizeMipmaps(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set options for color maps.
|
// Set options for color maps.
|
||||||
void setColorMap(nvtt::InputOptions & inputOptions)
|
void setColorMap(nvtt::InputOptions & inputOptions)
|
||||||
{
|
{
|
||||||
inputOptions.setNormalMap(false);
|
inputOptions.setNormalMap(false);
|
||||||
inputOptions.setConvertToNormalMap(false);
|
inputOptions.setConvertToNormalMap(false);
|
||||||
inputOptions.setGamma(2.2f, 2.2f);
|
inputOptions.setGamma(2.2f, 2.2f);
|
||||||
inputOptions.setNormalizeMipmaps(false);
|
inputOptions.setNormalizeMipmaps(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
MyAssertHandler assertHandler;
|
MyAssertHandler assertHandler;
|
||||||
MyMessageHandler messageHandler;
|
MyMessageHandler messageHandler;
|
||||||
|
|
||||||
bool alpha = false;
|
bool alpha = false;
|
||||||
bool normal = false;
|
bool normal = false;
|
||||||
bool color2normal = false;
|
bool color2normal = false;
|
||||||
bool wrapRepeat = false;
|
bool wrapRepeat = false;
|
||||||
bool noMipmaps = false;
|
bool noMipmaps = false;
|
||||||
bool fast = false;
|
bool fast = false;
|
||||||
bool nocuda = false;
|
bool nocuda = false;
|
||||||
bool bc1n = false;
|
bool bc1n = false;
|
||||||
bool luminance = false;
|
bool luminance = false;
|
||||||
nvtt::Format format = nvtt::Format_BC1;
|
nvtt::Format format = nvtt::Format_BC1;
|
||||||
bool premultiplyAlpha = false;
|
bool premultiplyAlpha = false;
|
||||||
nvtt::MipmapFilter mipmapFilter = nvtt::MipmapFilter_Box;
|
nvtt::MipmapFilter mipmapFilter = nvtt::MipmapFilter_Box;
|
||||||
bool loadAsFloat = false;
|
bool loadAsFloat = false;
|
||||||
|
|
||||||
const char * externalCompressor = NULL;
|
const char * externalCompressor = NULL;
|
||||||
|
|
||||||
bool silent = false;
|
bool silent = false;
|
||||||
bool dds10 = false;
|
bool dds10 = false;
|
||||||
|
|
||||||
nv::Path input;
|
nv::Path input;
|
||||||
nv::Path output;
|
nv::Path output;
|
||||||
|
|
||||||
|
|
||||||
// Parse arguments.
|
// Parse arguments.
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
// Input options.
|
// Input options.
|
||||||
if (strcmp("-color", argv[i]) == 0)
|
if (strcmp("-color", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else if (strcmp("-alpha", argv[i]) == 0)
|
else if (strcmp("-alpha", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
alpha = true;
|
alpha = true;
|
||||||
}
|
}
|
||||||
else if (strcmp("-normal", argv[i]) == 0)
|
else if (strcmp("-normal", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
normal = true;
|
normal = true;
|
||||||
}
|
}
|
||||||
else if (strcmp("-tonormal", argv[i]) == 0)
|
else if (strcmp("-tonormal", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
color2normal = true;
|
color2normal = true;
|
||||||
}
|
}
|
||||||
else if (strcmp("-clamp", argv[i]) == 0)
|
else if (strcmp("-clamp", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else if (strcmp("-repeat", argv[i]) == 0)
|
else if (strcmp("-repeat", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
wrapRepeat = true;
|
wrapRepeat = true;
|
||||||
}
|
}
|
||||||
else if (strcmp("-nomips", argv[i]) == 0)
|
else if (strcmp("-nomips", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
noMipmaps = true;
|
noMipmaps = true;
|
||||||
}
|
}
|
||||||
else if (strcmp("-premula", argv[i]) == 0)
|
else if (strcmp("-premula", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
premultiplyAlpha = true;
|
premultiplyAlpha = true;
|
||||||
}
|
}
|
||||||
else if (strcmp("-mipfilter", argv[i]) == 0)
|
else if (strcmp("-mipfilter", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
if (i+1 == argc) break;
|
if (i+1 == argc) break;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
if (strcmp("box", argv[i]) == 0) mipmapFilter = nvtt::MipmapFilter_Box;
|
if (strcmp("box", argv[i]) == 0) mipmapFilter = nvtt::MipmapFilter_Box;
|
||||||
else if (strcmp("triangle", argv[i]) == 0) mipmapFilter = nvtt::MipmapFilter_Triangle;
|
else if (strcmp("triangle", argv[i]) == 0) mipmapFilter = nvtt::MipmapFilter_Triangle;
|
||||||
else if (strcmp("kaiser", argv[i]) == 0) mipmapFilter = nvtt::MipmapFilter_Kaiser;
|
else if (strcmp("kaiser", argv[i]) == 0) mipmapFilter = nvtt::MipmapFilter_Kaiser;
|
||||||
}
|
}
|
||||||
else if (strcmp("-float", argv[i]) == 0)
|
else if (strcmp("-float", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
loadAsFloat = true;
|
loadAsFloat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compression options.
|
// Compression options.
|
||||||
else if (strcmp("-fast", argv[i]) == 0)
|
else if (strcmp("-fast", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
fast = true;
|
fast = true;
|
||||||
}
|
}
|
||||||
else if (strcmp("-nocuda", argv[i]) == 0)
|
else if (strcmp("-nocuda", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
nocuda = true;
|
nocuda = true;
|
||||||
}
|
}
|
||||||
else if (strcmp("-rgb", argv[i]) == 0)
|
else if (strcmp("-rgb", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
format = nvtt::Format_RGB;
|
format = nvtt::Format_RGB;
|
||||||
}
|
}
|
||||||
else if (strcmp("-lumi", argv[i]) == 0)
|
else if (strcmp("-lumi", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
luminance = true;
|
luminance = true;
|
||||||
format = nvtt::Format_RGB;
|
format = nvtt::Format_RGB;
|
||||||
}
|
}
|
||||||
else if (strcmp("-bc1", argv[i]) == 0)
|
else if (strcmp("-bc1", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
format = nvtt::Format_BC1;
|
format = nvtt::Format_BC1;
|
||||||
}
|
}
|
||||||
else if (strcmp("-bc1n", argv[i]) == 0)
|
else if (strcmp("-bc1n", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
format = nvtt::Format_BC1;
|
format = nvtt::Format_BC1;
|
||||||
bc1n = true;
|
bc1n = true;
|
||||||
}
|
}
|
||||||
else if (strcmp("-bc1a", argv[i]) == 0)
|
else if (strcmp("-bc1a", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
format = nvtt::Format_BC1a;
|
format = nvtt::Format_BC1a;
|
||||||
}
|
}
|
||||||
else if (strcmp("-bc2", argv[i]) == 0)
|
else if (strcmp("-bc2", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
format = nvtt::Format_BC2;
|
format = nvtt::Format_BC2;
|
||||||
}
|
}
|
||||||
else if (strcmp("-bc3", argv[i]) == 0)
|
else if (strcmp("-bc3", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
format = nvtt::Format_BC3;
|
format = nvtt::Format_BC3;
|
||||||
}
|
}
|
||||||
else if (strcmp("-bc3n", argv[i]) == 0)
|
else if (strcmp("-bc3n", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
format = nvtt::Format_BC3n;
|
format = nvtt::Format_BC3n;
|
||||||
}
|
}
|
||||||
else if (strcmp("-bc4", argv[i]) == 0)
|
else if (strcmp("-bc4", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
format = nvtt::Format_BC4;
|
format = nvtt::Format_BC4;
|
||||||
}
|
}
|
||||||
else if (strcmp("-bc5", argv[i]) == 0)
|
else if (strcmp("-bc5", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
format = nvtt::Format_BC5;
|
format = nvtt::Format_BC5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Undocumented option. Mainly used for testing.
|
// Undocumented option. Mainly used for testing.
|
||||||
else if (strcmp("-ext", argv[i]) == 0)
|
else if (strcmp("-ext", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
if (i+1 < argc && argv[i+1][0] != '-') {
|
if (i+1 < argc && argv[i+1][0] != '-') {
|
||||||
externalCompressor = argv[i+1];
|
externalCompressor = argv[i+1];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output options
|
// Output options
|
||||||
else if (strcmp("-silent", argv[i]) == 0)
|
else if (strcmp("-silent", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
silent = true;
|
silent = true;
|
||||||
}
|
}
|
||||||
else if (strcmp("-dds10", argv[i]) == 0)
|
else if (strcmp("-dds10", argv[i]) == 0)
|
||||||
{
|
{
|
||||||
dds10 = true;
|
dds10 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (argv[i][0] != '-')
|
else if (argv[i][0] != '-')
|
||||||
{
|
{
|
||||||
input = argv[i];
|
input = argv[i];
|
||||||
|
|
||||||
if (i+1 < argc && argv[i+1][0] != '-') {
|
if (i+1 < argc && argv[i+1][0] != '-') {
|
||||||
output = argv[i+1];
|
output = argv[i+1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
output.copy(input.str());
|
output.copy(input.str());
|
||||||
output.stripExtension();
|
output.stripExtension();
|
||||||
output.append(".dds");
|
output.append(".dds");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint version = nvtt::version();
|
const uint version = nvtt::version();
|
||||||
const uint major = version / 100;
|
const uint major = version / 100;
|
||||||
const uint minor = version % 100;
|
const uint minor = version % 100;
|
||||||
|
|
||||||
|
|
||||||
printf("NVIDIA Texture Tools %u.%u - Copyright NVIDIA Corporation 2007\n\n", major, minor);
|
printf("NVIDIA Texture Tools %u.%u - Copyright NVIDIA Corporation 2007\n\n", major, minor);
|
||||||
|
|
||||||
if (input.isNull())
|
if (input.isNull())
|
||||||
{
|
{
|
||||||
printf("usage: nvcompress [options] infile [outfile]\n\n");
|
printf("usage: nvcompress [options] infile [outfile]\n\n");
|
||||||
|
|
||||||
printf("Input options:\n");
|
printf("Input options:\n");
|
||||||
printf(" -color \tThe input image is a color map (default).\n");
|
printf(" -color \tThe input image is a color map (default).\n");
|
||||||
printf(" -alpha \tThe input image has an alpha channel used for transparency.\n");
|
printf(" -alpha \tThe input image has an alpha channel used for transparency.\n");
|
||||||
printf(" -normal \tThe input image is a normal map.\n");
|
printf(" -normal \tThe input image is a normal map.\n");
|
||||||
printf(" -tonormal \tConvert input to normal map.\n");
|
printf(" -tonormal \tConvert input to normal map.\n");
|
||||||
printf(" -clamp \tClamp wrapping mode (default).\n");
|
printf(" -clamp \tClamp wrapping mode (default).\n");
|
||||||
printf(" -repeat \tRepeat wrapping mode.\n");
|
printf(" -repeat \tRepeat wrapping mode.\n");
|
||||||
printf(" -nomips \tDisable mipmap generation.\n");
|
printf(" -nomips \tDisable mipmap generation.\n");
|
||||||
printf(" -premula \tPremultiply alpha into color channel.\n");
|
printf(" -premula \tPremultiply alpha into color channel.\n");
|
||||||
printf(" -mipfilter \tMipmap filter. One of the following: box, triangle, kaiser.\n");
|
printf(" -mipfilter \tMipmap filter. One of the following: box, triangle, kaiser.\n");
|
||||||
printf(" -float \tLoad as floating point image.\n\n");
|
printf(" -float \tLoad as floating point image.\n\n");
|
||||||
|
|
||||||
printf("Compression options:\n");
|
printf("Compression options:\n");
|
||||||
printf(" -fast \tFast compression.\n");
|
printf(" -fast \tFast compression.\n");
|
||||||
printf(" -nocuda \tDo not use cuda compressor.\n");
|
printf(" -nocuda \tDo not use cuda compressor.\n");
|
||||||
printf(" -rgb \tRGBA format\n");
|
printf(" -rgb \tRGBA format\n");
|
||||||
printf(" -lumi \tLUMINANCE format\n");
|
printf(" -lumi \tLUMINANCE format\n");
|
||||||
printf(" -bc1 \tBC1 format (DXT1)\n");
|
printf(" -bc1 \tBC1 format (DXT1)\n");
|
||||||
printf(" -bc1n \tBC1 normal map format (DXT1nm)\n");
|
printf(" -bc1n \tBC1 normal map format (DXT1nm)\n");
|
||||||
printf(" -bc1a \tBC1 format with binary alpha (DXT1a)\n");
|
printf(" -bc1a \tBC1 format with binary alpha (DXT1a)\n");
|
||||||
printf(" -bc2 \tBC2 format (DXT3)\n");
|
printf(" -bc2 \tBC2 format (DXT3)\n");
|
||||||
printf(" -bc3 \tBC3 format (DXT5)\n");
|
printf(" -bc3 \tBC3 format (DXT5)\n");
|
||||||
printf(" -bc3n \tBC3 normal map format (DXT5nm)\n");
|
printf(" -bc3n \tBC3 normal map format (DXT5nm)\n");
|
||||||
printf(" -bc4 \tBC4 format (ATI1)\n");
|
printf(" -bc4 \tBC4 format (ATI1)\n");
|
||||||
printf(" -bc5 \tBC5 format (3Dc/ATI2)\n\n");
|
printf(" -bc5 \tBC5 format (3Dc/ATI2)\n\n");
|
||||||
|
|
||||||
printf("Output options:\n");
|
printf("Output options:\n");
|
||||||
printf(" -silent \tDo not output progress messages\n");
|
printf(" -silent \tDo not output progress messages\n");
|
||||||
printf(" -dds10 \tUse DirectX 10 DDS format\n\n");
|
printf(" -dds10 \tUse DirectX 10 DDS format\n\n");
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure input file exists.
|
// Make sure input file exists.
|
||||||
if (!nv::FileSystem::exists(input.str()))
|
if (!nv::FileSystem::exists(input.str()))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "The file '%s' does not exist.\n", input.str());
|
fprintf(stderr, "The file '%s' does not exist.\n", input.str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set input options.
|
// Set input options.
|
||||||
nvtt::InputOptions inputOptions;
|
nvtt::InputOptions inputOptions;
|
||||||
|
|
||||||
if (nv::strCaseCmp(input.extension(), ".dds") == 0)
|
if (nv::strCaseCmp(input.extension(), ".dds") == 0)
|
||||||
{
|
{
|
||||||
// Load surface.
|
// Load surface.
|
||||||
nv::DirectDrawSurface dds(input);
|
nv::DirectDrawSurface dds(input);
|
||||||
if (!dds.isValid())
|
if (!dds.isValid())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "The file '%s' is not a valid DDS file.\n", input.str());
|
fprintf(stderr, "The file '%s' is not a valid DDS file.\n", input.str());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dds.isSupported() || dds.isTexture3D())
|
if (!dds.isSupported() || dds.isTexture3D())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "The file '%s' is not a supported DDS file.\n", input.str());
|
fprintf(stderr, "The file '%s' is not a supported DDS file.\n", input.str());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint faceCount;
|
uint faceCount;
|
||||||
if (dds.isTexture2D())
|
if (dds.isTexture2D())
|
||||||
{
|
{
|
||||||
inputOptions.setTextureLayout(nvtt::TextureType_2D, dds.width(), dds.height());
|
inputOptions.setTextureLayout(nvtt::TextureType_2D, dds.width(), dds.height());
|
||||||
faceCount = 1;
|
faceCount = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nvDebugCheck(dds.isTextureCube());
|
nvDebugCheck(dds.isTextureCube());
|
||||||
inputOptions.setTextureLayout(nvtt::TextureType_Cube, dds.width(), dds.height());
|
inputOptions.setTextureLayout(nvtt::TextureType_Cube, dds.width(), dds.height());
|
||||||
faceCount = 6;
|
faceCount = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint mipmapCount = dds.mipmapCount();
|
uint mipmapCount = dds.mipmapCount();
|
||||||
|
|
||||||
nv::Image mipmap;
|
nv::Image mipmap;
|
||||||
|
|
||||||
for (uint f = 0; f < faceCount; f++)
|
for (uint f = 0; f < faceCount; f++)
|
||||||
{
|
{
|
||||||
for (uint m = 0; m < mipmapCount; m++)
|
for (uint m = 0; m < mipmapCount; m++)
|
||||||
{
|
{
|
||||||
dds.mipmap(&mipmap, f, m); // @@ Load as float.
|
dds.mipmap(&mipmap, f, m); // @@ Load as float.
|
||||||
|
|
||||||
inputOptions.setMipmapData(mipmap.pixels(), mipmap.width(), mipmap.height(), 1, f, m);
|
inputOptions.setMipmapData(mipmap.pixels(), mipmap.width(), mipmap.height(), 1, f, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (nv::strCaseCmp(input.extension(), ".exr") == 0 || nv::strCaseCmp(input.extension(), ".hdr") == 0)
|
if (nv::strCaseCmp(input.extension(), ".exr") == 0 || nv::strCaseCmp(input.extension(), ".hdr") == 0)
|
||||||
{
|
{
|
||||||
loadAsFloat = true;
|
loadAsFloat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadAsFloat)
|
if (loadAsFloat)
|
||||||
{
|
{
|
||||||
nv::AutoPtr<nv::FloatImage> image(nv::ImageIO::loadFloat(input));
|
nv::AutoPtr<nv::FloatImage> image(nv::ImageIO::loadFloat(input));
|
||||||
|
|
||||||
if (image == NULL)
|
if (image == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "The file '%s' is not a supported image type.\n", input.str());
|
fprintf(stderr, "The file '%s' is not a supported image type.\n", input.str());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputOptions.setFormat(nvtt::InputFormat_RGBA_32F);
|
inputOptions.setFormat(nvtt::InputFormat_RGBA_32F);
|
||||||
inputOptions.setTextureLayout(nvtt::TextureType_2D, image->width(), image->height());
|
inputOptions.setTextureLayout(nvtt::TextureType_2D, image->width(), image->height());
|
||||||
|
|
||||||
for (uint i = 0; i < image->componentNum(); i++)
|
for (uint i = 0; i < image->componentNum(); i++)
|
||||||
{
|
{
|
||||||
inputOptions.setMipmapChannelData(image->channel(i), i, image->width(), image->height());
|
inputOptions.setMipmapChannelData(image->channel(i), i, image->width(), image->height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Regular image.
|
// Regular image.
|
||||||
nv::Image image;
|
nv::Image image;
|
||||||
if (!image.load(input))
|
if (!image.load(input))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "The file '%s' is not a supported image type.\n", input.str());
|
fprintf(stderr, "The file '%s' is not a supported image type.\n", input.str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputOptions.setTextureLayout(nvtt::TextureType_2D, image.width(), image.height());
|
inputOptions.setTextureLayout(nvtt::TextureType_2D, image.width(), image.height());
|
||||||
inputOptions.setMipmapData(image.pixels(), image.width(), image.height());
|
inputOptions.setMipmapData(image.pixels(), image.width(), image.height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wrapRepeat)
|
if (wrapRepeat)
|
||||||
{
|
{
|
||||||
inputOptions.setWrapMode(nvtt::WrapMode_Repeat);
|
inputOptions.setWrapMode(nvtt::WrapMode_Repeat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
inputOptions.setWrapMode(nvtt::WrapMode_Clamp);
|
inputOptions.setWrapMode(nvtt::WrapMode_Clamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alpha)
|
if (alpha)
|
||||||
{
|
{
|
||||||
inputOptions.setAlphaMode(nvtt::AlphaMode_Transparency);
|
inputOptions.setAlphaMode(nvtt::AlphaMode_Transparency);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
inputOptions.setAlphaMode(nvtt::AlphaMode_None);
|
inputOptions.setAlphaMode(nvtt::AlphaMode_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (normal)
|
if (normal)
|
||||||
{
|
{
|
||||||
setNormalMap(inputOptions);
|
setNormalMap(inputOptions);
|
||||||
}
|
}
|
||||||
else if (color2normal)
|
else if (color2normal)
|
||||||
{
|
{
|
||||||
setColorToNormalMap(inputOptions);
|
setColorToNormalMap(inputOptions);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setColorMap(inputOptions);
|
setColorMap(inputOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (noMipmaps)
|
if (noMipmaps)
|
||||||
{
|
{
|
||||||
inputOptions.setMipmapGeneration(false);
|
inputOptions.setMipmapGeneration(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (premultiplyAlpha)
|
if (premultiplyAlpha)
|
||||||
{
|
{
|
||||||
inputOptions.setPremultiplyAlpha(true);
|
inputOptions.setPremultiplyAlpha(true);
|
||||||
inputOptions.setAlphaMode(nvtt::AlphaMode_Premultiplied);
|
inputOptions.setAlphaMode(nvtt::AlphaMode_Premultiplied);
|
||||||
}
|
}
|
||||||
|
|
||||||
inputOptions.setMipmapFilter(mipmapFilter);
|
inputOptions.setMipmapFilter(mipmapFilter);
|
||||||
|
|
||||||
nvtt::CompressionOptions compressionOptions;
|
nvtt::CompressionOptions compressionOptions;
|
||||||
compressionOptions.setFormat(format);
|
compressionOptions.setFormat(format);
|
||||||
|
|
||||||
if (format == nvtt::Format_BC2) {
|
if (format == nvtt::Format_BC2) {
|
||||||
// Dither alpha when using BC2.
|
// Dither alpha when using BC2.
|
||||||
compressionOptions.setQuantization(false, true, false);
|
compressionOptions.setQuantization(false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format == nvtt::Format_RGBA)
|
if (format == nvtt::Format_RGBA)
|
||||||
{
|
{
|
||||||
if (luminance)
|
if (luminance)
|
||||||
{
|
{
|
||||||
compressionOptions.setPixelFormat(8, 0xff, 0, 0, 0);
|
compressionOptions.setPixelFormat(8, 0xff, 0, 0, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// @@ Edit this to choose the desired pixel format:
|
// @@ Edit this to choose the desired pixel format:
|
||||||
// compressionOptions.setPixelType(nvtt::PixelType_Float);
|
// compressionOptions.setPixelType(nvtt::PixelType_Float);
|
||||||
// compressionOptions.setPixelFormat(16, 16, 16, 16);
|
// compressionOptions.setPixelFormat(16, 16, 16, 16);
|
||||||
// compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
// compressionOptions.setPixelType(nvtt::PixelType_UnsignedNorm);
|
||||||
// compressionOptions.setPixelFormat(16, 0, 0, 0);
|
// compressionOptions.setPixelFormat(16, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fast)
|
if (fast)
|
||||||
{
|
{
|
||||||
compressionOptions.setQuality(nvtt::Quality_Fastest);
|
compressionOptions.setQuality(nvtt::Quality_Fastest);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
compressionOptions.setQuality(nvtt::Quality_Normal);
|
compressionOptions.setQuality(nvtt::Quality_Normal);
|
||||||
//compressionOptions.setQuality(nvtt::Quality_Production);
|
//compressionOptions.setQuality(nvtt::Quality_Production);
|
||||||
//compressionOptions.setQuality(nvtt::Quality_Highest);
|
//compressionOptions.setQuality(nvtt::Quality_Highest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bc1n)
|
if (bc1n)
|
||||||
{
|
{
|
||||||
compressionOptions.setColorWeights(1, 1, 0);
|
compressionOptions.setColorWeights(1, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (externalCompressor != NULL)
|
if (externalCompressor != NULL)
|
||||||
{
|
{
|
||||||
compressionOptions.setExternalCompressor(externalCompressor);
|
compressionOptions.setExternalCompressor(externalCompressor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MyErrorHandler errorHandler;
|
MyErrorHandler errorHandler;
|
||||||
MyOutputHandler outputHandler(output);
|
MyOutputHandler outputHandler(output);
|
||||||
if (outputHandler.stream->isError())
|
if (outputHandler.stream->isError())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error opening '%s' for writting\n", output.str());
|
fprintf(stderr, "Error opening '%s' for writting\n", output.str());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nvtt::Context context;
|
nvtt::Context context;
|
||||||
context.enableCudaAcceleration(!nocuda);
|
context.enableCudaAcceleration(!nocuda);
|
||||||
|
|
||||||
printf("CUDA acceleration ");
|
printf("CUDA acceleration ");
|
||||||
if (context.isCudaAccelerationEnabled())
|
if (context.isCudaAccelerationEnabled())
|
||||||
{
|
{
|
||||||
printf("ENABLED\n\n");
|
printf("ENABLED\n\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("DISABLED\n\n");
|
printf("DISABLED\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
outputHandler.setTotal(context.estimateSize(inputOptions, compressionOptions));
|
outputHandler.setTotal(context.estimateSize(inputOptions, compressionOptions));
|
||||||
outputHandler.setDisplayProgress(!silent);
|
outputHandler.setDisplayProgress(!silent);
|
||||||
|
|
||||||
nvtt::OutputOptions outputOptions;
|
nvtt::OutputOptions outputOptions;
|
||||||
//outputOptions.setFileName(output);
|
//outputOptions.setFileName(output);
|
||||||
outputOptions.setOutputHandler(&outputHandler);
|
outputOptions.setOutputHandler(&outputHandler);
|
||||||
outputOptions.setErrorHandler(&errorHandler);
|
outputOptions.setErrorHandler(&errorHandler);
|
||||||
|
|
||||||
if (dds10)
|
if (dds10)
|
||||||
{
|
{
|
||||||
outputOptions.setContainer(nvtt::Container_DDS10);
|
outputOptions.setContainer(nvtt::Container_DDS10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("Press ENTER.\n");
|
// printf("Press ENTER.\n");
|
||||||
// fflush(stdout);
|
// fflush(stdout);
|
||||||
// getchar();
|
// getchar();
|
||||||
|
|
||||||
Timer timer;
|
Timer timer;
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
if (!context.process(inputOptions, compressionOptions, outputOptions))
|
if (!context.process(inputOptions, compressionOptions, outputOptions))
|
||||||
{
|
{
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
printf("\rtime taken: %.3f seconds\n", timer.elapsed());
|
printf("\rtime taken: %.3f seconds\n", timer.elapsed());
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user