Package org.openstreetmap.josm.gui.draw
Class BlendComposite
java.lang.Object
org.openstreetmap.josm.gui.draw.BlendComposite
- All Implemented Interfaces:
Composite
A
Composite implementing the common "blend modes" of image editors (multiply, burn, hard light,
difference, divide), which the standard AlphaComposite does not provide.
The source alpha (including the coverage produced by antialiasing) controls how strongly the blended color
replaces the destination, following the "source over" rule of the W3C compositing model, so that a
translucent destination is handled correctly as well. It works on any color model, but is implemented per
pixel and thus only meant for drawing thin shapes such as grid lines. It must be used on
BufferedImage backed graphics, since hardware accelerated pipelines do not support
custom composites.
- Since:
- 19640
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classstatic enumThe supported blend modes. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map<BlendComposite.Mode,BlendComposite> private final BlendComposite.Mode -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static intblend(BlendComposite.Mode mode, int s, int d) Blends one color channel.private static intcomposeChannel(BlendComposite.Mode mode, int cs, int cb, int sa, int da, int a) Composes one color channel of a translucent destination, see the W3C compositing model:co = as*(1-ab)*Cs + as*ab*B(Cb,Cs) + (1-as)*ab*CbandCo = co/ao.(package private) static intcomposePixel(BlendComposite.Mode mode, int s, int d) Composes one pixel: blends the source color with the destination and combines the two with the "source over" rule, so that both the source alpha (including the coverage produced by antialiasing) and a translucent destination are handled correctly.createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) static BlendCompositeReturns the composite for the given mode.getMode()Returns the blend mode of this composite.private static intmix(int s, int d, int alpha) linear interpolation between d (alpha 0) and s (alpha 255)
-
Field Details
-
INSTANCES
-
mode
-
-
Constructor Details
-
BlendComposite
-
-
Method Details
-
getInstance
Returns the composite for the given mode.- Parameters:
mode- the blend mode- Returns:
- the composite
-
getMode
Returns the blend mode of this composite.- Returns:
- the blend mode
-
createContext
public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) - Specified by:
createContextin interfaceComposite
-
blend
Blends one color channel.- Parameters:
mode- blend modes- source channel value (0-255)d- destination channel value (0-255)- Returns:
- blended value (0-255)
-
composePixel
Composes one pixel: blends the source color with the destination and combines the two with the "source over" rule, so that both the source alpha (including the coverage produced by antialiasing) and a translucent destination are handled correctly.- Parameters:
mode- blend modes- source color (ARGB, not premultiplied)d- destination color (ARGB, not premultiplied)- Returns:
- the resulting color (ARGB, not premultiplied)
-
composeChannel
Composes one color channel of a translucent destination, see the W3C compositing model:co = as*(1-ab)*Cs + as*ab*B(Cb,Cs) + (1-as)*ab*CbandCo = co/ao.- Parameters:
mode- blend modecs- source channel value (0-255)cb- destination (backdrop) channel value (0-255)sa- source alpha (0-255)da- destination alpha (0-255)a- the resulting alpha (0-255), must not be 0- Returns:
- the resulting channel value (0-255)
-
mix
linear interpolation between d (alpha 0) and s (alpha 255)
-