2024-01-13 17:20:58 +00:00
|
|
|
import 'dart:math' as math;
|
|
|
|
|
|
|
|
import 'package:exif/exif.dart';
|
2024-01-27 21:25:01 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2024-01-13 17:20:58 +00:00
|
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|
|
|
|
2024-01-27 20:41:37 +00:00
|
|
|
Future<double> evFromImage(Uint8List bytes) async {
|
|
|
|
final tags = await readExifFromBytes(bytes);
|
|
|
|
final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}");
|
|
|
|
final apertureValueRatio = (tags["EXIF FNumber"]?.values as IfdRatios?)?.ratios.first;
|
|
|
|
final speedValueRatio = (tags["EXIF ExposureTime"]?.values as IfdRatios?)?.ratios.first;
|
|
|
|
if (iso == null || apertureValueRatio == null || speedValueRatio == null) {
|
2024-01-27 21:25:01 +00:00
|
|
|
throw FlutterError('Error parsing EXIF: ${tags.keys}');
|
2024-01-27 20:41:37 +00:00
|
|
|
}
|
2024-01-13 17:20:58 +00:00
|
|
|
|
2024-01-27 20:41:37 +00:00
|
|
|
final aperture = apertureValueRatio.numerator / apertureValueRatio.denominator;
|
|
|
|
final speed = speedValueRatio.numerator / speedValueRatio.denominator;
|
2024-01-13 17:20:58 +00:00
|
|
|
|
2024-01-27 20:41:37 +00:00
|
|
|
return log2(math.pow(aperture, 2)) - log2(speed) - log2(iso / 100);
|
2024-01-13 17:20:58 +00:00
|
|
|
}
|