Skip to content

PDF Spec 11 Soft Masks

Marc Jones edited this page Dec 30, 2025 · 1 revision

11.5-11.6 Soft Masks & Color

Part of: PDF-Spec-11-Transparency

Navigation: PDF-Spec-11-Groups | PDF-Spec-Index | PDF-Spec-11-Specifying


| B i C i 1 - C s i , ( ) | Blend function for element E i |

  • NOTE 2 The elements of a group are composited onto a backdrop that includes the group's initial backdrop. This is done to achieve the correct effects of the blend modes, most of which are dependent on both the backdrop and source colours being blended. This feature is what distinguishes non-isolated groups from isolated groups, discussed in the next sub-clause.
  • NOTE 3 Special attention should be directed to the formulas at the end that compute the final results C , f , and α , of the group compositing function. Essentially, these formulas remove the contribution of the group backdrop from the computed results. This ensures that when the group is subsequently composited with that backdrop (possibly with additional shape or opacity inputs or a different blend mode), the backdrop's contribution is included only once.

For colour, the backdrop removal is accomplished by an explicit calculation, whose effect is essentially the reverse of compositing with the Normal blend mode. The formula is a simplification of the following formulas, which present this operation more intuitively:

where is the backdrop fraction , the relative contribution of the backdrop colour to the overall colour. φ b

  • NOTE 4 For shape and alpha, backdrop removal is accomplished by maintaining two sets of variables to hold the accumulated values. There is never any need to compute the corresponding complete shape, f i , that includes the backdrop contribution.

The group shape and alpha, and , shall accumulate only the shape and alpha of the group elements, f g i α g i excluding the group backdrop. Their final values shall become the group results returned by the group compositing function. The complete alpha, α i , includes the backdrop contribution as well; its value is used in the colour compositing computations.

  • NOTE 5 As a result of these corrections, the effect of compositing objects as a group is the same as that of compositing them separately (without grouping) if the following conditions hold:

The group is non-isolated and has the same knockout attribute as its parent group (see 11.4.5, "Isolated Groups," and 'Knockout Groups').

When compositing the group's results with the group backdrop, the Normal blend mode is used, and the shape and opacity inputs are always 1.0.

11.4.5 Isolated Groups

An isolated group is one whose elements shall be composited onto a fully transparent initial backdrop rather than onto the group's backdrop. The resulting source colour, object shape, and object alpha for the group shall be therefore independent of the group backdrop. The only interaction with the group backdrop shall occur when the group's computed colour, shape, and alpha are composited with it.

In particular, the special effects produced by the blend modes of objects within the group take into account only the intrinsic colours and opacities of those objects; they shall not be influenced by the group's backdrop.

  • EXAMPLE Applying the Multiply blend mode to an object in the group produces a darkening effect on other objects lower in the group's stack but not on the group's backdrop.

Figure L.17 in Annex L illustrates this effect for a group consisting of four overlapping circles in a light gray colour ( C = M = Y = 0.0; K = 0.15). The circles are painted within the group with opacity 1.0 in the Multiply blend mode; the group itself is painted against its backdrop in Normal blend mode. In the top row, the group is isolated and thus does not interact with the rainbow backdrop. In the bottom row, the group is non-isolated and composites with the backdrop. The figure also illustrates the difference between knockout and non-knockout groups (see 'Knockout Groups').

  • NOTE 1 Conceptually, the effect of an isolated group could be represented by a simple object that directly specifies a colour, shape, and opacity at each point. This flattening of an isolated group is sometimes useful for importing and exporting fully composited artwork in applications. Furthermore, a group that specifies an explicit blending colour space shall be an isolated group.

For an isolated group, the group compositing formulas shall be altered by adding one statement to the initialization:

α 0 0.0 = if the group is isolated

That is, the initial backdrop on which the elements of the group are composited shall be transparent rather than inherited from the group's backdrop.

  • NOTE 2 This substitution also makes C 0 undefined, but the normal compositing formulas take care of that. Also, the result computation for C automatically simplifies to C = C n , since there is no backdrop contribution to be factored out.

11.4.6 Knockout Groups

In a knockout group, each individual element shall be composited with the group's initial backdrop rather than with the stack of preceding elements in the group. When objects have binary shapes (1.0 for inside, 0.0 for outside), each object shall overwrite (knocks out) the effects of any earlier elements it overlaps within the same group. At any given point, only the topmost object enclosing the point shall contribute to the result colour and opacity of the group as a whole.

  • EXAMPLE Figure L.17 in Annex L about 11.4.5, "Isolated Groups," illustrates the difference between knockout and non-knockout groups. In the left column, the four overlapping circles are defined as a knockout group and therefore do not composite with each other within the group. In the right column, the circles form a nonknockout group and thus do composite with each other. In each column, the upper and lower figures depict an isolated and a non-isolated group, respectively.
  • NOTE 1 This model is similar to the opaque imaging model, except that the 'topmost object wins' rule applies to both the colour and the opacity. Knockout groups are useful in composing a piece of artwork from a collection of overlapping objects, where the topmost object in any overlap completely obscures those beneath. At the same time, the topmost object interacts with the group's initial backdrop in the usual way, with its opacity and blend mode applied as appropriate.

The concept of knockout is generalized to accommodate fractional shape values. In that case, the immediate backdrop shall be only partially knocked out and shall be replaced by only a fraction of the result of compositing the object with the initial backdrop.

The restated group compositing formulas deal with knockout groups by introducing a new variable, b , which is a subscript that specifies which previous result to use as the backdrop in the compositing computations: 0 in a knockout group or i -1 in a non-knockout group. When b = i -1, the formulas simplify to the ones given in 11.4.4, "Group Compositing Computations."

