refactored shitty unusable code
Signed-off-by: rattatwinko <seppmutterman@gmail.com>
This commit is contained in:
@@ -12,15 +12,6 @@ public class CameraPanel extends JPanel {
|
||||
private BufferedImage currentImage;
|
||||
private BufferedImage processedImage;
|
||||
|
||||
// Basic transform effects
|
||||
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;
|
||||
|
||||
// Custom processor for advanced effects
|
||||
private Function<BufferedImage, BufferedImage> imageProcessor;
|
||||
|
||||
@@ -71,14 +62,6 @@ public class CameraPanel extends JPanel {
|
||||
int srcX = x;
|
||||
int srcY = y;
|
||||
|
||||
if (mirror) srcX = width - 1 - x;
|
||||
if (flip) srcY = height - 1 - y;
|
||||
if (rotate) {
|
||||
int temp = srcX;
|
||||
srcX = width - 1 - srcY;
|
||||
srcY = temp;
|
||||
}
|
||||
|
||||
// Ensure coordinates are in bounds
|
||||
srcX = Math.max(0, Math.min(width - 1, srcX));
|
||||
srcY = Math.max(0, Math.min(height - 1, srcY));
|
||||
@@ -88,33 +71,6 @@ public class CameraPanel extends JPanel {
|
||||
int g = (rgb >> 8) & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
|
||||
// Apply grayscale
|
||||
if (grayscale) {
|
||||
int gray = (r + g + b) / 3;
|
||||
r = g = b = gray;
|
||||
}
|
||||
|
||||
// Apply brightness
|
||||
if (brightness != 0) {
|
||||
r = clamp(r + brightness);
|
||||
g = clamp(g + brightness);
|
||||
b = clamp(b + brightness);
|
||||
}
|
||||
|
||||
// Apply contrast
|
||||
if (contrast != 1.0f) {
|
||||
r = clamp((int)((r - 128) * contrast + 128));
|
||||
g = clamp((int)((g - 128) * contrast + 128));
|
||||
b = clamp((int)((b - 128) * contrast + 128));
|
||||
}
|
||||
|
||||
// Apply invert
|
||||
if (invert) {
|
||||
r = 255 - r;
|
||||
g = 255 - g;
|
||||
b = 255 - b;
|
||||
}
|
||||
|
||||
result.setRGB(x, y, (r << 16) | (g << 8) | b);
|
||||
}
|
||||
}
|
||||
@@ -122,35 +78,16 @@ public class CameraPanel extends JPanel {
|
||||
return result;
|
||||
}
|
||||
|
||||
private int clamp(int value) {
|
||||
return Math.max(0, Math.min(255, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
if (processedImage != null) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
|
||||
// Scale image to fit panel while maintaining aspect ratio
|
||||
int panelWidth = getWidth();
|
||||
int panelHeight = getHeight();
|
||||
int imgWidth = processedImage.getWidth();
|
||||
int imgHeight = processedImage.getHeight();
|
||||
|
||||
double scaleX = (double) panelWidth / imgWidth;
|
||||
double scaleY = (double) panelHeight / imgHeight;
|
||||
double scale = Math.min(scaleX, scaleY);
|
||||
|
||||
int scaledWidth = (int) (imgWidth * scale);
|
||||
int scaledHeight = (int) (imgHeight * scale);
|
||||
|
||||
int x = (panelWidth - scaledWidth) / 2;
|
||||
int y = (panelHeight - scaledHeight) / 2;
|
||||
|
||||
g2d.drawImage(processedImage, x, y, scaledWidth, scaledHeight, null);
|
||||
g2d.drawImage(processedImage, 0, 0, getWidth(), getHeight(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,59 +95,4 @@ public class CameraPanel extends JPanel {
|
||||
return processedImage;
|
||||
}
|
||||
|
||||
// Basic effect setters
|
||||
public void setMirror(boolean mirror) {
|
||||
this.mirror = mirror;
|
||||
processImage();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setFlip(boolean flip) {
|
||||
this.flip = flip;
|
||||
processImage();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setRotate(boolean rotate) {
|
||||
this.rotate = rotate;
|
||||
processImage();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setGrayscale(boolean grayscale) {
|
||||
this.grayscale = grayscale;
|
||||
processImage();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setInvert(boolean invert) {
|
||||
this.invert = invert;
|
||||
processImage();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setBrightness(int brightness) {
|
||||
this.brightness = brightness;
|
||||
processImage();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setContrast(float contrast) {
|
||||
this.contrast = contrast;
|
||||
processImage();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void resetEffects() {
|
||||
this.mirror = false;
|
||||
this.flip = false;
|
||||
this.rotate = false;
|
||||
this.grayscale = false;
|
||||
this.invert = false;
|
||||
this.brightness = 0;
|
||||
this.contrast = 1.0f;
|
||||
this.imageProcessor = null;
|
||||
processImage();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user