下面列出了怎么用java.awt.CompositeContext的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public CompositeContext createContext(ColorModel srcColorModel,
ColorModel dstColorModel,
RenderingHints arg2) {
switch (mode) {
case MULTIPLY:
return new MultiplyContext();
// Modes with significant creation overhead (lookup tables). Cache those
case SOFT_LIGHT:
CompositeContext ctx = cache.get(Mode.SOFT_LIGHT);
if (ctx == null) {
ctx = new BlendContext(mode, color);
cache.put(Mode.SOFT_LIGHT, ctx);
}
return ctx;
default:
return new BlendContext(mode, color);
}
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
public TileContext(SunGraphics2D sg, PaintContext pCtx,
CompositeContext cCtx, ColorModel cModel) {
sunG2D = sg;
paintCtxt = pCtx;
compCtxt = cCtx;
compModel = cModel;
}
public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,
int[] abox) {
RenderingHints hints = sg.getRenderingHints();
ColorModel model = sg.getDeviceColorModel();
PaintContext paintContext =
sg.paint.createContext(model, devR, s.getBounds2D(),
sg.cloneTransform(),
hints);
CompositeContext compositeContext =
sg.composite.createContext(paintContext.getColorModel(), model,
hints);
return new TileContext(sg, paintContext, compositeContext, model);
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,
int[] abox) {
RenderingHints hints = sg.getRenderingHints();
ColorModel model = sg.getDeviceColorModel();
PaintContext paintContext =
sg.paint.createContext(model, devR, s.getBounds2D(),
sg.cloneTransform(),
hints);
CompositeContext compositeContext =
sg.composite.createContext(paintContext.getColorModel(), model,
hints);
return new TileContext(sg, paintContext, compositeContext, model);
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
public TileContext(SunGraphics2D sg, PaintContext pCtx,
CompositeContext cCtx, ColorModel cModel) {
sunG2D = sg;
paintCtxt = pCtx;
compCtxt = cCtx;
compModel = cModel;
}
public CompositeContext createContext( ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints )
{
final Composer c;
if ( srcColorModel.getNumColorComponents() > 1 )
{
if ( srcColorModel.hasAlpha() )
c = new ARGB2ARGB();
else
c = new RGB2ARGB();
}
else
c = new Gray2ARGB();
return new CompositeContext()
{
private Composer composer = c;
public void compose( Raster src, Raster dstIn, WritableRaster dstOut )
{
final int[] srcPixel = new int[ 4 ];
final int[] dstInPixel = new int[ 4 ];
for ( int x = 0; x < dstOut.getWidth(); x++ )
{
for ( int y = 0; y < dstOut.getHeight(); y++ )
{
src.getPixel( x, y, srcPixel );
dstIn.getPixel( x, y, dstInPixel );
composer.compose( srcPixel, dstInPixel, alpha );
dstOut.setPixel( x, y, dstInPixel );
}
}
}
public void dispose()
{}
};
}
public CompositeContext createContext( ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints )
{
final Composer c;
if ( srcColorModel.getNumColorComponents() > 1 )
{
if ( srcColorModel.hasAlpha() )
c = new ARGB2ARGB();
else
c = new RGB2ARGB();
}
else
c = new Gray2ARGB();
return new CompositeContext()
{
private Composer composer = c;
public void compose( Raster src, Raster dstIn, WritableRaster dstOut )
{
final int[] srcPixel = new int[ 4 ];
final int[] dstInPixel = new int[ 4 ];
for ( int x = 0; x < dstOut.getWidth(); x++ )
{
for ( int y = 0; y < dstOut.getHeight(); y++ )
{
src.getPixel( x, y, srcPixel );
dstIn.getPixel( x, y, dstInPixel );
composer.compose( srcPixel, dstInPixel, alpha );
dstOut.setPixel( x, y, dstInPixel );
}
}
}
public void dispose()
{}
};
}
public TileContext(SunGraphics2D sg, PaintContext pCtx,
CompositeContext cCtx, ColorModel cModel) {
sunG2D = sg;
paintCtxt = pCtx;
compCtxt = cCtx;
compModel = cModel;
}
public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,
int[] abox) {
RenderingHints hints = sg.getRenderingHints();
ColorModel model = sg.getDeviceColorModel();
PaintContext paintContext =
sg.paint.createContext(model, devR, s.getBounds2D(),
sg.cloneTransform(),
hints);
CompositeContext compositeContext =
sg.composite.createContext(paintContext.getColorModel(), model,
hints);
return new TileContext(sg, paintContext, compositeContext, model);
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
public TileContext(SunGraphics2D sg, PaintContext pCtx,
CompositeContext cCtx, ColorModel cModel) {
sunG2D = sg;
paintCtxt = pCtx;
compCtxt = cCtx;
compModel = cModel;
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int[] span = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
public TileContext(SunGraphics2D sg, PaintContext pCtx,
CompositeContext cCtx, ColorModel cModel) {
sunG2D = sg;
paintCtxt = pCtx;
compCtxt = cCtx;
compModel = cModel;
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
public TileContext(SunGraphics2D sg, PaintContext pCtx,
CompositeContext cCtx, ColorModel cModel) {
sunG2D = sg;
paintCtxt = pCtx;
compCtxt = cCtx;
compModel = cModel;
}
@Override
public CompositeContext createContext(ColorModel srcColorModel,
ColorModel dstColorModel,
RenderingHints hints)
{
return new CustomCompositeContext();
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,
int[] abox) {
RenderingHints hints = sg.getRenderingHints();
ColorModel model = sg.getDeviceColorModel();
PaintContext paintContext =
sg.paint.createContext(model, devR, s.getBounds2D(),
sg.cloneTransform(),
hints);
CompositeContext compositeContext =
sg.composite.createContext(paintContext.getColorModel(), model,
hints);
return new TileContext(sg, paintContext, compositeContext, model);
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
public TileContext(SunGraphics2D sg, PaintContext pCtx,
CompositeContext cCtx, ColorModel cModel) {
sunG2D = sg;
paintCtxt = pCtx;
compCtxt = cCtx;
compModel = cModel;
}
public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,
int[] abox) {
RenderingHints hints = sg.getRenderingHints();
ColorModel model = sg.getDeviceColorModel();
PaintContext paintContext =
sg.paint.createContext(model, devR, s.getBounds2D(),
sg.cloneTransform(),
hints);
CompositeContext compositeContext =
sg.composite.createContext(paintContext.getColorModel(), model,
hints);
return new TileContext(sg, paintContext, compositeContext, model);
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
public TileContext(SunGraphics2D sg, PaintContext pCtx,
CompositeContext cCtx, ColorModel cModel) {
sunG2D = sg;
paintCtxt = pCtx;
compCtxt = cCtx;
compModel = cModel;
}
public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,
int[] abox) {
RenderingHints hints = sg.getRenderingHints();
ColorModel model = sg.getDeviceColorModel();
PaintContext paintContext =
sg.paint.createContext(model, devR, s.getBounds2D(),
sg.cloneTransform(),
hints);
CompositeContext compositeContext =
sg.composite.createContext(paintContext.getColorModel(), model,
hints);
return new TileContext(sg, paintContext, compositeContext, model);
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,
int[] abox) {
RenderingHints hints = sg.getRenderingHints();
ColorModel model = sg.getDeviceColorModel();
PaintContext paintContext =
sg.paint.createContext(model, devR, s.getBounds2D(),
sg.cloneTransform(),
hints);
CompositeContext compositeContext =
sg.composite.createContext(paintContext.getColorModel(), model,
hints);
return new TileContext(sg, paintContext, compositeContext, model);
}
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}