001: /*
002: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024: package com.sun.mmedia;
025:
026: import com.sun.mmedia.FormatConversionUtils;
027:
028: import javax.microedition.lcdui.Image;
029:
030: /**
031: * The image access class for MIDP.
032: *
033: * @created December 16, 2005
034: */
035: class MIDPImageAccessor implements ImageAccess {
036:
037: /*
038: * ImageAccess I/F method
039: */
040: public int alphaLevelsNumber() {
041: /**
042: * TBD: get display for current MIDlet
043: * javax.microedition.lcdui.Display d = ...;
044: * return d.numAlphaLevels();
045: */
046: return 2;
047: }
048:
049: /*
050: * ImageAccess I/F method
051: */
052: public boolean isImage(Object image) {
053: return (image instanceof Image);
054: }
055:
056: /*
057: * ImageAccess I/F method
058: */
059: public boolean isMutableImage(Object image) {
060: Image img = (Image) image;
061: return img.isMutable();
062: }
063:
064: /*
065: * ImageAccess I/F method
066: */
067: public int getImageWidth(Object image) {
068: if (!(image instanceof Image))
069: return -1;
070:
071: Image img = (Image) image;
072: return img.getWidth();
073: }
074:
075: /*
076: * ImageAccess I/F method
077: */
078: public int getImageHeight(Object image) {
079: if (!(image instanceof Image))
080: return -1;
081:
082: Image img = (Image) image;
083: return img.getHeight();
084: }
085:
086: /*
087: * ImageAccess I/F method
088: */
089: public byte[] getRGBByteImageData(Object image) {
090: return FormatConversionUtils
091: .intArrayToByteArray(getRGBIntImageData(image));
092: }
093:
094: /*
095: * ImageAccess I/F method
096: */
097: public int[] getRGBIntImageData(Object image) {
098: if (!(image instanceof Image))
099: return null;
100:
101: Image img = (Image) image;
102:
103: int w = img.getWidth();
104: int h = img.getHeight();
105: int[] data = new int[w * h];
106:
107: img.getRGB(data, 0, w, 0, 0, w, h);
108: return data;
109: }
110:
111: /*
112: * ImageAccess I/F method
113: */
114: public Object imageCreateFromImage(Object image) {
115: if (!(image instanceof Image))
116: return null;
117:
118: Image img = (Image) image;
119:
120: return Image.createImage(img);
121: }
122:
123: /*
124: * ImageAccess I/F method
125: */
126: public Object imageCreateFromStream(java.io.InputStream stream) {
127: if (stream == null)
128: return null;
129:
130: Image image = null;
131: try {
132: image = Image.createImage(stream);
133: } catch (java.io.IOException ioe) {
134: return null;
135: }
136: return image;
137: }
138:
139: /*
140: * ImageAccess I/F method
141: */
142: public Object imageCreateFromByteArray(byte[] data, int offset,
143: int length) {
144: return Image.createImage(data, offset, length);
145: }
146: }
|