mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 23:10:40 +00:00
allow nullable ev100 in CameraContainerBloc
This commit is contained in:
parent
9a21d5f2f5
commit
b144cf7edb
1 changed files with 23 additions and 16 deletions
|
@ -34,7 +34,7 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
|
|||
double _exposureStep = 0.0;
|
||||
double _currentExposureOffset = 0.0;
|
||||
|
||||
double _ev100 = 0.0;
|
||||
double? _ev100 = 0.0;
|
||||
|
||||
CameraContainerBloc(
|
||||
this._meteringInteractor,
|
||||
|
@ -67,14 +67,19 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
|
|||
@override
|
||||
void onCommunicationState(communication_states.SourceState communicationState) {
|
||||
if (communicationState is communication_states.MeasureState) {
|
||||
if (_canTakePhoto) {
|
||||
_takePhoto().then((ev100Raw) {
|
||||
if (ev100Raw != null) {
|
||||
_ev100 = ev100Raw + _meteringInteractor.cameraEvCalibration;
|
||||
communicationBloc.add(communication_event.MeteringEndedEvent(_ev100));
|
||||
} else {
|
||||
_ev100 = null;
|
||||
communicationBloc.add(const communication_event.MeteringEndedEvent(null));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onRequestPermission(_, Emitter emit) async {
|
||||
final hasPermission = await _meteringInteractor.requestPermission();
|
||||
|
@ -172,23 +177,25 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
|
|||
);
|
||||
}
|
||||
|
||||
Future<double?> _takePhoto() async {
|
||||
if (_cameraController == null ||
|
||||
bool get _canTakePhoto => !(_cameraController == null ||
|
||||
!_cameraController!.value.isInitialized ||
|
||||
_cameraController!.value.isTakingPicture) {
|
||||
return null;
|
||||
}
|
||||
_cameraController!.value.isTakingPicture);
|
||||
|
||||
Future<double?> _takePhoto() async {
|
||||
try {
|
||||
final file = await _cameraController!.takePicture();
|
||||
final Uint8List bytes = await file.readAsBytes();
|
||||
Directory(file.path).deleteSync(recursive: true);
|
||||
|
||||
final tags = await readExifFromBytes(bytes);
|
||||
final iso = double.parse("${tags["EXIF ISOSpeedRatings"]}");
|
||||
final apertureValueRatio = (tags["EXIF FNumber"]!.values as IfdRatios).ratios.first;
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final aperture = apertureValueRatio.numerator / apertureValueRatio.denominator;
|
||||
final speedValueRatio = (tags["EXIF ExposureTime"]!.values as IfdRatios).ratios.first;
|
||||
final speed = speedValueRatio.numerator / speedValueRatio.denominator;
|
||||
|
||||
return log2(pow(aperture, 2)) - log2(speed) - log2(iso / 100);
|
||||
|
|
Loading…
Reference in a new issue