jdk/src/share/classes/java/awt/Image.java
author erikj
Thu, 07 Jun 2012 18:05:09 -0700
changeset 12813 c10ab96dcf41
parent 5506 202f599c92aa
child 16734 da1901d79073
permissions -rw-r--r--
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI Reviewed-by: ohair, ohrstrom, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1995, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.image.ImageProducer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.image.ImageObserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.image.ImageFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.image.FilteredImageSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.AreaAveragingScaleFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.image.ReplicateScaleFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.awt.image.SurfaceManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    36
import javax.tools.annotation.GenerateNativeHeader;
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    37
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The abstract class <code>Image</code> is the superclass of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * classes that represent graphical images. The image must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * obtained in a platform-specific manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    47
/* No native methods here, but the constants are needed in the supporting JNI code */
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    48
@GenerateNativeHeader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
public abstract class Image {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * convenience object; we can use this single static object for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * all images that do not create their own image caps; it holds the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * default (unaccelerated) properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static ImageCapabilities defaultImageCaps =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        new ImageCapabilities(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Priority for accelerating this image.  Subclasses are free to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * set different default priorities and applications are free to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * set the priority for specific images via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * <code>setAccelerationPriority(float)</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected float accelerationPriority = .5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Determines the width of the image. If the width is not yet known,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * this method returns <code>-1</code> and the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <code>ImageObserver</code> object is notified later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @param     observer   an object waiting for the image to be loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @return    the width of this image, or <code>-1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *                   if the width is not yet known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @see       java.awt.Image#getHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @see       java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public abstract int getWidth(ImageObserver observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Determines the height of the image. If the height is not yet known,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * this method returns <code>-1</code> and the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * <code>ImageObserver</code> object is notified later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param     observer   an object waiting for the image to be loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @return    the height of this image, or <code>-1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *                   if the height is not yet known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @see       java.awt.Image#getWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @see       java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public abstract int getHeight(ImageObserver observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Gets the object that produces the pixels for the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * This method is called by the image filtering classes and by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * methods that perform image conversion and scaling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @return     the image producer that produces the pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *                                  for this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @see        java.awt.image.ImageProducer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public abstract ImageProducer getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Creates a graphics context for drawing to an off-screen image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * This method can only be called for off-screen images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return  a graphics context to draw to the off-screen image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @exception UnsupportedOperationException if called for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *            non-off-screen image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see     java.awt.Graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @see     java.awt.Component#createImage(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public abstract Graphics getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Gets a property of this image by name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Individual property names are defined by the various image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * formats. If a property is not defined for a particular image, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * method returns the <code>UndefinedProperty</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * If the properties for this image are not yet known, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * returns <code>null</code>, and the <code>ImageObserver</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * object is notified later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * The property name <code>"comment"</code> should be used to store
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * an optional comment which can be presented to the application as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * description of the image, its source, or its author.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param       name   a property name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param       observer   an object waiting for this image to be loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @return      the value of the named property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @throws      <code>NullPointerException</code> if the property name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see         java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @see         java.awt.Image#UndefinedProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public abstract Object getProperty(String name, ImageObserver observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * The <code>UndefinedProperty</code> object should be returned whenever a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * property which was not defined for a particular image is fetched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public static final Object UndefinedProperty = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Creates a scaled version of this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * A new <code>Image</code> object is returned which will render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * the image at the specified <code>width</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * <code>height</code> by default.  The new <code>Image</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * may be loaded asynchronously even if the original source image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * has already been loaded completely.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * If either <code>width</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * or <code>height</code> is a negative number then a value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * substituted to maintain the aspect ratio of the original image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * dimensions. If both <code>width</code> and <code>height</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * are negative, then the original image dimensions are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param width the width to which to scale the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param height the height to which to scale the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param hints flags to indicate the type of algorithm to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * for image resampling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return     a scaled version of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @exception IllegalArgumentException if <code>width</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *             or <code>height</code> is zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see        java.awt.Image#SCALE_DEFAULT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @see        java.awt.Image#SCALE_FAST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @see        java.awt.Image#SCALE_SMOOTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @see        java.awt.Image#SCALE_REPLICATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @see        java.awt.Image#SCALE_AREA_AVERAGING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public Image getScaledInstance(int width, int height, int hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        ImageFilter filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if ((hints & (SCALE_SMOOTH | SCALE_AREA_AVERAGING)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            filter = new AreaAveragingScaleFilter(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            filter = new ReplicateScaleFilter(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        ImageProducer prod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        prod = new FilteredImageSource(getSource(), filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return Toolkit.getDefaultToolkit().createImage(prod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Use the default image-scaling algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public static final int SCALE_DEFAULT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Choose an image-scaling algorithm that gives higher priority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * to scaling speed than smoothness of the scaled image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public static final int SCALE_FAST = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Choose an image-scaling algorithm that gives higher priority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * to image smoothness than scaling speed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public static final int SCALE_SMOOTH = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Use the image scaling algorithm embodied in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * <code>ReplicateScaleFilter</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * The <code>Image</code> object is free to substitute a different filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * that performs the same algorithm yet integrates more efficiently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * into the imaging infrastructure supplied by the toolkit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @see        java.awt.image.ReplicateScaleFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public static final int SCALE_REPLICATE = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Use the Area Averaging image scaling algorithm.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * image object is free to substitute a different filter that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * performs the same algorithm yet integrates more efficiently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * into the image infrastructure supplied by the toolkit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see java.awt.image.AreaAveragingScaleFilter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public static final int SCALE_AREA_AVERAGING = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Flushes all reconstructable resources being used by this Image object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * This includes any pixel data that is being cached for rendering to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * the screen as well as any system resources that are being used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * to store data or pixels for the image if they can be recreated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * The image is reset to a state similar to when it was first created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * so that if it is again rendered, the image data will have to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * recreated or fetched again from its source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Examples of how this method affects specific types of Image object:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * BufferedImage objects leave the primary Raster which stores their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * pixels untouched, but flush any information cached about those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * pixels such as copies uploaded to the display hardware for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * accelerated blits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Image objects created by the Component methods which take a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * width and height leave their primary buffer of pixels untouched,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * but have all cached information released much like is done for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * BufferedImage objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * VolatileImage objects release all of their pixel resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * including their primary copy which is typically stored on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * the display hardware where resources are scarce.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * These objects can later be restored using their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * {@link java.awt.image.VolatileImage#validate validate}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Image objects created by the Toolkit and Component classes which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * loaded from files, URLs or produced by an {@link ImageProducer}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * are unloaded and all local resources are released.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * These objects can later be reloaded from their original source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * as needed when they are rendered, just as when they were first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public void flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (surfaceManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            surfaceManager.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Returns an ImageCapabilities object which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * inquired as to the capabilities of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Image on the specified GraphicsConfiguration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * This allows programmers to find
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * out more runtime information on the specific Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * object that they have created.  For example, the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * might create a BufferedImage but the system may have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * no video memory left for creating an image of that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * size on the given GraphicsConfiguration, so although the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * may be acceleratable in general, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * does not have that capability on this GraphicsConfiguration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param gc a <code>GraphicsConfiguration</code> object.  A value of null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * for this parameter will result in getting the image capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * for the default <code>GraphicsConfiguration</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @return an <code>ImageCapabilities</code> object that contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * the capabilities of this <code>Image</code> on the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * GraphicsConfiguration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @see java.awt.image.VolatileImage#getCapabilities()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * VolatileImage.getCapabilities()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (surfaceManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            return surfaceManager.getCapabilities(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // Note: this is just a default object that gets returned in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        // absence of any more specific information from a surfaceManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        // Subclasses of Image should either override this method or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        // make sure that they always have a non-null SurfaceManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // to return an ImageCapabilities object that is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // for their given subclass type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return defaultImageCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Sets a hint for this image about how important acceleration is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * This priority hint is used to compare to the priorities of other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Image objects when determining how to use scarce acceleration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * resources such as video memory.  When and if it is possible to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * accelerate this Image, if there are not enough resources available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * to provide that acceleration but enough can be freed up by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * de-accelerating some other image of lower priority, then that other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Image may be de-accelerated in deference to this one.  Images
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * that have the same priority take up resources on a first-come,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * first-served basis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @param priority a value between 0 and 1, inclusive, where higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * values indicate more importance for acceleration.  A value of 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * means that this Image should never be accelerated.  Other values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * are used simply to determine acceleration priority relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @throws IllegalArgumentException if <code>priority</code> is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * than zero or greater than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public void setAccelerationPriority(float priority) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        if (priority < 0 || priority > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            throw new IllegalArgumentException("Priority must be a value " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                               "between 0 and 1, inclusive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        accelerationPriority = priority;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (surfaceManager != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            surfaceManager.setAccelerationPriority(accelerationPriority);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Returns the current value of the acceleration priority hint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @see #setAccelerationPriority(float priority) setAccelerationPriority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @return value between 0 and 1, inclusive, which represents the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * priority value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public float getAccelerationPriority() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return accelerationPriority;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    SurfaceManager surfaceManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        SurfaceManager.setImageAccessor(new SurfaceManager.ImageAccessor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            public SurfaceManager getSurfaceManager(Image img) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                return img.surfaceManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            public void setSurfaceManager(Image img, SurfaceManager mgr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                img.surfaceManager = mgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
}