Package org.openstreetmap.josm.gui.draw
Class BlendComposite
- java.lang.Object
-
- org.openstreetmap.josm.gui.draw.BlendComposite
-
- All Implemented Interfaces:
java.awt.Composite
public final class BlendComposite extends java.lang.Object implements java.awt.Composite
ACompositeimplementing the common "blend modes" of image editors (multiply, burn, hard light, difference, divide), which the standardAlphaCompositedoes 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
BufferedImagebacked graphics, since hardware accelerated pipelines do not support custom composites.- Since:
- 19640
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classBlendComposite.BlendContextstatic classBlendComposite.ModeThe supported blend modes.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<BlendComposite.Mode,BlendComposite>INSTANCESprivate BlendComposite.Modemode
-
Constructor Summary
Constructors Modifier Constructor Description privateBlendComposite(BlendComposite.Mode mode)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (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.java.awt.CompositeContextcreateContext(java.awt.image.ColorModel srcColorModel, java.awt.image.ColorModel dstColorModel, java.awt.RenderingHints hints)static BlendCompositegetInstance(BlendComposite.Mode mode)Returns the composite for the given mode.BlendComposite.ModegetMode()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 Detail
-
INSTANCES
private static final java.util.Map<BlendComposite.Mode,BlendComposite> INSTANCES
-
mode
private final BlendComposite.Mode mode
-
-
Constructor Detail
-
BlendComposite
private BlendComposite(BlendComposite.Mode mode)
-
-
Method Detail
-
getInstance
public static BlendComposite getInstance(BlendComposite.Mode mode)
Returns the composite for the given mode.- Parameters:
mode- the blend mode- Returns:
- the composite
-
getMode
public BlendComposite.Mode getMode()
Returns the blend mode of this composite.- Returns:
- the blend mode
-
createContext
public java.awt.CompositeContext createContext(java.awt.image.ColorModel srcColorModel, java.awt.image.ColorModel dstColorModel, java.awt.RenderingHints hints)
- Specified by:
createContextin interfacejava.awt.Composite
-
blend
static int blend(BlendComposite.Mode mode, int s, int d)
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
static int composePixel(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.- Parameters:
mode- blend modes- source color (ARGB, not premultiplied)d- destination color (ARGB, not premultiplied)- Returns:
- the resulting color (ARGB, not premultiplied)
-
composeChannel
private static int composeChannel(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.- 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
private static int mix(int s, int d, int alpha)
linear interpolation between d (alpha 0) and s (alpha 255)
-
-