跳转至

11.2 透明度概述

11.2 Overview of Transparency

原始的 PDF 图像模型以不透明方式在页面上绘制对象(填充、描边、文本和图像),这些对象可能会被路径裁剪。在页面上的任意位置,其颜色应为最上层封闭对象的颜色,而忽略其可能覆盖的任何先前对象。这种效果通常是通过按指定顺序直接将对象渲染到页面上实现的,每个对象都会完全覆盖其所重叠的其他对象。

在透明图像模型下,页面上的所有对象都可能影响最终的结果。在某个特定点上的对象可视为构成了一个透明度栈(简称)。这些对象按照其指定的顺序从下至上排列。每个点上的页面颜色应由透明度模型定义的合成规则计算所有封闭对象的颜色而得出。

注意 1

对象的指定顺序决定了堆叠顺序,但不一定决定对象实际绘制到页面上的顺序。特别是,透明度模型不要求符合标准的阅读器立即栅格化对象,或在渲染整个栈到页面之前承诺使用栅格表示。这一点非常重要,因为栅格化通常会导致信息和精度的显著损失,而在透明度计算的中间阶段最好避免这种损失。

一个给定的对象应与背景进行合成。通常情况下,背景由之前指定的所有对象栈组成。合成的结果随后被视为下一个对象的背景。然而,在某些类型的透明度组(详见 “透明度组”)内部,可以选择不同的背景。

在对象与其背景合成时,每个点的颜色应根据指定的混合模式计算,该模式是对象颜色和背景颜色的函数。混合模式决定了颜色如何相互交互;不同的混合模式可用于实现各种有用的效果。单个对象的整个合成过程应使用同一种混合模式,但不同的对象可以使用不同的混合模式。

合成对象与背景时涉及两个标量值:形状不透明度。在概念上,对于每个对象,这些值应在平面上的每个点上定义,就像它们是附加的颜色分量一样。(在实际应用中,它们可能来自辅助来源,而不是对象本身固有的属性。)

形状和不透明度的取值范围为 0.0(无贡献)到 1.0(最大贡献)。在任何形状或不透明度为 0.0 的点上,对象的颜色均未定义。而在形状值为 0.0 的点上,不透明度也未定义。形状和不透明度遵循合成规则,因此整个栈在每个点上也具有对应的形状和不透明度。

对象的不透明度与背景的不透明度共同决定了背景颜色、对象颜色和混合颜色在最终合成颜色中的相对贡献。然后,对象的形状决定了合成颜色替换背景颜色的程度。形状值 0.0 和 1.0 分别标识对象外部和内部的点(具有清晰边缘的对象),而介于 0.0 和 1.0 之间的值可用于定义柔和边缘的对象。

形状和不透明度在概念上非常相似。事实上,它们通常可以合并为一个单一的值,称为Alpha,该值既控制颜色合成计算,也控制对象与背景之间的渐变。然而,在某些情况下,它们需要被分别处理;参见 11.4.6 “挖空组”(Knockout Groups)。

注意 2

基于栅格的实现可能需要维护一个独立的形状参数,以便正确执行抗锯齿处理。因此,在模型中显式地引入形状参数是很方便的。

栈中的一个或多个连续对象可以被组合成一个透明度组(以下简称)。整个组可以具有不同的属性,以修改组内对象的合成行为及其与背景的交互方式。此外,组本身也可以关联一个额外的混合模式、形状和不透明度,并在与背景合成时使用。透明度组可以嵌套在其他组中,形成一个树状结构的层次关系。

示例

[附录 L](Annex L)中的 图 L.16 展示了透明度分组的效果。在上方的两个图中,三个彩色圆形分别作为独立对象绘制,未进行分组。在左上角,三个对象以不透明度 1.0 绘制;每个对象都会完全用自己的颜色覆盖其背景(包括先前绘制的对象)。在右上角,相同的三个独立对象以 0.5 的不透明度绘制,使它们彼此以及与灰色和白色背景进行合成。在下方的两个图中,这三个对象被组合成一个透明度组。在左下角,单个对象在组内具有 1.0 的不透明度,但整个组以Normal 混合模式,并以 0.5 的不透明度绘制。因此,在组内,对象完全覆盖彼此,但整个组随后以透明方式与灰色和白色背景合成。在右下角,对象在组内具有 0.5 的不透明度,因此它们彼此合成。整个组以 1.0 的不透明度绘制到背景上,但使用不同的混合模式(HardLight),产生不同的视觉效果。

合成组的颜色结果可转换为单通道亮度值,并用作软遮罩。这种遮罩可作为形状或不透明度值的附加来源,供后续合成操作使用。当遮罩用于形状时,该技术被称为软剪切,它是对不透明图像模型中当前剪切路径的推广(参见 “剪切路径操作符”)。

当前页面的概念被推广为指代一个包含页面上所有对象栈的透明度组,并与一个纯白且完全不透明的背景进行合成。从逻辑上讲,该栈随后应被栅格化,以确定传输到输出设备的实际像素值。

注意 3

在某些情况下,PDF 页面可能被视为一个艺术作品片段,放置在另一页上。在这种情况下,它不会被视为页面,而是作为一个组处理,其背景可能与页面的背景不同。

