This commit is contained in:
2025-12-30 15:43:06 +01:00
commit 98a68ef75e
8 changed files with 426 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package io.swtc.proccessing;
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)
};
}
}