Browse Source

AAA improvements

Martijn Braam 1 year ago
parent
commit
0598d0e560
2 changed files with 29 additions and 5 deletions
  1. 2 0
      include/libmegapixels.h
  2. 27 5
      src/aaa.c

+ 2 - 0
include/libmegapixels.h

@@ -107,7 +107,9 @@ typedef struct _lmp_device_config libmegapixels_devconfig;
 typedef struct _lmp_aaa {
 		int exposure;
 		int whitebalance;
+		int tint;
 		int focus;
+		int blacklevel;
 } libmegapixels_aaa_stats;
 
 EXPORT int

+ 27 - 5
src/aaa.c

@@ -7,6 +7,7 @@ libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, cons
 {
 	unsigned int bright = 0;
 	unsigned int too_bright = 0;
+	unsigned int too_dark = 0;
 	unsigned int total = 0;
 	unsigned long long sum_r = 0, sum_g = 0, sum_b = 0;
 	for (ssize_t p = 0; p < width * height; p++) {
@@ -14,19 +15,23 @@ libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, cons
 		unsigned int r = frame[p] >> 16 & 0xff;
 		unsigned int g = frame[p] >> 8 & 0xff;
 		unsigned int b = frame[p] & 0xff;
-
-		if (g > 240) {
+		if (g > 220 || r > 220) {
 			too_bright++;
 		}
-		if (g > 200) {
+
+		if (g > 180 || r > 180) {
 			bright++;
 		}
+		if (g < 2) {
+			too_dark++;
+		}
 		sum_r += r;
 		sum_g += g;
 		sum_b += b;
 	}
 	unsigned int p_bright = (bright * 100) / total;
 	unsigned int p_too_bright = (too_bright * 100) / total;
+	unsigned int p_dark = (too_dark * 100) / total;
 	stats->exposure = 0;
 	if (p_bright < 1) {
 		stats->exposure = 1;
@@ -34,9 +39,26 @@ libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, cons
 	if (p_too_bright > 8) {
 		stats->exposure = -1;
 	}
-	float r = (float) sum_r / (float) sum_g;
-	float b = (float) sum_b / (float) sum_g;
+	stats->blacklevel = 0;
+	if (p_dark == 0) {
+		stats->blacklevel = -1;
+	}
+	if (p_dark > 8) {
+		stats->blacklevel = 1;
+	}
+
+	float y = (float) (sum_r + sum_g + sum_b) / 3.0f;
+	float r = (float) sum_r / y - 1.0f;
+	float g = (float) sum_g / y - 1.0f;
+	float b = (float) sum_b / y - 1.0f;
 	stats->whitebalance = 0;
+	stats->tint = 0;
+	if (g > 0.1f) {
+		stats->tint = 1;
+	}
+	if (g < 0.1f) {
+		stats->tint = -1;
+	}
 	if (r > b * 1.3) {
 		stats->whitebalance = -1;
 	}