quantizr/
options.rs

1use crate::error::Error;
2
3/// Quantization options
4pub struct Options {
5    max_colors: i32,
6}
7
8impl Default for Options {
9    fn default() -> Self {
10        Self { max_colors: 256 }
11    }
12}
13
14impl Options {
15    pub fn get_max_colors(&self) -> i32 {
16        self.max_colors
17    }
18
19    /// Sets the maximum number of colors in the resultant palette.
20    ///
21    /// Returns [`Error::ValueOutOfRange`] if the provided number is greater
22    /// than 256 or less than 2
23    pub fn set_max_colors(&mut self, colors: i32) -> Result<(), Error> {
24        if !(2..=256).contains(&colors) {
25            return Err(Error::ValueOutOfRange);
26        }
27
28        self.max_colors = colors;
29
30        Ok(())
31    }
32}