11.5 软面罩¶
Soft Masks
11.5.1 概述¶
General
如前面的小节所述,在合成对象时使用的形状和不透明度值可能包含称为蒙版形状(\(f_m\))和蒙版不透明度(\(q_m\))的组成部分,这些值可以从 PDF 文件中独立于对象的一个源提供。这样一个独立源被称为软蒙版,它定义的值可能在页面的不同点上有所不同。
注 1
“软”这个词强调,在给定点的蒙版值不仅限于 0.0 或 1.0,还可以取中间分数值。这种蒙版通常是提供位置相关不透明度值的唯一方法,因为基本对象本身没有固有不透明度。
注 2
用作形状值源的蒙版也被称为软裁剪,这是类比于不透明成像模型中的“硬”裁剪路径(见第 8.5.4 节)。软裁剪是硬裁剪的推广:硬裁剪可以被表示为一个软裁剪,在裁剪路径内部形状值为 1.0,在外部为 0.0。在硬裁剪路径内部,源对象的颜色替换背景;在外部,背景保持不变地显示出来。相比之下,在软裁剪中,可以在对象和其背景之间创建一个渐变过渡,就像在晕映效果中那样。
蒙版可以通过创建一个透明度组并将对象绘制到其中来定义,从而以通常的方式定义颜色、形状和不透明度。然后,可以使用以下小节描述的两种方法之一,从得到的组中导出蒙版 。
As stated in earlier sub-clauses, the shape and opacity values used in compositing an object may include components called the mask shape (\(f_m\)) and mask opacity (\(q_m\)), which may be supplied in a PDF file from a source independent of the object. Such an independent source, called a soft mask, defines values that may vary across different points on the page.
NOTE 1
The word soft emphasizes that the mask value at a given point is not limited to just 0.0 or 1.0 but can take on intermediate fractional values as well. Such a mask is typically the only means of providing position-dependent opacity values, since elementary objects do not have intrinsic opacity of their own.
NOTE 2
A mask used as a source of shape values is also called a soft clip, by analogy with the “hard” clipping path of the opaque imaging model (see Section 8.5.4). The soft clip is a generalization of the hard clip: a hard clip can be represented as a soft clip having shape values of 1.0 inside and 0.0 outside the clipping path. Everywhere inside a hard clipping path, the source object’s colour replaces the backdrop; everywhere outside, the backdrop shows through unchanged. With a soft clip, by contrast, a gradual transition can be created between an object and its backdrop, as in a vignette.
A mask may be defined by creating a transparency group and painting objects into it, thereby defining colour, shape, and opacity in the usual way. The resulting group may then be used to derive the mask in either of two ways, as described in the following sub-clauses.
11.5.2 从 Group Alpha 导出 Soft Mask¶
Deriving a Soft Mask from Group Alpha
在定义软蒙版的第一种方法中,首先应使用常规公式计算透明度组 G 的颜色、形状和不透明度:
\(〈 C, f, α 〉 = \text{合成} ( C_0 , α_0 , G )\)
其中 \(C_0\) 和 \(α_0\) 表示一个任意的背景,其值不影响最终结果。C、f 和 α 的计算结果分别是该组的颜色、形状和不透明度(已排除背景的影响)。
然后,每个点的蒙版值将从该组的不透明度中得出。不透明度值将通过单独指定的传递函数进行处理,从而可以对蒙版效果进行自定义。
注
由于在这种情况下不使用组的颜色,因此无需计算它 。
In the first method of defining a soft mask, the colour, shape, and opacity of a transparency group G shall be first computed by the usual formula
\(〈 C, f, α 〉 = \text{Composite} ( C_0 , α_0 , G )\)
where \(C_0\) and \(α_0\) represent an arbitrary backdrop whose value does not contribute to the eventual result. The C, f, and α results shall be the group’s colour, shape, and alpha, respectively, with the backdrop factored out.
The mask value at each point shall then be derived from the alpha of the group. The alpha value shall be passed through a separately specified transfer function, allowing the masking effect to be customized.
NOTE
Since the group’s colour is not used in this case, there is no need to compute it.
11.5.3 根据组光度导出软蒙版¶
Deriving a Soft Mask from Group Luminosity
从透明度组派生软蒙版的第二种方法应从将该组与指定颜色的完全不透明背景合成开始。然后,任何给定点的蒙版值应定义为所得颜色的亮度。
注 1
这允许从使用普通绘制操作符绘制的任意图稿的形状和颜色派生蒙版。
用于从组 G 创建蒙版的颜色 C 应由以下公式定义:
\(\begin{align} \left \langle C_g, f_g, \alpha _g \right \rangle &= \text{合成}(C_0, 1, G) \\ C &= (1 - \alpha _g) \times C_0 + \alpha _g \times C_g \end{align}\)
其中 \(C_0\) 是选定的背景颜色。
G 可以是任意类型的组——隔离或非隔离、挖空或非挖空——每种情况都会对 C 结果产生不同的效果。然后应根据组的颜色空间,通过以下方式之一将颜色 C 转换为亮度:
• 对于基于 CIE 的空间,转换到 CIE 1931 XYZ 空间并使用 Y 分量作为亮度。这会产生一个色彩学上正确的亮度。
注 2
在 PDF CalRGB 空间的情况下,公式为:
\(Y = Y_{A} \times A^{G_R} + Y_B \times B^{G_G} + Y_C \times C^G\)
使用颜色空间字典的 Gamma 和 Matrix 条目的分量(见 “基于 CIE 的色彩空间”中的 表 64)。类似的计算适用于其他基于 CIE 的色彩空间。
• 对于设备颜色空间,通过实现定义的方式将颜色转换为 DeviceGray ,并使用得到的灰度值作为亮度,不进行伽马或其他颜色校正。
注 3
这种方法并不声称色彩学上正确;它只是提供了一种数值上简单的方法来生成连续色调的蒙版值。以下是从 DeviceRGB 和 DeviceCMYK 转换的公式:
\(\begin{align} Y = 0.30 &\times R + 0.59 \times G + 0.11 \times B \\ Y = 0.30 &\times (1 - C) \times (1 - K) \\ & + 0.59 \times (1-M)\times (1-K) \\ & + 0.11 \times (1-Y)\times (1-K) \end{align}\)
在此转换之后,结果应通过单独指定的传递函数,允许对蒙版效果进行自定义。
注 4
最有可能有用的背景颜色是黑色,它会导致组形状之外的任何区域在结果蒙版中的亮度值为零。如果将组的内容视为正蒙版,这将产生与形状外部点相关的预期结果 。
The second method of deriving a soft mask from a transparency group shall begin by compositing the group with a fully opaque backdrop of a specified colour. The mask value at any given point shall then be defined to be the luminosity of the resulting colour.
NOTE 1
This allows the mask to be derived from the shape and colour of an arbitrary piece of artwork drawn with ordinary painting operators.
The colour C used to create the mask from a group G shall be defined by
\(\begin{align} \left \langle C_g, f_g, \alpha _g \right \rangle &= \text{Composite}(C_0, 1, G) \\ C &= (1 - \alpha _g) \times C_0 + \alpha _g \times C_g \end{align}\)
where \(C_0\) is the selected backdrop colour.
G may be any kind of group—isolated or not, knockout or not—producing various effects on the C result in each case. The colour C shall then be converted to luminosity in one of the following ways, depending on the group’s colour space:
- For CIE-based spaces, convert to the CIE 1931 XYZ space and use the Y component as the luminosity. This produces a colourimetrically correct luminosity.
NOTE 2
In the case of a PDF CalRGB space, the formula is
\(Y = Y_{A} \times A^{G_R} + Y_B \times B^{G_G} + Y_C \times C^G\)
using components of the Gamma and Matrix entries of the colour space dictionary (see Table 64 in “CIE-Based Colour Spaces”). An analogous computation applies to other CIE-based colour spaces.
- For device colour spaces, convert the colour to DeviceGray by implementation-defined means and use the resulting gray value as the luminosity, with no compensation for gamma or other colour calibration.
NOTE 3
This method makes no pretence of colourimetric correctness; it merely provides a numerically simple means to produce continuous-tone mask values. The following are formulas for converting from DeviceRGB and DeviceCMYK, respectively:
\(\begin{align} Y = 0.30 &\times R + 0.59 \times G + 0.11 \times B \\ Y = 0.30 &\times (1 - C) \times (1 - K) \\ & + 0.59 \times (1-M)\times (1-K) \\ & + 0.11 \times (1-Y)\times (1-K) \end{align}\)
Following this conversion, the result shall be passed through a separately specified transfer function, allowing the masking effect to be customized.
NOTE 4
The backdrop colour most likely to be useful is black, which causes any areas outside the group’s shape to have zero luminosity values in the resulting mask. If the contents of the group are viewed as a positive mask, this produces the results that would be expected with respect to points outside the shape.