File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 11use crate :: attr:: { Attributes , ControlFlow } ;
22use crate :: error:: * ;
3- use crate :: hist:: HistogramInternal ;
3+ use crate :: hist:: { HistogramInternal , Histogram } ;
44use crate :: image:: Image ;
55use crate :: kmeans:: Kmeans ;
66use crate :: mediancut:: mediancut;
@@ -288,6 +288,21 @@ impl QuantizationResult {
288288 pub fn palette_len ( & mut self ) -> usize {
289289 self . palette . len ( )
290290 }
291+
292+ /// Shortcut for making [`Histogram`] with `add_fixed_color`
293+ ///
294+ /// Set `gamma` to `0.` for sRGB colors.
295+ pub fn from_palette ( attr : & Attributes , palette : & [ RGBA ] , gamma : f64 ) -> Result < Self , Error > {
296+ if palette. len ( ) > MAX_COLORS {
297+ return Err ( Unsupported ) ;
298+ }
299+
300+ let mut hist = Histogram :: new ( attr) ;
301+ for & c in palette {
302+ hist. add_fixed_color ( c, gamma) ?;
303+ }
304+ hist. quantize ( attr)
305+ }
291306}
292307
293308impl Clone for QuantizationResult {
You can’t perform that action at this time.
0 commit comments