【问题标题】:Soft Light Blending Mode柔光混合模式
【发布时间】:2014-12-28 09:03:59
【问题描述】:

我正在尝试编写一个函数来计算给定前景和背景颜色的柔光。 函数如下;

var background = '0xFFFFFF';
var foreground = '0x47768C';

var calculateSoftlight = function (background, foreground) {
  var intBackground = parseInt(background, 16);
  var intForeground = parseInt(foreground, 16);

  var softlight = (1 - (2 * intForeground)) * (intBackground*intBackground) + (2 * intForeground * intBackground);
  return softlight.toString(16);
}

calculateSoftlight(background, foreground); //-8eed155338bb200000 

我正在使用此处列出的 Pegtop 公式; http://en.wikipedia.org/wiki/Blend_modes。我不确定这个的正确实施。有什么想法吗?

【问题讨论】:

    标签: javascript math colors blending color-blending


    【解决方案1】:

    将公式应用于每个 RGB 值,而不是使用十六进制。如果您需要使用 Hex 作为输入,您可能需要进行转换。

    您需要对每个值进行规范化(所以value / 255)并在公式中使用它。然后将结果乘以(并四舍五入)255 以转换回 8 位值。

    这样的东西应该很接近,但我没有专门使用过那个公式,所以这是未经测试的。

    var top = top / 255,
        bot = bot / 255;
    
    top = ((1 - 2*bot)*Math.pow(top, 2)) + 2*bot*top,
    top = Math.round(top * 255);
    

    【讨论】:

    • 添加了一些示例代码,以帮助更好地了解我试图解释的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 2020-04-28
    • 2018-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-24
    相关资源
    最近更新 更多