跳转至

11.6 指定 PDF 中的透明度

Specifying Transparency in PDF

11.6.1 概述

General

前面的子条款从抽象层面介绍了透明成像模型,很少提及其在 PDF 中的表示。本子条款描述了可用于在 PDF 中指定透明度的功能。

The preceding sub-clauses have presented the transparent imaging model at an abstract level, with little mention of its representation in PDF. This sub-clause describes the facilities available for specifying transparency in PDF.

11.6.2 指定源颜色和背景颜色

Specifying Source and Backdrop Colours

单个图形对象(定义在“图形对象”中)应作为透明合成的基本对象处理(对文本对象需进行特殊处理,定义在“文本镂空”中)。也就是说,给定对象的整个部分应被视为透明堆栈的一个元素。对象的各个部分不得相互合成,即使它们的描述方式似乎会导致重叠(例如自相交路径、路径的组合填充和描边,或包含重叠或折叠的阴影图案)。颜色合成公式中使用的对象源颜色 \(C_s\) 应以与不透明成像模型中相同的方式指定:通过图形状态中的当前颜色或图像中的源样本。背景颜色 \(C_b\) 应为先前绘制操作的结果。

Single graphics objects, as defined in “Graphics Objects”, shall be treated as elementary objects for transparency compositing purposes (subject to special treatment for text objects, as described in “Text Knockout”). That is, all of a given object shall be considered to be one element of a transparency stack. Portions of an object shall not be composited with one another, even if they are described in a way that would seem to cause overlaps (such as a self-intersecting path, combined fill and stroke of a path, or a shading pattern containing an overlap or fold-over). An object’s source colour \(C_s\) , used in the colour compositing formula, shall be specified in the same way as in the opaque imaging model: by means of the current colour in the graphics state or the source samples in an image. The backdrop colour \(C_b\) shall be the result of previous painting operations.

11.6.3 指定混合色彩空间和混合模式

Specifying Blending Colour Space and Blend Mode

混合色彩空间应为在其中绘制对象的透明度组的属性;其规范在 11.6.6“透明度组 XObjects”中描述。整个页面也应被视为一个组,即 页面组(请参阅“页面组”),具有自己的色彩空间属性。如果没有另行指定,页面组的色彩空间应从输出设备的原生色彩空间继承。

混合模式 \(B (C_b , C_s )\) 应由图形状态中的当前混合模式参数确定(参见“图形状态”),该参数由图形状态参数字典(“图形状态参数字典”)中的 BM 条目指定。其值应为名称对象,指定 11.3.5 “混合模式”中表 136137 中列出的标准混合模式之一,或此类名称的数组。在后一种情况下,应用程序应使用它识别的数组中的第一个混合模式(如果它无法识别任何混合模式,则使用 Normal)。

NOTE

将来可能会引入新的混合模式,并且无法识别这些模式的符合要求的读者应该有合理的回退行为。

当前混合模式应始终适用于印刷色成分;但有时可能适用于专色,详情请参阅 11.7.4.2“混合模式和套印”。

The blending colour space shall be an attribute of the transparency group within which an object is painted; its specification is described in 11.6.6, "Transparency Group XObjects." The page as a whole shall also be treated as a group, the page group (see “Page Group”), with a colour space attribute of its own. If not otherwise specified, the page group’s colour space shall be inherited from the native colour space of the output device.

The blend mode \(B (C_b , C_s )\) shall be determined by the current blend mode parameter in the graphics state (see “Graphics State”), which is specified by the BM entry in a graphics state parameter dictionary ( “Graphics State Parameter Dictionaries”). Its value shall be either a name object, designating one of the standard blend modes listed in Tables 136 and 137 in 11.3.5, "Blend Mode," or an array of such names. In the latter case, the application shall use the first blend mode in the array that it recognizes (or Normal if it recognizes none of them).

NOTE

New blend modes may be introduced in the future, and conforming readers that do not recognize them should have reasonable fallback behavior.

The current blend mode shall always apply to process colour components; but only sometimes may apply to spot colorants, see 11.7.4.2, "Blend Modes and Overprinting," for details.

11.6.4 指定形状和不透明度

Specifying Shape and Opacity

11.6.4.1 概述

General

如在11.3.7.2“源形状和不透明度”中所讨论的,在合成计算中使用的形状(f)和不透明度(q)值应来自以下一个或多个来源:

  • 正在被合成的对象的固有形状\((f_j )\)和不透明度\((q_j )\)
  • 独立于对象本身的单独形状\((f_m )\)或不透明度\((q_m )\)蒙版
  • 在每个点都要添加的标量形状\((f_k )\)或不透明度\((q_k )\)常量

以下小节描述了在 PDF 中应如何指定这些形状和不透明度来源 。

As discussed under 11.3.7.2, "Source Shape and Opacity," the shape (f) and opacity (q) values used in the compositing computation shall come from one or more of the following sources:

  • The intrinsic shape \((f_j )\) and opacity \((q_j )\) of the object being composited
  • A separate shape \((f_m )\) or opacity \((q_m )\) mask independent of the object itself
  • A scalar shape \((f_k )\) or opacity \((q_k )\) constant to be added at every point

The following sub-clauses describe how each of these shape and opacity sources shall be specified in PDF.

11.6.4.2 物体形状和不透明度

Object Shape and Opacity

使用 PDF 绘图操作符绘制的对象的形状值 \(f_j\) 应按以下方式定义:

  • 对于由路径或字形定义,并使用路径绘制操作符或文本显示操作符以单一颜色绘制的对象(“路径绘制操作符”和“文本显示操作符”),形状在路径内部始终为 1.0,在路径外部始终为 0.0。
  • 对于图像(“图像”),形状在图像矩形内部为 1.0,在其外部为 0.0。这可能会通过显式蒙版或色彩键蒙版进一步修改(“显式蒙蔽”和“色彩键遮罩”)。
  • 对于图像蒙版(“模板蒙板”),形状在绘制区域为 1.0,在被遮罩的区域为 0.0。
  • 对于使用平铺图案(“平铺图案”)或底纹图案(“底纹图案”)绘制的对象,形状将进一步受到定义图案的对象的限制(见“图案和透明度”)。
  • 对于使用 sh 操作符绘制的对象(“底纹操作符”),形状在底纹绘制几何形状的边界内为 1.0,在边界外为 0.0,忽略底纹字典中的 Background 条目(见“底纹字典”)。

