mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 23:10:40 +00:00
Recalculate EV on Iso change
This commit is contained in:
parent
00c0a6134d
commit
dbbc5738ce
5 changed files with 29 additions and 3 deletions
|
@ -18,6 +18,7 @@ class MeteringTopBar extends StatelessWidget {
|
|||
final double ev;
|
||||
final IsoValue iso;
|
||||
final double nd;
|
||||
final ValueChanged<IsoValue> onIsoChanged;
|
||||
|
||||
MeteringTopBar({
|
||||
required this.fastest,
|
||||
|
@ -25,6 +26,7 @@ class MeteringTopBar extends StatelessWidget {
|
|||
required this.ev,
|
||||
required this.iso,
|
||||
required this.nd,
|
||||
required this.onIsoChanged,
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
@ -108,7 +110,7 @@ class MeteringTopBar extends StatelessWidget {
|
|||
_isoDialogKey.currentState?.close();
|
||||
},
|
||||
onSelect: (value) {
|
||||
_isoDialogKey.currentState?.close();
|
||||
_isoDialogKey.currentState?.close().then((_) => onIsoChanged(value));
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:math';
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:lightmeter/models/exposure_pair.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/utils/log_2.dart';
|
||||
|
||||
import 'metering_event.dart';
|
||||
import 'metering_state.dart';
|
||||
|
@ -24,11 +25,23 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
|||
exposurePairs: [],
|
||||
),
|
||||
) {
|
||||
on<IsoChangedEvent>(_onIsoChanged);
|
||||
on<MeasureEvent>(_onMeasure);
|
||||
|
||||
add(const MeasureEvent());
|
||||
}
|
||||
|
||||
void _onIsoChanged(IsoChangedEvent event, Emitter emit) {
|
||||
final ev = state.ev + log2(event.isoValue.value / state.iso.value);
|
||||
emit(MeteringState(
|
||||
iso: event.isoValue,
|
||||
ev: ev,
|
||||
evCompensation: state.evCompensation,
|
||||
nd: state.nd,
|
||||
exposurePairs: _buildExposureValues(ev),
|
||||
));
|
||||
}
|
||||
|
||||
/// https://www.scantips.com/lights/exposurecalc.html
|
||||
void _onMeasure(_, Emitter emit) {
|
||||
double log2(double x) => log(x) / log(2);
|
||||
|
@ -39,14 +52,13 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
|||
|
||||
final evAtSystemIso = log2(pow(aperture.value, 2).toDouble()) - log2(shutterSpeed.value);
|
||||
final ev = evAtSystemIso - log2(iso.value / state.iso.value);
|
||||
final exposurePairs = _buildExposureValues(ev);
|
||||
|
||||
emit(MeteringState(
|
||||
iso: state.iso,
|
||||
ev: ev,
|
||||
evCompensation: state.evCompensation,
|
||||
nd: state.nd,
|
||||
exposurePairs: exposurePairs,
|
||||
exposurePairs: _buildExposureValues(ev),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
import 'package:lightmeter/models/photography_value.dart';
|
||||
|
||||
abstract class MeteringEvent {
|
||||
const MeteringEvent();
|
||||
}
|
||||
|
||||
class IsoChangedEvent extends MeteringEvent {
|
||||
final IsoValue isoValue;
|
||||
|
||||
const IsoChangedEvent(this.isoValue);
|
||||
}
|
||||
|
||||
class MeasureEvent extends MeteringEvent {
|
||||
const MeasureEvent();
|
||||
}
|
||||
|
|
|
@ -112,6 +112,7 @@ class _MeteringScreenState extends State<MeteringScreen> {
|
|||
ev: state.ev,
|
||||
iso: state.iso,
|
||||
nd: state.nd,
|
||||
onIsoChanged: (value) => context.read<MeteringBloc>().add(IsoChangedEvent(value)),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
3
lib/utils/log_2.dart
Normal file
3
lib/utils/log_2.dart
Normal file
|
@ -0,0 +1,3 @@
|
|||
import 'dart:math';
|
||||
|
||||
double log2(double x) => log(x) / log(2);
|
Loading…
Reference in a new issue