Quality of Life changes to the viewer

changed:
/ SwingIFrame ; Some new methodes for setting bg color, and fullscreen, keybinds are "F11" and "B"
/ WebcamCaptureLoop.java ; Safety is key!

---
rattatwinko
This commit is contained in:
2026-01-14 20:55:45 +01:00
parent ccc3d264f7
commit e7a3d98dd0
2 changed files with 115 additions and 7 deletions

View File

@@ -5,13 +5,15 @@ import com.github.sarxos.webcam.WebcamException;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import javax.swing.JOptionPane;
import javax.swing.*;
public class WebcamCaptureLoop {
private final Webcam webcam;
private final Consumer<BufferedImage> onFrameCaptured;
private volatile boolean running = false;
private final AtomicBoolean cleanedUp = new AtomicBoolean(false);
public WebcamCaptureLoop(Webcam webcam, Consumer<BufferedImage> onFrameCaptured) {
this.webcam = webcam;
@@ -64,22 +66,40 @@ public class WebcamCaptureLoop {
captureThread.start();
}
// method for cleaning up
/**
* Safely release webcam
*/
private synchronized void cleanup() {
if (!cleanedUp.compareAndSet(false, true)) {
return;
}
boolean success = false;
try {
// if the camera is open try to cloes it!
webcam.close();
if (webcam.isOpen())
webcam.close();
success = true;
} catch (WebcamException exception) {
SwingUtilities.invokeLater(() ->
JOptionPane.showMessageDialog(
null,
"Cleanup failed \nWebCamException@"+exception.getMessage(),
"WebCamException",
JOptionPane.ERROR_MESSAGE
);
JOptionPane.WARNING_MESSAGE // changed to warning, its better tbh
));
} finally {
if (!success)
cleanedUp.set(false);
}
}
/**
* Arguments: null (or just none)
* What does this method do? : Sets CameraThreads running flag to false and calls cleanup();
*/
public void stop() {
running = false;
cleanup();