所有基本对象在任何地方都具有固有不透明度 \(q_j\) 为 1.0。任何期望的小于 1.0 的不透明度应通过不透明蒙版或常量来应用,如下一小节所述 。

The shape value \(f_j\) of an object painted with PDF painting operators shall be defined as follows:

  • For objects defined by a path or a glyph and painted in a uniform colour with a path-painting or text-showing operator (“Path-Painting Operators”, and “Text-Showing Operators”), the shape shall always be 1.0 inside and 0.0 outside the path.
  • For images (“Images”), the shape shall be 1.0 inside the image rectangle and 0.0 outside it. This may be further modified by an explicit or colour key mask (“Explicit Masking” and “Colour Key Masking”).
  • For image masks (“Stencil Masking”), the shape shall be 1.0 for painted areas and 0.0 for masked areas.
  • For objects painted with a tiling pattern (“Tiling Patterns”) or a shading pattern (“Shading Patterns”), the shape shall be further constrained by the objects that define the pattern (see “Patterns and Transparency”).
  • For objects painted with the sh operator (“Shading Operator”), the shape shall be 1.0 inside and 0.0 outside the bounds of the shading’s painting geometry, disregarding the Background entry in the shading dictionary (see “Shading Dictionaries”).

All elementary objects shall have an intrinsic opacity \(q_j\) of 1.0 everywhere. Any desired opacity less than 1.0 shall be applied by means of an opacity mask or constant, as described in the following sub-clauses.

11.6.4.3 蒙版形状和不透明度

Mask Shape and Opacity

在任何 PDF 合成操作中,最多只能提供一个蒙版输入——称为软蒙版alpha 蒙版。蒙版可作为形状(\(f_m\))或不透明度(\(q_m\))值的源,具体取决于图形状态中alpha 源参数的设置(见“图形状态”)。这是一个布尔标志,通过图形状态参数字典中的 AIS(“alpha is shape”,即“alpha 表示形状”)条目来设置(见“图形状态参数字典”):如果软蒙版包含形状值,则为true;如果不透明度,则为false

