Renamed Frame to VideoFrame
authorTomas Wenström <tomas.wenstrom@gmail.com>
Sat, 23 Mar 2019 11:02:42 +0000 (12:02 +0100)
committerTomas Wenström <tomas.wenstrom@gmail.com>
Sat, 23 Mar 2019 11:04:31 +0000 (12:04 +0100)
src/kaka/cakelight/CakeLight.java
src/kaka/cakelight/FrameGrabber.java
src/kaka/cakelight/GuiTest.java
src/kaka/cakelight/VideoFrame.java [moved from src/kaka/cakelight/Frame.java with 97% similarity]
src/kaka/cakelight/VideoMode.java

index 95a3be1..3769dce 100644 (file)
@@ -30,7 +30,7 @@ public class CakeLight {
         // TODO
 //        FrameGrabber grabber = FrameGrabber.from(config);
 //        grabber.prepare();
-//        Frame frame = grabber.grabFrame();
+//        VideoFrame frame = grabber.grabFrame();
 //        double time = 0;
 //        for (int i = 0; i < 100; i++) {
 //            time += timeIt("frame", () -> grabber.grabFrame());
index dbf620a..1db5c2c 100644 (file)
@@ -37,12 +37,12 @@ public class FrameGrabber implements Closeable {
     /**
      * Must be run in the same thread as {@link #prepare}.
      */
-    public Optional<Frame> grabFrame() {
+    public Optional<VideoFrame> grabFrame() {
         try {
             byte[] data = new byte[bytesPerFrame];
             int count = fileStream.read(data);
             log("# of bytes read = " + count);
-            return Optional.of(Frame.of(data, config));
+            return Optional.of(VideoFrame.of(data, config));
         } catch (IOException e) {
             e.printStackTrace();
         }
index c72519a..0d199c2 100644 (file)
@@ -68,7 +68,7 @@ public class GuiTest extends Application {
         return javafx.scene.paint.Color.rgb(c.r(), c.g(), c.b());
     }
 
-    private void drawFrame(GraphicsContext gc, Frame frame) {
+    private void drawFrame(GraphicsContext gc, VideoFrame frame) {
         if (paused) return;
         System.out.println("Drawing a frame");
         drawCols(gc, frame);
@@ -100,7 +100,7 @@ public class GuiTest extends Application {
         }
     }
 
-    private void drawVideo(GraphicsContext gc, Frame frame) {
+    private void drawVideo(GraphicsContext gc, VideoFrame frame) {
         byte[] rgb = new byte[3];
         Mat img = frame.getConvertedImage();
         float colSize = 16 * BLOCK / (float)img.cols();
@@ -114,7 +114,7 @@ public class GuiTest extends Application {
         }
     }
 
-    private void drawCols(GraphicsContext gc, Frame frame) {
+    private void drawCols(GraphicsContext gc, VideoFrame frame) {
         byte[] rgb = new byte[3];
         for (int x = 0; x < config.leds.cols; x++) {
             for (int y = 0; y < 9; y++) {
@@ -124,7 +124,7 @@ public class GuiTest extends Application {
         }
     }
 
-    private void drawRows(GraphicsContext gc, Frame frame) {
+    private void drawRows(GraphicsContext gc, VideoFrame frame) {
         byte[] rgb = new byte[3];
         for (int y = 0; y < config.leds.rows; y++) {
             for (int x = 0; x < 16; x++) {
similarity index 97%
rename from src/kaka/cakelight/Frame.java
rename to src/kaka/cakelight/VideoFrame.java
index 053b713..30d8593 100644 (file)
@@ -8,7 +8,7 @@ import org.opencv.imgproc.Imgproc;
 import static kaka.cakelight.Main.saveFile;
 import static kaka.cakelight.Main.timeIt;
 
-public class Frame {
+public class VideoFrame {
     private byte[] data;
     private Configuration config;
 //    private Mat colImage;
@@ -16,12 +16,12 @@ public class Frame {
     private Mat converted;
     private Mat[] images;
 
-    private Frame(byte[] data) {
+    private VideoFrame(byte[] data) {
         this.data = data;
     }
 
-    public static Frame of(byte[] data, Configuration config) {
-        Frame frame = new Frame(data);
+    public static VideoFrame of(byte[] data, Configuration config) {
+        VideoFrame frame = new VideoFrame(data);
         frame.config = config;
         frame.convert();
         return frame;
index 1f6d68f..134fa2d 100644 (file)
@@ -8,7 +8,7 @@ import java.util.function.Consumer;
 public class VideoMode extends Mode {
     private Configuration config;
     private Thread grabberThread;
-    private Consumer<Frame> frameConsumer;
+    private Consumer<VideoFrame> frameConsumer;
     private VideoDeviceListener deviceListener;
 
     public VideoMode() {
@@ -34,9 +34,9 @@ public class VideoMode extends Mode {
             public void run() {
                 try (FrameGrabber grabber = FrameGrabber.from(videoDevice, config)) {
                     while (!isInterrupted()) {
-                        Optional<Frame> frame = grabber.grabFrame();
+                        Optional<VideoFrame> frame = grabber.grabFrame();
                         if (frameConsumer != null) frame.ifPresent(frameConsumer);
-                        frame.ifPresent(VideoMode.this::onFrame);
+                        frame.ifPresent(VideoMode.this::onVideoFrame);
 //                        timeIt("frame", grabber::grabFrame);
                     }
                 } catch (IOException e) {
@@ -47,11 +47,11 @@ public class VideoMode extends Mode {
         grabberThread.start();
     }
 
-    public void onVideoFrame(Consumer<Frame> consumer) {
+    public void onVideoFrame(Consumer<VideoFrame> consumer) {
         frameConsumer = consumer;
     }
 
-    private void onFrame(Frame frame) {
+    private void onVideoFrame(VideoFrame frame) {
         updateWithFrame(frame.getLedFrame());
     }