Use FxHasher in color to palette
This commit is contained in:
parent
c0d1ff816b
commit
aacc35e4af
1 changed files with 7 additions and 3 deletions
|
|
@ -4,7 +4,10 @@ use crate::png::PngImage;
|
|||
use indexmap::IndexMap;
|
||||
use itertools::Itertools;
|
||||
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]
|
||||
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>(
|
||||
iter: impl IntoIterator<Item = T>,
|
||||
palette: &mut IndexMap<T, u8>,
|
||||
palette: &mut FxIndexMap<T, u8>,
|
||||
reduced: &mut Vec<u8>,
|
||||
) -> bool
|
||||
where
|
||||
|
|
@ -107,7 +110,8 @@ pub fn reduced_color_to_palette(png: &PngImage) -> Option<PngImage> {
|
|||
return None;
|
||||
}
|
||||
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
|
||||
.transparency_pixel
|
||||
.as_ref()
|
||||
|
|
|
|||
Loading…
Reference in a new issue