You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by tk...@apache.org on 2001/04/24 17:32:22 UTC

cvs commit: xml-batik/sources/org/apache/batik/ext/awt/image/renderable DiffuseLightingRable8Bit.java SpecularLightingRable8Bit.java

tkormann    01/04/24 08:32:21

  Modified:    sources/org/apache/batik/bridge
                        SVGFeAbstractLightingElementBridge.java
                        SVGFeDiffuseLightingElementBridge.java
                        SVGFeSpecularLightingElementBridge.java
               sources/org/apache/batik/ext/awt/image/renderable
                        DiffuseLightingRable8Bit.java
                        SpecularLightingRable8Bit.java
  Log:
  add kernelUnitLength support for Specular and Diffuse lighting filter.
  
  Revision  Changes    Path
  1.3       +37 -1     xml-batik/sources/org/apache/batik/bridge/SVGFeAbstractLightingElementBridge.java
  
  Index: SVGFeAbstractLightingElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGFeAbstractLightingElementBridge.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SVGFeAbstractLightingElementBridge.java	2001/03/26 21:27:23	1.2
  +++ SVGFeAbstractLightingElementBridge.java	2001/04/24 15:32:07	1.3
  @@ -9,6 +9,7 @@
   package org.apache.batik.bridge;
   
   import java.awt.Color;
  +import java.util.StringTokenizer;
   
   import org.apache.batik.ext.awt.image.DistantLight;
   import org.apache.batik.ext.awt.image.Light;
  @@ -23,7 +24,7 @@
    * Bridge class for the <feDiffuseLighting> element.
    *
    * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
  - * @version $Id: SVGFeAbstractLightingElementBridge.java,v 1.2 2001/03/26 21:27:23 deweese Exp $
  + * @version $Id: SVGFeAbstractLightingElementBridge.java,v 1.3 2001/04/24 15:32:07 tkormann Exp $
    */
   public abstract class SVGFeAbstractLightingElementBridge
       extends SVGAbstractFilterPrimitiveElementBridge {
  @@ -63,6 +64,41 @@
                   (ctx, filterElement, e, color);
           }
           return null;
  +    }
  +
  +    /**
  +     * Convert the 'kernelUnitLength' attribute of the specified
  +     * feDiffuseLighting or feSpecularLighting filter primitive element.
  +     *
  +     * @param filterElement the filter primitive element
  +     */
  +    protected static double [] convertKernelUnitLength(Element filterElement) {
  +        String s = filterElement.getAttributeNS
  +            (null, SVG_KERNEL_UNIT_LENGTH_ATTRIBUTE);
  +        if (s.length() == 0) {
  +            return null;
  +        }
  +        double [] units = new double[2];
  +        StringTokenizer tokens = new StringTokenizer(s, " ,");
  +        try {
  +            units[0] = SVGUtilities.convertSVGNumber(tokens.nextToken());
  +            if (tokens.hasMoreTokens()) {
  +                units[1] = SVGUtilities.convertSVGNumber(tokens.nextToken());
  +            } else {
  +                units[1] = units[0];
  +            }
  +        } catch (NumberFormatException ex) {
  +            throw new BridgeException
  +                (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED,
  +                 new Object[] {SVG_KERNEL_UNIT_LENGTH_ATTRIBUTE, s});
  +
  +        }
  +        if (tokens.hasMoreTokens() || units[0] <= 0 || units[1] <= 0) {
  +            throw new BridgeException
  +                (filterElement, ERR_ATTRIBUTE_VALUE_MALFORMED,
  +                 new Object[] {SVG_KERNEL_UNIT_LENGTH_ATTRIBUTE, s});
  +        }
  +        return units;
       }
   
       /**
  
  
  
  1.9       +10 -3     xml-batik/sources/org/apache/batik/bridge/SVGFeDiffuseLightingElementBridge.java
  
  Index: SVGFeDiffuseLightingElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGFeDiffuseLightingElementBridge.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SVGFeDiffuseLightingElementBridge.java	2001/03/26 21:27:24	1.8
  +++ SVGFeDiffuseLightingElementBridge.java	2001/04/24 15:32:08	1.9
  @@ -22,7 +22,7 @@
    * Bridge class for the &lt;feDiffuseLighting> element.
    *
    * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
  - * @version $Id: SVGFeDiffuseLightingElementBridge.java,v 1.8 2001/03/26 21:27:24 deweese Exp $
  + * @version $Id: SVGFeDiffuseLightingElementBridge.java,v 1.9 2001/04/24 15:32:08 tkormann Exp $
    */
   public class SVGFeDiffuseLightingElementBridge
       extends SVGFeAbstractLightingElementBridge {
  @@ -73,6 +73,9 @@
           // extract the light definition from the filterElement's children list
           Light light = extractLight(filterElement, ctx);
   
  +        // 'kernelUnitLength' attribute
  +        double [] kernelUnitLength = convertKernelUnitLength(filterElement);
  +
           // 'in' attribute
           Filter in = getIn(filterElement,
                             filteredElement,
  @@ -102,8 +105,12 @@
                                                           defaultRegion,
                                                           filterRegion,
                                                           ctx);
  -        Filter filter = new DiffuseLightingRable8Bit
  -            (in, primitiveRegion, light, diffuseConstant, surfaceScale);
  +        Filter filter = new DiffuseLightingRable8Bit(in,
  +                                                     primitiveRegion,
  +                                                     light,
  +                                                     diffuseConstant,
  +                                                     surfaceScale,
  +                                                     kernelUnitLength);
   
           // update the filter Map
           updateFilterMap(filterElement, filter, filterMap);
  
  
  
  1.9       +7 -2      xml-batik/sources/org/apache/batik/bridge/SVGFeSpecularLightingElementBridge.java
  
  Index: SVGFeSpecularLightingElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGFeSpecularLightingElementBridge.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SVGFeSpecularLightingElementBridge.java	2001/03/26 21:27:25	1.8
  +++ SVGFeSpecularLightingElementBridge.java	2001/04/24 15:32:09	1.9
  @@ -23,7 +23,7 @@
    * Bridge class for the &lt;feSpecularLighting> element.
    *
    * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
  - * @version $Id: SVGFeSpecularLightingElementBridge.java,v 1.8 2001/03/26 21:27:25 deweese Exp $
  + * @version $Id: SVGFeSpecularLightingElementBridge.java,v 1.9 2001/04/24 15:32:09 tkormann Exp $
    */
   public class SVGFeSpecularLightingElementBridge
       extends SVGFeAbstractLightingElementBridge {
  @@ -75,6 +75,9 @@
           // extract the light definition from the filterElement's children list
           Light light = extractLight(filterElement, ctx);
   
  +        // 'kernelUnitLength' attribute
  +        double [] kernelUnitLength = convertKernelUnitLength(filterElement);
  +
           // 'in' attribute
           Filter in = getIn(filterElement,
                             filteredElement,
  @@ -110,7 +113,9 @@
                                                          light,
                                                          specularConstant,
                                                          specularExponent,
  -                                                       surfaceScale);
  +                                                       surfaceScale,
  +                                                       kernelUnitLength);
  +
   
           // update the filter Map
           updateFilterMap(filterElement, filter, filterMap);
  
  
  
  1.8       +23 -21    xml-batik/sources/org/apache/batik/ext/awt/image/renderable/DiffuseLightingRable8Bit.java
  
  Index: DiffuseLightingRable8Bit.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/renderable/DiffuseLightingRable8Bit.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DiffuseLightingRable8Bit.java	2001/03/28 19:18:00	1.7
  +++ DiffuseLightingRable8Bit.java	2001/04/24 15:32:15	1.8
  @@ -29,9 +29,9 @@
    * Implementation of the DiffuseLightRable interface.
    *
    * @author <a href="mailto:vincent.hardy@eng.sun.com>Vincent Hardy</a>
  - * @version $Id: DiffuseLightingRable8Bit.java,v 1.7 2001/03/28 19:18:00 deweese Exp $
  + * @version $Id: DiffuseLightingRable8Bit.java,v 1.8 2001/04/24 15:32:15 tkormann Exp $
    */
  -public class DiffuseLightingRable8Bit 
  +public class DiffuseLightingRable8Bit
       extends AbstractRable
       implements DiffuseLightingRable {
       /**
  @@ -57,18 +57,20 @@
       /**
        * The dx/dy to use in user space for the sobel gradient.
        */
  -    float [] kernelUnitLength = null;
  +    private float [] kernelUnitLength = null;
   
       public DiffuseLightingRable8Bit(Filter src,
  -                                        Rectangle2D litRegion,
  -                                        Light light,
  -                                        double kd,
  -                                        double surfaceScale){
  +                                    Rectangle2D litRegion,
  +                                    Light light,
  +                                    double kd,
  +                                    double surfaceScale,
  +                                    double [] kernelUnitLength) {
           super(src, null);
           setLight(light);
           setKd(kd);
           setSurfaceScale(surfaceScale);
           setLitRegion(litRegion);
  +        setKernelUnitLength(kernelUnitLength);
       }
   
       /**
  @@ -149,11 +151,11 @@
       }
   
       /**
  -     * Returns the min [dx,dy] distance in user space for evalutation of 
  +     * Returns the min [dx,dy] distance in user space for evalutation of
        * the sobel gradient.
        */
       public double [] getKernelUnitLength() {
  -        if (kernelUnitLength == null) 
  +        if (kernelUnitLength == null)
               return null;
   
           double [] ret = new double[2];
  @@ -163,7 +165,7 @@
       }
   
       /**
  -     * Sets the min [dx,dy] distance in user space for evaluation of the 
  +     * Sets the min [dx,dy] distance in user space for evaluation of the
        * sobel gradient. If set to zero or null then device space will be used.
        */
       public void setKernelUnitLength(double [] kernelUnitLength) {
  @@ -175,7 +177,7 @@
   
           if (this.kernelUnitLength == null)
               this.kernelUnitLength = new float[2];
  -            
  +
           this.kernelUnitLength[0] = (float)kernelUnitLength[0];
           this.kernelUnitLength[1] = (float)kernelUnitLength[1];
       }
  @@ -190,18 +192,18 @@
   
           AffineTransform at = rc.getTransform();
           Rectangle devRect = at.createTransformedShape(aoiR).getBounds();
  -        
  +
           if(devRect.width == 0 || devRect.height == 0){
               return null;
           }
   
           //
           // DiffuseLightingRed only operates on a scaled space.
  -        // The following extracts the scale portion of the 
  +        // The following extracts the scale portion of the
           // user to device transform
           //
           // The source is rendered with the scale-only transform
  -        // and the rendered result is used as a bumpMap for the 
  +        // and the rendered result is used as a bumpMap for the
           // DiffuseLightingRed filter.
           //
           double sx = at.getScaleX();
  @@ -228,21 +230,21 @@
               if ((kernelUnitLength[0] > 0) &&
                   (scaleX > 1/kernelUnitLength[0]))
                   scaleX = 1/kernelUnitLength[0];
  -        
  +
               if ((kernelUnitLength[1] > 0) &&
                   (scaleY > 1/kernelUnitLength[1]))
                   scaleY = 1/kernelUnitLength[1];
           }
  -        
  +
           AffineTransform scale =
               AffineTransform.getScaleInstance(scaleX, scaleY);
   
           devRect = scale.createTransformedShape(aoiR).getBounds();
   
           // Grow for surround needs of bump map.
  -        aoiR.setRect(aoiR.getX()     -(2/scaleX), 
  +        aoiR.setRect(aoiR.getX()     -(2/scaleX),
                        aoiR.getY()     -(2/scaleY),
  -                     aoiR.getWidth() +(4/scaleX), 
  +                     aoiR.getWidth() +(4/scaleX),
                        aoiR.getHeight()+(4/scaleY));
   
   
  @@ -266,17 +268,17 @@
               new AffineTransform(sx/scaleX, shy/scaleX,
                                   shx/scaleY, sy/scaleY,
                                   tx, ty);
  -        
  +
           if(!shearAt.isIdentity()) {
               RenderingHints rh = rc.getRenderingHints();
               Rectangle padRect = new Rectangle(devRect.x-1, devRect.y-1,
  -                                              devRect.width+2, 
  +                                              devRect.width+2,
                                                 devRect.height+2);
               cr = new PadRed(cr, padRect, PadMode.REPLICATE, rh);
   
               cr = new AffineRed(cr, shearAt, rh);
           }
  -       
  +
           return cr;
       }
   }
  
  
  
  1.8       +25 -23    xml-batik/sources/org/apache/batik/ext/awt/image/renderable/SpecularLightingRable8Bit.java
  
  Index: SpecularLightingRable8Bit.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/renderable/SpecularLightingRable8Bit.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SpecularLightingRable8Bit.java	2001/03/28 19:18:01	1.7
  +++ SpecularLightingRable8Bit.java	2001/04/24 15:32:17	1.8
  @@ -29,9 +29,9 @@
    * Implementation of the SpecularLightRable interface.
    *
    * @author <a href="mailto:vincent.hardy@eng.sun.com>Vincent Hardy</a>
  - * @version $Id: SpecularLightingRable8Bit.java,v 1.7 2001/03/28 19:18:01 deweese Exp $
  + * @version $Id: SpecularLightingRable8Bit.java,v 1.8 2001/04/24 15:32:17 tkormann Exp $
    */
  -public class SpecularLightingRable8Bit 
  +public class SpecularLightingRable8Bit
       extends AbstractRable
       implements SpecularLightingRable {
       /**
  @@ -62,20 +62,22 @@
       /**
        * The dx/dy to use in user space for the sobel gradient.
        */
  -    float [] kernelUnitLength = null;
  +    private float [] kernelUnitLength = null;
   
       public SpecularLightingRable8Bit(Filter src,
  -                                         Rectangle2D litRegion,
  -                                         Light light,
  -                                         double ks,
  -                                         double specularExponent,
  -                                         double surfaceScale){
  +                                     Rectangle2D litRegion,
  +                                     Light light,
  +                                     double ks,
  +                                     double specularExponent,
  +                                     double surfaceScale,
  +                                     double [] kernelUnitLength) {
           super(src, null);
           setLight(light);
           setKs(ks);
           setSpecularExponent(specularExponent);
           setSurfaceScale(surfaceScale);
           setLitRegion(litRegion);
  +        setKernelUnitLength(kernelUnitLength);
       }
   
       /**
  @@ -170,11 +172,11 @@
       }
   
       /**
  -     * Returns the min [dx,dy] distance in user space for evalutation of 
  +     * Returns the min [dx,dy] distance in user space for evalutation of
        * the sobel gradient.
        */
       public double [] getKernelUnitLength() {
  -        if (kernelUnitLength == null) 
  +        if (kernelUnitLength == null)
               return null;
   
           double [] ret = new double[2];
  @@ -184,7 +186,7 @@
       }
   
       /**
  -     * Sets the min [dx,dy] distance in user space for evaluation of the 
  +     * Sets the min [dx,dy] distance in user space for evaluation of the
        * sobel gradient. If set to zero or null then device space will be used.
        */
       public void setKernelUnitLength(double [] kernelUnitLength) {
  @@ -196,7 +198,7 @@
   
           if (this.kernelUnitLength == null)
               this.kernelUnitLength = new float[2];
  -            
  +
           this.kernelUnitLength[0] = (float)kernelUnitLength[0];
           this.kernelUnitLength[1] = (float)kernelUnitLength[1];
       }
  @@ -211,18 +213,18 @@
   
           AffineTransform at = rc.getTransform();
           Rectangle devRect = at.createTransformedShape(aoiR).getBounds();
  -        
  +
           if(devRect.width == 0 || devRect.height == 0){
               return null;
           }
   
           //
           // SpecularLightingRed only operates on a scaled space.
  -        // The following extracts the scale portion of the 
  +        // The following extracts the scale portion of the
           // user to device transform
           //
           // The source is rendered with the scale-only transform
  -        // and the rendered result is used as a bumpMap for the 
  +        // and the rendered result is used as a bumpMap for the
           // SpecularLightingRed filter.
           //
           double sx = at.getScaleX();
  @@ -246,22 +248,22 @@
           // These values represent the scale factor to the intermediate
           // coordinate system where we will apply our convolution.
           if (kernelUnitLength != null) {
  -            if (scaleX >= 1/kernelUnitLength[0]) 
  +            if (scaleX >= 1/kernelUnitLength[0])
                   scaleX = 1/kernelUnitLength[0];
  -        
  -            if (scaleY >= 1/kernelUnitLength[1]) 
  +
  +            if (scaleY >= 1/kernelUnitLength[1])
                   scaleY = 1/kernelUnitLength[1];
           }
  -        
  +
           AffineTransform scale =
               AffineTransform.getScaleInstance(scaleX, scaleY);
   
           devRect = scale.createTransformedShape(aoiR).getBounds();
   
           // Grow for surround needs.
  -        aoiR.setRect(aoiR.getX()     -(2/scaleX), 
  +        aoiR.setRect(aoiR.getX()     -(2/scaleX),
                        aoiR.getY()     -(2/scaleY),
  -                     aoiR.getWidth() +(4/scaleX), 
  +                     aoiR.getWidth() +(4/scaleX),
                        aoiR.getHeight()+(4/scaleY));
   
   
  @@ -289,13 +291,13 @@
           if(!shearAt.isIdentity()) {
               RenderingHints rh = rc.getRenderingHints();
               Rectangle padRect = new Rectangle(devRect.x-1, devRect.y-1,
  -                                              devRect.width+2, 
  +                                              devRect.width+2,
                                                 devRect.height+2);
               cr = new PadRed(cr, padRect, PadMode.REPLICATE, rh);
   
               cr = new AffineRed(cr, shearAt, rh);
           }
  -       
  +
           return cr;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org