11.3 基本合成计算¶
11.3 Basic Compositing Computations
11.3.1 概述¶
11.3.1 General
11.3.2 合成计算的基本符号¶
11.3.2 Basic Notation for Compositing Computations
通常,本节中的变量名称由小写字母表示标量量,例如不透明度。大写字母表示具有多个标量分量的值,例如颜色。在基本颜色合成计算的描述中,颜色值通常用字母 C 表示,并带有助记下标,以指示所引用的具体颜色值;例如,Cs 代表“源颜色”。形状和不透明度值分别用字母 f(表示“形状因子”)和 q(表示“不透明度”)表示,同样带有助记下标,例如 qs 代表“源不透明度”。符号 α(alpha)表示形状和不透明度值的乘积。
在某些计算中,一个或多个变量可能具有未定义的值;例如,当不透明度为零时,相应的颜色是未定义的。如果一个量是由零除法计算得到的,它也可能是未定义的。在任何使用此类未定义量的公式中,该量不会影响最终结果,因为它随后会被乘以零或以其他方式抵消。重要的是,虽然可以为这种未定义量选择任意值,但计算不得因溢出或除零等异常情况而发生故障。此外,还应遵循 0 ÷ 0 = 0 的惯例。
In general, variable names in this clause consisting of a lowercase letter denote a scalar quantity, such as an opacity. Uppercase letters denote a value with multiple scalar components, such as a colour. In the descriptions of the basic colour compositing computations, colour values are generally denoted by the letter C, with a mnemonic subscript indicating which of several colour values is being referred to; for instance, Cs stands for “source colour.” Shape and opacity values are denoted respectively by the letters f (for “form factor”) and q (for “opaqueness”)—again with a mnemonic subscript, such as qs for “source opacity.” The symbol α (alpha) stands for a product of shape and opacity values.
In certain computations, one or more variables may have undefined values; for instance, when opacity is equal to zero, the corresponding colour is undefined. A quantity can also be undefined if it results from division by zero. In any formula that uses such an undefined quantity, the quantity has no effect on the ultimate result because it is subsequently multiplied by zero or otherwise cancelled out. It is significant that while any arbitrary value may be chosen for such an undefined quantity, the computation shall not malfunction because of exceptions caused by overflow or division by zero. The further convention that 0 ÷ 0 = 0 should also be adopted.
11.3.3 基本合成公式¶
11.3.3 Basic Compositing Formula
为了适应透明度,图像模型的主要变化体现在颜色的绘制方式上。在透明模型中,绘制的结果颜色(result colour)是正在绘制的颜色(source colour)与其覆盖的颜色(backdrop colour)的函数。这两种颜色都可能随页面上的位置变化而变化;然而,本小节关注页面上的某个固定点,并假设背景色和源颜色是固定的。
此计算涉及两个额外参数:α(alpha),用于控制背景色与源颜色的相对贡献;以及混合函数(blend function),用于指定它们在绘制操作中如何组合。最终的基本颜色合成公式(简称 基本合成公式)用于确定绘制操作产生的结果颜色:
其中,各变量的含义见 表 135。
变量 | 含义 |
---|---|
\(C_b\) | 背景色 |
\(C_s\) | 源颜色 |
\(C_r\) | 结果颜色 |
\(\alpha_b\) | 背景 alpha 值 |
\(\alpha_s\) | 源 alpha 值 |
\(\alpha_r\) | 结果 alpha 值 |
\(B(C_b , C_s)\) | 混合函数 |
该公式是合成公式的一种简化形式,其中形状和不透明度值被合并并表示为单个 alpha 值;更一般的形式将在后续介绍。此函数基于 Porter 和 Duff 在文章《Compositing Digital Images》中定义的 over 操作(详见参考文献),并扩展以在重叠区域包含混合模式。接下来的小节将进一步阐述该公式的含义及其影响。
The primary change in the imaging model to accommodate transparency is in how colours are painted. In the transparent model, the result of painting (the result colour) is a function of both the colour being painted (the source colour) and the colour it is painted over (the backdrop colour). Both of these colours may vary as a function of position on the page; however, this sub-clause focuses on some fixed point on the page and assumes a fixed backdrop and source colour.
This computation uses two other parameters: alpha, which controls the relative contributions of the backdrop and source colours, and the blend function, which specifies how they shall be combined in the painting operation. The resulting basic colour compositing formula (or just basic compositing formula for short) shall determine the result colour produced by the painting operation:
\(C_r = \left ( 1- \frac{\alpha_s}{\alpha_r} \right ) \times C_b + \frac{\alpha_s}{\alpha_r} \times [(1 - \alpha _b) \times C_s + \alpha _b \times B(C_b, C_s)]\)
where the variables have the meanings shown in Table 135.
Variable | Meaning |
---|---|
\(C_b\) | Backdrop colour |
\(C_s\) | Source colour |
\(C_r\) | Result colour |
\(\alpha_b\) | Backdrop alpha |
\(\alpha_s\) | Source alpha |
\(\alpha_r\) | Result alpha |
\(B(C_b , C_s)\) | Blend function |
This formula represents a simplified form of the compositing formula in which the shape and opacity values are combined and represented as a single alpha value; the more general form is presented later. This function is based on the over operation defined in the article “Compositing Digital Images,” by Porter and Duff (see the Bibliography), extended to include a blend mode in the region of overlapping coverage. The following sub- clauses elaborate on the meaning and implications of this formula.
11.3.4 混合色彩空间¶
11.3.4 Blending Colour Space
11.3.3“基本合成公式”中展示的合成公式表示一个矢量函数:其操作的颜色以 n 元向量的形式表示,其中 n 表示合成过程中使用的颜色空间所需的分量数量。结果颜色 \(C_r\) 的第 i 个分量应通过将合成公式应用于组成颜色 \(C_b\)、\(C_s\) 和 \(B(C_b, C_s)\) 的第 i 个分量来获得。因此,计算结果取决于颜色的表示空间。基于此,合成时使用的颜色空间(称为混合颜色空间,blending colour space)被明确地纳入透明图像模型。当需要时,背景色和源颜色应在进行合成计算之前转换为混合颜色空间。
在 PDF 规范的 8.6 节所描述的颜色空间中,下列颜色空间应当支持作为混合颜色空间:
- DeviceGray
- DeviceRGB
- DeviceCMYK
- CalGray
- CalRGB
- ICCBased 颜色空间(等效于上述颜色空间,包括校准 CMYK)
Lab 颜色空间及表示亮度和色度分离的 ICCBased 颜色空间(例如 L*a*b*、L*u*v* 和 HSV)不得用作混合颜色空间,因为在这些空间中,分别对每个颜色分量进行合成计算无法得到有意义的结果。此外,用作混合颜色空间的 ICCBased 空间必须是双向的,即其 ICC 配置文件必须包含 AToB 和 BToA 变换。
混合颜色空间仅适用于过程颜色(process colours)。尽管可以在 Separation 或 DeviceN 颜色空间中指定的专色(spot colours)上进行混合,但这些颜色不得转换为混合颜色空间(除非它们首先回退到其备用颜色空间,如 8.6.6.4 和“DeviceN 颜色空间”中所述)。相反,应分别对指定的颜色分量与背景的相应分量进行混合。
各种混合模式的混合函数定义如下:每个颜色分量的取值范围应为 0.0 到 1.0,并且颜色空间应为加性颜色空间。在执行减色混合(subtractive blending)时(即 DeviceCMYK、Separation 和 DeviceN 颜色空间),颜色分量值在应用混合函数之前应先取补(从 1.0 减去),然后再对混合函数的结果取补,以恢复原始颜色空间的表示。
注意
此调整确保各种混合模式在所有颜色空间中的数值计算保持一致。然而,给定混合模式的实际视觉效果仍然取决于颜色空间。在设备颜色空间(device colour space)中进行混合会产生设备相关的结果,而在基于 CIE 的颜色空间中进行混合,则可以保证结果在所有设备间保持一致。有关颜色空间的更多详细信息,请参阅 11.7“颜色空间与渲染问题”。
The compositing formula shown in 11.3.3, "Basic Compositing Formula," represents a vector function: the colours it operates on are represented in the form of n-element vectors, where n denotes the number of components required by the colour space in used in the compositing process. The ith component of the result colour \(C_r\) shall be obtained by applying the compositing formula to the ith components of the constituent colours \(C_b\) , \(C_s\) , and \(B(C_b, C_s)\). The result of the computation thus depends on the colour space in which the colours are represented. For this reason, the colour space used for compositing, called the blending colour space, is explicitly made part of the transparent imaging model. When necessary, backdrop and source colours shall be converted to the blending colour space before the compositing computation.
Of the PDF colour spaces described in Section 8.6, the following shall be supported as blending colour spaces:
- DeviceGray
- DeviceRGB
- DeviceCMYK
- CalGray
- CalRGB
- ICCBased colour spaces equivalent to the preceding (including calibrated CMYK)
The Lab space and ICCBased spaces that represent lightness and chromaticity separately (such as L*a*b*, L*u*v*, and HSV) shall not be used as blending colour spaces because the compositing computations in such spaces do not give meaningful results when applied separately to each component. In addition, an ICCBased space used as a blending colour space shall be bidirectional; that is, the ICC profile shall contain both AToB and BToA transformations.
The blending colour space shall be consulted only for process colours. Although blending may also be done on individual spot colours specified in a Separation or DeviceN colour space, such colours shall not be converted to a blending colour space (except in the case where they first revert to their alternate colour space, as described under Section 8.6.6.4 and “DeviceN Colour Spaces”). Instead, the specified colour components shall be blended individually with the corresponding components of the backdrop.
The blend functions for the various blend modes are defined such that the range for each colour component shall be 0.0 to 1.0 and that the colour space shall be additive. When performing blending operations in subtractive colour spaces (DeviceCMYK, Separation, and DeviceN), the colour component values shall be complemented (subtracted from 1.0) before the blend function is applied and the results of the function shall then be complemented back before being used.
NOTE
This adjustment makes the effects of the various blend modes numerically consistent across all colour spaces. However, the actual visual effect produced by a given blend mode still depends on the colour space. Blending in a device colour space produces device-dependent results, whereas in a CIE-based space it produces results that are consistent across all devices. See 11.7, "Colour Space and Rendering Issues," for additional details concerning colour spaces.
11.3.5 混合模式¶
11.3.5 Blend Mode
原则上,任何能生成另一种颜色 \(C_r\) 作为结果的背景色与源色的函数,都可以用作混合函数 \(B(C_b , C_s)\),并用于合成公式中以自定义混合操作。PDF 定义了一组标准的命名混合函数,或称 混合模式,如表 136 和表 137 所示。[附录 L] 的图 L.18 和 L.19 分别展示了 RGB 和 CMYK 颜色的视觉效果。
如果混合模式是 可分离 的,那么结果颜色的每个分量完全由其对应的背景色和源色分量决定,即混合模式函数 \(B\) 分别应用于每一组对应的颜色分量:
其中,小写变量 \(c_r, c_b, c_s\) 分别表示颜色 \(C_r, C_b, C_s\) 的对应分量,以加色形式表示。可分离混合模式可用于任何颜色空间,因为它可独立应用于任意数量的分量。仅可分离混合模式可用于专色混合。
注 1
从理论上讲,混合模式可以对每个颜色分量使用不同的函数,仍然是可分离的;然而,PDF 标准混合模式中没有这种情况。
表 136 列出了 PDF 中的标准可分离混合模式及其用于计算混合颜色的算法/公式。
名称 | 结果 |
---|---|
正常(Normal) | \(B ( c_b , c_s ) = c_s\) 注 选择源颜色,忽略背景色。 |
兼容模式(Compatible) | 与「正常」相同。此模式仅用于兼容性,不应使用。 |
正片叠底(Multiply) | \(B ( c_b , c_s ) = c_b \times c_s\) 注1 将背景色与源色值相乘。 注2 结果颜色始终不比任一组成颜色更亮。黑色与任何颜色相乘得黑;白色与任何颜色相乘不改变原色。连续绘制非黑白重叠物体会逐渐变暗。 |
滤色(Screen) | \(\begin{align} B(c_b,c_s) &= 1-[(1-c_b)\times (1-c_s)]\\ &= c_b + c_s -(c_b \times c_s) \end{align}\) 注3 取背景色与源色的补数相乘后再取补数。 注4 结果颜色始终不比任一组成颜色更暗。白色与任何颜色叠加仍为白;黑色叠加不改变原色。效果类似多张幻灯片同时投影。 |
叠加(Overlay) | \(B(c_b, c_s) = \text{HardLight}(c_s, c_b)\) 注5 根据背景色值选择正片叠底或滤色。源色覆盖背景色但保留其高光与阴影,背景色未被替换而是与源色混合反映明暗变化。 |
变暗(Darken) | \(B ( c_b , c_s ) = \text{min}(c_b, c_s)\) 注6 选择背景色与源色中较暗者。 注7 当源色更暗时替换背景色,否则保持不变。 |
变亮(Lighten) | \(B ( c_b , c_s ) = \text{max}(c_b, c_s)\) 注8 选择背景色与源色中较亮者。 注9 当源色更亮时替换背景色,否则保持不变。 |
颜色减淡(ColorDodge) | \(B(c_b, c_s) = \begin{cases} \text{min}(1, c_b/(1-c_s)) & \text{若} \space c_s \lt 1 \\ 1 & \text{若} \space c_s = \end{cases}\) 注10 通过源色提亮背景色。黑色叠加无变化。 |
颜色加深(ColorBurn) | \(B(c_b, c_s) = \begin{cases} 1 - \text{min}(1, (1-c_b)/c_s) & \text{若} \space c_s \gt 0 \\ 0 & \text{若} \space c_s = \end{cases}\) 注11 通过源色加深背景色。白色叠加无变化。 |
强光(HardLight) | \(B(c_b, c_s) = \begin{cases} \text{Multiply}(c_b, 2 \times c_s) & \text{若} \space c_s \le 0.5 \\ \text{Screen}(c_b, 2\times c_s - 1) & \text{若} \space c_s \gt 0.5 \end{cases}\) 注12 根据源色值选择正片叠底或滤色。效果类似强光照射背景。 |
柔光(SoftLight) | \(B(c_b, c_s) = \begin{cases} c_b - (1-2\times c_s) \times c_b \times (1-c_b) & \text{若} \space c_s \le 0.5 \\ c_b + (2 \times c_s - 1) \times (D(c_b) - c_b) & \text{若} \space c_s \gt 0.5 \end{cases}\) 其中 \(D(x) = \begin{cases} ((16 \times x - 12) \times x + 4) \times x & \text{若} \space x \le 0.25 \\ \sqrt{x} & \text{若} \space x \gt 0.25 \end{cases}\) 注13 根据源色值暗化或亮化颜色。效果类似漫射聚光灯照射背景。 |
差值(Difference) | \(B(c_b,c_s) = |c_b - c_s|\) 注14 用较亮颜色减去较暗颜色: 注15 白色叠加反转背景色;黑色叠加无变化。 |
排除(Exclusion) | \(B ( c_b , c_s ) = c_b + c_s - 2 \times c_b \times c_s\) 注16 效果类似「差值」模式但对比度更低。白色叠加反转背景色;黑色叠加无变化。 |
表 137 列出了标准的不可分离混合模式。由于这些模式考虑所有颜色分量的组合,因此它们的计算取决于用于混合的颜色空间。在所有允许作为混合颜色空间的多分量颜色空间中,都可以应用这些模式(参见 “混合色彩空间”)。
注 2
所有这些混合模式在概念上都包含以下步骤:
a) 将背景色和源色从混合颜色空间转换为中间的 HSL(色相-饱和度-亮度)表示。
b) 从背景色和源色中选择色相、饱和度和亮度分量的某种组合来创建新颜色。
c) 将结果转换回原始(混合)颜色空间。
然而,以下给出的公式并未实际执行这些转换。相反,它们从提供结果色相的颜色(背景色或源色)开始;然后调整该颜色,使其具有适当的饱和度和亮度。
不可分离混合模式的公式使用了几个辅助函数。这些函数操作的颜色假定具有红色、绿色和蓝色分量。CMYK 颜色空间的混合需要特别处理,如本小节所述。
这些函数应具有以下定义:
\(\text{Lum}(C) = 0.3 \times C_{red} + 0.59 \times C_{green} + 0.11 \times C_{blue}\)
\(\begin{align} \text{SetLum}&(C, 1) \\ & \text{let} \space d = 1 - \text{Lum}(C) \\ & C_{\text{red} } = C_{\text{red} } + d \\ & C_{\text{green} } = C_{\text{green} } + d \\ & C_{\text{blue} } = C_{\text{blue} } + d \\ & \text{returnClipColor}(C) \end{align}\)
\(\begin{align} \text{ClipColor}&(C) \\ & \text{let} \space l = \text{Lum}(C) \\ & \text{let} \space n = \text{min}(C_{\text{red} }, C_{\text{green} }, C_{\text{blue} }) \\ & \text{let} \space x = \text{max}(C_{\text{red} }, C_{\text{green} }, C_{\text{blue} }) \\ & if \space n \lt 0.0 \\ & \qquad C_{\text{red} } = l + (((C_{\text{red} } -l) \times l)/(l-n))\\ & \qquad C_{\text{green} } = l + (((C_{\text{green} } -l) \times l)/(l-n))\\ & \qquad C_{\text{blue} } = l + (((C_{\text{blue} } -l) \times l)/(l-n))\\ & if \space n \gt 1.0 \\ & \qquad C_{\text{red} } = l + (((C_{\text{red} } -l) \times (1 – l))/(x – l))\\ & \qquad C_{\text{green} } = l + (((C_{\text{green} } -l) \times (1 – l))/(x – l))\\ & \qquad C_{\text{blue} } = l + (((C_{\text{blue} } -l) \times (1 – l))/(x – l))\\ & \text{return} \space C \end{align}\)
\(\text{Sat}(C) = \text{max}(C_{\text{red}}, C_{\text{green}}, C_{\text{blue}}) - \text{min}(C_{\text{red}}, C_{\text{green}}, C_{\text{blue}})\)
下标min、mid 和max(在下一个函数中)指的是进入函数时具有最小值、中间值和最大值的颜色分量。
\(\begin{align} \text{SetSat}&(C, s) \\ & \text{if} \space C_{\text{max}} \gt C_{\text{min}} \\ & \qquad C_{\text{min}} = (((C_{\text{mid}} - C_{\text{min}}) \times s)/(C_{\text{max}} - C_{\text{min}})) \\ & \qquad C_{\text{max}} = s \\ & \text{else} \\ & \qquad C_{\text{mid}} = C_{\text{max}} = 0.0 \\ & C_{\text{min}} = 0.0 \\ & \text{return} \space C \end{align}\)
名称 | 结果 |
---|---|
色调(Hue) | \(B( C_b , C_s ) = \text{SetLum}(\text{SetSat}(C_s, \text{Sat}(C_b)), \text{Lum}(C_b))\) 注释 1 使用源颜色的色调以及背景颜色的饱和度和亮度创建颜色。 |
饱和度(Saturation) | \(B( C_b , C_s ) = \text{SetLum}(\text{SetSat}(C_b, \text{Sat}(C_s)), \text{Lum}(C_b))\) 注 2 创建一种饱和度与源颜色相同、色调和亮度与背景颜色相同的颜色。使用此模式在纯灰色(无饱和度)的背景区域进行绘画不会产生任何变化。 |
颜色(Color) | \(B( C_b , C_s ) = \text{SetLum}(C_s, \text{Lum}(C_b))\) 注 3 使用源颜色的色调和饱和度以及背景颜色的亮度创建颜色。这保留了背景的灰度,并且对于为单色图像着色或为彩色图像着色非常有用。 |
亮度(Luminosity) | \(B( C_b , C_s ) = \text{SetLum}(C_b, \text{Lum}(C_s))\) 注 4 创建一种具有源颜色亮度和背景颜色色调和饱和度的颜色。这会产生与颜色模式相反的效果。 |
本子条款中的公式适用于 RGB 空间。CMYK 空间(包括 DeviceCMYK 和 ICCBased 校准的 CMYK 空间)中的混合应按以下方式处理:
- C、M 和 Y 分量应按通常方式转换为其互补的 R、G 和 B 分量。上述公式应应用于 RGB 颜色值。结果应转换回 C、M 和 Y。
- 对于 K 分量,结果应为 色调、饱和度 和 颜色 混合模式的 \(C_b\) 的 K 分量;对于 亮度 混合模式,结果应为 \(C_s\) 的 K 分量。
In principle, any function of the backdrop and source colours that yields another colour, \(C_r\), for the result may be used as a blend function \(B(C_b , C_s)\), in the compositing formula to customize the blending operation. PDF defines a standard set of named blend functions, or blend modes, listed in Tables 136 and 137. Figures L.18 and L.19 in Annex L illustrate the resulting visual effects for RGB and CMYK colours, respectively.
A blend mode is termed separable if each component of the result colour is completely determined by the corresponding components of the constituent backdrop and source colours—that is, if the blend mode function B is applied separately to each set of corresponding components:
\(c_r = B(c_b, c_s)\)
where the lowercase variables \(c_r\), \(c_b\) , and \(c_s\) denote corresponding components of the colours \(C_r\) , \(C_b\) , and \(C_s\) , expressed in additive form. A separable blend mode may be used with any colour space, since it applies independently to any number of components. Only separable blend modes shall be used for blending spot colours.
NOTE 1
Theoretically, a blend mode could have a different function for each colour component and still be separable; however, none of the standard PDF blend modes have this property.
Table 136 lists the standard separable blend modes available in PDF and the algorithms/formulas that shall be used in the calculation of blended colours.
Name | Result |
---|---|
Normal | \(B ( c_b , c_s ) = c_s\) NOTE Selects the source colour, ignoring the backdrop. |
Compatible | Same as Normal. This mode exists only for compatibility and should not be used. |
Multiply | \(B ( c_b , c_s ) = c_b \times c_s\) NOTE 1 Multiplies the backdrop and source colour values. NOTE 2 The result colour is always at least as dark as either of the two constituent colours. Multiplying any colour with black produces black; multiplying with white leaves the original colour unchanged. Painting successive overlapping objects with a colour other than black or white produces progressively darker colours. |
Screen | \(\begin{align} B(c_b,c_s) &= 1-[(1-c_b)\times (1-c_s)]\\ &= c_b + c_s -(c_b \times c_s) \end{align}\) NOTE 3 Multiplies the complements of the backdrop and source colour values, then complements the result. NOTE 4 The result colour is always at least as light as either of the two constituent colours. Screening any colour with white produces white; screening with black leaves the original colour unchanged. The effect is similar to projecting multiple photographic slides simultaneously onto a single screen. |
Overlay | \(B(c_b, c_s) = \text{HardLight}(c_s, c_b)\) NOTE 5 Multiplies or screens the colours, depending on the backdrop colour value. Source colours overlay the backdrop while preserving its highlights and shadows. The backdrop colour is not replaced but is mixed with the source colour to reflect the lightness or darkness of the backdrop. |
Darken | \(B ( c_b , c_s ) = \text{min}(c_b, c_s)\) NOTE 6 Selects the darker of the backdrop and source colours. NOTE 7 The backdrop is replaced with the source where the source is darker; otherwise, it is left unchanged. |
Lighten | \(B ( c_b , c_s ) = \text{max}(c_b, c_s)\) NOTE 8 Selects the lighter of the backdrop and source colours. NOTE 9 The backdrop is replaced with the source where the source is lighter; otherwise, it is left unchanged. |
ColorDodge | \(B(c_b, c_s) = \begin{cases} \text{min}(1, c_b/(1-c_s)) & \text{if} \space c_s \lt 1 \\ 1 & \text{if} \space c_s = \end{cases}\) NOTE 10 Brightens the backdrop colour to reflect the source colour. Painting with black produces no changes. |
ColorBurn | \(B(c_b, c_s) = \begin{cases} 1 - \text{min}(1, (1-c_b)/c_s) & \text{if} \space c_s \gt 0 \\ 0 & \text{if} \space c_s = \end{cases}\) NOTE 11 Darkens the backdrop colour to reflect the source colour. Painting with white produces no change. |
HardLight | \(B(c_b, c_s) = \begin{cases} \text{Multiply}(c_b, 2 \times c_s) & \text{if} \space c_s \le 0.5 \\ \text{Screen}(c_b, 2\times c_s - 1) & \text{if} \space c_s \gt 0.5 \end{cases}\) NOTE 12 Multiplies or screens the colours, depending on the source colour value. The effect is similar to shining a harsh spotlight on the backdrop. |
SoftLight | \(B(c_b, c_s) = \begin{cases} c_b - (1-2\times c_s) \times c_b \times (1-c_b) & \text{if} \space c_s \le 0.5 \\ c_b + (2 \times c_s - 1) \times (D(c_b) - c_b) & \text{if} \space c_s \gt 0.5 \end{cases}\) where \(D(x) = \begin{cases} ((16 \times x - 12) \times x + 4) \times x & \text{if} \space x \le 0.25 \\ \sqrt{x} & \text{if} \space x \gt 0.25 \end{cases}\) NOTE 13 Darkens or lightens the colours, depending on the source colour value. The effect is similar to shining a diffused spotlight on the backdrop. |
Difference | \(B(c_b,c_s) = |c_b - c_s|\) NOTE 14 Subtracts the darker of the two constituent colours from the lighter colour: NOTE 15 Painting with white inverts the backdrop colour; painting with black produces no change. |
Exclusion | \(B ( c_b , c_s ) = c_b + c_s - 2 \times c_b \times c_s\) NOTE 16 Produces an effect similar to that of the Difference mode but lower in contrast. Painting with white inverts the backdrop colour; painting with black produces no change. |
Table 137 lists the standard nonseparable blend modes. Since the nonseparable blend modes consider all colour components in combination, their computation depends on the blending colour space in which the components are interpreted. They may be applied to all multiple-component colour spaces that are allowed as blending colour spaces (see “Blending Colour Space”).
NOTE 2
All of these blend modes conceptually entail the following steps:
a) Convert the backdrop and source colours from the blending colour space to an intermediate HSL (hue-saturation-luminosity) representation.
b) Create a new colour from some combination of hue, saturation, and luminosity components selected from the backdrop and source colours.
c) Convert the result back to the original (blending) colour space.
However, the following formulas given do not actually perform these conversions. Instead, they start with whichever colour (backdrop or source) is providing the hue for the result; then they adjust this colour to have the proper saturation and luminosity.
The nonseparable blend mode formulas make use of several auxiliary functions. These functions operate on colours that are assumed to have red, green, and blue components. Blending of CMYK colour spaces requires special treatment, as described in this sub-clause.
These functions shall have the following definitions:
\(\text{Lum}(C) = 0.3 \times C_{red} + 0.59 \times C_{green} + 0.11 \times C_{blue}\)
\(\begin{align} \text{SetLum}&(C, 1) \\ & \text{let} \space d = 1 - \text{Lum}(C) \\ & C_{\text{red} } = C_{\text{red} } + d \\ & C_{\text{green} } = C_{\text{green} } + d \\ & C_{\text{blue} } = C_{\text{blue} } + d \\ & \text{returnClipColor}(C) \end{align}\)
\(\begin{align} \text{ClipColor}&(C) \\ & \text{let} \space l = \text{Lum}(C) \\ & \text{let} \space n = \text{min}(C_{\text{red} }, C_{\text{green} }, C_{\text{blue} }) \\ & \text{let} \space x = \text{max}(C_{\text{red} }, C_{\text{green} }, C_{\text{blue} }) \\ & if \space n \lt 0.0 \\ & \qquad C_{\text{red} } = l + (((C_{\text{red} } -l) \times l)/(l-n))\\ & \qquad C_{\text{green} } = l + (((C_{\text{green} } -l) \times l)/(l-n))\\ & \qquad C_{\text{blue} } = l + (((C_{\text{blue} } -l) \times l)/(l-n))\\ & if \space n \gt 1.0 \\ & \qquad C_{\text{red} } = l + (((C_{\text{red} } -l) \times (1 – l))/(x – l))\\ & \qquad C_{\text{green} } = l + (((C_{\text{green} } -l) \times (1 – l))/(x – l))\\ & \qquad C_{\text{blue} } = l + (((C_{\text{blue} } -l) \times (1 – l))/(x – l))\\ & \text{return} \space C \end{align}\)
\(\text{Sat}(C) = \text{max}(C_{\text{red}}, C_{\text{green}}, C_{\text{blue}}) - \text{min}(C_{\text{red}}, C_{\text{green}}, C_{\text{blue}})\)
The subscripts min, mid, and max (in the next function) refer to the colour components having the minimum, middle, and maximum values upon entry to the function.
\(\begin{align} \text{SetSat}&(C, s) \\ & \text{if} \space C_{\text{max}} \gt C_{\text{min}} \\ & \qquad C_{\text{min}} = (((C_{\text{mid}} - C_{\text{min}}) \times s)/(C_{\text{max}} - C_{\text{min}})) \\ & \qquad C_{\text{max}} = s \\ & \text{else} \\ & \qquad C_{\text{mid}} = C_{\text{max}} = 0.0 \\ & C_{\text{min}} = 0.0 \\ & \text{return} \space C \end{align}\)
Name | Result |
---|---|
Hue | \(B( C_b , C_s ) = \text{SetLum}(\text{SetSat}(C_s, \text{Sat}(C_b)), \text{Lum}(C_b))\) NOTE 1 Creates a colour with the hue of the source colour and the saturation and luminosity of the backdrop colour. |
Saturation | \(B( C_b , C_s ) = \text{SetLum}(\text{SetSat}(C_b, \text{Sat}(C_s)), \text{Lum}(C_b))\) NOTE 2 Creates a colour with the saturation of the source colour and the hue and luminosity of the backdrop colour. Painting with this mode in an area of the backdrop that is a pure gray (no saturation) produces no change. |
Color | \(B( C_b , C_s ) = \text{SetLum}(C_s, \text{Lum}(C_b))\) NOTE 3 Creates a colour with the hue and saturation of the source colour and the luminosity of the backdrop colour. This preserves the gray levels of the backdrop and is useful for colouring monochrome images or tinting colour images. |
Luminosity | \(B( C_b , C_s ) = \text{SetLum}(C_b, \text{Lum}(C_s))\) NOTE 4 Creates a colour with the luminosity of the source colour and the hue and saturation of the backdrop colour. This produces an inverse effect to that of the Color mode. |
The formulas in this sub-clause apply to RGB spaces. Blending in CMYK spaces (including both DeviceCMYK and ICCBased calibrated CMYK spaces) shall be handled in the following way:
- The C, M, and Y components shall be converted to their complementary R, G, and B components in the usual way. The preceding formulas shall be applied to the RGB colour values. The results shall be converted back to C, M, and Y.
- For the K component, the result shall be the K component of \(C_b\) for the Hue, Saturation, and Color blend modes; it shall be the K component of \(C_s\) for the Luminosity blend mode.
11.3.6 Alpha 的解释¶
Interpretation of Alpha
颜色合成公式
\(C_r = \left ( 1- \frac{\alpha _s}{\alpha _r} \right ) \times C_b + \frac{\alpha _s}{\alpha _r} \times [(1 - \alpha _b) \times C_s + \alpha_b \times B(C_b, C_s)]\)
该公式生成的结果颜色是背景色、源色以及混合项 \(B(C_b, C_s)\) 的加权平均值,权重由背景色和源色的透明度(\(\alpha_b\) 和 \(\alpha_s\))决定。对于最简单的混合模式 正常模式(Normal),其定义为:
\(B(c_b, c_s) = c_s\)
此时,合成公式简化为背景色和源色的简单加权平均,由背景色和源色的透明度值控制。对于更复杂的混合函数,背景色和源色的透明度决定了混合模式的效果是完全实现,还是通过与背景色和源色混合而减弱。
结果透明度 \(\alpha_r\) 实际上是一个计算结果,具体描述见 11.3.7 节「形状与不透明度计算」。结果颜色应根据结果透明度进行归一化处理,以确保在后续的合成操作中,该颜色和透明度的组合能够正确表示颜色的贡献。
注 1
如果 \(\alpha_r\) 为零,则结果颜色未定义。
注 2
上述公式是对以下公式的简化形式,后者更直观地展示了背景色、源色和混合颜色的相对贡献:
\(\alpha_r \times C_r = [(1 - \alpha _s) \times \alpha _b \times C_b] + [(1 - \alpha _b) \times \alpha _s \times C_s] + [\alpha _b \times \alpha _s \times B(C_b, C_s)]\)
(该简化基于透明度合成公式,具体内容见下一小节。)因此,从数学上讲,背景色和源色的透明度分别控制背景色和源色的影响,而它们的乘积控制混合函数的影响。当 \(\alpha_s = 0.0\) 或 \(\alpha_b = 0.0\) 时,混合模式不会产生任何效果;当 \(\alpha_s = 1.0\) 且 \(\alpha_b = 1.0\) 时,混合模式的效果达到最大。
The colour compositing formula
\(C_r = \left ( 1- \frac{\alpha _s}{\alpha _r} \right ) \times C_b + \frac{\alpha _s}{\alpha _r} \times [(1 - \alpha _b) \times C_s + \alpha_b \times B(C_b, C_s)]\)
produces a result colour that is a weighted average of the backdrop colour, the source colour, and the blended \(B (C_b , C_s )\) term, with the weighting determined by the backdrop and source alphas \(α_β\) and \(α_s\) . For the simplest blend mode, Normal, defined by
\(B(c_b, c_s) = c_s\)
the compositing formula collapses to a simple weighted average of the backdrop and source colours, controlled by the backdrop and source alpha values. For more interesting blend functions, the backdrop and source alphas control whether the effect of the blend mode is fully realized or is toned down by mixing the result with the backdrop and source colours.
The result alpha, \(α_ρ\) , actually represents a computed result, described in 11.3.7, "Shape and Opacity Computations." The result colour shall be normalized by the result alpha, ensuring that when this colour and alpha are subsequently used together in another compositing operation, the colour’s contribution is correctly represented.
NOTE 1
If \(α_ρ\) is zero, the result colour is undefined.
NOTE 2
The preceding formula represents a simplification of the following formula, which presents the relative contributions of backdrop, source, and blended colours in a more straightforward way:
\(\alpha_r \times C_r = [(1 - \alpha _s) \times \alpha _b \times C_b] + [(1 - \alpha _b) \times \alpha _s \times C_s] + [\alpha _b \times \alpha _s \times B(C_b, C_s)]\)
(The simplification requires a substitution based on the alpha compositing formula, which is presented in the next sub-clause.) Thus, mathematically, the backdrop and source alphas control the influence of the backdrop and source colours, respectively, while their product controls the influence of the blend function. An alpha value of \(α_s = 0.0\) or \(α_β = 0.0\) results in no blend mode effect; setting \(α_s = 1.0\) and \(α_β = 1.0\) results in maximum blend mode effect.
11.3.7 形状和不透明度计算¶
Shape and Opacity Computations
11.3.7.1 概述¶
General
如前所述,控制合成过程的透明度值应定义为形状和透明度的乘积:
\(\begin{align} &\alpha _{_b} = f_{_b} \times q_{_b} \\ &\alpha _{_r} = f_{_r} \times q_{_r} \\ &\alpha _{_s} = f_{_s} \times q_{_s} \end{align}\)
本小节分别讨论各种形状值和透明度值。再次提醒,从概念上讲,这些值是为页面上的每个点计算的。
As stated earlier, the alpha values that control the compositing process shall be defined as the product of shape and opacity:
\(\begin{align} &\alpha _{_b} = f_{_b} \times q_{_b} \\ &\alpha _{_r} = f_{_r} \times q_{_r} \\ &\alpha _{_s} = f_{_s} \times q_{_s} \end{align}\)
This sub-clause examines the various shape and opacity values individually. Once again, keep in mind that conceptually these values are computed for every point on the page.
11.3.7.2 源形状和不透明度¶
Source Shape and Opacity
形状和不透明度值可能来自多个来源。透明度模型为每种值提供了三个独立的来源。然而,PDF 表示法对独立指定所有这些来源的能力施加了一些限制(参见「指定形状和不透明度」)。
- 对象形状 基本对象(如描边、填充和文本)具有固有形状,其值在对象内部为 1.0,在外部为 0.0。类似地,带有显式蒙版的图像(参见「显式蒙版」)在未蒙版部分形状值为 1.0,在蒙版部分形状值为 0.0。组对象的形状是其包含对象形状的并集。
注 1
从数学上讲,基本对象具有“硬”边缘,在每个点的形状值为 0.0 或 1.0。然而,当这些对象被光栅化为设备像素时,边界沿线的形状值可能会进行抗锯齿处理,取分数值表示这些像素的部分覆盖。执行此类抗锯齿时,重要的是将分数覆盖视为形状而非不透明度。
- 蒙版形状 合成对象时,形状值可以从一个独立于对象本身的附加来源(或软蒙版)获取,如 11.5 节「软蒙版」所述。
注 2
使用软蒙版修改对象或组的形状(称为软裁剪)可以产生效果,例如对象与其背景之间的渐变过渡,如暗角效果。
- 恒定形状 源形状可以在每个点通过一个标量形状常数进行修改。
注 3
这只是一种便利方式,因为可以通过一个值处处相同的形状蒙版实现相同的效果。
-
对象不透明度 基本对象在所有位置的不透明度均为 1.0。组对象的不透明度是其包含的所有对象不透明度计算结果的组合。
-
蒙版不透明度 不透明度值(类似于形状值)可以由一个独立于被合成对象的软蒙版提供。
-
恒定不透明度 源不透明度可以在每个点通过一个标量不透明度常数进行修改。
注 4
将此值视为“当前不透明度”是有用的,类似于绘制基本对象时使用的当前颜色。
所有形状和不透明度输入的值应在 0.0 到 1.0(含)范围内,默认值为 1.0。
三个形状输入相乘,生成一个称为源形状的中间值:
三个不透明度输入相乘,生成一个称为源不透明度的中间值:
其中变量的含义如下表所示:
变量 | 含义 |
---|---|
\(f_{_s}\) | 源形状 |
\(f_{_j}\) | 对象形状 |
\(f_{_m}\) | 蒙版形状 |
\(f_{_k}\) | 恒定形状 |
\(q_{_s}\) | 源不透明度 |
\(q_{_j}\) | 对象不透明度 |
\(q_{_m}\) | 蒙版不透明度 |
\(q_{_k}\) | 恒定不透明度 |
注 5
这些输入的效果是,随着输入值的减小,绘制操作变得更加透明。
当对象使用平铺图案绘制时,对象内部点的对象形状和对象不透明度由图案中对应点的形状和不透明度决定,而不是在所有位置均为 1.0(参见「图案和不透明度」)。
Shape and opacity values may come from several sources. The transparency model provides for three independent sources for each. However, the PDF representation imposes some limitations on the ability to specify all of these sources independently (see “Specifying Shape and Opacity”).
- Object shape. Elementary objects such as strokes, fills, and text have an intrinsic shape, whose value shall be 1.0 for points inside the object and 0.0 outside. Similarly, an image with an explicit mask (see “Explicit Masking”) has a shape that shall be 1.0 in the unmasked portions and 0.0 in the masked portions. The shape of a group object shall be the union of the shapes of the objects it contains.
NOTE 1
Mathematically, elementary objects have “hard” edges, with a shape value of either 0.0 or 1.0 at every point. However, when such objects are rasterized to device pixels, the shape values along the boundaries may be anti-aliased, taking on fractional values representing fractional coverage of those pixels. When such anti- aliasing is performed, it is important to treat the fractional coverage as shape rather than opacity.
- Mask shape. Shape values for compositing an object may be taken from an additional source, or soft mask, independent of the object itself, as described in 11.5, "Soft Masks."
NOTE 2
The use of a soft mask to modify the shape of an object or group, called soft clipping, can produce effects such as a gradual transition between an object and its backdrop, as in a vignette.
- Constant shape. The source shape may be modified at every point by a scalar shape constant.
NOTE 3
This is merely a convenience, since the same effect could be achieved with a shape mask whose value is the same everywhere.
- Object opacity. Elementary objects have an opacity of 1.0 everywhere. The opacity of a group object shall be the result of the opacity computations for all of the objects it contains.
- Mask opacity. Opacity values, like shape values, may be provided by a soft mask independent of the object being composited.
- Constant opacity. The source opacity may be modified at every point by a scalar opacity constant.
NOTE 4
It is useful to think of this value as the “current opacity,” analogous to the current colour used when painting elementary objects.
All of the shape and opacity inputs shall have values in the range 0.0 to 1.0 (inclusive), with a default value of 1.0.
The three shape inputs shall be multiplied together, producing an intermediate value called the source shape.
\(f_{_s} = f_{_j} \times f_{_m} \times f_{_k}\)
The three opacity inputs shall be multiplied together, producing an intermediate value called the source opacity.
\(q_{_s} = q_{_j} \times q_{_m} \times q_{_k}\)
Where the variables have the meanings shown in Table 138.
Variable | Meaning |
---|---|
\(f_{_s}\) | Source shape |
\(f_{_j}\) | Object shape |
\(f_{_m}\) | Mask shape |
\(f_{_k}\) | Constant shape |
\(q_{_s}\) | Source opacity |
\(q_{_j}\) | Object opacity |
\(q_{_m}\) | Mask opacity |
\(q_{_k}\) | Constant opacity |
NOTE 5
The effect of each of these inputs is that the painting operation becomes more transparent as the input values decreases.
When an object is painted with a tiling pattern, the object shape and object opacity for points in the object’s interior are determined by those of corresponding points in the pattern, rather than being 1.0 everywhere (see “Patterns and Transparency”).
11.3.7.3 结果形状和不透明度¶
Result Shape and Opacity
除了结果颜色外,绘制操作还需计算关联的结果形状和结果不透明度。这些计算基于联合函数(Union):
其中,\(b\) 和 \(s\) 分别为待合成的背景值与源值。
注 1
这是对不透明形状的传统联合概念的推广,可视为“反转乘法”——输入和输出取补数后再相乘。结果趋向于 1.0:若任一输入为 1.0,结果必为 1.0。
结果形状与不透明度由以下公式给出:
其中变量定义如下表所示:
变量 | 含义 |
---|---|
\(f_r\) | 结果形状 |
\(f_b\) | 背景形状 |
\(f_s\) | 源形状 |
\(q_r\) | 结果不透明度 |
\(q_b\) | 背景不透明度 |
\(q_s\) | 源不透明度 |
公式解释:
- 结果形状 \(f_r\) 是背景形状 \(f_b\) 与源形状 \(f_s\) 的并集。
- 结果不透明度 \(q_r\) 是背景不透明度 \(q_b\) 与源不透明度 \(q_s\) 的加权并集(权重为各自形状),再通过结果形状 \(f_r\) 归一化。
注 2
由于 \(\alpha\)(透明度)等于形状与不透明度的乘积,可直接推导出:
此公式可在无需独立形状与不透明度时直接使用。
In addition to a result colour, the painting operation also shall compute an associated result shape and result opacity. These computations shall be based on the union function
\(\begin{align} \text{Union}(b, s) &= 1 - [(1-b) \times (1-s)] \\ &=b + s - (b \times s) \end{align}\)
where b and s shall be the backdrop and source values to be composited.
NOTE 1
This is a generalization of the conventional concept of union for opaque shapes, and it can be thought of as an “inverted multiplication”—a multiplication with the inputs and outputs complemented. The result tends toward 1.0: if either input is 1.0, the result is 1.0.
The result shape and opacity shall be given by
\(\begin{align} & f_r = \text{Union}(f_b, f_s) \\ \\ & q_r = \frac{\text{Union}(f_b \times q_b, f_s \times q_s) }{f_r} \end{align}\)
where the variables have the meanings shown in Table 139.
Variable | Meaning |
---|---|
\(f_r\) | Result shape |
\(f_b\) | Backdrop shape |
\(f_s\) | Source shape |
\(q_r\) | Result opacity |
\(q_b\) | Backdrop opacity |
\(q_s\) | Source opacity |
These formulas shall be interpreted as follows:
- The result shape shall be the union of the backdrop and source shapes.
- The result opacity shall be the union of the backdrop and source opacities, weighted by their respective shapes. The result shall then be divided by (normalized by) the result shape.
NOTE 2
Since alpha is just the product of shape and opacity, it can easily be shown that
\(\alpha _r = \text{Union}(\alpha _b, \alpha _s)\)
This formula can be used whenever the independent shape and opacity are not needed.
11.3.8 基本合成计算总结¶
Summary of Basic Compositing Computations
本子条款是对本节所述所有计算过程的总结。这些计算过程按变量先定义后使用的原则进行编排,部分公式经过重新排列以简化表达式。具体变量含义请参见表 135、138 和 139。
\(\begin{align} \text{Union}(b,s) &= 1 - [(1 - b) \times (1 - s)] \\ & = b + s - (b \times s) \end{align}\)
\(\begin{align} &f_s = f_j \times f_m \times f_k \\ &q_s = q_j \times q_m \times q_k \\ &f_r = \text{Union}(f_b, f_s) \\\\ &\alpha_b = f_b \times q_b \\ &\alpha_s = f_s \times q_s \\ &\alpha_r = \text{Union}(\alpha_b, \alpha_s)\\\\ &q_r = \frac{\alpha _r}{f_r} \\\\ &C_r = \left ( 1 - \frac{\alpha _s}{\alpha _r} \right ) \times C_b + \frac{\alpha _s}{\alpha _r} \times [(1 - \alpha _b) \times C_s + \alpha _b \times B(C_b, C_s)] \end{align}\)
This sub-clause is a summary of all the computations presented in this sub-clause. They are given in an order such that no variable is used before it is computed; also, some of the formulas have been rearranged to simplify them. See Tables 135, 138, and 139 for the meanings of the variables used in these formulas.
\(\begin{align} \text{Union}(b,s) &= 1 - [(1 - b) \times (1 - s)] \\ & = b + s - (b \times s) \end{align}\)
\(\begin{align} &f_s = f_j \times f_m \times f_k \\ &q_s = q_j \times q_m \times q_k \\ &f_r = \text{Union}(f_b, f_s) \\\\ &\alpha_b = f_b \times q_b \\ &\alpha_s = f_s \times q_s \\ &\alpha_r = \text{Union}(\alpha_b, \alpha_s)\\\\ &q_r = \frac{\alpha _r}{f_r} \\\\ &C_r = \left ( 1 - \frac{\alpha _s}{\alpha _r} \right ) \times C_b + \frac{\alpha _s}{\alpha _r} \times [(1 - \alpha _b) \times C_s + \alpha _b \times B(C_b, C_s)] \end{align}\)