FreeWRL/FreeX3D  3.0.0
EventInSFImage.java
1 package vrml.external.field;
4 import java.awt.*;
5 import java.math.BigInteger;
6 
7 public class EventInSFImage extends EventIn {
8 
9  public EventInSFImage() { EventType = FieldTypes.SFIMAGE; }
10 
11  public void setValue(int width, int height, int components, byte[] pixels) throws IllegalArgumentException {
12  int count;
13  int pixcount;
14  String val;
15  BigInteger newval;
16  byte xx[];
17 
18 
19  if (pixels.length != (width*height*components)) {
20  throw new IllegalArgumentException();
21  }
22 
23  if ((components < 1) || (components > 4)) {
24  throw new IllegalArgumentException();
25  }
26 
27  // use BigInt to ensure sign bit does not frick us up.
28  xx = new byte[components+1];
29  xx[0] = (byte) 0; // no sign bit here!
30 
31  val = new String("" + width + " " + height + " " + components);
32 
33  if (pixels== null) { pixcount = 0;} else {pixcount=pixels.length;}
34 
35  if (components == 1) {
36  for (count = 0; count < pixcount; count++) {
37  xx[1] = pixels[count];
38  newval = new BigInteger(xx);
39  //System.out.println ("Big int " + newval.toString(16));
40  val = val.concat(" 0x" + newval.toString(16));
41  }
42  }
43  if (components == 2) {
44  for (count = 0; count < pixcount; count+=2) {
45  xx[1] = pixels[count]; xx[2] = pixels[count+1];
46  newval = new BigInteger(xx);
47  //System.out.println ("Big int " + newval.toString(16));
48  val = val.concat(" 0x" + newval.toString(16));
49 
50  }
51  }
52  if (components == 3) {
53  for (count = 0; count < pixcount; count+=3) {
54  xx[1] = pixels[count]; xx[2] = pixels[count+1]; xx[3]=pixels[count+2];
55  newval = new BigInteger(xx);
56  //System.out.println ("Big int " + newval.toString(16));
57  val = val.concat(" 0x" + newval.toString(16));
58  }
59  }
60  if (components == 4) {
61  for (count = 0; count < pixcount; count+=4) {
62  xx[1] = pixels[count]; xx[2] = pixels[count+1]; xx[3]=pixels[count+2]; xx[4]=pixels[count+3];
63  newval = new BigInteger(xx);
64  //System.out.println ("Big int " + newval.toString(16));
65  val = val.concat(" 0x" + newval.toString(16));
66 
67  }
68  }
69  //System.out.println ("sending " + val);
70 
71  Browser.newSendEvent (this, val.length() + ":" + val + " ");
72 
73  return;
74  }
75 }