PDF Reference sixth edition, Adobe Portable Document Format Version 1.7 (book 1) — page 13
495
SECTION 6.4
Halftones
2. If the requested gray level is less than the threshold value, paint the device pix-
el black; otherwise, paint it white. Gray levels in the range 0.0 to 1.0 corre-
spond to threshold values from 0 to the maximum available (255 or 65,535).
Note: A threshold value of 0 is treated as if it were 1; therefore, a gray level of 0.0
paints all pixels black, regardless of the values in the threshold array.
This scheme easily generalizes to monochrome devices with multiple bits per
pixel. For example, if there are 2 bits per pixel, each pixel can directly represent
one of four different gray levels: black, dark gray, light gray, or white, encoded as
0, 1, 2, and 3, respectively. For any device pixel that is specified with some in-
between gray level, the halftoning algorithm consults the corresponding value in
the threshold array to determine whether to use the next-lower or next-higher
representable gray level. In this situation, the threshold values do not represent
absolute gray levels, but rather gradations between any two adjacent represent-
able gray levels.
A halftone defined in this way can also be used with color displays that have a
limited number of values for each color component. The red, green, and blue
components are simply treated independently as gray levels, applying the ap-
propriate threshold array to each. (This technique also works for a screen defined
as a spot function, since the spot function is used to compute a threshold array
internally.)
6.4.4
Halftone Dictionaries
In PDF 1.2, the graphics state includes a current halftone parameter, which deter-
mines the halftoning process to be used by the painting operators. The current
halftone can be specified as the value of the HT entry in a graphics state parameter
dictionary; see Table 4.8 on page 220. It may be defined by either a dictionary or a
stream, depending on the type of halftone; the term halftone dictionary is used
generically throughout this section to refer to either a dictionary object or the
dictionary portion of a stream object. (The halftones that are defined by streams
are specifically identified as such in the descriptions of particular halftone types;
unless otherwise stated, they are understood to be defined by simple dictionaries
instead.)
Every halftone dictionary must have a HalftoneType entry whose value is an inte-
ger specifying the overall type of halftone definition. The remaining entries in the
496
CHAPTER 6
Rendering
dictionary are interpreted according to this type. PDF supports the halftone types
listed in Table 6.2.
TABLE 6.2 PDF halftone types
TYPE
MEANING
1
Defines a single halftone screen by a frequency, angle, and spot function.
5
Defines an arbitrary number of halftone screens, one for each colorant or color
component (including both primary and spot colorants). The keys in this dic-
tionary are names of colorants; the values are halftone dictionaries of other
types, each defining the halftone screen for a single colorant.
6
Defines a single halftone screen by a threshold array containing 8-bit sample
values.
10
Defines a single halftone screen by a threshold array containing 8-bit sample
values, representing a halftone cell that may have a nonzero screen angle.
16
(PDF 1.3) Defines a single halftone screen by a threshold array containing 16-
bit sample values, representing a halftone cell that may have a nonzero screen
angle.
The dictionaries representing these halftone types contain the same entries as
the corresponding PostScript language halftone dictionaries (as described in Sec-
tion 7.4 of the PostScript Language Reference, Third Edition), with the following
exceptions:
• The PDF dictionaries may contain a Type entry with the value Halftone, identi-
fying the type of PDF object that the dictionary describes.
• Spot functions and transfer functions are represented by function objects in-
stead of PostScript procedures.
• Threshold arrays are specified as streams instead of files.
• In type 5 halftone dictionaries, the keys for colorants must be name objects;
they may not be strings as they may in PostScript.
Halftone dictionaries have an optional entry, HalftoneName, that identifies the
halftone by name. In PDF 1.3, if this entry is present, all other entries, including
HalftoneType, are optional. At rendering time, if the output device has a halftone
with the specified name, that halftone is used, overriding any other halftone pa-
rameters specified in the dictionary. This provides a way for PDF documents to
497
SECTION 6.4
Halftones
select the proprietary halftones supplied by some device manufacturers, which
would not otherwise be accessible because they are not explicitly defined in PDF.
If there is no HalftoneName entry, or if the requested halftone name does not ex-
ist on the device, the halftone’s parameters are defined by the other entries in the
dictionary, if any. If no other entries are present, the default halftone is used.
See Section 7.6.4, “Rendering Parameters and Transparency,” and in particular,
“Halftone and Transfer Function” on page 573, for further discussion of the role
of halftones in the transparent imaging model.
Type 1 Halftones
Table 6.3 describes the contents of a halftone dictionary of type 1, which defines a
halftone screen in terms of its frequency, angle, and spot function.
TABLE 6.3 Entries in a type 1 halftone dictionary
KEY
TYPE
VALUE
Type
name
(Optional) The type of PDF object that this dictionary describes; if
present, must be Halftone for a halftone dictionary.
HalftoneType
integer
(Required) A code identifying the halftone type that this dictionary
describes; must be 1 for this type of halftone.
HalftoneName
byte string
(Optional) The name of the halftone dictionary.
Frequency
number
(Required) The screen frequency, measured in halftone cells per inch in
device space.
Angle
number
(Required) The screen angle, in degrees of rotation counterclockwise
with respect to the device coordinate system. (Most output devices
have left-handed device spaces. On such devices, a counterclockwise
angle in device space corresponds to a clockwise angle in default user
space and on the physical medium.)
SpotFunction
function or name
(Required) A function object defining the order in which device pixels
within a screen cell are adjusted for different gray levels, or the name of
one of the predefined spot functions (see Table 6.1 on page 489).
AccurateScreens
boolean
(Optional) A flag specifying whether to invoke a special halftone al-
gorithm that is extremely precise but computationally expensive; see
below for further discussion. Default value: false.
498
CHAPTER 6
Rendering
KEY
TYPE
VALUE
TransferFunction function or name
(Optional) A transfer function, which overrides the current transfer
function in the graphics state for the same component. This entry is re-
quired if the dictionary is a component of a type 5 halftone (see “Type
5 Halftones” on page 505) and represents either a nonprimary or non-
standard primary color component (see Section 6.3, “Transfer Func-
tions”). The name Identity may be used to specify the
identity
function.
If the AccurateScreens entry has a value of true, a highly precise halftoning algo-
rithm is substituted in place of the standard one. If AccurateScreens is false or not
present, ordinary halftoning is used. Accurate halftoning achieves the requested
screen frequency and angle with very high accuracy, whereas ordinary halftoning
adjusts them so that a single screen cell is quantized to device pixels. High accu-
racy is important mainly for making color separations on high-resolution devic-
es. However, it may be computationally expensive and therefore is ordinarily
disabled.
In principle, PDF permits the use of halftone screens with arbitrarily large cells—
in other words, arbitrarily low frequencies. However, cells that are very large
relative to the device resolution or that are oriented at unfavorable angles may ex-
ceed the capacity of available memory. If this happens, an error occurs. The
AccurateScreens feature often requires very large amounts of memory to achieve
the highest accuracy.
Example 6.1 shows a halftone dictionary for a type 1 halftone.
Example 6.1
28 0 obj
<< /Type /Halftone
/HalftoneType 1
/Frequency 120
/Angle 30
/SpotFunction /CosineDot
/TransferFunction /Identity
>>
endobj
499
SECTION 6.4
Halftones
Type 6 Halftones
A type 6 halftone defines a halftone screen with a threshold array. The halftone is
represented as a stream containing the threshold values; the parameters defining
the halftone are specified by entries in the stream dictionary. This dictionary can
contain the entries shown in Table 6.4 in addition to the usual entries common to
all streams (see Table 3.4 on page 62). The Width and Height entries specify the
dimensions of the threshold array in device pixels; the stream must contain
Width × Height bytes, each representing a single threshold value. Threshold val-
ues are defined in device space in the same order as image samples in image space
(see Figure 4.26 on page 338), with the first value at device coordinates (0, 0) and
horizontal coordinates changing faster than vertical coordinates.
Type 10 Halftones
Although type 6 halftones can be used to specify a threshold array with a zero
screen angle, they make no provision for other angles. The type 10 halftone re-
moves this restriction and allows the use of threshold arrays for halftones with
nonzero screen angles as well.
TABLE 6.4 Additional entries specific to a type 6 halftone dictionary
KEY
TYPE
VALUE
Type
name
(Optional) The type of PDF object that this dictionary describes; if
present, must be Halftone for a halftone dictionary.
HalftoneType
integer
(Required) A code identifying the halftone type that this dictionary
describes; must be 6 for this type of halftone.
HalftoneName
byte string
(Optional) The name of the halftone dictionary.
Width
integer
(Required) The width of the threshold array, in device pixels.
Height
integer
(Required) The height of the threshold array, in device pixels.
TransferFunction function or name
(Optional) A transfer function, which overrides the current transfer
function in the graphics state for the same component. This entry is re-
quired if the dictionary is a component of a type 5 halftone (see “Type
5 Halftones” on page 505) and represents either a nonprimary or non-
standard primary color component (see Section 6.3, “Transfer Func-
tions”). The name Identity may be used to specify the identity
function.
500
CHAPTER 6
Rendering
Halftone cells at nonzero angles can be difficult to specify because they may not
line up well with scan lines and because it may be difficult to determine where a
given sampled point goes. The type 10 halftone addresses these difficulties by
dividing the halftone cell into a pair of squares that line up at zero angles with the
output device’s pixel grid. The squares contain the same information as the origi-
nal cell but are much easier to store and manipulate. In addition, they can be
mapped easily into the internal representation used for all rendering.
Figure 6.2 shows a halftone cell with a frequency of 38.4 cells per inch and an
angle of 50.2 degrees, represented graphically in device space at a resolution of
300 dots per inch. Each asterisk in the figure represents a location in device space
that is mapped to a specific location in the threshold array.
FIGURE 6.2 Halftone cell with a nonzero angle
Figure 6.3 shows how the halftone cell can be divided into two squares. If the
squares and the original cell are tiled across device space, the area to the right of
the upper square maps exactly into the empty area of the lower square, and vice
versa (see Figure 6.4). The last row in the first square is immediately adjacent to
the first row in the second square and starts in the same column.
501
SECTION 6.4
Halftones
X
*
Y
*
FIGURE 6.3 Angled halftone cell divided into two squares
Y
X
X
a
a
a a
a a
a a a
a a a
a a a a
a a a a
a a a a a
a a a a a
Y
a a a a a a a a a a b
b
a a a a a a a a b b
b b
a a a a a a b b b
b b b
a a a a b b b b
b b b b
a a b b b b b
* b
b b b
Y
a
b b b b b b b b b b
c
c b b b b b b b b
X
c c
c c b b b b b b
c c c
c c c b b b b
c c c c
c c c c
b b
c c c c c
c c c
b
* c
c c c c c c c c c c
c c c c c c c c
c c c c c c
c c c c
c c
Y
c
FIGURE 6.4 Halftone cell and two squares tiled across device space
502
CHAPTER 6
Rendering
Any halftone cell can be divided in this way. The side of the upper square (X) is
equal to the horizontal displacement from a point in one halftone cell to the cor-
responding point in the adjacent cell, such as those marked by asterisks in Figure
6.4. The side of the lower square (Y) is the vertical displacement between the
same two points. The frequency of a halftone screen constructed from squares
with sides X and Y is thus given by
resolution
frequency
= -----------------------
X2
+
Y2
and the angle by
⎛Y ⎞
angle
= atan
---
⎝X⎠
Like a type 6 halftone, a type 10 halftone is represented as a stream containing
the threshold values, with the parameters defining the halftone specified by en-
tries in the stream dictionary. This dictionary can contain the entries shown in
Table 6.5 in addition to the usual entries common to all streams (see Table 3.4 on
page 62). The Xsquare and Ysquare entries replace the type 6 halftone’s Width
and Height entries.
TABLE 6.5 Additional entries specific to a type 10 halftone dictionary
KEY
TYPE
VALUE
Type
name
(Optional) The type of PDF object that this dictionary describes;
if
present, must be Halftone for a halftone dictionary.
HalftoneType
integer
(Required) A code identifying the halftone type that this dictionary
describes; must be 10 for this type of halftone.
HalftoneName
byte string
(Optional) The name of the halftone dictionary.
Xsquare
integer
(Required) The side of square X, in device pixels; see below.
Ysquare
integer
(Required) The side of square Y, in device pixels; see below.
TransferFunction function or
(Optional) A transfer function, which overrides the current transfer func-
name
tion in the graphics state for the same component. This entry is required
if the dictionary is a component of a type 5 halftone (see “Type 5 Half-
tones” on page 505) and represents either a nonprimary or nonstandard
primary color component (see Section 6.3, “Transfer Functions”). The
name Identity may be used to specify the identity function.
503
SECTION 6.4
Halftones
The Xsquare and Ysquare entries specify the dimensions of the two squares in
device pixels. The stream must contain Xsquare 2 + Ysquare 2 bytes, each repre-
senting a single threshold value. The contents of square X are specified first,
followed by those of square Y. Threshold values within each square are defined in
device space in the same order as image samples in image space (see Figure 4.26
on page 338), with the first value at device coordinates (0, 0) and horizontal coor-
dinates changing faster than vertical coordinates.
Type 16 Halftones
Like type 10, a type 16 halftone (PDF 1.3) defines a halftone screen with a thresh-
old array and allows nonzero screen angles. In type 16, however, each element of
the threshold array is 16 bits wide instead of 8. This allows the threshold array to
distinguish 65,536 levels of color rather than only 256 levels. The threshold array
can consist of either one rectangle or two rectangles. If two rectangles are speci-
fied, they tile the device space as shown in Figure 6.5. The last row in the first
rectangle is immediately adjacent to the first row in the second and starts in the
same column.
Width
Height
Width ´ Height
Height2
Width2 ´
Height2
Width2
FIGURE 6.5 Tiling of device space in a type 16 halftone
A type 16 halftone, like type 6 and type 10, is represented as a stream containing
the threshold values, with the parameters defining the halftone specified by en-
tries in the stream dictionary. This dictionary can contain the entries shown in
Table 6.6 in addition to the usual entries common to all streams (see Table 3.4 on
page 62). The dictionary’s Width and Height entries define the dimensions of the
first (or only) rectangle. The dimensions of the second, optional rectangle are de-
fined by the optional entries Width2 and Height2. Each threshold value is repre-
504
CHAPTER 6
Rendering
sented as 2 bytes, with the high-order byte first. The stream must therefore
contain
2 × Width × Height bytes if there is only one rectangle or
2 × (Width × Height + Width2 × Height2) bytes if there are two rectangles. The
contents of the first rectangle are specified first, followed by those of the second
rectangle. Threshold values within each rectangle are defined in device space in
the same order as image samples in image space (see Figure 4.26 on page 338),
with the first value at device coordinates (0, 0) and horizontal coordinates chang-
ing faster than vertical coordinates.
TABLE 6.6 Additional entries specific to a type 16 halftone dictionary
KEY
TYPE
VALUE
Type
name
(Optional) The type of PDF object that this dictionary describes; if
present, must be Halftone for a halftone dictionary.
HalftoneType
integer
(Required) A code identifying the halftone type that this dictionary
describes; must be 16 for this type of halftone.
HalftoneName
byte string
(Optional) The name of the halftone dictionary.
Width
integer
(Required) The width of the first (or only) rectangle in the threshold
array, in device pixels.
Height
integer
(Required) The height of the first (or only) rectangle in the threshold
array, in device pixels.
Width2
integer
(Optional) The width of the optional second rectangle in the threshold
array, in device pixels. If this entry is present, the Height2 entry must
be present as well. If this entry is absent, the Height2 entry must also be
absent, and the threshold array has only one rectangle.
Height2
integer
(Optional) The height of the optional second rectangle in the threshold
array, in device pixels.
TransferFunction
function or name
(Optional) A transfer function, which overrides the current transfer
function in the graphics state for the same component. This entry is re-
quired if the dictionary is a component of a type 5 halftone (see “Type
5 Halftones,” below) and represents either a nonprimary or nonstand-
ard primary color component (see Section 6.3, “Transfer Functions”).
The name Identity may be used to specify the identity function.
505
SECTION 6.4
Halftones
Type 5 Halftones
Some devices, particularly color printers, require separate halftones for each indi-
vidual colorant. Also, devices that can produce named separations may require
individual halftones for each separation. Halftone dictionaries of type 5 allow
individual halftones to be specified for an arbitrary number of colorants or color
components.
A type 5 halftone dictionary (Table 6.7) is a composite dictionary containing
independent halftone definitions for multiple colorants. Its keys are name objects
representing the names of individual colorants or color components. The values
associated with these keys are other halftone dictionaries, each defining the half-
tone screen and transfer function for a single colorant or color component. The
component halftone dictionaries may be of any supported type except 5.
TABLE 6.7 Entries in a type 5 halftone dictionary
KEY
TYPE
VALUE
Type
name
(Optional) The type of PDF object that this dictionary describes; if present,
must be Halftone for a halftone dictionary.
HalftoneType
number
(Required) A code identifying the halftone type that this dictionary describes;
must be 5 for this type of halftone.
HalftoneName
byte string
(Optional) The name of the halftone dictionary.
any colorant
dictionary
(Required, one per colorant) The halftone corresponding to the colorant or
name
or stream
color component named by the key. The halftone may be of any type other
than 5. Note that the key must be a name object; strings are not permitted, as
they are in type 5 PostScript halftone dictionaries.
Default
dictionary
(Required) A halftone to be used for any colorant or color component that
or stream
does not have an entry of its own. The value may not be a type 5 halftone. If
there are any nonprimary colorants, the default halftone must have a transfer
function.
506
CHAPTER 6
Rendering
The colorants or color components represented in a type 5 halftone dictionary
fall into two categories:
• Primary color components for the standard native device color spaces (Gray for
DeviceGray; Red, Green, and Blue for DeviceRGB; Cyan, Magenta, Yellow, and
Black for DeviceCMYK;).
• Nonstandard color components for use as spot colorants in Separation and
DeviceN color spaces. Some of these may also be used as process colorants if
the native color space is nonstandard.
The dictionary must also contain an entry whose key is Default. The value of this
entry is a halftone dictionary to be used for any color component that does not
have an entry of its own.
When a halftone dictionary of some other type appears as the value of an entry in
a type 5 halftone dictionary, it applies only to the single colorant or color com-
ponent named by that entry’s key. This is in contrast to such a dictionary’s being
used as the current halftone parameter in the graphics state, which applies to all
color components. If nonprimary colorants are requested when the current half-
tone is defined by any means other than a type 5 halftone dictionary, the gray
halftone screen and transfer function are used for all such colorants.
Example 6.2 shows a type 5 halftone dictionary with the primary color compo-
nents for a CMYK device. In this example, the halftone dictionaries for the color
components and for the default all use the same spot function.
Example 6.2
27 0 obj
<< /Type /Halftone
/HalftoneType 5
/Cyan 31 0 R
/Magenta 32 0 R
/Yellow 33 0 R
/Black 34 0 R
/Default 35 0 R
>>
endobj
507
SECTION 6.4
Halftones
31 0 obj
<< /Type /Halftone
/HalftoneType 1
/Frequency 89.827
/Angle 15
/SpotFunction /Round
/AccurateScreens true
>>
endobj
32 0 obj
<< /Type /Halftone
/HalftoneType 1
/Frequency 89.827
/Angle 75
/SpotFunction /Round
/AccurateScreens true
>>
endobj
33 0 obj
<< /Type /Halftone
/HalftoneType 1
/Frequency 90.714
/Angle 0
/SpotFunction /Round
/AccurateScreens true
>>
endobj
34 0 obj
<< /Type /Halftone
/HalftoneType 1
/Frequency 89.803
/Angle 45
/SpotFunction /Round
/AccurateScreens true
>>
endobj
508
CHAPTER 6
Rendering
35 0 obj
<< /Type /Halftone
/HalftoneType 1
/Frequency 90.000
/Angle 45
/SpotFunction /Round
/AccurateScreens true
>>
endobj
6.5
Scan Conversion Details
The final step of rendering is scan conversion. As discussed in Section 2.1.4, “Scan
Conversion,” the application executes a scan conversion algorithm to paint
graphics, text, and images in the raster memory of the output device.
The specifics of the scan conversion algorithm are not defined as part of PDF.
Different implementations can perform scan conversion in different ways; tech-
niques that are appropriate for one device may be inappropriate for another. Still,
it is useful to have a general understanding of how scan conversion works, partic-
ularly when creating PDF documents intended for viewing on a display. At the
low resolutions typical of displays, variations of even one pixel’s width can have a
noticeable effect on the appearance of painted shapes.
The following sections describe the scan conversion algorithms that are typical of
Acrobat products. (These details also apply to PostScript products, yielding con-
sistent results when an application prints a document on a PostScript printer.)
Most scan conversion details are not under program control, but a few are; the
parameters for controlling them are described here.
6.5.1
Flatness Tolerance
The flatness tolerance controls the maximum permitted distance in device pixels
between the mathematically correct path and an approximation constructed from
straight line segments, as shown in Figure 6.6. Flatness can be specified as the op-
erand of the i operator (see Table 4.7 on page 219) or as the value of the FL entry
in a graphics state parameter dictionary (see Table 4.8 on page 220). It must be a
positive number; smaller values yield greater precision at the cost of more com-
putation.
509
SECTION 6.5
Scan Conversion Details
Note: Although the figure exaggerates the difference between the curved and flat-
tened paths for the sake of clarity, the purpose of the flatness tolerance is to control
the precision of curve rendering, not to draw inscribed polygons. If the parameter’s
value is large enough to cause visible straight line segments to appear, the result is
unpredictable.
Flatness error
tolerance
FIGURE 6.6 Flatness tolerance
6.5.2
Smoothness Tolerance
The smoothness tolerance (PDF 1.3) controls the quality of smooth shading
(type 2 patterns and the sh operator) and thus indirectly controls the rendering
performance. Smoothness is the allowable color error between a shading approx-
imated by piecewise linear interpolation and the true value of a (possibly non-
linear) shading function. The error is measured for each color component, and
the maximum error is used. The allowable error (or tolerance) is expressed as a
fraction of the range of the color component, from 0.0 to 1.0. Thus, a smoothness
tolerance of 0.1 represents a tolerance of 10 percent in each color component.
Smoothness can be specified as the value of the SM entry in a graphics state
parameter dictionary (see Table 4.8 on page 220).
Each output device may have internal limits on the maximum and minimum
tolerances attainable. For example, setting smoothness to 1.0 may result in an in-
ternal smoothness of 0.5 on a high-quality color device, while setting it to 0.0 on
the same device may result in an internal smoothness of 0.01 if an error of that
magnitude is imperceptible on the device.
510
CHAPTER 6
Rendering
The smoothness tolerance may also interact with the accuracy of color conver-
sion. In the case of a color conversion defined by a sampled function, the con-
version function is unknown. Thus the error may be sampled at too low a
frequency, in which case the accuracy defined by the smoothness tolerance can-
not be guaranteed. In most cases, however, where the conversion function is
smooth and continuous, the accuracy should be within the specified tolerance.
The effect of the smoothness tolerance is similar to that of the flatness tolerance.
Note, however, that flatness is measured in device-dependent units of pixel width,
whereas smoothness is measured as a fraction of color component range.
6.5.3
Scan Conversion Rules
The following rules determine which device pixels a painting operation affects.
All references to coordinates and pixels are in device space. A shape is a path to be
painted with the current color or with an image. Its coordinates are mapped into
device space but not rounded to device pixel boundaries. At this level, curves
have been flattened to sequences of straight lines, and all “insideness” computa-
tions have been performed.
Pixel boundaries always fall on integer coordinates in device space. A pixel is a
square region identified by the location of its corner with minimum horizontal
and vertical coordinates. The region is half-open, meaning that it includes its
lower but not its upper boundaries. More precisely, for any point whose real-
number coordinates are (x, y), let i = floor (x) and j = floor (y). The pixel that con-
tains this point is the one identified as (i, j). The region belonging to that pixel is
defined to be the set of points (x ′, y ′) such that i ≤ x ′ < i + 1 and j ≤ y ′ < j + 1.
Like pixels, shapes to be painted by filling and stroking operations are also treated
as half-open regions that include the boundaries along their “floor” sides, but not
along their “ceiling” sides.
A shape is scan-converted by painting any pixel whose square region intersects
the shape, no matter how small the intersection is. This ensures that no shape
ever disappears as a result of unfavorable placement relative to the device pixel
grid, as might happen with other possible scan conversion rules. The area cov-
ered by painted pixels is always at least as large as the area of the original shape.
This rule applies both to fill operations and to strokes with nonzero width. Zero-
width strokes are done in a device-dependent manner that may include fewer
pixels than the rule implies.
511
SECTION 6.5
Scan Conversion Details
Note: Normally, the intersection of two regions is defined as the intersection of their
interiors. However, for purposes of scan conversion, a filling region is considered to
intersect every pixel through which its boundary passes, even if the interior of the
filling region is empty. Thus, for example, a zero-width or zero-height rectangle
paints a line 1 pixel wide.
The region of device space to be painted by a sampled image is determined simi-
larly to that of a filled shape, though not identically. The application transforms
the image’s source rectangle into device space and defines a half-open region, just
as for fill operations. However, only those pixels whose centers lie within the re-
gion are painted. The position of the center of such a pixel—in other words, the
point whose coordinate values have fractional parts of one-half—is mapped back
into source space to determine how to color the pixel. There is no averaging over
the pixel area; if the resolution of the source image is higher than that of device
space, some source samples are not used.
For clipping, the clipping region consists of the set of pixels that would be in-
cluded by a fill operation. Subsequent painting operations affect a region that is
the intersection of the set of pixels defined by the clipping region with the set of
pixels for the region to be painted.
Scan conversion of character glyphs is performed by a different algorithm from
the one above. That font rendering algorithm uses hints in the glyph descriptions
and techniques that are specialized to glyph rasterization.
6.5.4
Automatic Stroke Adjustment
When a stroke is drawn along a path, the scan conversion algorithm may produce
lines of nonuniform thickness because of rasterization effects. In general, the line
width and the coordinates of the endpoints, transformed into device space, are
arbitrary real numbers not quantized to device pixels. A line of a given width can
intersect with different numbers of device pixels, depending on where it is posi-
tioned. Figure 6.7 illustrates this effect.
For best results, it is important to compensate for the rasterization effects to pro-
duce strokes of uniform thickness. This is especially important in low-resolution
display applications. To meet this need, PDF 1.2 provides an optional automatic
stroke adjustment feature. When stroke adjustment is enabled, the line width and
the coordinates of a stroke are automatically adjusted as necessary to produce
512
CHAPTER 6
Rendering
lines of uniform thickness. The thickness is as near as possible to the requested
line width—no more than half a pixel different.
Line width
Line width
Path
Path
1
pixel
Resulting line
Resulting line
FIGURE 6.7 Rasterization without stroke adjustment
Note: If stroke adjustment is enabled and the requested line width, transformed into
device space, is less than half a pixel, the stroke is rendered as a single-pixel line.
This is the thinnest line that can be rendered at device resolution. It is equivalent to
the effect produced by setting the line width to 0 (see Section 6.5.3, “Scan Conver-
sion Rules”).
Because automatic stroke adjustment can have a substantial effect on the appear-
ance of lines, a PDF document must be able to control whether the adjustment is
to be performed. This can be specified with the stroke adjustment parameter in
the graphics state, set by means of the SA entry in a graphics state parameter dic-
tionary (see Section 4.3.4, “Graphics State Parameter Dictionaries”); see imple-
mentation note 71 in Appendix H.
CHAPTER 7
Transparency
7
PDF 1.4 extends the Adobe imaging model to include the notion of transparency.
Transparent objects do not necessarily obey a strict opaque painting model but
can blend (composite) in interesting ways with other overlapping objects. This
chapter describes the general transparency model but does not cover how it is im-
plemented. Implementation-like descriptions are used at various points to de-
scribe how things work, for the purpose of elucidating the behavior of the model.
The actual implementation will almost certainly be different from what these de-
scriptions might imply.
The chapter is organized as follows:
• Section 7.1, “Overview of Transparency,” introduces the basic concepts of the
transparency model and its associated terminology.
• Section 7.2, “Basic Compositing Computations,” describes the mathematics
involved in compositing a single object with its backdrop.
• Section 7.3, “Transparency Groups,” introduces the concept of transparency
groups and describes their properties and behavior.
• Section 7.4, “Soft Masks,” covers the creation and use of masks to specify
position-dependent shape and opacity.
• Section 7.5, “Specifying Transparency in PDF,” describes how transparency
properties are represented in a PDF document.
• Section 7.6, “Color Space and Rendering Issues,” deals with some specific inter-
actions between transparency and other aspects of color specification and
rendering.
513
514
CHAPTER 7
Transparency
7.1
Overview of Transparency
The original Adobe imaging model paints objects (fills, strokes, text, and images),
possibly clipped by a path, opaquely onto a page. The color of the page at any
point is that of the topmost enclosing object, disregarding any previous objects it
may overlap. This effect can be—and often is—realized simply by rendering ob-
jects 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 can potentially
contribute to the result. Objects at a given point can be thought of as forming a
transparency stack (or stack for short). The objects are arranged from bottom to
top in the order in which they are specified. The color of the page at each point is
determined by combining the colors of all enclosing objects in the stack accord-
ing to compositing rules defined by the transparency model.
Note: 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 consumer application to ras-
terize 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 inter-
mediate stages of the transparency computation.
A given object is composited with a backdrop. Ordinarily, the backdrop consists
of the stack of all objects that have been specified previously. The result of com-
positing is then treated as the backdrop for the next object. However, within cer-
tain kinds of transparency groups (see below), a different backdrop is chosen.
When an object is composited with its backdrop, the color at each point is com-
puted using a specified blend mode, which is a function of both the object’s color
and the backdrop color. The blend mode determines how colors interact; differ-
ent blend modes can be used to achieve a variety of useful effects. A single blend
mode is in effect for compositing all of a given object, but different blend modes
can be applied to different objects.
Compositing of an object with its backdrop is mediated by two scalar quantities
called shape and opacity. Conceptually, for each object, these quantities are de-
fined at every point in the plane, just as if they were additional color components.
(In actual practice, they are often obtained from auxiliary sources rather than be-
ing intrinsic to the object.)
515
SECTION 7.1
Overview of Transparency
Both shape and opacity vary from 0.0 (no contribution) to 1.0 (maximum contri-
bution). At any point where either the shape or the opacity of an object is 0.0, its
color is undefined. At points where the shape is 0.0, the opacity is also undefined.
The shape and opacity are 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, determines the
relative contributions of the backdrop color, the object’s color, and the blended
color to the resulting composite color. The object’s shape then determines the de-
gree to which the composite color replaces the backdrop color. 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 com-
bined into a single value, called alpha, which controls both the color compositing
computation and the fading between an object and its backdrop. However, there
are a few situations in which they must be treated separately; see Section 7.3.5,
“Knockout Groups.” Moreover, raster-based implementations must maintain a
separate shape parameter to do anti-aliasing properly; it is therefore convenient
to have it be an explicit part of the model.
One or more consecutive objects in a stack can be collected together into a trans-
parency group (often referred to hereafter simply as a group). The group as a
whole can have various properties that modify the compositing behavior of ob-
jects within the group and their interactions with its backdrop. An additional
blend mode, shape, and opacity can also be associated with the group as a whole
and used when compositing it with its backdrop. Groups can be nested within
other groups, forming a tree-structured hierarchy.
Note: The concept of a transparency group is independent of existing notions of
group or layer in applications such as Adobe Illustrator®. Those groupings reflect
logical relationships among objects that are meaningful when editing those objects,
but they are not part of the imaging model.
Plate 16 illustrates the effects of transparency grouping. In the upper two figures,
three colored 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 color. 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
516
CHAPTER 7
Transparency
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 color result of compositing a group can be converted to a single-component
luminosity value and treated as a soft mask. Such a mask can then be used as an
additional source of shape or opacity values for subsequent compositing opera-
tions. 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 Section 4.4.3, “Clipping Path Operators”).
The notion of current page is generalized to refer to a transparency group consist-
ing 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 is then rasterized
to determine the actual pixel values to be transmitted to the output device.
Note: In contexts where a PDF page is treated as a piece of artwork to be placed on
some other page—such as an Illustrator artboard or an Encapsulated PostScript
(EPS) file—it is treated not as a page but as a group, whose backdrop may be de-
fined differently from that of a page.
7.2
Basic Compositing Computations
This section describes the basic computations for compositing a single object
with its backdrop. These computations are extended in Section 7.3, “Transparen-
cy Groups,” to cover groups consisting of multiple objects.
7.2.1
Basic Notation for Compositing Computations
In general, variable names in this chapter 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 color. In the descriptions of the basic color compos-
iting computations, color values are generally denoted by the letter C, with a
517
SECTION 7.2
Basic Compositing Computations
mnemonic subscript indicating which of several color values is being referred to;
for instance, Cs stands for “source color.” Shape and opacity values are denoted re-
spectively 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 zero, the corresponding color 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 canceled out. The sig-
nificant point is that while any arbitrary value can be chosen for such an unde-
fined quantity, the computation must not malfunction because of exceptions
caused by overflow or division by zero. It is convenient to adopt the further con-
vention that 0 ÷ 0 = 0.
7.2.2
Basic Compositing Formula
The primary change in the imaging model to accommodate transparency is in
how colors are painted. In the transparent model, the result of painting (the result
color) is a function of both the color being painted (the source color) and the color
it is painted over (the backdrop color). Both of these colors may vary as a function
of position on the page; however, this section focuses on some fixed point on the
page and assumes a fixed backdrop and source color.
Other parameters in this computation are the alpha, which controls the relative
contributions of the backdrop and source colors, and the blend function, which
specifies how they are combined in the painting operation. The resulting basic
color compositing formula (or just basic compositing formula for short) determines
the result color produced by the painting operation:
⎛
αs⎞
αs
Cr
=
⎜1
- -----⎟
×
Cb
+
-----
×[
(
1
-
αb
)× Cs + αb× B(Cb, Cs
)]
αr
αr
⎝
⎠
where the variables have the meanings shown in Table 7.1.
518
CHAPTER 7
Transparency
TABLE 7.1 Variables used in the basic compositing formula
VARIABLE
MEANING
Cb
Backdrop color
Cs
Source color
Cr
Result color
αb
Backdrop alpha
αs
Source alpha
αr
Result alpha
B(Cb,Cs)
Blend function
This formula is actually a simplified form of the compositing formula in which
the shape and opacity values are combined and represented as a single alpha val-
ue; 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 over-
lapping coverage. The following sections elaborate on the meaning and implica-
tions of this formula.
7.2.3
Blending Color Space
The compositing formula shown above is actually a vector function: the colors it
operates on are represented in the form of n-element vectors, where n is the num-
ber of components required by the color space in which compositing is per-
formed. The ith component of the result color Cr is obtained by applying the
compositing formula to the ith components of the constituent colors Cb , Cs , and
B (Cb , Cs ). The result of the computation thus depends on the color space in
which the colors are represented. For this reason, the color space used for com-
positing, called the blending color space, is explicitly made part of the transparent
imaging model. When necessary, backdrop and source colors are converted to the
blending color space before the compositing computation.
519
SECTION 7.2
Basic Compositing Computations
Of the PDF color spaces described in Section 4.5, “Color Spaces,” the following
are supported as blending color spaces:
• DeviceGray
• DeviceRGB
• DeviceCMYK
• CalGray
• CalRGB
• ICCBased color spaces equivalent to those above (including calibrated CMYK)
The Lab space and ICCBased spaces that represent lightness and chromaticity sep-
arately (such as L*a*b*, L*u*v*, and HSV) are not allowed as blending color spac-
es 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 color space must be bidirectional; that is, the ICC profile
must contain both AToB and BToA transformations.
The blending color space is consulted only for process colors. Although blending
can also be done on individual spot colors specified in a Separation or DeviceN
color space, such colors are never converted to a blending color space (except in
the case where they first revert to their alternate color space, as described under
“Separation Color Spaces” on page 264 and “DeviceN Color Spaces” on page
268). Instead, the specified color components are blended individually with the
corresponding components of the backdrop.
The blend functions for the various blend modes assume that the range for each
color component is 0.0 to 1.0 and that the color space is additive. The former
condition is true for all of the allowed blending color spaces, but the latter condi-
tion is not true. In particular, the DeviceCMYK, Separation, and DeviceN spaces
are subtractive. When performing blending operations in subtractive color spac-
es, it is assumed that the color component values are complemented (subtracted
from 1.0) before the blend function is applied and that the results of the function
are then complemented back before being used. This adjustment makes the ef-
fects of the various blend modes numerically consistent across all color spaces.
However, the actual visual effect produced by a given blend mode still depends
on the color space. Blending in a device color space produces device-dependent
results, whereas in a CIE-based space it produces results that are consistent
across all devices. See Section 7.6, “Color Space and Rendering Issues,” for addi-
tional details concerning color spaces.
520
CHAPTER 7
Transparency
7.2.4
Blend Mode
In principle, the blend function B (Cb , Cs ), used in the compositing formula to
customize the blending operation, could be any function of the backdrop and
source colors that yields another color, Cr, for the result. PDF defines a standard
set of named blend functions, or blend modes, listed in Tables 7.2 and 7.3. Plates
18 and 19 illustrate the resulting visual effects for RGB and CMYK colors, respec-
tively.
A blend mode is termed separable if each component of the result color is com-
pletely determined by the corresponding components of the constituent back-
drop and source colors—that is, if the blend mode function B is applied
separately to each set of corresponding components:
cr
=
B(cb, cs
)
where the lowercase variables cr, cb , and cs denote corresponding components of
the colors Cr, Cb , and Cs , expressed in additive form. (Theoretically, a blend
mode could have a different function for each color component and still be sepa-
rable; however, none of the standard PDF blend modes have this property.) A
separable blend mode can be used with any color space, since it applies indepen-
dently to any number of components. Only separable blend modes can be used
for blending spot colors.
Table 7.2 lists the standard separable blend modes available in PDF.
TABLE 7.2 Standard separable blend modes
NAME
RESULT
Normal
Selects the source color, ignoring the backdrop:
B(cb,cs)
=
cs
Multiply
Multiplies the backdrop and source color values:
B(cb,cs)
=
cb × cs
The result color is always at least as dark as either of the two constituent colors. Multiply-
ing any color with black produces black; multiplying with white leaves the original color
unchanged. Painting successive overlapping objects with a color other than black or white
produces progressively darker colors.
521
SECTION 7.2
Basic Compositing Computations
NAME
RESULT
Screen
Multiplies the complements of the backdrop and source color values, then complements
the result:
B(cb,cs)
=
1
– [
(
1
-
cb
)
×
(
1
–
cs
)]
=
cb + cs
-
(
cb × cs
)
The result color is always at least as light as either of the two constituent colors. Screening
any color with white produces white; screening with black leaves the original color un-
changed. The effect is similar to projecting multiple photographic slides simultaneously
onto a single screen.
Overlay
Multiplies or screens the colors, depending on the backdrop color value. Source colors
overlay the backdrop while preserving its highlights and shadows. The backdrop color is
not replaced but is mixed with the source color to reflect the lightness or darkness of the
backdrop.
B(cb,cs)
=
HardLight(cs, cb)
Darken
Selects the darker of the backdrop and source colors:
B(cb,cs)
=
min(cb, cs
)
The backdrop is replaced with the source where the source is darker; otherwise, it is left
unchanged.
Lighten
Selects the lighter of the backdrop and source colors:
B(cb,cs)
=
max(cb, cs
)
The backdrop is replaced with the source where the source is lighter; otherwise, it is left
unchanged.
ColorDodge
Brightens the backdrop color to reflect the source color. Painting with black produces no
changes.
min(1,cb
⁄
(
1
–
cs
))
if cs
<
1
⎧
B(cb,cs)
=
⎨
⎩1
if c
=
1
s
ColorBurn
Darkens the backdrop color to reflect the source color. Painting with white produces no
change.
1
–
min(1,
(
1
-
cb
)⁄ cs)
if cs
>
0
⎧
B(cb,cs)
=
⎨
⎩0
if cs
=
0
522
CHAPTER 7
Transparency
NAME
RESULT
HardLight
Multiplies or screens the colors, depending on the source color value. The effect is similar
to shining a harsh spotlight on the backdrop.
Multiply(cb, 2
×
cs)
if cs ≤ 0.5
⎧
B(cb,cs)
=
⎨
⎩Screen(c
×
cs
-
1)
if cs > 0.5
b, 2
SoftLight
Darkens or lightens the colors, depending on the source color value. The effect is similar
to shining a diffused spotlight on the backdrop.
cb
–
(
1
–
2
×
cs
)× cb
×
(
1
–
cb
)
if cs ≤ 0.5
⎧
(
)
=
⎨
c
+
(
2
×
cs
-
1
)
×
(
(
) cb
)
if cs > 0.5
⎩
b
where
⎧((16 × x - 12) × x + 4) × x
if x ≤ 0.25
D(x)
=
⎨
⎩
x
if x > 0.25
Difference
Subtracts the darker of the two constituent colors from the lighter color:
B(cb,cs)
=
cb – cs
Painting with white inverts the backdrop color; painting with black produces no change.
Exclusion
Produces an effect similar to that of the Difference mode but lower in contrast. Painting
with white inverts the backdrop color; painting with black produces no change.
B(cb,cs)
=
cb + cs
–
2
×
cb
×
c
s
Table 7.3 lists the standard nonseparable blend modes. Since the nonseparable
blend modes consider all color components in combination, their computation
depends on the blending color space in which the components are interpreted.
They may be applied to all multiple-component color spaces that are allowed as
blending color spaces (see Section 7.2.3, “Blending Color Space”).
All of these blend modes conceptually entail the following steps:
1. Convert the backdrop and source colors from the blending color space to an
intermediate HSL (hue-saturation-luminosity) representation.
2. Create a new color from some combination of hue, saturation, and luminosity
components selected from the backdrop and source colors.
523
SECTION 7.2
Basic Compositing Computations
3. Convert the result back to the original (blending) color space.
However, the formulas given below do not actually perform these conversions.
Instead, they start with whichever color (backdrop or source) is providing the hue
for the result; then they adjust this color to have the proper saturation and lumi-
nosity.
The nonseparable blend mode formulas make use of several auxiliary functions.
These functions operate on colors that are assumed to have red, green, and blue
components. (Blending of CMYK color spaces requires special treatment, as de-
scribed below.)
Lum(C)
=
0.3
×
Cred
+
0.59
×
Cgreen
+
0.11
×
Cblue
SetLum(C, l)
let d
=
l
-
Lum(C)
Cred
=
Cred + d
Cgreen
=
Cgreen + d
Cblue
=
Cblue + d
returnClipColor(C)
ClipColor(C)
let l
=
Lum(C)
let n
=
min(Cred, Cgreen, Cblue)
let x
=
max(Cred,Cgreen,Cblue)
if n
<
0.0
Cred
=
l
+
(((
Cred
-
l
)×l)⁄(l-n))
Cgreen
=
l
+
(((
Cgreen
-
l
)×l)⁄(l-n))
Cblue
=
l
+
(((
Cblue
-
l
)×l)⁄(l-n))
if x
>
1.0
Cred
=
l
+
(((
Cred
-
l
)×(1-l))⁄(x-l))
Cgreen
=
l
+
(((
Cgreen
-
l
)×(1-l))⁄(x-l))
Cblue
=
l
+
(((
Cblue
-
l
)×(1-l))⁄(x-l))
return C
Sat(C)
=
max(Cred, Cgreen, Cblue) min(Cred, Cgreen, Cblue)
524
CHAPTER 7
Transparency
In the following function, the subscripts min, mid, and max refer to the color
components having the minimum, middle, and maximum values upon entry to
the function.
SetSat(C, s)
if Cmax > Cmin
Cmid
=
(
(
(
Cmid Cmin
)×s)⁄(Cmax – Cmin
))
Cmax
=
s
else
Cmid = Cmax
=
0.0
Cmin
=
0.0
return C
TABLE 7.3 Standard nonseparable blend modes
NAME
RESULT
Hue
Creates a color with the hue of the source color and the saturation and luminosity of the
backdrop color.
B(Cb,Cs) = SetLum(SetSa
(
,
(
)), Lum(Cb))
Saturation
Creates a color with the saturation of the source color and the hue and luminosity of the
backdrop color. Painting with this mode in an area of the backdrop that is a pure gray (no
saturation) produces no change.
B(Cb,Cs) = SetLum(SetSa
(
,
(
)), Lum(Cb))
Color
Creates a color with the hue and saturation of the source color and the luminosity of the
backdrop color. This preserves the gray levels of the backdrop and is useful for coloring
monochrome images or tinting color images.
B(Cb,Cs) = SetLu
(
,
(
))
Luminosity
Creates a color with the luminosity of the source color and the hue and saturation of the
backdrop color. This produces an inverse effect to that of the Color mode.
B(Cb,Cs) = SetLu
(
,
(
))
525
SECTION 7.2
Basic Compositing Computations
The above formulas apply to RGB spaces. Blending in CMYK spaces (including
both DeviceCMYK and ICCBased calibrated CMYK spaces) is handled in the fol-
lowing way:
• The C, M, and Y components are converted to their complementary R, G, and
B components in the usual way. The formulas above are applied to the RGB col-
or values. The results are converted back to C, M, and Y.
• For the K component, the result is the K component of Cb for the Hue, Satura-
tion, and Color blend modes; it is the K component of Cs for the Luminosity
blend mode.
Note: An additional standard blend mode, Compatible, is a vestige of an earlier de-
sign and is no longer needed but is still recognized for the sake of compatibility. Its
effect is equivalent to that of the Normal blend mode. See “Compatibility with
Opaque Overprinting” on page 567 for further discussion.
7.2.5
Interpretation of Alpha
The color compositing formula
⎛
αs⎞
αs
Cr
=
⎜1
- -----⎟
×
Cb
+
-----
×[
(
1
-
αb
)× Cs + αb× B(Cb, Cs
)]
α
αr
⎝
r
⎠
produces a result color that is a weighted average of the backdrop color, the
source color, and the blended B (Cb , Cs ) term, with the weighting determined by
the backdrop and source alphas αb and αs . For the simplest blend mode, Normal,
defined by
·
B(cb,
cs
)
=
cs
the compositing formula collapses to a simple weighted average of the backdrop
and source colors, 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 colors.
The result alpha, αr, is actually a computed result, described below in Section
7.2.6, “Shape and Opacity Computations.” The result color is normalized by the
result alpha, ensuring that when this color and alpha are subsequently used to-
526
CHAPTER 7
Transparency
gether in another compositing operation, the color’s contribution is correctly rep-
resented. Note that if αr is zero, the result color is undefined.
The formula shown above is a simplification of the following formula, which pre-
sents the relative contributions of backdrop, source, and blended colors in a more
straightforward way:
αr × Cr
=
[
(
1
-
αs
)× αb× Cb
]
+
[
(
1
-
αb
)× αs× Cs
]
+[
αb ×αs ×B(Cb,Cs
)]
(The simplification requires a substitution based on the alpha compositing for-
mula, which is presented in the next section.) Thus, mathematically, the back-
drop and source alphas control the influence of the backdrop and source colors,
respectively, while their product controls the influence of the blend function. An
alpha value of αs = 0.0 or αb = 0.0 results in no blend mode effect; setting αs = 1.0
and αb = 1.0 results in maximum blend mode effect.
7.2.6
Shape and Opacity Computations
As stated earlier, the alpha values that control the compositing process are de-
fined as the product of shape and opacity:
αb = fb × qb
αr = fr × qr
αs = fs × qs
This section 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.
Source Shape and Opacity
Shape and opacity values can come from several sources. The transparency mod-
el provides for three independent sources for each. However, the PDF representa-
tion imposes some limitations on the ability to specify all of these sources
independently (see Section 7.5.3, “Specifying Shape and Opacity”).
• Object shape. Elementary objects such as strokes, fills, and text have an intrin-
sic shape, whose value is 1.0 for points inside the object and 0.0 outside. Simi-
larly, an image with an explicit mask (see “Explicit Masking” on page 351) has a
527
SECTION 7.2
Basic Compositing Computations
shape that is 1.0 in the unmasked portions and 0.0 in the masked portions. The
shape of a group object is the union of the shapes of the objects it contains.
Note: 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 can be taken from an addi-
tional source, or soft mask, independent of the object itself. (See Section 7.4,
“Soft Masks,” for a discussion of how such a mask might be generated.) 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 can be modified at every point by a scalar
shape constant. 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 is the result of the opacity computations for all of the
objects it contains.
• Mask opacity. Opacity values, like shape values, can be provided by a soft mask
independent of the object being composited.
• Constant opacity. The source opacity can be modified at every point by a scalar
opacity constant. It is useful to think of this value as the “current opacity,” anal-
ogous to the current color used when painting elementary objects.
All of these shape and opacity inputs range in value from 0.0 to 1.0, with a default
value of 1.0. The intent is that any of the inputs make the painting operation more
transparent as it goes toward 0.0. If more than one input goes toward 0.0, the ef-
fect is compounded. This is achieved mathematically by simply multiplying the
three inputs of each type, producing intermediate values called the source shape
and the source opacity:
fs
=
fj
×
fm × fk
qs
=
qj × qm × qk
where the variables have the meanings shown in Table 7.4.
528
CHAPTER 7
Transparency
TABLE 7.4 Variables used in the source shape and opacity formulas
VARIABLE
MEANING
fs
Source shape
fj
Object shape
fm
Mask shape
fk
Constant shape
qs
Source opacity
qj
Object opacity
qm
Mask opacity
qk
Constant opacity
Note: 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 Section 7.5.6, “Patterns
and Transparency”).
Result Shape and Opacity
In addition to a result color, the painting operation also computes an associated
result shape and result opacity. These computations are based on the union func-
tion
Union ( b, s ) = 1 - [(1 - b) × (1 - s)]
= b + s - (b×s)
where b and s are the backdrop and source values to be composited. This is a gen-
eralization 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 re-
sult is 1.0.
529
SECTION 7.2
Basic Compositing Computations
The result shape and opacity are given by
fr
=
Union(fb, fs
)
Union(fb × qb, fs × qs )
qr
= --------------------------------------------------------
f
r
where the variables have the meanings shown in Table 7.5.
TABLE 7.5 Variables used in the result shape and opacity formulas
VARIABLE
MEANING
fr
Result shape
fb
Backdrop shape
fs
Source shape
qr
Result opacity
qb
Backdrop opacity
qs
Source opacity
These formulas can be interpreted as follows:
• The result shape is simply the union of the backdrop and source shapes.
• The result opacity is the union of the backdrop and source opacities, weighted
by their respective shapes. The result is then normalized by the result shape,
ensuring that when this shape and opacity are subsequently used together in
another compositing operation, the opacity’s contribution is correctly repre-
sented.
Since alpha is just the product of shape and opacity, it can easily be shown that
αr = Union(αb, αs )
This formula can be used whenever the independent shape and opacity results
are not needed.
530
CHAPTER 7
Transparency
7.2.7
Summary of Basic Compositing Computations
Below is a summary of all the computations presented in this section. 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 7.1, 7.4, and 7.5
above for the meanings of the variables used in these formulas.
Union ( b, s ) = 1 - [(1 - b) × (1 - s)]
= b + s - (b×s)
fs
=
fj
×
fm × fk
qs
=
qj
×
qm ×qk
·
fr
=
Union(fb,
fs
)
αb = fb × qb
αs
=
fs
×
qs
αr
=
Union(αb,αs
)
αr
qr
= -----
f
r
⎛
αs⎞
αs
Cr
=
⎜1
- -----⎟
×
Cb
+
-----
×[
(
1
-
αb
)× Cs + αb× B(Cb, Cs
)]
α
αr
⎝
r
⎠
7.3
Transparency Groups
A transparency group is a sequence of consecutive objects in a transparency stack
that are collected together and composited to produce a single color, shape, and
opacity at each point. The result is then treated as if it were a single object for sub-
sequent compositing operations. This facilitates creating independent pieces of
artwork, each composed of multiple objects, and then combining them, possibly
with additional transparency effects applied during the combination. Groups can
be nested within other groups to form a tree-structured group hierarchy.
The objects contained within a group are treated as a separate transparency stack
called the group stack. The objects in the stack are composited against some initial
backdrop (discussed later), producing a composite color, shape, and opacity for
the group as a whole. The result is an object whose shape is the union of the
531
SECTION 7.3
Transparency Groups
shapes of its constituent objects and whose color and opacity are the result of the
compositing operations. This object is then composited with the group’s back-
drop in the usual way.
In addition to its computed color, shape, and opacity, the group as a whole can
have several further attributes:
• All of the input variables that affect the compositing computation for individu-
al objects can also be applied when compositing the group with its backdrop.
These variables include mask and constant shape, mask and constant opacity,
and blend mode.
• The group can be isolated or non-isolated, determining the initial backdrop
against which its stack is composited.
• The group can be knockout or non-knockout, determining whether the objects
within its stack are composited with one another or only with the group’s back-
drop.
• An isolated group can specify its own blending color space, independent of that
of the group’s backdrop.
• Instead of being composited onto the current page, a group’s results can be used
as a source of shape or opacity values for creating a soft mask (see Section 7.4,
“Soft Masks”).
The next section introduces some notation for dealing with group compositing.
Subsequent sections describe the group compositing formulas for a non-isolated,
non-knockout group and the special properties of isolated and knockout groups.
7.3.1
Notation for Group Compositing Computations
Since we are now dealing with multiple objects at a time, it is useful to have some
notation for distinguishing among them. Accordingly, the variables introduced
earlier are altered to include a second-level subscript denoting an object’s position
in the transparency stack. Thus, for example,
stands for the source color of
Cs
i
the ith object in the stack. The subscript 0 represents the initial backdrop; sub-
scripts 1 to n denote the bottommost to topmost objects in an n-element stack. In
addition, the subscripts b and r are dropped from the variables Cb , fb , qb , αb , Cr,
fr, qr, and αr ; other variables retain their mnemonic subscripts.
532
CHAPTER 7
Transparency
These conventions permit the compositing formulas to be restated as recurrence
relations among the elements of a stack. For instance, the result of the color com-
positing computation for object i is denoted by Ci (formerly Cr ). This computa-
tion takes as one of its inputs the immediate backdrop color, which is the result of
the color compositing computation for object i − 1; this is denoted by Ci − 1
(formerly Cb ).
The revised formulas for a simple n-element stack (not including any groups) are,
for i = 1, … , n:
fs
=
fj
×
fm
×
fk
i
i
i
i
qs
=
qj
×
qm
×
qk
i
i
i
i
αs
=
fs
×
qs
i
i
i
αi
=
Union(αi-1,
αs
)
i
fi
=
Union(fi-1,
fs
)
i
αi
qi
= -----
f
i
αs
αs
⎛
⎞
i
Ci
=
⎜1
- ------ ⎟
×
Ci-1
+
×[(
1
-
αi-1
)× Cs
+
αi-1
×
Bi (Ci-1
,
C
)]
si
⎝
α
⎠
αi
i
i
where the variables have the meanings shown in Table 7.6. Compare these
formulas with those shown in Section 7.2.7, “Summary of Basic Compositing
Computations.”
TABLE 7.6 Revised variables for the basic compositing formulas
VARIABLE
MEANING
fs
Source shape for object i
i
fj
Object shape for object i
i
fm
Mask shape for object i
i
533
SECTION 7.3
Transparency Groups
VARIABLE
MEANING
fk
Constant shape for object i
i
fi
Result shape after compositing object i
qs
Source opacity for object i
i
qj
Object opacity for object i
i
qm
Mask opacity for object i
i
qk
Constant opacity for object i
i
qi
Result opacity after compositing object i
αs
Source alpha for object i
i
αi
Result alpha after compositing object i
Cs
Source color for object i
i
Ci
Result color after compositing object i
Bi(Ci-1, Cs
)
Blend function for object i
i
7.3.2
Group Structure and Nomenclature
As stated earlier, the elements of a group are treated as a separate transparency
stack, the group stack. These objects are composited against a selected initial
backdrop (to be described) and the resulting color, shape, and opacity are then
treated as if they belonged to a single object. The resulting object is in turn com-
posited with the group’s backdrop in the usual way.
This computation entails interpreting the stack as a tree. For an n-element group
that begins at position i in the stack, it treats the next n objects as an n-element
substack, whose elements are given an independent numbering of 1 to n. These
objects are then removed from the object numbering in the parent (containing)
534
CHAPTER 7
Transparency
stack and replaced by the group object, numbered i, followed by the remaining
objects to be painted on top of the group, renumbered starting at i + 1. This oper-
ation applies recursively to any nested subgroups. Henceforth, the term element
(denoted Ei ) refers to a member of some group; it can be either an individual ob-
ject or a contained subgroup.
From the perspective of a particular element in a nested group, there are three
different backdrops of interest:
• The group backdrop is the result of compositing all elements up to but not in-
cluding the first element in the group. (This definition is altered if the parent
group is a knockout group; see Section 7.3.5, “Knockout Groups.”)
• The initial backdrop is a backdrop that is selected for compositing the group’s
first element. This is either the same as the group backdrop (for a non-isolated
group) or a fully transparent backdrop (for an isolated group).
• The immediate backdrop is the result of compositing all elements in the group
up to but not including the current element.
When all elements in a group have been composited, the result is treated as if the
group were a single object, which is then composited with the group backdrop.
(This operation occurs whether the initial backdrop chosen for compositing the
elements of the group was the group backdrop or a transparent backdrop. There
is a special correction to ensure that the backdrop’s contribution to the overall re-
sult is applied only once.)
7.3.3
Group Compositing Computations
The color and opacity of a group are defined by the group compositing function:
〈 C, f, α 〉
=
Composite(C0,α0,
G
)
where the variables have the meanings shown in Table 7.7.
TABLE 7.7 Arguments and results of the group compositing function
VARIABLE
MEANING
G
The transparency group: a compound object consisting of all ele-
ments E1, … , En of the group—the n constituent objects’ colors,
shapes, opacities, and blend modes
535
SECTION 7.3
Transparency Groups
VARIABLE
MEANING
C0
Color of the group’s backdrop
C
Computed color of the group, to be used as the source color when
the group is treated as an object
f
Computed shape of the group, to be used as the object shape when
the group is treated as an object
α0
Alpha of the group’s backdrop
α
Computed alpha of the group, to be used as the object alpha when
the group is treated as an object
Note that the opacity is not given explicitly as an argument or result of this func-
tion. Almost all of the computations use the product of shape and opacity (alpha)
rather than opacity alone; therefore, it is usually convenient to work directly with
shape and alpha rather than shape and opacity. When needed, the opacity can be
computed by dividing the alpha by the associated shape.
The result of applying the group compositing function is then treated as if it were
a single object, which in turn is composited with the group’s backdrop according
to the usual formulas. In those formulas, the color, shape, and alpha (C, f, and α)
calculated by the group compositing function are used, respectively, as the source
color Cs , the object shape fj , and the object alpha αj .
The group compositing formulas for a non-isolated, non-knockout group are de-
fined as follows:
• Initialization:
fg
=
α
= 0.0
g0
0
• For each group element Ei ∈ G (i = 1, … , n):
⎧
Composite(Ci-1,
αi-1,
Ei)
if Ei is a group
〈
〉
=
⎨
Csi, fji, αji
⎩
intrinsic color, shape, and (shape × opacity) of Ei
otherwise
Большое спасибо!
Ваше мнение очень важно для нас.

Нет комментариевНе стесняйтесь поделиться с нами вашим ценным мнением.
Текст