(attr: &Attributes, palette: &mut PalF)
| 329 | } |
| 330 | |
| 331 | fn sort_palette(attr: &Attributes, palette: &mut PalF) { |
| 332 | let last_index_transparent = attr.last_index_transparent; |
| 333 | |
| 334 | let mut tmp: ArrayVec<_, { MAX_COLORS }> = palette.iter_mut().map(|(c, p)| (*c, *p)).collect(); |
| 335 | tmp.sort_by_key(|(color, pop)| { |
| 336 | let is_transparent = color.a <= MAX_TRANSP_A; |
| 337 | (is_transparent == last_index_transparent, Reverse(OrdFloat::new(pop.popularity()))) |
| 338 | }); |
| 339 | palette.iter_mut().zip(tmp).for_each(|((dcol, dpop), (scol, spop))| { |
| 340 | *dcol = scol; |
| 341 | *dpop = spop; |
| 342 | }); |
| 343 | |
| 344 | if last_index_transparent { |
| 345 | let alpha_index = palette.as_slice().iter().enumerate() |
| 346 | .filter(|(_, c)| c.a <= MAX_TRANSP_A) |
| 347 | .min_by_key(|(_, c)| OrdFloat::new(c.a)) |
| 348 | .map(|(i, _)| i); |
| 349 | if let Some(alpha_index) = alpha_index { |
| 350 | let last_index = palette.as_slice().len() - 1; |
| 351 | palette.swap(last_index, alpha_index); |
| 352 | } |
| 353 | } else { |
| 354 | let num_transparent = palette.as_slice().iter().enumerate() |
| 355 | .filter(|(_, c)| c.a <= MAX_TRANSP_A) |
| 356 | .map(|(i, _)| i + 1) // num entries, not index |
| 357 | .max(); |
| 358 | if let Some(num_transparent) = num_transparent { |
| 359 | attr.verbose_print(format!(" eliminated opaque tRNS-chunk entries...{} entr{} transparent", num_transparent, if num_transparent == 1 { "y" } else { "ies" })); |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | impl fmt::Debug for QuantizationResult { |
| 365 | #[cold] |
no test coverage detected