Files
swt-cctv/src/main/java/io/swtc/proccessing/AutoGainProcessor.java
rattatwinko ccc3d264f7 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
2026-01-13 20:52:32 +01:00

42 lines
1.0 KiB
Java

package io.swtc.proccessing;
/*
*
* Soon to be deprecated!
*
* */
@Deprecated
public class AutoGainProcessor {
public float[] calculateAutoGains(int[] pixels) {
long rSum = 0, gSum = 0, bSum = 0;
int step = 8;
int sampledCount = 0;
for (int i = 0; i < pixels.length; i += step) {
int pixel = pixels[i];
rSum += (pixel >> 16) & 0xFF;
gSum += (pixel >> 8) & 0xFF;
bSum += pixel & 0xFF;
sampledCount++;
}
if (sampledCount == 0) return new float[]{1f, 1f, 1f};
float rAvg = (float) rSum / sampledCount;
float gAvg = (float) gSum / sampledCount;
float bAvg = (float) bSum / sampledCount;
float grayAvg = (rAvg + gAvg + bAvg) / 3.0f;
if (grayAvg < 1.0f) return new float[]{1.0f, 1.0f, 1.0f};
return new float[]{
Math.min(2.0f, grayAvg / rAvg),
Math.min(2.0f, grayAvg / gAvg),
Math.min(2.0f, grayAvg / bAvg)
};
}
}