01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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 Alexey A. Petrenko, Igor V. Stolyarov
19: * @version $Revision$
20: */package org.apache.harmony.awt.gl;
21:
22: import java.awt.Image;
23: import java.awt.image.BufferedImage;
24: import java.awt.image.VolatileImage;
25:
26: import org.apache.harmony.awt.gl.image.OffscreenImage;
27: import org.apache.harmony.awt.nativebridge.NativeBridge;
28: import org.apache.harmony.misc.accessors.AccessorFactory;
29: import org.apache.harmony.misc.accessors.ArrayAccessor;
30: import org.apache.harmony.misc.accessors.MemoryAccessor;
31: import org.apache.harmony.misc.accessors.StringAccessor;
32:
33: /**
34: * This class includes widely useful static instances and methods.
35: *
36: */
37: public class Utils {
38: public static final MemoryAccessor memaccess = AccessorFactory
39: .getMemoryAccessor();
40:
41: public static final ArrayAccessor arraccess = AccessorFactory
42: .getArrayAccessor();
43:
44: public static final StringAccessor straccess = AccessorFactory
45: .getStringAccessor();
46:
47: public static final NativeBridge nativeBridge = NativeBridge
48: .getInstance();
49:
50: public static BufferedImage getBufferedImage(Image img) {
51: if (img instanceof BufferedImage) {
52: return (BufferedImage) img;
53: } else if (img instanceof VolatileImage) {
54: return ((VolatileImage) img).getSnapshot();
55: } else {
56: OffscreenImage offImg;
57: if (img instanceof OffscreenImage) {
58: offImg = (OffscreenImage) img;
59: } else {
60: offImg = new OffscreenImage(img.getSource());
61: }
62: if (offImg.prepareImage(null)) {
63: return offImg.getBufferedImage();
64: }
65: return null;
66: }
67: }
68: }
|