refactor: deduplicate HSV validation with loop over channel ranges

This commit is contained in:
2026-03-31 23:43:44 +08:00
parent 0cdea53f8d
commit 1ded747a0c

View File

@@ -443,14 +443,16 @@ impl PerspectiveCorrectionConfig {
impl ChromaKeyConfig {
pub fn validate(&self) -> Result<()> {
validate_hsv_component("display.chroma_key.hsv_min[0]", self.hsv_min[0], 0, 180)?;
validate_hsv_component("display.chroma_key.hsv_min[1]", self.hsv_min[1], 0, 255)?;
validate_hsv_component("display.chroma_key.hsv_min[2]", self.hsv_min[2], 0, 255)?;
validate_hsv_component("display.chroma_key.hsv_max[0]", self.hsv_max[0], 0, 180)?;
validate_hsv_component("display.chroma_key.hsv_max[1]", self.hsv_max[1], 0, 255)?;
validate_hsv_component("display.chroma_key.hsv_max[2]", self.hsv_max[2], 0, 255)?;
for index in 0..3 {
let hsv_ranges = [180, 255, 255]; // H, S, V max values
for (index, &max_val) in hsv_ranges.iter().enumerate() {
validate_hsv_component(
&format!("display.chroma_key.hsv_min[{index}]"),
self.hsv_min[index], 0, max_val,
)?;
validate_hsv_component(
&format!("display.chroma_key.hsv_max[{index}]"),
self.hsv_max[index], 0, max_val,
)?;
if self.hsv_min[index] > self.hsv_max[index] {
bail!("display.chroma_key hsv_min[{index}] 不能大于 hsv_max[{index}]");
}