Add support for input floating point images. Patch provided by Jim Tilander. See issue 27.
This commit is contained in:
parent
aebcea412c
commit
70267fda15
@ -862,3 +862,20 @@ void FloatImage::applyKernelHorizontal(const PolyphaseKernel & k, int y, int c,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FloatImage* FloatImage::clone() const
|
||||||
|
{
|
||||||
|
FloatImage* copy = new FloatImage();
|
||||||
|
copy->m_width = m_width;
|
||||||
|
copy->m_height = m_height;
|
||||||
|
copy->m_componentNum = m_componentNum;
|
||||||
|
copy->m_count = m_count;
|
||||||
|
|
||||||
|
if(m_mem)
|
||||||
|
{
|
||||||
|
copy->allocate(m_componentNum, m_width, m_height);
|
||||||
|
memcpy(copy->m_mem, m_mem, m_count * sizeof(float));
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -114,6 +114,9 @@ public:
|
|||||||
float sampleLinearMirror(float x, float y, int c) const;
|
float sampleLinearMirror(float x, float y, int c) const;
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
|
FloatImage* clone() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
uint index(uint x, uint y) const;
|
uint index(uint x, uint y) const;
|
||||||
|
@ -115,6 +115,11 @@ namespace nvtt
|
|||||||
m_inputImage = inputOptions.image(idx);
|
m_inputImage = inputOptions.image(idx);
|
||||||
m_fixedImage = NULL;
|
m_fixedImage = NULL;
|
||||||
m_floatImage = NULL;
|
m_floatImage = NULL;
|
||||||
|
|
||||||
|
if (const FloatImage * floatImage = inputOptions.floatImage(idx))
|
||||||
|
{
|
||||||
|
m_floatImage = floatImage->clone();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign and take ownership of given image.
|
// Assign and take ownership of given image.
|
||||||
@ -203,7 +208,7 @@ namespace nvtt
|
|||||||
AutoPtr<FloatImage> m_floatImage;
|
AutoPtr<FloatImage> m_floatImage;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // nvtt namespace
|
||||||
|
|
||||||
|
|
||||||
Compressor::Compressor() : m(*new Compressor::Private())
|
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.width == int(w) && inputImage.height == int(h) && inputImage.depth == int(d))
|
||||||
{
|
{
|
||||||
if (inputImage.data != NULL)
|
if (inputImage.hasValidData())
|
||||||
{
|
{
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
@ -526,7 +531,7 @@ int Compressor::Private::findClosestMipmap(const InputOptions::Private & inputOp
|
|||||||
int idx = f * inputOptions.mipmapCount + m;
|
int idx = f * inputOptions.mipmapCount + m;
|
||||||
const InputOptions::Private::InputImage & inputImage = inputOptions.images[idx];
|
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);
|
int difference = (inputImage.width - w) + (inputImage.height - h) + (inputImage.depth - d);
|
||||||
|
|
||||||
@ -647,7 +652,9 @@ void Compressor::Private::processInputImage(Mipmap & mipmap, const InputOptions:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (inputOptions.inputGamma != inputOptions.outputGamma)
|
if (inputOptions.inputGamma != inputOptions.outputGamma ||
|
||||||
|
inputOptions.colorTransform == ColorTransform_Linear ||
|
||||||
|
inputOptions.colorTransform == ColorTransform_Swizzle)
|
||||||
{
|
{
|
||||||
mipmap.toFloatImage(inputOptions);
|
mipmap.toFloatImage(inputOptions);
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,8 @@ void InputOptions::setTextureLayout(TextureType type, int width, int height, int
|
|||||||
img.mipLevel = mipLevel;
|
img.mipLevel = mipLevel;
|
||||||
img.face = f;
|
img.face = f;
|
||||||
|
|
||||||
img.data = NULL;
|
img.uint8data = NULL;
|
||||||
|
img.floatdata = NULL;
|
||||||
|
|
||||||
w = max(1U, w / 2);
|
w = max(1U, w / 2);
|
||||||
h = max(1U, h / 2);
|
h = max(1U, h / 2);
|
||||||
@ -203,9 +204,47 @@ bool InputOptions::setMipmapData(const void * data, int width, int height, int d
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m.images[idx].data = new nv::Image();
|
switch(m.inputFormat)
|
||||||
m.images[idx].data->allocate(width, height);
|
{
|
||||||
memcpy(m.images[idx].data->pixels(), data, width * height * 4);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -416,7 +455,7 @@ const Image * InputOptions::Private::image(uint face, uint mipmap) const
|
|||||||
nvDebugCheck(image.face == face);
|
nvDebugCheck(image.face == face);
|
||||||
nvDebugCheck(image.mipLevel == mipmap);
|
nvDebugCheck(image.mipLevel == mipmap);
|
||||||
|
|
||||||
return image.data.ptr();
|
return image.uint8data.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Image * InputOptions::Private::image(uint idx) const
|
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];
|
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();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <nvmath/Vector.h>
|
#include <nvmath/Vector.h>
|
||||||
#include <nvmath/Matrix.h>
|
#include <nvmath/Matrix.h>
|
||||||
#include <nvimage/Image.h>
|
#include <nvimage/Image.h>
|
||||||
|
#include <nvimage/FloatImage.h>
|
||||||
#include "nvtt.h"
|
#include "nvtt.h"
|
||||||
|
|
||||||
namespace nvtt
|
namespace nvtt
|
||||||
@ -94,6 +95,8 @@ namespace nvtt
|
|||||||
const nv::Image * image(uint face, uint mipmap) const;
|
const nv::Image * image(uint face, uint mipmap) const;
|
||||||
const nv::Image * image(uint idx) const;
|
const nv::Image * image(uint idx) const;
|
||||||
|
|
||||||
|
const nv::FloatImage * floatImage(uint idx) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Internal image structure.
|
// Internal image structure.
|
||||||
@ -108,7 +111,8 @@ namespace nvtt
|
|||||||
int height;
|
int height;
|
||||||
int depth;
|
int depth;
|
||||||
|
|
||||||
nv::AutoPtr<nv::Image> data;
|
nv::AutoPtr<nv::Image> uint8data;
|
||||||
|
nv::AutoPtr<nv::FloatImage> floatdata;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // nvtt namespace
|
} // nvtt namespace
|
||||||
|
@ -140,8 +140,7 @@ namespace nvtt
|
|||||||
enum InputFormat
|
enum InputFormat
|
||||||
{
|
{
|
||||||
InputFormat_BGRA_8UB,
|
InputFormat_BGRA_8UB,
|
||||||
// InputFormat_RGBE_8UB,
|
InputFormat_RGBA_32F,
|
||||||
// InputFormat_BGRA_32F,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Mipmap downsampling filters.
|
/// Mipmap downsampling filters.
|
||||||
|
Loading…
Reference in New Issue
Block a user