Add support for input floating point images. Patch provided by Jim Tilander. See issue 27.

This commit is contained in:
castano
2008-05-15 06:18:24 +00:00
parent aebcea412c
commit 70267fda15
6 changed files with 91 additions and 13 deletions

View File

@ -115,6 +115,11 @@ namespace nvtt
m_inputImage = inputOptions.image(idx);
m_fixedImage = NULL;
m_floatImage = NULL;
if (const FloatImage * floatImage = inputOptions.floatImage(idx))
{
m_floatImage = floatImage->clone();
}
}
// Assign and take ownership of given image.
@ -203,7 +208,7 @@ namespace nvtt
AutoPtr<FloatImage> m_floatImage;
};
}
} // nvtt namespace
Compressor::Compressor() : m(*new Compressor::Private())
@ -502,7 +507,7 @@ int Compressor::Private::findExactMipmap(const InputOptions::Private & inputOpti
if (inputImage.width == int(w) && inputImage.height == int(h) && inputImage.depth == int(d))
{
if (inputImage.data != NULL)
if (inputImage.hasValidData())
{
return idx;
}
@ -526,7 +531,7 @@ int Compressor::Private::findClosestMipmap(const InputOptions::Private & inputOp
int idx = f * inputOptions.mipmapCount + m;
const InputOptions::Private::InputImage & inputImage = inputOptions.images[idx];
if (inputImage.data != NULL)
if (inputImage.hasValidData())
{
int difference = (inputImage.width - w) + (inputImage.height - h) + (inputImage.depth - d);
@ -647,7 +652,9 @@ void Compressor::Private::processInputImage(Mipmap & mipmap, const InputOptions:
}
else
{
if (inputOptions.inputGamma != inputOptions.outputGamma)
if (inputOptions.inputGamma != inputOptions.outputGamma ||
inputOptions.colorTransform == ColorTransform_Linear ||
inputOptions.colorTransform == ColorTransform_Swizzle)
{
mipmap.toFloatImage(inputOptions);
}

View File

@ -165,7 +165,8 @@ void InputOptions::setTextureLayout(TextureType type, int width, int height, int
img.mipLevel = mipLevel;
img.face = f;
img.data = NULL;
img.uint8data = NULL;
img.floatdata = NULL;
w = max(1U, w / 2);
h = max(1U, h / 2);
@ -203,9 +204,47 @@ bool InputOptions::setMipmapData(const void * data, int width, int height, int d
return false;
}
m.images[idx].data = new nv::Image();
m.images[idx].data->allocate(width, height);
memcpy(m.images[idx].data->pixels(), data, width * height * 4);
switch(m.inputFormat)
{
case InputFormat_BGRA_8UB:
if (Image * image = new nv::Image())
{
image->allocate(width, height);
memcpy(image->pixels(), data, width * height * 4);
m.images[idx].data = image;
}
else
{
// @@ Out of memory error.
return false;
}
break;
case InputFormat_RGBA_32F:
if (FloatImage * image = new nv::FloatImage())
{
const float * floatData = (const float *)data;
image->allocate(4, width, height);
for (int c = 0; c < 4; c++)
{
float * channel = image->channel(c);
for (int i = 0; i < width * height; i++)
{
channel[i] = floatData[i*4 + c];
}
}
m.images[idx].data = image;
}
else
{
// @@ Out of memory error.
return false;
}
break;
default:
return false;
}
return true;
}
@ -416,7 +455,7 @@ const Image * InputOptions::Private::image(uint face, uint mipmap) const
nvDebugCheck(image.face == face);
nvDebugCheck(image.mipLevel == mipmap);
return image.data.ptr();
return image.uint8data.ptr();
}
const Image * InputOptions::Private::image(uint idx) const
@ -425,5 +464,14 @@ const Image * InputOptions::Private::image(uint idx) const
const InputImage & image = this->images[idx];
return image.data.ptr();
return image.uint8data.ptr();
}
const FloatImage * InputOptions::Private::image(uint idx) const
{
nvDebugCheck(idx < faceCount * mipmapCount);
const InputImage & image = this->images[idx];
return image.floatdata.ptr();
}

View File

@ -28,6 +28,7 @@
#include <nvmath/Vector.h>
#include <nvmath/Matrix.h>
#include <nvimage/Image.h>
#include <nvimage/FloatImage.h>
#include "nvtt.h"
namespace nvtt
@ -94,6 +95,8 @@ namespace nvtt
const nv::Image * image(uint face, uint mipmap) const;
const nv::Image * image(uint idx) const;
const nv::FloatImage * floatImage(uint idx) const;
};
// Internal image structure.
@ -108,7 +111,8 @@ namespace nvtt
int height;
int depth;
nv::AutoPtr<nv::Image> data;
nv::AutoPtr<nv::Image> uint8data;
nv::AutoPtr<nv::FloatImage> floatdata;
};
} // nvtt namespace

View File

@ -140,8 +140,7 @@ namespace nvtt
enum InputFormat
{
InputFormat_BGRA_8UB,
// InputFormat_RGBE_8UB,
// InputFormat_BGRA_32F,
InputFormat_RGBA_32F,
};
/// Mipmap downsampling filters.