我正在尝试计算 satMod (饱和调制),如下所示:
<a:srgbClr val="58CAFF">
<a:satMod="300000"/>
</a:srgbClr>
EMCA-376 规范的第 20.1.2.3.27 节谈到了 。元素:“此元素指定输入颜色,其饱和度按给定百分比进行调制。50% 饱和度调制会将饱和度降低一半。200% 饱和度调制会使饱和度加倍。”
我遇到的问题是,许多颜色已经足够饱和,将饱和度增加 300%(其中的 300000 对应于 300%)使其超出 0-100% 范围。我只是将饱和度限制为 100%,但我的结果与 Excel 的结果有很大不同。
在饱和度溢出的情况下,似乎这里发生了一些特殊的魔法。有人知道 Office/Excel 在这种情况下会做什么吗?
我在这里发现基本上相同的问题: http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/040e0a1f-dbfe-4ce5-826b-38b4b6f6d3f7
答案表明srgb颜色应该是在修改饱和度之前先转换为线性 RGB,然后转换为 HSL。对我来说这还没有解决问题。
I'm trying to calculate the satMod (saturation modulation) for something like the following:
<a:srgbClr val="58CAFF">
<a:satMod="300000"/>
</a:srgbClr>
Section 20.1.2.3.27 of the EMCA-376 spec says of the <satMod> element: "This element specifies the input color with its saturation modulated by the given percentage. A 50% saturation modulate reduces the saturation by half. A 200% saturation modulate doubles the saturation."
The problem I'm having is that many colors are already saturated enough that increasing the saturation by 300% (the 300000 in there corresponds to 300%) puts it way out of the 0-100% range. I have been simply capping the saturation at 100% but my results are pretty different from what Excel does.
It seems there is some special magic happening here in cases where the saturation should overflow. Anyone know what Office/Excel does in this case?
I found essentially the same question here: http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/040e0a1f-dbfe-4ce5-826b-38b4b6f6d3f7
The answer indicated that the srgb color should be converted to linear rgb first and then to hsl before the saturation is modified. For me that hasn't solved the problem.
发布评论
评论(1)
那是我问了最初的问题。我已经想通了。对于单一颜色转换(
satMod
、redMod
、lumMod
等),您必须将值限制在 sRGB 0,0 范围内, 0 或 255,255,255(或 1.0,1.0,1.0)。这意味着如果您的satMod
将颜色修改了 300% 并且结果是高于 255 的颜色值,请将其限制为 255(或 1.0)。使用生成的颜色,您可以应用其他颜色变换(如果它们位于您的颜色srgbClr
或其他颜色空间中)。这就是我在像你这样的例子中所做的。
将颜色转换为 HSL 空间(这些类型的 RGB->HSL 例程在 Bing/Google 查找中很常见)。
将该颜色和
satMod
发送到如下例程:在此例程结束时,您会注意到两个调用 1)
HSL_To_sRGB (色相、饱和度、亮度)
和 2)Clamp_sARGB()
。第一个转换回 sRGB 空间,第二个限制 RGB 值,如下所示:请注意,如果您仅修改饱和度,则无需使用线性 RGB。我在类级别字段中维护 RBG 和 HSL 空间(RGB 在 0-1 空间中),因此您会在该例程末尾看到
sRGB_To_HSL(Red, Green, Blue)
。现在这是针对在 PowerPoint 中显示的 DrawingML。 Excel 可能有所不同(有一个很长的线程 此处涉及可能也有您答案的图表)。请记住,修改饱和度也可以修改亮度,具体取决于您对例程进行编码的方式。如果是这种情况,您在从 HSL 转换回 RGB 时需要使用原始亮度。
如果这些都不适合您,您可以将示例 XLSX 放在
DropBox 指向某处正在发生的事情、您的期望等等?
That was me that asked that original question. I have since figured it out. With ever single color transformations (
satMod
,redMod
,lumMod
, etc.), you have to clamp the value to within sRGB 0,0,0 or 255,255,255 (or 1.0,1.0,1.0). Meaning if yoursatMod
modifies your color by 300% and the result is a color value above 255, clamp it to 255 (or 1.0). With that resulting color, you can then apply other color transforms if they are in your colorsrgbClr
or other color spaces.This is what I do in an example like yours.
Convert color to HSL space (these kinds of RGB->HSL routines are common on Bing/Google in a look up).
Send in that color and the
satMod
to a routine like this:At the end of this routine, you'll notice two calls 1)
HSL_To_sRGB(Hue, Saturation, Luminance)
and 2)Clamp_sARGB()
. The first one converts back to sRGB space and the second one clamps the RGB values, like this:Note there is no need to use Linear RGB in the case where you're only modifying the saturation. I maintain both RBG and HSL spaces in class level fields (RGB in 0-1 space), so that's why you see
sRGB_To_HSL(Red, Green, Blue)
at the end of that routine.Now this is for DrawingML as it appears in PowerPoint. Excel may be different (there is a long drawn out thread here that deals with charts that may also have your answer). Keep in mind that modifying saturation can also modify luminance depending on how you coded your routine. If that's the case, you'll want to use the original luminance when converting back from HSL to RGB.
If none of this is working for you, can you put an example XLSX on a
DropBox point somewhere with what is going on, what you're expecting, etc.?