Office Open XML satMod 的饱和度超过 100%

发布于 2024-11-25 06:42:04 字数 759 浏览 2 评论 0 原文

我正在尝试计算 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梓梦 2024-12-02 06:42:04

那是我问了最初的问题。我已经想通了。对于单一颜色转换(satModredModlumMod 等),您必须将值限制在 sRGB 0,0 范围内, 0 或 255,255,255(或 1.0,1.0,1.0)。这意味着如果您的 satMod 将颜色修改了 300% 并且结果是高于 255 的颜色值,请将其限制为 255(或 1.0)。使用生成的颜色,您可以应用其他颜色变换(如果它们位于您的颜色 srgbClr 或其他颜色空间中)。

这就是我在像你这样的例子中所做的。

  1. 将颜色转换为 HSL 空间(这些类型的 RGB->HSL 例程在 Bing/Google 查找中很常见)。

  2. 将该颜色和 satMod 发送到如下例程:

    Public Sub modulateHSL(ByVal c As HSL, ByVal val As System.Double)
        选择案例c
            案例 HSL.Hue
                色相 = 色相 * 值
                如果色相 = 0.0 那么
                    如果 val >= 1.0 那么
                        色调 = val - 修正(val)
                    结束如果
                别的
                    色相 = 色相 - 修复(色相)
                结束如果
            案例 HSL.饱和度
                饱和度 = 饱和度 * 值
            案例 HSL.亮度
                亮度 = 亮度 * 值
        结束选择
        HSL_To_sRGB(色相、饱和度、亮度)
        Clamp_sARGB() 
    结束子
    
  3. 在此例程结束时,您会注意到两个调用 1) HSL_To_sRGB (色相、饱和度、亮度) 和 2) Clamp_sARGB()。第一个转换回 sRGB 空间,第二个限制 RGB 值,如下所示:

    公共子 Clamp_sARGB()
        如果红色 <= 0.0 则红色 = 0.0 否则如果红色 >= 1.0 则红色 = 1.0
        如果绿色 <= 0.0 则绿色 = 0.0 否则如果绿色 >= 1.0 则绿色 = 1.0
        如果蓝色 <= 0.0 则蓝色 = 0.0 否则如果蓝色 >= 1.0 则蓝色 = 1.0
        如果 Alpha <= 0.0 则 Alpha = 0.0 否则如果 Alpha >= 1.0 则 Alpha = 1.0
        sRGB_To_HSL(红、绿、蓝)
    结束子
    

请注意,如果您仅修改饱和度,则无需使用线性 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 your satMod 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 color srgbClr or other color spaces.

This is what I do in an example like yours.

  1. Convert color to HSL space (these kinds of RGB->HSL routines are common on Bing/Google in a look up).

  2. Send in that color and the satMod to a routine like this:

    Public Sub modulateHSL(ByVal c As HSL, ByVal val As System.Double)
        Select Case c
            Case HSL.Hue
                Hue = Hue * val
                If Hue = 0.0 Then
                    If val >= 1.0 Then
                        Hue = val - Fix(val)
                    End If
                Else
                    Hue = Hue - Fix(Hue)
                End If
            Case HSL.Saturation
                Saturation = Saturation * val
            Case HSL.Luminance
                Luminance = Luminance * val
        End Select
        HSL_To_sRGB(Hue, Saturation, Luminance)
        Clamp_sARGB() 
    End Sub
    
  3. 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:

    Public Sub Clamp_sARGB()
        If Red <= 0.0 Then Red = 0.0 Else If Red >= 1.0 Then Red = 1.0
        If Green <= 0.0 Then Green = 0.0 Else If Green >= 1.0 Then Green = 1.0
        If Blue <= 0.0 Then Blue = 0.0 Else If Blue >= 1.0 Then Blue = 1.0
        If Alpha <= 0.0 Then Alpha = 0.0 Else If Alpha >= 1.0 Then Alpha = 1.0
        sRGB_To_HSL(Red, Green, Blue)
    End Sub
    

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.?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文