软蒙版应按以下方式之一指定:

  • 图形状态中的当前软蒙版参数,通过图形状态参数字典中的 SMask 条目设置,包含一个软蒙版字典(见“软蒙版字典”,该字典定义了蒙版的内容。在软蒙版字典的位置可以使用名称 None ,表示不存在软蒙版。在这种情况下,蒙版的形状或不透明度应隐式地在任何地方都为 1.0。
  • 图像 XObject 可能在其图像字典的 SMask 条目中包含自己的软蒙版图像,以子图像 XObject 的形式存在(见“图像字典”)。如果存在此蒙版,则应覆盖图像字典的 Mask 条目指定的任何显式蒙版或色彩键蒙版。图像字典中的任何一种形式的蒙版都将覆盖图形状态中的当前软蒙版。
  • 其数据源为 JPXDecode 过滤器的图像 XObject 可以指定一个 SMaskInData 条目,表明软蒙版嵌入在数据流中(见“JPXDecode 过滤器”)。

图形状态中的当前软蒙版旨在一次仅用于裁剪单个对象(基本对象或透明度组)。如果在绘制两个或更多重叠对象时应用软蒙版,在重叠区域蒙版的效果会自身相乘(挖空组除外),产生的结果形状或不透明度很可能并非预期。若要将软蒙版应用于多个对象,通常最好将这些对象定义为一个透明度组,并将蒙版应用于整个组。这些考虑因素同样适用于当前的 alpha 常量(见下一小节)。

At most one mask input—called a soft mask, or alpha mask—shall be provided to any PDF compositing operation. The mask may serve as a source of either shape (\(f_m\) ) or opacity (\(q_m\) ) values, depending on the setting of the alpha source parameter in the graphics state (see “Graphics State”). This is a boolean flag, set with the AIS (“alpha is shape”) entry in a graphics state parameter dictionary (“Graphics State Parameter Dictionaries”): true if the soft mask contains shape values, false for opacity.

The soft mask shall be specified in one of the following ways:

  • The current soft mask parameter in the graphics state, set with the SMask entry in a graphics state parameter dictionary, contains a soft-mask dictionary (see “Soft-Mask Dictionaries”) defining the contents of the mask. The name None may be specified in place of a soft-mask dictionary, denoting the absence of a soft mask. In this case, the mask shape or opacity shall be implicitly 1.0 everywhere.
  • An image XObject may contain its own soft-mask image in the form of a subsidiary image XObject in the SMask entry of the image dictionary (see “Image Dictionaries”). This mask, if present, shall override any explicit or colour key mask specified by the image dictionary’s Mask entry. Either form of mask in the image dictionary shall override the current soft mask in the graphics state.
  • An image XObject that has a JPXDecode filter as its data source may specify an SMaskInData entry, indicating that the soft mask is embedded in the data stream (see “JPXDecode Filter”).

NOTE

The current soft mask in the graphics state is intended to be used to clip only a single object at a time (either an elementary object or a transparency group). If a soft mask is applied when painting two or more overlapping objects, the effect of the mask multiplies with itself in the area of overlap (except in a knockout group), producing a result shape or opacity that is probably not what is intended. To apply a soft mask to multiple objects, it is usually best to define the objects as a transparency group and apply the mask to the group as a whole. These considerations also apply to the current alpha constant (see the next sub-clause).

11.6.4.4 恒定形状和不透明度

Constant Shape and Opacity

图形状态中的当前 alpha 常量参数(见“图形状态”)应是两个标量值——一个用于描边,另一个用于所有其他绘制操作——在颜色合成公式中用作恒定形状(\(f_k\))或恒定不透明度(\(q_k\))分量。

注 1

此参数类似于绘制基本对象时使用的当前颜色。

在将透明度组的结果绘制到其背景上时,也应应用非描边 alpha 常量。

描边和非描边 alpha 常量分别由图形状态参数字典中的 CAca 条目设置(见“图形状态参数字典”)。如前文对软蒙版所述,图形状态中的 alpha 源标志应决定 alpha 常量是被解释为形状值(true)还是不透明度值(false)。

注 2

在 11.6.4.3 节“蒙版形状和不透明度”末尾的注释同样适用于当前 alpha 常量参数以及当前软蒙版 。

The current alpha constant parameter in the graphics state (see “Graphics State”) shall be two scalar values—one for strokes and one for all other painting operations—to be used for the constant shape (\(f_k\)) or constant opacity (\(q_k\)) component in the colour compositing formulas.

NOTE 1

This parameter is analogous to the current colour used when painting elementary objects.

The nonstroking alpha constant shall also be applied when painting a transparency group’s results onto its backdrop.

The stroking and nonstroking alpha constants shall be set, respectively, by the CA and ca entries in a graphics state parameter dictionary (see “Graphics State Parameter Dictionaries”). As described previously for the soft mask, the alpha source flag in the graphics state shall determine whether the alpha constants are interpreted as shape values (true) or opacity values (false).

NOTE 2

The note at the end of 11.6.4.3, "Mask Shape and Opacity," applies to the current alpha constant parameter as well as the current soft mask.

11.6.5 指定软蒙版

Specifying Soft Masks

11.6.5.1 概述

General

如 11.6.4.3 节“蒙版形状和不透明度”所述,用于合成计算的软蒙版可以通过以下几种方式指定:

  • 作为图形状态中当前软蒙版参数的软蒙版字典;有关更多详细信息,请参阅 11.6.5.2 节“软蒙版字典”。
  • 作为与采样图像关联的软蒙版图像;有关更多详细信息,请参阅 11.6.5.3 节“软蒙版图像”。
  • (PDF 1.5)作为嵌入在 JPEG2000 编码数据中的蒙版通道;有关更多详细信息,请参阅“JPXDecode 过滤器”以及表 89 中的 SMaskInData 条目 。

As noted under 11.6.4.3, "Mask Shape and Opacity," soft masks for use in compositing computations may be specified in one of the following ways:

  • As a soft-mask dictionary in the current soft mask parameter of the graphics state; see 11.6.5.2, "Soft-Mask Dictionaries," for more details.
  • As a soft-mask image associated with a sampled image; see 11.6.5.3, "Soft-Mask Images," for more details.
  • (PDF 1.5) as a mask channel embedded in JPEG2000 encoded data; see “JPXDecode Filter”, and the SMaskInData entry of Table 89 for more details.

11.6.5.2 软掩码词典

Soft-Mask Dictionaries

定义软蒙版最常见的方法是使用软蒙版字典,将其指定为图形状态中的当前软蒙版(见“图形状态”)。表 144 展示了此类字典的内容。

蒙版值应根据 11.5.2 节“从组 alpha 导出软蒙版”和 11.5.3 节“根据组光度导出软蒙版”中描述的两种方法之一,从透明度组的值派生而来。该组应由软蒙版字典中的 G 条目指定的透明度组 XObject(见“透明度组 XObject”)定义。S(子类型)条目应指定使用这两种派生方法中的哪一种:

  • 如果子类型为 Alpha,应评估透明度组 XObject G 以仅计算组 alpha。应忽略组成对象的颜色,并且不执行颜色合成计算。然后将传递函数 TR 应用于计算出的组 alpha 以生成蒙版值。在透明度组的边界框之外,蒙版值是将传递函数应用于输入值 0.0 的结果。
  • 如果子类型为 Luminosity,应将透明度组 XObject G 与完全不透明的背景合成,该背景的颜色由软蒙版字典的 BC 条目在所有位置定义。然后应将计算出的结果颜色转换为单分量光度值,并将传递函数 TR 应用于此光度以生成蒙版值。在透明度组的边界框之外,蒙版值应通过将 BC 颜色转换为光度并将传递函数应用于结果来派生。

蒙版的坐标系统应通过连接透明度组的表单字典(见“表单字典”)中 Matrix 条目指定的变换矩阵与在图形状态中使用 gs 操作符建立软蒙版时当前的变换矩阵来定义。

在定义软蒙版的透明度组 XObject 中,即使在使用软蒙版的组或页面上可用,专色分量也永远不可用。如果组 XObject 的内容流指定了使用专色分量的 SeparationDeviceN 颜色空间,则应替换备用颜色空间(见“分离颜色空间”和“DeviceN 颜色空间”)。

表 143 – 软蒙版字典中的条目
类型
Type 名称 (可选)此字典描述的 PDF 对象的类型;如果存在,对于软蒙版字典应为 Mask
S 名称 (必需)一个子类型,指定用于从 G 条目指定的透明度组派生蒙版值的方法:
Alpha   使用组的计算 alpha,忽略其颜色(见“从组 alpha 导出软蒙版”)。
Luminosity   将组的计算颜色转换为单分量光度值(见“根据组光度导出软蒙版”)。
G (必需)一个透明度组 XObject(见“透明度组 XObject”),用作派生蒙版的 alpha 或颜色值的源。如果子类型 SLuminosity,组属性字典应包含一个 CS 条目,定义执行合成计算的 color space。
BC 数组 (可选)一个分量值数组,指定用作与透明度组 XObject G 合成的背景的颜色。仅在子类型 SLuminosity 时才参考此条目。该数组应由 n 个数字组成,其中 n 是组属性字典中 CS 条目指定的 color space 中的分量数(见“透明度组 XObject”)。默认值:color space 的初始值,表示黑色。
TR 函数或名称 (可选)一个函数对象(见“函数”),指定用于派生蒙版值的传递函数。该函数应接受一个输入,即计算出的组 alpha 或光度(取决于子类型 S 的值),并应返回一个输出,即结果蒙版值。输入应在 0.0 到 1.0 的范围内。计算出的输出应在 0.0 到 1.0 的范围内;如果超出此范围,则应强制转换为最接近的有效值。可以用名称 Identity 代替函数对象来指定恒等函数。默认值:Identity

The most common way of defining a soft mask is with a soft-mask dictionary specified as the current soft mask in the graphics state (see “Graphics State”). Table 144 shows the contents of this type of dictionary.

The mask values shall be derived from those of a transparency group, using one of the two methods described in 11.5.2, "Deriving a Soft Mask from Group Alpha," and 11.5.3, "Deriving a Soft Mask from Group Luminosity." The group shall be defined by a transparency group XObject (see “Transparency Group XObjects”) designated by the G entry in the soft-mask dictionary. The S (subtype) entry shall specify which of the two derivation methods to use:

  • If the subtype is Alpha, the transparency group XObject G shall be evaluated to compute a group alpha only. The colours of the constituent objects shall be ignored and the colour compositing computations shall not be performed. The transfer function TR shall then be applied to the computed group alpha to produce the mask values. Outside the bounding box of the transparency group, the mask value shall be the result of applying the transfer function to the input value 0.0.
  • If the subtype is Luminosity, the transparency group XObject G shall be composited with a fully opaque backdrop whose colour is everywhere defined by the soft-mask dictionary’s BC entry. The computed result colour shall then be converted to a single-component luminosity value, and the transfer function TR shall be applied to this luminosity to produce the mask values. Outside the transparency group’s bounding box, the mask value shall be derived by transforming the BC colour to luminosity and applying the transfer function to the result.

The mask’s coordinate system shall be defined by concatenating the transformation matrix specified by the Matrix entry in the transparency group’s form dictionary (see “Form Dictionaries”) with the current transformation matrix at the moment the soft mask is established in the graphics state with the gs operator.

In a transparency group XObject that defines a soft mask, spot colour components shall never be available, even if they are available in the group or page on which the soft mask is used. If the group XObject’s content stream specifies a Separation or DeviceN colour space that uses spot colour components, the alternate colour space shall be substituted (see “Separation Colour Spaces” and “DeviceN Colour Spaces”).

Table 144 – Entries in a soft-mask dictionary
Key Type Value
Type name (Optional) The type of PDF object that this dictionary describes; if present, shall be Mask for a soft-mask dictionary.
S name (Required) A subtype specifying the method to be used in deriving the mask values from the transparency group specified by the G entry:
Alpha   The group’s computed alpha shall be used, disregarding its colour (see “Deriving a Soft Mask from Group Alpha”). Luminosity   The group’s computed colour shall be converted to a single-component luminosity value (see “Deriving a Soft Mask from Group Luminosity”).
G stream (Required) A transparency group XObject (see “Transparency Group XObjects”) to be used as the source of alpha or colour values for deriving the mask. If the subtype S is Luminosity, the group attributes dictionary shall contain a CS entry defining the colour space in which the compositing computation is to be performed.
BC array (Optional) An array of component values specifying the colour to be used as the backdrop against which to composite the transparency group XObject G. This entry shall be consulted only if the subtype S is Luminosity. The array shall consist of n numbers, where n is the number of components in the colour space specified by the CS entry in the group attributes dictionary (see “Transparency Group XObjects”). Default value: the colour space’s initial value, representing black.
TR function or name (Optional) A function object (see “Functions”) specifying the transfer function to be used in deriving the mask values. The function shall accept one input, the computed group alpha or luminosity (depending on the value of the subtype S), and shall return one output, the resulting mask value. The input shall be in the range 0.0 to 1.0. The computed output shall be in the range 0.0 to 1.0; if it falls outside this range, it shall be forced to the nearest valid value. The name Identity may be specified in place of a function object to designate the identity function. Default value: Identity.

11.6.5.3 软蒙版图像

Soft-Mask Images

定义软蒙版的第二种方法是将软蒙版图像与图像 XObject 关联起来。这是在父 XObject 的图像字典的 SMask 条目中指定的子图像 XObject(见“图像字典”)。此类软蒙版图像的子图像字典中的条目应具有与普通图像 XObject(如“图像字典”中的表 89所述)相同的格式和含义,但需遵循表 145中列出的限制。这种类型的图像字典可能包含一个额外的条目,Matte

当图像与软蒙版图像一起使用时,有时将图像数据与某种称为蒙版颜色的背景颜色预混合是有利的。每个图像样本表示原始源颜色和蒙版颜色的加权平均值,使用相应的蒙版样本作为加权因子。(这是通常称为预乘 alpha的技术的推广。)

如果图像数据是预混合的,则蒙版颜色应由软蒙版图像字典中的 Matte 条目指定(见表 145)。预混合计算针对每个分量独立执行,计算公式为:

\[c' = m + α \times (c - m)\]

其中:

\(c'\) 是图像源数据中要提供的值

\(c\) 是原始图像分量值

\(m\) 是蒙版颜色分量值

\(α\) 是相应的蒙版样本

此计算应使用实际的图像分量值,FilterDecode 变换的效果已经应用。无论颜色空间是加法还是减法,计算方式都相同。

表 145 – 软蒙版图像字典中条目的限制
限制
Type 如果存在,应为 XObject
Subtype 应为 Image
Width 如果存在 Matte 条目(见表 146),应与父图像的 Width 值相同;否则独立于父图像。无论样本是否逐个重合,两个图像都应映射到用户空间中的单位正方形(与所有图像一样)。
Height Width 的考虑因素相同。
ColorSpace 必需;应为 DeviceGray
BitsPerComponent 必需。
Intent 忽略。
ImageMask 应为 false 或不存在。
Mask 应不存在。
SMask 应不存在。
Decode 默认值:[ 0 1 ]。
Interpolate 可选。
Alternates 忽略。
Name 忽略。
StructParent 忽略。
ID 忽略。
OPI 忽略。

表 146 – 软蒙版图像字典中的附加条目
类型
Matte 数组 (可选;PDF 1.4)一个分量值数组,指定父图像中的图像数据应预混合的蒙版颜色。该数组应由 n 个数字组成,其中 n 是父图像的图像字典中 ColorSpace 条目指定的颜色空间中的分量数;这些数字应是该颜色空间中的有效颜色分量。如果此条目不存在,则不应预混合图像数据。

在透明度混合和合成计算中使用预混合图像数据时,结果应与使用原始未混合图像数据且未指定蒙版颜色的情况相同。特别是,混合函数的输入应为原始颜色值。要从 \(c'\) 导出 \(c\),符合标准的阅读器有时可能需要反转之前显示的公式。得到的 \(c\) 值应在图像颜色空间的颜色分量值范围内。

预混合计算应在父图像的 ColorSpace 条目指定的颜色空间中进行。这与图像可能绘制的组颜色空间无关。如果需要颜色转换,预混合的反转应在颜色转换之前进行。如果图像颜色空间是 Indexed 空间(见“索引颜色空间”),则应预混合颜色表中的颜色值(而不是索引值本身)。

The second way to define a soft mask is by associating a soft-mask image with an image XObject. This is a subsidiary image XObject specified in the SMask entry of the parent XObject’s image dictionary (see “Image Dictionaries”). Entries in the subsidiary image dictionary for such a soft-mask image shall have the same format and meaning as in that of an ordinary image XObject (as described in Table 89 in “Image Dictionaries”), subject to the restrictions listed in Table 145. This type of image dictionary may contain an additional entry, Matte.

When an image is accompanied by a soft-mask image, it is sometimes advantageous for the image data to be preblended with some background colour, called the matte colour. Each image sample represents a weighted average of the original source colour and the matte colour, using the corresponding mask sample as the weighting factor. (This is a generalization of a technique commonly called premultiplied alpha.)

If the image data is preblended, the matte colour shall be specified by a Matte entry in the soft-mask image dictionary (see Table 145). The preblending computation, performed independently for each component, shall be

\[c' = m + α \times (c - m)\]

where

\(c'\) is the value to be provided in the image source data

\(c\) is the original image component value

\(m\) is the matte colour component value

\(α\) is the corresponding mask sample

This computation shall use actual colour component values, with the effects of the Filter and Decode transformations already performed. The computation shall be the same whether the colour space is additive or subtractive.

Table 145 – Restrictions on the entries in a soft-mask image dictionary
Key Restriction
Type If present, shall be XObject.
Subtype Shall be Image.
Width If a Matte entry (see Table 146) is present, shall be the same as the Width value of the parent image; otherwise independent of it. Both images shall be mapped to the unit square in user space (as are all images), regardless of whether the samples coincide individually.
Height Same considerations as for Width.
ColorSpace Required; shall be DeviceGray.
BitsPerComponent Required.
Intent Ignored.
ImageMask Shall be false or absent.
Mask Shall be absent.
SMask Shall be absent.
Decode Default value: [ 0 1 ].
Interpolate Optional.
Alternates Ignored.
Name Ignored.
StructParent Ignored.
ID Ignored.
OPI Ignored.

Table 146 – Additional entry in a soft-mask image dictionary
Key Type Value
Matte array (Optional; PDF 1.4) An array of component values specifying the matte colour with which the image data in the parent image shall have been preblended. The array shall consist of n numbers, where n is the number of components in the colour space specified by the ColorSpace entry in the parent image’s image dictionary; the numbers shall be valid colour components in that colour space. If this entry is absent, the image data shall not be preblended.

When preblended image data is used in transparency blending and compositing computations, the results shall be the same as if the original, unblended image data were used and no matte colour were specified. In particular, the inputs to the blend function shall be the original colour values. To derive c from c′, the conforming reader may sometimes need to invert the formula shown previously. The resulting c value shall lie within the range of colour component values for the image colour space.

The preblending computation shall be done in the colour space specified by the parent image’s ColorSpace entry. This is independent of the group colour space into which the image may be painted. If a colour conversion is required, inversion of the preblending shall precede the colour conversion. If the image colour space is an Indexed space (see “Indexed Colour Spaces”), the colour values in the colour table (not the index values themselves) shall be preblended.

11.6.6 透明度组 XObjects

Transparency Group XObjects

在 PDF 中,透明度组表示为一种特殊类型的组 XObject(见“组 XObject”),称为透明度组 XObject。组 XObject 又是一种表单 XObject,由其表单字典中存在 Group 条目来区分(见“表单字典”)。该条目的值是一个子组属性字典,用于定义组的属性。字典内容的格式和含义由其组子类型决定,该子类型由字典的 S 条目指定。透明度组(子类型 Transparency)的条目显示在表 147中。

页面对象(见“页面对象”)也可能有一个 Group 条目,其值是一个组属性字典,用于指定页面组的属性(见“页面组”)。对于页面组,字典中某些条目的解释与透明度组 XObject 略有不同;详见表中的描述。

表 147 – 透明度组属性字典特有的附加条目
类型
S 名称 (必需)组的子类型,用于标识此字典描述的组的类型;对于透明度组,应为 Transparency
CS 名称或数组 (有时必需)组的颜色空间,用于以下目的:
  • 作为将颜色转换到的颜色空间,当颜色被绘制到组中时
  • 作为对象在组内合成的混合颜色空间(见“混合颜色空间”)
  • 当组本身作为一个对象绘制到其背景上时,作为组整体的颜色空间
组的颜色空间应是任何设备或基于 CIE 的颜色空间,其分量在 0.0 到 1.0 范围内被视为独立的加法或减法值,受11.3.4混合颜色空间”中描述的限制约束。这些限制排除了 Lab 和亮度 - 色度 ICCBased 颜色空间,以及特殊的颜色空间 PatternIndexedSeparationDeviceN。设备颜色空间应根据当前资源字典的 ColorSpace 子字典中的 DefaultGrayDefaultRGBDefaultCMYK 条目进行重新映射(见“默认颜色空间”)。
通常,CS 条目仅适用于隔离透明度组(即 Itrue 的组),即便如此,它也是可选的。然而,对于没有任何父组或页面可从中继承的透明度组 XObject(特别是作为子类型为 Luminosity 的软蒙版字典中 G 条目的值的情况),此条目必须存在于组属性字典中(见“软蒙版字典”)。
此外,即使 Ifalse 或不存在,CS 条目也可能存在于与页面对象关联的组属性字典中。在正常情况下,页面直接输出到介质上时,无论 I 值如何,页面组实际上都是隔离的,因此应遵循指定的 CS 值。但如果页面又被用作其他页面的一个元素,并且该组是非隔离的,CS 应被忽略,颜色空间应从与页面合成的实际背景继承(见“页面组”)。
默认值:绘制此透明度组的父组或页面的颜色空间。(父组的颜色空间本身可能是显式指定的,也可能是继承的。)
对于用作注释外观的透明度组 XObject(见“外观流”),默认颜色空间应从注释所在的页面继承。
I 布尔值 (可选)一个标志,用于指定透明度组是否为隔离的(见“隔离组”)。如果此标志为 true,组内的对象将相对于完全透明的初始背景进行合成;如果为 false,则相对于组的背景进行合成。默认值:false
在页面的组属性字典中,此条目的解释略有不同。在正常情况下,页面直接输出到介质上时,页面组实际上是隔离的,指定的 I 值应被忽略。但如果页面又被用作其他页面的一个元素,它将被视为透明度组 XObject;I 值应按正常方式解释,以确定页面组是否为隔离的。
K 布尔值 (可选)一个标志,用于指定透明度组是否为挖空组(见“挖空组”)。如果此标志为 false,组内后面的对象将与与其重叠的前面对象合成;如果为 true,它们将与组的初始背景合成,并覆盖(“挖空”)任何前面重叠的对象。默认值:false

透明度组 XObject 的内容流应定义属于该组的图形对象。当对透明度组 XObject 应用 Do 操作符时,它将执行其内容流,并将生成的组颜色、形状和不透明度合成为其父组或页面的一部分,就好像它们来自一个基本图形对象一样。Do 在执行表单 XObject 的正常操作(如“表单 XObject”中所述)之外,还应执行以下操作:

  • 如果透明度组是非隔离的(其组属性字典中 I 条目的值为 false),其初始背景(由 XObject 的 BBox 条目指定的边界框内)应定义为父组或页面的累积颜色和 alpha 值——即到目前为止父组中所绘制的所有内容的结果。然而,如果父组是挖空组,初始背景应与父组相同。如果组是隔离的(Itrue),其初始背景应定义为透明。
  • 在执行透明度组 XObject 的内容流之前,图形状态中的当前混合模式应初始化为 Normal,当前的描边和非描边 alpha 常量应初始化为 1.0,当前的软蒙版应设置为 None

注 1

在执行开始时初始化这些图形状态参数的目的是确保它们不会被应用两次:一次是在成员对象绘制到组中时,另一次是在组绘制到父组或页面时。

  • 透明度组 XObject 内容流中的操作符绘制的对象应根据11.3.3基本合成公式”中描述的规则合成为组的一部分。在此计算过程中,应遵循组属性字典中的挖空标志(K)和图形状态的透明度相关参数。
  • 如果在组属性字典中指定了组颜色空间(CS),所有绘制操作符在将对象合成为组之前都应将源颜色转换为该颜色空间,并且每个点的结果颜色应在该颜色空间中进行解释。如果未指定组颜色空间,则当前颜色空间应从父组或页面动态继承。(如果未另行指定,页面组的颜色空间应从输出设备的本机颜色空间继承。)
  • 执行透明度组 XObject 的内容流后,图形状态应恢复到调用 Do 操作符之前的状态(就像对任何表单 XObject 一样)。然后,组的形状(组内所有绘制对象的并集,由组 XObject 的边界框裁剪)应使用组在每个点的累积颜色和不透明度绘制到父组或页面中。

如果对给定的透明度组 XObject 多次调用 Do 操作符,每次调用都将被视为一个独立的透明度组。也就是说,结果就好像该组在每次调用时都与背景独立合成一样。

注 2

执行表单 XObject 缓存的应用程序应考虑此要求。

前面描述的操作仅适用于透明度组 XObject——即具有 Group 条目且该条目指定一个组属性子字典,其组子类型(S)为 Transparency 的表单 XObject。没有 Group 条目的普通表单 XObject 不会因透明度目的而应用任何分组行为。也就是说,它包含的图形对象将单独合成,就好像它们直接绘制到父组或页面中一样 。

A transparency group is represented in PDF as a special type of group XObject (see “Group XObjects”) called a transparency group XObject. A group XObject is in turn a type of form XObject, distinguished by the presence of a Group entry in its form dictionary (see “Form Dictionaries”). The value of this entry is a subsidiary group attributes dictionary defining the properties of the group. The format and meaning of the dictionary’s contents shall be determined by its group subtype, which is specified by the dictionary’s S entry. The entries for a transparency group (subtype Transparency) are shown in Table 147.

A page object (see “Page Objects”) may also have a Group entry, whose value is a group attributes dictionary specifying the attributes of the page group (see “Page Group”). Some of the dictionary entries are interpreted slightly differently for a page group than for a transparency group XObject; see their descriptions in the table for details.

Table 147 – Additional entries specific to a transparency group attributes dictionary
Key Type Value
S name (Required) The group subtype, which identifies the type of group whose attributes this dictionary describes; shall be Transparency for a transparency group.
CS name or array (Sometimes required) The group colour space, which is used for the following purposes:
  • As the colour space into which colours shall be converted when painted into the group
  • As the blending colour space in which objects shall be composited within the group (see “Blending Colour Space”)
  • As the colour space of the group as a whole when it in turn is painted as an object onto its backdrop
The group colour space shall be any device or CIE-based colour space that treats its components as independent additive or subtractive values in the range 0.0 to 1.0, subject to the restrictions described in 11.3.4, "Blending Colour Space." These restrictions exclude Lab and lightness- chromaticity ICCBased colour spaces, as well as the special colour spaces Pattern, Indexed, Separation, and DeviceN. Device colour spaces shall be subject to remapping according to the DefaultGray, DefaultRGB, and DefaultCMYK entries in the ColorSpace subdictionary of the current resource dictionary (see “Default Colour Spaces”).
Ordinarily, the CS entry may be present only for isolated transparency groups (those for which I is true), and even then it is optional. However, this entry shall be present in the group attributes dictionary for any transparency group XObject that has no parent group or page from which to inherit—in particular, one that is the value of the G entry in a soft-mask dictionary of subtype Luminosity (see “Soft-Mask Dictionaries”).
Additionally, the CS entry may be present in the group attributes dictionary associated with a page object, even if I is false or absent. In the normal case in which the page is imposed directly on the output medium, the page group is effectively isolated regardless of the I value, and the specified CS value shall therefore be honoured. But if the page is in turn used as an element of some other page and if the group is non- isolated, CS shall be ignored and the colour space shall be inherited from the actual backdrop with which the page is composited (see “Page Group”).
Default value: the colour space of the parent group or page into which this transparency group is painted. (The parent’s colour space in turn may be either explicitly specified or inherited.)
For a transparency group XObject used as an annotation appearance (see “Appearance Streams”), the default colour space shall be inherited from the page on which the annotation appears.
I boolean (Optional) A flag specifying whether the transparency group is isolated (see “Isolated Groups”). If this flag is true, objects within the group shall be composited against a fully transparent initial backdrop; if false, they shall be composited against the group’s backdrop. Default value: false.
In the group attributes dictionary for a page, the interpretation of this entry shall be slightly altered. In the normal case in which the page is imposed directly on the output medium, the page group is effectively isolated and the specified I value shall be ignored. But if the page is in turn used as an element of some other page, it shall be treated as if it were a transparency group XObject; the I value shall be interpreted in the normal way to determine whether the page group is isolated.
K boolean (Optional) A flag specifying whether the transparency group is a knockout group (see “Knockout Groups”). If this flag is false, later objects within the group shall be composited with earlier ones with which they overlap; if true, they shall be composited with the group’s initial backdrop and shall overwrite (“knock out”) any earlier overlapping objects. Default value: false.

The transparency group XObject’s content stream shall define the graphics objects belonging to the group. When applied to a transparency group XObject, the Do operator shall execute its content stream and shall composite the resulting group colour, shape, and opacity into the group’s parent group or page as if they had come from an elementary graphics object. Do shall perform the following actions in addition to the normal ones for a form XObject (as described in “Form XObjects”):

  • If the transparency group is non-isolated (the value of the I entry in its group attributes dictionary is false), its initial backdrop, within the bounding box specified by the XObject’s BBox entry, shall be defined to be the accumulated colour and alpha of the parent group or page—that is, the result of everything that has been painted in the parent up to that point. However, if the parent is a knockout group, the initial backdrop shall be the same as that of the parent. If the group is isolated (I is true), its initial backdrop shall be defined to be transparent.
  • Before execution of the transparency group XObject’s content stream, the current blend mode in the graphics state shall be initialized to Normal, the current stroking and nonstroking alpha constants to 1.0, and the current soft mask to None.

NOTE 1

The purpose of initializing these graphics state parameters at the beginning of execution is to ensure that they are not applied twice: once when member objects are painted into the group and again when the group is painted into the parent group or page.

  • Objects painted by operators in the transparency group XObject’s content stream shall be composited into the group according to the rules described in 11.3.3, "Basic Compositing Formula." The knockout flag (K) in the group attributes dictionary and the transparency-related parameters of the graphics state shall be honoured during this computation.
  • If a group colour space (CS) is specified in the group attributes dictionary, all painting operators shall convert source colours to that colour space before compositing objects into the group, and the resulting colour at each point shall be interpreted in that colour space. If no group colour space is specified, the prevailing colour space shall be dynamically inherited from the parent group or page. (If not otherwise specified, the page group’s colour space shall be inherited from the native colour space of the output device.)
  • After execution of the transparency group XObject’s content stream, the graphics state shall revert to its former state before the invocation of the Do operator (as it does for any form XObject). The group’s shape—the union of all objects painted into the group, clipped by the group XObject’s bounding box— shall then be painted into the parent group or page, using the group’s accumulated colour and opacity at each point.

If the Do operator is invoked more than once for a given transparency group XObject, each invocation shall be treated as a separate transparency group. That is, the result shall be as if the group were independently composited with the backdrop on each invocation.

NOTE 2

Applications that perform caching of rendered form XObjects shall take this requirement into account.

The actions described previously shall occur only for a transparency group XObject—a form XObject having a Group entry that designates a group attributes subdictionary whose group subtype (S) is Transparency. An ordinary form XObject—one having no Group entry—shall not be subject to any grouping behaviour for transparency purposes. That is, the graphics objects it contains shall be composited individually, just as if they were painted directly into the parent group or page.

11.6.7 图案和透明度

Patterns and Transparency

在透明成像模型中,构成平铺图案(见“平铺图案”)图案单元的图形对象可能包括透明对象和透明度组。无论在何处绘制图案,在图案单元内部以及图案单元与其背景之间都可能发生透明合成。同样,底纹图案(“底纹图案”)与其背景的合成就好像使用 sh 操作符应用了底纹字典一样。

在这两种情况下,图案定义应视为隐式地包含在一个非隔离的透明度组中:对于平铺图案是非挖空组,对于底纹图案是挖空组。定义在求值时不应继承图形状态参数的当前值;这些参数仅在随后使用生成的图案绘制对象时才生效。相反,图形状态参数应按以下方式初始化:

  • 对于透明度组,与透明度相关的参数(混合模式、软蒙版和 alpha 常量)应初始化为其标准默认值(这一点对于透明度组始终如此)。
  • 所有其他参数应初始化为图案被定义为资源的内容流(如页面或表单 XObject)开始时的值。(这是所有图案在不透明和透明成像模型中的正常行为。)
  • 对于底纹图案,参数值可以通过图案字典中的 ExtGState 条目内容进行补充(见“底纹图案”)。仅使用影响 sh 操作符的参数,例如当前变换矩阵和渲染意图。不应使用影响路径绘制操作符的参数,因为执行 sh 并不涉及绘制路径。
  • 如果底纹字典有一个 Background 条目,则在调用 sh 操作符之前,图案的隐式透明度组应使用指定的背景颜色填充。

当图案稍后用于绘制图形对象时,从图案定义求值得到的颜色、形状和不透明度值将用作透明度合成公式中对象的源颜色(\(C_s\))、对象形状(\(f_j\))和对象不透明度(\(q_j\))。这种绘制操作受当时有效的图形状态参数值的影响,就像使用恒定颜色绘制对象一样。

注 1

与不透明成像模型不同,在不透明成像模型中,平铺图案的图案单元可以评估一次,然后无限复制以填充绘制区域,在一般的透明情况下,效果就好像对于每个图块都独立重新执行图案定义一样,同时考虑到每个点处的背景颜色。然而,在常见的情况下,如果图案完全由使用 Normal 混合模式绘制的对象组成,则可以通过将图案单元视为隔离组来优化这种行为。因为在这种情况下,结果仅取决于图案单元的颜色、形状和不透明度,而不取决于背景的颜色、形状和不透明度,所以可以像在不透明绘画中一样评估一次图案单元,然后进行复制。

注 2

在基于光栅的平铺实现中,所有图块应视为一个单一的透明度组。这样可以避免由于在相邻图块之间的边界处多次标记像素而产生的伪影。

上述讨论适用于有色(PaintType 1)和无色(PaintType 2)平铺图案。在后一种情况下,无色图案的定义不得指定颜色的限制同样适用于定义中可能包含的任何透明度组。然而,对于在图形状态中指定与透明度相关的参数没有相应的限制 。

In the transparent imaging model, the graphics objects making up the pattern cell of a tiling pattern (see “Tiling Patterns”) may include transparent objects and transparency groups. Transparent compositing may occur both within the pattern cell and between it and the backdrop wherever the pattern is painted. Similarly, a shading pattern (“Shading Patterns”) composites with its backdrop as if the shading dictionary were applied with the sh operator.

In both cases, the pattern definition shall be treated as if it were implicitly enclosed in a non-isolated transparency group: a non-knockout group for tiling patterns, a knockout group for shading patterns. The definition shall not inherit the current values of the graphics state parameters at the time it is evaluated; those parameters shall take effect only when the resulting pattern is later used to paint an object. Instead, the graphics state parameters shall be initialized as follows:

  • As always for transparency groups, those parameters related to transparency (blend mode, soft mask, and alpha constant) shall be initialized to their standard default values.
  • All other parameters shall be initialized to their values at the beginning of the content stream (such as a page or a form XObject) in which the pattern shall be defined as a resource. (This is the normal behaviour for all patterns, in both the opaque and transparent imaging models.)
  • In the case of a shading pattern, the parameter values may be augmented by the contents of the ExtGState entry in the pattern dictionary (see “Shading Patterns”). Only those parameters that affect the sh operator, such as the current transformation matrix and rendering intent, shall be used. Parameters that affect path-painting operators shall not be used, since the execution of sh does not entail painting a path.
  • If the shading dictionary has a Background entry, the pattern’s implicit transparency group shall be filled with the specified background colour before the sh operator is invoked.

When the pattern is later used to paint a graphics object, the colour, shape, and opacity values resulting from the evaluation of the pattern definition shall be used as the object’s source colour (\(C_s\) ), object shape (\(f_j\) ), and object opacity (\(q_j\) ) in the transparency compositing formulas. This painting operation is subject to the values of he graphics state parameters in effect at the time, just as in painting an object with a constant colour.

NOTE 1

Unlike the opaque imaging model, in which the pattern cell of a tiling pattern may be evaluated once and then replicated indefinitely to fill the painted area, the effect in the general transparent case is as if the pattern definition were reexecuted independently for each tile, taking into account the colour of the backdrop at each point. However, in the common case in which the pattern consists entirely of objects painted with the Normal blend mode, this behaviour can be optimized by treating the pattern cell as if it were an isolated group. Since in this case the results depend only on the colour, shape, and opacity of the pattern cell and not on those of the backdrop, the pattern cell can be evaluated once and then replicated, just as in opaque painting.

NOTE 2

In a raster-based implementation of tiling, all tiles should be treated as a single transparency group. This avoids artifacts due to multiple marking of pixels along the boundaries between adjacent tiles.

The foregoing discussion applies to both coloured (PaintType 1) and uncoloured (PaintType 2) tiling patterns. In the latter case, the restriction that an uncoloured pattern’s definition shall not specify colours extends as well to any transparency group that the definition may include. There are no corresponding restrictions, however, on specifying transparency-related parameters in the graphics state.