Victor D
Victor D

Reputation: 15

Algorithm of blending 'One OneMinusSrcAlpha'

I'm trying to find the algorithm of this blending in rust. When searching through the image crate source, the blending method used is 'src-over' or 'SrcAlpha InvSrcAlpha' if I'm correct: source.

So the only thing I need to change is the source factor, from SrcAlpha to One.

Unity doc say: "The value of this input is one. Use this to use the value of the source or the destination color."

So only use the source value without mult.

I tried to change that:

let (bg_r_a, bg_g_a, bg_b_a) = (bg_r * bg_a, bg_g * bg_a, bg_b * bg_a);
let (fg_r_a, fg_g_a, fg_b_a) = (fg_r * fg_a, fg_g * fg_a, fg_b * fg_a);

to

let (bg_r_a, bg_g_a, bg_b_a) = (bg_r * bg_a, bg_g * bg_a, bg_b * bg_a);
let (fg_r_a, fg_g_a, fg_b_a) = (fg_r * 1., fg_g * 1., fg_b * 1.);

Here's an example result

The 'expected' is in fact not the exact result that i want but very close. I got it from a manual unmultiply alpha, and manual color boost (multiply each channel by 5).

When debugging the blend function I noticed that r,g,b overflow the range of the color (more that 1.0), which make the result image white. and alpha channel remain very very low.

So is the algorithm correct? Otherwise the issue come from my source.

Upvotes: 0

Views: 336

Answers (0)

Related Questions