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 de...@apache.org on 2001/07/23 21:36:30 UTC

cvs commit: xml-batik/sources/org/apache/batik/gvt PatternPaintContext.java

deweese     01/07/23 12:36:30

  Modified:    sources/org/apache/batik/bridge URIResolver.java
               sources/org/apache/batik/ext/awt/image/renderable
                        TileRable.java TileRable8Bit.java
               sources/org/apache/batik/ext/awt/image/rendered TileRed.java
               sources/org/apache/batik/gvt PatternPaintContext.java
  Log:
  1) Fixed PR 2667 a NPE for URIResolver when building from memory DOM.
  2) _Greatly_ increased the speed of small patterns (the smaller the
     pattern block in device space the bigger the difference).
  PR: 2667
  
  Revision  Changes    Path
  1.8       +14 -14    xml-batik/sources/org/apache/batik/bridge/URIResolver.java
  
  Index: URIResolver.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/URIResolver.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- URIResolver.java	2001/07/18 22:04:53	1.7
  +++ URIResolver.java	2001/07/23 19:36:29	1.8
  @@ -27,7 +27,7 @@
    * This class is used to resolve the URI that can be found in a SVG document.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: URIResolver.java,v 1.7 2001/07/18 22:04:53 deweese Exp $
  + * @version $Id: URIResolver.java,v 1.8 2001/07/23 19:36:29 deweese Exp $
    */
   public class URIResolver {
       /**
  @@ -85,22 +85,22 @@
           if (documentURI == null)
               documentURI = document.getURL();
   
  -        if (documentURI.equals(uri)) {
  -            return document;
  -        }
  -        if (uri.startsWith(documentURI) &&
  -            uri.length() > documentURI.length() + 1 &&
  -            uri.charAt(documentURI.length()) == '#') {
  -            uri = uri.substring(documentURI.length());
  -        }
  -
  -        if (uri.startsWith("#")) {
  -            return document.getElementById(uri.substring(1));
  +        ParsedURL purl = new ParsedURL(documentURI, uri);
  +        String    ref  = purl.getRef();
  +        if ((ref != null) && (documentURI != null)) {
  +            ParsedURL pDocURL = new ParsedURL(documentURI);
  +            // Check if the rest of the URL matches...
  +            // if so then return the referenced element.
  +            if ((pDocURL.getPath() == purl.getPath()) &&
  +                (pDocURL.getPort() == purl.getPort()) &&
  +                (pDocURL.getHost() == purl.getHost()) &&
  +                (pDocURL.getProtocol() == purl.getProtocol()))
  +                return document.getElementById(ref);
           }
   
  -        ParsedURL purl = new ParsedURL(documentURI, uri);
  +        // uri is not a reference into this document, so load the 
  +        // document it does reference.
           Document doc = documentLoader.loadDocument(purl.toString());
  -        String ref = purl.getRef();
           if (ref != null)
               return doc.getElementById(ref);
           return doc;
  
  
  
  1.2       +2 -2      xml-batik/sources/org/apache/batik/ext/awt/image/renderable/TileRable.java
  
  Index: TileRable.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/renderable/TileRable.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TileRable.java	2001/01/24 05:39:34	1.1
  +++ TileRable.java	2001/07/23 19:36:29	1.2
  @@ -14,9 +14,9 @@
    * A renderable that can tile its source into the tile region.
    * 
    * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
  - * @version $Id: TileRable.java,v 1.1 2001/01/24 05:39:34 vhardy Exp $
  + * @version $Id: TileRable.java,v 1.2 2001/07/23 19:36:29 deweese Exp $
    */
  -public interface TileRable extends Filter {
  +public interface TileRable extends FilterColorInterpolation {
       /**
        * Returns the tile region
        */
  
  
  
  1.4       +6 -4      xml-batik/sources/org/apache/batik/ext/awt/image/renderable/TileRable8Bit.java
  
  Index: TileRable8Bit.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/renderable/TileRable8Bit.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TileRable8Bit.java	2001/04/24 21:34:47	1.3
  +++ TileRable8Bit.java	2001/07/23 19:36:29	1.4
  @@ -31,9 +31,11 @@
    * 8 bit TileRable implementation
    *
    * @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
  - * @version $Id: TileRable8Bit.java,v 1.3 2001/04/24 21:34:47 deweese Exp $
  + * @version $Id: TileRable8Bit.java,v 1.4 2001/07/23 19:36:29 deweese Exp $
    */
  -public class TileRable8Bit extends AbstractRable implements TileRable{
  +public class TileRable8Bit 
  +    extends    AbstractColorInterpolationRable 
  +    implements TileRable{
       /**
        * Tile region
        */
  @@ -235,7 +237,7 @@
           RenderContext tileRc  = new RenderContext(tileAt, srcRect, rh);
           // RenderedImage tileRed = new DemandRed(source, tileRc);
           RenderedImage tileRed = source.createRendering(tileRc);
  -
  +        
           // System.out.println("TileRed: " + 
           //                    GraphicsUtil.wrap(tileRed).getBounds());
   
  @@ -269,7 +271,7 @@
                                         Integer.MAX_VALUE/2);
           }
           // System.out.println("tiledArea: " + tiledArea);
  -
  +        tileRed = convertSourceCS(tileRed);
           TileRed tiledRed = new TileRed(tileRed, tiledArea, dw, dh);
   
           // org.apache.batik.test.gvt.ImageDisplay.showImage("Tile", tiledRed);
  
  
  
  1.7       +57 -3     xml-batik/sources/org/apache/batik/ext/awt/image/rendered/TileRed.java
  
  Index: TileRed.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/rendered/TileRed.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TileRed.java	2001/05/02 14:56:27	1.6
  +++ TileRed.java	2001/07/23 19:36:29	1.7
  @@ -37,7 +37,7 @@
    * left corner of the tiled region.
    * 
    * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
  - * @version $Id: TileRed.java,v 1.6 2001/05/02 14:56:27 deweese Exp $
  + * @version $Id: TileRed.java,v 1.7 2001/07/23 19:36:29 deweese Exp $
    */
   public class TileRed extends AbstractRed implements TileGenerator {
       static final AffineTransform IDENTITY = new AffineTransform();
  @@ -133,8 +133,62 @@
                tile.getMinX(), tile.getMinY(), null);
   
           if (raster != null) {
  -            fillRasterFrom(raster, tile);
  -            this.tile = null;  // don't need it (It's in the raster).
  +            int minX   = raster.getMinX();
  +            int minY   = raster.getMinY();
  +            int width  = raster.getWidth();
  +            int height = raster.getHeight();
  +
  +            // This is a fairly expensive operation so do it once
  +            // upfront.  If we wanted this to go even faster we could
  +            // bypass copyData alltogeather and do the copy loops
  +            // directly.
  +            boolean int_pack = GraphicsUtil.is_INT_PACK_Data(sm, false);
  +
  +            WritableRaster fromRaster = raster.createWritableChild
  +                (minX, minY, xStep, yStep, minX, minY, null);
  +
  +            // Fill one 'tile' of the input....
  +            fillRasterFrom(fromRaster, tile);
  +            this.tile = null;  // don't need it anymore (It's in the raster).
  +            
  +            // Now replicate that out to the rest of the 
  +            // raster.  We keep growing the size of the
  +            // chunk we replicate by 2x.
  +
  +            // Start replicating across the first row...
  +            int step=xStep;
  +            for (int x=xStep; x<width; x+=step, step*=2) {
  +                int w = step;
  +                if (x+w > width) w = width-x;
  +                WritableRaster toRaster = raster.createWritableChild
  +                    (minX+x, minY, w, yStep, minX, minY, null);
  +
  +                if (int_pack)
  +                    GraphicsUtil.copyData_INT_PACK(fromRaster, toRaster);
  +                else
  +                    GraphicsUtil.copyData_FALLBACK(fromRaster, toRaster);
  +
  +                fromRaster = raster.createWritableChild
  +                    (minX, minY, x+w, yStep, minX, minY, null);
  +            }
  +
  +            // Next replicate that row down to the bottom of the raster...
  +            step = yStep;
  +            for (int y=yStep; y<height; y+=step, step*=2) {
  +                int h = step;
  +                if (y+h > height) h = height-y;
  +                WritableRaster toRaster = raster.createWritableChild
  +                    (minX, minY+y, width, h, minX, minY, null);
  +
  +                if (int_pack)
  +                    GraphicsUtil.copyData_INT_PACK(fromRaster, toRaster);
  +                else
  +                    GraphicsUtil.copyData_FALLBACK(fromRaster, toRaster);
  +
  +
  +                fromRaster = raster.createWritableChild
  +                    (minX, minY, width, y+h, minX, minY, null);
  +            }
           }
           else {
               this.tile        = tile;
  
  
  
  1.6       +22 -39    xml-batik/sources/org/apache/batik/gvt/PatternPaintContext.java
  
  Index: PatternPaintContext.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/PatternPaintContext.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PatternPaintContext.java	2001/05/02 14:56:32	1.5
  +++ PatternPaintContext.java	2001/07/23 19:36:30	1.6
  @@ -29,6 +29,7 @@
   
   import org.apache.batik.ext.awt.image.GraphicsUtil;
   import org.apache.batik.ext.awt.image.renderable.Filter;
  +import org.apache.batik.ext.awt.image.renderable.TileRable;
   import org.apache.batik.ext.awt.image.renderable.TileRable8Bit;
   import org.apache.batik.ext.awt.image.rendered.TileCacheRed;
   
  @@ -37,7 +38,7 @@
    * paint implementation.
    *
    * @author <a href="vincent.hardy@eng.sun.com">Vincent Hardy</a>
  - * @version $Id: PatternPaintContext.java,v 1.5 2001/05/02 14:56:32 deweese Exp $
  + * @version $Id: PatternPaintContext.java,v 1.6 2001/07/23 19:36:30 deweese Exp $
    */
   public class PatternPaintContext implements PaintContext {
   
  @@ -93,59 +94,41 @@
           // System.out.println("PatB: " + patternRegion);
           // System.out.println("Tile: " + tile);
   
  -        Filter tileRable = new TileRable8Bit(tile,
  -                                             EVERYTHING,
  -                                             patternRegion,
  -                                             overflow);
  +        TileRable tileRable = new TileRable8Bit(tile,
  +                                                EVERYTHING,
  +                                                patternRegion,
  +                                                overflow);
  +
  +        ColorSpace destCS = destCM.getColorSpace();
  +        if (destCS == ColorSpace.getInstance(ColorSpace.CS_sRGB))
  +            tileRable.setColorSpaceLinear(false);
  +        else if (destCS == ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB))
  +            tileRable.setColorSpaceLinear(true);
   
           RenderContext rc = new RenderContext(usr2dev,  EVERYTHING, hints);
  -
           tiled = tileRable.createRendering(rc);
   
           // System.out.println("tileRed: " + tiled);
           // org.apache.batik.test.gvt.ImageDisplay.showImage("Tiled: ", tiled);
   
           //System.out.println("Created rendering");
  -        if(tiled != null) {
  -            rasterCM = tiled.getColorModel();
  -            ColorSpace destCS = destCM.getColorSpace();
  -
  -            if (destCS != rasterCM.getColorSpace()) {
  -                if (destCS == ColorSpace.getInstance(ColorSpace.CS_sRGB))
  -                    tiled = GraphicsUtil.convertTosRGB
  -                        (GraphicsUtil.wrap(tiled));
  -                else if (destCS == 
  -                         ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB))
  -                    tiled = GraphicsUtil.convertToLsRGB
  -                        (GraphicsUtil.wrap(tiled));
  -            }
  -
  -            rasterCM = tiled.getColorModel();
  -            if (rasterCM.hasAlpha()) {
  -                if (destCM.hasAlpha()) {
  -                    if (rasterCM.isAlphaPremultiplied() !=
  -                        destCM  .isAlphaPremultiplied())
  -                        rasterCM = GraphicsUtil.coerceColorModel
  -                            (rasterCM, destCM.isAlphaPremultiplied());
  -                } else {
  -                    rasterCM = GraphicsUtil.coerceColorModel(rasterCM, false);
  -                }
  -            }
  -        }
  -        else {
  +        if(tiled == null) {
               //System.out.println("Tile was null");
               rasterCM = ColorModel.getRGBdefault();
               WritableRaster wr;
               wr = rasterCM.createCompatibleWritableRaster(32, 32);
               tiled = new BufferedImage(rasterCM, wr, false, null);
  +            return;
           }
   
  -
  -        // System.out.println("DestCM  : " + destCM);
  -        // System.out.println("RasterCM: " + rasterCM);
  -        // Exception e = new Exception("Pattern");
  -        // e.printStackTrace();
  -        
  +        rasterCM = tiled.getColorModel();
  +        if (rasterCM.hasAlpha()) {
  +            if (destCM.hasAlpha()) 
  +                rasterCM = GraphicsUtil.coerceColorModel
  +                    (rasterCM, destCM.isAlphaPremultiplied());
  +            else 
  +                rasterCM = GraphicsUtil.coerceColorModel(rasterCM, false);
  +        }
       }
   
       public void dispose(){
  
  
  

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