forked from bartvdbraak/blender
Bugfix #26901
Compositing, lens distortion node: it delivered RGBA out with alpha zero, making it not draw previews, violates both premul or straight alpha usage. Now it just sets alpha to 1 for entire output. Cleaned code readability a bit as well.
This commit is contained in:
parent
c84e26cb91
commit
54f3167270
@ -44,7 +44,7 @@ static bNodeSocketType cmp_node_lensdist_out[]= {
|
|||||||
{ -1, 0, "" }
|
{ -1, 0, "" }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* assumes *dst is type RGBA */
|
||||||
static void lensDistort(CompBuf *dst, CompBuf *src, float kr, float kg, float kb, int jit, int proj, int fit)
|
static void lensDistort(CompBuf *dst, CompBuf *src, float kr, float kg, float kb, int jit, int proj, int fit)
|
||||||
{
|
{
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
@ -53,20 +53,27 @@ static void lensDistort(CompBuf* dst, CompBuf* src, float kr, float kg, float kb
|
|||||||
if (proj) {
|
if (proj) {
|
||||||
// shift
|
// shift
|
||||||
CompBuf *tsrc = dupalloc_compbuf(src);
|
CompBuf *tsrc = dupalloc_compbuf(src);
|
||||||
|
|
||||||
for (z=0; z<tsrc->type; ++z)
|
for (z=0; z<tsrc->type; ++z)
|
||||||
IIR_gauss(tsrc, (kr+0.5f)*(kr+0.5f), z, 1);
|
IIR_gauss(tsrc, (kr+0.5f)*(kr+0.5f), z, 1);
|
||||||
kr *= 20.f;
|
kr *= 20.f;
|
||||||
|
|
||||||
for (y=0; y<dst->y; y++) {
|
for (y=0; y<dst->y; y++) {
|
||||||
fRGB *colp = (fRGB*)&dst->rect[y*dst->x*dst->type];
|
fRGB *colp = (fRGB*)&dst->rect[y*dst->x*dst->type];
|
||||||
const float v = (y + 0.5f)/(float)dst->y;
|
const float v = (y + 0.5f)/(float)dst->y;
|
||||||
|
|
||||||
for (x=0; x<dst->x; x++) {
|
for (x=0; x<dst->x; x++) {
|
||||||
const float u = (x + 0.5f)/(float)dst->x;
|
const float u = (x + 0.5f)/(float)dst->x;
|
||||||
|
|
||||||
qd_getPixelLerpChan(tsrc, (u*dst->x + kr) - 0.5f, v*dst->y - 0.5f, 0, colp[x]);
|
qd_getPixelLerpChan(tsrc, (u*dst->x + kr) - 0.5f, v*dst->y - 0.5f, 0, colp[x]);
|
||||||
if (tsrc->type == CB_VAL)
|
if (tsrc->type == CB_VAL)
|
||||||
colp[x][1] = tsrc->rect[x + y*tsrc->x];
|
colp[x][1] = tsrc->rect[x + y*tsrc->x];
|
||||||
else
|
else
|
||||||
colp[x][1] = tsrc->rect[(x + y*tsrc->x)*tsrc->type + 1];
|
colp[x][1] = tsrc->rect[(x + y*tsrc->x)*tsrc->type + 1];
|
||||||
qd_getPixelLerpChan(tsrc, (u*dst->x - kr) - 0.5f, v*dst->y - 0.5f, 2, colp[x]+2);
|
qd_getPixelLerpChan(tsrc, (u*dst->x - kr) - 0.5f, v*dst->y - 0.5f, 2, colp[x]+2);
|
||||||
|
|
||||||
|
/* set alpha */
|
||||||
|
colp[x][3]= 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free_compbuf(tsrc);
|
free_compbuf(tsrc);
|
||||||
@ -80,17 +87,20 @@ static void lensDistort(CompBuf* dst, CompBuf* src, float kr, float kg, float kb
|
|||||||
const float mk = MAX3(kr, kg, kb);
|
const float mk = MAX3(kr, kg, kb);
|
||||||
const float sc = (fit && (mk > 0.f)) ? (1.f/(1.f + 2.f*mk)) : (1.f/(1.f + mk));
|
const float sc = (fit && (mk > 0.f)) ? (1.f/(1.f + 2.f*mk)) : (1.f/(1.f + mk));
|
||||||
const float drg = 4.f*(kg - kr), dgb = 4.f*(kb - kg);
|
const float drg = 4.f*(kg - kr), dgb = 4.f*(kb - kg);
|
||||||
|
|
||||||
kr *= 4.f, kg *= 4.f, kb *= 4.f;
|
kr *= 4.f, kg *= 4.f, kb *= 4.f;
|
||||||
|
|
||||||
for (y=0; y<dst->y; y++) {
|
for (y=0; y<dst->y; y++) {
|
||||||
fRGB *colp = (fRGB*)&dst->rect[y*dst->x*dst->type];
|
fRGB *colp = (fRGB*)&dst->rect[y*dst->x*dst->type];
|
||||||
const float v = sc*((y + 0.5f) - cy)/cy;
|
const float v = sc*((y + 0.5f) - cy)/cy;
|
||||||
|
|
||||||
for (x=0; x<dst->x; x++) {
|
for (x=0; x<dst->x; x++) {
|
||||||
int dr = 0, dg = 0, db = 0;
|
int dr = 0, dg = 0, db = 0;
|
||||||
float d, t, ln[6] = {0, 0, 0, 0, 0, 0};
|
float d, t, ln[6] = {0, 0, 0, 0, 0, 0};
|
||||||
fRGB c1, tc = {0, 0, 0, 0};
|
fRGB c1, tc = {0, 0, 0, 0};
|
||||||
const float u = sc*((x + 0.5f) - cx)/cx;
|
const float u = sc*((x + 0.5f) - cx)/cx;
|
||||||
int sta = 0, mid = 0, end = 0;
|
int sta = 0, mid = 0, end = 0;
|
||||||
|
|
||||||
if ((t = 1.f - kr*(u*u + v*v)) >= 0.f) {
|
if ((t = 1.f - kr*(u*u + v*v)) >= 0.f) {
|
||||||
d = 1.f/(1.f + sqrtf(t));
|
d = 1.f/(1.f + sqrtf(t));
|
||||||
ln[0] = (u*d + 0.5f)*dst->x - 0.5f, ln[1] = (v*d + 0.5f)*dst->y - 0.5f;
|
ln[0] = (u*d + 0.5f)*dst->x - 0.5f, ln[1] = (v*d + 0.5f)*dst->y - 0.5f;
|
||||||
@ -113,6 +123,7 @@ static void lensDistort(CompBuf* dst, CompBuf* src, float kr, float kg, float kb
|
|||||||
const float dsf = sqrtf(dx*dx + dy*dy) + 1.f;
|
const float dsf = sqrtf(dx*dx + dy*dy) + 1.f;
|
||||||
const int ds = (int)(jit ? ((dsf < 4.f) ? 2.f : sqrtf(dsf)) : dsf);
|
const int ds = (int)(jit ? ((dsf < 4.f) ? 2.f : sqrtf(dsf)) : dsf);
|
||||||
const float sd = 1.f/(float)ds;
|
const float sd = 1.f/(float)ds;
|
||||||
|
|
||||||
for (z=0; z<ds; ++z) {
|
for (z=0; z<ds; ++z) {
|
||||||
const float tz = ((float)z + (jit ? BLI_frand() : 0.5f))*sd;
|
const float tz = ((float)z + (jit ? BLI_frand() : 0.5f))*sd;
|
||||||
t = 1.f - (kr + tz*drg)*(u*u + v*v);
|
t = 1.f - (kr + tz*drg)*(u*u + v*v);
|
||||||
@ -128,6 +139,7 @@ static void lensDistort(CompBuf* dst, CompBuf* src, float kr, float kg, float kb
|
|||||||
const float dsf = sqrtf(dx*dx + dy*dy) + 1.f;
|
const float dsf = sqrtf(dx*dx + dy*dy) + 1.f;
|
||||||
const int ds = (int)(jit ? ((dsf < 4.f) ? 2.f : sqrtf(dsf)) : dsf);
|
const int ds = (int)(jit ? ((dsf < 4.f) ? 2.f : sqrtf(dsf)) : dsf);
|
||||||
const float sd = 1.f/(float)ds;
|
const float sd = 1.f/(float)ds;
|
||||||
|
|
||||||
for (z=0; z<ds; ++z) {
|
for (z=0; z<ds; ++z) {
|
||||||
const float tz = ((float)z + (jit ? BLI_frand() : 0.5f))*sd;
|
const float tz = ((float)z + (jit ? BLI_frand() : 0.5f))*sd;
|
||||||
t = 1.f - (kg + tz*dgb)*(u*u + v*v);
|
t = 1.f - (kg + tz*dgb)*(u*u + v*v);
|
||||||
@ -144,11 +156,11 @@ static void lensDistort(CompBuf* dst, CompBuf* src, float kr, float kg, float kb
|
|||||||
if (dg) colp[x][1] = 2.f*tc[1] / (float)dg;
|
if (dg) colp[x][1] = 2.f*tc[1] / (float)dg;
|
||||||
if (db) colp[x][2] = 2.f*tc[2] / (float)db;
|
if (db) colp[x][2] = 2.f*tc[2] / (float)db;
|
||||||
|
|
||||||
|
/* set alpha */
|
||||||
|
colp[x][3]= 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user