85 lines
2.9 KiB
Java
85 lines
2.9 KiB
Java
import io.swtc.proccessing.AWBProccessor;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
/*
|
|
* This is a pure logic class so testing this will be fine, all other classes arent really logic classes, they handle more
|
|
* of displaying stuff.
|
|
* */
|
|
|
|
class AWBProccessorTest {
|
|
|
|
private AWBProccessor processor;
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
processor = new AWBProccessor();
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Return 1.0 gain for a gray image")
|
|
void testNeutralGray() {
|
|
// Create an array of 16 pixels, all middle gray (128, 128, 128)
|
|
// Hex: 0xFF808080 ; We ignore Alpha all together in our code. so yeah
|
|
int grayPixel = (255 << 24) | (128 << 16) | (128 << 8) | 128;
|
|
int[] pixels = new int[16];
|
|
Arrays.fill(pixels, grayPixel);
|
|
|
|
float[] gains = processor.calculateAutoGains(pixels);
|
|
|
|
// R, G, B should all be 1.0 because they are already equal to the average
|
|
assertArrayEquals(new float[]{1.0f, 1.0f, 1.0f}, gains, 0.001f);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Should boost a weak color channel")
|
|
void testColorCorrection() {
|
|
/*
|
|
Create an image that is "too red"
|
|
Red = 200, Green = 100, Blue = 100
|
|
grayAvg = (200 + 100 + 100) / 3 = 133.33
|
|
Red gain = 133.33 / 200 = 0.66
|
|
Green gain = 133.33 / 100 = 1.33
|
|
*/
|
|
int reddishPixel = (200 << 16) | (100 << 8) | 100;
|
|
int[] pixels = {reddishPixel, reddishPixel, reddishPixel, reddishPixel};
|
|
|
|
float[] gains = processor.calculateAutoGains(pixels);
|
|
|
|
assertTrue(gains[0] < 1.0f, "Red gain should decrease");
|
|
assertTrue(gains[1] > 1.0f, "Green gain should increase");
|
|
assertTrue(gains[2] > 1.0f, "Blue gain should increase");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Cap max gain at 2.0")
|
|
void testGainCapping() {
|
|
// Extreme case, very little blue
|
|
// Red=100, Green=100, Blue=10
|
|
// grayAvg = 70. Blue gain would be 70/10 = 7.0, but should be capped at 2.0
|
|
int lowBluePixel = (100 << 16) | (100 << 8) | 10;
|
|
int[] pixels = new int[8];
|
|
for (int i = 0; i < 8; i++) pixels[i] = lowBluePixel;
|
|
|
|
float[] gains = processor.calculateAutoGains(pixels);
|
|
|
|
assertArrayEquals(new float[]{0.7f, 0.7f, 2.0f}, gains, 0.001f);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Handle a empty / black image safely")
|
|
void testEmptyAndBlack() {
|
|
// Test empty array
|
|
assertArrayEquals(new float[]{1f, 1f, 1f}, processor.calculateAutoGains(new int[0]));
|
|
|
|
// Test total black (grayAvg will be 0)
|
|
int[] blackPixels = {0, 0, 0, 0};
|
|
assertArrayEquals(new float[]{1f, 1f, 1f}, processor.calculateAutoGains(blackPixels));
|
|
}
|
|
} |