ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/image Image.java
Date Mon, 29 Jul 2002 15:23:20 GMT
ehatcher    2002/07/29 08:23:20

  Modified:    src/main/org/apache/tools/ant/taskdefs defaults.properties
  Added:       src/main/org/apache/tools/ant/types/optional/image Arc.java
                        BasicShape.java ColorMapper.java Draw.java
                        DrawOperation.java Ellipse.java ImageOperation.java
                        Rectangle.java Rotate.java Scale.java Text.java
                        TransformOperation.java
               src/main/org/apache/tools/ant/taskdefs/optional/image
                        Image.java
  Log:
  Kevin Grey's <image> task.  A few modifications were made, most notably changes on setter types and removal of some unused variables flagged by IDEA.
  
  Revision  Changes    Path
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/Arc.java
  
  Index: Arc.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  import javax.media.jai.PlanarImage;
  import java.awt.BasicStroke;
  import java.awt.Graphics2D;
  import java.awt.geom.Arc2D;
  import java.awt.image.BufferedImage;
  
  public class Arc extends BasicShape implements DrawOperation {
      protected int width = 0;
      protected int height = 0;
      protected int start = 0;
      protected int stop = 0;
      protected int type = Arc2D.OPEN;
  
      public void setWidth(int width) {
          this.width = width;
      }
  
      public void setHeight(int height) {
          this.height = height;
      }
  
      public void setStart(int start) {
          this.start = start;
      }
  
      public void setStop(int stop) {
          this.stop = stop;
      }
  
      /**
       * @todo refactor using an EnumeratedAttribute
       */
      public void setType(String str_type) {
          if (str_type.toLowerCase().equals("open")) {
              type = Arc2D.OPEN;
          } else if (str_type.toLowerCase().equals("pie")) {
              type = Arc2D.PIE;
          } else if (str_type.toLowerCase().equals("chord")) {
              type = Arc2D.CHORD;
          }
      }
  
      public PlanarImage executeDrawOperation() {
          BufferedImage bi = new BufferedImage(width + (stroke_width * 2), height + (stroke_width * 2), BufferedImage.TYPE_4BYTE_ABGR_PRE);
  
          Graphics2D graphics = (Graphics2D) bi.getGraphics();
  
          if (!stroke.equals("transparent")) {
              BasicStroke b_stroke = new BasicStroke(stroke_width);
              graphics.setColor(ColorMapper.getColorByName(stroke));
              graphics.setStroke(b_stroke);
              graphics.draw(new Arc2D.Double(stroke_width, stroke_width, width, height, start, stop, type));
          }
  
          if (!fill.equals("transparent")) {
              graphics.setColor(ColorMapper.getColorByName(fill));
              graphics.fill(new Arc2D.Double(stroke_width, stroke_width, width, height, start, stop, type));
          }
  
  
          for (int i = 0; i < instructions.size(); i++) {
              ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
              if (instr instanceof DrawOperation) {
                  PlanarImage img = ((DrawOperation) instr).executeDrawOperation();
                  graphics.drawImage(img.getAsBufferedImage(), null, 0, 0);
              } else if (instr instanceof TransformOperation) {
                  graphics = (Graphics2D) bi.getGraphics();
                  PlanarImage image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
                  bi = image.getAsBufferedImage();
              }
          }
          return PlanarImage.wrapRenderedImage(bi);
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/BasicShape.java
  
  Index: BasicShape.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  public abstract class BasicShape extends ImageOperation implements DrawOperation {
      protected int stroke_width = 0;
      protected String fill = "transparent";
      protected String stroke = "black";
  
  
      public void setFill(String col) {
          fill = col;
      }
  
      public void setStroke(String col) {
          stroke = col;
      }
  
      public void setStrokewidth(int width) {
          stroke_width = width;
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java
  
  Index: ColorMapper.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  import java.awt.Color;
  
  /**
   *
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   * @see org.apache.tools.ant.taskdefs.optional.image.Image
   */
  public final class ColorMapper {
      public static final String COLOR_BLACK = "black";
      public static final String COLOR_BLUE = "blue";
      public static final String COLOR_CYAN = "cyan";
      public static final String COLOR_DARKGRAY = "darkgray";
      public static final String COLOR_GRAY = "gray";
      public static final String COLOR_LIGHTGRAY = "lightgray";
      // Gotta atleast put in the proper spelling :-P
      public static final String COLOR_DARKGREY = "darkgrey";
      public static final String COLOR_GREY = "grey";
      public static final String COLOR_LIGHTGREY = "lightgrey";
      public static final String COLOR_GREEN = "green";
      public static final String COLOR_MAGENTA = "magenta";
      public static final String COLOR_ORANGE = "orange";
      public static final String COLOR_PINK = "pink";
      public static final String COLOR_RED = "red";
      public static final String COLOR_WHITE = "white";
      public static final String COLOR_YELLOW = "yellow";
  
      /**
       * @todo refactor to use an EnumeratedAttribute (maybe?)
       */
      public static final Color getColorByName(String color_name) {
          color_name = color_name.toLowerCase();
  
          if (color_name.equals(COLOR_BLACK)) {
              return Color.black;
          } else if (color_name.equals(COLOR_BLUE)) {
              return Color.blue;
          } else if (color_name.equals(COLOR_CYAN)) {
              return Color.cyan;
          } else if (color_name.equals(COLOR_DARKGRAY) || color_name.equals(COLOR_DARKGREY)) {
              return Color.darkGray;
          } else if (color_name.equals(COLOR_GRAY) || color_name.equals(COLOR_GREY)) {
              return Color.gray;
          } else if (color_name.equals(COLOR_LIGHTGRAY) || color_name.equals(COLOR_LIGHTGREY)) {
              return Color.lightGray;
          } else if (color_name.equals(COLOR_GREEN)) {
              return Color.green;
          } else if (color_name.equals(COLOR_MAGENTA)) {
              return Color.magenta;
          } else if (color_name.equals(COLOR_ORANGE)) {
              return Color.orange;
          } else if (color_name.equals(COLOR_PINK)) {
              return Color.pink;
          } else if (color_name.equals(COLOR_RED)) {
              return Color.red;
          } else if (color_name.equals(COLOR_WHITE)) {
              return Color.white;
          } else if (color_name.equals(COLOR_YELLOW)) {
              return Color.yellow;
          }
          return Color.black;
      }
  
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/Draw.java
  
  Index: Draw.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  import javax.media.jai.RenderedOp;
  import javax.media.jai.PlanarImage;
  import javax.media.jai.JAI;
  import java.awt.*;
  import java.awt.image.BufferedImage;
  
  /**
   *
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   * @see org.apache.tools.ant.tasks.optional.image.Image
   */
  public class Draw extends TransformOperation
  {
      protected int xloc = 0;
      protected int yloc = 0;
  
      public void setXloc(int x)
      {
          xloc = x;
      }
  
      public void setYloc(int y)
      {
          yloc = y;
      }
  
      public void addRectangle(Rectangle rect)
      {
          instructions.add(rect);
      }
  
      public void addText(Text text)
      {
          instructions.add(text);
      }
  
      public void addEllipse(Ellipse elip)
      {
          instructions.add(elip);
      }
  
      public void addArc(Arc arc)
      {
          instructions.add(arc);
      }
  
  
      public PlanarImage executeTransformOperation(PlanarImage image)
      {
          BufferedImage bi = image.getAsBufferedImage();
          Graphics2D graphics = (Graphics2D)bi.getGraphics();
  
          for (int i=0; i<instructions.size(); i++)
          {
              ImageOperation instr = ((ImageOperation)instructions.elementAt(i));
              if (instr instanceof DrawOperation)
              {
                  PlanarImage op = ((DrawOperation)instr).executeDrawOperation();
                  log("\tDrawing to x=" + xloc + " y=" + yloc);
                  graphics.drawImage(op.getAsBufferedImage(),null,xloc,yloc);
              }
              else if (instr instanceof TransformOperation)
              {
                  PlanarImage op = ((TransformOperation)instr).executeTransformOperation(null);
                  BufferedImage child = op.getAsBufferedImage();
                  log("\tDrawing to x=" + xloc + " y=" + yloc);
                  graphics.drawImage(child, null, xloc, yloc);
                  PlanarImage test = PlanarImage.wrapRenderedImage(bi);
              }
          }
          image = PlanarImage.wrapRenderedImage(bi);
  
          return image;
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/DrawOperation.java
  
  Index: DrawOperation.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  import javax.media.jai.PlanarImage;
  
  /**
   * Interface which represents an Operation which is "drawable", such
   * as a Rectangle, Circle or Text.  The Operation is responsible for
   * creating its own image buffer and drawing itself into it, then
   * wrapping and returning it as a PlanarImage.  This allows multible
   * "drawable" objects to be nested.
   *
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   * @see org.apache.tools.ant.taskdefs.optional.image.Image
   */
  public interface DrawOperation {
      /**
       * Abstract method which is intended to create an image buffer
       * and return it so it can be drawn into another object.  Use
       * an Alpha channel for a "transparent" background.
       */
      public PlanarImage executeDrawOperation();
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/Ellipse.java
  
  Index: Ellipse.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  import javax.media.jai.PlanarImage;
  import java.awt.BasicStroke;
  import java.awt.Graphics2D;
  import java.awt.geom.Ellipse2D;
  import java.awt.image.BufferedImage;
  
  /**
   *
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   * @see org.apache.tools.ant.taskdefs.optional.image.Image
   */
  public class Ellipse extends BasicShape implements DrawOperation {
      protected int width = 0;
      protected int height = 0;
  
      public void setWidth(int width) {
          this.width = width;
      }
  
      public void setHeight(int height) {
          this.height = height;
      }
  
      public PlanarImage executeDrawOperation() {
          BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
  
          Graphics2D graphics = (Graphics2D) bi.getGraphics();
  
          if (!stroke.equals("transparent")) {
              BasicStroke b_stroke = new BasicStroke(stroke_width);
              graphics.setColor(ColorMapper.getColorByName(stroke));
              graphics.setStroke(b_stroke);
              graphics.draw(new Ellipse2D.Double(0, 0, width, height));
          }
  
          if (!fill.equals("transparent")) {
              graphics.setColor(ColorMapper.getColorByName(fill));
              graphics.fill(new Ellipse2D.Double(0, 0, width, height));
          }
  
  
          for (int i = 0; i < instructions.size(); i++) {
              ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
              if (instr instanceof DrawOperation) {
                  PlanarImage img = ((DrawOperation) instr).executeDrawOperation();
                  graphics.drawImage(img.getAsBufferedImage(), null, 0, 0);
              } else if (instr instanceof TransformOperation) {
                  graphics = (Graphics2D) bi.getGraphics();
                  PlanarImage image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
                  bi = image.getAsBufferedImage();
              }
          }
          return PlanarImage.wrapRenderedImage(bi);
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java
  
  Index: ImageOperation.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  import org.apache.tools.ant.types.DataType;
  import javax.media.jai.RenderedOp;
  import javax.media.jai.PlanarImage;
  import java.util.Vector;
  
  /**
   *
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   * @see org.apache.tools.ant.tasks.optional.image.Image
   */
  public abstract class ImageOperation extends DataType
  {
      protected Vector instructions = new Vector();
  
      public void addRotate(Rotate instr)
      {
          instructions.add(instr);
      }
  
      public void addDraw(Draw instr)
      {
          instructions.add(instr);
      }
  
      public void addRectangle(Rectangle instr)
      {
          instructions.add(instr);
      }
  
      public void addText(Text instr)
      {
          instructions.add(instr);
      }
  
      public void addScale(Scale instr)
      {
          instructions.add(instr);
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/Rectangle.java
  
  Index: Rectangle.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  import javax.media.jai.PlanarImage;
  import java.awt.BasicStroke;
  import java.awt.Graphics2D;
  import java.awt.image.BufferedImage;
  
  /**
   *
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   * @see org.apache.tools.ant.taskdefs.optional.image.Image
   */
  public class Rectangle extends BasicShape implements DrawOperation {
      protected int width = 0;
      protected int height = 0;
      protected int arcwidth = 0;
      protected int archeight = 0;
  
      public void setWidth(int w) {
          width = w;
      }
  
      public void setHeight(int h) {
          height = h;
      }
  
      public void setArcwidth(int w) {
          arcwidth = w;
      }
  
      public void setArcheight(int h) {
          archeight = h;
      }
  
      public PlanarImage executeDrawOperation() {
          log("\tCreating Rectangle w=" + width + " h=" + height + " arcw=" + arcwidth + " arch=" + archeight);
          BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
  
          Graphics2D graphics = (Graphics2D) bi.getGraphics();
  
          if (!stroke.equals("transparent")) {
              BasicStroke b_stroke = new BasicStroke(stroke_width);
              graphics.setColor(ColorMapper.getColorByName(stroke));
              graphics.setStroke(b_stroke);
  
              if ((arcwidth != 0) || (archeight != 0)) {
                  graphics.drawRoundRect(0, 0, width, height, arcwidth, archeight);
              } else {
                  graphics.drawRect(0, 0, width, height);
              }
          }
  
          if (!fill.equals("transparent")) {
              graphics.setColor(ColorMapper.getColorByName(fill));
              if ((arcwidth != 0) || (archeight != 0)) {
                  graphics.fillRoundRect(stroke_width, stroke_width, width - (stroke_width * 2), height - (stroke_width * 2), arcwidth, archeight);
              } else {
                  graphics.fillRect(stroke_width, stroke_width, width - (stroke_width * 2), height - (stroke_width * 2));
              }
          }
  
  
          for (int i = 0; i < instructions.size(); i++) {
              ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
              if (instr instanceof DrawOperation) {
                  PlanarImage img = ((DrawOperation) instr).executeDrawOperation();
                  graphics.drawImage(img.getAsBufferedImage(), null, 0, 0);
              } else if (instr instanceof TransformOperation) {
                  graphics = (Graphics2D) bi.getGraphics();
                  PlanarImage image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
                  bi = image.getAsBufferedImage();
              }
          }
          return PlanarImage.wrapRenderedImage(bi);
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/Rotate.java
  
  Index: Rotate.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  import org.apache.tools.ant.types.DataType;
  
  import javax.media.jai.PlanarImage;
  import javax.media.jai.InterpolationNearest;
  import javax.media.jai.JAI;
  import java.awt.image.renderable.ParameterBlock;
  import java.awt.image.BufferedImage;
  import java.awt.*;
  
  /**
   * ImageOperation to rotate an image by a certain degree
   *
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   * @see org.apache.tools.ant.tasks.optional.image.Image
   */
  public class Rotate extends TransformOperation implements DrawOperation
  {
      protected float angle = 0.0F;
  
      /**
       * Sets the angle of rotation in degrees.
       * @param ang The angle at which to rotate the image
       */
      public void setAngle(String ang)
      {
          angle = Float.parseFloat(ang);
      }
  
  
      public PlanarImage performRotate(PlanarImage image)
      {
          float t_angle = (float) (angle * (Math.PI / 180.0F));
          ParameterBlock pb = new ParameterBlock();
          pb.addSource(image);
          pb.add(0.0F);
          pb.add(0.0F);
          pb.add(t_angle);
          pb.add(new InterpolationNearest());
          return JAI.create("Rotate", pb, null);
      }
  
  
      /**
       *  Performs the image rotation when being handled as a TransformOperation.
       * @param image The image to perform the transformation on.
       */
      public PlanarImage executeTransformOperation(PlanarImage image)
      {
          BufferedImage bi = null;
          Graphics2D graphics = null;
          for (int i = 0; i < instructions.size(); i++)
          {
              ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
              if (instr instanceof DrawOperation)
              {
                  // If this TransformOperation has DrawOperation children
                  // then Rotate the first child and return.
                  System.out.println("Execing Draws");
                  PlanarImage op = ((DrawOperation) instr).executeDrawOperation();
                  image = performRotate(op);
                  return image;
              }
              else if (instr instanceof TransformOperation)
              {
                  bi = image.getAsBufferedImage();
                  graphics = (Graphics2D) bi.getGraphics();
                  System.out.println("Execing Transforms");
                  image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
                  bi = image.getAsBufferedImage();
              }
          }
          System.out.println("Execing as TransformOperation");
          image = performRotate(image);
          System.out.println(image);
          return image;
      }
  
      /**
       *  Performs the image rotation when being handled as a DrawOperation.
       *  It absolutely requires that there be a DrawOperation nested beneath it,
       *  but only the FIRST DrawOperation will be handled since it can only return
       *  ONE image.
       * @param image The image to perform the transformation on.
       */
      public PlanarImage executeDrawOperation()
      {
          for (int i = 0; i < instructions.size(); i++)
          {
              ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
              if (instr instanceof DrawOperation)
              {
                  // If this TransformOperation has DrawOperation children
                  // then Rotate the first child and return.
                  PlanarImage op = ((DrawOperation) instr).executeDrawOperation();
                  op = performRotate(op);
                  return op;
              }
          }
          return null;
      }
  
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/Scale.java
  
  Index: Scale.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  import javax.media.jai.JAI;
  import javax.media.jai.PlanarImage;
  import java.awt.Graphics2D;
  import java.awt.image.BufferedImage;
  import java.awt.image.renderable.ParameterBlock;
  
  /**
   *
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   * @see org.apache.tools.ant.taskdefs.optional.image.Image
   */
  public class Scale extends TransformOperation implements DrawOperation {
      private String width_str = null;
      private String height_str = null;
      private boolean x_percent = true;
      private boolean y_percent = true;
      private boolean keep_proportions = false;
  
      public void setKeepproportions(boolean props) {
          keep_proportions = props;
      }
  
      public void setWidth(String width) {
          width_str = width;
      }
  
      public void setHeight(String height) {
          height_str = height;
      }
  
      public float getWidth() {
          float width = 0.0F;
          int perc_index = width_str.indexOf('%');
          if (perc_index > 0) {
              width = Float.parseFloat(width_str.substring(0, perc_index));
              x_percent = true;
              return width / 100;
          } else {
              x_percent = false;
              return Float.parseFloat(width_str);
          }
      }
  
      public float getHeight() {
          int perc_index = height_str.indexOf('%');
          if (perc_index > 0) {
              float height = Float.parseFloat(height_str.substring(0, perc_index));
              y_percent = true;
              return height / 100;
          } else {
              y_percent = false;
              return Float.parseFloat(height_str);
          }
      }
  
      public PlanarImage performScale(PlanarImage image) {
          ParameterBlock pb = new ParameterBlock();
          pb.addSource(image);
          float x_fl = getWidth();
          float y_fl = getHeight();
          if (!x_percent) {
              x_fl = (x_fl / image.getWidth());
          }
          if (!y_percent) {
              y_fl = (y_fl / image.getHeight());
          }
          if (keep_proportions) {
              y_fl = x_fl;
          }
          pb.add(new Float(x_fl));
          pb.add(new Float(y_fl));
  
          log("\tScaling to " + x_fl + "% x " + y_fl + "%");
          return JAI.create("scale", pb);
      }
  
  
      public PlanarImage executeTransformOperation(PlanarImage image) {
          BufferedImage bi = null;
          for (int i = 0; i < instructions.size(); i++) {
              ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
              if (instr instanceof DrawOperation) {
                  return performScale(image);
              } else if (instr instanceof TransformOperation) {
                  bi = image.getAsBufferedImage();
                  image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
                  bi = image.getAsBufferedImage();
              }
          }
          return performScale(image);
      }
  
  
      public PlanarImage executeDrawOperation() {
          for (int i = 0; i < instructions.size(); i++) {
              ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
              if (instr instanceof DrawOperation) {
                  PlanarImage image = null;
                  // If this TransformOperation has DrawOperation children
                  // then Rotate the first child and return.
                  performScale(image);
                  return image;
              }
          }
          return null;
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/Text.java
  
  Index: Text.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  
  import javax.media.jai.PlanarImage;
  import java.awt.Color;
  import java.awt.Font;
  import java.awt.FontMetrics;
  import java.awt.Graphics2D;
  import java.awt.RenderingHints;
  import java.awt.image.BufferedImage;
  
  /**
   *
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   * @see org.apache.tools.ant.taskdefs.optional.image.Image
   */
  public class Text extends ImageOperation implements DrawOperation {
      private String str_text = "";
      private String font = "Arial";
      private int point = 10;
      private boolean bold = false;
      private boolean italic = false;
      private String color = "black";
  
      public void setString(String str) {
          str_text = str;
      }
  
      public void setFont(String f) {
          font = f;
      }
  
      public void setPoint(String p) {
          point = Integer.parseInt(p);
      }
  
      public void setColor(String c) {
          color = c;
      }
  
      /**
       * @todo is this used?
       */
      public void setBold(boolean state) {
          bold = state;
      }
  
      /**
       * @todo is this used?
       */
      public void setItalic(boolean state) {
          italic = state;
      }
  
      public PlanarImage executeDrawOperation() {
          log("\tCreating Text \"" + str_text + "\"");
  
          Color couloir = ColorMapper.getColorByName(color);
          int width = 1;
          int height = 1;
  
          BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
          Graphics2D graphics = (Graphics2D) bi.getGraphics();
          graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
          Font f = new Font(font, Font.PLAIN, point);
          FontMetrics fmetrics = graphics.getFontMetrics(f);
          height = fmetrics.getMaxAscent() + fmetrics.getMaxDescent();
          width = fmetrics.stringWidth(str_text);
  
  
          bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
          graphics = (Graphics2D) bi.getGraphics();
  
          graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  
          graphics.setFont(f);
          graphics.setColor(couloir);
          graphics.drawString(str_text, 0, height - fmetrics.getMaxDescent());
          PlanarImage image = PlanarImage.wrapRenderedImage(bi);
          return image;
      }
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java
  
  Index: TransformOperation.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.types.optional.image;
  import javax.media.jai.RenderedOp;
  import javax.media.jai.PlanarImage;
  
  /**
   *
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   * @see org.apache.tools.ant.tasks.optional.image.Image
   */
  public abstract class TransformOperation extends ImageOperation
  {
      public abstract PlanarImage executeTransformOperation(PlanarImage img);
  
      public void addRectangle(Rectangle instr)
      {
          instructions.add(instr);
      }
  
  }
  
  
  
  1.131     +1 -0      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.130
  retrieving revision 1.131
  diff -u -r1.130 -r1.131
  --- defaults.properties	9 Jul 2002 21:05:59 -0000	1.130
  +++ defaults.properties	29 Jul 2002 15:23:20 -0000	1.131
  @@ -72,6 +72,7 @@
   tempfile=org.apache.tools.ant.taskdefs.TempFile
   
   # optional tasks
  +image=org.apache.tools.ant.taskdefs.optional.image.Image
   script=org.apache.tools.ant.taskdefs.optional.Script
   netrexxc=org.apache.tools.ant.taskdefs.optional.NetRexxC
   renameext=org.apache.tools.ant.taskdefs.optional.RenameExtensions
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java
  
  Index: Image.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.tools.ant.taskdefs.optional.image;
  
  import com.sun.media.jai.codec.FileSeekableStream;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.DirectoryScanner;
  import org.apache.tools.ant.taskdefs.MatchingTask;
  import org.apache.tools.ant.types.optional.image.Draw;
  import org.apache.tools.ant.types.optional.image.ImageOperation;
  import org.apache.tools.ant.types.optional.image.Rotate;
  import org.apache.tools.ant.types.optional.image.Scale;
  import org.apache.tools.ant.types.optional.image.TransformOperation;
  
  import javax.media.jai.JAI;
  import javax.media.jai.PlanarImage;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.util.Vector;
  
  /**
   * A MatchingTask which relies on <A HREF="http://java.sun.com/products/java-media/jai">JAI (Java Advanced Imaging)</A>
   * to perform image manipulation operations on existing images.  The
   * operations are represented as ImageOperation DataType objects.
   * The operations are arranged to conform to the Chaining Model
   * of JAI.
   * Check out the <A HREF="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/">JAI Programming Guide</A>
   *
   * @see org.apache.tools.ant.types.optional.image.ImageOperation
   * @see org.apache.tools.ant.types.DataType
   * @author <a href="mailto:kzgrey@ntplx.net">Kevin Z Grey</a>
   */
  public class Image extends MatchingTask {
      protected Vector instructions = new Vector();
      protected String str_encoding = "JPEG";
      protected boolean overwrite = false;
      protected boolean garbage_collect = false;
  
      protected File srcDir = null;
      protected File destDir = null;
  
  
      /**
       * Set the source dir to find the image files.
       */
      public void setSrcdir(File srcDir) {
          this.srcDir = srcDir;
      }
  
      /**
       * Set the image encoding type.  <A HREF="http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Encode.doc.html#56610">See this table in the JAI Programming Guide</A>.
       */
      public void setEncoding(String encoding) {
          str_encoding = encoding;
      }
  
      /**
       *  Sets whether or not to overwrite a file if there is a naming conflict.
       */
      public void setOverwrite(String ovr) {
          if (ovr.toLowerCase().equals("true") || ovr.toLowerCase().equals("yes")) {
              overwrite = true;
          }
      }
  
      /**
       *  Enables Garbage Collection after each image processed.  Defaults to false.
       */
      public void setGc(String gc) {
          if (gc.toLowerCase().equals("true") || gc.toLowerCase().equals("yes")) {
              garbage_collect = true;
          }
      }
  
  
      /**
       * Sets the destination directory for manipulated images.
       * @param destination The destination directory
       */
      public void setDest(String destination) {
          destDir = new File(destination);
      }
  
      /**
       * Adds an ImageOperation to chain.
       * @param instr The ImageOperation to append to the chain
       */
      public void addImageOperation(ImageOperation instr) {
          instructions.add(instr);
      }
  
      /**
       * Adds a Rotate ImageOperation to the chain
       * @param instr The Rotate operation to add to the chain
       * @see org.apache.tools.ant.types.optional.image.Rotate
       */
      public void addRotate(Rotate instr) {
          instructions.add(instr);
      }
  
      /**
       * Adds a Scale ImageOperation to the chain
       * @param instr The Scale operation to add to the chain
       * @see org.apache.tools.ant.types.optional.image.Scale
       */
      public void addScale(Scale instr) {
          instructions.add(instr);
      }
  
      /**
       * Adds a Draw ImageOperation to the chain.  DrawOperation
       * DataType objects can be nested inside the Draw object
       * @param instr The Draw operation to add to the chain
       * @see org.apache.tools.ant.types.optional.image.Draw
       * @see org.apache.tools.ant.types.optional.image.DrawOperation
       */
      public void addDraw(Draw instr) {
          instructions.add(instr);
      }
  
      /**
       * Executes all the chained ImageOperations on the file
       * specified.
       * @param file The file to be processed
       */
      public void processFile(File file) {
          try {
              log("Processing File: " + file.getAbsolutePath());
              FileSeekableStream input = new FileSeekableStream(file);
              PlanarImage image = JAI.create("stream", input);
              for (int i = 0; i < instructions.size(); i++) {
                  Object instr = instructions.elementAt(i);
                  if (instr instanceof TransformOperation) {
                      image = ((TransformOperation) instr).executeTransformOperation(image);
                  } else {
                      log("Not a TransformOperation: " + instr);
                  }
              }
              input.close();
              FileOutputStream stream = new FileOutputStream(file);
              log("Encoding As " + str_encoding);
  
              String file_ext = str_encoding.toLowerCase();
              if (str_encoding.toLowerCase().equals("jpg")) {
                  str_encoding = "JPEG";
                  file_ext = "jpg";
              } else if (str_encoding.toLowerCase().equals("tif")) {
                  str_encoding = "TIFF";
                  file_ext = "tif";
              }
  
              JAI.create("encode", image, stream, str_encoding.toUpperCase(), null);
              stream.flush();
              stream.close();
  
              String old_name = file.getAbsolutePath();
              int t_loc = old_name.lastIndexOf(".");
              String t_name = old_name.substring(0, t_loc + 1) + file_ext;
              File new_file = new File(t_name);
              if ((overwrite && new_file.exists()) && (!new_file.equals(file))) {
                  new_file.delete();
              }
              file.renameTo(new_file);
          } catch (IOException err) {
              log("Error processing file:  " + err);
          }
      }
  
      /**
       * Executes the Task
       */
      public void execute() {
          try {
              DirectoryScanner ds = super.getDirectoryScanner(srcDir);
              String[] files = ds.getIncludedFiles();
  
              for (int i = 0; i < files.length; i++) {
                  processFile(new File(srcDir.getAbsolutePath() + File.separator + files[i]));
                  if (garbage_collect) {
                      System.gc();
                  }
              }
          } catch (Exception err) {
              err.printStackTrace();
              throw new BuildException(err.getMessage());
          }
      }
  }
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message