Caution - The operators defined in this section are extensions to the Display PostScript language. They are not part of the standard DPS and thus are not available in all DPS implementations. An application that depends on these operators is not portable and cannot display on servers that do not support these operators.
Compositing is an OpenStep extension to the Display PostScript system. Compositing enables separately rendered images to be combined into a final image. It encompasses a wide range of imaging capabilities:
It provides a means for simply copying an image as is from one place to another with PostScript.
It allows two images to be added together so that both appear in the composite superimposed on each other.
It defines a number of operations that take advantage of transparency in one or both images that are combined. When the images are composited, the transparency of one image can let parts of the other image show through.
Compositing can be used for copying within the same window, as during scrolling, or for taking an image rendered in one drawable and transferring it to another. In OpenStep applications, images are often stored in pixmaps and composited into windows as they are needed.
When images are partially transparent, they can be composited so that the transparent sections of one image determine what the viewer sees of the other. Each compositing operation uses transparency in a different way. In a typical operation, one image provides a background or foreground for the other. When parts of an image are transparent, it can be composited over an opaque background, which will show though transparent “holes” in the image on top. In other operations, transparent sections of one image can be used to “erase” matching sections of the images it is composited with. In most operations, the composite is calculated from the transparency of both images.
Compositing with transparency can achieve a variety of interesting visual effects. A partially transparent, uniformly gray area can be used like a pale wash to darken the image it is composited with. Patches of partially transparent gray can add shadows to another image. Repeated compositing while slowly altering the transparency of two images can dissolve one into another. Or an animated figure can be composited over a fixed background.
Before images can be composited, they must be rendered. To take advantage of transparency when compositing, at least one of the images needs to be rendered with transparent paint.
The following PostScript program fragment shows the use of the compositing operators. The program creates two simple images and composites them. The first image, the destination, is a 0.8 gray triangle on a white background; the second, the source, is a 0.6 gray triangle on a transparent background.
% Create the Destination triangle % Make the background of the source transparent 0 0.8 setgray 100 100 moveto 100 0 rlineto 0 -100 rlineto fill setalpha 0 0 100 100 rectfill % Draw the Source triangle 1 setalpha 0.6 setgray 0 0 moveto 0 100 rlineto 100 0 rlineto fill % Compute the result 0 0 100 100 null 100 0 Sover composite
The eighth operand to the composite operator, Sover, defines how the source and destination pixels are combined. In the example, the opaque parts of the source image are placed over the destination image. The resulting image looks like the following figure.
This section describes the new DPS operators. The information is provided in the format used in the PostScript manuals PostScript Language Reference Manual and Programming the Display PostScript System with X.
setalpha coverage setalpha
Sets the coverage parameter in the current graphics state to coverage. coverage should be a number between 0 and 1, with 0 corresponding to transparent, 1 corresponding to opaque, and intermediate values corresponding to partial coverage. The default value is 1. This establishes how much background shows through for purposes of compositing. If the coverage value is less than 0, the coverage parameter is set to 0. If the value is greater than 1, the coverage parameter is set to 1.
The coverage value affects the color painted by PostScript marking operations. The current color is pre-multiplied by the alpha value before rendering. This multiplication occurs after the current color has been transformed to RGB space.
Errors stackunderflow, typecheck
See also composite, currentalpha
currentalpha -currentalpha coverage
Returns the coverage parameter of the current graphics state.
See also composite, setalpha
composite srcx srcy width height srcgstate destx desty op composite
Performs the compositing operation specified by op between pairs of pixels in two images, a source and a destination. The source pixels are in the drawable referred to by the srcgstate graphics state, and the destination pixels are in the drawable specified by the current graphics state. If srcgstate is NULL, the current graphics state is assumed.
The rectangle specified by srcx, srcy, width, and height defines the source image. The outline of the rectangle may cross pixel boundaries due to fractional coordinates, scaling, or rotated axes. The pixels included in the source are all those that the outline of the rectangle encloses or enters.
The destination image has the same size, shape, and orientation as the source; destx and desty give destination's location image compared to the source. Even if the two graphic states have different orientations, the images will not; composite will not rotate images.
Both images are clipped to the frame rectangles of the respective drawables. The destination image is further clipped to the clipping path of the current graphics state. The result of a composite operation replaces the destination image.
op specifies the compositing operation. The color of each destination image pixel (alpha value) after the operation, dst' (dstA'), is given by:
dst' = src * Fs(srcA, dstA, op) + dst * Fd(srcA, dstA, op)
dstA' = srcA * Fs(srcA, dstA, op) + dstA * Fs(srcA, dstA, op)
where src and srcA are the source color and alpha values, dst and dstA are the destination color and alpha values, and Fs and Fd are the functions given in Table 2-2.
Errors rangecheck, stackunderflow, typecheck
See also compositerect, setalpha, setgray, sethsbcolor, setrgbcolor
Table 2-2 Factors of the Compositing Equation
The following figure shows the result of the compositing operations.
compositerect destx desty width height op compositerect -
In general, this operator is the same as the composite operator except that there is no real source image. The destination is in the current graphics state; destx, desty, width, and height describe the destination image in that graphics state's current coordinate system. The effect on the destination is as if there were a source image filled with the color and coverage specified by the graphics state's current color and coverage parameters. op has the same meaning as the op operand of the composite operator; however, one additional operation, Highlight, is allowed.
Highlight turns every white pixel in the destination rectangle to light gray and every light gray pixel to white, regardless of the pixel's coverage value. Light gray is defined as 2/3. Repeating the same operation reverses the effect. (On monochrome displays, Highlight inverts each pixel so that white becomes black, black becomes white.)
Note - The Highlight operation doesn't change the value of a pixel's coverage component. To ensure that the pixel's color and coverage combination remains valid, Highlight operations should be temporary and should be reversed before any further compositing.
For compositerect, the pixels included in the destination are those that the outline of the specified rectangle encloses or enters. The destination image is clipped to the frame rectangle and clipping path of the window in the current graphics state.
Errors rangecheck, stackunderflow, typecheck
See also composite, setalpha, setgray, sethsbcolor, setrbgcolor
dissolve srcx srcy width height srcgstate destx desty delta dissolve -
The effect of this operation is a blending of a source and a destination image. The first seven arguments choose source and destination pixels as they do for composite. The exact fraction of the blend is specified by delta, which is a floating-point number between 0.0 and 1.0. The resulting image is:
delta * source + (1-delta) * destination
If srcgstate is null, the current graphics state is assumed.
Errors stackunderflow, typecheck
See also composite
The values of the composite op are available for applications in the PostScript systemdict. The definitions are as follows:
/Clear 0 def
/Copy 1 def
/Sover 2 def
/Sin 3 def
/Sout 4 def
/Satop 5 def
/Dover 6 def
/Din 7 def
/Dout 8 def
/Datop 9 def
/Xor 10 def
/PlusD 11 def
/Highlight 12 def
/PlusL 13 def
Alpha values that are not completely opaque (1) or completely transparent (0) should be used with caution. Compositing operations with partial transparency yield the highest image quality only when a large number of colors are available in the DPS color cube and gray ramp. That is, image quality is best with a 24-bit TrueColor or 8-bit StaticGray visual, and image quality will be poor with an 8-bit PseudoColor visual. In addition, the performance of compositing operations is greatly reduced for partially transparent pixels due to the extra computation required in these cases.
For best results with the Highlight op, the number of colors in the DPS context's gray ramp should be such that
fract(((float) numgrays - 1)* 2. / 3.) == 0
In other words, (numgrays = 4, 7, 6, 8, 16, ....). This ensures that the color 2/3 gray is not halftoned.
Given the limited number of colors usually available in the DPS color cube and gray ramp, images with alpha values that are not completely opaque (1) or completely transparent (0) should be avoided to obtain best image quality.
Compositing operations are only defined for pixels values that are in the gray ramp or color cube specified by the gstate. Compositing pixels with values outside the color cube and gray ramp may not yield expected results.
The results of compositing operations for 1-bit drawables that have alpha values that are not equal to 0 or 1 is undefined.
The op Highlight inverts the color of the pixel on a 1-bit drawable.
Drawables that have been rendered to with non-opaque alpha have additional pixel storage associated with them, called the alpha channel. X Window system operations do not affect the alpha channel, with the following exceptions:
When windows with alpha channel are exposed, if the window has an X background defined (background != None), when the background is painted, the alpha component of the exposed pixels is painted with alpha = 1.
When a window is resized, the alpha channel storage is resized.
The erasepage operator paints the current drawable of the graphics state with opaque white. Thus, the alpha values for all pixels in the drawable are equal to 1, and the alpha channel storage is destroyed.
Compositing drawables with unequal depths is undefined.