14.1 The Compositing Protocol

Compositing creates a design whose appearance at each point is a composite of the appearances of two other designs at that point. Three varieties of compositing are provided: composing over, composing in, and composing out. [annotate]

[composing over, Concept← A Glossary]
[composing in, Concept← A Glossary]
[composing out, Concept← A Glossary]

The methods for compose-over, compose-in, and compose-out will typically specialize both of the design arguments. [annotate]

In Release 2, compositing might only be supported for uniform designs. [annotate]

compose-over  design1 design2 [Generic Function]
          

Composes a new design that is equivalent to the design design1 on top of the design design2. Drawing the resulting design produces the same visual appearance as drawing design2 and then drawing design1, but might be faster and might not allow the intermediate state to be visible on the screen. [annotate]

If both arguments are regions, compose-over is the same as region-union. [annotate]

Note:

This contradicts the earlier description of what compose-over should do.

Consider: (draw-design s (compose-over (make-line* 0 0 100 100) (make-rectangle* 40 40 60 60))). Is there really only the rectangle drawn? (The region-union is just the rectangle, because of the dimensionality rule).

[edit]-- Gilbert Baumann 2013-12-29 23:16Z
 

This function is permitted to capture its mutable inputs; the consequences of modifying those objects are unspecified. The result returned by compose-over might be freshly constructed or might be an existing object. [annotate]

[annotate]

compose-in  ink mask [Generic Function]
          

Composes a new design by clipping the design ink to the inside of the design mask. The first design, ink, supplies the color, while the second design, mask, changes the shape of the design by adjusting the opacity. [annotate]

More precisely, at each point in the drawing plane the resulting design specifies a color and an opacity as follows: the color is the same color that ink specifies. The opacity is the opacity that ink specifies, multiplied by the stencil opacity of mask. [annotate]

The stencil opacity of a design at a point is defined as the opacity that would result from drawing the design onto a fictitious medium whose drawing plane is initially completely transparent black (opacity and all color components are zero), and whose foreground and background are both opaque black. With this definition, the stencil opacity of a member of class opacity is simply its value. [annotate]

[stencil opacity, Concept← A Glossary]

If mask is a solid design, the effect of compose-in is to clip ink to mask. If mask is translucent, the effect is a soft matte. [annotate]

If both arguments are regions, compose-in is the same as region-intersection. [annotate]

Note:

Again, this contradicts the eariler description about what compose-in should do. Consider

(draw-design s (compose-in (make-line* 0 0 100 100) (make-rectangle 40 40 60 60)) :line-thickness 10)

The effect under the assumption, that compose-in is the same as region-intersection is, that the line is clipped to (40 40 60 60) and then drawn 10 pixels wide, at the end points it would spill over the region defined by the rectangle. So the figure drawn is not the same as clipping the 10 pixels wide line to said rectangle.

[edit]-- Gilbert Baumann 2013-12-29 23:24Z
 

This function is permitted to capture its mutable inputs; the consequences of modifying those objects are unspecified. The result returned by compose-in might be freshly constructed or might be an existing object. [annotate]

[annotate]

compose-out  ink mask [Generic Function]
          

Composes a new design by clipping the design ink to the outside of the design mask. The first design, ink, supplies the color, while the second design, mask, changes the shape of the design by adjusting the opacity. [annotate]

More precisely, at each point in the drawing plane the resulting design specifies a color and an opacity as follows: the color is the same color that ink specifies. The opacity is the opacity that ink specifies, multiplied by 1 minus the stencil opacity of mask. [annotate]

If mask is a solid design, the effect of compose-out is to clip ink to the complement of mask. If mask is translucent, the effect is a soft matte. [annotate]

If both arguments are regions, compose-out is the same as region-difference of mask and ink. [annotate]

Note: Yet again, this is a contradiction. Please see compose-in. [edit]-- Gilbert Baumann 2013-12-29 23:26Z
 

This function is permitted to capture its mutable inputs; the consequences of modifying those objects are unspecified. The result returned by compose-out might be freshly constructed or might be an existing object. [annotate]

[annotate]