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 [10/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/SVGComposite.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/SVGComposite.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/SVGComposite.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/SVGComposite.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,1536 @@
+/*
+
+ 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;
+
+import java.awt.AlphaComposite;
+import java.awt.Composite;
+import java.awt.CompositeContext;
+import java.awt.RenderingHints;
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBufferInt;
+import java.awt.image.PackedColorModel;
+import java.awt.image.Raster;
+import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.WritableRaster;
+
+/**
+ * This provides an implementation of all the composite rules in SVG.
+ *
+ * @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
+ * @version $Id: SVGComposite.java 478363 2006-11-22 23:01:13Z dvholten $
+ */
+public class SVGComposite
+ implements Composite {
+
+ public static final SVGComposite OVER
+ = new SVGComposite(CompositeRule.OVER);
+
+ public static final SVGComposite IN
+ = new SVGComposite(CompositeRule.IN);
+
+ public static final SVGComposite OUT
+ = new SVGComposite(CompositeRule.OUT);
+
+ public static final SVGComposite ATOP
+ = new SVGComposite(CompositeRule.ATOP);
+
+ public static final SVGComposite XOR
+ = new SVGComposite(CompositeRule.XOR);
+
+ public static final SVGComposite MULTIPLY
+ = new SVGComposite(CompositeRule.MULTIPLY);
+
+ public static final SVGComposite SCREEN
+ = new SVGComposite(CompositeRule.SCREEN);
+
+ public static final SVGComposite DARKEN
+ = new SVGComposite(CompositeRule.DARKEN);
+
+ public static final SVGComposite LIGHTEN
+ = new SVGComposite(CompositeRule.LIGHTEN);
+
+
+ CompositeRule rule;
+
+ public CompositeRule getRule() { return rule; }
+
+ public SVGComposite(CompositeRule rule) {
+ this.rule = rule;
+ }
+
+ public boolean equals(Object o) {
+ if (o instanceof SVGComposite) {
+ SVGComposite svgc = (SVGComposite)o;
+ return (svgc.getRule() == getRule());
+ } else if (o instanceof AlphaComposite) {
+ AlphaComposite ac = (AlphaComposite)o;
+ switch (getRule().getRule()) {
+ case CompositeRule.RULE_OVER:
+ return (ac == AlphaComposite.SrcOver);
+ case CompositeRule.RULE_IN:
+ return (ac == AlphaComposite.SrcIn);
+ case CompositeRule.RULE_OUT:
+ return (ac == AlphaComposite.SrcOut);
+ default:
+ return false;
+ }
+ }
+ return false;
+ }
+
+ public boolean is_INT_PACK(ColorModel cm) {
+ // Check ColorModel is of type DirectColorModel
+ if(!(cm instanceof PackedColorModel)) return false;
+
+ PackedColorModel pcm = (PackedColorModel)cm;
+
+ int [] masks = pcm.getMasks();
+
+ // Check transfer type
+ if(masks.length != 4) return false;
+
+ if (masks[0] != 0x00ff0000) return false;
+ if (masks[1] != 0x0000ff00) return false;
+ if (masks[2] != 0x000000ff) return false;
+ if (masks[3] != 0xff000000) return false;
+
+ return true;
+ }
+
+ public CompositeContext createContext(ColorModel srcCM,
+ ColorModel dstCM,
+ RenderingHints hints) {
+ if (false) {
+ ColorSpace srcCS = srcCM.getColorSpace();
+ ColorSpace dstCS = dstCM.getColorSpace();
+ System.out.println("srcCS: " + srcCS);
+ System.out.println("dstCS: " + dstCS);
+ System.out.println
+ ("lRGB: " + ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB));
+ System.out.println
+ ("sRGB: " + ColorSpace.getInstance(ColorSpace.CS_sRGB));
+ }
+
+ // Orig Time no int_pack = 51792
+ // Simple int_pack = 19600
+ boolean use_int_pack = (is_INT_PACK(srcCM) && is_INT_PACK(dstCM));
+ // use_int_pack = false;
+
+ switch (rule.getRule()) {
+ case CompositeRule.RULE_OVER:
+ if (!dstCM.hasAlpha()) {
+ if (use_int_pack)
+ return new OverCompositeContext_INT_PACK_NA(srcCM, dstCM);
+ else
+ return new OverCompositeContext_NA (srcCM, dstCM);
+ }
+
+ if (!use_int_pack)
+ return new OverCompositeContext(srcCM, dstCM);
+
+ if (srcCM.isAlphaPremultiplied())
+ return new OverCompositeContext_INT_PACK(srcCM, dstCM);
+ else
+ return new OverCompositeContext_INT_PACK_UNPRE(srcCM, dstCM);
+
+ case CompositeRule.RULE_IN:
+ if (use_int_pack)
+ return new InCompositeContext_INT_PACK(srcCM, dstCM);
+ else
+ return new InCompositeContext (srcCM, dstCM);
+
+ case CompositeRule.RULE_OUT:
+ if (use_int_pack)
+ return new OutCompositeContext_INT_PACK(srcCM, dstCM);
+ else
+ return new OutCompositeContext (srcCM, dstCM);
+
+ case CompositeRule.RULE_ATOP:
+ if (use_int_pack)
+ return new AtopCompositeContext_INT_PACK(srcCM, dstCM);
+ else
+ return new AtopCompositeContext(srcCM, dstCM);
+
+ case CompositeRule.RULE_XOR:
+ if (use_int_pack)
+ return new XorCompositeContext_INT_PACK(srcCM, dstCM);
+ else
+ return new XorCompositeContext (srcCM, dstCM);
+
+ case CompositeRule.RULE_ARITHMETIC:
+ float [] coeff = rule.getCoefficients();
+ if (use_int_pack)
+ return new ArithCompositeContext_INT_PACK_LUT
+ (srcCM, dstCM, coeff[0], coeff[1], coeff[2], coeff[3]);
+ else
+ return new ArithCompositeContext
+ (srcCM, dstCM, coeff[0], coeff[1], coeff[2], coeff[3]);
+
+ case CompositeRule.RULE_MULTIPLY:
+ if (use_int_pack)
+ return new MultiplyCompositeContext_INT_PACK(srcCM, dstCM);
+ else
+ return new MultiplyCompositeContext(srcCM, dstCM);
+
+ case CompositeRule.RULE_SCREEN:
+ if (use_int_pack)
+ return new ScreenCompositeContext_INT_PACK(srcCM, dstCM);
+ else
+ return new ScreenCompositeContext (srcCM, dstCM);
+
+ case CompositeRule.RULE_DARKEN:
+ if (use_int_pack)
+ return new DarkenCompositeContext_INT_PACK(srcCM, dstCM);
+ else
+ return new DarkenCompositeContext (srcCM, dstCM);
+
+ case CompositeRule.RULE_LIGHTEN:
+ if (use_int_pack)
+ return new LightenCompositeContext_INT_PACK(srcCM, dstCM);
+ else
+ return new LightenCompositeContext (srcCM, dstCM);
+
+ default:
+ throw new UnsupportedOperationException
+ ("Unknown composite rule requested.");
+ }
+
+ }
+
+ public abstract static class AlphaPreCompositeContext
+ implements CompositeContext {
+
+ ColorModel srcCM, dstCM;
+ AlphaPreCompositeContext(ColorModel srcCM, ColorModel dstCM) {
+ this.srcCM = srcCM;
+ this.dstCM = dstCM;
+ }
+
+ public void dispose() {
+ srcCM = null;
+ dstCM = null;
+ }
+
+ protected abstract void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut);
+
+ public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
+ ColorModel srcPreCM = srcCM;
+ if (!srcCM.isAlphaPremultiplied())
+ srcPreCM = GraphicsUtil.coerceData((WritableRaster)src,
+ srcCM, true);
+
+ ColorModel dstPreCM = dstCM;
+ if (!dstCM.isAlphaPremultiplied())
+ dstPreCM = GraphicsUtil.coerceData((WritableRaster)dstIn,
+ dstCM, true);
+
+ precompose(src, dstIn, dstOut);
+
+ if (!srcCM.isAlphaPremultiplied())
+ GraphicsUtil.coerceData((WritableRaster)src,
+ srcPreCM, false);
+
+ if (!dstCM.isAlphaPremultiplied()) {
+ GraphicsUtil.coerceData(dstOut, dstPreCM, false);
+
+ if (dstIn != dstOut)
+ GraphicsUtil.coerceData((WritableRaster)dstIn,
+ dstPreCM, false);
+ }
+ }
+ }
+
+ public abstract static class AlphaPreCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext {
+
+ AlphaPreCompositeContext_INT_PACK(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ protected abstract void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp);
+
+ protected void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+
+ int x0=dstOut.getMinX();
+ int w =dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int h =dstOut.getHeight();
+
+ SinglePixelPackedSampleModel srcSPPSM;
+ srcSPPSM = (SinglePixelPackedSampleModel)src.getSampleModel();
+
+ final int srcScanStride = srcSPPSM.getScanlineStride();
+ DataBufferInt srcDB = (DataBufferInt)src.getDataBuffer();
+ final int [] srcPixels = srcDB.getBankData()[0];
+ final int srcBase =
+ (srcDB.getOffset() +
+ srcSPPSM.getOffset(x0-src.getSampleModelTranslateX(),
+ y0-src.getSampleModelTranslateY()));
+
+
+ SinglePixelPackedSampleModel dstInSPPSM;
+ dstInSPPSM = (SinglePixelPackedSampleModel)dstIn.getSampleModel();
+
+ final int dstInScanStride = dstInSPPSM.getScanlineStride();
+ DataBufferInt dstInDB = (DataBufferInt)dstIn.getDataBuffer();
+ final int [] dstInPixels = dstInDB.getBankData()[0];
+ final int dstInBase =
+ (dstInDB.getOffset() +
+ dstInSPPSM.getOffset(x0-dstIn.getSampleModelTranslateX(),
+ y0-dstIn.getSampleModelTranslateY()));
+
+ SinglePixelPackedSampleModel dstOutSPPSM
+ = (SinglePixelPackedSampleModel)dstOut.getSampleModel();
+
+ final int dstOutScanStride = dstOutSPPSM.getScanlineStride();
+ DataBufferInt dstOutDB = (DataBufferInt)dstOut.getDataBuffer();
+ final int [] dstOutPixels = dstOutDB.getBankData()[0];
+ final int dstOutBase =
+ (dstOutDB.getOffset() +
+ dstOutSPPSM.getOffset(x0-dstOut.getSampleModelTranslateX(),
+ y0-dstOut.getSampleModelTranslateY()));
+
+ final int srcAdjust = srcScanStride - w;
+ final int dstInAdjust = dstInScanStride - w;
+ final int dstOutAdjust = dstOutScanStride - w;
+
+ precompose_INT_PACK(w, h,
+ srcPixels, srcAdjust, srcBase,
+ dstInPixels, dstInAdjust, dstInBase,
+ dstOutPixels, dstOutAdjust, dstOutBase);
+ }
+ }
+
+
+ /**
+ * This implements SRC_OVER for 4 band byte data.
+ */
+ public static class OverCompositeContext
+ extends AlphaPreCompositeContext {
+ OverCompositeContext(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ for (int y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ int sp = 0;
+ int end = w*4;
+ while(sp<end) {
+ final int dstM = (255-srcPix[sp+3])*norm;
+ dstPix[sp] = srcPix[sp] + ((dstPix[sp]*dstM +pt5)>>>24);
+ ++sp;
+ dstPix[sp] = srcPix[sp] + ((dstPix[sp]*dstM +pt5)>>>24);
+ ++sp;
+ dstPix[sp] = srcPix[sp] + ((dstPix[sp]*dstM +pt5)>>>24);
+ ++sp;
+ dstPix[sp] = srcPix[sp] + ((dstPix[sp]*dstM +pt5)>>>24);
+ ++sp;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+
+ }
+ }
+
+ /**
+ * This implements SRC_OVER for 4 band byte src data and
+ * 3 band byte dst data.
+ */
+ public static class OverCompositeContext_NA
+ extends AlphaPreCompositeContext {
+ OverCompositeContext_NA(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ for (int y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ int srcSP = 0;
+ int dstSP = 0;
+ int end = w*4;
+ while (srcSP<end) {
+ final int dstM = (255-srcPix[srcSP+3])*norm;
+ dstPix[dstSP] =
+ srcPix[srcSP] + ((dstPix[dstSP]*dstM +pt5)>>>24);
+ ++srcSP; ++dstSP;
+ dstPix[dstSP] =
+ srcPix[srcSP] + ((dstPix[dstSP]*dstM +pt5)>>>24);
+ ++srcSP; ++dstSP;
+ dstPix[dstSP] =
+ srcPix[srcSP] + ((dstPix[dstSP]*dstM +pt5)>>>24);
+ srcSP+=2; ++dstSP;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+ }
+ }
+
+ /**
+ * This implements SRC_OVER for Int packed data where the src is
+ * premultiplied.
+ */
+ public static class OverCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext_INT_PACK {
+ OverCompositeContext_INT_PACK(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, dstInP, dstM;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstInP = dstInPixels[dstInSp++];
+
+ dstM = (255-(srcP>>>24))*norm;
+ dstOutPixels[dstOutSp++] =
+ ((( srcP & 0xFF000000) +
+ (((((dstInP>>>24) )*dstM+pt5)&0xFF000000) ))|
+ (( srcP & 0x00FF0000) +
+ (((((dstInP>> 16)&0xFF)*dstM+pt5)&0xFF000000)>>> 8))|
+ (( srcP & 0x0000FF00) +
+ (((((dstInP>> 8)&0xFF)*dstM+pt5)&0xFF000000)>>>16))|
+ (( srcP & 0x000000FF) +
+ (((((dstInP )&0xFF)*dstM+pt5) )>>>24)));
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+ /**
+ * This implements SRC_OVER for Int packed data and dest has no Alpha...
+ */
+ public static class OverCompositeContext_INT_PACK_NA
+ extends AlphaPreCompositeContext_INT_PACK {
+ OverCompositeContext_INT_PACK_NA(ColorModel srcCM, ColorModel dstCM) {
+ super (srcCM, dstCM);
+ }
+
+ // When we get here src data has been premultiplied.
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, dstInP, dstM;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstInP = dstInPixels[dstInSp++];
+
+ dstM = (255-(srcP>>>24))*norm;
+ dstOutPixels[dstOutSp++] =
+ ((( srcP & 0x00FF0000) +
+ (((((dstInP>> 16)&0xFF)*dstM+pt5)&0xFF000000)>>> 8))|
+ (( srcP & 0x0000FF00) +
+ (((((dstInP>> 8)&0xFF)*dstM+pt5)&0xFF000000)>>>16))|
+ (( srcP & 0x000000FF) +
+ (((((dstInP )&0xFF)*dstM+pt5) )>>>24)));
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+ /**
+ * This implements SRC_OVER for Int packed data where the src is
+ * unpremultiplied. This avoids having to multiply the alpha on the
+ * the source then divide it out again.
+ */
+ public static class OverCompositeContext_INT_PACK_UNPRE
+ extends AlphaPreCompositeContext_INT_PACK {
+ OverCompositeContext_INT_PACK_UNPRE
+ (ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+
+ if (srcCM.isAlphaPremultiplied())
+ throw new IllegalArgumentException
+ ("OverCompositeContext_INT_PACK_UNPRE is only for" +
+ "sources with unpremultiplied alpha");
+ }
+
+ public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
+ ColorModel dstPreCM = dstCM;
+ if (!dstCM.isAlphaPremultiplied())
+ dstPreCM = GraphicsUtil.coerceData((WritableRaster)dstIn,
+ dstCM, true);
+
+ precompose(src, dstIn, dstOut);
+
+ if (!dstCM.isAlphaPremultiplied()) {
+ GraphicsUtil.coerceData(dstOut, dstPreCM, false);
+
+ if (dstIn != dstOut)
+ GraphicsUtil.coerceData((WritableRaster)dstIn,
+ dstPreCM, false);
+ }
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, srcM, dstP, dstM;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstP = dstInPixels[dstInSp++];
+
+ srcM = ( (srcP>>>24))*norm;
+ dstM = (255-(srcP>>>24))*norm;
+
+ dstOutPixels[dstOutSp++] =
+ ((((( srcP&0xFF000000) +
+ ((dstP>>>24) )*dstM + pt5)&0xFF000000) ) |
+ (((((srcP>> 16)&0xFF)*srcM +
+ ((dstP>> 16)&0xFF)*dstM + pt5)&0xFF000000)>>> 8) |
+ (((((srcP>> 8)&0xFF)*srcM +
+ ((dstP>> 8)&0xFF)*dstM + pt5)&0xFF000000)>>>16) |
+ (((((srcP )&0xFF)*srcM +
+ ((dstP )&0xFF)*dstM + pt5) )>>>24));
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+ public static class InCompositeContext
+ extends AlphaPreCompositeContext {
+ InCompositeContext(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ for (int y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ int sp = 0;
+ int end = w*4;
+ while(sp<end) {
+ final int srcM = dstPix[sp+3]*norm;
+ dstPix[sp] = (srcPix[sp]*srcM + pt5)>>>24; ++sp;
+ dstPix[sp] = (srcPix[sp]*srcM + pt5)>>>24; ++sp;
+ dstPix[sp] = (srcPix[sp]*srcM + pt5)>>>24; ++sp;
+ dstPix[sp] = (srcPix[sp]*srcM + pt5)>>>24; ++sp;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+
+ }
+ }
+
+ public static class InCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext_INT_PACK {
+ InCompositeContext_INT_PACK(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, srcM;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcM = (dstInPixels[dstInSp++]>>>24)*norm;
+ srcP = srcPixels [srcSp++];
+ dstOutPixels[dstOutSp++] =
+ ((((((srcP>>>24) )*srcM + pt5)&0xFF000000) ) |
+ (((((srcP>> 16)&0xFF)*srcM + pt5)&0xFF000000)>>> 8) |
+ (((((srcP>> 8)&0xFF)*srcM + pt5)&0xFF000000)>>>16) |
+ (((((srcP )&0xFF)*srcM + pt5) )>>>24));
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+ public static class OutCompositeContext
+ extends AlphaPreCompositeContext {
+ OutCompositeContext(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ for (int y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ int sp = 0;
+ int end = w*4;
+ while(sp<end) {
+ final int srcM = (255-dstPix[sp+3])*norm;
+ dstPix[sp] = (srcPix[sp]*srcM + pt5)>>>24; ++sp;
+ dstPix[sp] = (srcPix[sp]*srcM + pt5)>>>24; ++sp;
+ dstPix[sp] = (srcPix[sp]*srcM + pt5)>>>24; ++sp;
+ dstPix[sp] = (srcPix[sp]*srcM + pt5)>>>24; ++sp;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+
+ }
+ }
+
+ public static class OutCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext_INT_PACK {
+ OutCompositeContext_INT_PACK(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, srcM;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcM = (255-(dstInPixels[dstInSp++]>>>24))*norm;
+ srcP = srcPixels [srcSp++];
+ dstOutPixels[dstOutSp++] =
+ ((((((srcP>>>24) )*srcM + pt5)&0xFF000000) ) |
+ (((((srcP>> 16)&0xFF)*srcM + pt5)&0xFF000000)>>> 8) |
+ (((((srcP>> 8)&0xFF)*srcM + pt5)&0xFF000000)>>>16) |
+ (((((srcP )&0xFF)*srcM + pt5) )>>>24));
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+ public static class AtopCompositeContext
+ extends AlphaPreCompositeContext {
+ AtopCompositeContext(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ for (int y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ int sp = 0;
+ int end = w*4;
+ while(sp<end) {
+ final int srcM = ( dstPix[sp+3])*norm;
+ final int dstM = (255-srcPix[sp+3])*norm;
+ dstPix[sp] =(srcPix[sp]*srcM + dstPix[sp]*dstM +pt5)>>>24;
+ ++sp;
+ dstPix[sp] =(srcPix[sp]*srcM + dstPix[sp]*dstM +pt5)>>>24;
+ ++sp;
+ dstPix[sp] =(srcPix[sp]*srcM + dstPix[sp]*dstM +pt5)>>>24;
+ sp+=2;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+
+ }
+ }
+
+ public static class AtopCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext_INT_PACK {
+ AtopCompositeContext_INT_PACK(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, srcM, dstP, dstM;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstP = dstInPixels[dstInSp++];
+
+ srcM = ( dstP>>>24) *norm;
+ dstM = (255-(srcP>>>24))*norm;
+
+ dstOutPixels[dstOutSp++] =
+ ((dstP&0xFF000000) |
+ (((((srcP>> 16)&0xFF)*srcM +
+ ((dstP>> 16)&0xFF)*dstM + pt5)&0xFF000000)>>> 8) |
+ (((((srcP>> 8)&0xFF)*srcM +
+ ((dstP>> 8)&0xFF)*dstM + pt5)&0xFF000000)>>>16) |
+ (((((srcP )&0xFF)*srcM +
+ ((dstP )&0xFF)*dstM + pt5) )>>>24));
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+ public static class XorCompositeContext
+ extends AlphaPreCompositeContext {
+
+ XorCompositeContext(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ for (int y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ int sp = 0;
+ int end = w*4;
+ while(sp<end) {
+ final int srcM = (255-dstPix[sp+3])*norm;
+ final int dstM = (255-srcPix[sp+3])*norm;
+
+ dstPix[sp] = (srcPix[sp]*srcM +
+ dstPix[sp]*dstM + pt5)>>>24; ++sp;
+ dstPix[sp] = (srcPix[sp]*srcM +
+ dstPix[sp]*dstM + pt5)>>>24; ++sp;
+ dstPix[sp] = (srcPix[sp]*srcM +
+ dstPix[sp]*dstM + pt5)>>>24; ++sp;
+ dstPix[sp] = (srcPix[sp]*srcM +
+ dstPix[sp]*dstM + pt5)>>>24; ++sp;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+
+ }
+ }
+
+ public static class XorCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext_INT_PACK {
+ XorCompositeContext_INT_PACK(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, srcM, dstP, dstM;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstP = dstInPixels[dstInSp++];
+
+ srcM = (255-(dstP>>>24))*norm;
+ dstM = (255-(srcP>>>24))*norm;
+
+ dstOutPixels[dstOutSp++] =
+ ((((((srcP>>>24) )*srcM +
+ ((dstP>>>24) )*dstM + pt5)&0xFF000000) ) |
+ (((((srcP>> 16)&0xFF)*srcM +
+ ((dstP>> 16)&0xFF)*dstM + pt5)&0xFF000000)>>> 8) |
+ (((((srcP>> 8)&0xFF)*srcM +
+ ((dstP>> 8)&0xFF)*dstM + pt5)&0xFF000000)>>>16) |
+ (((((srcP )&0xFF)*srcM +
+ ((dstP )&0xFF)*dstM + pt5) )>>>24));
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+ public static class ArithCompositeContext
+ extends AlphaPreCompositeContext {
+ float k1, k2, k3, k4;
+ ArithCompositeContext(ColorModel srcCM,
+ ColorModel dstCM,
+ float k1, float k2, float k3, float k4) {
+ super(srcCM, dstCM);
+ this.k1 = k1;
+ this.k2 = k2;
+ this.k3 = k3;
+ this.k4 = k4;
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+ int bands = dstOut.getNumBands();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ float kk1 = k1/255.0f;
+ float kk4 = k4*255.0f+0.5f;
+
+ int y, i, b, val, max;
+ for (y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ for (i=0; i<srcPix.length; i++) {
+ max=0;
+ for (b=1; b<bands; b++, i++) {
+ val =(int)((kk1*srcPix[i]*dstPix[i]) +
+ k2*srcPix[i] + k3*dstPix[i] + kk4);
+ if ((val & 0xFFFFFF00) != 0)
+ if ((val & 0x80000000) != 0) val = 0;
+ else val = 255;
+ if (val > max) max=val;
+ dstPix[i] = val;
+ }
+
+ val =(int)((kk1*srcPix[i]*dstPix[i]) +
+ k2*srcPix[i] + k3*dstPix[i] + kk4);
+ if ((val & 0xFFFFFF00) != 0)
+ if ((val & 0x80000000) != 0) val = 0;
+ else val = 255;
+ if (val > max)
+ dstPix[i] = val;
+ else
+ dstPix[i] = max;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+ }
+ }
+
+ public static class ArithCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext_INT_PACK {
+ float k1, k2, k3, k4;
+ ArithCompositeContext_INT_PACK(ColorModel srcCM,
+ ColorModel dstCM,
+ float k1, float k2,
+ float k3, float k4) {
+ super(srcCM, dstCM);
+ this.k1 = k1/255.0f;
+ this.k2 = k2;
+ this.k3 = k3;
+ this.k4 = k4*255.0f+0.5f;
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ int srcP, dstP, a, r, g, b;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstP = dstInPixels [dstInSp++];
+ a = (int)((srcP>>>24)*(dstP>>>24)*k1 +
+ (srcP>>>24)*k2 + (dstP>>>24)*k3 + k4);
+ if ((a & 0xFFFFFF00) != 0)
+ if ((a & 0x80000000) != 0) a = 0;
+ else a = 255;
+
+ r = (int)(((srcP>> 16)&0xFF)*((dstP>> 16)&0xFF)*k1 +
+ ((srcP>> 16)&0xFF)*k2 +
+ ((dstP>> 16)&0xFF)*k3 + k4);
+ if ((r & 0xFFFFFF00) != 0)
+ if ((r & 0x80000000) != 0) r = 0;
+ else r = 255;
+ if (a < r) a = r;
+
+ g = (int)(((srcP>> 8)&0xFF)*((dstP>> 8)&0xFF)*k1 +
+ ((srcP>> 8)&0xFF)*k2 +
+ ((dstP>> 8)&0xFF)*k3 + k4);
+ if ((g & 0xFFFFFF00) != 0)
+ if ((g & 0x80000000) != 0) g = 0;
+ else g = 255;
+ if (a < g) a = g;
+
+ b = (int)((srcP&0xFF)*(dstP&0xFF)*k1 +
+ (srcP&0xFF)*k2 + (dstP&0xFF)*k3 + k4);
+ if ((b & 0xFFFFFF00) != 0)
+ if ((b & 0x80000000) != 0) b = 0;
+ else b = 255;
+ if (a < b) a = b;
+
+ dstOutPixels[dstOutSp++]
+ = ((a<<24) | (r<<16) | (g<<8) | b);
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ // long endTime = System.currentTimeMillis();
+ // System.out.println("Arith Time: " + (endTime-startTime));
+ }
+ }
+
+ public static class ArithCompositeContext_INT_PACK_LUT
+ extends AlphaPreCompositeContext_INT_PACK {
+ byte [] lut;
+ ArithCompositeContext_INT_PACK_LUT(ColorModel srcCM,
+ ColorModel dstCM,
+ float k1, float k2,
+ float k3, float k4) {
+ super(srcCM, dstCM);
+ k1 = k1/255.0f;
+ k4 = k4*255.0f+0.5f;
+ int sz = 256*256;
+ lut = new byte[sz];
+ int val;
+ for (int i=0; i<sz; i++) {
+ val = (int)((i>>8)*(i&0xFF)*k1 + (i>>8)*k2 + (i&0xFF)*k3 + k4);
+ if ((val & 0xFFFFFF00) != 0)
+ if ((val & 0x80000000) != 0) val = 0;
+ else val = 255;
+ lut[i] = (byte)val;
+ }
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ byte[] workTbl = lut; // local is cheaper
+ int srcP, dstP;
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstP = dstInPixels[dstInSp++];
+
+ int a = 0xFF & workTbl[(((srcP>> 16)&0xFF00)|((dstP>>>24) ))];
+ int r = 0xFF & workTbl[(((srcP>> 8)&0xFF00)|((dstP>> 16)&0x00FF))];
+ int g = 0xFF & workTbl[(((srcP )&0xFF00)|((dstP>> 8)&0x00FF))];
+ int b = 0xFF & workTbl[(((srcP<< 8)&0xFF00)|((dstP )&0x00FF))];
+ if (r>a) a = r;
+ if (g>a) a = g;
+ if (b>a) a = b;
+ dstOutPixels[dstOutSp++] = (a<<24)|(r<<16)|(g<<8)|(b);
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ // long endTime = System.currentTimeMillis();
+ // System.out.println("ArithLut Time: " + (endTime-startTime));
+ }
+ }
+
+
+ /**
+ * The following classes implement the various blend modes from SVG. */
+ public static class MultiplyCompositeContext
+ extends AlphaPreCompositeContext {
+
+ MultiplyCompositeContext(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+ int srcM, dstM;
+
+ for (int y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ int sp = 0;
+ int end = w*4;
+ while(sp<end) {
+ srcM = 255-dstPix[sp+3];
+ dstM = 255-srcPix[sp+3];
+
+ dstPix[sp] = ((srcPix[sp]*srcM + dstPix[sp]*dstM +
+ srcPix[sp]*dstPix[sp])*norm + pt5)>>>24;
+ ++sp;
+
+ dstPix[sp] = ((srcPix[sp]*srcM + dstPix[sp]*dstM +
+ srcPix[sp]*dstPix[sp])*norm + pt5)>>>24;
+ ++sp;
+
+ dstPix[sp] = ((srcPix[sp]*srcM + dstPix[sp]*dstM +
+ srcPix[sp]*dstPix[sp])*norm + pt5)>>>24;
+ ++sp;
+
+ dstPix[sp] = (srcPix[sp] + dstPix[sp] -
+ ((dstPix[sp]*srcPix[sp]*norm + pt5)>>>24));
+ ++sp;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+ }
+ }
+
+ public static class MultiplyCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext_INT_PACK {
+ MultiplyCompositeContext_INT_PACK(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, srcA, srcR, srcG, srcB, srcM;
+ int dstP, dstA, dstR, dstG, dstB, dstM;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstP = dstInPixels[dstInSp++];
+
+ srcA = (srcP>>>24);
+ dstA = (dstP>>>24);
+ srcR = (srcP>> 16)&0xFF;
+ dstR = (dstP>> 16)&0xFF;
+ srcG = (srcP>> 8)&0xFF;
+ dstG = (dstP>> 8)&0xFF;
+ srcB = (srcP )&0xFF;
+ dstB = (dstP )&0xFF;
+
+ srcM = 255-dstA;
+ dstM = 255-srcA;
+
+ dstOutPixels[dstOutSp++] =
+ (((((srcR*srcM + dstR*dstM + srcR*dstR)
+ *norm + pt5)&0xFF000000)>>> 8) |
+ ((((srcG*srcM + dstG*dstM + srcG*dstG)
+ *norm + pt5)&0xFF000000)>>>16) |
+ ((((srcB*srcM + dstB*dstM + srcB*dstB)
+ *norm + pt5) )>>>24) |
+ ((srcA + dstA - ((srcA*dstA*norm + pt5)>>>24))<<24));
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+ public static class ScreenCompositeContext
+ extends AlphaPreCompositeContext {
+
+ ScreenCompositeContext(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ for (int y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ int sp = 0;
+ int end = w*4;
+ while(sp<end) {
+
+ int iSrcPix = srcPix[ sp ];
+ int iDstPix = dstPix[ sp ];
+
+ dstPix[sp] = ( iSrcPix + iDstPix -
+ ((iDstPix*iSrcPix*norm + pt5)>>>24));
+ ++sp;
+ iSrcPix = srcPix[ sp ];
+ iDstPix = dstPix[ sp ];
+ dstPix[sp] = ( iSrcPix + iDstPix -
+ ((iDstPix*iSrcPix*norm + pt5)>>>24));
+ ++sp;
+ iSrcPix = srcPix[ sp ];
+ iDstPix = dstPix[ sp ];
+ dstPix[sp] = ( iSrcPix + iDstPix -
+ ((iDstPix*iSrcPix*norm + pt5)>>>24));
+ ++sp;
+ iSrcPix = srcPix[ sp ];
+ iDstPix = dstPix[ sp ];
+ dstPix[sp] = ( iSrcPix + iDstPix -
+ ((iDstPix*iSrcPix*norm + pt5)>>>24));
+ ++sp;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+ }
+ }
+
+ public static class ScreenCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext_INT_PACK {
+ ScreenCompositeContext_INT_PACK(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, srcA, srcR, srcG, srcB;
+ int dstP, dstA, dstR, dstG, dstB;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstP = dstInPixels[dstInSp++];
+
+ srcA = (srcP>>>24);
+ dstA = (dstP>>>24);
+ srcR = (srcP>> 16)&0xFF;
+ dstR = (dstP>> 16)&0xFF;
+ srcG = (srcP>> 8)&0xFF;
+ dstG = (dstP>> 8)&0xFF;
+ srcB = (srcP )&0xFF;
+ dstB = (dstP )&0xFF;
+
+ dstOutPixels[dstOutSp++] =
+ (((srcR + dstR - ((srcR*dstR*norm + pt5)>>>24))<<16)|
+ ((srcG + dstG - ((srcG*dstG*norm + pt5)>>>24))<< 8)|
+ ((srcB + dstB - ((srcB*dstB*norm + pt5)>>>24)) )|
+ ((srcA + dstA - ((srcA*dstA*norm + pt5)>>>24))<<24));
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+ public static class DarkenCompositeContext
+ extends AlphaPreCompositeContext {
+
+ DarkenCompositeContext(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int sp, srcM, dstM, t1, t2;
+
+ for (int y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ sp = 0;
+ final int end = w*4;
+ while(sp<end) {
+ srcM = 255-dstPix[sp+3];
+ dstM = 255-srcPix[sp+3];
+
+ t1 = ((srcM*srcPix[sp]*norm + pt5)>>>24) + dstPix[sp];
+ t2 = ((dstM*dstPix[sp]*norm + pt5)>>>24) + srcPix[sp];
+ if (t1 > t2) dstPix[sp] = t2;
+ else dstPix[sp] = t1;
+ ++sp;
+
+ t1 = ((srcM*srcPix[sp]*norm + pt5)>>>24) + dstPix[sp];
+ t2 = ((dstM*dstPix[sp]*norm + pt5)>>>24) + srcPix[sp];
+ if (t1 > t2) dstPix[sp] = t2;
+ else dstPix[sp] = t1;
+ ++sp;
+
+ t1 = ((srcM*srcPix[sp]*norm + pt5)>>>24) + dstPix[sp];
+ t2 = ((dstM*dstPix[sp]*norm + pt5)>>>24) + srcPix[sp];
+ if (t1 > t2) dstPix[sp] = t2;
+ else dstPix[sp] = t1;
+ ++sp;
+
+ dstPix[sp] = (srcPix[sp] + dstPix[sp] -
+ ((dstPix[sp]*srcPix[sp]*norm + pt5)>>>24));
+ ++sp;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+ }
+ }
+
+ public static class DarkenCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext_INT_PACK {
+ DarkenCompositeContext_INT_PACK(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, srcM;
+ int dstP, dstM, dstA, dstR, dstG, dstB;
+
+ int srcV, dstV, tmp;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstP = dstInPixels[dstInSp++];
+
+ srcV = (srcP>>>24);
+ dstV = (dstP>>>24);
+ srcM = (255-dstV)*norm;
+ dstM = (255-srcV)*norm;
+ dstA = (srcV + dstV - ((srcV*dstV*norm + pt5)>>>24));
+
+ srcV = (srcP>> 16)&0xFF;
+ dstV = (dstP>> 16)&0xFF;
+ dstR = ((srcM*srcV + pt5)>>>24) + dstV;
+ tmp = ((dstM*dstV + pt5)>>>24) + srcV;
+ if (dstR > tmp) dstR = tmp;
+
+ srcV = (srcP>> 8)&0xFF;
+ dstV = (dstP>> 8)&0xFF;
+ dstG = ((srcM*srcV + pt5)>>>24) + dstV;
+ tmp = ((dstM*dstV + pt5)>>>24) + srcV;
+ if (dstG > tmp) dstG = tmp;
+
+
+ srcV = (srcP )&0xFF;
+ dstV = (dstP )&0xFF;
+ dstB = ((srcM*srcV + pt5)>>>24) + dstV;
+ tmp = ((dstM*dstV + pt5)>>>24) + srcV;
+ if (dstB > tmp) dstB = tmp;
+
+ dstA &= 0xFF; // trim to 8 bit
+ dstR &= 0xFF;
+ dstG &= 0xFF;
+ dstB &= 0xFF;
+
+ dstOutPixels[dstOutSp++] =
+ ((dstA<<24) | (dstR<<16) | (dstG<< 8) | dstB);
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+ public static class LightenCompositeContext
+ extends AlphaPreCompositeContext {
+
+ LightenCompositeContext(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose(Raster src, Raster dstIn,
+ WritableRaster dstOut) {
+ int [] srcPix = null;
+ int [] dstPix = null;
+
+ int x=dstOut.getMinX();
+ int w=dstOut.getWidth();
+
+ int y0=dstOut.getMinY();
+ int y1=y0 + dstOut.getHeight();
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int sp, srcM, dstM, t1, t2;
+
+ for (int y = y0; y<y1; y++) {
+ srcPix = src.getPixels (x, y, w, 1, srcPix);
+ dstPix = dstIn.getPixels(x, y, w, 1, dstPix);
+ sp = 0;
+ final int end = w*4;
+ while(sp<end) {
+ srcM = 255-dstPix[sp+3];
+ dstM = 255-srcPix[sp+3];
+
+ t1 = ((srcM*srcPix[sp]*norm + pt5)>>>24) + dstPix[sp];
+ t2 = ((dstM*dstPix[sp]*norm + pt5)>>>24) + srcPix[sp];
+ if (t1 > t2) dstPix[sp] = t1;
+ else dstPix[sp] = t2;
+ ++sp;
+
+ t1 = ((srcM*srcPix[sp]*norm + pt5)>>>24) + dstPix[sp];
+ t2 = ((dstM*dstPix[sp]*norm + pt5)>>>24) + srcPix[sp];
+ if (t1 > t2) dstPix[sp] = t1;
+ else dstPix[sp] = t2;
+ ++sp;
+
+ t1 = ((srcM*srcPix[sp]*norm + pt5)>>>24) + dstPix[sp];
+ t2 = ((dstM*dstPix[sp]*norm + pt5)>>>24) + srcPix[sp];
+ if (t1 > t2) dstPix[sp] = t1;
+ else dstPix[sp] = t2;
+ ++sp;
+
+ dstPix[sp] = (srcPix[sp] + dstPix[sp] -
+ ((dstPix[sp]*srcPix[sp]*norm + pt5)>>>24));
+ ++sp;
+ }
+ dstOut.setPixels(x, y, w, 1, dstPix);
+ }
+ }
+ }
+
+ public static class LightenCompositeContext_INT_PACK
+ extends AlphaPreCompositeContext_INT_PACK {
+ LightenCompositeContext_INT_PACK(ColorModel srcCM, ColorModel dstCM) {
+ super(srcCM, dstCM);
+ }
+
+ public void precompose_INT_PACK
+ (final int width, final int height,
+ final int [] srcPixels, final int srcAdjust, int srcSp,
+ final int [] dstInPixels, final int dstInAdjust, int dstInSp,
+ final int [] dstOutPixels, final int dstOutAdjust, int dstOutSp) {
+
+ final int norm = (1<<24)/255;
+ final int pt5 = (1<<23);
+
+ int srcP, srcM;
+ int dstP, dstM, dstA, dstR, dstG, dstB;
+
+ int srcV, dstV, tmp;
+
+ for (int y = 0; y<height; y++) {
+ final int end = dstOutSp+width;
+ while (dstOutSp<end) {
+ srcP = srcPixels [srcSp++];
+ dstP = dstInPixels[dstInSp++];
+
+ srcV = (srcP>>>24);
+ dstV = (dstP>>>24);
+ srcM = (255-dstV)*norm;
+ dstM = (255-srcV)*norm;
+ dstA = (srcV + dstV - ((srcV*dstV*norm + pt5)>>>24));
+
+ srcV = (srcP>> 16)&0xFF;
+ dstV = (dstP>> 16)&0xFF;
+ dstR = ((srcM*srcV + pt5)>>>24) + dstV;
+ tmp = ((dstM*dstV + pt5)>>>24) + srcV;
+ if (dstR < tmp) dstR = tmp;
+
+ srcV = (srcP>> 8)&0xFF;
+ dstV = (dstP>> 8)&0xFF;
+ dstG = ((srcM*srcV + pt5)>>>24) + dstV;
+ tmp = ((dstM*dstV + pt5)>>>24) + srcV;
+ if (dstG < tmp) dstG = tmp;
+
+
+ srcV = (srcP )&0xFF;
+ dstV = (dstP )&0xFF;
+ dstB = ((srcM*srcV + pt5)>>>24) + dstV;
+ tmp = ((dstM*dstV + pt5)>>>24) + srcV;
+ if (dstB < tmp) dstB = tmp;
+
+ dstA &= 0xFF; // trim to 8 bit
+ dstR &= 0xFF;
+ dstG &= 0xFF;
+ dstB &= 0xFF;
+
+ dstOutPixels[dstOutSp++] =
+ ((dstA<<24) | (dstR<<16) | (dstG<< 8) | dstB);
+ }
+ srcSp += srcAdjust;
+ dstInSp += dstInAdjust;
+ dstOutSp += dstOutAdjust;
+ }
+ }
+ }
+
+}
Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/SVGComposite.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/SpotLight.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/SpotLight.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/SpotLight.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/SpotLight.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,241 @@
+/*
+
+ 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;
+
+import java.awt.Color;
+
+/**
+ * A light source which emits a light of constant intensity in all directions.
+ *
+ * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
+ * @version $Id: SpotLight.java 501495 2007-01-30 18:00:36Z dvholten $
+ */
+public class SpotLight extends AbstractLight {
+ /**
+ * The light position, in user space
+ */
+ private double lightX, lightY, lightZ;
+
+ /**
+ * Point where the light points to
+ */
+ private double pointAtX, pointAtY, pointAtZ;
+
+ /**
+ * Specular exponent (light focus)
+ */
+ private double specularExponent;
+
+ /**
+ * Limiting cone angle
+ */
+ private double limitingConeAngle, limitingCos;
+
+ /**
+ * Light direction vector
+ */
+ private final double[] S = new double[3];
+
+ /**
+ * @return the light's x position
+ */
+ public double getLightX(){
+ return lightX;
+ }
+
+ /**
+ * @return the light's y position
+ */
+ public double getLightY(){
+ return lightY;
+ }
+
+ /**
+ * @return the light's z position
+ */
+ public double getLightZ(){
+ return lightZ;
+ }
+
+ /**
+ * @return x-axis coordinate where the light points to
+ */
+ public double getPointAtX(){
+ return pointAtX;
+ }
+
+ /**
+ * @return y-axis coordinate where the light points to
+ */
+ public double getPointAtY(){
+ return pointAtY;
+ }
+
+ /**
+ * @return z-axis coordinate where the light points to
+ */
+ public double getPointAtZ(){
+ return pointAtZ;
+ }
+
+ /**
+ * @return light's specular exponent (focus)
+ */
+ public double getSpecularExponent(){
+ return specularExponent;
+ }
+
+ /**
+ * @return light's limiting cone angle
+ */
+ public double getLimitingConeAngle(){
+ return limitingConeAngle;
+ }
+
+ public SpotLight(double lightX, double lightY, double lightZ,
+ double pointAtX, double pointAtY, double pointAtZ,
+ double specularExponent, double limitingConeAngle,
+ Color lightColor){
+ super(lightColor);
+
+ this.lightX = lightX;
+ this.lightY = lightY;
+ this.lightZ = lightZ;
+ this.pointAtX = pointAtX;
+ this.pointAtY = pointAtY;
+ this.pointAtZ = pointAtZ;
+ this.specularExponent = specularExponent;
+ this.limitingConeAngle = limitingConeAngle;
+ this.limitingCos = Math.cos( Math.toRadians( limitingConeAngle ) );
+
+ S[0] = pointAtX - lightX;
+ S[1] = pointAtY - lightY;
+ S[2] = pointAtZ - lightZ;
+
+ double invNorm = 1/Math.sqrt(S[0]*S[0] + S[1]*S[1] + S[2]*S[2]);
+
+ S[0] *= invNorm;
+ S[1] *= invNorm;
+ S[2] *= invNorm;
+ }
+
+ /**
+ * @return true if the light is constant over the whole surface
+ */
+ public boolean isConstant(){
+ return false;
+ }
+
+ /**
+ * Computes the light vector in (x, y, z)
+ *
+ * @param x x-axis coordinate where the light should be computed
+ * @param y y-axis coordinate where the light should be computed
+ * @param z z-axis coordinate where the light should be computed
+ * @param L array of length 3 where the result is stored
+ * @return the intensity factor for this light vector.
+ */
+ public final double getLightBase(final double x, final double y,
+ final double z,
+ final double[] L){
+ // Light Vector, L
+ double L0 = lightX - x;
+ double L1 = lightY - y;
+ double L2 = lightZ - z;
+
+ final double invNorm = 1.0/Math.sqrt( L0*L0 + L1*L1 + L2*L2 );
+
+ L0 *= invNorm;
+ L1 *= invNorm;
+ L2 *= invNorm;
+
+ double LS = -(L0*S[0] + L1*S[1] + L2*S[2]);
+
+ // copy the work-variables into return-array
+ L[0] = L0;
+ L[1] = L1;
+ L[2] = L2;
+
+ if(LS <= limitingCos){
+ return 0;
+ } else {
+ double Iatt = limitingCos/LS;
+ Iatt *= Iatt;
+ Iatt *= Iatt;
+ Iatt *= Iatt;
+ Iatt *= Iatt;
+ Iatt *= Iatt;
+ Iatt *= Iatt; // akin Math.pow(Iatt, 64)
+
+ Iatt = 1 - Iatt;
+ return Iatt*Math.pow(LS, specularExponent);
+ }
+ }
+
+ /**
+ * Computes the light vector in (x, y, z)
+ *
+ * @param x x-axis coordinate where the light should be computed
+ * @param y y-axis coordinate where the light should be computed
+ * @param z z-axis coordinate where the light should be computed
+ * @param L array of length 3 where the result is stored,
+ * x,y,z are scaled by light intensity.
+ */
+ public final void getLight(final double x, final double y,
+ final double z,
+ final double[] L){
+ final double s = getLightBase(x, y, z, L);
+ L[0] *= s;
+ L[1] *= s;
+ L[2] *= s;
+ }
+
+ /**
+ * computes light vector in (x, y, z).
+ *
+ * @param x x-axis coordinate where the light should be computed
+ * @param y y-axis coordinate where the light should be computed
+ * @param z z-axis coordinate where the light should be computed
+ * @param L array of length 4 where result is stored.
+ * 0,1,2 are x,y,z respectively of light vector (normalized).
+ * 3 is the intensity of the light at this point.
+ */
+ public final void getLight4(final double x, final double y, final double z,
+ final double[] L){
+ L[3] = getLightBase(x, y, z, L);
+ }
+
+ public double[][] getLightRow4(double x, double y,
+ final double dx, final int width,
+ final double[][] z,
+ final double[][] lightRow) {
+ double [][] ret = lightRow;
+ if (ret == null)
+ ret = new double[width][4];
+
+ for(int i=0; i<width; i++){
+ getLight4(x, y, z[i][3], ret[i]);
+ x += dx;
+ }
+
+ return ret;
+ }
+
+}
+
Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/SpotLight.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/TableTransfer.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/TableTransfer.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/TableTransfer.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/TableTransfer.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,97 @@
+/*
+
+ 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;
+
+
+/**
+ * TableTransfer.java
+ *
+ * This class defines the Table type transfer function for the
+ * feComponentTransfer filter, as defined in chapter 15, section 11 of the SVG
+ * specification.
+ *
+ * @author <a href="mailto:sheng.pei@sun.com">Sheng Pei</a>
+ * @version $Id: TableTransfer.java 475477 2006-11-15 22:44:28Z cam $
+ */
+public class TableTransfer implements TransferFunction {
+ /**
+ * This byte array stores the lookuptable data
+ */
+ public byte [] lutData;
+
+ /**
+ * This int array is the input table values from the user
+ */
+ public int [] tableValues;
+
+ /*
+ * The number of the input table's elements
+ */
+ private int n;
+
+ /*
+ * The input is an int array which will be used
+ * later to construct the lut data
+ */
+ public TableTransfer(int [] tableValues){
+ this.tableValues = tableValues;
+ this.n = tableValues.length;
+ }
+
+ /*
+ * This method will build the lut data. Each entry's
+ * value will increase/decrease between the nearby
+ * intervals.
+ */
+ private void buildLutData(){
+ lutData = new byte [256];
+ int j;
+ float fi, r;
+ int ffi, cfi;
+
+ /*for (j=0; j<n; j++){
+ System.out.println("tableValues[" + j + "] = " + tableValues[j]);
+ }*/
+
+ for (j=0; j<=255; j++){
+ fi = j*(n-1)/255f;
+ ffi = (int)Math.floor(fi);
+ cfi = (ffi + 1)>(n-1)?(n-1):(ffi+1);
+ r = fi - ffi;
+ lutData[j] = (byte)((int)((tableValues[ffi] + r*(tableValues[cfi] - tableValues[ffi])))&0xff);
+ // System.out.println("[" + j + "] : " + ffi + "/" + cfi + "/" + r);
+ }
+
+ /*for(j=0; j<=255; j++){
+ System.out.print("[" + j + "] = " + (0xff & lutData[j]) + " ");
+ }
+
+ System.out.println();
+ System.out.println();*/
+ }
+
+ /**
+ * This method will return the lut data in order
+ * to construct a LookUpTable object
+ */
+ public byte [] getLookupTable(){
+ buildLutData();
+ return lutData;
+ }
+}
Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/TableTransfer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/TransferFunction.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/TransferFunction.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/TransferFunction.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/TransferFunction.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,35 @@
+/*
+
+ 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;
+
+/**
+ * Defines the interface for all the <tt>ComponentTransferOp</tt> transfer
+ * functions, which can all be converted to a lookup table
+ *
+ * @author <a href="mailto:sheng.pei@eng.sun.com">Sheng Pei</a>
+ * @version $Id: TransferFunction.java 479564 2006-11-27 09:56:57Z dvholten $
+ */
+public interface TransferFunction {
+
+ /**
+ * Returns the lookup table.
+ */
+ byte[] getLookupTable();
+
+}
Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/TransferFunction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/URLImageCache.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/URLImageCache.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/URLImageCache.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/URLImageCache.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,103 @@
+/*
+
+ 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;
+
+import org.apache.flex.forks.batik.ext.awt.image.renderable.Filter;
+import org.apache.flex.forks.batik.util.ParsedURL;
+import org.apache.flex.forks.batik.util.SoftReferenceCache;
+
+/**
+ * This class manages a cache of soft references to Images that
+ * we have already loaded.
+ *
+ * <p>
+ * Adding an image is two fold. First you add the ParsedURL, this lets
+ * the cache know that someone is working on this ParsedURL. Then when
+ * the completed RenderedImage is ready you put it into the cache.
+ * </p>
+ * <p>
+ * If someone requests a ParsedURL after it has been added but before it has
+ * been put they will be blocked until the put.
+ * </p>
+ *
+ * @author <a href="mailto:thomas.deweese@kodak.com">Thomas DeWeese</a>
+ * @version $Id: URLImageCache.java 475477 2006-11-15 22:44:28Z cam $
+ */
+public class URLImageCache extends SoftReferenceCache {
+
+ static URLImageCache theCache = new URLImageCache();
+
+ public static URLImageCache getDefaultCache() { return theCache; }
+
+ /**
+ * Let people create there own caches.
+ */
+ public URLImageCache() { }
+
+ /**
+ * Check if <tt>request(url)</tt> will return with a Filter
+ * (not putting you on the hook for it). Note that it is possible
+ * that this will return true but between this call and the call
+ * to request the soft-reference will be cleared. So it
+ * is still possible for request to return NULL, just much less
+ * likely (you can always call 'clear' in that case).
+ */
+ public synchronized boolean isPresent(ParsedURL purl) {
+ return super.isPresentImpl(purl);
+ }
+
+ /**
+ * Check if <tt>request(url)</tt> will return immediately with the
+ * Filter. Note that it is possible that this will return
+ * true but between this call and the call to request the
+ * soft-reference will be cleared.
+ */
+ public synchronized boolean isDone(ParsedURL purl) {
+ return super.isDoneImpl(purl);
+ }
+
+ /**
+ * If this returns null then you are now 'on the hook'.
+ * to put the Filter associated with ParsedURL into the
+ * cache. */
+ public synchronized Filter request(ParsedURL purl) {
+ return (Filter)super.requestImpl(purl);
+ }
+
+ /**
+ * Clear the entry for ParsedURL.
+ * This is the easiest way to 'get off the hook'.
+ * if you didn't indend to get on it.
+ */
+ public synchronized void clear(ParsedURL purl) {
+ super.clearImpl(purl);
+ }
+
+ /**
+ * Associate bi with purl. bi is only referenced through
+ * a soft reference so don't rely on the cache to keep it
+ * around. If the map no longer contains our purl it was
+ * probably cleared or flushed since we were put on the hook
+ * for it, so in that case we will do nothing.
+ */
+ public synchronized void put(ParsedURL purl, Filter filt) {
+ super.putImpl(purl, filt);
+ }
+}
Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/URLImageCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/codec/jpeg/JPEGImageWriter.java
URL: http://svn.apache.org/viewvc/incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/codec/jpeg/JPEGImageWriter.java?rev=1402274&view=auto
==============================================================================
--- incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/codec/jpeg/JPEGImageWriter.java (added)
+++ incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/codec/jpeg/JPEGImageWriter.java Thu Oct 25 19:01:43 2012
@@ -0,0 +1,83 @@
+/*
+
+ 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.codec.jpeg;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.RenderedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.flex.forks.batik.ext.awt.image.GraphicsUtil;
+import org.apache.flex.forks.batik.ext.awt.image.spi.ImageWriter;
+import org.apache.flex.forks.batik.ext.awt.image.spi.ImageWriterParams;
+
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGEncodeParam;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
+
+/**
+ * ImageWriter implementation that uses the sun.com.image.codec.jpeg
+ * intefaces to write JPEG files.
+ *
+ * @version $Id: JPEGImageWriter.java 582434 2007-10-06 02:11:51Z cam $
+ */
+public class JPEGImageWriter implements ImageWriter {
+
+ /**
+ * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream)
+ */
+ public void writeImage(RenderedImage image, OutputStream out)
+ throws IOException {
+ writeImage(image, out, null);
+ }
+
+ /**
+ * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream, org.apache.flex.forks.batik.ext.awt.image.spi.ImageWriterParams)
+ */
+ public void writeImage(RenderedImage image, OutputStream out,
+ ImageWriterParams params) throws IOException {
+ BufferedImage bi;
+ if (image instanceof BufferedImage) {
+ bi = (BufferedImage)image;
+ } else {
+ //TODO Is this the right way?
+ bi = GraphicsUtil.makeLinearBufferedImage(
+ image.getWidth(), image.getHeight(), false);
+ }
+ JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
+ if (params != null) {
+ JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
+ if (params.getJPEGQuality() != null) {
+ param.setQuality(
+ params.getJPEGQuality().floatValue(),
+ params.getJPEGForceBaseline().booleanValue());
+ }
+ encoder.encode(bi, param);
+ } else {
+ encoder.encode(bi);
+ }
+ }
+
+ /**
+ * @see ImageWriter#getMIMEType()
+ */
+ public String getMIMEType() {
+ return "image/jpeg";
+ }
+}
Propchange: incubator/flex/sdk/branches/develop/modules/thirdparty/batik/sources/org/apache/flex/forks/batik/ext/awt/image/codec/jpeg/JPEGImageWriter.java
------------------------------------------------------------------------------
svn:eol-style = native