Some cleanup.
This commit is contained in:
@ -93,6 +93,69 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mipmap could be:
|
||||||
|
// - a pointer to an input image.
|
||||||
|
// - a fixed point image.
|
||||||
|
// - a floating point image.
|
||||||
|
struct Mipmap
|
||||||
|
{
|
||||||
|
Mipmap() : m_inputImage(NULL) {}
|
||||||
|
~Mipmap() {}
|
||||||
|
|
||||||
|
// Reference input image.
|
||||||
|
void set(const InputOptions::Private & inputOptions, uint f, uint m)
|
||||||
|
{
|
||||||
|
m_inputImage = inputOptions.image(f, m);
|
||||||
|
m_fixedImage = NULL;
|
||||||
|
m_floatImage = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign and take ownership of given image.
|
||||||
|
void set(FloatImage * image)
|
||||||
|
{
|
||||||
|
m_inputImage = NULL;
|
||||||
|
m_fixedImage = NULL;
|
||||||
|
m_floatImage = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign and take ownership of given image.
|
||||||
|
void set(Image * image)
|
||||||
|
{
|
||||||
|
m_inputImage = NULL;
|
||||||
|
m_fixedImage = image;
|
||||||
|
m_floatImage = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const FloatImage * asFloatImage() const
|
||||||
|
{
|
||||||
|
return m_floatImage.ptr();
|
||||||
|
}
|
||||||
|
|
||||||
|
const Image * asFixedImage() const
|
||||||
|
{
|
||||||
|
if (m_inputImage != NULL)
|
||||||
|
{
|
||||||
|
return m_inputImage;
|
||||||
|
}
|
||||||
|
return m_fixedImage.ptr();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*void toFixed(const InputOptions::Private & inputOptions)
|
||||||
|
{
|
||||||
|
if (m_floatImage != NULL)
|
||||||
|
{
|
||||||
|
// Convert to fixed.
|
||||||
|
m_fixedImage = toFixedImage(m_floatImage.ptr(), inputOptions);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
private:
|
||||||
|
const Image * m_inputImage;
|
||||||
|
AutoPtr<Image> m_fixedImage;
|
||||||
|
AutoPtr<FloatImage> m_floatImage;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
@ -162,17 +225,17 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
|||||||
inputOptions.computeTargetExtents();
|
inputOptions.computeTargetExtents();
|
||||||
|
|
||||||
// Output DDS header.
|
// Output DDS header.
|
||||||
if (!outputHeader(inputOptions, outputOptions, compressionOptions))
|
if (!outputHeader(inputOptions, compressionOptions, outputOptions))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint f = 0; f < inputOptions.faceCount; f++)
|
for (uint f = 0; f < inputOptions.faceCount; f++)
|
||||||
{
|
{
|
||||||
/*if (!compressMipmaps(f, inputOptions, outputOptions, compressionOptions))
|
if (!compressMipmaps(f, inputOptions, compressionOptions, outputOptions))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outputOptions.closeFile();
|
outputOptions.closeFile();
|
||||||
@ -182,7 +245,7 @@ bool Compressor::Private::compress(const InputOptions::Private & inputOptions, c
|
|||||||
|
|
||||||
|
|
||||||
// Output DDS header.
|
// Output DDS header.
|
||||||
bool Compressor::Private::outputHeader(const InputOptions::Private & inputOptions, const OutputOptions::Private & outputOptions, const CompressionOptions::Private & compressionOptions) const
|
bool Compressor::Private::outputHeader(const InputOptions::Private & inputOptions, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const
|
||||||
{
|
{
|
||||||
// Output DDS header.
|
// Output DDS header.
|
||||||
if (outputOptions.outputHandler == NULL || !outputOptions.outputHeader)
|
if (outputOptions.outputHandler == NULL || !outputOptions.outputHeader)
|
||||||
@ -262,7 +325,64 @@ bool Compressor::Private::outputHeader(const InputOptions::Private & inputOption
|
|||||||
return writeSucceed;
|
return writeSucceed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @@ compressMipmaps...
|
|
||||||
|
bool Compressor::Private::compressMipmaps(uint f, const InputOptions::Private & inputOptions, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const
|
||||||
|
{
|
||||||
|
uint w = inputOptions.targetWidth;
|
||||||
|
uint h = inputOptions.targetHeight;
|
||||||
|
uint d = inputOptions.targetDepth;
|
||||||
|
/*
|
||||||
|
int inputImageIdx = findMipmap(inputOptions, f, 0, w, h, d);
|
||||||
|
if (inputImageIdx == -1)
|
||||||
|
{
|
||||||
|
// First mipmap missing.
|
||||||
|
if (outputOptions.errorHandler != NULL) outputOptions.errorHandler->error(Error_InvalidInput);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImagePair pair;
|
||||||
|
*/
|
||||||
|
|
||||||
|
Mipmap mipmap;
|
||||||
|
// Mipmap could be:
|
||||||
|
// - a pointer to an input image.
|
||||||
|
// - a fixed point image.
|
||||||
|
// - a floating point image.
|
||||||
|
|
||||||
|
const uint mipmapCount = inputOptions.realMipmapCount();
|
||||||
|
nvDebugCheck(mipmapCount > 0);
|
||||||
|
|
||||||
|
for (uint m = 0; m < mipmapCount; m++)
|
||||||
|
{
|
||||||
|
if (outputOptions.outputHandler)
|
||||||
|
{
|
||||||
|
int size = computeImageSize(w, h, d, compressionOptions.bitcount, compressionOptions.format);
|
||||||
|
outputOptions.outputHandler->mipmap(size, w, h, d, f, m);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
inputImageIdx = findImage(inputOptions, f, w, h, d, inputImageIdx, &pair);
|
||||||
|
|
||||||
|
// @@ Where to do the color transform?
|
||||||
|
// - Color transform may not be linear, so we cannot do before computing mipmaps.
|
||||||
|
// - Should be done in linear space, that is, after gamma correction.
|
||||||
|
|
||||||
|
|
||||||
|
pair.toFixed(inputOptions);
|
||||||
|
|
||||||
|
// @@ Quantization should be done in compressMipmap! @@ It should not modify the input image!!!
|
||||||
|
quantize(pair.fixedImage(), compressionOptions);
|
||||||
|
|
||||||
|
compressMipmap(pair.fixedImage(), outputOptions, compressionOptions);
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Compute extents of next mipmap:
|
||||||
|
w = max(1U, w / 2);
|
||||||
|
h = max(1U, h / 2);
|
||||||
|
d = max(1U, d / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
@ -546,60 +666,9 @@ static int findImage(const InputOptions::Private & inputOptions, uint f, uint w,
|
|||||||
return bestIdx; // @@ ???
|
return bestIdx; // @@ ???
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool compressMipmaps(uint f, const InputOptions::Private & inputOptions, const OutputOptions::Private & outputOptions, const CompressionOptions::Private & compressionOptions)
|
|
||||||
{
|
|
||||||
uint w = inputOptions.targetWidth;
|
|
||||||
uint h = inputOptions.targetHeight;
|
|
||||||
uint d = inputOptions.targetDepth;
|
|
||||||
|
|
||||||
int inputImageIdx = findMipmap(inputOptions, f, 0, w, h, d);
|
|
||||||
if (inputImageIdx == -1)
|
|
||||||
{
|
|
||||||
// First mipmap missing.
|
|
||||||
if (outputOptions.errorHandler != NULL) outputOptions.errorHandler->error(Error_InvalidInput);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImagePair pair;
|
|
||||||
|
|
||||||
const uint mipmapCount = inputOptions.realMipmapCount();
|
|
||||||
nvDebugCheck(mipmapCount > 0);
|
|
||||||
|
|
||||||
for (uint m = 0; m < mipmapCount; m++)
|
|
||||||
{
|
|
||||||
if (outputOptions.outputHandler)
|
|
||||||
{
|
|
||||||
int size = computeImageSize(w, h, compressionOptions.bitcount, compressionOptions.format);
|
|
||||||
outputOptions.outputHandler->mipmap(size, w, h, d, f, m);
|
|
||||||
}
|
|
||||||
|
|
||||||
inputImageIdx = findImage(inputOptions, f, w, h, d, inputImageIdx, &pair);
|
|
||||||
|
|
||||||
// @@ Where to do the color transform?
|
|
||||||
// - Color transform may not be linear, so we cannot do before computing mipmaps.
|
|
||||||
// - Should be done in linear space, that is, after gamma correction.
|
|
||||||
|
|
||||||
|
|
||||||
pair.toFixed(inputOptions);
|
|
||||||
|
|
||||||
// @@ Quantization should be done in compressMipmap! @@ It should not modify the input image!!!
|
|
||||||
quantize(pair.fixedImage(), compressionOptions);
|
|
||||||
|
|
||||||
compressMipmap(pair.fixedImage(), outputOptions, compressionOptions);
|
|
||||||
|
|
||||||
// Compute extents of next mipmap:
|
|
||||||
w = max(1U, w / 2);
|
|
||||||
h = max(1U, h / 2);
|
|
||||||
d = max(1U, d / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
||||||
bool Compressor::Private::compressMipmap(const Image * image, const OutputOptions::Private & outputOptions, const CompressionOptions::Private & compressionOptions) const
|
bool Compressor::Private::compressMipmap(const Image * image, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(image != NULL);
|
nvDebugCheck(image != NULL);
|
||||||
|
|
||||||
|
@ -43,8 +43,9 @@ namespace nvtt
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool outputHeader(const InputOptions::Private & inputOptions, const OutputOptions::Private & outputOptions, const CompressionOptions::Private & compressionOptions) const;
|
bool outputHeader(const InputOptions::Private & inputOptions, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const;
|
||||||
bool compressMipmap(const nv::Image * image, const OutputOptions::Private & outputOptions, const CompressionOptions::Private & compressionOptions) const;
|
bool compressMipmaps(uint f, const InputOptions::Private & inputOptions, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const;
|
||||||
|
bool compressMipmap(const nv::Image * image, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -144,7 +144,7 @@ void InputOptions::setTextureLayout(TextureType type, int width, int height, int
|
|||||||
m.faceCount = (type == TextureType_Cube) ? 6 : 1;
|
m.faceCount = (type == TextureType_Cube) ? 6 : 1;
|
||||||
m.imageCount = m.mipmapCount * m.faceCount;
|
m.imageCount = m.mipmapCount * m.faceCount;
|
||||||
|
|
||||||
m.images = new Private::Image[m.imageCount];
|
m.images = new Private::InputImage[m.imageCount];
|
||||||
|
|
||||||
for(uint f = 0; f < m.faceCount; f++)
|
for(uint f = 0; f < m.faceCount; f++)
|
||||||
{
|
{
|
||||||
@ -154,7 +154,7 @@ void InputOptions::setTextureLayout(TextureType type, int width, int height, int
|
|||||||
|
|
||||||
for (uint mipLevel = 0; mipLevel < m.mipmapCount; mipLevel++)
|
for (uint mipLevel = 0; mipLevel < m.mipmapCount; mipLevel++)
|
||||||
{
|
{
|
||||||
Private::Image & img = m.images[f * m.mipmapCount + mipLevel];
|
Private::InputImage & img = m.images[f * m.mipmapCount + mipLevel];
|
||||||
img.width = w;
|
img.width = w;
|
||||||
img.height = h;
|
img.height = h;
|
||||||
img.depth = d;
|
img.depth = d;
|
||||||
@ -381,3 +381,14 @@ int InputOptions::Private::realMipmapCount() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Image * InputOptions::Private::image(uint face, uint mipmap) const
|
||||||
|
{
|
||||||
|
nvDebugCheck(face < faceCount);
|
||||||
|
nvDebugCheck(mipmap < mipmapCount);
|
||||||
|
|
||||||
|
const InputImage & image = this->images[face * mipmapCount + mipmap];
|
||||||
|
nvDebugCheck(image.face == face);
|
||||||
|
nvDebugCheck(image.mipLevel == mipmap);
|
||||||
|
|
||||||
|
return image.data.ptr();
|
||||||
|
}
|
||||||
|
@ -46,8 +46,8 @@ namespace nvtt
|
|||||||
uint mipmapCount;
|
uint mipmapCount;
|
||||||
uint imageCount;
|
uint imageCount;
|
||||||
|
|
||||||
struct Image;
|
struct InputImage;
|
||||||
Image * images;
|
InputImage * images;
|
||||||
|
|
||||||
// Gamma conversion.
|
// Gamma conversion.
|
||||||
float inputGamma;
|
float inputGamma;
|
||||||
@ -88,12 +88,14 @@ namespace nvtt
|
|||||||
|
|
||||||
int realMipmapCount() const;
|
int realMipmapCount() const;
|
||||||
|
|
||||||
|
const nv::Image * image(uint face, uint mipmap) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Internal image structure.
|
// Internal image structure.
|
||||||
struct InputOptions::Private::Image
|
struct InputOptions::Private::InputImage
|
||||||
{
|
{
|
||||||
Image() {}
|
InputImage() {}
|
||||||
|
|
||||||
int mipLevel;
|
int mipLevel;
|
||||||
int face;
|
int face;
|
||||||
|
@ -410,7 +410,7 @@ static void quantize(Image * img, const CompressionOptions::Private & compressio
|
|||||||
// Process the input, convert to normal map, normalize, or convert to linear space.
|
// Process the input, convert to normal map, normalize, or convert to linear space.
|
||||||
static FloatImage * processInput(const InputOptions::Private & inputOptions, int idx)
|
static FloatImage * processInput(const InputOptions::Private & inputOptions, int idx)
|
||||||
{
|
{
|
||||||
const InputOptions::Private::Image & mipmap = inputOptions.images[idx];
|
const InputOptions::Private::InputImage & mipmap = inputOptions.images[idx];
|
||||||
|
|
||||||
if (inputOptions.convertToNormalMap)
|
if (inputOptions.convertToNormalMap)
|
||||||
{
|
{
|
||||||
@ -499,7 +499,7 @@ static int findMipmap(const InputOptions::Private & inputOptions, uint f, int fi
|
|||||||
for (int m = firstMipmap; m < int(inputOptions.mipmapCount); m++)
|
for (int m = firstMipmap; m < int(inputOptions.mipmapCount); m++)
|
||||||
{
|
{
|
||||||
int idx = f * inputOptions.mipmapCount + m;
|
int idx = f * inputOptions.mipmapCount + m;
|
||||||
const InputOptions::Private::Image & mipmap = inputOptions.images[idx];
|
const InputOptions::Private::InputImage & mipmap = inputOptions.images[idx];
|
||||||
|
|
||||||
if (mipmap.width >= int(w) && mipmap.height >= int(h) && mipmap.depth >= int(d))
|
if (mipmap.width >= int(w) && mipmap.height >= int(h) && mipmap.depth >= int(d))
|
||||||
{
|
{
|
||||||
@ -527,7 +527,7 @@ static int findImage(const InputOptions::Private & inputOptions, uint f, uint w,
|
|||||||
nvDebugCheck(pair != NULL);
|
nvDebugCheck(pair != NULL);
|
||||||
|
|
||||||
int bestIdx = findMipmap(inputOptions, f, inputImageIdx, w, h, d);
|
int bestIdx = findMipmap(inputOptions, f, inputImageIdx, w, h, d);
|
||||||
const InputOptions::Private::Image & mipmap = inputOptions.images[bestIdx];
|
const InputOptions::Private::InputImage & mipmap = inputOptions.images[bestIdx];
|
||||||
|
|
||||||
if (mipmap.width == w && mipmap.height == h && mipmap.depth == d)
|
if (mipmap.width == w && mipmap.height == h && mipmap.depth == d)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user