Skip to main content

[JAVA2D] Can't create Composite

1 reply [Last post]
Anonymous

I'm new to creating custom Composites and CompositeContexts, and
whenever I try to use it, the Java2D engine throws a 'Not Implimented
Yet' error.

First, I create my composite and send it to the Graphics2D:

Composite cachedComposite = null;
cachedComposite = g.getComposite();
g.setComposite(new AdobeComposite(AdobeComposite.CT_NORMAL,
1f));

My composite is created and the constructor on my Composite and
CompositeContext is called. However, before a call is made to
CompositeContext.compose(), the following error is thrown:

java.lang.InternalError: not implemented yet
at
sun.awt.windows.Win32OffScreenSurfaceData.getRaster(Win32OffScreenSurfaceData.java:338)
at
sun.java2d.pipe.GeneralCompositePipe.renderPathTile(GeneralCompositePipe.java:82)
at
sun.java2d.pipe.DuctusShapeRenderer.renderPath(DuctusShapeRenderer.java:102)
at
sun.java2d.pipe.DuctusShapeRenderer.fill(DuctusShapeRenderer.java:49)
at sun.java2d.pipe.ValidatePipe.fill(ValidatePipe.java:119)
at sun.java2d.SunGraphics2D.fill(SunGraphics2D.java:2157)
at com.kitfox.svg.ShapeElement.renderShape(ShapeElement.java:186)

What am I doing wrong? Should this be happening?

My classes are below.

Mark McKay
--
http://www.kitfox.com

/**
*
* @author kitfox
*/
public class AdobeComposite implements Composite
{
public static final int CT_NORMAL = 0;
public static final int CT_MULTIPLY = 1;
public static final int CT_LAST = 2;

final int compositeType;
final float extraAlpha;

/** Creates a new instance of AdobeComposite */
public AdobeComposite(int compositeType, float extraAlpha)
{
this.compositeType = compositeType;
this.extraAlpha = extraAlpha;

if (compositeType < 0 || compositeType >= CT_LAST)
{
new Exception("Invalid composite type").printStackTrace();
}

if (extraAlpha < 0f || extraAlpha > 1f)
{
new Exception("Invalid alpha").printStackTrace();
}
}

public int getCompositeType() { return compositeType; }

public CompositeContext createContext(ColorModel srcColorModel,
ColorModel dstColorModel, RenderingHints hints)
{
return new AdobeCompositeContext(compositeType, extraAlpha);
}

}

/**
*
* @author kitfox
*/
public class AdobeCompositeContext implements CompositeContext
{
final int compositeType;
final float extraAlpha;

float[] rgba_src = new float[4];
float[] rgba_dstIn = new float[4];
float[] rgba_dstOut = new float[4];

/** Creates a new instance of AdobeCompositeContext */
public AdobeCompositeContext(int compositeType, float extraAlpha)
{
this.compositeType = compositeType;
this.extraAlpha = extraAlpha;

rgba_dstOut[3] = 1f;
}

public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
{
int width = src.getWidth();
int height = src.getHeight();

for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
src.getPixel(i, j, rgba_src);
dstIn.getPixel(i, j, rgba_dstIn);

//Ignore transparent pixels
if (rgba_src[3] == 0)
{
// dstOut.setPixel(i, j, rgba_dstIn);
continue;
}

float alpha = rgba_src[3];

switch (compositeType)
{
default:
case AdobeComposite.CT_NORMAL:
rgba_dstOut[0] = rgba_src[0] * alpha +
rgba_dstIn[0] * (1f - alpha);
rgba_dstOut[1] = rgba_src[1] * alpha +
rgba_dstIn[1] * (1f - alpha);
rgba_dstOut[2] = rgba_src[2] * alpha +
rgba_dstIn[2] * (1f - alpha);
break;
case AdobeComposite.CT_MULTIPLY:
rgba_dstOut[0] = rgba_src[0] * rgba_dstIn[0] *
alpha + rgba_dstIn[0] * (1f - alpha);
rgba_dstOut[1] = rgba_src[1] * rgba_dstIn[1] *
alpha + rgba_dstIn[1] * (1f - alpha);
rgba_dstOut[2] = rgba_src[2] * rgba_dstIn[2] *
alpha + rgba_dstIn[2] * (1f - alpha);
break;
}
}
}
}

public void dispose() {
}

}

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sbaratham
Offline
Joined: 2006-02-17

Mark,

I was wondering if you figured out what the problem was. I am having a similar problem with one of our swing applications which works fine under jdk1.3.1, but exhibits the problem under jdk 1.4.2.

Thanks,
Sreeni.

sbaratham@170systems.com