BlinkenSimJava v.0.1.1 (2004-06-29)
Christian Heimke

Christian Heimke commited on 2011-07-15 09:13:03
Showing 27 changed files, with 459 additions and 24 deletions.

... ...
@@ -1,22 +1,124 @@
1 1
 import java.lang.*;
2 2
 import java.applet.*;
3 3
 import java.awt.*;
4
+import java.net.*;
4 5
 
5 6
 public class BlinkenSim extends Applet
6 7
 { 
8
+  private int pixelX = 0;
9
+  private int pixelY = 0;
10
+  private int colors = 0;
11
+  private int backgroundX = 0;
12
+  private int backgroundY = 0;
13
+  private int windowX = 0;
14
+  private int windowY = 0;
15
+  private int startX = 0;
16
+  private int startY = 0;
17
+  private int distanceX = 0;
18
+  private int distanceY = 0;
19
+  private Image backgroundImg;
20
+  private Image overlayImg;
7 21
   private DynMcufClient mcuf;
8 22
   private FrameProcessor frameProc;
9 23
 
10 24
   public void init( )
11 25
   {
12
-    String host = "";
26
+    String param;
27
+    URL url;
28
+    String host;
13 29
     int port = 0;
14 30
 
31
+    param = getParameter( "pixelX" );
32
+    if( param != null )
33
+      pixelX = Integer.parseInt( param );
34
+    if( pixelX < 1 || pixelX > 100 )
35
+      pixelX = 26;
36
+    param = getParameter( "pixelY" );
37
+    if( param != null )
38
+      pixelY = Integer.parseInt( param );
39
+    if( pixelY < 1 || pixelY > 100 )
40
+      pixelY = 20;
41
+    param = getParameter( "colors" );
42
+    if( param != null )
43
+      colors = Integer.parseInt( param );
44
+    if( colors < 1 || colors > 256 )
45
+      colors = 8;
46
+    param = getParameter( "backgroundX" );
47
+    if( param != null )
48
+      backgroundX = Integer.parseInt( param );
49
+    if( backgroundX < 1 || backgroundX > 2048 )
50
+      backgroundX = 144;
51
+    param = getParameter( "backgroundY" );
52
+    if( param != null )
53
+      backgroundY = Integer.parseInt( param );
54
+    if( backgroundY < 1 || backgroundY > 2048 )
55
+      backgroundY = 108;
56
+    param = getParameter( "windowX" );
57
+    if( param != null )
58
+      windowX = Integer.parseInt( param );
59
+    if( windowX < 1 || windowX > 256 )
60
+      windowX = 2;
61
+    param = getParameter( "windowY" );
62
+    if( param != null )
63
+      windowY = Integer.parseInt( param );
64
+    if( windowY < 1 || windowY > 256 )
65
+      windowY = 4;
66
+    param = getParameter( "startX" );
67
+    if( param != null )
68
+      startX = Integer.parseInt( param );
69
+    if( startX < 1 || startX > 2048 )
70
+      startX = 21;
71
+    param = getParameter( "startY" );
72
+    if( param != null )
73
+      startY = Integer.parseInt( param );
74
+    if( startY < 1 || startY > 2048 )
75
+      startY = 5;
76
+    param = getParameter( "distanceX" );
77
+    if( param != null )
78
+      distanceX = Integer.parseInt( param );
79
+    if( distanceX < 1 || distanceX > 512 )
80
+      distanceX = 2;
81
+    param = getParameter( "distanceY" );
82
+    if( param != null )
83
+      distanceY = Integer.parseInt( param );
84
+    if( distanceY < 1 || distanceY > 512 )
85
+      distanceY = 24;
86
+
87
+    url = getDocumentBase( );
88
+    if( url != null )
89
+    {
90
+      backgroundImg = getImage( url, getParameter( "background" ) );
91
+      overlayImg = getImage( url, getParameter( "overlay" ) );
92
+    }
93
+    else
94
+    {
95
+      try
96
+      {
97
+        url = new URL( "file:" + getParameter( "background" ) );
98
+        backgroundImg = getImage( url );
99
+      }
100
+      catch( MalformedURLException e )
101
+      {
102
+        backgroundImg = createImage( -1, -1 );
103
+      }
104
+      try
105
+      {
106
+        url = new URL( "file:" + getParameter( "overlay" ) );
107
+        overlayImg = getImage( url );
108
+      }
109
+      catch( MalformedURLException e )
110
+      {
111
+        overlayImg = createImage( -1, -1 );
112
+      }
113
+    }
114
+
15 115
     host = getParameter( "host" );
16
-    if( host.length( ) <= 0 )
116
+    if( host == null || host.length( ) <= 0 )
17 117
       host = "proxy.blinkenlights.de";
18 118
     
19
-    port = Integer.parseInt( getParameter( "port" ) );
119
+    param = getParameter( "port" );
120
+    if( param != null )
121
+      port = Integer.parseInt( param );
20 122
     if( port <= 0 || port > 65535 )
21 123
       port = 4242;
22 124
 
... ...
@@ -34,43 +136,31 @@ public class BlinkenSim extends Applet
34 136
 
35 137
   public void paint( Graphics g )
36 138
   {
37
-    int height, width, channels;
38 139
     byte[][][] data;
39 140
     Image img;
40 141
     Graphics gBuf;
41
-    int y, x, c, val;
142
+    int y, yy, x, xx, c;
42 143
     
43 144
     Frame frame = frameProc.getFrame( );
44
-    height = frame.getHeight( );
45
-    width = frame.getWidth( );
46
-    channels = frame.getChannels( );
145
+    frame.resize( pixelY, pixelX, 1 );
47 146
     data = frame.getData( );
48 147
     
49
-    img = createImage( width * 10 + 20, height * 20 + 50 );
148
+    img = createImage( backgroundX, backgroundY );
50 149
     gBuf = img.getGraphics( );
51 150
 
52
-    gBuf.setColor( Color.black );
53
-    gBuf.fillRect( 0, 0, width * 10 + 20, height * 20 + 50 );
151
+    gBuf.drawImage( backgroundImg, 0, 0, this );
54 152
 
55
-    gBuf.setColor( Color.white );
56
-    gBuf.drawString( "BlinkenSimJava: " + height + "x" + width + "-" + channels, 20, 20 );
57
-
58
-    for( y = 0; y < height; y++ )
153
+    for( y = 0, yy = startY; y < pixelY; y++, yy += distanceY )
59 154
     {
60
-      for( x = 0; x < width; x++ )
155
+      for( x = 0, xx = startX; x < pixelX; x++, xx += distanceX )
61 156
       {
62
-        val = 0;
63
-        for( c = 0; c < channels; c++ )
64
-          val += data[y][x][c] & 0xFF;
65
-        val /= channels;
66
-        gBuf.setColor( new Color( val, val, val ) );
67
-        gBuf.fillRect( x * 10 + 10, y * 20 + 30, 10, 20 );
157
+        c = ((data[y][x][0] & 0xFF) * (colors - 1) + 0x7F) / 0xFF;
158
+        gBuf.drawImage( overlayImg, xx, yy, xx + windowX, yy + windowY,
159
+                        c * windowX, 0, c * windowX + windowX, windowY, this );
68 160
       }
69 161
     }
70 162
 
71 163
     g.drawImage( img, 0, 0, this );
72
-
73
-    //System.out.println( frame.toString( ) );
74 164
   }
75 165
 
76 166
   public void update( Graphics g )
... ...
@@ -53,6 +53,62 @@ public class Frame
53 53
     return data;
54 54
   }
55 55
 
56
+  public void resize( int height, int width, int channels )
57
+  {
58
+    byte[][][] data;
59
+    int y, x, c;
60
+    int emptyY, emptyX, skipY, skipX, rangeY, rangeX, val;
61
+
62
+    data = new byte[height][width][channels];
63
+    for( y = 0; y < height; y++ )
64
+      for( x = 0; x < width; x++ )
65
+        for( c = 0; c < channels; c++ )
66
+          data[y][x][c] = 0;
67
+
68
+    if( height > this.height )
69
+    {
70
+      emptyY = (height - this.height) / 2; 
71
+      skipY = 0;
72
+      rangeY = this.height;
73
+    }
74
+    else
75
+    {
76
+      emptyY = 0;
77
+      skipY = (this.height - height) / 2;
78
+      rangeY = height;
79
+    }
80
+    if( width > this.width )
81
+    {
82
+      emptyX = (width - this.width) / 2; 
83
+      skipX = 0;
84
+      rangeX = this.width;
85
+    }
86
+    else
87
+    {
88
+      emptyX = 0;
89
+      skipX = (this.width - width) / 2;
90
+      rangeX = width;
91
+    }
92
+
93
+    for( y = 0; y < rangeY; y++ )
94
+    {
95
+      for( x = 0; x < rangeX; x++ )
96
+      {
97
+        val = 0;
98
+        for( c = 0; c < this.channels; c++ )
99
+          val += this.data[skipY + y][skipX + x][c] & 0xFF;
100
+        val /= this.channels;
101
+        for( c = 0; c < channels; c++ )
102
+          data[emptyY + y][emptyX + x][c] = (byte)val;
103
+      }
104
+    }
105
+
106
+    this.height = height;
107
+    this.width = width;
108
+    this.channels = channels;
109
+    this.data = data;
110
+  }
111
+
56 112
   public String toString( )
57 113
   {
58 114
     String str = "";
... ...
@@ -1,4 +1,5 @@
1 1
 BlinkenLights stream viever in Java
2 2
 done by 1stein@schuermans.info
3
+pre-alpha-released under GPL (version 2)
3 4
 very incomplete
4 5
 no comments yet ;)
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - BNF - 144x108</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="144" height="108">
7
+      <param name="pixelX" value="26">
8
+      <param name="pixelY" value="20">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="bnf-144x108-bg.png">
11
+      <param name="backgroundX" value="144">
12
+      <param name="backgroundY" value="108">
13
+      <param name="overlay" value="bnf-144x108-ov.png">
14
+      <param name="windowX" value="2">
15
+      <param name="windowY" value="4">
16
+      <param name="startX" value="21">
17
+      <param name="startY" value="5">
18
+      <param name="distanceX" value="2">
19
+      <param name="distanceY" value="4">
20
+      <param name="host" value="www.1stein.no-ip.com">
21
+      <param name="port" value="23231">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - BNF - 144x108</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="144" height="108">
7
+      <param name="pixelX" value="26">
8
+      <param name="pixelY" value="20">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="bnf-144x108-bg.png">
11
+      <param name="backgroundX" value="144">
12
+      <param name="backgroundY" value="108">
13
+      <param name="overlay" value="bnf-144x108-ov.png">
14
+      <param name="windowX" value="2">
15
+      <param name="windowY" value="4">
16
+      <param name="startX" value="21">
17
+      <param name="startY" value="5">
18
+      <param name="distanceX" value="2">
19
+      <param name="distanceY" value="4">
20
+      <param name="host" value="192.168.0.33">
21
+      <param name="port" value="23231">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - BNF - 640x480</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="640" height="480">
7
+      <param name="pixelX" value="26">
8
+      <param name="pixelY" value="20">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="bnf-640x480-bg.png">
11
+      <param name="backgroundX" value="640">
12
+      <param name="backgroundY" value="480">
13
+      <param name="overlay" value="bnf-640x480-ov.png">
14
+      <param name="windowX" value="7">
15
+      <param name="windowY" value="14">
16
+      <param name="startX" value="125">
17
+      <param name="startY" value="31">
18
+      <param name="distanceX" value="7">
19
+      <param name="distanceY" value="14">
20
+      <param name="host" value="www.1stein.no-ip.com">
21
+      <param name="port" value="23231">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - BNF - 640x480</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="640" height="480">
7
+      <param name="pixelX" value="26">
8
+      <param name="pixelY" value="20">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="bnf-640x480-bg.png">
11
+      <param name="backgroundX" value="640">
12
+      <param name="backgroundY" value="480">
13
+      <param name="overlay" value="bnf-640x480-ov.png">
14
+      <param name="windowX" value="7">
15
+      <param name="windowY" value="14">
16
+      <param name="startX" value="125">
17
+      <param name="startY" value="31">
18
+      <param name="distanceX" value="7">
19
+      <param name="distanceY" value="14">
20
+      <param name="host" value="192.168.0.33">
21
+      <param name="port" value="23231">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - HDL - 1024x768</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="1024" height="768">
7
+      <param name="pixelX" value="18">
8
+      <param name="pixelY" value="8">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="hdl-1024x768-bg.png">
11
+      <param name="backgroundX" value="1024">
12
+      <param name="backgroundY" value="768">
13
+      <param name="overlay" value="hdl-1024x768-ov.png">
14
+      <param name="windowX" value="30">
15
+      <param name="windowY" value="35">
16
+      <param name="startX" value="347">
17
+      <param name="startY" value="74">
18
+      <param name="distanceX" value="30">
19
+      <param name="distanceY" value="55">
20
+      <param name="host" value="www.1stein.no-ip.com">
21
+      <param name="port" value="23230">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - HDL - 1024x768</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="1024" height="768">
7
+      <param name="pixelX" value="18">
8
+      <param name="pixelY" value="8">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="hdl-1024x768-bg.png">
11
+      <param name="backgroundX" value="1024">
12
+      <param name="backgroundY" value="768">
13
+      <param name="overlay" value="hdl-1024x768-ov.png">
14
+      <param name="windowX" value="30">
15
+      <param name="windowY" value="35">
16
+      <param name="startX" value="347">
17
+      <param name="startY" value="74">
18
+      <param name="distanceX" value="30">
19
+      <param name="distanceY" value="55">
20
+      <param name="host" value="192.168.0.33">
21
+      <param name="port" value="23230">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - HDL - 144x108</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="144" height="108">
7
+      <param name="pixelX" value="18">
8
+      <param name="pixelY" value="8">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="hdl-144x108-bg.png">
11
+      <param name="backgroundX" value="144">
12
+      <param name="backgroundY" value="108">
13
+      <param name="overlay" value="hdl-144x108-ov.png">
14
+      <param name="windowX" value="4">
15
+      <param name="windowY" value="7">
16
+      <param name="startX" value="46">
17
+      <param name="startY" value="14">
18
+      <param name="distanceX" value="4">
19
+      <param name="distanceY" value="7">
20
+      <param name="host" value="www.1stein.no-ip.com">
21
+      <param name="port" value="23230">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - HDL - 144x108</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="144" height="108">
7
+      <param name="pixelX" value="18">
8
+      <param name="pixelY" value="8">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="hdl-144x108-bg.png">
11
+      <param name="backgroundX" value="144">
12
+      <param name="backgroundY" value="108">
13
+      <param name="overlay" value="hdl-144x108-ov.png">
14
+      <param name="windowX" value="4">
15
+      <param name="windowY" value="7">
16
+      <param name="startX" value="46">
17
+      <param name="startY" value="14">
18
+      <param name="distanceX" value="4">
19
+      <param name="distanceY" value="7">
20
+      <param name="host" value="192.168.0.33">
21
+      <param name="port" value="23230">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - HDL - 640x480</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="640" height="480">
7
+      <param name="pixelX" value="18">
8
+      <param name="pixelY" value="8">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="hdl-640x480-bg.png">
11
+      <param name="backgroundX" value="640">
12
+      <param name="backgroundY" value="480">
13
+      <param name="overlay" value="hdl-640x480-ov.png">
14
+      <param name="windowX" value="19">
15
+      <param name="windowY" value="22">
16
+      <param name="startX" value="217">
17
+      <param name="startY" value="52">
18
+      <param name="distanceX" value="19">
19
+      <param name="distanceY" value="34">
20
+      <param name="host" value="www.1stein.no-ip.com">
21
+      <param name="port" value="23230">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - HDL - 640x480</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="640" height="480">
7
+      <param name="pixelX" value="18">
8
+      <param name="pixelY" value="8">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="hdl-640x480-bg.png">
11
+      <param name="backgroundX" value="640">
12
+      <param name="backgroundY" value="480">
13
+      <param name="overlay" value="hdl-640x480-ov.png">
14
+      <param name="windowX" value="19">
15
+      <param name="windowY" value="22">
16
+      <param name="startX" value="217">
17
+      <param name="startY" value="52">
18
+      <param name="distanceX" value="19">
19
+      <param name="distanceY" value="34">
20
+      <param name="host" value="192.168.0.33">
21
+      <param name="port" value="23230">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - HDL - 800x600</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="800" height="600">
7
+      <param name="pixelX" value="18">
8
+      <param name="pixelY" value="8">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="hdl-800x600-bg.png">
11
+      <param name="backgroundX" value="800">
12
+      <param name="backgroundY" value="600">
13
+      <param name="overlay" value="hdl-800x600-ov.png">
14
+      <param name="windowX" value="24">
15
+      <param name="windowY" value="28">
16
+      <param name="startX" value="267">
17
+      <param name="startY" value="60">
18
+      <param name="distanceX" value="24">
19
+      <param name="distanceY" value="43">
20
+      <param name="host" value="www.1stein.no-ip.com">
21
+      <param name="port" value="23230">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
... ...
@@ -0,0 +1,24 @@
1
+<html>
2
+  <head>
3
+    <title>BlinkenSimJava - HDL - 800x600</title>
4
+  </head>
5
+  <body>
6
+    <applet archive="BlinkenSim.jar" code="BlinkenSim.class" width="800" height="600">
7
+      <param name="pixelX" value="18">
8
+      <param name="pixelY" value="8">
9
+      <param name="colors" value="8">
10
+      <param name="background" value="hdl-800x600-bg.png">
11
+      <param name="backgroundX" value="800">
12
+      <param name="backgroundY" value="600">
13
+      <param name="overlay" value="hdl-800x600-ov.png">
14
+      <param name="windowX" value="24">
15
+      <param name="windowY" value="28">
16
+      <param name="startX" value="267">
17
+      <param name="startY" value="60">
18
+      <param name="distanceX" value="24">
19
+      <param name="distanceY" value="43">
20
+      <param name="host" value="192.168.0.33">
21
+      <param name="port" value="23230">
22
+    </applet archive="BlinkenSim.jar">
23
+  </body>
24
+</html>
0 25