预乘alpha合成 [英] Pre-multiplied alpha compositing

查看:217
本文介绍了预乘alpha合成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现预乘的alpha混合。在这个页面:什么是颜色混合,他们做解释标准的字母? 。混合而不是预乘值

I am trying to implement pre-multiplied alpha blending. On this page : What Is Color Blending?, they do explain standard alpha blending but not for pre-multiplied values.

Alpha混合(来源:×Blend.SourceAlpha)+(目标×Blend.InvSourceAlpha)

根据公式,将其转换为这样的:

According formula, it translates to this :

  a = ((srcA * srcA) >> 8) + ((tgtA * (255 - srcA)) >> 8);
  r = ((srcR * srcA) >> 8) + ((tgtR * (255 - srcA)) >> 8);
  g = ((srcG * srcA) >> 8) + ((tgtG * (255 - srcA)) >> 8);
  b = ((srcB * srcA) >> 8) + ((tgtB * (255 - srcA)) >> 8);



它的工作原理,很明显...

It works, obviously ...

现在我该怎样转换这个处理预乘值?

Now how do I convert this to process pre-multiplied values ?

  a = ((srcA)) + ((tgtA * (255 - srcA)) >> 8);
  r = ((srcR)) + ((tgtR * (255 - srcA)) >> 8);
  g = ((srcG)) + ((tgtG * (255 - srcA)) >> 8);
  b = ((srcB)) + ((tgtB * (255 - srcA)) >> 8);



既然已经预乘,我放弃了第一项乘法...对! ?
但结果是alpha混合和添加剂调合而成的,倾向于更多的添加剂。最终它并没有真正显得过于混合。这也可能是错误的,因为它应该看起来酷似经典的阿尔法混合;或者这是预期的行为?

Since it has been pre-multiplied, I discard the multiplication in the first term ... right !? But the result is between alpha blending and additive blending, tending more to additive. In the end it doesn't really look too blended. It's probably wrong since it should look exactly like classic alpha blending; or is this expected behavior ?

感谢您。

推荐答案

的原因预相乘的作品,是因为它实际上结束了现蕾目标的alpha它添加源图像到目标

The reason pre-multiplying works is because it actually ends up squaring the alpha for the target before it adds the source image to the target

如前。如果没有预乘法,我们得到这个源图像数据:

eg. Without pre multiplying, we get this for the source image data:

srcA = origA
srcR = origR
srcG = origG
srcB = origB

和应用,当我们得到这个结果图像一个目标:

And we get this for the resulting image when applied to a target:

a = ((srcA * srcA) >> 8) + ((tgtA * (255 - srcA)) >> 8)
r = ((srcR * srcA) >> 8) + ((tgtR * (255 - srcA)) >> 8)
g = ((srcG * srcA) >> 8) + ((tgtG * (255 - srcA)) >> 8)
b = ((srcB * srcA) >> 8) + ((tgtB * (255 - srcA)) >> 8)

拓展了这一点,我们得到:

Expanding this out we get:

a = ((origA * origA) >> 8) + ((tgtA * (255 - origA)) >> 8)
r = ((origR * origA) >> 8) + ((tgtR * (255 - origA)) >> 8)
g = ((origG * origA) >> 8) + ((tgtG * (255 - origA)) >> 8)
b = ((origB * origA) >> 8) + ((tgtB * (255 - origA)) >> 8)

没有惊喜那里......

No surprises there...

现在对于我们得到的预先乘源图像数据:

Now for the pre-multiplied source image data we get:

srcA = (origA * origA) >> 8
srcR = (origR * origA) >> 8
srcG = (origG * origA) >> 8
srcB = (origB * origA) >> 8



其中,当施加到目标是:

Which, when applied to a target is:

a = (srcA >> 8) + ((tgtA * (255 - srcA)) >> 8);
r = (srcR >> 8) + ((tgtR * (255 - srcA)) >> 8);
g = (srcG >> 8) + ((tgtG * (255 - srcA)) >> 8);
b = (srcB >> 8) + ((tgtB * (255 - srcA)) >> 8);



好了,我们知道这一点,但如果我们扩大了这一点,你会看到其中的差别:

Ok, so we know this, but if we expand this out you will see the difference:

a = (origA * origA) >> 8 + ((tgtA * (255 – ((origA * origA) >> 8))) >> 8);
r = (origR * origA) >> 8 + ((tgtR * (255 - ((origA * origA) >> 8))) >> 8);
g = (origG * origA) >> 8 + ((tgtG * (255 – ((origA * origA) >> 8))) >> 8);
b = (origB * origA) >> 8 + ((tgtB * (255 – ((origA * origA) >> 8))) >> 8);



与此相比的非预先乘扩展:

Compare that to the NON Pre-Multiplied expansion of:

a = ((origA * origA) >> 8) + ((tgtA * (255 - origA)) >> 8)
r = ((origR * origA) >> 8) + ((tgtR * (255 - origA)) >> 8)
g = ((origG * origA) >> 8) + ((tgtG * (255 - origA)) >> 8)
b = ((origB * origA) >> 8) + ((tgtB * (255 - origA)) >> 8)

和马上就可以看到它应用到目标时,我们平方ORIGA值,这意味着更多的目标将通过来所产生的颜色值。

And straight away you can see that we are squaring the origA value when applying it to the target, this means that more of the target will come through to the resulting color values.

的平方它,你都这么说,我想要更多的目标才能通过。

By squaring it you are saying, I want more of the target to come through.

这就是为什么当预乘以它消除周围绑扎透明的量块,因为较低的alpha值的像素获得更多的目标像素的比你想,如果你没有预乘这发生在指数的规模。

This is why when pre-multiplying it removes the amount of banding around transparent blocks, because those pixels with lower Alpha values get more of the target pixels than you would if you didn't pre-multiply and this happens on an exponential scale.

我希望这会清除它。

这篇关于预乘alpha合成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