implemented fade example, fixed bug in data output
Stefan Schuermans

Stefan Schuermans commited on 2011-09-11 11:18:16
Showing 4 changed files, with 93 additions and 5 deletions.

... ...
@@ -34,14 +34,14 @@ PKG_PATH_EX=$(PKG_PATH)/examples
34 34
 
35 35
 CLASSES=AddrParser Config Constants Display Distri \
36 36
         Mapping MessageIf MsgType Pixel PixelParser Version
37
-CLASSES_EX=Blink Msg
37
+CLASSES_EX=Blink Fade Msg
38 38
 CLASS_FILES=$(addprefix $(PKG_PATH)/,$(addsuffix .class,$(CLASSES)))
39 39
 CLASS_FILES_EX=$(addprefix $(PKG_PATH_EX)/,$(addsuffix .class,$(CLASSES_EX)))
40 40
 CONFIG_EX=$(PKG_PATH_EX)/config/single8x8.flp
41 41
 
42 42
 CLASSPATH=.
43 43
 
44
-.PHONY: all clean jar blink
44
+.PHONY: all clean jar blink fade
45 45
 .SUFFIXES:
46 46
 .SECONDARY:
47 47
 
... ...
@@ -58,6 +58,9 @@ jar: JFlexiPix.jar
58 58
 blink: $(PKG_PATH_EX)/Blink.class
59 59
 	$(JAVA) -classpath . $(subst /,.,$(basename $<)) $(CONFIG_EX)
60 60
 
61
+fade: $(PKG_PATH_EX)/Fade.class
62
+	$(JAVA) -classpath . $(subst /,.,$(basename $<)) $(CONFIG_EX)
63
+
61 64
 $(CLASS_FILES_EX): $(CLASS_FILES)
62 65
 
63 66
 $(PKG_PATH)/Version.java: Makefile
... ...
@@ -372,7 +372,7 @@ class Config
372 372
       if (m_messageIf != null)
373 373
         m_messageIf.message(MsgType.Warn,
374 374
                             String.format("invalid line %d in config file," +
375
-                                          " ignored\n", m_lineNo));
375
+                                          " ignored", m_lineNo));
376 376
       return;
377 377
     }
378 378
     setting = matcher.group(1);
... ...
@@ -424,7 +424,7 @@ class Config
424 424
                                                m_display.m_size.m_y) +
425 425
          String.format("%d distributors, ",    m_display.m_distriCnt ) +
426 426
          String.format("%d outputs, ",         m_display.m_outputCnt ) +
427
-         String.format("%d pixels\n",          m_display.m_pixelCnt));
427
+         String.format("%d pixels",            m_display.m_pixelCnt));
428 428
   }
429 429
 
430 430
   /**
... ...
@@ -131,7 +131,7 @@ public class Display
131 131
 
132 132
         // get RGB data of pixels for every output
133 133
         for (out = 0, i = 0; out < distri.m_outputCnt; ++out) {
134
-          for (pix = 0; pix < distri.m_pixelCnt; ++pix) {
134
+          for (pix = 0; pix < distri.m_pixelCnt; ++pix, ++i) {
135 135
             pixel = distri.m_pixels[i];
136 136
             if (pixel != null) {
137 137
 
... ...
@@ -0,0 +1,85 @@
1
+/* JFlexiPix - Java implementation of FlexiPix output library
2
+ *
3
+ * Copyright 2010-2011 Stefan Schuermans <stefan blinkenarea org>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, version 3 of the License.
8
+ *
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+package org.blinkenarea.JFlexiPix.examples;
20
+
21
+import org.blinkenarea.JFlexiPix.*;
22
+
23
+public class Fade
24
+{
25
+  // entry point
26
+  public static void main(String [] args)
27
+  {
28
+    String config;
29
+    Display display;
30
+    int width, height, i, x, y;
31
+    byte [] image;
32
+
33
+    // check usage
34
+    if (args.length < 1) {
35
+      System.out.println("usage: java Fade <config.flp>");
36
+      return;
37
+    }
38
+    config = args[0];
39
+
40
+    /* create a display, take configuration from a file,
41
+       deliver messages to message method of new Msg object */
42
+    try {
43
+      display = new Display(config, new Msg());
44
+    } catch (Exception e) {
45
+      System.out.println("could not create display\n");
46
+      e.printStackTrace();
47
+      return;
48
+    }
49
+
50
+    // get size and show it
51
+    width  = display.getWidth();
52
+    height = display.getHeight();
53
+    System.out.println("display size:");
54
+    System.out.println(String.format("  width:  %5d", width ));
55
+    System.out.println(String.format("  height: %5d", height));
56
+
57
+    /* create an image with a nice fade:
58
+       black to red from left to right,
59
+       black to green from top to bottom */
60
+    image = new byte [height * width * 3];
61
+    i = 0;
62
+    for (y = 0; y < height; ++y) {
63
+      for (x = 0; x < width; ++x) {
64
+        image[i++] = (byte)(255.0*x/(width -1)+0.5); // red
65
+        image[i++] = (byte)(255.0*y/(height-1)+0.5); // green
66
+        image[i++] = (byte)0;                        // no blue
67
+      }
68
+    }
69
+
70
+    // output image
71
+    display.data(image,
72
+                 3,         // consecutive pixels are 3 bytes apart
73
+                 width * 3, // consecutive lines are width * 3 bytes apart
74
+                 0, 0, width, height);
75
+    display.send();
76
+    try {
77
+      Thread.sleep(500);
78
+    } catch (InterruptedException e) {
79
+    }
80
+
81
+    // free display
82
+    display = null;
83
+  }
84
+}
85
+
0 86