analyzeLight static method
Analyzes ambient light conditions from frame luminance.
Implementation
static LightAnalysis analyzeLight(Uint8List imageBytes) {
if (imageBytes.isEmpty) {
return const LightAnalysis(
condition: LightCondition.tooLow,
averageLuminance: 0.0,
estimatedLux: 0.0,
torchRecommended: true,
);
}
// Calculate average luminance
double totalLuminance = 0;
for (int i = 0; i < imageBytes.length; i++) {
totalLuminance += imageBytes[i];
}
final avgLuminance = totalLuminance / imageBytes.length / 255.0;
// Estimate lux from normalized luminance (rough approximation)
final estimatedLux = avgLuminance * 1000.0;
final LightCondition condition;
final bool torchRecommended;
if (avgLuminance < 0.08) {
condition = LightCondition.tooLow;
torchRecommended = true;
} else if (avgLuminance < 0.20) {
condition = LightCondition.low;
torchRecommended = true;
} else if (avgLuminance < 0.70) {
condition = LightCondition.normal;
torchRecommended = false;
} else if (avgLuminance < 0.90) {
condition = LightCondition.bright;
torchRecommended = false;
} else {
condition = LightCondition.overexposed;
torchRecommended = false;
}
return LightAnalysis(
condition: condition,
averageLuminance: avgLuminance,
estimatedLux: estimatedLux,
torchRecommended: torchRecommended,
);
}