mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 23:10:40 +00:00
[iOS] fixed histogram
This commit is contained in:
parent
b4be0cced3
commit
26619ce3de
1 changed files with 48 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:camera/camera.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
|
||||
|
@ -64,6 +65,19 @@ class _CameraHistogramState extends State<CameraHistogram> {
|
|||
histogramG = List.filled(256, 0);
|
||||
histogramB = List.filled(256, 0);
|
||||
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.android:
|
||||
_yuv420toRgb(image);
|
||||
case TargetPlatform.iOS:
|
||||
_bgra8888toRgb(image);
|
||||
default:
|
||||
}
|
||||
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
void _yuv420toRgb(CameraImage image) {
|
||||
final int uvRowStride = image.planes[1].bytesPerRow;
|
||||
final int uvPixelStride = image.planes[1].bytesPerPixel!;
|
||||
|
||||
|
@ -85,9 +99,23 @@ class _CameraHistogramState extends State<CameraHistogram> {
|
|||
histogramB[b.round().clamp(0, 255)]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
void _bgra8888toRgb(CameraImage image) {
|
||||
for (int i = 0; i < image.planes.first.bytes.length; i++) {
|
||||
final int channel = i % 4;
|
||||
switch (channel) {
|
||||
case 3:
|
||||
break;
|
||||
case 2:
|
||||
histogramR[image.planes.first.bytes[i]]++;
|
||||
case 1:
|
||||
histogramG[image.planes.first.bytes[i]]++;
|
||||
case 0:
|
||||
histogramB[image.planes.first.bytes[i]]++;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue