RGB 值的加色混合算法 [英] Algorithm for Additive Color Mixing for RGB Values
本文介绍了RGB 值的加色混合算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种算法来对 RGB 值进行加色混合.
是否像将 RGB 值加在一起最大为 256 一样简单?
(r1, g1, b1) + (r2, g2, b2) =(min(r1+r2, 256), min(g1+g2, 256), min(b1+b2, 256))
解决方案
看你想要什么,看不同方法的结果如何.
如果你愿意
<前>红色 + 黑色 = 红色红色 + 绿色 = 黄色红 + 绿 + 蓝 = 白红色 + 白色 = 白色黑色 + 白色 = 白色然后使用夹子添加(例如 min(r1 + r2, 255)
)这更像是您提到的光模型.
如果你愿意
<前>红色 + 黑色 = 深红色红色 + 绿色 = 深黄色红色 + 绿色 + 蓝色 = 深灰色红色 + 白色 = 粉色黑色 + 白色 = 灰色然后您需要对这些值求平均值(例如 (r1 + r2)/2
)这更适合使颜色变亮/变暗和创建渐变.
I'm looking for an algorithm to do additive color mixing for RGB values.
Is it as simple as adding the RGB values together to a max of 256?
(r1, g1, b1) + (r2, g2, b2) =
(min(r1+r2, 256), min(g1+g2, 256), min(b1+b2, 256))
解决方案
It depends on what you want, and it can help to see what the results are of different methods.
If you want
Red + Black = Red Red + Green = Yellow Red + Green + Blue = White Red + White = White Black + White = White
then adding with a clamp works (e.g. min(r1 + r2, 255)
) This is more like the light model you've referred to.
If you want
Red + Black = Dark Red Red + Green = Dark Yellow Red + Green + Blue = Dark Gray Red + White = Pink Black + White = Gray
then you'll need to average the values (e.g. (r1 + r2) / 2
) This works better for lightening/darkening colors and creating gradients.
这篇关于RGB 值的加色混合算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文