diff --git a/lib/providers/camera_provider.dart b/lib/providers/camera_provider.dart index a24a795..8646309 100644 --- a/lib/providers/camera_provider.dart +++ b/lib/providers/camera_provider.dart @@ -174,8 +174,8 @@ } /// カメラリソースを解放する. - void disposeCamera() { - _stopImageStream(); + Future disposeCamera() async { + await _stopImageStream(); _latestFrame = null; _controller?.dispose(); _controller = null; diff --git a/lib/services/file_service.dart b/lib/services/file_service.dart index e169f32..ab4b257 100644 --- a/lib/services/file_service.dart +++ b/lib/services/file_service.dart @@ -20,23 +20,9 @@ await directory.create(recursive: true); } - final yRaw = yuvData['yPlane']; - final uRaw = yuvData['uPlane']; - final vRaw = yuvData['vPlane']; - - final Uint8List yPlane; - final Uint8List uPlane; - final Uint8List vPlane; - - if (yRaw is Uint8List) { - yPlane = yRaw; - uPlane = uRaw as Uint8List; - vPlane = vRaw as Uint8List; - } else { - yPlane = Uint8List.fromList((yRaw as List).cast()); - uPlane = Uint8List.fromList((uRaw as List).cast()); - vPlane = Uint8List.fromList((vRaw as List).cast()); - } + final yPlane = _toUint8List(yuvData['yPlane']); + final uPlane = _toUint8List(yuvData['uPlane']); + final vPlane = _toUint8List(yuvData['vPlane']); if (yPlane.isEmpty) { throw Exception('YUV データが空です'); @@ -111,6 +97,11 @@ return '${baseName}_$suffix.png'; } + /// `dynamic` な YUV プレーンを `Uint8List` に変換する. + Uint8List _toUint8List(dynamic raw) => raw is Uint8List + ? raw + : Uint8List.fromList((raw as List).cast()); + /// YUV420 を RGB に変換し PNG エンコードする(isolate 内で実行). static Uint8List _convertYuvToPng(Map params) { final width = params['width'] as int;