001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Igor V. Stolyarov
019: * @version $Revision$
020: * Created on 23.11.2005
021: *
022: */package java.awt.image;
023:
024: import java.awt.Image;
025: import java.awt.image.DataBuffer;
026: import java.awt.image.DataBufferByte;
027: import java.awt.image.DataBufferDouble;
028: import java.awt.image.DataBufferFloat;
029: import java.awt.image.DataBufferInt;
030: import java.awt.image.DataBufferShort;
031: import java.awt.image.DataBufferUShort;
032:
033: import org.apache.harmony.awt.gl.AwtImageBackdoorAccessor;
034: import org.apache.harmony.awt.gl.GLVolatileImage;
035: import org.apache.harmony.awt.gl.Surface;
036: import org.apache.harmony.awt.gl.image.DataBufferListener;
037: import org.apache.harmony.awt.internal.nls.Messages;
038:
039: /**
040: * This class not part of public API. It useful for receiving package private
041: * data from other packages.
042: */
043: class AwtImageBackdoorAccessorImpl extends AwtImageBackdoorAccessor {
044:
045: static void init() {
046: inst = new AwtImageBackdoorAccessorImpl();
047: }
048:
049: @Override
050: public Surface getImageSurface(Image image) {
051: if (image instanceof BufferedImage) {
052: return ((BufferedImage) image).getImageSurface();
053: } else if (image instanceof GLVolatileImage) {
054: return ((GLVolatileImage) image).getImageSurface();
055: }
056: return null;
057: }
058:
059: @Override
060: public boolean isGrayPallete(IndexColorModel icm) {
061: return icm.isGrayPallete();
062: }
063:
064: @Override
065: public Object getData(DataBuffer db) {
066: if (db instanceof DataBufferByte) {
067: return ((DataBufferByte) db).getData();
068: } else if (db instanceof DataBufferUShort) {
069: return ((DataBufferUShort) db).getData();
070: } else if (db instanceof DataBufferShort) {
071: return ((DataBufferShort) db).getData();
072: } else if (db instanceof DataBufferInt) {
073: return ((DataBufferInt) db).getData();
074: } else if (db instanceof DataBufferFloat) {
075: return ((DataBufferFloat) db).getData();
076: } else if (db instanceof DataBufferDouble) {
077: return ((DataBufferDouble) db).getData();
078: } else {
079: // awt.235=Wrong Data Buffer type : {0}
080: throw new IllegalArgumentException(Messages.getString(
081: "awt.235", //$NON-NLS-1$
082: db.getClass()));
083: }
084: }
085:
086: @Override
087: public int[] getDataInt(DataBuffer db) {
088: if (db instanceof DataBufferInt) {
089: return ((DataBufferInt) db).getData();
090: }
091: return null;
092: }
093:
094: @Override
095: public byte[] getDataByte(DataBuffer db) {
096: if (db instanceof DataBufferByte) {
097: return ((DataBufferByte) db).getData();
098: }
099: return null;
100: }
101:
102: @Override
103: public short[] getDataShort(DataBuffer db) {
104: if (db instanceof DataBufferShort) {
105: return ((DataBufferShort) db).getData();
106: }
107: return null;
108: }
109:
110: @Override
111: public short[] getDataUShort(DataBuffer db) {
112: if (db instanceof DataBufferUShort) {
113: return ((DataBufferUShort) db).getData();
114: }
115: return null;
116: }
117:
118: @Override
119: public double[] getDataDouble(DataBuffer db) {
120: if (db instanceof DataBufferDouble) {
121: return ((DataBufferDouble) db).getData();
122: }
123: return null;
124: }
125:
126: @Override
127: public float[] getDataFloat(DataBuffer db) {
128: if (db instanceof DataBufferFloat) {
129: return ((DataBufferFloat) db).getData();
130: }
131: return null;
132: }
133:
134: @Override
135: public void addDataBufferListener(DataBuffer db,
136: DataBufferListener listener) {
137: db.addDataBufferListener(listener);
138: }
139:
140: @Override
141: public void removeDataBufferListener(DataBuffer db) {
142: db.removeDataBufferListener();
143: }
144:
145: @Override
146: public void validate(DataBuffer db) {
147: db.validate();
148: }
149:
150: @Override
151: public void releaseData(DataBuffer db) {
152: db.releaseData();
153: }
154: }
|