test and readme

This commit is contained in:
2025-12-30 16:03:01 +01:00
parent 98a68ef75e
commit 908a4c8bab
3 changed files with 110 additions and 0 deletions

View File

@@ -54,5 +54,13 @@
<version>3.3.3</version>
<classifier>natives-windows</classifier>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>6.1.0-M1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

17
readme.md Normal file
View File

@@ -0,0 +1,17 @@
# SWT-CCTV
A rather simple CCTV software which operates with Java.
If you want to build this project on yourself, you will need IntelliJ (or any other IDE) and Maven!
## Dependencies:
- Webcam by Sarxos
- SWT
- _lwjgl (with opengl)_ → This is important for our goals of rendering on the GPU.
- junit for testing stuff
### Future Plans:
They arent too big, i want one thing more and that is some more utilities in the camera window.
Also some Network streaming but i am too lazy to do that
### Author(s):
- rattatwinko

View File

@@ -0,0 +1,85 @@
import io.swtc.proccessing.AutoGainProcessor;
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 AutoGainProcessorTest {
private AutoGainProcessor processor;
@BeforeEach
void setUp() {
processor = new AutoGainProcessor();
}
@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));
}
}