ML-175 Improved logging for missing EXIF fields (#207)

* include only the necessary values in logs

* added runtime type to iso
This commit is contained in:
Vadim 2025-01-20 20:03:02 +01:00 committed by GitHub
parent aa29ef28e6
commit e334f0f8da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,24 +4,29 @@ import 'package:exif/exif.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
const String _isoExifKey = 'EXIF ISOSpeedRatings';
const String _apertureExifKey = 'EXIF FNumber';
const String _shutterSpeedExifKey = 'EXIF ExposureTime';
Future<double> evFromImage(Uint8List bytes) async { Future<double> evFromImage(Uint8List bytes) async {
final tags = await readExifFromBytes(bytes); final tags = await readExifFromBytes(bytes);
final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}"); final iso = double.tryParse("${tags[_isoExifKey]}");
final apertureValueRatio = (tags["EXIF FNumber"]?.values as IfdRatios?)?.ratios.first; final apertureValueRatio = (tags[_apertureExifKey]?.values as IfdRatios?)?.ratios.first;
final speedValueRatio = (tags["EXIF ExposureTime"]?.values as IfdRatios?)?.ratios.first; final speedValueRatio = (tags[_shutterSpeedExifKey]?.values as IfdRatios?)?.ratios.first;
if (iso == null || apertureValueRatio == null || speedValueRatio == null) { if (iso == null || apertureValueRatio == null || speedValueRatio == null) {
throw ArgumentError( throw ArgumentError(
'Error parsing EXIF: ${tags.keys.join(', ')}', 'Error parsing EXIF',
[ [
if (iso == null) 'EXIF ISOSpeedRatings', if (iso == null) '$_isoExifKey: ${tags[_isoExifKey]?.printable} ${tags[_isoExifKey]?.printable.runtimeType}',
if (apertureValueRatio == null) 'EXIF FNumber', if (apertureValueRatio == null) '$_apertureExifKey: $apertureValueRatio',
if (speedValueRatio == null) 'EXIF ExposureTime', if (speedValueRatio == null) '$_shutterSpeedExifKey: $speedValueRatio',
].join(', '), ].join(', '),
); );
} }
final aperture = apertureValueRatio.numerator / apertureValueRatio.denominator; final aperture = apertureValueRatio.toDouble();
final speed = speedValueRatio.numerator / speedValueRatio.denominator; final speed = speedValueRatio.toDouble();
return log2(math.pow(aperture, 2)) - log2(speed) - log2(iso / 100); return log2(math.pow(aperture, 2)) - log2(speed) - log2(iso / 100);
} }