lightmeter_helper.c 910 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "lightmeter_helper.h"
  2. extern const int iso_numbers[];
  3. extern const float aperture_numbers[];
  4. extern const float speed_numbers[];
  5. float lux2ev(float lux, LightMeterISONumbers iso) {
  6. return log2(lux / 2.5) + log2(iso_numbers[iso] / 100.0);
  7. }
  8. float getMinDistance(float x, float v1, float v2) {
  9. if(x - v1 > v2 - x) {
  10. return v2;
  11. }
  12. return v1;
  13. }
  14. float normalizeAperture(float a) {
  15. for(int i = 0; i < AP_NUM; i++) {
  16. float a1 = aperture_numbers[i];
  17. float a2 = aperture_numbers[i + 1];
  18. if(a1 < a && a2 >= a) {
  19. return getMinDistance(a, a1, a2);
  20. }
  21. }
  22. return 0;
  23. }
  24. float normalizeTime(float a) {
  25. for(int i = 0; i < SPEED_NUM; i++) {
  26. float a1 = speed_numbers[i];
  27. float a2 = speed_numbers[i + 1];
  28. if(a1 < a && a2 >= a) {
  29. return getMinDistance(a, a1, a2);
  30. }
  31. }
  32. return 0;
  33. }