mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 07:20:39 +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 _exposureStep = 0.0;
|
||||||
double _currentExposureOffset = 0.0;
|
double _currentExposureOffset = 0.0;
|
||||||
|
|
||||||
double _ev100 = 0.0;
|
double? _ev100 = 0.0;
|
||||||
|
|
||||||
CameraContainerBloc(
|
CameraContainerBloc(
|
||||||
this._meteringInteractor,
|
this._meteringInteractor,
|
||||||
|
@ -67,12 +67,17 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
|
||||||
@override
|
@override
|
||||||
void onCommunicationState(communication_states.SourceState communicationState) {
|
void onCommunicationState(communication_states.SourceState communicationState) {
|
||||||
if (communicationState is communication_states.MeasureState) {
|
if (communicationState is communication_states.MeasureState) {
|
||||||
_takePhoto().then((ev100Raw) {
|
if (_canTakePhoto) {
|
||||||
if (ev100Raw != null) {
|
_takePhoto().then((ev100Raw) {
|
||||||
_ev100 = ev100Raw + _meteringInteractor.cameraEvCalibration;
|
if (ev100Raw != null) {
|
||||||
communicationBloc.add(communication_event.MeteringEndedEvent(_ev100));
|
_ev100 = ev100Raw + _meteringInteractor.cameraEvCalibration;
|
||||||
}
|
communicationBloc.add(communication_event.MeteringEndedEvent(_ev100));
|
||||||
});
|
} else {
|
||||||
|
_ev100 = null;
|
||||||
|
communicationBloc.add(const communication_event.MeteringEndedEvent(null));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,23 +177,25 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<double?> _takePhoto() async {
|
bool get _canTakePhoto => !(_cameraController == null ||
|
||||||
if (_cameraController == null ||
|
!_cameraController!.value.isInitialized ||
|
||||||
!_cameraController!.value.isInitialized ||
|
_cameraController!.value.isTakingPicture);
|
||||||
_cameraController!.value.isTakingPicture) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Future<double?> _takePhoto() async {
|
||||||
try {
|
try {
|
||||||
final file = await _cameraController!.takePicture();
|
final file = await _cameraController!.takePicture();
|
||||||
final Uint8List bytes = await file.readAsBytes();
|
final Uint8List bytes = await file.readAsBytes();
|
||||||
Directory(file.path).deleteSync(recursive: true);
|
Directory(file.path).deleteSync(recursive: true);
|
||||||
|
|
||||||
final tags = await readExifFromBytes(bytes);
|
final tags = await readExifFromBytes(bytes);
|
||||||
final iso = double.parse("${tags["EXIF ISOSpeedRatings"]}");
|
final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}");
|
||||||
final apertureValueRatio = (tags["EXIF FNumber"]!.values as IfdRatios).ratios.first;
|
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 aperture = apertureValueRatio.numerator / apertureValueRatio.denominator;
|
||||||
final speedValueRatio = (tags["EXIF ExposureTime"]!.values as IfdRatios).ratios.first;
|
|
||||||
final speed = speedValueRatio.numerator / speedValueRatio.denominator;
|
final speed = speedValueRatio.numerator / speedValueRatio.denominator;
|
||||||
|
|
||||||
return log2(pow(aperture, 2)) - log2(speed) - log2(iso / 100);
|
return log2(pow(aperture, 2)) - log2(speed) - log2(iso / 100);
|
||||||
|
|
Loading…
Reference in a new issue