The original PDF imaging model paints objects (fills, strokes, text, and images), possibly clipped by a path, opaquely onto a page. The colour of the page at any point shall be that of the topmost enclosing object, disregarding any previous objects it may overlap. This effect may be—and often is—realized simply by rendering objects directly to the page in the order in which they are specified, with each object completely overwriting any others that it overlaps.

Under the transparent imaging model, all of the objects on a page may potentially contribute to the result. Objects at a given point may be thought of as forming a transparency stack (or stack for short). The objects shall be arranged from bottom to top in the order in which they are specified. The colour of the page at each point shall be determined by combining the colours of all enclosing objects in the stack according to compositing rules defined by the transparency model.

NOTE 1

The order in which objects are specified determines the stacking order but not necessarily the order in which the objects are actually painted onto the page. In particular, the transparency model does not require a conforming reader to rasterize objects immediately or to commit to a raster representation at any time before rendering the entire stack onto the page. This is important, since rasterization often causes significant loss of information and precision that is best avoided during intermediate stages of the transparency computation.

A given object shall be composited with a backdrop. Ordinarily, the backdrop consists of the stack of all objects that have been specified previously. The result of compositing shall then be treated as the backdrop for the next object. However, within certain kinds of transparency groups (see “Transparency Groups”), a different backdrop may be chosen.

During the compositing of an object with its backdrop, the colour at each point shall be computed using a specified blend mode, which is a function of both the object’s colour and the backdrop colour. The blend mode shall determine how colours interact; different blend modes may be used to achieve a variety of useful effects. A single blend mode shall be in effect for compositing all of a given object, but different blend modes may be applied to different objects.

Two scalar quantities called shape and opacity mediate compositing of an object with its backdrop. Conceptually, for each object, these quantities shall be defined at every point in the plane, just as if they were additional colour components. (In actual practice, they may be obtained from auxiliary sources rather than being intrinsic to the object.)

Both shape and opacity vary from 0.0 (no contribution) to 1.0 (maximum contribution). At any point where either the shape or the opacity of an object is equal to 0.0, its colour shall be undefined. At points where the shape is equal to 0.0, the opacity shall also be undefined. The shape and opacity shall be subject to compositing rules; therefore, the stack as a whole also has a shape and opacity at each point.

An object’s opacity, in combination with the backdrop’s opacity, shall determine the relative contributions of the backdrop colour, the object’s colour, and the blended colour to the resulting composite colour. The object’s shape shall then determine the degree to which the composite colour replaces the backdrop colour. Shape values of 0.0 and 1.0 identify points that lie outside and inside a conventional sharp-edged object; intermediate values are useful in defining soft-edged objects.

Shape and opacity are conceptually very similar. In fact, they can usually be combined into a single value, called alpha, which controls both the colour compositing computation and the fading between an object and its backdrop. However, there are a few situations in which they shall be treated separately; see 11.4.6, "Knockout Groups."

NOTE 2

Raster-based implementations may need to maintain a separate shape parameter to do anti-aliasing properly; it is therefore convenient to have shape as an explicit part of the model.

One or more consecutive objects in a stack may be collected together into a transparency group (often referred to hereafter simply as a group). The group as a whole may have various properties that modify the compositing behaviour of objects within the group and their interactions with its backdrop. An additional blend mode, shape, and opacity may also be associated with the group as a whole and used when compositing it with its backdrop. Groups may be nested within other groups, forming a tree-structured hierarchy.

EXAMPLE

Figure L.16 in Annex L illustrates the effects of transparency grouping. In the upper two figures, three coloured circles are painted as independent objects with no grouping. At the upper left, the three objects are painted opaquely (opacity = 1.0); each object completely replaces its backdrop (including previously painted objects) with its own colour. At the upper right, the same three independent objects are painted with an opacity of 0.5, causing them to composite with each other and with the gray and white backdrop. In the lower two figures, the three objects are combined as a transparency group. At the lower left, the individual objects have an opacity of 1.0 within the group, but the group as a whole is painted in the Normal blend mode with an opacity of 0.5. The objects thus completely overwrite each other within the group, but the resulting group then composites transparently with the gray and white backdrop. At the lower right, the objects have an opacity of 0.5 within the group and thus composite with each other. The group as a whole is painted against the backdrop with an opacity of 1.0 but in a different blend mode (HardLight), producing a different visual effect.

The colour result of compositing a group may be converted to a single-component luminosity value and treated as a soft mask. Such a mask may then be used as an additional source of shape or opacity values for subsequent compositing operations. When the mask is used as a shape, this technique is known as soft clipping; it is a generalization of the current clipping path in the opaque imaging model (see “Clipping Path Operators”).

The notion of current page is generalized to refer to a transparency group consisting of the entire stack of objects placed on the page, composited with a backdrop that is pure white and fully opaque. Logically, this entire stack shall then be rasterized to determine the actual pixel values to be transmitted to the output device.

NOTE 3

In contexts where a PDF page is treated as a piece of artwork to be placed on some other page it is treated not as a page but as a group, whose backdrop may be defined differently from that of a page.