fix blend, add setborder and fill methods.
This commit is contained in:
parent
c59a2e0a4b
commit
be12367910
|
@ -590,7 +590,7 @@ void TexImage::scaleBias(int channel, float scale, float bias)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TexImage::blend(float red, float green, float blue, float alpha)
|
void TexImage::blend(float red, float green, float blue, float alpha, float t)
|
||||||
{
|
{
|
||||||
detach();
|
detach();
|
||||||
|
|
||||||
|
@ -600,15 +600,17 @@ void TexImage::blend(float red, float green, float blue, float alpha)
|
||||||
if (img == NULL) continue;
|
if (img == NULL) continue;
|
||||||
|
|
||||||
float * restrict r = img->channel(0);
|
float * restrict r = img->channel(0);
|
||||||
float * restrict g = img->channel(0);
|
float * restrict g = img->channel(1);
|
||||||
float * restrict b = img->channel(0);
|
float * restrict b = img->channel(2);
|
||||||
|
float * restrict a = img->channel(3);
|
||||||
|
|
||||||
const int count = img->width() * img->height();
|
const int count = img->width() * img->height();
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
r[i] = lerp(r[i], red, alpha);
|
r[i] = lerp(r[i], red, t);
|
||||||
g[i] = lerp(g[i], green, alpha);
|
g[i] = lerp(g[i], green, t);
|
||||||
b[i] = lerp(b[i], blue, alpha);
|
b[i] = lerp(b[i], blue, t);
|
||||||
|
a[i] = lerp(a[i], alpha, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -623,9 +625,9 @@ void TexImage::premultiplyAlpha()
|
||||||
if (img == NULL) continue;
|
if (img == NULL) continue;
|
||||||
|
|
||||||
float * restrict r = img->channel(0);
|
float * restrict r = img->channel(0);
|
||||||
float * restrict g = img->channel(0);
|
float * restrict g = img->channel(1);
|
||||||
float * restrict b = img->channel(0);
|
float * restrict b = img->channel(2);
|
||||||
float * restrict a = img->channel(0);
|
float * restrict a = img->channel(3);
|
||||||
|
|
||||||
const int count = img->width() * img->height();
|
const int count = img->width() * img->height();
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
|
@ -654,9 +656,9 @@ void TexImage::toGreyScale(float redScale, float greenScale, float blueScale, fl
|
||||||
alphaScale /= sum;
|
alphaScale /= sum;
|
||||||
|
|
||||||
float * restrict r = img->channel(0);
|
float * restrict r = img->channel(0);
|
||||||
float * restrict g = img->channel(0);
|
float * restrict g = img->channel(1);
|
||||||
float * restrict b = img->channel(0);
|
float * restrict b = img->channel(2);
|
||||||
float * restrict a = img->channel(0);
|
float * restrict a = img->channel(3);
|
||||||
|
|
||||||
const int count = img->width() * img->height();
|
const int count = img->width() * img->height();
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
|
@ -667,6 +669,73 @@ void TexImage::toGreyScale(float redScale, float greenScale, float blueScale, fl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw colored border.
|
||||||
|
void TexImage::setBorder(float r, float g, float b, float a)
|
||||||
|
{
|
||||||
|
detach();
|
||||||
|
|
||||||
|
foreach (i, m->imageArray)
|
||||||
|
{
|
||||||
|
FloatImage * img = m->imageArray[i];
|
||||||
|
if (img == NULL) continue;
|
||||||
|
|
||||||
|
const int w = img->width();
|
||||||
|
const int h = img->height();
|
||||||
|
|
||||||
|
for (int i = 0; i < w; i++)
|
||||||
|
{
|
||||||
|
img->setPixel(r, i, 0, 0);
|
||||||
|
img->setPixel(g, i, 0, 1);
|
||||||
|
img->setPixel(b, i, 0, 2);
|
||||||
|
img->setPixel(a, i, 0, 3);
|
||||||
|
|
||||||
|
img->setPixel(r, i, h-1, 0);
|
||||||
|
img->setPixel(g, i, h-1, 1);
|
||||||
|
img->setPixel(b, i, h-1, 2);
|
||||||
|
img->setPixel(a, i, h-1, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < h; i++)
|
||||||
|
{
|
||||||
|
img->setPixel(r, 0, i, 0);
|
||||||
|
img->setPixel(g, 0, i, 1);
|
||||||
|
img->setPixel(b, 0, i, 2);
|
||||||
|
img->setPixel(a, 0, i, 3);
|
||||||
|
|
||||||
|
img->setPixel(r, w-1, i, 0);
|
||||||
|
img->setPixel(g, w-1, i, 1);
|
||||||
|
img->setPixel(b, w-1, i, 2);
|
||||||
|
img->setPixel(a, w-1, i, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill image with the given color.
|
||||||
|
void TexImage::fill(float red, float green, float blue, float alpha)
|
||||||
|
{
|
||||||
|
detach();
|
||||||
|
|
||||||
|
foreach (i, m->imageArray)
|
||||||
|
{
|
||||||
|
FloatImage * img = m->imageArray[i];
|
||||||
|
if (img == NULL) continue;
|
||||||
|
|
||||||
|
float * restrict r = img->channel(0);
|
||||||
|
float * restrict g = img->channel(1);
|
||||||
|
float * restrict b = img->channel(2);
|
||||||
|
float * restrict a = img->channel(3);
|
||||||
|
|
||||||
|
const int count = img->width() * img->height();
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
r[i] = red;
|
||||||
|
g[i] = green;
|
||||||
|
b[i] = blue;
|
||||||
|
a[i] = alpha;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set normal map options.
|
// Set normal map options.
|
||||||
void TexImage::toNormalMap(float sm, float medium, float big, float large)
|
void TexImage::toNormalMap(float sm, float medium, float big, float large)
|
||||||
{
|
{
|
||||||
|
|
|
@ -408,9 +408,11 @@ namespace nvtt
|
||||||
NVTT_API void transform(const float w0[4], const float w1[4], const float w2[4], const float w3[4], const float offset[4]);
|
NVTT_API void transform(const float w0[4], const float w1[4], const float w2[4], const float w3[4], const float offset[4]);
|
||||||
NVTT_API void swizzle(int r, int g, int b, int a);
|
NVTT_API void swizzle(int r, int g, int b, int a);
|
||||||
NVTT_API void scaleBias(int channel, float scale, float bias);
|
NVTT_API void scaleBias(int channel, float scale, float bias);
|
||||||
NVTT_API void blend(float r, float g, float b, float a);
|
NVTT_API void blend(float r, float g, float b, float a, float t);
|
||||||
NVTT_API void premultiplyAlpha();
|
NVTT_API void premultiplyAlpha();
|
||||||
NVTT_API void toGreyScale(float redScale, float greenScale, float blueScale, float alphaScale);
|
NVTT_API void toGreyScale(float redScale, float greenScale, float blueScale, float alphaScale);
|
||||||
|
NVTT_API void setBorder(float r, float g, float b, float a);
|
||||||
|
NVTT_API void fill(float r, float g, float b, float a);
|
||||||
|
|
||||||
// Set normal map options.
|
// Set normal map options.
|
||||||
NVTT_API void toNormalMap(float sm, float medium, float big, float large);
|
NVTT_API void toNormalMap(float sm, float medium, float big, float large);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user