|
1 | 1 | usecrate::attr::{Attributes,ControlFlow}; |
2 | 2 | usecrate::error::*; |
3 | | -usecrate::hist::HistogramInternal; |
| 3 | +usecrate::hist::{HistogramInternal,Histogram}; |
4 | 4 | usecrate::image::Image; |
5 | 5 | usecrate::kmeans::Kmeans; |
6 | 6 | usecrate::mediancut::mediancut; |
@@ -288,6 +288,26 @@ impl QuantizationResult { |
288 | 288 | pubfnpalette_len(&mutself) ->usize{ |
289 | 289 | self.palette.len() |
290 | 290 | } |
| 291 | + |
| 292 | +/// Shortcut for making [`Histogram`] with `add_fixed_color` |
| 293 | +/// |
| 294 | +/// Set `gamma` to `0.` for sRGB colors. |
| 295 | +pubfnfrom_palette(attr:&Attributes,palette:&[RGBA],gamma:f64) ->Result<Self,Error>{ |
| 296 | +if palette.len() >MAX_COLORS{ |
| 297 | +returnErr(Unsupported); |
| 298 | +} |
| 299 | + |
| 300 | +letmut hist =Histogram::new(attr); |
| 301 | +for&cin palette{ |
| 302 | + hist.add_fixed_color(c, gamma)?; |
| 303 | +} |
| 304 | + hist.quantize(attr) |
| 305 | +} |
| 306 | + |
| 307 | +/// Getter for the value set in [`set_dithering_level`] |
| 308 | +pubfndithering_level(&self) ->f32{ |
| 309 | +self.dither_level |
| 310 | +} |
291 | 311 | } |
292 | 312 |
|
293 | 313 | implCloneforQuantizationResult{ |
|