Import the millipixels AAA stats

This commit is contained in:
Martijn Braam
2023-07-20 20:33:55 +02:00
parent 84de134497
commit 6fbb99a637
3 changed files with 58 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ set(LIBRARY_VERSION_STRING 0.1)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_VISIBILITY_PRESET hidden)
add_library(megapixels SHARED include/libmegapixels.h src/findconfig.c src/parse.c src/mode.c src/pipeline.c src/log.c src/util.c src/convert.c)
add_library(megapixels SHARED include/libmegapixels.h src/findconfig.c src/parse.c src/mode.c src/pipeline.c src/log.c src/util.c src/convert.c src/aaa.c)
set_target_properties(megapixels PROPERTIES
VERSION ${LIBRARY_VERSION_STRING}
SOVERSION ${LIBRARY_VERSION_MAJOR}

View File

@@ -97,6 +97,13 @@ struct _lmp_device_config {
};
typedef struct _lmp_device_config libmegapixels_devconfig;
typedef struct _lmp_aaa {
int exposure;
int whitebalance;
int focus;
} libmegapixels_aaa_stats;
EXPORT int
libmegapixels_init(libmegapixels_devconfig **config);
@@ -148,4 +155,8 @@ libmegapixels_format_bits_per_pixel(int format);
EXPORT int
libmegapixels_mode_equals(libmegapixels_mode *a, libmegapixels_mode *b);
EXPORT void
libmegapixels_aaa_software_statistics(unsigned int *frame, int width, int height,
libmegapixels_aaa_stats *stats);
#endif

46
src/aaa.c Normal file
View File

@@ -0,0 +1,46 @@
#include <stdio.h>
#include "libmegapixels.h"
void
libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, const int height,
libmegapixels_aaa_stats *stats)
{
unsigned int bright = 0;
unsigned int too_bright = 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++) {
total++;
unsigned int r = frame[p] >> 16 & 0xff;
unsigned int g = frame[p] >> 8 & 0xff;
unsigned int b = frame[p] & 0xff;
if (g > 240) {
too_bright++;
}
if (g > 200) {
bright++;
}
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;
stats->exposure = 0;
if (p_bright < 1) {
stats->exposure = 1;
}
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->whitebalance = 0;
if (r > b * 1.3) {
stats->whitebalance = -1;
}
if (b > r * 1.3) {
stats->whitebalance = 1;
}
}