app: improve and simplify alpha handling of LCH blending modes

parent feb2bb40
......@@ -131,21 +131,16 @@ chroma_post_process (const gfloat *in,
{
while (samples--)
{
gfloat comp_alpha, new_alpha;
gfloat comp_alpha = layer[ALPHA] * opacity;
comp_alpha = layer[ALPHA] * opacity;
if (mask)
comp_alpha *= *mask++;
new_alpha = in[ALPHA] + (1.0f - in[ALPHA]) * comp_alpha;
if (comp_alpha && new_alpha)
if (comp_alpha != 0.0f)
{
gfloat ratio = comp_alpha / new_alpha;
out[RED] = out[RED] * ratio + in[RED] * (1.0f - ratio);
out[GREEN] = out[GREEN] * ratio + in[GREEN] * (1.0f - ratio);
out[BLUE] = out[BLUE] * ratio + in[BLUE] * (1.0f - ratio);
out[RED] = out[RED] * comp_alpha + in[RED] * (1.0f - comp_alpha);
out[GREEN] = out[GREEN] * comp_alpha + in[GREEN] * (1.0f - comp_alpha);
out[BLUE] = out[BLUE] * comp_alpha + in[BLUE] * (1.0f - comp_alpha);
}
else
{
......
......@@ -120,21 +120,16 @@ color_post_process (const gfloat *in,
{
while (samples--)
{
gfloat comp_alpha, new_alpha;
gfloat comp_alpha = layer[ALPHA] * opacity;
comp_alpha = layer[ALPHA] * opacity;
if (mask)
comp_alpha *= *mask++;
new_alpha = in[ALPHA] + (1.0f - in[ALPHA]) * comp_alpha;
if (comp_alpha && new_alpha)
if (comp_alpha != 0.0f)
{
gfloat ratio = comp_alpha / new_alpha;
out[RED] = out[RED] * ratio + in[RED] * (1.0f - ratio);
out[GREEN] = out[GREEN] * ratio + in[GREEN] * (1.0f - ratio);
out[BLUE] = out[BLUE] * ratio + in[BLUE] * (1.0f - ratio);
out[RED] = out[RED] * comp_alpha + in[RED] * (1.0f - comp_alpha);
out[GREEN] = out[GREEN] * comp_alpha + in[GREEN] * (1.0f - comp_alpha);
out[BLUE] = out[BLUE] * comp_alpha + in[BLUE] * (1.0f - comp_alpha);
}
else
{
......
......@@ -132,21 +132,16 @@ hue_post_process (const gfloat *in,
{
while (samples--)
{
gfloat comp_alpha, new_alpha;
gfloat comp_alpha = layer[ALPHA] * opacity;
comp_alpha = layer[ALPHA] * opacity;
if (mask)
comp_alpha *= *mask++;
new_alpha = in[ALPHA] + (1.0f - in[ALPHA]) * comp_alpha;
if (comp_alpha && new_alpha)
if (comp_alpha != 0.0f)
{
gfloat ratio = comp_alpha / new_alpha;
out[RED] = out[RED] * ratio + in[RED] * (1.0f - ratio);
out[GREEN] = out[GREEN] * ratio + in[GREEN] * (1.0f - ratio);
out[BLUE] = out[BLUE] * ratio + in[BLUE] * (1.0f - ratio);
out[RED] = out[RED] * comp_alpha + in[RED] * (1.0f - comp_alpha);
out[GREEN] = out[GREEN] * comp_alpha + in[GREEN] * (1.0f - comp_alpha);
out[BLUE] = out[BLUE] * comp_alpha + in[BLUE] * (1.0f - comp_alpha);
}
else
{
......
......@@ -116,21 +116,16 @@ lightness_post_process (const gfloat *in,
{
while (samples--)
{
gfloat comp_alpha, new_alpha;
gfloat comp_alpha = layer[ALPHA] * opacity;
comp_alpha = layer[ALPHA] * opacity;
if (mask)
comp_alpha *= *mask++;
new_alpha = in[ALPHA] + (1.0f - in[ALPHA]) * comp_alpha;
if (comp_alpha && new_alpha)
if (comp_alpha != 0.0f)
{
gfloat ratio = comp_alpha / new_alpha;
out[RED] = out[RED] * ratio + in[RED] * (1.0f - ratio);
out[GREEN] = out[GREEN] * ratio + in[GREEN] * (1.0f - ratio);
out[BLUE] = out[BLUE] * ratio + in[BLUE] * (1.0f - ratio);
out[RED] = out[RED] * comp_alpha + in[RED] * (1.0f - comp_alpha);
out[GREEN] = out[GREEN] * comp_alpha + in[GREEN] * (1.0f - comp_alpha);
out[BLUE] = out[BLUE] * comp_alpha + in[BLUE] * (1.0f - comp_alpha);
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment