不考虑抗锯齿线的边缘而将alpha纳入考虑范围的泛洪填充算法? [英] Flood fill algorithm that takes alpha into account without leaving fringes around anti-aliased lines?

查看:109
本文介绍了不考虑抗锯齿线的边缘而将alpha纳入考虑范围的泛洪填充算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一种典型的泛洪填充算法,当使用纯色(使用ARGB组件之间的欧几里德距离比较颜色)时,它可以按预期工作.

I've implemented a typical flood fill algorithm and it works as expected when solid colors are used where I use the Euclidean distance between the ARGB components to compare colors.

我的问题是,如果您在透明背景上绘制一条抗锯齿的红线,我的洪水填充算法将无法填充大多数半透明像素,从而在对象周围留下条纹.专门针对此示例,线的中心为纯红色(即,ARGB格式为(255,255,0,0)),并且线的边缘也为纯红色,但这些像素的alpha范围低至1%alpha (即(1,255,0,0)).通常,我希望能够绘制一个抗锯齿的圆形轮廓,在中心填充水,并且不要留下条纹.

My problem is that if you draw something like an anti-aliased red line on a transparent background my flood fill algorithm will not fill over most semi-transparent pixels, leaving fringes around objects. Specifically for this example, the center of the line is solid red (i.e. (255, 255, 0, 0) in ARGB format) and the fringes of the line are also solid red but the alpha of these pixels ranges down to 1% alpha (i.e. (1, 255, 0, 0)). Generally, I want to be able to draw, say, a anti-aliased circle outline, flood fill in the center and not have it leave fringes.

我该使用什么功能比较颜色和/或如何调整泛洪填充算法,以使这些条纹不会留在对象周围?

What function do I use to compare colors and/or how do I adapt the flood fill algorithm so such fringes are not left around objects?

我试图告诉算法,如果它的Alpha值小于90%,则始终填充整个像素,这有时看起来还可以,但是在填充淡淡的线条时过于激进.

I've tried telling the algorithm to always fill over a pixel if it's alpha is <90% and this sometimes looks OK but it's too aggressive at filling over faint lines.

要详细说明0-5代表0、20、40、60、80和100%alpha的红色像素的样子,反锯齿红线的图像可能看起来像这样:

To elaborate what this looks like where 0 - 5 represents a red pixels a 0, 20, 40, 60, 80 and 100% alpha, an image of an anti aliased red line might look like this:

0 0 0 0 0 0 0

0 0 0 0 0 0 0

0 0 0 3 0 0 0

0 0 0 3 0 0 0

0 0 3 5 3 0 0

0 0 3 5 3 0 0

0 0 3 5 3 0 0

0 0 3 5 3 0 0

0 0 3 5 3 0 0

0 0 3 5 3 0 0

0 0 0 3 0 0 0

0 0 0 3 0 0 0

0 0 0 0 0 0 0

0 0 0 0 0 0 0

我目前在左上角用红色填充的洪水填充算法会将所有0替换为5.其余3则在线条周围形成难看的光环.

My current flood fill algorithm filling red in the top-left corner will replace all the 0s with a 5. The remaining 3s form an ugly looking halo around the line.

推荐答案

您的泛洪填充应替换颜色的RGB部分,但保留原始的alpha.这样一来,您无需改变混合比例即可获得新颜色.

Your flood fill should replace the RGB portions of the colors, but leave the original alpha. That way you get the new color without changing the blending ratio.

(如果位图使用预乘Alpha,则应按现有Alpha缩放替换RGB,但在示例中,您不使用预乘Alpha.)

(If your bitmap uses pre-multiplied alpha, then you should scale the replacement RGB by the existing alpha, but in your examples, you aren't using pre-multiplied alphas.)

这篇关于不考虑抗锯齿线的边缘而将alpha纳入考虑范围的泛洪填充算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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