Create default output handle on setFileName to avoid modifying const argument.
Fix ref counting errors in TexImage. Format TODO messages.
This commit is contained in:
parent
78d65e8368
commit
c1f9c4df42
@ -62,8 +62,11 @@ namespace nvtt
|
||||
|
||||
uint getBitCount() const
|
||||
{
|
||||
if (bitcount != 0) return bitcount;
|
||||
else return rsize + gsize + bsize + asize;
|
||||
if (format == Format_RGBA) {
|
||||
if (bitcount != 0) return bitcount;
|
||||
else return rsize + gsize + bsize + asize;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -311,8 +311,7 @@ int Compressor::estimateSize(int w, int h, int d, const CompressionOptions & com
|
||||
|
||||
const Format format = co.format;
|
||||
|
||||
uint bitCount = co.bitcount;
|
||||
if (format == Format_RGBA && bitCount == 0) bitCount = co.rsize + co.gsize + co.bsize + co.asize;
|
||||
uint bitCount = co.getBitCount();
|
||||
|
||||
return computeImageSize(w, h, d, bitCount, format);
|
||||
}
|
||||
@ -325,7 +324,6 @@ TexImage Compressor::createTexImage() const
|
||||
return *new TexImage();
|
||||
}
|
||||
|
||||
|
||||
bool Compressor::outputHeader(const TexImage & tex, int mipmapCount, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
{
|
||||
m.outputHeader(tex, mipmapCount, compressionOptions.m, outputOptions.m);
|
||||
@ -336,7 +334,6 @@ bool Compressor::compress(const TexImage & tex, const CompressionOptions & compr
|
||||
// @@ Convert to fixed point and call compress2D for each face.
|
||||
}
|
||||
|
||||
/// Estimate the size of compressing the given texture.
|
||||
int Compressor::estimateSize(const TexImage & tex, const CompressionOptions & compressionOptions) const
|
||||
{
|
||||
const uint w = tex.width();
|
||||
@ -348,8 +345,6 @@ int Compressor::estimateSize(const TexImage & tex, const CompressionOptions & co
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Compressor::Private::compress(const InputOptions::Private & inputOptions, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const
|
||||
{
|
||||
// Make sure enums match.
|
||||
@ -358,12 +353,14 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
||||
nvStaticCheck(FloatImage::WrapMode_Repeat == (FloatImage::WrapMode)WrapMode_Repeat);
|
||||
|
||||
// Get output handler.
|
||||
if (!outputOptions.openFile())
|
||||
if (!outputOptions.hasValidOutputHandler())
|
||||
{
|
||||
if (outputOptions.errorHandler) outputOptions.errorHandler->error(Error_FileOpen);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#pragma message(NV_FILE_LINE "TODO: If DefaultOutputHandler, then seek begining of the file.")
|
||||
|
||||
inputOptions.computeTargetExtents();
|
||||
|
||||
// Output DDS header.
|
||||
@ -380,8 +377,6 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
||||
}
|
||||
}
|
||||
|
||||
outputOptions.closeFile();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -630,7 +625,7 @@ bool Compressor::Private::outputHeader(const TexImage & tex, int mipmapCount, co
|
||||
{
|
||||
if (tex.width() <= 0 || tex.height() <= 0 || tex.depth() <= 0 || mipmapCount <= 0)
|
||||
{
|
||||
#pragma message(NV_FILE_LINE "Set invalid argument error")
|
||||
#pragma message(NV_FILE_LINE "TODO: Set invalid argument error.")
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,9 @@ OutputOptions::OutputOptions() : m(*new OutputOptions::Private())
|
||||
|
||||
OutputOptions::~OutputOptions()
|
||||
{
|
||||
// Cleanup output handler.
|
||||
setOutputHandler(NULL);
|
||||
|
||||
delete &m;
|
||||
}
|
||||
|
||||
@ -50,14 +53,24 @@ void OutputOptions::reset()
|
||||
/// Set output file name.
|
||||
void OutputOptions::setFileName(const char * fileName)
|
||||
{
|
||||
m.fileName = fileName;
|
||||
m.fileName = fileName; // @@ Do we need to record filename?
|
||||
m.outputHandler = NULL;
|
||||
|
||||
DefaultOutputHandler * oh = new DefaultOutputHandler(fileName);
|
||||
if (!oh->stream.isError())
|
||||
{
|
||||
m.outputHandler = oh;
|
||||
}
|
||||
}
|
||||
|
||||
/// Set output handler.
|
||||
void OutputOptions::setOutputHandler(OutputHandler * outputHandler)
|
||||
{
|
||||
m.fileName.reset();
|
||||
if (!m.fileName.isNull())
|
||||
{
|
||||
delete m.outputHandler;
|
||||
m.fileName.reset();
|
||||
}
|
||||
m.outputHandler = outputHandler;
|
||||
}
|
||||
|
||||
@ -80,30 +93,13 @@ void OutputOptions::setContainer(Container container)
|
||||
}
|
||||
|
||||
|
||||
bool OutputOptions::Private::openFile() const
|
||||
bool OutputOptions::Private::hasValidOutputHandler() const
|
||||
{
|
||||
if (!fileName.isNull())
|
||||
{
|
||||
nvCheck(outputHandler == NULL);
|
||||
|
||||
DefaultOutputHandler * oh = new DefaultOutputHandler(fileName.str());
|
||||
if (oh->stream.isError())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
outputHandler = oh;
|
||||
return outputHandler != NULL;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OutputOptions::Private::closeFile() const
|
||||
{
|
||||
if (!fileName.isNull())
|
||||
{
|
||||
delete outputHandler;
|
||||
outputHandler = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ namespace nvtt
|
||||
//return !stream.isError();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
nv::StdOutputStream stream;
|
||||
};
|
||||
|
||||
@ -61,13 +61,12 @@ namespace nvtt
|
||||
{
|
||||
nv::Path fileName;
|
||||
|
||||
mutable OutputHandler * outputHandler;
|
||||
OutputHandler * outputHandler;
|
||||
ErrorHandler * errorHandler;
|
||||
bool outputHeader;
|
||||
Container container;
|
||||
|
||||
bool openFile() const;
|
||||
void closeFile() const;
|
||||
bool hasValidOutputHandler() const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -61,7 +61,8 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
#pragma message(NV_FILE_LINE "Move these functions to a common location")
|
||||
#pragma message(NV_FILE_LINE "TODO: Move these functions to a common location.")
|
||||
|
||||
static int blockSize(Format format)
|
||||
{
|
||||
if (format == Format_DXT1 || format == Format_DXT1a || format == Format_DXT1n) {
|
||||
@ -107,20 +108,20 @@ TexImage::TexImage() : m(new TexImage::Private())
|
||||
|
||||
TexImage::TexImage(const TexImage & tex) : m(tex.m)
|
||||
{
|
||||
m->addRef();
|
||||
if (m != NULL) m->addRef();
|
||||
}
|
||||
|
||||
TexImage::~TexImage()
|
||||
{
|
||||
m->release();
|
||||
if (m != NULL) m->release();
|
||||
m = NULL;
|
||||
}
|
||||
|
||||
void TexImage::operator=(const TexImage & tex)
|
||||
{
|
||||
tex.m->addRef();
|
||||
if (tex.m != NULL) tex.m->addRef();
|
||||
if (m != NULL) m->release();
|
||||
m = tex.m;
|
||||
m->release();
|
||||
}
|
||||
|
||||
void TexImage::detach()
|
||||
@ -141,6 +142,12 @@ void TexImage::setTextureType(TextureType type)
|
||||
|
||||
m->type = type;
|
||||
|
||||
// Free images. @@ Use AutoPtr?
|
||||
foreach (i, m->imageArray)
|
||||
{
|
||||
delete m->imageArray[i];
|
||||
}
|
||||
|
||||
if (type == TextureType_2D)
|
||||
{
|
||||
// @@ Free images.
|
||||
@ -237,7 +244,7 @@ int TexImage::countMipmaps() const
|
||||
|
||||
bool TexImage::load(const char * fileName)
|
||||
{
|
||||
#pragma message(NV_FILE_LINE "Add support for DDS textures in TexImage::load")
|
||||
#pragma message(NV_FILE_LINE "TODO: Add support for DDS textures in TexImage::load().")
|
||||
|
||||
AutoPtr<FloatImage> img(ImageIO::loadFloat(fileName));
|
||||
|
||||
@ -268,7 +275,7 @@ bool TexImage::save(const char * fileName) const
|
||||
}
|
||||
}
|
||||
|
||||
bool TexImage::setImage2D(InputFormat format, int w, int h, int idx, const void * restrict data)
|
||||
bool TexImage::setImage2D(nvtt::InputFormat format, int w, int h, int idx, const void * restrict data)
|
||||
{
|
||||
if (idx < 0 || uint(idx) >= m->imageArray.count())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user