• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 /**
18  * @author Igor V. Stolyarov
19  * @version $Revision$
20  */
21 
22 package java.awt;
23 
24 import java.awt.image.AreaAveragingScaleFilter;
25 import java.awt.image.FilteredImageSource;
26 import java.awt.image.ImageFilter;
27 import java.awt.image.ImageObserver;
28 import java.awt.image.ImageProducer;
29 import java.awt.image.ReplicateScaleFilter;
30 
31 import org.apache.harmony.awt.internal.nls.Messages;
32 
33 /**
34  * The Image abstract class represents the graphic images.
35  *
36  * @since Android 1.0
37  */
38 public abstract class Image {
39 
40     /**
41      * The UndefinedProperty object should be returned if property is not
42      * defined for a particular image.
43      */
44     public static final Object UndefinedProperty = new Object(); // $NON-LOCK-1$
45 
46     /**
47      * The Constant SCALE_DEFAULT indicates the default image scaling algorithm.
48      */
49     public static final int SCALE_DEFAULT = 1;
50 
51     /**
52      * The Constant SCALE_FAST indicates an image scaling algorithm which places
53      * a higher priority on scaling speed than on the image's smoothness.
54      */
55     public static final int SCALE_FAST = 2;
56 
57     /**
58      * The Constant SCALE_SMOOTH indicates an image scaling algorithm which
59      * places a higher priority on image smoothness than on scaling speed.
60      */
61     public static final int SCALE_SMOOTH = 4;
62 
63     /**
64      * The Constant SCALE_REPLICATE indicates the image scaling algorithm in the
65      * ReplicateScaleFilter class.
66      */
67     public static final int SCALE_REPLICATE = 8;
68 
69     /**
70      * The Constant SCALE_AREA_AVERAGING indicates the area averaging image
71      * scaling algorithm.
72      */
73     public static final int SCALE_AREA_AVERAGING = 16;
74 
75     /**
76      * The acceleration priority indicates image acceleration.
77      */
78     protected float accelerationPriority = 0.5f;
79 
80     /**
81      * The Constant capabilities.
82      */
83     private static final ImageCapabilities capabilities = new ImageCapabilities(false);
84 
85     /**
86      * Gets the image property with the specified name. The UndefinedProperty
87      * object should be return if the property is not specified for this image.
88      * The return value should be null if the property is currently unknown yet
89      * and the specified ImageObserver is to be notified later.
90      *
91      * @param name
92      *            the name of image's property.
93      * @param observer
94      *            the ImageObserver.
95      * @return the Object which represents value of the specified property.
96      */
getProperty(String name, ImageObserver observer)97     public abstract Object getProperty(String name, ImageObserver observer);
98 
99     /**
100      * Gets the ImageProducer object which represents data of this Image.
101      *
102      * @return the ImageProducer object which represents data of this Image.
103      */
getSource()104     public abstract ImageProducer getSource();
105 
106     /**
107      * Gets the width of this image. The specified ImageObserver object is
108      * notified when the width of this image is available.
109      *
110      * @param observer
111      *            the ImageObserver object which is is notified when the width
112      *            of this image is available.
113      * @return the width of image, or -1 if the width of this image is not
114      *         available.
115      */
getWidth(ImageObserver observer)116     public abstract int getWidth(ImageObserver observer);
117 
118     /**
119      * Gets the height of this image. The specified ImageObserver object is
120      * notified when the height of this image is available.
121      *
122      * @param observer
123      *            the ImageObserver object which is is notified when the height
124      *            of this image is available.
125      * @return the height of image, or -1 if the height of this image is not
126      *         available.
127      */
getHeight(ImageObserver observer)128     public abstract int getHeight(ImageObserver observer);
129 
130     /**
131      * Gets the scaled instance of this Image. This method returns an Image
132      * object constructed from the source of this image with the specified
133      * width, height, and applied scaling algorithm.
134      *
135      * @param width
136      *            the width of scaled Image.
137      * @param height
138      *            the height of scaled Image.
139      * @param hints
140      *            the constant which indicates scaling algorithm.
141      * @return the scaled Image.
142      */
getScaledInstance(int width, int height, int hints)143     public Image getScaledInstance(int width, int height, int hints) {
144         ImageFilter filter;
145         if ((hints & (SCALE_SMOOTH | SCALE_AREA_AVERAGING)) != 0) {
146             filter = new AreaAveragingScaleFilter(width, height);
147         } else {
148             filter = new ReplicateScaleFilter(width, height);
149         }
150         ImageProducer producer = new FilteredImageSource(getSource(), filter);
151         return Toolkit.getDefaultToolkit().createImage(producer);
152     }
153 
154     /**
155      * Gets a Graphics object for rendering this image. This method can be used
156      * for off-screen images.
157      *
158      * @return a Graphics object for rendering to this image.
159      */
getGraphics()160     public abstract Graphics getGraphics();
161 
162     /**
163      * Flushes resources which are used by this Image object. This method resets
164      * the image to the reconstructed state from the image's source.
165      */
flush()166     public abstract void flush();
167 
168     /**
169      * Gets the acceleration priority of this image.
170      *
171      * @return the acceleration priority of this image.
172      */
getAccelerationPriority()173     public float getAccelerationPriority() {
174         return accelerationPriority;
175     }
176 
177     /**
178      * Sets the acceleration priority for this image.
179      *
180      * @param priority
181      *            the new acceleration priority (value in the range 0-1).
182      */
setAccelerationPriority(float priority)183     public void setAccelerationPriority(float priority) {
184         if (priority < 0 || priority > 1) {
185             // awt.10A=Priority must be a value between 0 and 1, inclusive
186             throw new IllegalArgumentException(Messages.getString("awt.10A")); //$NON-NLS-1$
187         }
188         accelerationPriority = priority;
189     }
190 
191     /**
192      * Gets an ImageCapabilities object of this Image object for the specified
193      * GraphicsConfiguration.
194      *
195      * @param gc
196      *            the specified GraphicsConfiguration object (null value means
197      *            default GraphicsConfiguration).
198      * @return an ImageCapabilities object of this Image object for the
199      *         specified GraphicsConfiguration.
200      */
getCapabilities(GraphicsConfiguration gc)201     public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
202         // Note: common image is not accelerated.
203         return capabilities;
204     }
205 }
206