Composition - Serabe/rinzelight GitHub Wiki
Composing two images is drawing the source image onto the destiny image.
The Porter-Duff rules define how the composition is made. There are 12 of them:
- clear.
- dst.
- dst-atop.
- dst-in
- dst-over
- src
- src-in
- src-out
- src-over
- xor
The Porter-Duff rules are functions in rinzelight. They can be used with no or one arguments. The argument is taken as a factor. Take a look at AlphaComposite javadoc for more info. The most important point about Porter-Duff rules being functions is that you must use them as (rule)
not simply as rule
. For example
(compose dst src (src-over)); Right!
(compose dst src src-over); Wrong!
The following examples shows the differences between the different methods.
clear
dst
dst-atop
dst-in
dst-out
dst-over
src
src-atop
src-in
src-out
src-over
xor
rinzelight.composition
contains two with-
macros. Both of them executes the code inside a doto
whose object is the Graphics2D for the given image. Furthermore, they reset the composite to the original one.
These are lowlevel macros, so you cannot use rinzelight function inside them.
This method sets the XOR mode to the color passed as second argument.
This method sets the active composite to the one given as second parameter.
Compose function is heavily overloaded. It can take from two to five arguments. Each case will be discussed.
dst
and src
are the images for the composition, comp
is the composite used for it (it may be one of the Porter-Duff rules or a custom Composite object). x
and y
are the coordinates of the pixel where the composition starts.
dst
and src
are the images for the composition, comp
is the composite used for it (it may be one of the Porter-Duff rules or a custom Composite object). grav
is the gravity used to get the coordinates of the pixel where the composition starts.
dst
and src
are the images for the composition. The third argument may be a composite or a gravity. The composite?
predicate is applied to the third argument and, if it is not a Composite, then (src-over)
is applied. If it is a composite, composition takes place starting on upper-left corner (pixel 0,0).
dst
and src
are the images for the composition. Default composite ((src-over)
) is supplied, and the starting pixel is 0,0.
Since working with different parameters has been widely covered, the example will show the different predefined gravities in action.
Center
North
North-east
East
South-east
South
South-west
West
North-west
You may be wondering why composites need to be executed and geometries can be passed as a function. Here is the reasoning behind it:
A composite is an object, i.e. an instance of a class implementing Composite, while a geometry is defined as a function. Porter-Deff rules are defined as functions instead of composites since they can be multiplied by a factor. It certainly be more logical to use a macro, but by now I don’t know how to write a macro inside a macro, but it is certainly the way to follow.