Hi,
I'm trying to code a bevel effect by hand using the Batik marvelous filters
in order to get the same result as in this SVG file:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="500" height="500">
<defs>
<filter id="Bevel">
<feGaussianBlur in="SourceAlpha" stdDeviation="4"
result="blur"/>
<feSpecularLighting in="blur" surfaceScale="5"
specularConstant="0.75"
specularExponent="10" result="specOut"
style="lighting-color:rgb(187,187,187)">
<fePointLight x="-5000" y="-10000" z="20000"/>
</feSpecularLighting>
<feComposite in="specOut" in2="SourceAlpha" operator="in"
result="specOut2"/>
<feComposite in="SourceGraphic" in2="specOut2"
operator="arithmetic" k1="0"
k2="1" k3="1" k4="0"/>
</filter>
</defs>
<rect x="0" y="0" width="100" height="100"
style="filter:url(#Bevel);fill:red;stroke:rgb(0,0,128);stroke-width:1"/>
</svg>
Here is the code I use to create the same filter. When I call the
"createBevelImage" method on a rectangle shape filled with red, all I got
is a blank image instead of a red rectangle with a bevel. If I comment out
the code that create the last filter (the arithmetic compositing), the
image I get (the "specOut" image) is made of grey colors instead of white.
I know that I make an unuasual use of Batik here, so I might be wrong
somewhere.
public static Image createBevelImage(Shape shape, Paint fillPaint,
Rectangle2D imageBounds)
{
Filter filter;
Image image;
ShapeNode shapeNode;
Rectangle2D litRegion;
Light light;
double specularExponent;
double surfaceScale;
double specularConstant;
double[] kernelUnitLength;
Rectangle2D specularBounds;
Filter sourceGraphic;
Filter sourceAlpha;
ArrayList compositeSources;
FillShapePainter fillPainter;
shapeNode = new ShapeNode();
shapeNode.setShape(shape);
fillPainter = new FillShapePainter(shapeNode.getShape());
fillPainter.setPaint(fillPaint);
shapeNode.setShapePainter(fillPainter);
sourceGraphic = new GraphicsNodeRable8Bit(shapeNode);
sourceAlpha = new FilterAlphaRable(sourceGraphic);
/* <feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"/> */
filter = new GaussianBlurRable8Bit(sourceAlpha, 4, 4);
/*
<feSpecularLighting in="blur" surfaceScale="5" specularConstant=".75"
specularExponent="20" lighting-color="#bbbbbb"
result="specOut">
<fePointLight x="-5000" y="-10000" z="20000"/>
</feSpecularLighting>
*/
light = new PointLight(-5000, -10000, 20000, new Color(187, 187, 187));
specularExponent = 10;
surfaceScale = 5;
specularConstant = 0.75;
kernelUnitLength = null;
litRegion = shape.getBounds2D();
filter = new SpecularLightingRable8Bit(filter, litRegion, light,
specularConstant, specularExponent, surfaceScale, kernelUnitLength);
/* <feComposite in="specOut" in2="SourceAlpha" operator="in"
result="specOut"/> */
compositeSources = new ArrayList();
compositeSources.add(filter);
compositeSources.add(sourceAlpha);
filter = new CompositeRable8Bit(compositeSources, CompositeRule.IN, true);
/* <feComposite in="SourceGraphic" in2="specOut" operator="arithmetic"
k1="0" k2="1" k3="1" k4="0"/> */
compositeSources = new ArrayList();
compositeSources.add(sourceGraphic);
compositeSources.add(filter);
filter = new CompositeRable8Bit(compositeSources,
CompositeRule.ARITHMETIC(0, 1, 1, 0), true);
image = createFilteredImage(filter, shapeNode, imageBounds);
return image;
}
public static BufferedImage createFilteredImage(Filter filter, ShapeNode
shapeNode, Rectangle2D imageBounds)
{
StaticRenderer renderer;
RootGraphicsNode rootNode;
BufferedImage image;
shapeNode.setFilter(filter);
rootNode = new RootGraphicsNode();
rootNode.add(shapeNode);
Rectangle2D.union(shapeNode.getBounds(), filter.getBounds2D(),
imageBounds);
// Render.
renderer = new StaticRenderer();
renderer.setTransform(AffineTransform.getTranslateInstance(-imageBounds.getX(),
-imageBounds.getY()));
try
{
renderer.setTree(rootNode);
renderer.updateOffScreen((int)(imageBounds.getWidth() -
imageBounds.getX()), (int)(imageBounds.getHeight() - imageBounds.getY()));
renderer.repaint(imageBounds);
}
catch(Exception e)
{
e.printStackTrace();
}
image = renderer.getOffScreen();
return image;
}
Any help appreciated,
Philippe
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]