In the general case, the computation shall proceed in two stages:

  • a) Composite the source object with the group's initial backdrop, disregarding the object's shape and using a source shape value of 1.0 everywhere. This produces unnormalized temporary alpha and colour results, α t and C t .
  1. NOTE 2 For colour, this computation is essentially the same as the unsimplified colour compositing formula given in 11.3.6, "Interpretation of Alpha," but using a source shape of 1.0.
  • b) Compute a weighted average of this result with the object's immediate backdrop, using the source shape as the weighting factor. Then normalize the result colour by the result alpha:

This averaging computation shall be performed for both colour and alpha.

  • NOTE 3 The preceding formulas show this averaging directly. The formulas in 11.4.8, "Summary of Group Compositing Computations," are slightly altered to use source shape and alpha rather than source shape and opacity, avoiding the need to compute a source opacity value explicitly.
  • NOTE 4 C t in Group Compositing Computations is slightly different from the preceding C t : it is premultiplied by . f s i
  • NOTE 5 The extreme values of the source shape produce the straightforward knockout effect. That is, a shape value of 1.0 (inside) yields the colour and opacity that result from compositing the object with the initial backdrop. A shape value of 0.0 (outside) leaves the previous group results unchanged.

The existence of the knockout feature is the main reason for maintaining a separate shape value rather than only a single alpha that combines shape and opacity. The separate shape value shall be computed in any group that is subsequently used as an element of a knockout group.

A knockout group may be isolated or non-isolated; that is, isolated and knockout are independent attributes. A non-isolated knockout group composites its topmost enclosing element with the group's backdrop. An isolated knockout group composites the element with a transparent backdrop.

  • NOTE 6 When a non-isolated group is nested within a knockout group, the initial backdrop of the inner group is the same as that of the outer group; it is not the immediate backdrop of the inner group. This behaviour, although perhaps unexpected, is a consequence of the group compositing formulas when b = 0.

11.4.7 Page Group

All of the elements painted directly onto a page-both top-level groups and top-level objects that are not part of any group-shall be treated as if they were contained in a transparency group P , which in turn is composited with a context-dependent backdrop. This group is called the page group .

The page group shall be treated in one of two distinctly different ways:

  • Ordinarily, the page shall be imposed directly on an output medium, such as paper or a display screen. The page group shall be treated as an isolated group, whose results shall then be composited with a backdrop colour appropriate for the medium. The backdrop is nominally white, although varying according to the actual properties of the medium. However, some conforming readers may choose to provide a different backdrop, such as a checker board or grid to aid in visualizing the effects of transparency in the artwork.
  • A 'page' of a PDF file may be treated as a graphics object to be used as an element of a page of some other document.

EXAMPLE

This case arises, for example, when placing a PDF file containing a piece of artwork produced by a drawing program into a page layout produced by a layout program. In this situation, the PDF 'page' is not composited with the media colour; instead, it is treated as an ordinary transparency group, which can be either isolated or non-isolated and is composited with its backdrop in the normal way.

The remainder of this sub-clause pertains only to the first use of the page group, where it is to be imposed directly on the medium.

The colour C of the page at a given point shall be defined by a simplification of the general group compositing formula:

where the variables have the meanings shown in Table 143. The first formula computes the colour and alpha for the group given a transparent backdrop-in effect, treating P as an isolated group. The second formula composites the results with the context-dependent backdrop (using the equivalent of the Normal blend mode).

Table 143 - Variables used in the page group compositing formulas

Variable Meaning
P The page group, consisting of all elements E 1 , …, E n in the page's top-level stack
C g Computed colour of the page group
f g Computed shape of the page group
α g Computed alpha of the page group
C Computed colour of the page
W Initial colour of the page (nominally white but may vary depending on the properties of the medium or the needs of the application)
U An undefined colour (which is not used, since the α 0 argument of Composite is 0)

If not otherwise specified, the page group's colour space shall be inherited from the native colour space of the output device-that is, a device colour space, such as DeviceRGB or DeviceCMYK . An explicit colour space should be specified, particularly a CIE-based space, to ensure more predictable results of the compositing computations within the page group. In this case, all page-level compositing shall be done in the specified colour space, and the entire result shall then be converted to the native colour space of the output device before being composited with the context-dependent backdrop.

NOTE This case also arises when the page is not actually being rendered but is converted to a flattened representation in an opaque imaging model, such as PostScript.

11.4.8 Summary of Group Compositing Computations

This sub-clause is a restatement of the group compositing formulas that also takes isolated groups and knockout groups into account. See Tables 141 and 142 in 11.4.4, "Group Compositing Computations," for the meanings of the variables.

Initialization:

For each group element E i ∈ G (i = 1, … , n) :

Result:

NOTE Once again, keep in mind that these formulas are in their most general form. They can be significantly simplified when some sources of shape and opacity are not present or when shape and opacity need not be maintained separately. Furthermore, in each specific type of group (isolated or not, knockout or not), some terms of these formulas cancel or drop out. An efficient implementation should use the simplified derived formulas.

11.5 Soft Masks

11.5.1 General

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 Deriving a Soft Mask from Group Alpha

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

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

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

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

using components of the Gamma and Matrix entries of the colour space dictionary (see Table 64 in 'CIEBased 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:

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.

PDF 32000-1:2008

11.6 Specifying Transparency in PDF

11.6.1 General

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

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

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

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

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 textshowing 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

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

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

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, "SoftMask 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

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


Navigation: PDF-Spec-11-Groups | PDF-Spec-Index | PDF-Spec-11-Specifying

Clone this wiki locally