incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cframp...@apache.org
Subject svn commit: r1402274 [29/31] - in /incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext: ./ awt/ awt/color/ awt/font/ awt/g2d/ awt/geom/ awt/image/ awt/image/codec/ awt/image/codec/jpeg/ awt/image/codec/p...
Date Thu, 25 Oct 2012 19:01:49 GMT
Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/PadRed.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/PadRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/PadRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/PadRed.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,509 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.image.DataBufferInt;
+import java.awt.image.SampleModel;
+import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.WritableRaster;
+
+import org.apache.flex.forks.batik.ext.awt.image.GraphicsUtil;
+import org.apache.flex.forks.batik.ext.awt.image.PadMode;
+
+
+/**
+ * This is an implementation of a Pad operation as a RenderedImage.
+ *
+ * @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
+ * @version $Id: PadRed.java 478276 2006-11-22 18:33:37Z dvholten $ */
+public class PadRed extends AbstractRed {
+
+    static final boolean DEBUG=false;
+
+    PadMode padMode;
+    RenderingHints hints;
+
+    /**
+     * Construct A Rendered Pad operation.  If the pad is smaller than
+     * the original image size then this devolves to a Crop.
+     *
+     * @param src     The image to pad/crop
+     * @param bounds  The bounds of the result (same coord system as src).
+     * @param padMode The pad mode to use (currently ignored).
+     * @param hints The hints to use for drawing 'pad' area.
+     */
+    public PadRed(CachableRed    src,
+                  Rectangle      bounds,
+                  PadMode        padMode,
+                  RenderingHints hints) {
+        super(src,bounds,src.getColorModel(),
+              fixSampleModel(src, bounds),
+              bounds.x, bounds.y,
+              null);
+
+        this.padMode = padMode;
+
+        if (DEBUG) {
+            System.out.println("Src: " + src + " Bounds: " + bounds +
+                               " Off: " +
+                               src.getTileGridXOffset() + ", " +
+                               src.getTileGridYOffset());
+        }
+        this.hints = hints;
+
+    }
+
+    public WritableRaster copyData(WritableRaster wr) {
+        // Get my source.
+        CachableRed src = (CachableRed)getSources().get(0);
+
+        Rectangle srcR = src.getBounds();
+        Rectangle wrR  = wr.getBounds();
+
+        if (wrR.intersects(srcR)) {
+            Rectangle r = wrR.intersection(srcR);
+
+            // Limit the raster I send to my source to his rect.
+            WritableRaster srcWR;
+            srcWR = wr.createWritableChild(r.x, r.y, r.width, r.height,
+                                           r.x, r.y, null);
+            src.copyData(srcWR);
+        }
+
+        if (padMode == PadMode.ZERO_PAD) {
+            handleZero(wr);
+        } else if (padMode == PadMode.REPLICATE) {
+            handleReplicate(wr);
+        } else if (padMode == PadMode.WRAP) {
+            handleWrap(wr);
+        }
+
+        return wr;
+    }
+
+    protected static class ZeroRecter {
+        WritableRaster wr;
+        int bands;
+        static int [] zeros=null;
+        public ZeroRecter(WritableRaster wr) {
+            this.wr = wr;
+            this.bands = wr.getSampleModel().getNumBands();
+        }
+        public void zeroRect(Rectangle r) {
+            synchronized (this) {
+                if ((zeros == null) || (zeros.length <r.width*bands))
+                    zeros = new int[r.width*bands];
+            }
+
+            for (int y=0; y<r.height; y++) {
+                wr.setPixels(r.x, r.y+y, r.width, 1, zeros);
+            }
+        }
+
+        public static ZeroRecter getZeroRecter(WritableRaster wr) {
+            if (GraphicsUtil.is_INT_PACK_Data(wr.getSampleModel(), false))
+                return new ZeroRecter_INT_PACK(wr);
+            else
+                return new ZeroRecter(wr);
+        }
+
+        public static void zeroRect(WritableRaster wr) {
+            ZeroRecter zr = getZeroRecter(wr);
+            zr.zeroRect(wr.getBounds());
+        }
+
+    }
+
+    protected static class ZeroRecter_INT_PACK extends ZeroRecter {
+        final int base;
+        final int scanStride;
+        final int[] pixels;
+        final int[] zeros;
+        final int x0, y0;
+
+        public ZeroRecter_INT_PACK(WritableRaster wr) {
+            super(wr);
+
+            SinglePixelPackedSampleModel sppsm;
+            sppsm = (SinglePixelPackedSampleModel)wr.getSampleModel();
+
+            scanStride = sppsm.getScanlineStride();
+            DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
+            x0 = wr.getMinY();
+            y0 = wr.getMinX();
+            base = (db.getOffset() +
+                    sppsm.getOffset(x0-wr.getSampleModelTranslateX(),
+                                    y0-wr.getSampleModelTranslateY()));
+
+            pixels = db.getBankData()[0];
+            if (wr.getWidth() > 10)
+                zeros = new int[wr.getWidth()];
+            else
+                zeros = null;
+        }
+
+        public void zeroRect(Rectangle r) {
+            final int rbase = base+(r.x-x0) + (r.y-y0)*scanStride;
+
+            if (r.width > 10) {
+                // Longer runs use arraycopy...
+                for (int y=0; y<r.height; y++) {
+                    int sp = rbase + y*scanStride;
+                    System.arraycopy(zeros, 0, pixels, sp, r.width);
+                }
+            } else {
+                // Small runs quicker to avoid func call.
+                int sp = rbase;
+                int end = sp +r.width;
+                int adj = scanStride-r.width;
+                for (int y=0; y<r.height; y++) {
+                    while (sp < end)
+                        pixels[sp++] = 0;
+                    sp  += adj;
+                    end += scanStride;
+                }
+            }
+        }
+    }
+
+    protected void handleZero(WritableRaster wr) {
+        // Get my source.
+        CachableRed src  = (CachableRed)getSources().get(0);
+        Rectangle   srcR = src.getBounds();
+        Rectangle   wrR  = wr.getBounds();
+
+        ZeroRecter zr = ZeroRecter.getZeroRecter(wr);
+
+        // area rect (covers the area left to handle).
+        Rectangle ar = new Rectangle(wrR.x, wrR.y, wrR.width, wrR.height);
+        // draw rect (used for calls to zeroRect);
+        Rectangle dr = new Rectangle(wrR.x, wrR.y, wrR.width, wrR.height);
+
+        // We split the edge drawing up into four parts.
+        //
+        //  +-----------------------------+
+        //  | 1    | 2                    |
+        //  |      +---------------+------|
+        //  /      /               /4     /
+        //  /      /               /      /
+        //  /      /               /      /
+        //  /      /               /      /
+        //  |      +---------------+------|
+        //  |      |  3                   |
+        //  +-----------------------------+
+        //
+        //  We update our x,y, width, height as we go along so
+        //  we 'forget' about the parts we have already painted...
+
+        // Draw #1
+        if (DEBUG) {
+            System.out.println("WrR: " + wrR + " srcR: " + srcR);
+            // g2d.setColor(new Color(255,0,0,128));
+        }
+        if (ar.x < srcR.x) {
+            int w = srcR.x-ar.x;
+            if (w > ar.width) w=ar.width;
+            // g2d.fillRect(x, y, w, height);
+            dr.width = w;
+            zr.zeroRect(dr);
+
+            ar.x+=w;
+            ar.width-=w;
+        }
+
+        // Draw #2
+        if (DEBUG) {
+            System.out.println("WrR: [" +
+                               ar.x + "," + ar.y + "," +
+                               ar.width + "," + ar.height +
+                               "] s rcR: " + srcR);
+            // g2d.setColor(new Color(0,0,255,128));
+        }
+        if (ar.y < srcR.y) {
+            int h = srcR.y-ar.y;
+            if (h > ar.height) h=ar.height;
+            // g2d.fillRect(x, y, width, h);
+            dr.x      = ar.x;
+            dr.y      = ar.y;
+            dr.width  = ar.width;
+            dr.height = h;
+            zr.zeroRect(dr);
+
+            ar.y     +=h;
+            ar.height-=h;
+        }
+
+        // Draw #3
+        if (DEBUG) {
+            System.out.println("WrR: [" +
+                               ar.x + "," + ar.y + "," +
+                               ar.width + "," + ar.height +
+                               "] srcR: " + srcR);
+            // g2d.setColor(new Color(0,255,0,128));
+        }
+        if (ar.y+ar.height > srcR.y+srcR.height) {
+            int h = (ar.y+ar.height) - (srcR.y+srcR.height);
+            if (h > ar.height) h=ar.height;
+
+            int y0 = ar.y+ar.height-h; // the +/-1 cancel (?)
+
+            // g2d.fillRect(x, y0, width, h);
+            dr.x      = ar.x;
+            dr.y      = y0;
+            dr.width  = ar.width;
+            dr.height = h;
+            zr.zeroRect(dr);
+
+            ar.height -= h;
+        }
+
+        // Draw #4
+        if (DEBUG) {
+            System.out.println("WrR: [" +
+                               ar.x + "," + ar.y + "," +
+                               ar.width + "," + ar.height +
+                               "] srcR: " + srcR);
+            // g2d.setColor(new Color(255,255,0,128));
+        }
+        if (ar.x+ar.width > srcR.x+srcR.width) {
+            int w = (ar.x+ar.width) - (srcR.x+srcR.width);
+            if (w > ar.width) w=ar.width;
+            int x0 = ar.x+ar.width-w; // the +/-1 cancel (?)
+
+            // g2d.fillRect(x0, y, w, height);
+            dr.x      = x0;
+            dr.y      = ar.y;
+            dr.width  = w;
+            dr.height = ar.height;
+            zr.zeroRect(dr);
+
+            ar.width-=w;
+        }
+    }
+
+
+    protected void handleReplicate(WritableRaster wr) {
+        // Get my source.
+        CachableRed src  = (CachableRed)getSources().get(0);
+        Rectangle   srcR = src.getBounds();
+        Rectangle   wrR  = wr.getBounds();
+
+        int x      = wrR.x;
+        int y      = wrR.y;
+        int width  = wrR.width;
+        int height = wrR.height;
+
+        Rectangle   r;
+        {
+            // Calculate an intersection that makes some sense
+            // even when the rects don't really intersect
+            // (The x and y ranges will be correct if they
+            // overlap in one dimension even if they don't
+            // intersect in both dimensions).
+            int minX = (srcR.x > x) ? srcR.x : x;
+            int maxX = (((srcR.x+srcR.width-1) < (x+width-1)) ?
+                        ( srcR.x+srcR.width-1) : (x+width-1));
+            int minY = (srcR.y > y) ? srcR.y : y;
+            int maxY = (((srcR.y+srcR.height-1) < (y+height-1)) ?
+                        ( srcR.y+srcR.height-1) : (y+height-1));
+
+            int x0 = minX;
+            int w = maxX-minX+1;
+            int y0 = minY;
+            int h = maxY-minY+1;
+            if (w <0 ) { x0 = 0; w = 0; }
+            if (h <0 ) { y0 = 0; h = 0; }
+            r = new Rectangle(x0, y0, w, h);
+        }
+
+        // We split the edge drawing up into four parts.
+        //
+        //  +-----------------------------+
+        //  | 3    | 1             | 4    |
+        //  |      +---------------+      |
+        //  /      /               /      /
+        //  /      / src           /      /
+        //  /      /               /      /
+        //  /      /               /      /
+        //  |      +---------------+      |
+        //  |      | 2             |      |
+        //  +-----------------------------+
+        //
+
+        // Draw #1
+        if (y < srcR.y) {
+            int repW = r.width;
+            int repX = r.x;
+            int wrX  = r.x;
+            int wrY  = y;
+            if (x+width-1 <= srcR.x) {
+                // we are off to the left of src. so set repX to the
+                // left most pixel...
+                repW = 1;
+                repX = srcR.x;
+                wrX  = x+width-1;
+            } else if (x >= srcR.x+srcR.width) {
+                // we are off to the right of src, so set repX to
+                // the right most pixel
+                repW = 1;
+                repX = srcR.x+srcR.width-1;
+                wrX  = x;
+            }
+
+            // This fills the top row of section 1 from src (we
+            // go to src instead of getting the data from wr because
+            // in some cases wr will be completely off the top of src
+            WritableRaster wr1 = wr.createWritableChild(wrX, wrY,
+                                                        repW, 1,
+                                                        repX, srcR.y, null);
+            src.copyData(wr1);
+            wrY++;
+
+            int endY = srcR.y;
+            if (y+height < endY) endY = y+height;
+
+            if (wrY < endY) {
+                int [] pixels = wr.getPixels(wrX, wrY-1,
+                                             repW, 1, (int [])null);
+                while (wrY < srcR.y) {
+                    wr.setPixels(wrX, wrY, repW, 1, pixels);
+                    wrY++;
+                }
+            }
+        }
+
+        // Draw #2
+        if ((y+height) > (srcR.y+srcR.height)) {
+            int repW = r.width;
+            int repX = r.x;
+            int repY = srcR.y+srcR.height-1;
+
+            int wrX  = r.x;
+            int wrY  = srcR.y+srcR.height;
+            if (wrY < y) wrY = y;
+
+            if (x+width <= srcR.x) {
+                // we are off to the left of src. so set repX to the
+                // left most pixel...
+                repW = 1;
+                repX = srcR.x;
+                wrX  = x+width-1;
+            } else if (x >= srcR.x+srcR.width) {
+                // we are off to the right of src, so set repX to
+                // the right most pixel
+                repW = 1;
+                repX = srcR.x+srcR.width-1;
+                wrX  = x;
+            }
+
+            if (DEBUG) {
+                System.out.println("wr: "  + wr.getBounds());
+                System.out.println("req: [" + wrX + ", " + wrY + ", " +
+                                   repW + ", 1]");
+            }
+
+            // First we get the top row of pixels from src. (we
+            // go to src instead of getting the data from wr because
+            // in some cases wr will be completely off the bottom of src).
+            WritableRaster wr1 = wr.createWritableChild(wrX, wrY,
+                                                        repW, 1,
+                                                        repX, repY, null);
+            // This fills the top row of section 2 from src
+            src.copyData(wr1);
+            wrY++;
+
+            int endY = y+height;
+            if (wrY < endY) {
+                // This fills the rest of section 2 from the first line.
+                int [] pixels = wr.getPixels(wrX, wrY-1,
+                                             repW, 1, (int [])null);
+                while (wrY < endY) {
+                    wr.setPixels(wrX, wrY, repW, 1, pixels);
+                    wrY++;
+                }
+            }
+        }
+
+        // Draw #3
+        if (x < srcR.x) {
+            // We are garunteed that we have a column of pixels down
+            // the edge of 1 and src.  We simply replicate this column
+            // out to the edges of 2.
+            int wrX = srcR.x;
+            if (x+width <= srcR.x) {
+                wrX = x+width-1;
+            }
+
+            int xLoc = x;
+            int [] pixels = wr.getPixels(wrX, y, 1, height, (int [])null);
+            while (xLoc < wrX) {
+                wr.setPixels(xLoc, y, 1, height, pixels);
+                xLoc++;
+            }
+        }
+
+        // Draw #4
+        if (x+width > srcR.x+srcR.width) {
+            // We are garunteed that we have a column of pixels down
+            // the edge of 1 and src.  We simply replicate this column
+            // out to the edges of 3.
+            int wrX = srcR.x+srcR.width-1;
+            if (x >= srcR.x+srcR.width) {
+                wrX = x;
+            }
+
+            int xLoc = wrX+1;
+            int endX = x+width-1;
+            int [] pixels = wr.getPixels(wrX, y, 1, height, (int [])null);
+            while (xLoc < endX) {
+                wr.setPixels(xLoc, y, 1, height, pixels);
+                xLoc++;
+            }
+        }
+    }
+
+    protected void handleWrap(WritableRaster wr) {
+
+        handleZero(wr);
+    }
+
+        /**
+         * This function 'fixes' the source's sample model.
+         * right now it just ensures that the sample model isn't
+         * much larger than my width.
+         */
+    protected static SampleModel fixSampleModel(CachableRed src,
+                                                Rectangle   bounds) {
+        int defSz = AbstractTiledRed.getDefaultTileSize();
+
+        SampleModel sm = src.getSampleModel();
+        int w = sm.getWidth();
+        if (w < defSz) w = defSz;
+        if (w > bounds.width)  w = bounds.width;
+        int h = sm.getHeight();
+        if (h < defSz) h = defSz;
+        if (h > bounds.height) h = bounds.height;
+
+        // System.out.println("Pad SMSz: " + w + "x" + h);
+
+        return sm.createCompatibleSampleModel(w, h);
+    }
+}

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/PadRed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ProfileRed.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ProfileRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ProfileRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ProfileRed.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,282 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.RenderingHints;
+import java.awt.Transparency;
+import java.awt.color.ColorSpace;
+import java.awt.image.BandedSampleModel;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorConvertOp;
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferByte;
+import java.awt.image.DirectColorModel;
+import java.awt.image.Raster;
+import java.awt.image.RenderedImage;
+import java.awt.image.WritableRaster;
+
+import org.apache.flex.forks.batik.ext.awt.color.ICCColorSpaceExt;
+
+
+/**
+ * This implementation of rendered image forces a color profile
+ * on its source
+ *
+ * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
+ * @version $Id: ProfileRed.java 504084 2007-02-06 11:24:46Z dvholten $
+ */
+public class ProfileRed extends AbstractRed {
+    private static final ColorSpace sRGBCS
+        = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+    private static final ColorModel sRGBCM
+        = new DirectColorModel(sRGBCS,
+                               32,
+                               0x00ff0000,
+                               0x0000ff00,
+                               0x000000ff,
+                               0xff000000,
+                               false,
+                               DataBuffer.TYPE_INT);
+
+    private ICCColorSpaceExt colorSpace;
+
+    /**
+     * @param src Images on which the input ColorSpace should
+     *        be forced
+     * @param colorSpace colorSpace that should be forced on the
+     *        source
+     */
+    public ProfileRed(CachableRed src,
+                      ICCColorSpaceExt colorSpace){
+        this.colorSpace = colorSpace;
+
+        init(src, src.getBounds(),
+             sRGBCM, sRGBCM.createCompatibleSampleModel(src.getWidth(),
+                                                        src.getHeight()),
+             src.getTileGridXOffset(), src.getTileGridYOffset(), null);
+
+    }
+
+    public CachableRed getSource() {
+        return (CachableRed)getSources().get(0);
+    }
+
+    /**
+     * This method will turn the input image in an sRGB image as follows.
+     * If there is no colorSpace defined, then the input image is
+     * simply converted to singlePixelPacked sRGB if needed.
+     * If there is a colorSpace defined, the the image data is 'interpreted'
+     * as being in that space, instead of that of the image's colorSpace.
+     *
+     * Here is how the input image is processed:
+     * a. It is converted to using a ComponentColorModel
+     * b. Its data is extracted, ignoring it's ColorSpace
+     * c. A new ComponentColorModel is built for the replacing colorSpace
+     *    Note that if the number of components in the input image and
+     *    the number of components in the replacing ColorSpace do not
+     *    match, it is not possible to apply the conversion.
+     * d. A new BufferedImage is built, using the new
+     *    ComponentColorModel and the data from the original image
+     *    converted to the ComponentColorModel built in a. The alpha
+     *    channel is excluded from that new BufferedImage.
+     * e. The BufferedImage created in d. is converted to sRGB using
+     *    ColorConvertOp
+     * f. The alpha channel information is integrated back into the image.
+     *
+     * IMPORTANT NOTE: The code uses a BandedSampleModel in c.) and
+     * d.) and discard the alpha channel during the color conversions
+     * (it is restored in f.)), because of bugs in the interleaved
+     * model with alpha. The BandedSampleModel did not cause any bug
+     * as of JDK 1.3.
+     */
+    public WritableRaster copyData(WritableRaster argbWR){
+        try{
+            RenderedImage img = getSource();
+
+            /**
+             * Check that the number of color components match in the input
+             * image and in the replacing profile.
+             */
+            ColorModel imgCM = img.getColorModel();
+            ColorSpace imgCS = imgCM.getColorSpace();
+            int nImageComponents = imgCS.getNumComponents();
+            int nProfileComponents = colorSpace.getNumComponents();
+            if(nImageComponents != nProfileComponents){
+                // Should we go in error???? Here we simply trace an error
+                // and return null
+                System.err.println("Input image and associated color profile have" +
+                                   " mismatching number of color components: conversion is not possible");
+                return argbWR;
+            }
+
+            /**
+             * Get the data from the source for the requested region
+             */
+            int w = argbWR.getWidth();
+            int h = argbWR.getHeight();
+            int minX = argbWR.getMinX();
+            int minY = argbWR.getMinY();
+            WritableRaster srcWR =
+                imgCM.createCompatibleWritableRaster(w, h);
+            srcWR = srcWR.createWritableTranslatedChild(minX, minY);
+            img.copyData(srcWR);
+
+            /**
+             * If the source data is not a ComponentColorModel using a
+             * BandedSampleModel, do the conversion now.
+             */
+            if(!(imgCM instanceof ComponentColorModel) ||
+               !(img.getSampleModel() instanceof BandedSampleModel) ||
+               (imgCM.hasAlpha() && imgCM.isAlphaPremultiplied() )) {
+                ComponentColorModel imgCompCM
+                    = new ComponentColorModel
+                        (imgCS,                      // Same ColorSpace as img
+                         imgCM.getComponentSize(),   // Number of bits/comp
+                         imgCM.hasAlpha(),             // Same alpha as img
+                         false, // unpremult alpha (so we can remove it next).
+                         imgCM.getTransparency(),      // Same trans as img
+                         DataBuffer.TYPE_BYTE);        // 8 bit/component.
+
+                WritableRaster wr = Raster.createBandedRaster
+                    (DataBuffer.TYPE_BYTE,
+                     argbWR.getWidth(), argbWR.getHeight(),
+                     imgCompCM.getNumComponents(),
+                     new Point(0, 0));
+
+                BufferedImage imgComp = new BufferedImage
+                    (imgCompCM, wr, imgCompCM.isAlphaPremultiplied(), null);
+
+                BufferedImage srcImg = new BufferedImage
+                    (imgCM, srcWR.createWritableTranslatedChild(0, 0),
+                     imgCM.isAlphaPremultiplied(), null);
+
+                Graphics2D g = imgComp.createGraphics();
+                g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
+                                   RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+                g.drawImage(srcImg, 0, 0, null);
+                img = imgComp;
+                imgCM = imgCompCM;
+                srcWR = wr.createWritableTranslatedChild(minX, minY);
+            }
+
+            /**
+             * Now, the input image is using a component color
+             * model. We can therefore create an image with the new
+             * profile, using a ComponentColorModel as well, because
+             * we know the number of components match (this was
+             * checked at the begining of this routine).  */
+            ComponentColorModel newCM = new ComponentColorModel
+                (colorSpace,                    // **** New ColorSpace ****
+                 imgCM.getComponentSize(),      // Array of number of bits per components
+                 false,                         // No alpa
+                 false,                         // Not premultiplied
+                 Transparency.OPAQUE,           // No transparency
+                 DataBuffer.TYPE_BYTE);         // 8 Bits
+
+            // Build a raster with bands 0, 1 and 2 of img's raster
+            DataBufferByte data = (DataBufferByte)srcWR.getDataBuffer();
+            srcWR = Raster.createBandedRaster
+                (data, argbWR.getWidth(), argbWR.getHeight(),
+                 argbWR.getWidth(), new int[]{0, 1, 2},
+                 new int[]{0, 0, 0}, new Point(0, 0));
+            BufferedImage newImg = new BufferedImage
+                (newCM, srcWR, newCM.isAlphaPremultiplied(), null);
+
+            /**
+             * Now, convert the image to sRGB
+             */
+            ComponentColorModel sRGBCompCM = new ComponentColorModel
+                (ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                 new int[]{8, 8, 8},
+                 false,
+                 false,
+                 Transparency.OPAQUE,
+                 DataBuffer.TYPE_BYTE);
+
+            WritableRaster wr = Raster.createBandedRaster
+                (DataBuffer.TYPE_BYTE, argbWR.getWidth(), argbWR.getHeight(),
+                 sRGBCompCM.getNumComponents(), new Point(0, 0));
+
+            BufferedImage sRGBImage = new BufferedImage
+                (sRGBCompCM, wr, false, null);
+            ColorConvertOp colorConvertOp = new ColorConvertOp(null);
+            colorConvertOp.filter(newImg, sRGBImage);
+
+            /**
+             * Integrate alpha back into the image if there is any
+             */
+            if (imgCM.hasAlpha()){
+                DataBufferByte rgbData = (DataBufferByte)wr.getDataBuffer();
+                byte[][] imgBanks = data.getBankData();
+                byte[][] rgbBanks = rgbData.getBankData();
+
+                byte[][] argbBanks = {rgbBanks[0], rgbBanks[1],
+                                      rgbBanks[2], imgBanks[3]};
+                DataBufferByte argbData = new DataBufferByte(argbBanks, imgBanks[0].length);
+                srcWR = Raster.createBandedRaster
+                    (argbData, argbWR.getWidth(), argbWR.getHeight(),
+                     argbWR.getWidth(), new int[]{0, 1, 2, 3},
+                     new int[]{0, 0, 0, 0}, new Point(0, 0));
+                sRGBCompCM = new ComponentColorModel
+                    (ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                     new int[]{8, 8, 8, 8},
+                     true,
+                     false,
+                     Transparency.TRANSLUCENT,
+                     DataBuffer.TYPE_BYTE);
+                sRGBImage = new BufferedImage(sRGBCompCM,
+                                              srcWR,
+                                              false,
+                                              null);
+
+            }
+
+            /*BufferedImage result = new BufferedImage(img.getWidth(),
+              img.getHeight(),
+              BufferedImage.TYPE_INT_ARGB);*/
+            BufferedImage result = new BufferedImage(sRGBCM,
+                                                     argbWR.createWritableTranslatedChild(0, 0),
+                                                     false,
+                                                     null);
+
+
+            ///////////////////////////////////////////////
+            // BUG IN ColorConvertOp: The following breaks:
+            // colorConvertOp.filter(sRGBImage, result);
+            //
+            // Using Graphics2D instead....
+            ///////////////////////////////////////////////
+            Graphics2D g = result.createGraphics();
+            g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
+                               RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+            g.drawImage(sRGBImage, 0, 0, null);
+            g.dispose();
+
+            return argbWR;
+        }catch(Exception e){
+            e.printStackTrace();
+            throw new Error( e.getMessage() );
+        }
+    }
+
+}

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ProfileRed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/RenderedImageCachableRed.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/RenderedImageCachableRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/RenderedImageCachableRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/RenderedImageCachableRed.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,156 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.Raster;
+import java.awt.image.RenderedImage;
+import java.awt.image.SampleModel;
+import java.awt.image.WritableRaster;
+import java.util.Vector;
+
+
+/**
+ * This implements CachableRed around a RenderedImage.
+ * You can use this to wrap a RenderedImage that you want to
+ * appear as a CachableRed.
+ * It essentially ignores the dependency and dirty region methods.
+ *
+ * @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
+ * @version $Id: RenderedImageCachableRed.java 478363 2006-11-22 23:01:13Z dvholten $
+ */
+public class RenderedImageCachableRed implements CachableRed {
+
+    public static CachableRed wrap(RenderedImage ri) {
+        if (ri instanceof CachableRed)
+            return (CachableRed) ri;
+        if (ri instanceof BufferedImage)
+            return new BufferedImageCachableRed((BufferedImage)ri);
+        return new RenderedImageCachableRed(ri);
+    }
+
+    private RenderedImage src;
+    private Vector srcs = new Vector(0);
+
+    public RenderedImageCachableRed(RenderedImage src) {
+        if(src == null){
+            throw new IllegalArgumentException();
+        }
+        this.src = src;
+    }
+
+    public Vector getSources() {
+        return srcs; // should always be empty...
+    }
+
+    public Rectangle getBounds() { 
+        return new Rectangle(getMinX(),    // could we cache the rectangle??
+                             getMinY(),
+                             getWidth(),
+                             getHeight());
+    }
+
+    public int getMinX() {
+        return src.getMinX();
+    }
+    public int getMinY() {
+        return src.getMinY();
+    }
+
+    public int getWidth() {
+        return src.getWidth();
+    }
+    public int getHeight() {
+        return src.getHeight();
+    }
+
+    public ColorModel getColorModel() {
+        return src.getColorModel();
+    }
+
+    public SampleModel getSampleModel() {
+        return src.getSampleModel();
+    }
+
+    public int getMinTileX() {
+        return src.getMinTileX();
+    }
+    public int getMinTileY() {
+        return src.getMinTileY();
+    }
+
+    public int getNumXTiles() {
+        return src.getNumXTiles();
+    }
+    public int getNumYTiles() {
+        return src.getNumYTiles();
+    }
+
+    public int getTileGridXOffset() {
+        return src.getTileGridXOffset();
+    }
+
+    public int getTileGridYOffset() {
+        return src.getTileGridYOffset();
+    }
+
+    public int getTileWidth() {
+        return src.getTileWidth();
+    }
+    public int getTileHeight() {
+        return src.getTileHeight();
+    }
+
+    public Object getProperty(String name) {
+        return src.getProperty(name);
+    }
+
+    public String[] getPropertyNames() {
+        return src.getPropertyNames();
+    }
+
+    public Raster getTile(int tileX, int tileY) {
+        return src.getTile(tileX, tileY);
+    }
+
+    public WritableRaster copyData(WritableRaster raster) {
+        return src.copyData(raster);
+    }
+
+    public Raster getData() {
+        return src.getData();
+    }
+
+    public Raster getData(Rectangle rect) {
+        return src.getData(rect);
+    }
+
+    public Shape getDependencyRegion(int srcIndex, Rectangle outputRgn) {
+        throw new IndexOutOfBoundsException
+            ("Nonexistant source requested.");
+    }
+
+    public Shape getDirtyRegion(int srcIndex, Rectangle inputRgn) {
+        throw new IndexOutOfBoundsException
+            ("Nonexistant source requested.");
+    }
+}

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/RenderedImageCachableRed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/SpecularLightingRed.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/SpecularLightingRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/SpecularLightingRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/SpecularLightingRed.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,254 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+import java.awt.Rectangle;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBufferInt;
+import java.awt.image.SampleModel;
+import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.WritableRaster;
+
+import org.apache.flex.forks.batik.ext.awt.image.GraphicsUtil;
+import org.apache.flex.forks.batik.ext.awt.image.Light;
+import org.apache.flex.forks.batik.ext.awt.image.SpotLight;
+
+/**
+ * 
+ * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
+ * @version $Id: SpecularLightingRed.java 475477 2006-11-15 22:44:28Z cam $
+ */
+public class SpecularLightingRed extends AbstractTiledRed{
+    /**
+     * Specular lighting constant
+     */
+    private double ks;
+
+    /**
+     * Specular lighting exponent
+     */
+    private double specularExponent;
+
+    /**
+     * Light used for specular lighting
+     */
+    private Light light;
+
+    /**
+     * BumpMap source
+     */
+    private BumpMap bumpMap;
+
+    /**
+     * Device space to user space scale factors, along
+     * each axis.
+     */
+    private double scaleX, scaleY;
+
+    /**
+     * LitRegion
+     */
+    private Rectangle litRegion;
+
+    /**
+     * true if calculations should be performed in linear sRGB
+     */
+    private boolean linear;
+     
+
+    public SpecularLightingRed(double ks,
+                               double specularExponent,
+                               Light light,
+                               BumpMap bumpMap,
+                               Rectangle litRegion,
+                               double scaleX, double scaleY,
+                               boolean linear) {
+        this.ks = ks;
+        this.specularExponent = specularExponent;
+        this.light = light;
+        this.bumpMap = bumpMap;
+        this.litRegion = litRegion;
+        this.scaleX = scaleX;
+        this.scaleY = scaleY;
+        this.linear = linear;
+
+        ColorModel cm;
+        if (linear)
+            cm = GraphicsUtil.Linear_sRGB_Unpre;
+        else
+            cm = GraphicsUtil.sRGB_Unpre;
+
+        int tw = litRegion.width;
+        int th = litRegion.height;
+        int defSz = AbstractTiledRed.getDefaultTileSize();
+        if (tw > defSz) tw = defSz;
+        if (th > defSz) th = defSz;
+        SampleModel sm = cm.createCompatibleSampleModel(tw, th);
+                                             
+        init((CachableRed)null, litRegion, cm, sm,
+             litRegion.x, litRegion.y, null);
+    }
+
+    public WritableRaster copyData(WritableRaster wr) {
+        copyToRaster(wr);
+        return wr;
+    }
+
+    public void genRect(WritableRaster wr) {
+        // Copy variable on stack for faster access in tight loop
+        final double scaleX = this.scaleX;
+        final double scaleY = this.scaleY;
+
+        final double[] lightColor = light.getColor(linear);
+
+        final int w = wr.getWidth();
+        final int h = wr.getHeight();
+        final int minX = wr.getMinX();
+        final int minY = wr.getMinY();
+
+        final DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
+        final int[] pixels = db.getBankData()[0];
+
+        final SinglePixelPackedSampleModel sppsm;
+        sppsm = (SinglePixelPackedSampleModel)wr.getSampleModel();
+
+        final int offset = 
+            (db.getOffset() +
+             sppsm.getOffset(minX-wr.getSampleModelTranslateX(), 
+                             minY-wr.getSampleModelTranslateY()));
+        // int offset = db.getOffset();
+        final int scanStride = sppsm.getScanlineStride();
+        final int adjust = scanStride - w;
+        int p = offset;
+        int a=0, i=0, j=0;
+
+        // x and y are in user space
+        double x = scaleX*minX;
+        double y = scaleY*minY;
+        double norm = 0;
+
+        int pixel = 0, tmp;
+        double mult;
+        mult = (lightColor[0]>lightColor[1])?lightColor[0]:lightColor[1];
+        mult = (mult>lightColor[2])?mult:lightColor[2];
+        
+        double scale = 255/mult;
+        pixel = (int)(lightColor[0]*scale+0.5);
+        tmp   = (int)(lightColor[1]*scale+0.5);
+        pixel = pixel<<8 | tmp;
+        tmp   = (int)(lightColor[2]*scale+0.5);
+        pixel = pixel<<8 | tmp;
+
+        mult*=255*ks;
+
+        // System.out.println("Pixel: 0x" + Integer.toHexString(pixel));
+
+        final double[][][] NA = bumpMap.getNormalArray(minX, minY, w, h);
+
+        // System.out.println("Entering Specular Lighting");
+        if (light instanceof SpotLight) {
+            SpotLight slight = (SpotLight)light;
+            final double[][] LA = new double[w][4];
+            for(i=0; i<h; i++){
+                // System.out.println("Row: " + i);
+                final double [][] NR = NA[i];
+                slight.getLightRow4(x, y+i*scaleY, scaleX, w, NR, LA);
+                for (j=0; j<w; j++){
+                    // Get Normal 
+                    final double [] N = NR[j];
+                    
+                    // Get Light Vector
+                    final double [] L = LA[j];
+                    double vs = L[3];
+                    if (vs == 0) {
+                        a = 0;
+                    } else {
+                        L[2] += 1;
+                        norm = L[0]*L[0] + L[1]*L[1] + L[2]*L[2];
+                        norm = Math.sqrt(norm);
+                        double dot = N[0]*L[0] + N[1]*L[1] + N[2]*L[2];
+                        vs = vs*Math.pow(dot/norm, specularExponent);
+                        a = (int)(mult*vs + 0.5);
+                        if ((a & 0xFFFFFF00) != 0)
+                            a = ((a & 0x80000000) != 0)?0:255;
+                    }
+                    pixels[p++] = (a << 24 | pixel);
+                }
+                p += adjust;
+            }
+        } else if(!light.isConstant()){
+            final double[][] LA = new double[w][4];
+            for(i=0; i<h; i++){
+                // System.out.println("Row: " + i);
+                final double [][] NR = NA[i];
+                light.getLightRow(x, y+i*scaleY, scaleX, w, NR, LA);
+                for (j=0; j<w; j++){
+                    // Get Normal 
+                    final double [] N = NR[j];
+                    
+                    // Get Light Vector
+                    final double [] L = LA[j];
+                    L[2] += 1;
+                    norm = L[0]*L[0] + L[1]*L[1] + L[2]*L[2];
+                    norm = Math.sqrt(norm);
+                    double dot = N[0]*L[0] + N[1]*L[1] + N[2]*L[2];
+                    // vs = vs/norm;
+                    norm = Math.pow(dot/norm, specularExponent);
+                    a = (int)(mult*norm + 0.5);
+                    if ((a & 0xFFFFFF00) != 0)
+                        a = ((a & 0x80000000) != 0)?0:255;
+                    pixels[p++] = (a << 24 | pixel);
+                }
+                p += adjust;
+            }
+        }
+        else{
+            // Get constant light vector
+            final double[] L = new double[3];
+            light.getLight(0, 0, 0, L);
+
+            // Compute Half-way vector
+            L[2] += 1;
+            norm = Math.sqrt(L[0]*L[0] + L[1]*L[1] + L[2]*L[2]);
+            if(norm > 0){
+                L[0] /= norm;
+                L[1] /= norm;
+                L[2] /= norm;
+            }
+
+            for(i=0; i<h; i++){
+                final double [][] NR = NA[i];
+                for(j=0; j<w; j++){
+                    // Get Normal 
+                    final double [] N = NR[j];
+                    
+                    a = (int)(mult*Math.pow(N[0]*L[0] + N[1]*L[1] + N[2]*L[2], 
+                                            specularExponent) + 0.5);
+                    
+                    if ((a & 0xFFFFFF00) != 0)
+                        a = ((a & 0x80000000) != 0)?0:255;
+
+                    pixels[p++] = (a << 24 | pixel);
+                }
+                p += adjust;
+            }
+        }
+        // System.out.println("Exiting Specular Lighting");
+    }
+}

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/SpecularLightingRed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileBlock.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileBlock.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileBlock.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileBlock.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,269 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * This class is responsible for breaking up a block of tiles into
+ * a set of smaller requests that are as large as possible without
+ * rerequesting significant numbers of tiles that are already
+ * available.
+ *
+ * @version $Id: TileBlock.java 489226 2006-12-21 00:05:36Z cam $
+ */
+public class TileBlock {
+
+    int occX, occY, occW, occH;
+    int xOff, yOff, w, h, benefit;
+    boolean [] occupied;
+
+    /**
+     * Construct a tile block this represents a block of contigous
+     * tiles.
+     * @param xOff The x index of left edge of the tile block.
+     * @param yOff The y index of top edge of the tile block.
+     * @param w    The number of tiles across in the block
+     * @param h    The number of tiles down  the block
+     * @param occupied Which entries in the block are already
+     *                 computed.
+     */
+    TileBlock(int occX, int occY, int occW, int occH, boolean [] occupied,
+              int xOff, int yOff, int w, int h) {
+        this.occX = occX;
+        this.occY = occY;
+        this.occW = occW;
+        this.occH = occH;
+        this.xOff = xOff;
+        this.yOff = yOff;
+        this.w    = w   ;
+        this.h    = h   ;
+        this.occupied = occupied;
+
+        // System.out.println("Block: [" +
+        //                    xloc + "," + yloc + ","  +
+        //                    w + "," + h + "]");
+        for (int y=0; y<h; y++)
+            for (int x=0; x<w; x++)
+                if (!occupied[x+xOff+occW*(y+yOff)])
+                    benefit++;
+    }
+
+    /**
+     * Really nice to string that outlines what tiles are filled
+     * and what region this block covers.  Really useful for
+     * debugging the TileBlock stuff.
+     */
+    public String toString() {
+        String ret = "";
+        for (int y=0; y<occH; y++) {
+            for (int x=0; x<occW+1; x++) {
+                if ((x==xOff) || (x==xOff+w)) {
+                    if ((y==yOff) || (y==yOff+h-1))
+                        ret += "+";
+                    else  if ((y>yOff) && (y<yOff+h-1))
+                        ret += "|";
+                    else
+                        ret += " ";
+                }
+                else if ((y==yOff)     && (x> xOff) && (x < xOff+w))
+                    ret += "-";
+                else if ((y==yOff+h-1) && (x> xOff) && (x < xOff+w))
+                    ret += "_";
+                else
+                    ret += " ";
+
+                if (x== occW)
+                    continue;
+
+                if (occupied[x+y*occW])
+                    ret += "*";
+                else
+                    ret += ".";
+            }
+            ret += "\n";
+        }
+        return ret;
+    }
+
+    /**
+     * Return the x location of this block of tiles
+     */
+    int getXLoc()    { return occX+xOff; }
+
+    /**
+     * Return the y location of this block of tiles
+     */
+    int getYLoc()    { return occY+yOff; }
+
+    /**
+     * Return the width of this block of tiles
+     */
+    int getWidth()   { return w; }
+
+    /**
+     * Return the height of this block of tiles
+     */
+    int getHeight()  { return h; }
+
+    /**
+     * Return the number of new tiles computed.
+     */
+    int getBenefit() { return benefit; }
+
+    /**
+     * Return the approximate amount of work required to compute
+     * those tiles.
+     */
+    int getWork()    { return w*h+1; }
+
+    /**
+     * Returns the total amount of work for the array of tile blocks
+     */
+    static int getWork(TileBlock [] blocks) {
+        int ret=0;
+        for (int i=0; i<blocks.length; i++)
+            ret += blocks[i].getWork();
+        return ret;
+    }
+
+    /**
+     * Returnes an optimized list of TileBlocks to generate that
+     * tries to minimize the work to benefit ratio, for the set of
+     * blocks defined by this block.
+     */
+    TileBlock [] getBestSplit() {
+        if (simplify())
+            return null;
+
+        // Optimal split already...
+        if (benefit == w*h)
+            return new TileBlock [] { this };
+
+        return splitOneGo();
+    }
+
+    public TileBlock [] splitOneGo() {
+        boolean [] filled = (boolean [])occupied.clone();
+        List items = new ArrayList();
+        for (int y=yOff; y<yOff+h; y++)
+            for (int x=xOff; x<xOff+w; x++) {
+                if (!filled[x+y*occW]) {
+                    // We have an unfilled tile slot, so first we
+                    // figure out how long the slot is in this row.
+                    int cw = xOff+w-x;
+                    for (int cx=x; cx<x+cw; cx++)
+                        if (filled[cx+y*occW])
+                            cw = cx-x;
+                        else
+                            filled[cx+y*occW] = true;  // fill as we go..
+
+                    // Then we check the next rows until we hit
+                    // a row that doesn't have this slot all free.
+                    // at which point we stop...
+                    int ch=1;
+                    for (int cy=y+1; cy<yOff+h; cy++) {
+                        int cx=x;
+                        for (; cx<x+cw; cx++)
+                            if (filled[cx+cy*occW])
+                                break;
+
+                        // Partial row so bail (we'll get it later..)
+                        if (cx != x+cw)
+                            break;
+
+                        // Fill in the slot since we will use it...
+                        for (cx=x; cx<x+cw; cx++)
+                            filled[cx+cy*occW] = true;
+                        ch++;
+                    }
+                    items.add(new TileBlock(occX, occY, occW, occH,
+                                            occupied, x, y, cw, ch));
+                    x+=(cw-1);
+                }
+            }
+
+        TileBlock [] ret = new TileBlock[items.size()];
+        items.toArray( ret );
+
+        return ret;
+    }
+
+    public boolean simplify() {
+
+        boolean[] workOccupied = occupied;   // local is cheaper
+
+        for (int y=0; y<h; y++) {
+            int x;
+            for (x=0; x<w; x++)
+                if (!workOccupied[x+xOff+occW*(y+yOff)])
+                    break;
+            if (x!=w) break;
+
+            // Fully occupied row so remove it.
+            yOff++;
+            y--;
+            h--;
+        }
+
+        // return true if we were simplified out of existance.
+        if (h==0) return true;
+
+        // If we make it past here we must have at least one good block.
+
+        for (int y=h-1; y>=0; y--) {
+            int x;
+            for (x=0; x<w; x++)
+                if (!workOccupied[x+xOff+occW*(y+yOff)])
+                    break;
+            if (x!=w) break;
+
+            // Fully occupied row so remove it.
+            h--;
+        }
+
+        for (int x=0; x<w; x++) {
+            int y;
+            for (y=0; y<h; y++)
+                if (!workOccupied[x+xOff+occW*(y+yOff)])
+                    break;
+            if (y!=h) break;
+
+            // Fully occupied Col so remove it.
+            xOff++;
+            x--;
+            w--;
+        }
+
+        for (int x=w-1; x>=0; x--) {
+            int y;
+            for (y=0; y<h; y++)
+                if (!workOccupied[x+xOff+occW*(y+yOff)])
+                    break;
+            if (y!=h) break;
+
+            // Fully occupied Col so remove it.
+            w--;
+        }
+
+        return false;
+    }
+}

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileBlock.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileCache.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileCache.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileCache.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileCache.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,46 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+import java.awt.image.RenderedImage;
+
+/**
+ *
+ * @version $Id: TileCache.java 498740 2007-01-22 18:35:57Z dvholten $
+ */
+public class TileCache {
+        private static LRUCache cache = new LRUCache(50);
+
+        public static void setSize(int sz) { cache.setSize(sz); }
+
+        public static TileStore getTileGrid(int minTileX, int minTileY,
+                                       int xSz, int ySz, TileGenerator src) {
+                return new TileGrid(minTileX, minTileY, xSz, ySz, src, cache);
+        }
+
+        public static TileStore getTileGrid(RenderedImage img,
+                                            TileGenerator src) {
+                return new TileGrid(img.getMinTileX(),  img.getMinTileY(),
+                            img.getNumXTiles(), img.getNumYTiles(),
+                            src, cache);
+        }
+        public static TileStore getTileMap(TileGenerator src) {
+                return new TileMap(src, cache);
+        }
+}

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileCacheRed.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileCacheRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileCacheRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileCacheRed.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,86 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+import java.awt.Rectangle;
+import java.awt.image.ColorModel;
+import java.awt.image.SampleModel;
+import java.awt.image.WritableRaster;
+
+/**
+ * This implementation of RenderedImage only serves to put the tiles
+ * generated by it's input into the TileCache.
+ *
+ * @author <a href="mailto:thomas.deweese@kodak.com">Thomas DeWeese</a>
+ * @version $Id: TileCacheRed.java 491223 2006-12-30 14:04:41Z dvholten $
+ */
+public class TileCacheRed extends AbstractTiledRed {
+
+    /**
+     * Place the results of computations of cr into the global tile cache.
+     * @param cr The operation to cache results from.
+     */
+    public TileCacheRed(CachableRed cr) {
+        super(cr, null);
+    }
+
+    /**
+     * Place the results of computations of cr into the global tile cache.
+     * @param cr The operation to cache results from.
+     */
+    public TileCacheRed(CachableRed cr, int tileWidth, int tileHeight) {
+        super();
+        ColorModel  cm = cr.getColorModel();
+        Rectangle bounds = cr.getBounds();
+        if (tileWidth  > bounds.width)  tileWidth  = bounds.width;
+        if (tileHeight > bounds.height) tileHeight = bounds.height;
+        SampleModel sm = cm.createCompatibleSampleModel(tileWidth, tileHeight);
+        init(cr, bounds, cm, sm, 
+             cr.getTileGridXOffset(), cr.getTileGridYOffset(),
+             null);
+    }
+
+    public void genRect(WritableRaster wr) {
+        // Get my source.
+        CachableRed src = (CachableRed)getSources().get(0);
+
+        src.copyData(wr);
+    }
+
+    public void flushCache(Rectangle rect) {
+        int tx0 = getXTile(rect.x);
+        int ty0 = getYTile(rect.y);
+        int tx1 = getXTile(rect.x+rect.width -1);
+        int ty1 = getYTile(rect.y+rect.height-1);
+
+        if (tx0 < minTileX) tx0 = minTileX;
+        if (ty0 < minTileY) ty0 = minTileY;
+
+        if (tx1 >= minTileX+numXTiles) tx1 = minTileX+numXTiles-1;
+        if (ty1 >= minTileY+numYTiles) ty1 = minTileY+numYTiles-1;
+
+        if ((tx1 < tx0) || (ty1 < ty0))
+            return;
+
+        TileStore store = getTileStore();
+        for (int y=ty0; y<=ty1; y++)
+            for (int x=tx0; x<=tx1; x++)
+                store.setTile(x, y, null);
+    }
+}

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileCacheRed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileGenerator.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileGenerator.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileGenerator.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileGenerator.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,31 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+import  java.awt.image.Raster;
+
+/**
+ * This the generic interface for a source of tiles.  This is used
+ * when the cache has a miss.
+ *
+ * @version $Id: TileGenerator.java 498740 2007-01-22 18:35:57Z dvholten $
+ */
+public interface TileGenerator {
+        Raster genTile(int x, int y);
+}

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileGrid.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileGrid.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileGrid.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileGrid.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,166 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+import  java.awt.image.Raster;
+
+import org.apache.flex.forks.batik.util.HaltingThread;
+
+/**
+ * This is a Grid based implementation of the TileStore.
+ * This makes it pretty quick, but it can use a fair amount of
+ * memory for large tile grids.
+ *
+ * @version $Id: TileGrid.java 498740 2007-01-22 18:35:57Z dvholten $
+ */
+public class TileGrid implements TileStore {
+    private static final boolean DEBUG = false;
+    private static final boolean COUNT = false;
+
+    private int xSz, ySz;
+    private int minTileX, minTileY;
+    private TileLRUMember   [][] rasters=null;
+    private TileGenerator source = null;
+    private LRUCache      cache = null;
+
+    public TileGrid(int minTileX, int minTileY,
+                    int xSz, int ySz,
+                    TileGenerator source,
+                    LRUCache cache) {
+        this.cache    = cache;
+        this.source   = source;
+        this.minTileX = minTileX;
+        this.minTileY = minTileY;
+        this.xSz      = xSz;
+        this.ySz      = ySz;
+
+        rasters = new TileLRUMember[ySz][];
+    }
+
+    public void setTile(int x, int y, Raster ras) {
+        x-= minTileX;
+        y-= minTileY;
+        if ((x<0) || (x>=xSz)) return;
+        if ((y<0) || (y>=ySz)) return;
+
+        TileLRUMember [] row = rasters[y];
+        TileLRUMember item;
+        if (ras == null) {
+            // Clearing entry.
+            if (row == null) return;
+            item = row[x];
+            if (item == null) return;
+
+            row[x] = null;
+            cache.remove(item);
+            return;
+        }
+
+        if (row != null) {
+            item = row[x];
+            if (item == null) {
+                item = new TileLRUMember();
+                row[x] = item;
+            }
+        } else {
+            row = new TileLRUMember[xSz];
+            item = new TileLRUMember();
+            row[x] = item;
+            rasters[y] = row;
+        }
+        item.setRaster(ras);
+
+        cache.add(item);
+
+        if (DEBUG) System.out.println("Setting: (" + (x+minTileX) + ", " +
+                                      (y+minTileY) + ")");
+    }
+
+    // Returns Raster if the tile is _currently_ in the cache.
+    // If it is not currently in the cache it returns null.
+    public Raster getTileNoCompute(int x, int y) {
+        x-=minTileX;
+        y-=minTileY;
+        if ((x<0) || (x>=xSz)) return null;
+        if ((y<0) || (y>=ySz)) return null;
+
+        TileLRUMember [] row = rasters[y];
+        if (row == null)
+            return null;
+        TileLRUMember item = row[x];
+        if (item == null)
+            return null;
+        Raster ret = item.retrieveRaster();
+        if (ret != null)
+            cache.add(item);
+        return ret;
+    }
+
+    public Raster getTile(int x, int y) {
+        x-=minTileX;
+        y-=minTileY;
+        if ((x<0) || (x>=xSz)) return null;
+        if ((y<0) || (y>=ySz)) return null;
+
+        if (DEBUG) System.out.println("Fetching: (" + (x+minTileX) + ", " +
+                                      (y+minTileY) + ")");
+        if (COUNT) synchronized (TileGrid.class) { requests++; }
+
+        Raster       ras  = null;
+        TileLRUMember [] row  = rasters[y];
+        TileLRUMember    item = null;
+        if (row != null) {
+            item = row[x];
+            if (item != null)
+                ras = item.retrieveRaster();
+            else {
+                item = new TileLRUMember();
+                row[x] = item;
+            }
+        } else {
+            row = new TileLRUMember[xSz];
+            rasters[y] = row;
+            item = new TileLRUMember();
+            row[x] = item;
+        }
+
+        if (ras == null) {
+            if (DEBUG) System.out.println("Generating: ("+(x+minTileX)+", "+
+                                          (y+minTileY) + ")");
+            if (COUNT) synchronized (TileGrid.class) { misses++; }
+            ras = source.genTile(x+minTileX, y+minTileY);
+
+            // In all likelyhood the contents of this tile is junk!
+            // So don't cache it (returning is probably fine since it
+            // won't come back to haunt us...
+            if (HaltingThread.hasBeenHalted())
+                return ras;
+
+            item.setRaster(ras);
+        }
+
+        // Update the item's position in the cache..
+        cache.add(item);
+
+        return ras;
+    }
+
+    static int requests;
+    static int misses;
+}

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileGrid.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileLRUMember.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileLRUMember.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileLRUMember.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileLRUMember.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,81 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+import  java.awt.image.Raster;
+import  java.lang.ref.Reference;
+import  java.lang.ref.SoftReference;
+
+/**
+ * This is a useful class that wraps a Raster for patricipation in
+ * an LRU Cache.  When this object drops out of the LRU cache it
+ * removes it's hard reference to the tile, but retains it's soft
+ * reference allowing for the recovery of the tile when the JVM is
+ * not under memory pressure
+ *
+ * @version $Id: TileLRUMember.java 498740 2007-01-22 18:35:57Z dvholten $
+ */
+public class TileLRUMember implements LRUCache.LRUObj {
+    private static final boolean DEBUG = false;
+
+        protected LRUCache.LRUNode myNode  = null;
+        protected Reference        wRaster = null;
+        protected Raster           hRaster = null;
+
+        public TileLRUMember() { }
+
+        public TileLRUMember(Raster ras) {
+            setRaster(ras);
+        }
+
+        public void setRaster(Raster ras) {
+            hRaster = ras;
+            wRaster = new SoftReference(ras);
+        }
+
+        public boolean checkRaster() {
+            if (hRaster != null) return true;
+
+            if ((wRaster       != null) &&
+            (wRaster.get() != null)) return true;
+
+            return false;
+        }
+
+        public Raster retrieveRaster() {
+            if (hRaster != null) return hRaster;
+            if (wRaster == null) return null;
+
+            hRaster = (Raster)wRaster.get();
+
+            if (hRaster == null)  // didn't manage to retrieve it...
+            wRaster = null;
+
+            return hRaster;
+        }
+
+        public LRUCache.LRUNode lruGet()         { return myNode; }
+        public void lruSet(LRUCache.LRUNode nde) { myNode = nde; }
+        public void lruRemove()                  {
+            myNode  = null;
+            hRaster = null;
+            if (DEBUG) System.out.println("Removing");
+        }
+}
+

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileLRUMember.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileMap.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileMap.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileMap.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileMap.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,156 @@
+/*
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+package org.apache.flex.forks.batik.ext.awt.image.rendered;
+
+import java.awt.Point;
+import java.awt.image.Raster;
+import java.lang.ref.SoftReference;
+import java.util.HashMap;
+
+import org.apache.flex.forks.batik.util.CleanerThread;
+import org.apache.flex.forks.batik.util.HaltingThread;
+
+/**
+ *
+ * @version $Id: TileMap.java 498740 2007-01-22 18:35:57Z dvholten $
+ */
+public class TileMap implements TileStore {
+    private static final boolean DEBUG = false;
+    private static final boolean COUNT = false;
+
+    private HashMap rasters=new HashMap();
+
+    static class TileMapLRUMember extends TileLRUMember {
+        public Point   pt;
+        public SoftReference parent;
+
+        class RasterSoftRef extends CleanerThread.SoftReferenceCleared {
+            RasterSoftRef(Object o) { super(o); }
+            public void cleared() {
+                if (DEBUG) System.err.println("Cleaned: " + this);
+                TileMap tm = (TileMap)parent.get();
+                if (tm != null)
+                    tm.rasters.remove(pt);
+            }
+        }
+
+        TileMapLRUMember(TileMap parent, Point pt, Raster ras) {
+            super(ras);
+            this.parent = new SoftReference(parent);
+            this.pt     = pt;
+        }
+
+        public void setRaster(Raster ras) {
+            hRaster = ras;
+            wRaster = new RasterSoftRef(ras);
+        }
+    }
+
+    private TileGenerator source = null;
+    private LRUCache      cache = null;
+
+    public TileMap(TileGenerator source,
+                   LRUCache cache) {
+        this.cache    = cache;
+        this.source   = source;
+    }
+
+    public void setTile(int x, int y, Raster ras) {
+        Point pt = new Point(x, y);
+
+        if (ras == null) {
+            // Clearing entry...
+            Object o = rasters.remove(pt);
+            if (o != null)
+                cache.remove((TileMapLRUMember)o);
+            return;
+        }
+
+        Object o = rasters.get(pt);
+        TileMapLRUMember item;
+        if (o == null) {
+            item = new TileMapLRUMember(this, pt, ras);
+            rasters.put(pt, item);
+        } else {
+            item = (TileMapLRUMember)o;
+            item.setRaster(ras);
+        }
+
+        cache.add(item);
+        if (DEBUG) System.out.println("Setting: (" + x + ", " + y + ')' );
+    }
+
+    // Returns Raster if the tile is _currently_ in the cache.
+    // If it is not currently in the cache it returns null.
+    public Raster getTileNoCompute(int x, int y) {
+        Point pt = new Point(x, y);
+        Object o = rasters.get(pt);
+        if (o == null)
+            return null;
+
+        TileMapLRUMember item = (TileMapLRUMember)o;
+        Raster ret = item.retrieveRaster();
+        if (ret != null)
+            cache.add(item);
+        return ret;
+    }
+
+    public Raster getTile(int x, int y) {
+        if (DEBUG) System.out.println("Fetching: (" + (x) + ", " +
+                                      (y) + ')' );
+        if (COUNT) synchronized (TileMap.class) { requests++; }
+
+        Raster       ras  = null;
+        Point pt = new Point(x, y);
+        Object o = rasters.get(pt);
+        TileMapLRUMember item = null;
+        if (o != null) {
+            item = (TileMapLRUMember)o;
+            ras = item.retrieveRaster();
+        }
+
+        if (ras == null) {
+            if (DEBUG) System.out.println("Generating: ("+(x)+", "+
+                                          (y) + ")");
+            if (COUNT) synchronized (TileMap.class) { misses++; }
+            ras = source.genTile(x, y);
+
+            // In all likelyhood the contents of this tile is junk!
+            // So don't cache it (returning is probably fine since it
+            // shouldn't come back to haunt us...)
+            if (HaltingThread.hasBeenHalted())
+                return ras;
+
+            if (item != null)
+                item.setRaster(ras);
+            else  {
+                item = new TileMapLRUMember(this, pt, ras);
+                rasters.put(pt, item);
+            }
+        }
+
+        // Update the item's position in the cache..
+        cache.add(item);
+
+        return ras;
+    }
+
+    static int requests;
+    static int misses;
+}

Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/TileMap.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message