aaa.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <stdio.h>
  2. #include "libmegapixels.h"
  3. void
  4. libmegapixels_aaa_software_statistics(unsigned int *frame, const int width, const int height,
  5. libmegapixels_aaa_stats *stats)
  6. {
  7. unsigned int bright = 0;
  8. unsigned int too_bright = 0;
  9. unsigned int total = 0;
  10. unsigned long long sum_r = 0, sum_g = 0, sum_b = 0;
  11. for (ssize_t p = 0; p < width * height; p++) {
  12. total++;
  13. unsigned int r = frame[p] >> 16 & 0xff;
  14. unsigned int g = frame[p] >> 8 & 0xff;
  15. unsigned int b = frame[p] & 0xff;
  16. if (g > 240) {
  17. too_bright++;
  18. }
  19. if (g > 200) {
  20. bright++;
  21. }
  22. sum_r += r;
  23. sum_g += g;
  24. sum_b += b;
  25. }
  26. unsigned int p_bright = (bright * 100) / total;
  27. unsigned int p_too_bright = (too_bright * 100) / total;
  28. stats->exposure = 0;
  29. if (p_bright < 1) {
  30. stats->exposure = 1;
  31. }
  32. if (p_too_bright > 8) {
  33. stats->exposure = -1;
  34. }
  35. float r = (float) sum_r / (float) sum_g;
  36. float b = (float) sum_b / (float) sum_g;
  37. stats->whitebalance = 0;
  38. if (r > b * 1.3) {
  39. stats->whitebalance = -1;
  40. }
  41. if (b > r * 1.3) {
  42. stats->whitebalance = 1;
  43. }
  44. }