|
@@ -15,16 +15,31 @@ clamp_float(float value, float min, float max)
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, const int height,
|
|
|
- libmegapixels_aaa_stats *stats)
|
|
|
+libmegapixels_aaa_init(libmegapixels_aaa_stats *stats)
|
|
|
+{
|
|
|
+ float identity[] = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
|
|
+ libmegapixels_aaa_set_matrix(stats, identity, identity);
|
|
|
+}
|
|
|
+
|
|
|
+void
|
|
|
+libmegapixels_aaa_set_matrix(libmegapixels_aaa_stats *stats, const float *matrix1, const float *matrix2)
|
|
|
+{
|
|
|
+ for (size_t i = 0; i < 9; i++) {
|
|
|
+ stats->matrix1[i] = matrix1[i];
|
|
|
+ stats->matrix2[i] = matrix2[i];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void
|
|
|
+libmegapixels_aaa_software_statistics(libmegapixels_aaa_stats *stats, const unsigned int *frame, const int width,
|
|
|
+ const int height)
|
|
|
{
|
|
|
unsigned int bright = 0;
|
|
|
unsigned int too_bright = 0;
|
|
|
unsigned int too_dark = 0;
|
|
|
- unsigned int total = 0;
|
|
|
+ unsigned int total = width * height;
|
|
|
unsigned long long sum_r = 0, sum_g = 0, sum_b = 0;
|
|
|
for (ssize_t p = 0; p < width * height; p++) {
|
|
|
- total++;
|
|
|
unsigned int r = (frame[p] >> 0) & 0xff;
|
|
|
unsigned int g = (frame[p] >> 8) & 0xff;
|
|
|
unsigned int b = (frame[p] >> 16) & 0xff;
|
|
@@ -48,6 +63,8 @@ libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, cons
|
|
|
sum_b += b;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // Exposure calculations
|
|
|
unsigned int p_bright = (bright * 100) / total;
|
|
|
unsigned int p_too_bright = (too_bright * 100) / total;
|
|
|
unsigned int p_dark = (too_dark * 100) / total;
|
|
@@ -66,16 +83,12 @@ libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, cons
|
|
|
stats->blacklevel = 1;
|
|
|
}
|
|
|
|
|
|
- float y = (float) (sum_r * 0.2126 + sum_g * 0.7175 + sum_b * 0.0722);
|
|
|
- float r = (float) sum_r / y;
|
|
|
- float g = (float) sum_g / y;
|
|
|
- float b = (float) sum_b / y;
|
|
|
- if (y < 1) {
|
|
|
- r = 0;
|
|
|
- g = 0;
|
|
|
- b = 0;
|
|
|
- }
|
|
|
- float m = (r + b) / 2.0f;
|
|
|
- stats->temp = clamp_float(b - r, 0, 2);
|
|
|
- stats->tint = clamp_float(g - m, 0, 2);
|
|
|
+ // Whitebalance calculations
|
|
|
+ float r = (float) sum_r / total;
|
|
|
+ float g = (float) sum_g / total;
|
|
|
+ float b = (float) sum_b / total;
|
|
|
+
|
|
|
+ stats->avg_r = (r * stats->matrix1[0]) + (g * stats->matrix1[1]) + (b * stats->matrix1[2]);
|
|
|
+ stats->avg_g = (r * stats->matrix1[3]) + (g * stats->matrix1[4]) + (b * stats->matrix1[5]);
|
|
|
+ stats->avg_b = (r * stats->matrix1[6]) + (g * stats->matrix1[7]) + (b * stats->matrix1[8]);
|
|
|
}
|