Add support for linear and swizzle transforms. Fixes issue 4.

This commit is contained in:
castano
2008-05-06 23:21:39 +00:00
parent 94c3fa75a8
commit 48f61dbfc0
5 changed files with 68 additions and 6 deletions

View File

@ -4,6 +4,7 @@
#include <nvcore/Ptr.h>
#include <nvmath/Color.h>
#include <nvmath/Matrix.h>
#include "FloatImage.h"
#include "Filter.h"
@ -240,6 +241,52 @@ void FloatImage::exponentiate(uint base_component, uint num, float power)
}
}
/// Apply linear transform.
void FloatImage::transform(uint base_component, const Matrix & m)
{
nvCheck(base_component + 4 <= m_componentNum);
const uint size = m_width * m_height;
float * r = this->channel(base_component + 0);
float * g = this->channel(base_component + 1);
float * b = this->channel(base_component + 2);
float * a = this->channel(base_component + 3);
for (uint i = 0; i < size; i++)
{
Vector4 color = nv::transform(m, Vector4(*r, *g, *b, *a));
*r++ = color.x();
*g++ = color.y();
*b++ = color.z();
*a++ = color.w();
}
}
void FloatImage::swizzle(uint base_component, uint r, uint g, uint b, uint a)
{
nvCheck(base_component + 4 <= m_componentNum);
const uint size = m_width * m_height;
float * c[4];
c[0] = this->channel(base_component + 0);
c[1] = this->channel(base_component + 1);
c[2] = this->channel(base_component + 2);
c[3] = this->channel(base_component + 3);
for (uint i = 0; i < size; i++)
{
float tmp[4] = { c[r], c[g], c[b], c[a] };
*r++ = tmp[0];
*g++ = tmp[1];
*b++ = tmp[2];
*a++ = tmp[3];
}
}
float FloatImage::sampleNearest(const float x, const float y, const int c, const WrapMode wm) const
{
if( wm == WrapMode_Clamp ) return sampleNearestClamp(x, y, c);