a new windowing system!
add: + CameraPanel ; To make life easier for coders + SwingIFrame ; Which is now our main UI component + VideoRecorder ; A helper Class for SwingIFrame to record cameras! changed: / SwingCCTVManager ; changes for the new UI Component deprecation: /-/ AutoGainProcessor ; cause it isnt needed anymore, back then this was needed cause we opened the webcams manually (color wise) --- rattatwinko
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package io.swtc.proccessing;
|
||||
|
||||
/*
|
||||
*
|
||||
* Soon to be deprecated!
|
||||
*
|
||||
* */
|
||||
|
||||
@Deprecated
|
||||
public class AutoGainProcessor {
|
||||
|
||||
public float[] calculateAutoGains(int[] pixels) {
|
||||
|
||||
204
src/main/java/io/swtc/proccessing/CameraPanel.java
Normal file
204
src/main/java/io/swtc/proccessing/CameraPanel.java
Normal file
@@ -0,0 +1,204 @@
|
||||
package io.swtc.proccessing;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/*
|
||||
*
|
||||
* Now here its getting rather interesting! this class processes some
|
||||
* important stuff!
|
||||
*
|
||||
* */
|
||||
|
||||
public class CameraPanel extends JPanel {
|
||||
private BufferedImage currentImage;
|
||||
private boolean mirror = false;
|
||||
private boolean flip = false;
|
||||
private boolean rotate = false;
|
||||
private boolean grayscale = false;
|
||||
private boolean invert = false;
|
||||
private int brightness = 0;
|
||||
private float contrast = 1.0f;
|
||||
|
||||
public void setImage(BufferedImage img) {
|
||||
this.currentImage = img;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public BufferedImage getCurrentImage() {
|
||||
return currentImage;
|
||||
}
|
||||
|
||||
public BufferedImage getCurrentProcessedImage() {
|
||||
if (currentImage == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BufferedImage processed = currentImage;
|
||||
|
||||
// apply color effects
|
||||
if (grayscale || invert || brightness != 0 || contrast != 1.0f) {
|
||||
processed = applyColorEffects(processed);
|
||||
}
|
||||
|
||||
// apply transform.
|
||||
if (mirror || flip || rotate) {
|
||||
processed = applyTransforms(processed);
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
/* Helper Methods ... its the same boilerplate shit over and over again, im sick of this. */
|
||||
public void setMirror(boolean mirror) {
|
||||
this.mirror = mirror;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void setFlip(boolean flip) {
|
||||
this.flip = flip;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void setRotate(boolean rotate) {
|
||||
this.rotate = rotate;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void setGrayscale(boolean grayscale) {
|
||||
this.grayscale = grayscale;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void setInvert(boolean invert) {
|
||||
this.invert = invert;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void setBrightness(int brightness) {
|
||||
this.brightness = brightness;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void setContrast(float contrast) {
|
||||
this.contrast = contrast;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void resetEffects() {
|
||||
mirror = flip = rotate = grayscale = invert = false;
|
||||
brightness = 0;
|
||||
contrast = 1.0f;
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (currentImage != null) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
|
||||
BufferedImage processedImage = currentImage;
|
||||
|
||||
// effects
|
||||
if (grayscale || invert || brightness != 0 || contrast != 1.0f) {
|
||||
processedImage = applyColorEffects(processedImage);
|
||||
}
|
||||
|
||||
// transforms
|
||||
int w = getWidth(), h = getHeight();
|
||||
|
||||
if (rotate) {
|
||||
g2.translate(w / 2, h / 2);
|
||||
g2.rotate(Math.PI);
|
||||
g2.translate(-w / 2, -h / 2);
|
||||
}
|
||||
|
||||
|
||||
// here we have if, cause we need to do the stuff, yk?
|
||||
if (mirror && flip) {
|
||||
g2.drawImage(processedImage, w, h, -w, -h, null);
|
||||
} else if (mirror) {
|
||||
g2.drawImage(processedImage, w, 0, -w, h, null);
|
||||
} else if (flip) {
|
||||
g2.drawImage(processedImage, 0, h, w, -h, null);
|
||||
} else {
|
||||
g2.drawImage(processedImage, 0, 0, w, h, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage applyColorEffects(BufferedImage img) {
|
||||
BufferedImage result = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
for (int x = 0; x < img.getWidth(); x++) {
|
||||
int rgb = img.getRGB(x, y);
|
||||
int r = (rgb >> 16) & 0xFF;
|
||||
int g = (rgb >> 8) & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
|
||||
if (grayscale) {
|
||||
int gray = (r + g + b) / 3;
|
||||
r = g = b = gray;
|
||||
}
|
||||
|
||||
// this is fun, this regulates the brightness or the contrast!
|
||||
// this is some real java, the other stuff is just UI design, which i am bad at,
|
||||
// but this! This is some real shit
|
||||
r = (int) ((r - 128) * contrast + 128 + brightness);
|
||||
g = (int) ((g - 128) * contrast + 128 + brightness);
|
||||
b = (int) ((b - 128) * contrast + 128 + brightness);
|
||||
|
||||
// invert the colors!
|
||||
if (invert) {
|
||||
r = 255 - r;
|
||||
g = 255 - g;
|
||||
b = 255 - b;
|
||||
}
|
||||
|
||||
// clamp so we dont get into weird color grades, or any weird looking spaces
|
||||
// if we dont do this we cant really do stuff which looks bearable
|
||||
r = Math.max(0, Math.min(255, r));
|
||||
g = Math.max(0, Math.min(255, g));
|
||||
b = Math.max(0, Math.min(255, b));
|
||||
|
||||
result.setRGB(x, y, (r << 16) | (g << 8) | b);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private BufferedImage applyTransforms(BufferedImage img) {
|
||||
int width = img.getWidth();
|
||||
int height = img.getHeight();
|
||||
BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int sourceX = x;
|
||||
int sourceY = y;
|
||||
|
||||
if (mirror) {
|
||||
sourceX = width - 1 - x;
|
||||
}
|
||||
if (flip) {
|
||||
sourceY = height - 1 - y;
|
||||
}
|
||||
if (rotate) {
|
||||
int tempX = width - 1 - sourceX;
|
||||
int tempY = height - 1 - sourceY;
|
||||
sourceX = tempX;
|
||||
sourceY = tempY;
|
||||
}
|
||||
|
||||
result.setRGB(x, y, img.getRGB(sourceX, sourceY));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user