2010-10-22 58 views
3

处理打开的xml文档时,颜色可以将各种转换应用于基色以生成相对颜色。例如<a:satMod value="25000">会将基色饱和度修改25%。有两种变换,我已经能够找到的资料非常少,他们是:OpenXML方案颜色转换 - 应用<a:gamma>和<a:invgamma>

<a:gamma> 

文档说“这个元素指定由该程序生成渲染输出的颜色应该是输入的sRGB伽玛转变颜色。”

<a:invGamma> 

文档说“该元素指定由所述生成的应用程序呈现的输出颜色应该是输入彩色的倒数的sRGB伽玛移”。

我想了解什么计算,我将不得不做基础颜色转换它使用这些转换之一。有没有人知道这一点?

回答

2

是的。简而言之,

  • <a:gamma>只是意味着采取sRGB值(0-1比例)并线性化它(转换为线性RGB)。取这些线性RGB值并将其保存为sRGB(如果需要,可将其转换为0-255范围)。
  • <a:invGamma>正好相反 - 取线性RGB值(0-1比例)并将其非线性化(转换为sRGB)。将这些非线性化的RGB值保存为sRGB(如果需要,可将其转换为0-255范围)。

那么什么是线性RGB?计算结果为here on Wikipedia's sRGB page

这里也是一个VBA版本:

Public Function sRGB_to_linearRGB(value As Double) 
    If value < 0# Then 
     sRGB_to_linearRGB = 0# 
     Exit Function 
    End If 
    If value <= 0.04045 Then 
     sRGB_to_linearRGB = value/12.92 
     Exit Function 
    End If 
    If value <= 1# Then 
     sRGB_to_linearRGB = ((value + 0.055)/1.055)^2.4 
     Exit Function 
    End If 
    sRGB_to_linearRGB = 1# 
End Function 

Public Function linearRGB_to_sRGB(value As Double) 
    If value < 0# Then 
     linearRGB_to_sRGB = 0# 
     Exit Function 
    End If 
    If value <= 0.0031308 Then 
     linearRGB_to_sRGB = value * 12.92 
     Exit Function 
    End If 
    If value < 1# Then 
     linearRGB_to_sRGB = 1.055 * (value^(1#/2.4)) - 0.055 
     Exit Function 
    End If 
    linearRGB_to_sRGB = 1# 
End Function 

您传递中是在0-1范围内的R,G,B分量的value,无论是sRGB的或线性RGB。你会收到相同的范围,0-1,根据你的需要,你可以转换为0-255范围来构建你的颜色。

+0

好,太感谢宅男。 – 2010-10-24 13:09:49