m3_lightmeter/lib/utils/ev_from_bytes.dart
Vadim 73d0c32323
Hide Pro features from the metering screen (#147)
* implemented `MockCameraContainerBloc` to stub camera on simulator

* hide pro features from metering screen

* disable pro features in settings

* use closed child background color in `AnimatedDialog`

* adjust `AnimatedDialogPicker` to items count

* close `AnimatedDialog` through context

* cleanup

* fixed `ReadingValueContainer` text color

* removed legacy translations

* fixed tests

* fixed `AnimatedDialog` scaling

* added `evFromImage` test

* added no EXIF test to `evFromImage`
2024-01-13 18:20:58 +01:00

27 lines
994 B
Dart

import 'dart:developer';
import 'dart:math' as math;
import 'dart:typed_data';
import 'package:exif/exif.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
Future<double?> evFromImage(Uint8List bytes) async {
try {
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) {
log('Error parsing EXIF: ${tags.keys}');
return null;
}
final aperture = apertureValueRatio.numerator / apertureValueRatio.denominator;
final speed = speedValueRatio.numerator / speedValueRatio.denominator;
return log2(math.pow(aperture, 2)) - log2(speed) - log2(iso / 100);
} catch (e) {
log(e.toString());
return null;
}
}