Output floats in the AAA code
This commit is contained in:
@@ -106,8 +106,8 @@ typedef struct _lmp_device_config libmegapixels_devconfig;
|
|||||||
|
|
||||||
typedef struct _lmp_aaa {
|
typedef struct _lmp_aaa {
|
||||||
int exposure;
|
int exposure;
|
||||||
int whitebalance;
|
float temp;
|
||||||
int tint;
|
float tint;
|
||||||
int focus;
|
int focus;
|
||||||
int blacklevel;
|
int blacklevel;
|
||||||
} libmegapixels_aaa_stats;
|
} libmegapixels_aaa_stats;
|
||||||
@@ -167,4 +167,4 @@ EXPORT void
|
|||||||
libmegapixels_aaa_software_statistics(unsigned int *frame, int width, int height,
|
libmegapixels_aaa_software_statistics(unsigned int *frame, int width, int height,
|
||||||
libmegapixels_aaa_stats *stats);
|
libmegapixels_aaa_stats *stats);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
71
src/aaa.c
71
src/aaa.c
@@ -1,6 +1,19 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "libmegapixels.h"
|
#include "libmegapixels.h"
|
||||||
|
|
||||||
|
|
||||||
|
float
|
||||||
|
clamp_float(float value, float min, float max)
|
||||||
|
{
|
||||||
|
if (value > max)
|
||||||
|
return max;
|
||||||
|
|
||||||
|
if (value < min)
|
||||||
|
return min;
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, const int height,
|
libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, const int height,
|
||||||
libmegapixels_aaa_stats *stats)
|
libmegapixels_aaa_stats *stats)
|
||||||
@@ -12,22 +25,28 @@ libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, cons
|
|||||||
unsigned long long sum_r = 0, sum_g = 0, sum_b = 0;
|
unsigned long long sum_r = 0, sum_g = 0, sum_b = 0;
|
||||||
for (ssize_t p = 0; p < width * height; p++) {
|
for (ssize_t p = 0; p < width * height; p++) {
|
||||||
total++;
|
total++;
|
||||||
unsigned int r = frame[p] >> 16 & 0xff;
|
unsigned int r = (frame[p] >> 0) & 0xff;
|
||||||
unsigned int g = frame[p] >> 8 & 0xff;
|
unsigned int g = (frame[p] >> 8) & 0xff;
|
||||||
unsigned int b = frame[p] & 0xff;
|
unsigned int b = (frame[p] >> 16) & 0xff;
|
||||||
if (g > 220 || r > 220) {
|
unsigned int y = (r + g + b) / 3;
|
||||||
|
|
||||||
|
if (y > 220) {
|
||||||
too_bright++;
|
too_bright++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g > 180 || r > 180) {
|
if (y > 180) {
|
||||||
bright++;
|
bright++;
|
||||||
}
|
}
|
||||||
if (g < 2) {
|
if (y < 2) {
|
||||||
too_dark++;
|
too_dark++;
|
||||||
}
|
}
|
||||||
sum_r += r;
|
|
||||||
sum_g += g;
|
// Whitebalance on the midrange pixels only
|
||||||
sum_b += b;
|
if (y > 75 && y < 200) {
|
||||||
|
sum_r += r;
|
||||||
|
sum_g += g;
|
||||||
|
sum_b += b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
unsigned int p_bright = (bright * 100) / total;
|
unsigned int p_bright = (bright * 100) / total;
|
||||||
unsigned int p_too_bright = (too_bright * 100) / total;
|
unsigned int p_too_bright = (too_bright * 100) / total;
|
||||||
@@ -40,29 +59,23 @@ libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, cons
|
|||||||
stats->exposure = -1;
|
stats->exposure = -1;
|
||||||
}
|
}
|
||||||
stats->blacklevel = 0;
|
stats->blacklevel = 0;
|
||||||
if (p_dark == 0) {
|
if (p_dark < 1) {
|
||||||
stats->blacklevel = -1;
|
stats->blacklevel = -1;
|
||||||
}
|
}
|
||||||
if (p_dark > 8) {
|
if (p_dark > 3) {
|
||||||
stats->blacklevel = 1;
|
stats->blacklevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float y = (float) (sum_r + sum_g + sum_b) / 3.0f;
|
float y = (float) (sum_r * 0.2126 + sum_g * 0.7175 + sum_b * 0.0722);
|
||||||
float r = (float) sum_r / y - 1.0f;
|
float r = (float) sum_r / y;
|
||||||
float g = (float) sum_g / y - 1.0f;
|
float g = (float) sum_g / y;
|
||||||
float b = (float) sum_b / y - 1.0f;
|
float b = (float) sum_b / y;
|
||||||
stats->whitebalance = 0;
|
if (y < 1) {
|
||||||
stats->tint = 0;
|
r = 0;
|
||||||
if (g > 0.1f) {
|
g = 0;
|
||||||
stats->tint = 1;
|
b = 0;
|
||||||
}
|
}
|
||||||
if (g < 0.1f) {
|
float m = (r + b) / 2.0f;
|
||||||
stats->tint = -1;
|
stats->temp = clamp_float(b - r, 0, 2);
|
||||||
}
|
stats->tint = clamp_float(g - m, 0, 2);
|
||||||
if (r > b * 1.3) {
|
}
|
||||||
stats->whitebalance = -1;
|
|
||||||
}
|
|
||||||
if (b > r * 1.3) {
|
|
||||||
stats->whitebalance = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user