src/share/classes/java/awt/image/AffineTransformOp.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt.image;
  27 
  28 import java.awt.geom.AffineTransform;
  29 import java.awt.geom.NoninvertibleTransformException;
  30 import java.awt.geom.Rectangle2D;
  31 import java.awt.geom.Point2D;
  32 import java.awt.AlphaComposite;
  33 import java.awt.GraphicsEnvironment;
  34 import java.awt.Rectangle;
  35 import java.awt.RenderingHints;
  36 import java.awt.Transparency;
  37 import javax.tools.annotation.GenerateNativeHeader;
  38 import sun.awt.image.ImagingLib;
  39 
  40 /**
  41  * This class uses an affine transform to perform a linear mapping from
  42  * 2D coordinates in the source image or <CODE>Raster</CODE> to 2D coordinates
  43  * in the destination image or <CODE>Raster</CODE>.
  44  * The type of interpolation that is used is specified through a constructor,
  45  * either by a <CODE>RenderingHints</CODE> object or by one of the integer
  46  * interpolation types defined in this class.
  47  * <p>
  48  * If a <CODE>RenderingHints</CODE> object is specified in the constructor, the
  49  * interpolation hint and the rendering quality hint are used to set
  50  * the interpolation type for this operation.  The color rendering hint
  51  * and the dithering hint can be used when color conversion is required.
  52  * <p>
  53  * Note that the following constraints have to be met:
  54  * <ul>
  55  * <li>The source and destination must be different.
  56  * <li>For <CODE>Raster</CODE> objects, the number of bands in the source must
  57  * be equal to the number of bands in the destination.
  58  * </ul>
  59  * @see AffineTransform
  60  * @see BufferedImageFilter
  61  * @see java.awt.RenderingHints#KEY_INTERPOLATION
  62  * @see java.awt.RenderingHints#KEY_RENDERING
  63  * @see java.awt.RenderingHints#KEY_COLOR_RENDERING
  64  * @see java.awt.RenderingHints#KEY_DITHERING
  65  */
  66 /* No native methods here, but the constants are needed in the supporting JNI code */
  67 @GenerateNativeHeader
  68 public class AffineTransformOp implements BufferedImageOp, RasterOp {
  69     private AffineTransform xform;
  70     RenderingHints hints;
  71 
  72     /**
  73      * Nearest-neighbor interpolation type.
  74      */
  75     public static final int TYPE_NEAREST_NEIGHBOR = 1;
  76 
  77     /**
  78      * Bilinear interpolation type.
  79      */
  80     public static final int TYPE_BILINEAR = 2;
  81 
  82     /**
  83      * Bicubic interpolation type.
  84      */
  85     public static final int TYPE_BICUBIC = 3;
  86 
  87     int interpolationType = TYPE_NEAREST_NEIGHBOR;
  88 
  89     /**
  90      * Constructs an <CODE>AffineTransformOp</CODE> given an affine transform.
  91      * The interpolation type is determined from the
  92      * <CODE>RenderingHints</CODE> object.  If the interpolation hint is
  93      * defined, it will be used. Otherwise, if the rendering quality hint is
  94      * defined, the interpolation type is determined from its value.  If no
  95      * hints are specified (<CODE>hints</CODE> is null),
  96      * the interpolation type is {@link #TYPE_NEAREST_NEIGHBOR
  97      * TYPE_NEAREST_NEIGHBOR}.
  98      *
  99      * @param xform The <CODE>AffineTransform</CODE> to use for the
 100      * operation.
 101      *
 102      * @param hints The <CODE>RenderingHints</CODE> object used to specify
 103      * the interpolation type for the operation.
 104      *
 105      * @throws ImagingOpException if the transform is non-invertible.


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt.image;
  27 
  28 import java.awt.geom.AffineTransform;
  29 import java.awt.geom.NoninvertibleTransformException;
  30 import java.awt.geom.Rectangle2D;
  31 import java.awt.geom.Point2D;
  32 import java.awt.AlphaComposite;
  33 import java.awt.GraphicsEnvironment;
  34 import java.awt.Rectangle;
  35 import java.awt.RenderingHints;
  36 import java.awt.Transparency;
  37 import java.lang.annotation.Native;
  38 import sun.awt.image.ImagingLib;
  39 
  40 /**
  41  * This class uses an affine transform to perform a linear mapping from
  42  * 2D coordinates in the source image or <CODE>Raster</CODE> to 2D coordinates
  43  * in the destination image or <CODE>Raster</CODE>.
  44  * The type of interpolation that is used is specified through a constructor,
  45  * either by a <CODE>RenderingHints</CODE> object or by one of the integer
  46  * interpolation types defined in this class.
  47  * <p>
  48  * If a <CODE>RenderingHints</CODE> object is specified in the constructor, the
  49  * interpolation hint and the rendering quality hint are used to set
  50  * the interpolation type for this operation.  The color rendering hint
  51  * and the dithering hint can be used when color conversion is required.
  52  * <p>
  53  * Note that the following constraints have to be met:
  54  * <ul>
  55  * <li>The source and destination must be different.
  56  * <li>For <CODE>Raster</CODE> objects, the number of bands in the source must
  57  * be equal to the number of bands in the destination.
  58  * </ul>
  59  * @see AffineTransform
  60  * @see BufferedImageFilter
  61  * @see java.awt.RenderingHints#KEY_INTERPOLATION
  62  * @see java.awt.RenderingHints#KEY_RENDERING
  63  * @see java.awt.RenderingHints#KEY_COLOR_RENDERING
  64  * @see java.awt.RenderingHints#KEY_DITHERING
  65  */


  66 public class AffineTransformOp implements BufferedImageOp, RasterOp {
  67     private AffineTransform xform;
  68     RenderingHints hints;
  69 
  70     /**
  71      * Nearest-neighbor interpolation type.
  72      */
  73     @Native public static final int TYPE_NEAREST_NEIGHBOR = 1;
  74 
  75     /**
  76      * Bilinear interpolation type.
  77      */
  78     @Native public static final int TYPE_BILINEAR = 2;
  79 
  80     /**
  81      * Bicubic interpolation type.
  82      */
  83     @Native public static final int TYPE_BICUBIC = 3;
  84 
  85     int interpolationType = TYPE_NEAREST_NEIGHBOR;
  86 
  87     /**
  88      * Constructs an <CODE>AffineTransformOp</CODE> given an affine transform.
  89      * The interpolation type is determined from the
  90      * <CODE>RenderingHints</CODE> object.  If the interpolation hint is
  91      * defined, it will be used. Otherwise, if the rendering quality hint is
  92      * defined, the interpolation type is determined from its value.  If no
  93      * hints are specified (<CODE>hints</CODE> is null),
  94      * the interpolation type is {@link #TYPE_NEAREST_NEIGHBOR
  95      * TYPE_NEAREST_NEIGHBOR}.
  96      *
  97      * @param xform The <CODE>AffineTransform</CODE> to use for the
  98      * operation.
  99      *
 100      * @param hints The <CODE>RenderingHints</CODE> object used to specify
 101      * the interpolation type for the operation.
 102      *
 103      * @throws ImagingOpException if the transform is non-invertible.