// 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());
/**
* 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();
}
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);
}
}
- 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();
}
}
- 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++) {
}
}
- 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++) {
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;
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;
public class VideoMode extends Mode {
private Configuration config;
private Thread grabberThread;
- private Consumer<Frame> frameConsumer;
+ private Consumer<VideoFrame> frameConsumer;
private VideoDeviceListener deviceListener;
public VideoMode() {
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) {
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());
}