You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cf...@apache.org on 2012/10/25 21:01:49 UTC

svn commit: r1402274 [26/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...

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/BumpMap.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/BumpMap.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/BumpMap.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/BumpMap.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,493 @@
+/*
+
+   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.DataBufferInt;
+import java.awt.image.Raster;
+import java.awt.image.RenderedImage;
+import java.awt.image.SinglePixelPackedSampleModel;
+
+/**
+ * Default BumpMap implementation.
+ *
+ * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
+ * @version $Id: BumpMap.java 501495 2007-01-30 18:00:36Z dvholten $
+ */
+public final class BumpMap {
+    /**
+     * Image whose alpha channel is used for the
+     * normal calculation
+     */
+    private RenderedImage texture;
+
+    /**
+     * Surface scale used in the normal computation
+     */
+    private double surfaceScale, surfaceScaleX, surfaceScaleY;
+
+    /**
+     * User space to device space scale factors
+     */
+    private double scaleX, scaleY;
+
+    /**
+     * Stores the normals for this bumpMap.
+     * scaleX and scaleY are the user space to device
+     * space scales.
+     */
+    public BumpMap(RenderedImage texture,
+                   double surfaceScale,
+                   double scaleX, double scaleY){
+        this.texture = texture;
+        this.surfaceScaleX = surfaceScale*scaleX;
+        this.surfaceScaleY = surfaceScale*scaleY;
+        this.surfaceScale = surfaceScale;
+        this.scaleX = scaleX;
+        this.scaleY = scaleY;
+    }
+
+    /**
+     * @return surface scale used by this bump map.
+     */
+    public double getSurfaceScale(){
+        return surfaceScale;
+    }
+
+    /**
+     * @param x x-axis coordinate for which the normal is computed
+     * @param y y-axis coordinate for which the normal is computed
+     */
+    public double[][][] getNormalArray
+        (final int x, final int y,
+         final int w, final int h)
+    {
+        final double[][][] N = new double[h][w][4];
+
+        Rectangle srcRect = new Rectangle(x-1, y-1, w+2, h+2);
+        Rectangle srcBound = new Rectangle
+            (texture.getMinX(), texture.getMinY(),
+             texture.getWidth(), texture.getHeight());
+
+        if ( ! srcRect.intersects(srcBound) )
+            return N;
+
+        srcRect = srcRect.intersection(srcBound);
+        final Raster r = texture.getData(srcRect);
+
+        srcRect = r.getBounds();
+
+        // System.out.println("SrcRect: " + srcRect);
+        // System.out.println("rect: [" +
+        //                    x + ", " + y + ", " +
+        //                    w + ", " + h + "]");
+
+        final DataBufferInt db = (DataBufferInt)r.getDataBuffer();
+
+
+        final int[] pixels = db.getBankData()[0];
+
+        final SinglePixelPackedSampleModel sppsm;
+        sppsm = (SinglePixelPackedSampleModel)r.getSampleModel();
+
+
+        final int scanStride = sppsm.getScanlineStride();
+        final int scanStridePP = scanStride + 1;
+        final int scanStrideMM = scanStride - 1;
+        double prpc=0, prcc=0, prnc=0;
+        double crpc=0, crcc=0, crnc=0;
+        double nrpc=0, nrcc=0, nrnc=0;
+        double invNorm;
+
+        final double quarterSurfaceScaleX = surfaceScaleX / 4f;
+        final double quarterSurfaceScaleY = surfaceScaleY / 4f;
+        final double halfSurfaceScaleX = surfaceScaleX / 2f;
+        final double halfSurfaceScaleY = surfaceScaleY /2;
+        final double thirdSurfaceScaleX = surfaceScaleX / 3f;
+        final double thirdSurfaceScaleY = surfaceScaleY / 3f;
+        final double twoThirdSurfaceScaleX = surfaceScaleX * 2 / 3f;
+        final double twoThirdSurfaceScaleY = surfaceScaleY * 2 / 3f;
+
+        final double pixelScale = 1.0/255;
+
+        if(w <= 0)
+            return N;
+        // Process pixels on the border
+        if(h <= 0)
+            return N;
+
+        final int xEnd   = Math.min(srcRect.x+srcRect.width -1, x+w);
+        final int yEnd   = Math.min(srcRect.y+srcRect.height-1, y+h);
+        final int offset =
+            (db.getOffset() +
+             sppsm.getOffset(srcRect.x -r.getSampleModelTranslateX(),
+                             srcRect.y -r.getSampleModelTranslateY()));
+
+        int yloc=y;
+        if (yloc < srcRect.y) {
+            yloc = srcRect.y;
+        }
+
+        // Top edge extend filters...
+        if (yloc == srcRect.y) {
+            if (yloc == yEnd) {
+                // Only one row of pixels...
+                final double [][] NRow = N[yloc-y];
+                int xloc=x;
+                if (xloc < srcRect.x)
+                    xloc = srcRect.x;
+                int p  = (offset + (xloc-srcRect.x) +
+                          scanStride*(yloc-srcRect.y));
+
+                crcc = (pixels[p] >>> 24)*pixelScale;
+
+                if (xloc != srcRect.x) {
+                    crpc = (pixels[p - 1] >>> 24)*pixelScale;
+                }
+                else if (xloc < xEnd) {
+                    // Top left pixel, in src (0, 0);
+                    crnc = (pixels[p+1] >>> 24)*pixelScale;
+
+                    final double [] n = NRow[xloc-x];
+
+                    n[0] = 2*surfaceScaleX*(crcc - crnc);
+                    invNorm = 1.0/Math.sqrt(n[0]*n[0] + 1);
+                    n[0] *= invNorm;
+                    n[1]  = 0;
+                    n[2]  = invNorm;
+                    n[3]  = crcc*surfaceScale;
+                    p++;
+                    xloc++;
+                    crpc = crcc;
+                    crcc = crnc;
+                } else {
+                    // Single pix.
+                    crpc = crcc;
+                }
+
+                for (; xloc<xEnd; xloc++) {
+                    // Middle Top row...
+                    crnc = (pixels[p+1] >>> 24)*pixelScale;
+                    final double [] n = NRow[xloc-x];
+
+                    n[0] = surfaceScaleX * (crpc - crnc );
+                    invNorm = 1.0/Math.sqrt(n[0]*n[0] + 1);
+                    n[0] *= invNorm;
+                    n[1]  = 0;
+                    n[2]  = invNorm;
+                    n[3]  = crcc*surfaceScale;
+                    p++;
+                    crpc = crcc;
+                    crcc = crnc;
+                }
+
+                if ((xloc < x+w) &&
+                    (xloc == srcRect.x+srcRect.width-1)) {
+                    // Last pixel of top row
+                    final double [] n = NRow[xloc-x];
+
+                    n[0] = 2*surfaceScaleX*(crpc - crcc);
+                    invNorm = 1.0/Math.sqrt(n[0]*n[0] + n[1]*n[1] + 1);
+                    n[0] *= invNorm;
+                    n[1] *= invNorm;
+                    n[2]  = invNorm;
+                    n[3]  = crcc*surfaceScale;
+                }
+                return N;
+            }
+
+            final double [][] NRow = N[yloc-y];
+            int p  = offset + scanStride*(yloc-srcRect.y);
+            int xloc=x;
+            if (xloc < srcRect.x)
+                xloc = srcRect.x;
+            p += xloc-srcRect.x;
+
+            crcc = (pixels[p] >>> 24)*pixelScale;
+            nrcc = (pixels[p + scanStride] >>> 24)*pixelScale;
+
+            if (xloc != srcRect.x) {
+                crpc = (pixels[p - 1] >>> 24)*pixelScale;
+                nrpc = (pixels[p + scanStrideMM] >>> 24)*pixelScale;
+            }
+            else if (xloc < xEnd) {
+                // Top left pixel, in src (0, 0);
+                crnc = (pixels[p+1] >>> 24)*pixelScale;
+                nrnc = (pixels[p + scanStridePP] >>> 24)*pixelScale;
+
+                final double [] n = NRow[xloc-x];
+
+                n[0] = - twoThirdSurfaceScaleX *
+                    ((2*crnc + nrnc - 2*crcc - nrcc));
+                n[1] = - twoThirdSurfaceScaleY *
+                    ((2*nrcc + nrnc - 2*crcc - crnc));
+                invNorm = 1.0/Math.sqrt(n[0]*n[0] + n[1]*n[1] + 1);
+                n[0] *= invNorm;
+                n[1] *= invNorm;
+                n[2]  = invNorm;
+                n[3]  = crcc*surfaceScale;
+                p++;
+                xloc++;
+                crpc = crcc;
+                nrpc = nrcc;
+                crcc = crnc;
+                nrcc = nrnc;
+            } else {
+                // Single pix
+                crpc = crcc;
+                nrpc = nrcc;
+            }
+
+            for (; xloc<xEnd; xloc++) {
+                // Middle Top row...
+                crnc = (pixels[p+1] >>> 24)*pixelScale;
+                nrnc = (pixels[p + scanStridePP] >>> 24)*pixelScale;
+
+                final double [] n = NRow[xloc-x];
+
+                n[0] = - thirdSurfaceScaleX * (( 2*crnc + nrnc)
+                                               - (2*crpc + nrpc));
+                n[1] = - halfSurfaceScaleY *(( nrpc + 2*nrcc + nrnc)
+                                             - (crpc + 2*crcc + crnc));
+
+                invNorm = 1.0/Math.sqrt(n[0]*n[0] + n[1]*n[1] + 1);
+                n[0] *= invNorm;
+                n[1] *= invNorm;
+                n[2]  = invNorm;
+                n[3]  = crcc*surfaceScale;
+                p++;
+                crpc = crcc;
+                nrpc = nrcc;
+                crcc = crnc;
+                nrcc = nrnc;
+            }
+
+            if ((xloc < x+w) &&
+                (xloc == srcRect.x+srcRect.width-1)) {
+                // Last pixel of top row
+                final double [] n = NRow[xloc-x];
+
+                n[0] = - twoThirdSurfaceScaleX *(( 2*crcc + nrcc)
+                                                 - (2*crpc + nrpc));
+                n[1] = - twoThirdSurfaceScaleY *(( 2*nrcc + nrpc)
+                                                 - (2*crcc + crpc));
+
+                invNorm = 1.0/Math.sqrt(n[0]*n[0] + n[1]*n[1] + 1);
+                n[0] *= invNorm;
+                n[1] *= invNorm;
+                n[2]  = invNorm;
+                n[3]  = crcc*surfaceScale;
+            }
+            yloc++;
+        }
+
+        for (; yloc<yEnd; yloc++) {
+            final double [][] NRow = N[yloc-y];
+            int p  = offset + scanStride*(yloc-srcRect.y);
+
+            int xloc=x;
+            if (xloc < srcRect.x)
+                xloc = srcRect.x;
+
+            p += xloc-srcRect.x;
+
+            prcc = (pixels[p - scanStride] >>> 24)*pixelScale;
+            crcc = (pixels[p] >>> 24)*pixelScale;
+            nrcc = (pixels[p + scanStride] >>> 24)*pixelScale;
+
+            if (xloc != srcRect.x) {
+                prpc = (pixels[p - scanStridePP] >>> 24)*pixelScale;
+                crpc = (pixels[p - 1] >>> 24)*pixelScale;
+                nrpc = (pixels[p + scanStrideMM] >>> 24)*pixelScale;
+            }
+            else if (xloc < xEnd) {
+                // Now, process left column, from (0, 1) to (0, h-1)
+                crnc = (pixels[p+1] >>> 24)*pixelScale;
+                prnc = (pixels[p - scanStrideMM] >>> 24)*pixelScale;
+                nrnc = (pixels[p + scanStridePP] >>> 24)*pixelScale;
+
+                final double [] n = NRow[xloc-x];
+
+                n[0] = - halfSurfaceScaleX *(( prnc + 2*crnc + nrnc)
+                                             - (prcc + 2*crcc + nrcc));
+                n[1] = - thirdSurfaceScaleY *(( 2*prcc + prnc)
+                                              - ( 2*crcc + crnc));
+
+                invNorm = 1.0/Math.sqrt(n[0]*n[0] + n[1]*n[1] + 1);
+                n[0] *= invNorm;
+                n[1] *= invNorm;
+                n[2]  = invNorm;
+                n[3]  = crcc*surfaceScale;
+
+                p++;
+                xloc++;
+
+                prpc = prcc;
+                crpc = crcc;
+                nrpc = nrcc;
+                prcc = prnc;
+                crcc = crnc;
+                nrcc = nrnc;
+            } else {
+                // Single pix
+                prpc = prcc;
+                crpc = crcc;
+                nrpc = nrcc;
+            }
+
+            for (; xloc<xEnd; xloc++) {
+                // Middle Middle row...
+                prnc = (pixels[p - scanStrideMM] >>> 24)*pixelScale;
+                crnc = (pixels[p+1] >>> 24)*pixelScale;
+                nrnc = (pixels[p + scanStridePP] >>> 24)*pixelScale;
+
+                final double [] n = NRow[xloc-x];
+
+                n[0] = - quarterSurfaceScaleX *(( prnc + 2*crnc + nrnc)
+                                                - (prpc + 2*crpc + nrpc));
+                n[1] = - quarterSurfaceScaleY *(( nrpc + 2*nrcc + nrnc)
+                                                - (prpc + 2*prcc + prnc));
+
+                invNorm = 1.0/Math.sqrt(n[0]*n[0] + n[1]*n[1] + 1);
+                n[0] *= invNorm;
+                n[1] *= invNorm;
+                n[2]  = invNorm;
+                n[3]  = crcc*surfaceScale;
+
+                p++;
+                prpc = prcc;
+                crpc = crcc;
+                nrpc = nrcc;
+                prcc = prnc;
+                crcc = crnc;
+                nrcc = nrnc;
+            }
+
+            if ((xloc < x+w) &&
+                (xloc == srcRect.x+srcRect.width-1)) {
+                // Now, proces right column, from (w-1, 1) to (w-1, h-1)
+                final double [] n = NRow[xloc-x];
+
+                n[0] = - halfSurfaceScaleX *( (prcc + 2*crcc + nrcc)
+                                             -(prpc + 2*crpc + nrpc));
+                n[1] = - thirdSurfaceScaleY *(( nrpc + 2*nrcc)
+                                              - ( prpc + 2*prcc));
+
+                invNorm = 1.0/Math.sqrt(n[0]*n[0] + n[1]*n[1] + 1);
+                n[0] *= invNorm;
+                n[1] *= invNorm;
+                n[2]  = invNorm;
+                n[3]  = crcc*surfaceScale;
+            }
+        }
+
+        if ((yloc < y+h) &&
+            (yloc == srcRect.y+srcRect.height-1)) {
+            final double [][] NRow = N[yloc-y];
+            int p  = offset + scanStride*(yloc-srcRect.y);
+            int xloc=x;
+            if (xloc < srcRect.x)
+                xloc = srcRect.x;
+
+            p += xloc-srcRect.x;
+
+            crcc = (pixels[p] >>> 24)*pixelScale;
+            prcc = (pixels[p - scanStride] >>> 24)*pixelScale;
+
+            if (xloc != srcRect.x) {
+                prpc = (pixels[p - scanStridePP] >>> 24)*pixelScale;
+                crpc = (pixels[p - 1] >>> 24)*pixelScale;
+            }
+            else if (xloc < xEnd) {
+                // Process first pixel of last row
+                crnc = (pixels[p + 1] >>> 24)*pixelScale;
+                prnc = (pixels[p - scanStrideMM] >>> 24)*pixelScale;
+
+                final double [] n = NRow[xloc-x];
+
+                n[0] = - twoThirdSurfaceScaleX * ((2*crnc + prnc - 2*crcc - prcc));
+                n[1] = - twoThirdSurfaceScaleY * ((2*crcc + crnc - 2*prcc - prnc));
+                invNorm = 1.0/Math.sqrt(n[0]*n[0] + n[1]*n[1] + 1);
+                n[0] *= invNorm;
+                n[1] *= invNorm;
+                n[2]  = invNorm;
+                n[3]  = crcc*surfaceScale;
+
+                p++;
+                xloc++;
+                crpc = crcc;
+                prpc = prcc;
+                crcc = crnc;
+                prcc = prnc;
+            } else {
+                // Single pix
+                crpc = crcc;
+                prpc = prcc;
+            }
+
+            for (; xloc<xEnd; xloc++) {
+                // Middle of Bottom row...
+                crnc = (pixels[p + 1] >>> 24)*pixelScale;
+                prnc = (pixels[p - scanStrideMM] >>> 24)*pixelScale;
+
+                // System.out.println("Vals: " +
+                //                    prpc + "," + prcc + "," + prnc + "  " +
+                //                    crpc + "," + crcc + "," + crnc );
+
+                final double [] n = NRow[xloc-x];
+
+                n[0] = - thirdSurfaceScaleX *(( 2*crnc + prnc)
+                                              - (2*crpc + prpc));
+                n[1] = - halfSurfaceScaleY *(( crpc + 2*crcc + crnc)
+                                             - (prpc + 2*prcc + prnc));
+
+                invNorm = 1.0/Math.sqrt(n[0]*n[0] + n[1]*n[1] + 1);
+                n[0] *= invNorm;
+                n[1] *= invNorm;
+                n[2]  = invNorm;
+                n[3]  = crcc*surfaceScale;
+
+                p++;
+                crpc = crcc;
+                prpc = prcc;
+                crcc = crnc;
+                prcc = prnc;
+            }
+
+            if ((xloc < x+w) &&
+                (xloc == srcRect.x+srcRect.width-1)) {
+                // Bottom right corner
+                final double [] n = NRow[xloc-x];
+
+                n[0] = - twoThirdSurfaceScaleX *(( 2*crcc + prcc)
+                                                 - (2*crpc + prpc));
+                n[1] = - twoThirdSurfaceScaleY *(( 2*crcc + crpc)
+                                                 - (2*prcc + prpc));
+
+                invNorm = 1.0/Math.sqrt(n[0]*n[0] + n[1]*n[1] + 1);
+                n[0] *= invNorm;
+                n[1] *= invNorm;
+                n[2]  = invNorm;
+                n[3]  = crcc*surfaceScale;
+            }
+        }
+        return N;
+    }
+}
+

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

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/CachableRed.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/CachableRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/CachableRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/CachableRed.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,65 @@
+/*
+
+   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.RenderedImage;
+
+/**
+ * This provides a number of extra methods that enable a system to
+ * better analyse the dependencies between nodes in a render graph.
+ *
+ * @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
+ * @version $Id: CachableRed.java 478276 2006-11-22 18:33:37Z dvholten $
+*/
+public interface CachableRed extends RenderedImage {
+
+    /**
+     * Returns the bounds of the current image.
+     * This should be 'in sync' with getMinX, getMinY, getWidth, getHeight
+     */
+    Rectangle getBounds();
+
+    /**
+     * Returns the region of input data is is required to generate
+     * outputRgn.
+     * @param srcIndex  The source to do the dependency calculation for.
+     * @param outputRgn The region of output you are interested in
+     * generating dependencies for.  The is given in the output pixel
+     * coordiate system for this node.
+     * @return The region of input required.  This is in the output pixel
+     * coordinate system for the source indicated by srcIndex.
+     */
+    Shape getDependencyRegion(int srcIndex, Rectangle outputRgn);
+
+    /**
+     * This calculates the region of output that is affected by a change
+     * in a region of input.
+     * @param srcIndex The input that inputRgn reflects changes in.
+     * @param inputRgn the region of input that has changed, used to
+     *  calculate the returned shape.  This is given in the pixel
+     *  coordinate system of the source indicated by srcIndex.
+     * @return The region of output that would be invalid given
+     *  a change to inputRgn of the source selected by srcIndex.
+     *  this is in the output pixel coordinate system of this node.
+     */
+    Shape getDirtyRegion(int srcIndex, Rectangle inputRgn);
+}
+

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

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ColorMatrixRed.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/ColorMatrixRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ColorMatrixRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ColorMatrixRed.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,204 @@
+/*
+
+   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.color.ColorSpace;
+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;
+
+/**
+ *
+ * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
+ * @version $Id: ColorMatrixRed.java 479564 2006-11-27 09:56:57Z dvholten $
+ */
+public class ColorMatrixRed extends AbstractRed{
+    /**
+     * Matrix to apply to color components
+     */
+    private float[][] matrix;
+
+    public float[][] getMatrix(){
+        return copyMatrix(matrix);
+    }
+
+    public void setMatrix(float[][] matrix){
+        float[][] tmp = copyMatrix(matrix);
+
+        if(tmp == null){
+            throw new IllegalArgumentException();
+        }
+
+        if(tmp.length != 4){
+            throw new IllegalArgumentException();
+        }
+
+        for(int i=0; i<4; i++){
+            if(tmp[i].length != 5){
+                throw new IllegalArgumentException( String.valueOf( i ) + " : " + tmp[i].length);
+            }
+        }
+        this.matrix = matrix;
+    }
+
+    private float[][] copyMatrix(float[][] m){
+        if(m == null){
+            return null;
+        }
+
+        float[][] cm = new float[m.length][];
+        for(int i=0; i<m.length; i++){
+            if(m[i] != null){
+                cm[i] = new float[m[i].length];
+                System.arraycopy(m[i], 0, cm[i], 0, m[i].length);
+            }
+        }
+
+        return cm;
+    }
+
+    public ColorMatrixRed(CachableRed src, float[][] matrix){
+        setMatrix(matrix);
+
+        ColorModel srcCM = src.getColorModel();
+        ColorSpace srcCS = null;
+        if (srcCM != null)
+            srcCS = srcCM.getColorSpace();
+        ColorModel cm;
+        if (srcCS == null)
+            cm = GraphicsUtil.Linear_sRGB_Unpre;
+        else {
+            if (srcCS == ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB))
+                cm = GraphicsUtil.Linear_sRGB_Unpre;
+            else
+                cm = GraphicsUtil.sRGB_Unpre;
+        }
+
+        SampleModel sm =
+            cm.createCompatibleSampleModel(src.getWidth(),
+                                           src.getHeight());
+
+        init(src, src.getBounds(), cm, sm,
+             src.getTileGridXOffset(), src.getTileGridYOffset(), null);
+    }
+
+
+    public WritableRaster copyData(WritableRaster wr){
+        //System.out.println("Getting data for : " + wr.getWidth() + "/" + wr.getHeight() + "/" + wr.getMinX() + "/" + wr.getMinY());
+
+        //
+        // First, get source data
+        //
+        CachableRed src = (CachableRed)getSources().get(0);
+        // System.out.println("Hello");
+        // System.out.println("src class : " + src.getClass().getName());
+        // System.out.println("this : " + this);
+        wr = src.copyData(wr);
+        // System.out.println("Hi");
+        //System.out.println("Source was : " + wr.getWidth() + "/" + wr.getHeight()+ "/" + wr.getMinX() + "/" + wr.getMinY());
+
+        // Unpremultiply data if required
+        ColorModel cm = src.getColorModel();
+        GraphicsUtil.coerceData(wr, cm, false);
+
+        //
+        // Now, process pixel values
+        //
+        final int minX = wr.getMinX();
+        final int minY = wr.getMinY();
+        final int w = wr.getWidth();
+        final int h = wr.getHeight();
+        DataBufferInt dbf = (DataBufferInt)wr.getDataBuffer();
+        final int[] pixels = dbf.getBankData()[0];
+
+        SinglePixelPackedSampleModel sppsm;
+        sppsm = (SinglePixelPackedSampleModel)wr.getSampleModel();
+
+        final int offset =
+            (dbf.getOffset() +
+             sppsm.getOffset(minX-wr.getSampleModelTranslateX(),
+                             minY-wr.getSampleModelTranslateY()));
+
+        // final int offset = dbf.getOffset();
+
+        final int scanStride =
+            ((SinglePixelPackedSampleModel)wr.getSampleModel())
+            .getScanlineStride();
+        final int adjust = scanStride - w;
+        int p = offset;
+        int i=0, j=0;
+
+        final float a00=matrix[0][0]/255f, a01=matrix[0][1]/255f, a02=matrix[0][2]/255f, a03=matrix[0][3]/255f, a04=matrix[0][4]/255f;
+        final float a10=matrix[1][0]/255f, a11=matrix[1][1]/255f, a12=matrix[1][2]/255f, a13=matrix[1][3]/255f, a14=matrix[1][4]/255f;
+        final float a20=matrix[2][0]/255f, a21=matrix[2][1]/255f, a22=matrix[2][2]/255f, a23=matrix[2][3]/255f, a24=matrix[2][4]/255f;
+        final float a30=matrix[3][0]/255f, a31=matrix[3][1]/255f, a32=matrix[3][2]/255f, a33=matrix[3][3]/255f, a34=matrix[3][4]/255f;
+
+        for(i=0; i<h; i++){
+            for(j=0; j<w; j++){
+                int pel = pixels[p];
+
+                int a = pel >>> 24;
+                int r = (pel >> 16) & 0xff;
+                int g = (pel >> 8 ) & 0xff;
+                int b =  pel        & 0xff;
+
+                int dr = (int)((a00*r + a01*g + a02*b + a03*a + a04)*255.0f);
+                int dg = (int)((a10*r + a11*g + a12*b + a13*a + a14)*255.0f);
+                int db = (int)((a20*r + a21*g + a22*b + a23*a + a24)*255.0f);
+                int da = (int)((a30*r + a31*g + a32*b + a33*a + a34)*255.0f);
+
+                /*dr = dr > 255 ? 255 : dr < 0 ? 0 : dr;
+                dg = dg > 255 ? 255 : dg < 0 ? 0 : dg;
+                db = db > 255 ? 255 : db < 0 ? 0 : db;
+                da = da > 255 ? 255 : da < 0 ? 0 : da;*/
+
+
+                // If any high bits are set we are not in range.
+                // If the highest bit is set then we are negative so
+                // clamp to zero else we are > 255 so clamp to 255.
+                if ((dr & 0xFFFFFF00) != 0)
+                    dr = ((dr & 0x80000000) != 0)?0:255;
+                if ((dg & 0xFFFFFF00) != 0)
+                    dg = ((dg & 0x80000000) != 0)?0:255;
+                if ((db & 0xFFFFFF00) != 0)
+                    db = ((db & 0x80000000) != 0)?0:255;
+                if ((da & 0xFFFFFF00) != 0)
+                    da = ((da & 0x80000000) != 0)?0:255;
+
+                pixels[p++] = (da << 24
+                               |
+                               dr << 16
+                               |
+                               dg << 8
+                               |
+                               db);
+
+            }
+            p += adjust;
+        }
+
+        //System.out.println("Result is : " + wr.getWidth() + "/" + wr.getHeight()+ "/" + wr.getMinX() + "/" + wr.getMinY());
+        return wr;
+    }
+
+}

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

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ComponentTransferRed.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/ComponentTransferRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ComponentTransferRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/ComponentTransferRed.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.RenderingHints;
+import java.awt.image.ByteLookupTable;
+import java.awt.image.LookupOp;
+import java.awt.image.WritableRaster;
+
+import org.apache.flex.forks.batik.ext.awt.image.GraphicsUtil;
+import org.apache.flex.forks.batik.ext.awt.image.TransferFunction;
+
+/**
+ *
+ * @author <a href="mailto:thomas.deweese@kodak.com">Thomas DeWeese</a>
+ * @version $Id: ComponentTransferRed.java 479564 2006-11-27 09:56:57Z dvholten $
+ */
+public class ComponentTransferRed extends AbstractRed {
+    LookupOp operation;
+
+    /**
+     * The constructor will instantiate a LookupOp instance using
+     * a LookupOp, which is built using the four LUT
+     * data obtained by the TransferFunction objects
+     * funcs[0] : Alpha component transfer function
+     * funcs[1] : Red component transfer function
+     * funcs[2] : Green component transfer function
+     * funcs[3] : Blue component transfer function
+     */
+    public ComponentTransferRed(CachableRed src,
+                                TransferFunction [] funcs,
+                                RenderingHints hints) {
+        super(src, src.getBounds(),
+              GraphicsUtil.coerceColorModel(src.getColorModel(), false),
+              src.getSampleModel(),
+              null);
+
+        byte [][] tableData = {funcs[1].getLookupTable(),
+                               funcs[2].getLookupTable(),
+                               funcs[3].getLookupTable(),
+                               funcs[0].getLookupTable()};
+
+        // Note that we create an anonymous subclass here.
+        // For what ever reason this makes the Op work correctly.
+        // If you remove this, it seems to get the color channels messed
+        // up.  The downside is that I suspect that this means we are
+        // falling into a more general, and hence slower case, but
+        // at least it works....
+        operation  =  new LookupOp(new ByteLookupTable(0, tableData), hints)
+            { };
+    }
+
+    public WritableRaster copyData(WritableRaster wr){
+        CachableRed src = (CachableRed)getSources().get(0);
+
+        wr = src.copyData(wr);
+        GraphicsUtil.coerceData(wr, src.getColorModel(), false);
+
+        WritableRaster srcWR = wr.createWritableTranslatedChild(0,0);
+
+        operation.filter(srcWR, srcWR);
+
+        return wr;
+    }
+}

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

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/CompositeRed.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/CompositeRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/CompositeRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/CompositeRed.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,310 @@
+/*
+
+   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.CompositeContext;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.color.ColorSpace;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.DirectColorModel;
+import java.awt.image.Raster;
+import java.awt.image.SampleModel;
+import java.awt.image.WritableRaster;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.flex.forks.batik.ext.awt.image.CompositeRule;
+import org.apache.flex.forks.batik.ext.awt.image.GraphicsUtil;
+import org.apache.flex.forks.batik.ext.awt.image.PadMode;
+import org.apache.flex.forks.batik.ext.awt.image.SVGComposite;
+
+/**
+ * This is an implementation of an affine operation as a RenderedImage.
+ * Right now the implementation makes use of the AffineBufferedImageOp
+ * to do the work.  Eventually this may move to be more tiled in nature.
+ *
+ * @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
+ * @version $Id: CompositeRed.java 489226 2006-12-21 00:05:36Z cam $
+ */
+public class CompositeRed extends AbstractRed {
+
+    CompositeRule rule;
+    CompositeContext [] contexts;
+
+    public CompositeRed(List srcs, CompositeRule rule) {
+        super(); // We _must_ call init...
+
+        CachableRed src = (CachableRed)srcs.get(0);
+
+        ColorModel  cm = fixColorModel (src);
+
+        this.rule = rule;
+
+        SVGComposite comp = new SVGComposite(rule);
+        contexts = new CompositeContext[srcs.size()];
+
+        int idx = 0;
+        Iterator i = srcs.iterator();
+        Rectangle myBounds = null;
+        while (i.hasNext()) {
+            CachableRed cr = (CachableRed)i.next();
+
+            contexts[idx++] = comp.createContext(cr.getColorModel(), cm, null);
+
+            Rectangle newBound = cr.getBounds();
+            if (myBounds == null) {
+                myBounds = newBound;
+                continue;
+            }
+
+            switch (rule.getRule()) {
+            case CompositeRule.RULE_IN:
+                if (myBounds.intersects(newBound))
+                    myBounds = myBounds.intersection(newBound);
+                else {
+                    myBounds.width = 0;
+                    myBounds.height = 0;
+                }
+                break;
+            case CompositeRule.RULE_OUT:
+                // Last node determines bounds...
+                myBounds = newBound;
+                break;
+            default:
+                // myBounds= myBounds.union(newBound);
+                myBounds.add( newBound );
+            }
+        }
+
+        if (myBounds == null)
+            throw new IllegalArgumentException
+                ("Composite Operation Must have some source!");
+
+        if (rule.getRule() == CompositeRule.RULE_ARITHMETIC) {
+            List vec = new ArrayList( srcs.size() );
+            i = srcs.iterator();
+            while (i.hasNext()) {
+                CachableRed cr = (CachableRed)i.next();
+                Rectangle r = cr.getBounds();
+                // For arithmetic make sure they are all the same size...
+                if ((r.x      != myBounds.x) ||
+                    (r.y      != myBounds.y) ||
+                    (r.width  != myBounds.width) ||
+                    (r.height != myBounds.height))
+                    cr = new PadRed(cr, myBounds, PadMode.ZERO_PAD, null);
+                vec.add(cr);
+            }
+            srcs = vec;
+        }
+
+        // fix my sample model so it makes sense given my size.
+        SampleModel sm = fixSampleModel(src, cm, myBounds);
+
+        // System.out.println("Comp: " + myBounds);
+        // System.out.println("  SM: " + sm.getWidth()+"x"+sm.getHeight());
+
+        int defSz = AbstractTiledRed.getDefaultTileSize();
+
+        // Make tile(0,0) fall on the closest intersection of defaultSz.
+        int tgX = defSz*(int)Math.floor(myBounds.x/defSz);
+        int tgY = defSz*(int)Math.floor(myBounds.y/defSz);
+
+        // Finish initializing our base class...
+        init(srcs, myBounds, cm, sm, tgX, tgY, null);
+    }
+
+    public WritableRaster copyData(WritableRaster wr) {
+        // copyToRaster(wr);
+        genRect(wr);
+        return wr;
+    }
+
+    public Raster getTile(int x, int y) {
+        int tx = tileGridXOff+x*tileWidth;
+        int ty = tileGridYOff+y*tileHeight;
+        Point pt = new Point(tx, ty);
+        WritableRaster wr = Raster.createWritableRaster(sm, pt);
+        genRect(wr);
+
+        return wr;
+    }
+
+    public void emptyRect(WritableRaster wr) {
+        PadRed.ZeroRecter zr = PadRed.ZeroRecter.getZeroRecter(wr);
+        zr.zeroRect(new Rectangle(wr.getMinX(), wr.getMinY(),
+                                  wr.getWidth(), wr.getHeight()));
+    }
+
+    public void genRect(WritableRaster wr) {
+        // long startTime = System.currentTimeMillis();
+        // System.out.println("Comp GenR: " + wr);
+        Rectangle r = wr.getBounds();
+
+        int idx = 0;
+        Iterator i = srcs.iterator();
+        boolean first = true;
+        while (i.hasNext()) {
+            CachableRed cr = (CachableRed)i.next();
+            if (first) {
+                Rectangle crR = cr.getBounds();
+                if ((r.x < crR.x)                   ||
+                    (r.y < crR.y)                   ||
+                    (r.x+r.width > crR.x+crR.width) ||
+                    (r.y+r.height > crR.y+crR.height))
+                    // Portions outside my bounds, zero them...
+                    emptyRect(wr);
+
+                // Fill in initial image...
+                cr.copyData(wr);
+
+                if ( ! cr.getColorModel().isAlphaPremultiplied() )
+                    GraphicsUtil.coerceData(wr, cr.getColorModel(), true);
+                first = false;
+            } else {
+                Rectangle crR = cr.getBounds();
+                if (crR.intersects(r)) {
+                    Rectangle smR = crR.intersection(r);
+                    Raster ras = cr.getData(smR);
+                    WritableRaster smWR = wr.createWritableChild
+                        (smR.x, smR.y, smR.width, smR.height,
+                         smR.x, smR.y, null);
+
+                    contexts[idx].compose(ras, smWR, smWR);
+                }
+            }
+
+            idx++;
+        }
+        // long endTime = System.currentTimeMillis();
+        // System.out.println("Other: " + (endTime-startTime));
+    }
+
+    // This is an alternate Implementation that uses drawImage.
+    // In testing this was not significantly faster and it had some
+    // problems with alpha premultiplied.
+    public void genRect_OVER(WritableRaster wr) {
+        // long startTime = System.currentTimeMillis();
+        // System.out.println("Comp GenR: " + wr);
+        Rectangle r = wr.getBounds();
+
+        ColorModel cm = getColorModel();
+
+        BufferedImage bi = new BufferedImage
+            (cm, wr.createWritableTranslatedChild(0,0),
+             cm.isAlphaPremultiplied(), null);
+
+        Graphics2D g2d = GraphicsUtil.createGraphics(bi);
+        g2d.translate(-r.x, -r.y);
+
+        Iterator i = srcs.iterator();
+        boolean first = true;
+        while (i.hasNext()) {
+            CachableRed cr = (CachableRed)i.next();
+            if (first) {
+                Rectangle crR = cr.getBounds();
+                if ((r.x < crR.x)                   ||
+                    (r.y < crR.y)                   ||
+                    (r.x+r.width > crR.x+crR.width) ||
+                    (r.y+r.height > crR.y+crR.height))
+                    // Portions outside my bounds, zero them...
+                    emptyRect(wr);
+
+                // Fill in initial image...
+                cr.copyData(wr);
+
+                GraphicsUtil.coerceData(wr, cr.getColorModel(),
+                                        cm.isAlphaPremultiplied());
+                first = false;
+            } else {
+                GraphicsUtil.drawImage(g2d, cr);
+            }
+        }
+        // long endTime = System.currentTimeMillis();
+        // System.out.println("OVER: " + (endTime-startTime));
+    }
+
+        /**
+         * 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,
+                                                ColorModel  cm,
+                                                Rectangle   bounds) {
+        int defSz = AbstractTiledRed.getDefaultTileSize();
+
+        // Make tile(0,0) fall on the closest intersection of defaultSz.
+        int tgX = defSz*(int)Math.floor(bounds.x/defSz);
+        int tgY = defSz*(int)Math.floor(bounds.y/defSz);
+
+        int tw  = (bounds.x+bounds.width)-tgX;
+        int th  = (bounds.y+bounds.height)-tgY;
+
+        SampleModel sm = src.getSampleModel();
+
+        int  w  = sm.getWidth();
+        if (w < defSz) w = defSz;
+        if (w > tw)    w = tw;
+
+        int h   = sm.getHeight();
+        if (h < defSz) h = defSz;
+        if (h > th)    h = th;
+
+        if ((w <= 0) || (h <= 0)) {
+            w = 1;
+            h = 1;
+        }
+
+        // System.out.println("tg: " + tgX + "x" + tgY);
+        // System.out.println("t: " + tw + "x" + th);
+        // System.out.println("sz: " + w + "x" + h);
+
+        return cm.createCompatibleSampleModel(w, h);
+    }
+
+    protected static ColorModel fixColorModel(CachableRed src) {
+        ColorModel  cm = src.getColorModel();
+
+        if (cm.hasAlpha()) {
+            if (!cm.isAlphaPremultiplied())
+                cm = GraphicsUtil.coerceColorModel(cm, true);
+            return cm;
+        }
+
+        int b = src.getSampleModel().getNumBands()+1;
+        if (b > 4)
+            throw new IllegalArgumentException
+                ("CompositeRed can only handle up to three band images");
+
+        int [] masks = new int[4];
+        for (int i=0; i < b-1; i++)
+            masks[i] = 0xFF0000 >> (8*i);
+        masks[3] = 0xFF << (8*(b-1));
+        ColorSpace cs = cm.getColorSpace();
+
+        return new DirectColorModel(cs, 8*b, masks[0], masks[1],
+                                    masks[2], masks[3],
+                                    true, DataBuffer.TYPE_INT);
+    }
+}

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

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/DiffuseLightingRed.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/DiffuseLightingRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/DiffuseLightingRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/DiffuseLightingRed.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,213 @@
+/*
+
+   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;
+
+/**
+ * 
+ * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
+ * @version $Id: DiffuseLightingRed.java 475477 2006-11-15 22:44:28Z cam $
+ */
+public class DiffuseLightingRed extends AbstractRed{
+    /**
+     * Diffuse lighting constant
+     */
+    private double kd;
+
+    /**
+     * Light used for diffuse 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 DiffuseLightingRed(double kd,
+                              Light light,
+                              BumpMap bumpMap,
+                              Rectangle litRegion,
+                              double scaleX, double scaleY,
+                              boolean linear){
+        this.kd = kd;
+        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_Pre;
+        else
+            cm = GraphicsUtil.sRGB_Pre;
+
+        SampleModel sm = 
+            cm.createCompatibleSampleModel(litRegion.width,
+                                           litRegion.height);
+                                             
+        init((CachableRed)null, litRegion, cm, sm,
+             litRegion.x, litRegion.y, null);
+    }
+
+    public WritableRaster copyData(WritableRaster wr){
+        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()));
+
+        final int scanStride = sppsm.getScanlineStride();
+        final int adjust = scanStride - w;
+        int p = offset;
+        int r=0, g=0, b=0;
+        int i=0, j=0;
+
+        // System.out.println("Getting diffuse red : " + minX + "/" + minY + "/" + w + "/" + h);
+        double x = scaleX*minX;
+        double y = scaleY*minY;
+        double NL = 0;
+
+        // final double[] L = new double[3];
+        final double[][][] NA = bumpMap.getNormalArray(minX, minY, w, h);
+        if(!light.isConstant()){
+            final double[][] LA = new double[w][3];
+
+            for(i=0; i<h; 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];
+                    
+                    NL = 255.*kd*(N[0]*L[0] + N[1]*L[1] + N[2]*L[2]);
+                    
+                    r = (int)(NL*lightColor[0]);
+                    g = (int)(NL*lightColor[1]);
+                    b = (int)(NL*lightColor[2]);
+                    
+                    // If any high bits are set we are not in range.
+                    // If the highest bit is set then we are negative so
+                    // clamp to zero else we are > 255 so clamp to 255.
+                    if ((r & 0xFFFFFF00) != 0)
+                        r = ((r & 0x80000000) != 0)?0:255;
+                    if ((g & 0xFFFFFF00) != 0)
+                        g = ((g & 0x80000000) != 0)?0:255;
+                    if ((b & 0xFFFFFF00) != 0)
+                        b = ((b & 0x80000000) != 0)?0:255;
+                    
+                    pixels[p++] = (0xff000000
+                                   |
+                                   r << 16
+                                   |
+                                   g << 8
+                                   |
+                                   b);
+                    
+                }
+                p += adjust;
+            }
+        }
+        else{
+            // System.out.println(">>>>>>>> Processing constant light ...");
+            // Constant light
+            final double[] L = new double[3];
+            light.getLight(0, 0, 0, L);
+
+            for(i=0; i<h; i++){
+                final double [][] NR = NA[i];
+                for(j=0; j<w; j++){
+                    // Get Normal 
+                    final double[] N = NR[j];
+                    
+                    NL = 255.*kd*(N[0]*L[0] + N[1]*L[1] + N[2]*L[2]);
+                    
+                    r = (int)(NL*lightColor[0]);
+                    g = (int)(NL*lightColor[1]);
+                    b = (int)(NL*lightColor[2]);
+                    
+                    // If any high bits are set we are not in range.
+                    // If the highest bit is set then we are negative so
+                    // clamp to zero else we are > 255 so clamp to 255.
+                    if ((r & 0xFFFFFF00) != 0)
+                        r = ((r & 0x80000000) != 0)?0:255;
+                    if ((g & 0xFFFFFF00) != 0)
+                        g = ((g & 0x80000000) != 0)?0:255;
+                    if ((b & 0xFFFFFF00) != 0)
+                        b = ((b & 0x80000000) != 0)?0:255;
+                    
+                    pixels[p++] = (0xff000000
+                                   |
+                                   r << 16
+                                   |
+                                   g << 8
+                                   |
+                                   b);
+                }
+                p += adjust;
+            }
+        }
+        
+        return wr;
+    }
+
+}

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

Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/DisplacementMapRed.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/DisplacementMapRed.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/DisplacementMapRed.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/rendered/DisplacementMapRed.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,755 @@
+/*
+
+   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.ColorModel;
+import java.awt.image.DataBufferInt;
+import java.awt.image.Raster;
+import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.WritableRaster;
+
+import org.apache.flex.forks.batik.ext.awt.image.ARGBChannel;
+import org.apache.flex.forks.batik.ext.awt.image.GraphicsUtil;
+import org.apache.flex.forks.batik.ext.awt.image.PadMode;
+
+
+/**
+ * This implementation of RenderableImage will render its input
+ * GraphicsNode on demand for tiles.
+ *
+ * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
+ * @version $Id: DisplacementMapRed.java 478276 2006-11-22 18:33:37Z dvholten $
+ */
+public class DisplacementMapRed extends AbstractRed {
+    // Use these to control timing and Nearest Neighbot vs. Bilinear Interp.
+    private static final boolean TIME   = false;
+    private static final boolean USE_NN = false;
+
+    /**
+     * The displacement scale factor along the x axis
+     */
+    private float scaleX;
+
+    /**
+     * The displacement scale factor along the y axis
+     */
+    private float scaleY;
+
+    /**
+     * The channel type of the operation on X axis
+     */
+    private ARGBChannel xChannel;
+
+    /**
+     * The channel type of the operation on Y axis
+     */
+    private ARGBChannel yChannel;
+
+    /**
+     * The image to distort.
+     */
+    CachableRed image;
+
+    /**
+     * The offset image (displacement map).
+     */
+    CachableRed offsets;
+
+    /**
+     * The maximum possible offsets in x and y
+     */
+    int maxOffX, maxOffY;
+
+    /**
+     * The set of rendering hints
+     */
+    RenderingHints hints;
+
+    /**
+     * Computed tile Offsets Soft referencces to TileOffsets instances...
+     */
+    TileOffsets [] xOffsets;
+    TileOffsets [] yOffsets;
+
+    static class TileOffsets {
+        int [] tile;
+        int [] off;
+        TileOffsets(int len, int base, int stride,
+                    int loc, int endLoc, int slop, int tile, int endTile) {
+            this.tile = new int[len+1];
+            this.off  = new int[len+1];
+
+            if (tile == endTile) endLoc -= slop;
+
+            for (int i=0; i<len; i++) {
+                this.tile[i] = tile;
+                this.off [i] = base+(loc*stride);
+                loc++;
+                if (loc == endLoc) {
+                    loc = 0;
+                    tile++;
+                    if (tile == endTile) endLoc -=slop;
+                }
+            }
+            this.tile[len] = this.tile[len-1];
+            this.off [len] = this.off [len-1];
+        }
+    }
+
+    /**
+     * @param image the image to distort
+     * @param offsets the displacement map
+     * @param xChannel defines the channel of off whose values will be
+     *                 on X-axis operation
+     * @param yChannel defines the channel of off whose values will be
+     * @param scaleX defines the scale factor of the filter operation
+     *               on the X axis.
+     * @param scaleY defines the scale factor of the filter operation
+     *               on the Y axis
+     * @param rh the rendering hints
+     */
+    public DisplacementMapRed(CachableRed image,
+                              CachableRed offsets,
+                              ARGBChannel xChannel,
+                              ARGBChannel yChannel,
+                              float scaleX, float scaleY,
+                              RenderingHints rh) {
+
+        if(xChannel == null){
+            throw new IllegalArgumentException("Must provide xChannel");
+        }
+
+        if(yChannel == null){
+            throw new IllegalArgumentException("Must provide yChannel");
+        }
+
+        this.offsets = offsets;
+        this.scaleX = scaleX;
+        this.scaleY = scaleY;
+        this.xChannel = xChannel;
+        this.yChannel = yChannel;
+        this.hints   = rh;
+
+        maxOffX = (int)Math.ceil(scaleX/2);
+        maxOffY = (int)Math.ceil(scaleY/2);
+
+        Rectangle rect = image.getBounds();
+
+        Rectangle r    = image.getBounds();
+        r.x -= maxOffX; r.width  += 2*maxOffX;
+        r.y -= maxOffY; r.height += 2*maxOffY;
+        image = new PadRed(image, r, PadMode.ZERO_PAD, null);
+        image = new TileCacheRed(image);
+        this.image = image;
+        ColorModel cm = image.getColorModel();
+        if (!USE_NN)
+            // For Bilinear we need alpha premult.
+            cm = GraphicsUtil.coerceColorModel(cm, true);
+
+        init(image, rect, cm, image.getSampleModel(),
+             rect.x, rect.y, null);
+
+        xOffsets = new TileOffsets[getNumXTiles()];
+        yOffsets = new TileOffsets[getNumYTiles()];
+    }
+
+    public WritableRaster copyData(WritableRaster wr) {
+        copyToRaster(wr);
+        return wr;
+    }
+
+    public Raster getTile(int tileX, int tileY) {
+        WritableRaster dest = makeTile(tileX, tileY);
+        Rectangle srcR   = dest.getBounds();
+
+        // Get Raster from offsetes
+        Raster     mapRas = offsets.getData(srcR);
+        ColorModel mapCM  = offsets.getColorModel();
+        // ensure map isn't pre-multiplied.
+        GraphicsUtil.coerceData((WritableRaster)mapRas, mapCM, false);
+
+        TileOffsets xinfo = getXOffsets(tileX);
+        TileOffsets yinfo = getYOffsets(tileY);
+
+        if (USE_NN)
+            filterNN(mapRas, dest,
+                     xinfo.tile, xinfo.off,
+                     yinfo.tile, yinfo.off);
+        else if (image.getColorModel().isAlphaPremultiplied())
+            filterBL(mapRas, dest,
+                     xinfo.tile, xinfo.off,
+                     yinfo.tile, yinfo.off);
+        else
+            filterBLPre(mapRas, dest,
+                        xinfo.tile, xinfo.off,
+                        yinfo.tile, yinfo.off);
+
+        return dest;
+    }
+
+    public TileOffsets getXOffsets(int xTile) {
+        TileOffsets ret = xOffsets[xTile-getMinTileX()];
+        if (ret != null)
+            return ret;
+
+        SinglePixelPackedSampleModel sppsm;
+        sppsm = (SinglePixelPackedSampleModel)getSampleModel();
+        int base  = sppsm.getOffset(0, 0);
+        int tw    = sppsm.getWidth();
+
+        // The span we need to cover in the input image.
+        int width = tw+2*maxOffX;
+
+        // The start and end X in image's tile coordinate system...
+        int x0      = getTileGridXOffset() + xTile * tw - maxOffX
+                          - image.getTileGridXOffset();
+        int x1      = x0 + width-1;
+
+        int tile    = (int)Math.floor(x0/(double)tw);
+        int endTile = (int)Math.floor(x1/(double)tw);
+        int loc     = x0-(tile*tw);
+        int endLoc  = tw;
+
+        // Amount not used from right edge tile
+        int slop = ((endTile+1)*tw-1) - x1;
+
+        ret = new TileOffsets(width, base, 1,
+                              loc, endLoc, slop, tile, endTile);
+
+        xOffsets[xTile-getMinTileX()] = ret;
+        return ret;
+    }
+
+    public TileOffsets getYOffsets(int yTile) {
+        TileOffsets ret = yOffsets[yTile-getMinTileY()];
+        if (ret != null)
+            return ret;
+
+        SinglePixelPackedSampleModel sppsm;
+        sppsm = (SinglePixelPackedSampleModel)getSampleModel();
+        int stride  = sppsm.getScanlineStride();
+        int th      = sppsm.getHeight();
+
+        // The span we need to cover in the input image.
+        int height  = th+2*maxOffY;
+
+        // The start and end Y in image's tile coordinate system...
+        int y0      = getTileGridYOffset() + yTile * th - maxOffY
+                          - image.getTileGridYOffset();
+        int y1      = y0 + height - 1;
+
+        int tile    = (int)Math.floor(y0/(double)th);
+        int endTile = (int)Math.floor(y1/(double)th);
+        int loc     = y0-(tile*th);
+        int endLoc  = th;
+
+        // Amount not used from bottom edge tile
+        int slop = ((endTile+1)*th-1) - y1;
+
+        ret = new TileOffsets(height, 0, stride,
+                              loc, endLoc, slop, tile, endTile);
+
+        yOffsets[yTile-getMinTileY()] = ret;
+        return ret;
+    }
+
+    public void filterBL(Raster off, WritableRaster dst,
+                         int [] xTile, int [] xOff,
+                         int [] yTile, int [] yOff) {
+        final int w      = dst.getWidth();
+        final int h      = dst.getHeight();
+        final int xStart = maxOffX;
+        final int yStart = maxOffY;
+        final int xEnd   = xStart+w;
+        final int yEnd   = yStart+h;
+
+        // Access the integer buffer for each image.
+        DataBufferInt dstDB = (DataBufferInt)dst.getDataBuffer();
+        DataBufferInt offDB = (DataBufferInt)off.getDataBuffer();
+
+        // Offset defines where in the stack the real data begin
+        SinglePixelPackedSampleModel dstSPPSM, offSPPSM;
+
+        dstSPPSM = (SinglePixelPackedSampleModel)dst.getSampleModel();
+        final int dstOff = dstDB.getOffset() +
+            dstSPPSM.getOffset(dst.getMinX() - dst.getSampleModelTranslateX(),
+                               dst.getMinY() - dst.getSampleModelTranslateY());
+
+        offSPPSM = (SinglePixelPackedSampleModel)off.getSampleModel();
+        final int offOff = offDB.getOffset() +
+            offSPPSM.getOffset(dst.getMinX() - off.getSampleModelTranslateX(),
+                               dst.getMinY() - off.getSampleModelTranslateY());
+
+        // Stride is the distance between two consecutive column elements,
+        // in the one-dimention dataBuffer
+        final int dstScanStride = dstSPPSM.getScanlineStride();
+        final int offScanStride = offSPPSM.getScanlineStride();
+
+        final int dstAdjust = dstScanStride - w;
+        final int offAdjust = offScanStride - w;
+
+        // Access the pixel value array
+        final int[] dstPixels = dstDB.getBankData()[0];
+        final int[] offPixels = offDB.getBankData()[0];
+
+        // Below is the number of shifts for each axis
+        // e.g when xChannel is ALPHA, the pixel needs
+        // to be shifted 24, RED 16, GREEN 8 and BLUE 0
+        final int xShift = xChannel.toInt()*8;
+        final int yShift = yChannel.toInt()*8;
+
+        // The pointer of img and dst indicating where the pixel values are
+        int dp = dstOff, ip = offOff;
+
+        // Fixed point representation of scale factor.
+        final int fpScaleX = (int)((scaleX/255.0)*(1<<15)+0.5);
+        final int fpAdjX   = (int)(-127.5*fpScaleX-0.5);
+        final int fpScaleY = (int)((scaleY/255.0)*(1<<15)+0.5);
+        final int fpAdjY   = (int)(-127.5*fpScaleY-0.5);
+
+        long start = System.currentTimeMillis();
+
+        int pel00, pel01, pel10, pel11, xFrac, yFrac, newPel;
+        int sp0, sp1, pel0, pel1;
+
+        int x, y, x0, y0, xDisplace, yDisplace, dPel;
+
+        int xt=xTile[0]-1, yt=yTile[0]-1, xt1, yt1;
+        int [] imgPix = null;
+
+        for (y=yStart; y<yEnd; y++) {
+            for (x=xStart; x<xEnd; x++, dp++, ip++) {
+                dPel = offPixels[ip];
+
+                xDisplace = (fpScaleX*((dPel>>xShift)&0xff))+fpAdjX;
+                yDisplace = (fpScaleY*((dPel>>yShift)&0xff))+fpAdjY;
+
+                x0 = x+(xDisplace>>15);
+                y0 = y+(yDisplace>>15);
+
+                if ((xt != xTile[x0]) ||
+                    (yt != yTile[y0])) {
+                    xt = xTile[x0]; yt = yTile[y0];
+                    imgPix = ((DataBufferInt)image.getTile(xt, yt)
+                              .getDataBuffer()).getBankData()[0];
+                }
+                pel00  = imgPix[xOff[x0]+yOff[y0]];
+
+                xt1 = xTile[x0+1];
+                yt1 = yTile[y0+1];
+                if ((yt == yt1)) {
+                    // Same tile vertically, check across...
+                    if ((xt == xt1)) {
+                        // All from same tile..
+                        pel10  = imgPix[xOff[x0+1]+yOff[y0]];
+                        pel01  = imgPix[xOff[x0]  +yOff[y0+1]];
+                        pel11  = imgPix[xOff[x0+1]+yOff[y0+1]];
+                    } else {
+                        // Different tile horizontally...
+                        pel01  = imgPix[xOff[x0]+yOff[y0+1]];
+
+                        imgPix = ((DataBufferInt)image.getTile(xt1, yt)
+                                  .getDataBuffer()).getBankData()[0];
+                        pel10  = imgPix[xOff[x0+1]+yOff[y0]];
+                        pel11  = imgPix[xOff[x0+1]+yOff[y0+1]];
+                        xt = xt1;
+                    }
+                } else {
+                    // Steped into next tile down, check across...
+                    if ((xt == xt1)) {
+                        // Different tile horizontally.
+                        pel10  = imgPix[xOff[x0+1]+yOff[y0]];
+
+                        imgPix = ((DataBufferInt)image.getTile(xt, yt1)
+                                  .getDataBuffer()).getBankData()[0];
+                        pel01  = imgPix[xOff[x0]  +yOff[y0+1]];
+                        pel11  = imgPix[xOff[x0+1]+yOff[y0+1]];
+                        yt = yt1;
+                    } else {
+                        // Ugg we are at the 4way intersection of tiles...
+                        imgPix = ((DataBufferInt)image.getTile(xt, yt1)
+                                  .getDataBuffer()).getBankData()[0];
+                        pel01  = imgPix[xOff[x0]+yOff[y0+1]];
+
+                        imgPix = ((DataBufferInt)image.getTile(xt1, yt1)
+                                  .getDataBuffer()).getBankData()[0];
+                        pel11  = imgPix[xOff[x0+1]+yOff[y0+1]];
+
+                        imgPix = ((DataBufferInt)image.getTile(xt1, yt)
+                                  .getDataBuffer()).getBankData()[0];
+                        pel10  = imgPix[xOff[x0+1]+yOff[y0]];
+                        xt = xt1;
+                    }
+                }
+
+                xFrac = xDisplace&0x7FFF;
+                yFrac = yDisplace&0x7FFF;
+
+                // Combine the alpha channels.
+                sp0  = (pel00>>>16) & 0xFF00;
+                sp1  = (pel10>>>16) & 0xFF00;
+                pel0 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                sp0  = (pel01>>>16) & 0xFF00;
+                sp1  = (pel11>>>16) & 0xFF00;
+                pel1 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                newPel = (((pel0<<15) + (pel1-pel0)*yFrac + 0x00400000)
+                          &0x7F800000)<<  1;
+
+                // Combine the red channels.
+                sp0  = (pel00>>  8) & 0xFF00;
+                sp1  = (pel10>>  8) & 0xFF00;
+                pel0 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                sp0  = (pel01>>  8) & 0xFF00;
+                sp1  = (pel11>>  8) & 0xFF00;
+                pel1 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                newPel |= (((pel0<<15) + (pel1-pel0)*yFrac + 0x00400000)
+                           &0x7F800000)>>> 7;
+
+                // Combine the green channels.
+                sp0  = (pel00     ) & 0xFF00;
+                sp1  = (pel10     ) & 0xFF00;
+                pel0 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                sp0  = (pel01     ) & 0xFF00;
+                sp1  = (pel11     ) & 0xFF00;
+                pel1 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                newPel |= (((pel0<<15) + (pel1-pel0)*yFrac + 0x00400000)
+                           &0x7F800000)>>>15;
+
+                // Combine the blue channels.
+                sp0  = (pel00<<  8) & 0xFF00;
+                sp1  = (pel10<<  8) & 0xFF00;
+                pel0 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                sp0  = (pel01<<  8) & 0xFF00;
+                sp1  = (pel11<<  8) & 0xFF00;
+                pel1 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                newPel |= (((pel0<<15) + (pel1-pel0)*yFrac + 0x00400000)
+                           &0x7F800000)>>>23;
+
+                dstPixels[dp] = newPel;
+            }
+
+            dp += dstAdjust;
+            ip += offAdjust;
+        }
+
+        if (TIME) {
+            long end = System.currentTimeMillis();
+            System.out.println("Time: " + (end-start));
+        }
+    }// end of the filter() method for Raster
+
+    public void filterBLPre(Raster off, WritableRaster dst,
+                            int [] xTile, int [] xOff,
+                            int [] yTile, int [] yOff) {
+        final int w      = dst.getWidth();
+        final int h      = dst.getHeight();
+        final int xStart = maxOffX;
+        final int yStart = maxOffY;
+        final int xEnd   = xStart+w;
+        final int yEnd   = yStart+h;
+
+        // Access the integer buffer for each image.
+        DataBufferInt dstDB = (DataBufferInt)dst.getDataBuffer();
+        DataBufferInt offDB = (DataBufferInt)off.getDataBuffer();
+
+        // Offset defines where in the stack the real data begin
+        SinglePixelPackedSampleModel dstSPPSM, offSPPSM;
+
+        dstSPPSM = (SinglePixelPackedSampleModel)dst.getSampleModel();
+        final int dstOff = dstDB.getOffset() +
+            dstSPPSM.getOffset(dst.getMinX() - dst.getSampleModelTranslateX(),
+                               dst.getMinY() - dst.getSampleModelTranslateY());
+
+        offSPPSM = (SinglePixelPackedSampleModel)off.getSampleModel();
+        final int offOff = offDB.getOffset() +
+            offSPPSM.getOffset(dst.getMinX() - off.getSampleModelTranslateX(),
+                               dst.getMinY() - off.getSampleModelTranslateY());
+
+        // Stride is the distance between two consecutive column elements,
+        // in the one-dimention dataBuffer
+        final int dstScanStride = dstSPPSM.getScanlineStride();
+        final int offScanStride = offSPPSM.getScanlineStride();
+
+        final int dstAdjust = dstScanStride - w;
+        final int offAdjust = offScanStride - w;
+
+        // Access the pixel value array
+        final int[] dstPixels = dstDB.getBankData()[0];
+        final int[] offPixels = offDB.getBankData()[0];
+
+        // Below is the number of shifts for each axis
+        // e.g when xChannel is ALPHA, the pixel needs
+        // to be shifted 24, RED 16, GREEN 8 and BLUE 0
+        final int xShift = xChannel.toInt()*8;
+        final int yShift = yChannel.toInt()*8;
+
+        // The pointer of img and dst indicating where the pixel values are
+        int dp = dstOff, ip = offOff;
+
+        // Fixed point representation of scale factor.
+        // Fixed point representation of scale factor.
+        final int fpScaleX = (int)((scaleX/255.0)*(1<<15)+0.5);
+        final int fpAdjX   = (int)(-127.5*fpScaleX-0.5);
+        final int fpScaleY = (int)((scaleY/255.0)*(1<<15)+0.5);
+        final int fpAdjY   = (int)(-127.5*fpScaleY-0.5);
+
+        long start = System.currentTimeMillis();
+
+        int pel00, pel01, pel10, pel11, xFrac, yFrac, newPel;
+        int sp0, sp1, pel0, pel1, a00, a01, a10, a11;
+
+        int x, y, x0, y0, xDisplace, yDisplace, dPel;
+        final int norm = (1<<24)/255;
+
+        int xt=xTile[0]-1, yt=yTile[0]-1, xt1, yt1;
+        int [] imgPix = null;
+
+        for (y=yStart; y<yEnd; y++) {
+            for (x=xStart; x<xEnd; x++, dp++, ip++) {
+                dPel = offPixels[ip];
+
+                xDisplace = (fpScaleX*((dPel>>xShift)&0xff))+fpAdjX;
+                yDisplace = (fpScaleY*((dPel>>yShift)&0xff))+fpAdjY;
+
+                x0 = x+(xDisplace>>15);
+                y0 = y+(yDisplace>>15);
+
+                if ((xt != xTile[x0]) || (yt != yTile[y0])) {
+                    xt = xTile[x0];
+                    yt = yTile[y0];
+                    imgPix = ((DataBufferInt)image.getTile(xt, yt)
+                              .getDataBuffer()).getBankData()[0];
+                }
+                pel00  = imgPix[xOff[x0]+yOff[y0]];
+
+                xt1 = xTile[x0+1];
+                yt1 = yTile[y0+1];
+                if ((yt == yt1)) {
+                    // Same tile vertically, check across...
+                    if ((xt == xt1)) {
+                        // All from same tile..
+                        pel10  = imgPix[xOff[x0+1]+yOff[y0]];
+                        pel01  = imgPix[xOff[x0]  +yOff[y0+1]];
+                        pel11  = imgPix[xOff[x0+1]+yOff[y0+1]];
+                    } else {
+                        // Different tile horizontally...
+                        pel01  = imgPix[xOff[x0]+yOff[y0+1]];
+
+                        imgPix = ((DataBufferInt)image.getTile(xt1, yt)
+                                  .getDataBuffer()).getBankData()[0];
+                        pel10  = imgPix[xOff[x0+1]+yOff[y0]];
+                        pel11  = imgPix[xOff[x0+1]+yOff[y0+1]];
+                        xt = xt1;
+                    }
+                } else {
+                    // Steped into next tile down, check across...
+                    if ((xt == xt1)) {
+                        // Different tile horizontally.
+                        pel10  = imgPix[xOff[x0+1]+yOff[y0]];
+
+                        imgPix = ((DataBufferInt)image.getTile(xt, yt1)
+                                  .getDataBuffer()).getBankData()[0];
+                        pel01  = imgPix[xOff[x0]  +yOff[y0+1]];
+                        pel11  = imgPix[xOff[x0+1]+yOff[y0+1]];
+                        yt = yt1;
+                    } else {
+                        // Ugg we are at the 4way intersection of tiles...
+                        imgPix = ((DataBufferInt)image.getTile(xt, yt1)
+                                  .getDataBuffer()).getBankData()[0];
+                        pel01  = imgPix[xOff[x0]+yOff[y0+1]];
+
+                        imgPix = ((DataBufferInt)image.getTile(xt1, yt1)
+                                  .getDataBuffer()).getBankData()[0];
+                        pel11  = imgPix[xOff[x0+1]+yOff[y0+1]];
+
+                        imgPix = ((DataBufferInt)image.getTile(xt1, yt)
+                                  .getDataBuffer()).getBankData()[0];
+                        pel10  = imgPix[xOff[x0+1]+yOff[y0]];
+                        xt = xt1;
+                    }
+                }
+
+                xFrac = xDisplace&0x7FFF;
+                yFrac = yDisplace&0x7FFF;
+
+                // Combine the alpha channels.
+                sp0  = (pel00>>>16) & 0xFF00;
+                sp1  = (pel10>>>16) & 0xFF00;
+                pel0 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                a00 = ((sp0>>8)*norm + 0x80)>>8;
+                a10 = ((sp1>>8)*norm + 0x80)>>8;
+
+                sp0  = (pel01>>>16) & 0xFF00;
+                sp1  = (pel11>>>16) & 0xFF00;
+                pel1 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                a01 = ((sp0>>8)*norm + 0x80)>>8;
+                a11 = ((sp1>>8)*norm + 0x80)>>8;
+                newPel = (((pel0<<15) + (pel1-pel0)*yFrac + 0x00400000)
+                          &0x7F800000)<<  1;
+
+                // Combine the red channels.
+                sp0  = ((((pel00>> 16) & 0xFF)*a00) + 0x80)>>8;
+                sp1  = ((((pel10>> 16) & 0xFF)*a10) + 0x80)>>8;
+                pel0 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                sp0  = ((((pel01>> 16) & 0xFF)*a01) + 0x80)>>8;
+                sp1  = ((((pel11>> 16) & 0xFF)*a11) + 0x80)>>8;
+                pel1 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                newPel |= (((pel0<<15) + (pel1-pel0)*yFrac + 0x00400000)
+                           &0x7F800000)>>> 7;
+
+                // Combine the green channels.
+                sp0  = ((((pel00>> 8) & 0xFF)*a00) + 0x80)>>8;
+                sp1  = ((((pel10>> 8) & 0xFF)*a10) + 0x80)>>8;
+                pel0 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                sp0  = ((((pel01>> 8) & 0xFF)*a01) + 0x80)>>8;
+                sp1  = ((((pel11>> 8) & 0xFF)*a11) + 0x80)>>8;
+                pel1 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                newPel |= (((pel0<<15) + (pel1-pel0)*yFrac + 0x00400000)
+                           &0x7F800000)>>>15;
+
+                // Combine the blue channels.
+                sp0  = (((pel00 & 0xFF)*a00) + 0x80)>>8;
+                sp1  = (((pel10 & 0xFF)*a10) + 0x80)>>8;
+                pel0 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                sp0  = (((pel01 & 0xFF)*a01) + 0x80)>>8;
+                sp1  = (((pel11 & 0xFF)*a11) + 0x80)>>8;
+                pel1 = (sp0 + (((sp1-sp0)*xFrac+0x4000)>>15)) & 0xFFFF;
+                newPel |= (((pel0<<15) + (pel1-pel0)*yFrac + 0x00400000)
+                           &0x7F800000)>>>23;
+
+                dstPixels[dp] = newPel;
+            }
+
+            dp += dstAdjust;
+            ip += offAdjust;
+        }
+
+        if (TIME) {
+            long end = System.currentTimeMillis();
+            System.out.println("Time: " + (end-start));
+        }
+    }// end of the filter() method for Raster
+
+    /**
+     * Does displacement map using Nearest neighbor interpolation
+     *
+     * @param off the displacement map
+     * @param dst stores the filtered image. If null, a destination will
+     *        be created. img and dst can refer to the same Raster, in
+     *        which situation the img will be modified.
+     */
+    public void filterNN(Raster off, WritableRaster dst,
+                         int [] xTile, int [] xOff,
+                         int [] yTile, int [] yOff) {
+        final int w      = dst.getWidth();
+        final int h      = dst.getHeight();
+        final int xStart = maxOffX;
+        final int yStart = maxOffY;
+        final int xEnd   = xStart+w;
+        final int yEnd   = yStart+h;
+
+        // Access the integer buffer for each image.
+        DataBufferInt dstDB = (DataBufferInt)dst.getDataBuffer();
+        DataBufferInt offDB = (DataBufferInt)off.getDataBuffer();
+
+        // Offset defines where in the stack the real data begin
+        SinglePixelPackedSampleModel dstSPPSM, offSPPSM;
+
+        dstSPPSM = (SinglePixelPackedSampleModel)dst.getSampleModel();
+        final int dstOff = dstDB.getOffset() +
+            dstSPPSM.getOffset(dst.getMinX() - dst.getSampleModelTranslateX(),
+                               dst.getMinY() - dst.getSampleModelTranslateY());
+
+        offSPPSM = (SinglePixelPackedSampleModel)off.getSampleModel();
+        final int offOff = offDB.getOffset() +
+            offSPPSM.getOffset(off.getMinX() - off.getSampleModelTranslateX(),
+                               off.getMinY() - off.getSampleModelTranslateY());
+
+        // Stride is the distance between two consecutive column elements,
+        // in the one-dimention dataBuffer
+        final int dstScanStride = dstSPPSM.getScanlineStride();
+        final int offScanStride = offSPPSM.getScanlineStride();
+
+        final int dstAdjust = dstScanStride - w;
+        final int offAdjust = offScanStride - w;
+
+        // Access the pixel value array
+        final int[] dstPixels = dstDB.getBankData()[0];
+        final int[] offPixels = offDB.getBankData()[0];
+
+        // Below is the number of shifts for each axis
+        // e.g when xChannel is ALPHA, the pixel needs
+        // to be shifted 24, RED 16, GREEN 8 and BLUE 0
+        final int xShift = xChannel.toInt()*8;
+        final int yShift = yChannel.toInt()*8;
+
+        final int fpScaleX = (int)((scaleX/255.0)*(1<<15)+0.5);
+        final int fpScaleY = (int)((scaleY/255.0)*(1<<15)+0.5);
+
+        // Calculate the shift to make '.5' no movement.
+        // This also includes rounding factor (0x4000) for Fixed Point stuff.
+        final int fpAdjX   = (int)(-127.5*fpScaleX-0.5) + 0x4000;
+        final int fpAdjY   = (int)(-127.5*fpScaleY-0.5) + 0x4000;
+
+        // The pointer of img and dst indicating where the pixel values are
+        int dp = dstOff, ip = offOff;
+
+        long start = System.currentTimeMillis();
+        int y=yStart, xt=xTile[0]-1, yt=yTile[0]-1;
+        int [] imgPix = null;
+
+        int x0, y0, xDisplace, yDisplace, dPel;
+        while (y<yEnd) {
+            int x=xStart;
+            while (x<xEnd) {
+                dPel = offPixels[ip];
+
+                xDisplace = (fpScaleX*((dPel>>xShift)&0xff))+fpAdjX;
+                yDisplace = (fpScaleY*((dPel>>yShift)&0xff))+fpAdjY;
+
+                x0 = x+(xDisplace>>15);
+                y0 = y+(yDisplace>>15);
+
+                if ((xt != xTile[x0]) ||
+                    (yt != yTile[y0])) {
+                    xt = xTile[x0]; yt = yTile[y0];
+                    imgPix = ((DataBufferInt)image.getTile(xt, yt)
+                              .getDataBuffer()).getBankData()[0];
+                }
+                dstPixels[dp] = imgPix[xOff[x0]+yOff[y0]];
+
+                dp++;
+                ip++;
+                x++;
+            }
+
+            dp += dstAdjust;
+            ip += offAdjust;
+            y++;
+        }
+        if (TIME) {
+            long end = System.currentTimeMillis();
+            System.out.println("Time: " + (end-start));
+        }
+    }// end of the filter() method for Raster
+}
+
+

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