001: /*
002: * $RCSfile: SFImage.java,v $
003: *
004: * @(#)SFImage.java 1.13 98/11/05 20:35:01
005: *
006: * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
007: *
008: * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
009: * modify and redistribute this software in source and binary code form,
010: * provided that i) this copyright notice and license appear on all copies of
011: * the software; and ii) Licensee does not utilize the software in a manner
012: * which is disparaging to Sun.
013: *
014: * This software is provided "AS IS," without a warranty of any kind. ALL
015: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
016: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
017: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
018: * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
020: * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: *
032: * $Revision: 1.2 $
033: * $Date: 2005/02/03 23:07:01 $
034: * $State: Exp $
035: */
036: /*
037: * @Author: Rick Goldberg
038: * @Author: Doug Gehringer
039: *
040: */
041: package org.jdesktop.j3d.loaders.vrml97.impl;
042:
043: import java.util.Observable;
044: import java.util.Observer;
045:
046: /** Description of the Class */
047: public class SFImage extends Field {
048: byte[] pixels;
049: int width;
050: int height;
051: int depth;
052:
053: /**
054: *Constructor for the SFImage object
055: *
056: *@param w Description of the Parameter
057: *@param h Description of the Parameter
058: *@param d Description of the Parameter
059: *@param p Description of the Parameter
060: */
061: public SFImage(int w, int h, int d, byte[] p) {
062: if (p != null) {
063: pixels = new byte[p.length];
064: System.arraycopy(p, 0, pixels, 0, p.length);
065: } else {
066: pixels = null;
067: }
068:
069: width = w;
070: height = h;
071: depth = d;
072:
073: }
074:
075: /**
076: * Gets the width attribute of the SFImage object
077: *
078: *@return The width value
079: */
080: public int getWidth() {
081: return width;
082: }
083:
084: /**
085: * Gets the height attribute of the SFImage object
086: *
087: *@return The height value
088: */
089: public int getHeight() {
090: return height;
091: }
092:
093: /**
094: * Gets the components attribute of the SFImage object
095: *
096: *@return The components value
097: */
098: public int getComponents() {
099: return depth;
100: }
101:
102: /**
103: * Gets the pixels attribute of the SFImage object
104: *
105: *@param p Description of the Parameter
106: */
107: public void getPixels(byte[] p) {
108: System.arraycopy(pixels, 0, p, 0, pixels.length);
109: }
110:
111: /**
112: * Sets the value attribute of the SFImage object
113: *
114: *@param w The new value value
115: *@param h The new value value
116: *@param d The new value value
117: *@param p The new value value
118: */
119: public void setValue(int w, int h, int d, byte[] p) {
120: width = w;
121: height = h;
122: depth = d;
123: if ((w * h * d) > 0) {
124: pixels = new byte[p.length];// could check h*w*d = p.length
125: try {
126: System.arraycopy(p, 0, pixels, 0, p.length);
127: } catch (Exception e) {
128: System.err
129: .println("SFImage.setValue(): exception " + e);
130: }
131: } else {
132: pixels = null;
133: }
134:
135: route();// be very careful since the new new new new semantic
136: // is route to copy
137: }
138:
139: /**
140: * Sets the value attribute of the SFImage object
141: *
142: *@param i The new value value
143: */
144: public void setValue(ConstSFImage i) {
145: setValue((SFImage) i.ownerField);
146: }
147:
148: /**
149: * Sets the value attribute of the SFImage object
150: *
151: *@param i The new value value
152: */
153: public void setValue(SFImage i) {
154: setValue(i.width, i.height, i.depth, i.pixels);
155: }
156:
157: /**
158: * Description of the Method
159: *
160: *@return Description of the Return Value
161: */
162: public synchronized Object clone() {
163: return new SFImage(width, height, depth, pixels);
164: }
165:
166: /**
167: * Description of the Method
168: *
169: *@param field Description of the Parameter
170: */
171: public void update(Field field) {
172: setValue((SFImage) field);
173: }
174:
175: /**
176: * Description of the Method
177: *
178: *@return Description of the Return Value
179: */
180: public synchronized ConstField constify() {
181: if (constField == null) {
182: constField = new ConstSFImage(this );
183: }
184: return constField;
185: }
186:
187: /**
188: * Description of the Method
189: *
190: *@return Description of the Return Value
191: */
192: public vrml.Field wrap() {
193: return new vrml.field.SFImage(this);
194: }
195:
196: }
|