File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: attr:: { Attributes , ControlFlow } ;
2
2
use crate :: error:: * ;
3
- use crate :: hist:: HistogramInternal ;
3
+ use crate :: hist:: { HistogramInternal , Histogram } ;
4
4
use crate :: image:: Image ;
5
5
use crate :: kmeans:: Kmeans ;
6
6
use crate :: mediancut:: mediancut;
@@ -288,6 +288,26 @@ impl QuantizationResult {
288
288
pub fn palette_len ( & mut self ) -> 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
+ 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
+ }
306
+
307
+ /// Getter for the value set in [`set_dithering_level`]
308
+ pub fn dithering_level ( & self ) -> f32 {
309
+ self . dither_level
310
+ }
291
311
}
292
312
293
313
impl Clone for QuantizationResult {
You can’t perform that action at this time.
0 commit comments