12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #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;
- }
- }
|