mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2025-05-12 19:20:42 +00:00
[ios] calculate EFL
This commit is contained in:
parent
4c689db8ee
commit
3f05e8426e
5 changed files with 51 additions and 8 deletions
|
@ -9,6 +9,7 @@ import Flutter
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
|
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
|
||||||
let caffeinePlatformChannel = CaffeinePlatformChannel(binaryMessenger: controller.binaryMessenger)
|
let caffeinePlatformChannel = CaffeinePlatformChannel(binaryMessenger: controller.binaryMessenger)
|
||||||
|
let cameraInfoPlatformChannel = CameraInfoPlatformChannel(binaryMessenger: controller.binaryMessenger)
|
||||||
GeneratedPluginRegistrant.register(with: self)
|
GeneratedPluginRegistrant.register(with: self)
|
||||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,5 @@ public class CaffeinePlatformChannel: NSObject {
|
||||||
result(FlutterMethodNotImplemented)
|
result(FlutterMethodNotImplemented)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
45
ios/Runner/PlatformChannels/CameraInfoPlatformChannel.swift
Normal file
45
ios/Runner/PlatformChannels/CameraInfoPlatformChannel.swift
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
//
|
||||||
|
// CameraInfoPlatformChannel.swift
|
||||||
|
// Runner
|
||||||
|
//
|
||||||
|
// Created by Vadim Turko on 2025-05-11.
|
||||||
|
//
|
||||||
|
import AVFoundation
|
||||||
|
import Flutter
|
||||||
|
|
||||||
|
public class CameraInfoPlatformChannel: NSObject {
|
||||||
|
let methodChannel: FlutterMethodChannel
|
||||||
|
|
||||||
|
init(binaryMessenger: FlutterBinaryMessenger) {
|
||||||
|
self.methodChannel = FlutterMethodChannel(
|
||||||
|
name: "com.vodemn.lightmeter.CameraInfoPlatformChannel.MethodChannel",
|
||||||
|
binaryMessenger: binaryMessenger
|
||||||
|
)
|
||||||
|
super.init()
|
||||||
|
methodChannel.setMethodCallHandler({
|
||||||
|
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
|
||||||
|
switch call.method {
|
||||||
|
case "mainCameraEfl":
|
||||||
|
if let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) {
|
||||||
|
result(self.get35mmEquivalentFocalLength(format: device.activeFormat))
|
||||||
|
} else {
|
||||||
|
result(nil)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
result(FlutterMethodNotImplemented)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func get35mmEquivalentFocalLength(format : AVCaptureDevice.Format) -> Float {
|
||||||
|
// get reported field of view. Documentation says this is the horizontal field of view
|
||||||
|
var fov = format.videoFieldOfView
|
||||||
|
// convert to radians
|
||||||
|
fov *= Float.pi/180.0
|
||||||
|
// angle and opposite of right angle triangle are half the fov and half the width of
|
||||||
|
// 35mm film (ie 18mm). The adjacent value of the right angle triangle is the equivalent
|
||||||
|
// focal length. Using some right angle triangle math you can work out focal length
|
||||||
|
let focalLen = 18 / tan(fov/2)
|
||||||
|
return focalLen
|
||||||
|
}
|
||||||
|
}
|
|
@ -100,11 +100,13 @@ class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
SharedPreferences.getInstance(),
|
SharedPreferences.getInstance(),
|
||||||
const LightSensorService(LocalPlatform()).hasSensor(),
|
const LightSensorService(LocalPlatform()).hasSensor(),
|
||||||
|
const CameraInfoService().mainCameraEfl(),
|
||||||
remoteConfigService.activeAndFetchFeatures(),
|
remoteConfigService.activeAndFetchFeatures(),
|
||||||
equipmentProfilesStorageService.init(),
|
equipmentProfilesStorageService.init(),
|
||||||
filmsStorageService.init(),
|
filmsStorageService.init(),
|
||||||
]).then((value) {
|
]).then((value) {
|
||||||
userPreferencesService = UserPreferencesService((value[0] as SharedPreferences?)!);
|
userPreferencesService = UserPreferencesService((value[0] as SharedPreferences?)!)
|
||||||
|
..cameraFocalLength = value[2] as int?;
|
||||||
hasLightSensor = value[1] as bool? ?? false;
|
hasLightSensor = value[1] as bool? ?? false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
@ -12,9 +10,7 @@ class CameraInfoService {
|
||||||
const CameraInfoService();
|
const CameraInfoService();
|
||||||
|
|
||||||
Future<int?> mainCameraEfl() async {
|
Future<int?> mainCameraEfl() async {
|
||||||
if (Platform.isIOS) {
|
final focalLength = await cameraInfoPlatformChannel.invokeMethod<double?>('mainCameraEfl');
|
||||||
return null;
|
return focalLength?.round();
|
||||||
}
|
|
||||||
return (await cameraInfoPlatformChannel.invokeMethod<double?>('mainCameraEfl'))?.round();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue