Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb749148

Browse files
committed
Make it easier to reconstruct QuantizationResult
1 parent1f1e11a commitb749148

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

‎src/quant.rs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
usecrate::attr::{Attributes,ControlFlow};
22
usecrate::error::*;
3-
usecrate::hist::HistogramInternal;
3+
usecrate::hist::{HistogramInternal,Histogram};
44
usecrate::image::Image;
55
usecrate::kmeans::Kmeans;
66
usecrate::mediancut::mediancut;
@@ -288,6 +288,26 @@ impl QuantizationResult {
288288
pubfnpalette_len(&mutself) ->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+
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+
}
291311
}
292312

293313
implCloneforQuantizationResult{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp