Use FxHasher in color to palette

This commit is contained in:
Andrew 2022-11-08 17:00:15 +13:00
parent c0d1ff816b
commit aacc35e4af

View file

@ -4,7 +4,10 @@ use crate::png::PngImage;
use indexmap::IndexMap; use indexmap::IndexMap;
use itertools::Itertools; use itertools::Itertools;
use rgb::{FromSlice, RGB8, RGBA8}; use rgb::{FromSlice, RGB8, RGBA8};
use std::hash::Hash; use rustc_hash::FxHasher;
use std::hash::{BuildHasherDefault, Hash};
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
#[must_use] #[must_use]
pub fn reduce_rgba_to_grayscale_alpha(png: &PngImage) -> Option<PngImage> { pub fn reduce_rgba_to_grayscale_alpha(png: &PngImage) -> Option<PngImage> {
@ -78,7 +81,7 @@ pub fn reduce_rgba_to_grayscale_alpha(png: &PngImage) -> Option<PngImage> {
fn reduce_scanline_to_palette<T>( fn reduce_scanline_to_palette<T>(
iter: impl IntoIterator<Item = T>, iter: impl IntoIterator<Item = T>,
palette: &mut IndexMap<T, u8>, palette: &mut FxIndexMap<T, u8>,
reduced: &mut Vec<u8>, reduced: &mut Vec<u8>,
) -> bool ) -> bool
where where
@ -107,7 +110,8 @@ pub fn reduced_color_to_palette(png: &PngImage) -> Option<PngImage> {
return None; return None;
} }
let mut raw_data = Vec::with_capacity(png.data.len()); let mut raw_data = Vec::with_capacity(png.data.len());
let mut palette = IndexMap::with_capacity(257); let mut palette = FxIndexMap::default();
palette.reserve(257);
let transparency_pixel = png let transparency_pixel = png
.transparency_pixel .transparency_pixel
.as_ref() .as_ref()