deweese     01/12/05 05:46:05

  Modified:    sources/org/apache/batik/ext/awt/image GraphicsUtil.java
                        SVGComposite.java
               sources/org/apache/batik/ext/awt/image/renderable
                        ConvolveMatrixRable8Bit.java
               sources/org/apache/batik/ext/awt/image/rendered
                        FilterAlphaRed.java PadRed.java
               test-resources/org/apache/batik/test samplesRendering.xml
               test-sources/org/apache/batik/test/svg
                        ParametrizedRenderingAccuracyTest.java
                        PreconfiguredRenderingTest.java
                        SVGRenderingAccuracyTest.java
               test-sources/org/apache/batik/test/util
                        ImageCompareTest.java
  Log:
  1) Fixed a bug with SourceAlpha in filters.
  2) Fixed a bug in alpha handling for Convolution Kernels with negative
     values.
  3) Fixed a bug in alpha handling for some Arithmetic composites.
  4) Fixed bookOfKells.svgz in regard.
  5) Diffs no longer use Arithmetic composite for generating difference image
     (alpha would now be wrong).
  
  Revision  Changes    Path
  1.21      +9 -5      
xml-batik/sources/org/apache/batik/ext/awt/image/GraphicsUtil.java
  
  Index: GraphicsUtil.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/GraphicsUtil.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- GraphicsUtil.java 2001/11/29 15:05:26     1.20
  +++ GraphicsUtil.java 2001/12/05 13:46:04     1.21
  @@ -66,7 +66,7 @@
    * implementations.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
  - * @version $Id: GraphicsUtil.java,v 1.20 2001/11/29 15:05:26 deweese Exp $
  + * @version $Id: GraphicsUtil.java,v 1.21 2001/12/05 13:46:04 deweese Exp $
    */
   public class GraphicsUtil {
   
  @@ -376,6 +376,10 @@
                           trans = AffineTransform.getTranslateInstance(iR.x, 
                                                                        iR.y);
   
  +                        // String label = "sub [" + x + ", " + y + "]: ";
  +                        // org.ImageDisplay.showImage
  +                        //     (label, subBI);
  +
                           g2d.drawImage(subBI, trans, null);
                           // big2d.fillRect(0, 0, tw, th);
                       }
  @@ -1386,20 +1390,20 @@
               = (db.getOffset() +
                  sppsm.getOffset(wr.getMinX()-wr.getSampleModelTranslateX(),
                                  wr.getMinY()-wr.getSampleModelTranslateY()));
  -        int n=0;
  +        int pixel, a, aFP, n=0;
           // Access the pixel data array
           final int pixels[] = db.getBankData()[0];
           for (int y=0; y<wr.getHeight(); y++) {
               int sp = base + y*scanStride;
               final int end = sp + width;
               while (sp < end) {
  -                int pixel = pixels[sp];
  -                int a = pixel>>>24;
  +                pixel = pixels[sp];
  +                a = pixel>>>24;
                   if (a<=0) {
                       pixels[sp] = 0x00FFFFFF;
                   }
                   else if (a<255) {
  -                    int aFP = (0x00FF0000/a);
  +                    aFP = (0x00FF0000/a);
                       pixels[sp] =
                           ((a << 24) |
                            (((((pixel&0xFF0000)>>16)*aFP)&0xFF0000)    ) |
  
  
  
  1.3       +39 -19    
xml-batik/sources/org/apache/batik/ext/awt/image/SVGComposite.java
  
  Index: SVGComposite.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/SVGComposite.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SVGComposite.java 2001/11/29 15:05:26     1.2
  +++ SVGComposite.java 2001/12/05 13:46:04     1.3
  @@ -29,7 +29,7 @@
    * This provides an implementation of all the composite rules in SVG.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
  - * @version $Id: SVGComposite.java,v 1.2 2001/11/29 15:05:26 deweese Exp $
  + * @version $Id: SVGComposite.java,v 1.3 2001/12/05 13:46:04 deweese Exp $
    */
   public class SVGComposite
       implements Composite {
  @@ -812,6 +812,7 @@
   
               int x=dstOut.getMinX();
               int w=dstOut.getWidth();
  +            int bands = dstOut.getNumBands();
   
               int y0=dstOut.getMinY();
               int y1=y0 + dstOut.getHeight();
  @@ -819,18 +820,31 @@
               float kk1 = k1/255.0f;
               float kk4 = k4*255.0f+0.5f;
   
  -            int val;
  -            for (int y = y0; y<y1; y++) {
  +            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 (int i=0; i<srcPix.length; i++) {
  +                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;
  -
  -                    dstPix[i] = val;
  +                    if (val > max) 
  +                        dstPix[i] = val;
  +                    else
  +                        dstPix[i] = max;
                   }
                   dstOut.setPixels(x, y, w, 1, dstPix);
               }
  @@ -879,6 +893,7 @@
                       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 + 
  @@ -886,12 +901,14 @@
                       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);
  @@ -937,22 +954,25 @@
               final int pt5  = (1<<23);
   
               int srcP, dstP;
  -
  +            int 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++];
  -
  -                    dstOutPixels[dstOutSp++] 
  -                        = (((((int)lut[(((srcP>> 16)&0xFF00) | 
  -                                        ((dstP>>>24)&0x00FF))])     )<< 24) |
  -                           ((((int)lut[(((srcP>>  8)&0xFF00) | 
  -                                        ((dstP>> 16)&0x00FF))])&0xFF)<< 16) |
  -                           ((((int)lut[(((srcP     )&0xFF00) | 
  -                                        ((dstP>>  8)&0x00FF))])&0xFF)<<  8) |
  -                           ((((int)lut[(((srcP<<  8)&0xFF00) | 
  -                                        ((dstP     )&0x00FF))])&0xFF)     ));
  +                    srcP = srcPixels  [srcSp++];
  +                    dstP = dstInPixels[dstInSp++];
  +                    
  +                    a = lut[(((srcP>> 16)&0xFF00)|((dstP>>>24)       ))];
  +                    a &= 0xFF;
  +                    r = lut[(((srcP>>  8)&0xFF00)|((dstP>> 16)&0x00FF))];
  +                    r &= 0xFF;
  +                    g = lut[(((srcP     )&0xFF00)|((dstP>>  8)&0x00FF))];
  +                    g &= 0xFF;
  +                    b = lut[(((srcP<<  8)&0xFF00)|((dstP     )&0x00FF))];
  +                    b &= 0xFF;
  +                    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;
  
  
  
  1.6       +88 -1     
xml-batik/sources/org/apache/batik/ext/awt/image/renderable/ConvolveMatrixRable8Bit.java
  
  Index: ConvolveMatrixRable8Bit.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/renderable/ConvolveMatrixRable8Bit.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ConvolveMatrixRable8Bit.java      2001/08/07 17:28:21     1.5
  +++ ConvolveMatrixRable8Bit.java      2001/12/05 13:46:05     1.6
  @@ -30,6 +30,9 @@
   import java.awt.image.renderable.RenderContext;
   import java.awt.image.WritableRaster;
   
  +import java.awt.image.DataBufferInt;
  +import java.awt.image.SinglePixelPackedSampleModel;
  +
   import org.apache.batik.ext.awt.image.GraphicsUtil;
   import org.apache.batik.ext.awt.image.PadMode;
   
  @@ -46,7 +49,7 @@
    *   Does not support edgeMode="wrap" - pending Tile code.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
  - * @version $Id: ConvolveMatrixRable8Bit.java,v 1.5 2001/08/07 17:28:21 deweese Exp 
$
  + * @version $Id: ConvolveMatrixRable8Bit.java,v 1.6 2001/12/05 13:46:05 deweese Exp 
$
    */
   public class ConvolveMatrixRable8Bit
       extends    AbstractColorInterpolationRable
  @@ -55,6 +58,7 @@
       Kernel kernel;
       Point  target;
       float bias;
  +    boolean kernelHasNegValues;
       PadMode edgeMode;
       float [] kernelUnitLength = new float[2];
   
  @@ -87,6 +91,13 @@
       public void setKernel(Kernel k) {
           touch();
           this.kernel = k;
  +        kernelHasNegValues = false;
  +        float [] kv = k.getKernelData(null);
  +        for (int i=0; i<kv.length; i++)
  +            if (kv[i] < 0) {
  +                kernelHasNegValues = true;
  +                break;
  +            }
       }
   
       public Point getTarget() {
  @@ -176,6 +187,73 @@
           this.preserveAlpha = preserveAlpha;
       }
   
  +
  +    public void fixAlpha(BufferedImage bi) {
  +        if ((!bi.getColorModel().hasAlpha()) ||
  +            (!bi.isAlphaPremultiplied()))
  +            // No need to fix alpha if it isn't premultiplied...
  +            return;
  +        if (GraphicsUtil.is_INT_PACK_Data(bi.getSampleModel(), true)) 
  +            fixAlpha_INT_PACK(bi.getRaster());
  +        else
  +            fixAlpha_FALLBACK(bi.getRaster());
  +    }
  +
  +    public void fixAlpha_INT_PACK(WritableRaster wr) {
  +        SinglePixelPackedSampleModel sppsm;
  +        sppsm = (SinglePixelPackedSampleModel)wr.getSampleModel();
  +
  +        final int width = wr.getWidth();
  +
  +        final int scanStride = sppsm.getScanlineStride();
  +        DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
  +        final int base
  +            = (db.getOffset() +
  +               sppsm.getOffset(wr.getMinX()-wr.getSampleModelTranslateX(),
  +                               wr.getMinY()-wr.getSampleModelTranslateY()));
  +        int pixel, a, v;
  +        // Access the pixel data array
  +        final int pixels[] = db.getBankData()[0];
  +        for (int y=0; y<wr.getHeight(); y++) {
  +            int sp = base + y*scanStride;
  +            final int end = sp + width;
  +            while (sp < end) {
  +                pixel = pixels[sp];
  +                a = pixel>>>24;
  +                v = (pixel>>16)&0xFF;
  +                if (a < v) a = v;
  +                v = (pixel>> 8)&0xFF;
  +                if (a < v) a = v;
  +                v = (pixel    )&0xFF;
  +                if (a < v) a = v;
  +                pixels[sp] = (pixel&0x00FFFFFF) | (a << 24);
  +                sp++;
  +            }
  +        }
  +    }
  +
  +    public void fixAlpha_FALLBACK(WritableRaster wr) {
  +        int x0=wr.getMinX();
  +        int w =wr.getWidth();
  +        int y0=wr.getMinY();
  +        int y1=y0 + wr.getHeight()-1;
  +        int bands = wr.getNumBands();
  +        int a, x, y, b, i;
  +        int [] pixel = null;
  +        for (y=y0; y<=y1; y++) {
  +            pixel = wr.getPixels(x0, y, w, 1, pixel);
  +            i=0;
  +            for (x=0; x<w; x++) {
  +                a=pixel[i];
  +                for (b=1; b<bands; b++)
  +                    if (pixel[i+b] > a) a = pixel[i+b];
  +                pixel[i+bands-1] = a;
  +                i+=bands;
  +            }
  +            wr.setPixels(x0, y, w, 1, pixel);
  +        }
  +    }
  +
       public RenderedImage createRendering(RenderContext rc) {
           // Just copy over the rendering hints.
           RenderingHints rh = rc.getRenderingHints();
  @@ -320,6 +398,15 @@
   
               // Easy case just apply the op...
               destBI = op.filter(srcBI, null);
  +
  +            if (kernelHasNegValues) {
  +                // When the kernel has negative values it's possible
  +                // for the resultant image to have alpha values less
  +                // than the associated color values this will lead to
  +                // problems later when we try to display the image so
  +                // we fix this here.
  +                fixAlpha(destBI);
  +            }
   
           } else {
               BufferedImage srcBI;
  
  
  
  1.2       +3 -2      
xml-batik/sources/org/apache/batik/ext/awt/image/rendered/FilterAlphaRed.java
  
  Index: FilterAlphaRed.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/rendered/FilterAlphaRed.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FilterAlphaRed.java       2001/01/24 05:39:38     1.1
  +++ FilterAlphaRed.java       2001/12/05 13:46:05     1.2
  @@ -34,7 +34,7 @@
    * This strips out the source alpha channel into a one band image.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
  - * @version $Id: FilterAlphaRed.java,v 1.1 2001/01/24 05:39:38 vhardy Exp $ */
  + * @version $Id: FilterAlphaRed.java,v 1.2 2001/12/05 13:46:05 deweese Exp $ */
   public class FilterAlphaRed extends AbstractRed {
   
       /**
  @@ -56,6 +56,7 @@
       }
   
       public WritableRaster copyData(WritableRaster wr) {
  +        // new Exception("FilterAlphaRed: ").printStackTrace();
           // Get my source.
           CachableRed srcRed = (CachableRed)getSources().get(0);
   
  @@ -64,7 +65,7 @@
               // Already one band of data so we just use it...
               return srcRed.copyData(wr);
   
  -        
  +        PadRed.ZeroRecter.zeroRect(wr);
           Raster srcRas = srcRed.getData(wr.getBounds());
           AbstractRed.copyBand(srcRas, srcRas.getNumBands()-1, wr, 
                                wr.getNumBands()-1);
  
  
  
  1.10      +6 -1      
xml-batik/sources/org/apache/batik/ext/awt/image/rendered/PadRed.java
  
  Index: PadRed.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/rendered/PadRed.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PadRed.java       2001/11/08 23:02:43     1.9
  +++ PadRed.java       2001/12/05 13:46:05     1.10
  @@ -32,7 +32,7 @@
    * This is an implementation of a Pad operation as a RenderedImage.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
  - * @version $Id: PadRed.java,v 1.9 2001/11/08 23:02:43 deweese Exp $ */
  + * @version $Id: PadRed.java,v 1.10 2001/12/05 13:46:05 deweese Exp $ */
   public class PadRed extends AbstractRed {
   
       static final boolean DEBUG=false;
  @@ -122,6 +122,11 @@
                   return new ZeroRecter_INT_PACK(wr);
               else
                   return new ZeroRecter(wr);
  +        }
  +
  +        public static void zeroRect(WritableRaster wr) {
  +            ZeroRecter zr = getZeroRecter(wr);
  +            zr.zeroRect(wr.getBounds());
           }
   
       }
  
  
  
  1.55      +2 -2      
xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml
  
  Index: samplesRendering.xml
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- samplesRendering.xml      2001/12/03 15:24:56     1.54
  +++ samplesRendering.xml      2001/12/05 13:46:05     1.55
  @@ -8,7 +8,7 @@
   
   <!-- ========================================================================= -->
   <!-- @author [EMAIL PROTECTED]                                         -->
  -<!-- @version $Id: samplesRendering.xml,v 1.54 2001/12/03 15:24:56 vhardy Exp $ -->
  +<!-- @version $Id: samplesRendering.xml,v 1.55 2001/12/05 13:46:05 deweese Exp $ -->
   <!-- ========================================================================= -->
   <testSuite id="samplesRendering" name="samples and samples/test Rendering" 
class="org.apache.batik.test.svg.SamplesRenderingTest">
   
  @@ -26,7 +26,7 @@
           <test id="samples/batikFX.svg" />
           <test id="samples/batikLogo.svg" />
           <test id="samples/batikYin.svg" />
  -        <test id="samples/bookOfKells.svg" />
  +        <test id="samples/bookOfKells.svgz" />
           <test id="samples/chessboard.svg" />
           <test id="samples/gradients.svg" />
           <test id="samples/GVT.svg" />
  
  
  
  1.3       +2 -2      
xml-batik/test-sources/org/apache/batik/test/svg/ParametrizedRenderingAccuracyTest.java
  
  Index: ParametrizedRenderingAccuracyTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-sources/org/apache/batik/test/svg/ParametrizedRenderingAccuracyTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ParametrizedRenderingAccuracyTest.java    2001/10/22 09:26:17     1.2
  +++ ParametrizedRenderingAccuracyTest.java    2001/12/05 13:46:05     1.3
  @@ -21,7 +21,7 @@
    * to the SVG file.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Hardy</a>
  - * @version $Id: ParametrizedRenderingAccuracyTest.java,v 1.2 2001/10/22 09:26:17 
vhardy Exp $
  + * @version $Id: ParametrizedRenderingAccuracyTest.java,v 1.3 2001/12/05 13:46:05 
deweese Exp $
    */
   public class ParametrizedRenderingAccuracyTest
       extends SamplesRenderingTest {
  @@ -58,7 +58,7 @@
   
           String[] dirNfile = breakSVGFile(svgFile);
   
  -        setConfig(buildSVGURL(dirNfile[0], dirNfile[1]),
  +        setConfig(buildSVGURL(dirNfile[0], dirNfile[1], dirNfile[2]),
                     buildRefImgURL(dirNfile[0], dirNfile[1]));
   
           setVariationURL(buildVariationURL(dirNfile[0], dirNfile[1]));
  
  
  
  1.4       +20 -9     
xml-batik/test-sources/org/apache/batik/test/svg/PreconfiguredRenderingTest.java
  
  Index: PreconfiguredRenderingTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-sources/org/apache/batik/test/svg/PreconfiguredRenderingTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PreconfiguredRenderingTest.java   2001/10/22 09:26:17     1.3
  +++ PreconfiguredRenderingTest.java   2001/12/05 13:46:05     1.4
  @@ -15,7 +15,7 @@
    * rules for the various configuration parameters.
    *
    * @author <a href="[EMAIL PROTECTED]">Vincent Hardy</a>
  - * @version $Id: PreconfiguredRenderingTest.java,v 1.3 2001/10/22 09:26:17 vhardy 
Exp $
  + * @version $Id: PreconfiguredRenderingTest.java,v 1.4 2001/12/05 13:46:05 deweese 
Exp $
    */
   public abstract class PreconfiguredRenderingTest extends SVGRenderingAccuracyTest {
       /**
  @@ -24,6 +24,7 @@
       public static final String PNG_EXTENSION = ".png";
   
       public static final String SVG_EXTENSION = ".svg";
  +    public static final String SVGZ_EXTENSION = ".svgz";
   
       public static final char PATH_SEPARATOR = '/';
   
  @@ -39,7 +40,7 @@
   
           String[] dirNfile = breakSVGFile(svgFile);
   
  -        setConfig(buildSVGURL(dirNfile[0], dirNfile[1]),
  +        setConfig(buildSVGURL(dirNfile[0], dirNfile[1], dirNfile[2]),
                     buildRefImgURL(dirNfile[0], dirNfile[1]));
   
           setVariationURL(buildVariationURL(dirNfile[0], dirNfile[1]));
  @@ -62,9 +63,8 @@
        * The svgURL is built as:
        * getSVGURLPrefix() + svgDir + svgFile
        */
  -    protected String buildSVGURL(String svgDir, String svgFile){
  -        return getSVGURLPrefix() + svgDir +
  -            svgFile + SVG_EXTENSION;
  +    protected String buildSVGURL(String svgDir, String svgFile, String svgExt){
  +        return getSVGURLPrefix() + svgDir + svgFile + svgExt;
       }
   
       protected abstract String getSVGURLPrefix();
  @@ -125,12 +125,22 @@
   
   
       protected String[] breakSVGFile(String svgFile){
  -        if(svgFile == null || !svgFile.endsWith(SVG_EXTENSION)){
  +        if(svgFile == null) {
               throw new IllegalArgumentException(svgFile);
           }
   
  -        svgFile = svgFile.substring(0, svgFile.length() - SVG_EXTENSION.length());
  +        String [] ret = new String[3];
   
  +        if (svgFile.endsWith(SVG_EXTENSION)) {
  +            ret[2] = SVG_EXTENSION;
  +        } else if (svgFile.endsWith(SVGZ_EXTENSION)) {
  +            ret[2] = SVGZ_EXTENSION;
  +        } else {
  +            throw new IllegalArgumentException(svgFile);
  +        }
  +
  +        svgFile = svgFile.substring(0, svgFile.length()-ret[2].length());
  +
           int fileNameStart = svgFile.lastIndexOf(PATH_SEPARATOR);
           String svgDir = "";
           if(fileNameStart != -1){
  @@ -141,8 +151,9 @@
               svgDir = svgFile.substring(0, fileNameStart + 1);
               svgFile = svgFile.substring(fileNameStart + 1);
           }
  -
  -        return new String[]{svgDir, svgFile};
  +        ret[0] = svgDir;
  +        ret[1] = svgFile;
  +        return ret;
       }
   
   }
  
  
  
  1.26      +49 -7     
xml-batik/test-sources/org/apache/batik/test/svg/SVGRenderingAccuracyTest.java
  
  Index: SVGRenderingAccuracyTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-sources/org/apache/batik/test/svg/SVGRenderingAccuracyTest.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- SVGRenderingAccuracyTest.java     2001/11/14 12:59:51     1.25
  +++ SVGRenderingAccuracyTest.java     2001/12/05 13:46:05     1.26
  @@ -28,8 +28,11 @@
   import java.awt.Graphics2D;
   import java.awt.image.BufferedImage;
   import java.awt.image.RenderedImage;
  +import java.awt.image.WritableRaster;
  +import java.awt.image.ColorModel;
   
   import org.apache.batik.ext.awt.image.CompositeRule;
  +import org.apache.batik.ext.awt.image.GraphicsUtil;
   import org.apache.batik.ext.awt.image.rendered.CompositeRed;
   import org.apache.batik.ext.awt.image.rendered.BufferedImageCachableRed;
   
  @@ -64,7 +67,7 @@
    * all pixel values are the same).
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Hardy</a>
  - * @version $Id: SVGRenderingAccuracyTest.java,v 1.25 2001/11/14 12:59:51 vhardy 
Exp $
  + * @version $Id: SVGRenderingAccuracyTest.java,v 1.26 2001/12/05 13:46:05 deweese 
Exp $
    */
   public class SVGRenderingAccuracyTest extends AbstractTest {
       /**
  @@ -709,15 +712,54 @@
           BufferedImage diff = new BufferedImage(ref.getWidth(),
                                                  ref.getHeight(),
                                                  BufferedImage.TYPE_INT_ARGB);
  +        WritableRaster refWR = ref.getRaster();
  +        WritableRaster genWR = gen.getRaster();
  +        WritableRaster dstWR = diff.getRaster();
  +
  +        boolean refPre = ref.isAlphaPremultiplied();
  +        if (!refPre) {
  +            ColorModel     cm = ref.getColorModel();
  +            cm = GraphicsUtil.coerceData(refWR, cm, true);
  +            ref = new BufferedImage(cm, refWR, true, null);
  +        }
  +        boolean genPre = gen.isAlphaPremultiplied();
  +        if (!genPre) {
  +            ColorModel     cm = gen.getColorModel();
  +            cm = GraphicsUtil.coerceData(genWR, cm, true);
  +            gen = new BufferedImage(cm, genWR, true, null);
  +        }
  +
   
  -        Vector src = new Vector();
  -        src.addElement(new BufferedImageCachableRed(ref));
  -        src.addElement(new BufferedImageCachableRed(gen));
  +        int w=ref.getWidth();
  +        int h=ref.getHeight();
  +        int nb = ref.getSampleModel().getNumBands();
  +
  +        int y, i,val;
  +        int [] refPix = null;
  +        int [] genPix = null;
  +        for (y=0; y<h; y++) {
  +            refPix = refWR.getPixels  (0, y, w, 1, refPix);
  +            genPix = genWR.getPixels  (0, y, w, 1, genPix);
  +            for (i=0; i<refPix.length; i++) {
  +                val = ((genPix[i]-refPix[i])*10)+128;
  +                if ((val & 0xFFFFFF00) != 0)
  +                    if ((val & 0x80000000) != 0) val = 0;
  +                    else                         val = 255;
  +                genPix[i] = val;
  +            }
  +            dstWR.setPixels(0, y, w, 1, genPix);
  +        }
   
  -        CompositeRed cr = new CompositeRed(src,
  -                                           CompositeRule.ARITHMETIC(0, 10, -10, 
0.5f));
  +        if (!genPre) {
  +            ColorModel cm = gen.getColorModel();
  +            cm = GraphicsUtil.coerceData(genWR, cm, false);
  +        }
  +        
  +        if (!refPre) {
  +            ColorModel cm = ref.getColorModel();
  +            cm = GraphicsUtil.coerceData(refWR, cm, false);
  +        }
   
  -        cr.copyToRaster(diff.getRaster());
           return diff;
       }
   
  
  
  
  1.3       +52 -9     
xml-batik/test-sources/org/apache/batik/test/util/ImageCompareTest.java
  
  Index: ImageCompareTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-sources/org/apache/batik/test/util/ImageCompareTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ImageCompareTest.java     2001/11/13 07:23:05     1.2
  +++ ImageCompareTest.java     2001/12/05 13:46:05     1.3
  @@ -13,6 +13,8 @@
   
   import java.awt.image.BufferedImage;
   import java.awt.image.RenderedImage;
  +import java.awt.image.WritableRaster;
  +import java.awt.image.ColorModel;
   
   import java.io.BufferedInputStream;
   import java.io.File;
  @@ -27,6 +29,7 @@
   
   import org.apache.batik.ext.awt.image.spi.ImageTagRegistry;
   import org.apache.batik.ext.awt.image.renderable.Filter;
  +import org.apache.batik.ext.awt.image.GraphicsUtil;
   
   import org.apache.batik.util.ParsedURL;
   
  @@ -46,7 +49,7 @@
    * describing why the two images are different.
    *
    * @author <a href="[EMAIL PROTECTED]">Vincent Hardy</a>
  - * @version $Id: ImageCompareTest.java,v 1.2 2001/11/13 07:23:05 vhardy Exp $
  + * @version $Id: ImageCompareTest.java,v 1.3 2001/12/05 13:46:05 deweese Exp $
    */
   public class ImageCompareTest extends AbstractTest {
       public static final String ERROR_COULD_NOT_OPEN_IMAGE
  @@ -283,20 +286,60 @@
       /**
        * Builds a new BufferedImage that is the difference between the two input 
images
        */
  -    protected BufferedImage buildDiffImage(BufferedImage ref,
  -                                           BufferedImage gen){
  +    public static BufferedImage buildDiffImage(BufferedImage ref,
  +                                               BufferedImage gen) {
           BufferedImage diff = new BufferedImage(ref.getWidth(),
                                                  ref.getHeight(),
                                                  BufferedImage.TYPE_INT_ARGB);
  +        WritableRaster refWR = ref.getRaster();
  +        WritableRaster genWR = gen.getRaster();
  +        WritableRaster dstWR = diff.getRaster();
  +
  +        boolean refPre = ref.isAlphaPremultiplied();
  +        if (!refPre) {
  +            ColorModel     cm = ref.getColorModel();
  +            cm = GraphicsUtil.coerceData(refWR, cm, true);
  +            ref = new BufferedImage(cm, refWR, true, null);
  +        }
  +        boolean genPre = gen.isAlphaPremultiplied();
  +        if (!genPre) {
  +            ColorModel     cm = gen.getColorModel();
  +            cm = GraphicsUtil.coerceData(genWR, cm, true);
  +            gen = new BufferedImage(cm, genWR, true, null);
  +        }
   
  -        Vector src = new Vector();
  -        src.addElement(new BufferedImageCachableRed(ref));
  -        src.addElement(new BufferedImageCachableRed(gen));
  +
  +        int w=ref.getWidth();
  +        int h=ref.getHeight();
  +        int nb = ref.getSampleModel().getNumBands();
  +
  +        int y, i,val;
  +        int [] refPix = null;
  +        int [] genPix = null;
  +        for (y=0; y<h; y++) {
  +            refPix = refWR.getPixels  (0, y, w, 1, refPix);
  +            genPix = genWR.getPixels  (0, y, w, 1, genPix);
  +            for (i=0; i<refPix.length; i++) {
  +                // val = ((genPix[i]-refPix[i])*5)+128;
  +                val = ((refPix[i]-genPix[i])*10)+128;
  +                if ((val & 0xFFFFFF00) != 0)
  +                    if ((val & 0x80000000) != 0) val = 0;
  +                    else                         val = 255;
  +                genPix[i] = val;
  +            }
  +            dstWR.setPixels(0, y, w, 1, genPix);
  +        }
   
  -        CompositeRed cr = new CompositeRed(src,
  -                                           CompositeRule.ARITHMETIC(0, 10, -10, 
0.5f));
  +        if (!genPre) {
  +            ColorModel cm = gen.getColorModel();
  +            cm = GraphicsUtil.coerceData(genWR, cm, false);
  +        }
  +        
  +        if (!refPre) {
  +            ColorModel cm = ref.getColorModel();
  +            cm = GraphicsUtil.coerceData(refWR, cm, false);
  +        }
   
  -        cr.copyToRaster(diff.getRaster());
           return diff;
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to