File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -124,7 +124,7 @@ impl Kmeans {
124124/// This replaces these entries with histogram colors that are currently least-fitting the palette.
125125fn replace_unused_colors ( palette : & mut PalF , hist : & HistogramInternal ) -> Result < ( ) , Error > {
126126 for pal_idx in 0 ..palette. len ( ) {
127- let pop = palette. pop_as_slice ( ) [ pal_idx] ;
127+ let Some ( pop) = palette. pop_as_slice ( ) . get ( pal_idx) else { break } ;
128128 if pop. popularity ( ) == 0. && !pop. is_fixed ( ) {
129129 let n = Nearest :: new ( palette) ?;
130130 let mut worst = None ;
Original file line number Diff line number Diff line change @@ -240,8 +240,14 @@ impl PalF {
240240 }
241241
242242 pub fn set ( & mut self , idx : usize , color : f_pixel , popularity : PalPop ) {
243- self . colors [ idx] = color;
244- self . pops [ idx] = popularity;
243+ debug_assert ! ( idx < self . colors. len( ) && idx < self . pops. len( ) ) ;
244+
245+ if let Some ( pops_idx) = self . pops . get_mut ( idx) {
246+ * pops_idx = popularity;
247+ }
248+ if let Some ( colors_idx) = self . colors . get_mut ( idx) {
249+ * colors_idx = color;
250+ }
245251 }
246252
247253 #[ inline( always) ]
You can’t perform that action at this time.
0 commit comments