refactor: deduplicate HSV validation with loop over channel ranges
This commit is contained in:
@@ -443,14 +443,16 @@ impl PerspectiveCorrectionConfig {
|
|||||||
|
|
||||||
impl ChromaKeyConfig {
|
impl ChromaKeyConfig {
|
||||||
pub fn validate(&self) -> Result<()> {
|
pub fn validate(&self) -> Result<()> {
|
||||||
validate_hsv_component("display.chroma_key.hsv_min[0]", self.hsv_min[0], 0, 180)?;
|
let hsv_ranges = [180, 255, 255]; // H, S, V max values
|
||||||
validate_hsv_component("display.chroma_key.hsv_min[1]", self.hsv_min[1], 0, 255)?;
|
for (index, &max_val) in hsv_ranges.iter().enumerate() {
|
||||||
validate_hsv_component("display.chroma_key.hsv_min[2]", self.hsv_min[2], 0, 255)?;
|
validate_hsv_component(
|
||||||
validate_hsv_component("display.chroma_key.hsv_max[0]", self.hsv_max[0], 0, 180)?;
|
&format!("display.chroma_key.hsv_min[{index}]"),
|
||||||
validate_hsv_component("display.chroma_key.hsv_max[1]", self.hsv_max[1], 0, 255)?;
|
self.hsv_min[index], 0, max_val,
|
||||||
validate_hsv_component("display.chroma_key.hsv_max[2]", self.hsv_max[2], 0, 255)?;
|
)?;
|
||||||
|
validate_hsv_component(
|
||||||
for index in 0..3 {
|
&format!("display.chroma_key.hsv_max[{index}]"),
|
||||||
|
self.hsv_max[index], 0, max_val,
|
||||||
|
)?;
|
||||||
if self.hsv_min[index] > self.hsv_max[index] {
|
if self.hsv_min[index] > self.hsv_max[index] {
|
||||||
bail!("display.chroma_key hsv_min[{index}] 不能大于 hsv_max[{index}]");
|
bail!("display.chroma_key hsv_min[{index}] 不能大于 hsv_max[{index}]");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user