Skip to content

Commit

Permalink
Remove ahash feature
Browse files Browse the repository at this point in the history
And add workaroud to use non random state for chrome on windows.

Based on googlefonts/fontations#751.
  • Loading branch information
vigneshvg committed Jan 31, 2024
1 parent 74cfc55 commit 6c0218b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
crate-type = ["rlib", "cdylib"]

[dependencies]
ahash = {version = "0.8.6", optional = true}
byteorder = "1.5.0"
libc = {version = "0.2.152", optional = true}
ndk = {version = "0.8.0", features = ["media"], optional = true}
Expand All @@ -34,7 +33,6 @@ dav1d = ["dep:libc", "dep:dav1d-sys"]
libgav1 = ["dep:libgav1-sys"]
libyuv = ["dep:libyuv-sys"]
android_mediacodec = ["dep:ndk"]
use_ahash = ["dep:ahash"]

[package.metadata.capi.header]
name = "avif"
Expand Down
4 changes: 2 additions & 2 deletions src/decoder/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl Item {
pub type Items = HashMap<u32, Item>;

pub fn construct_items(meta: &MetaBox) -> AvifResult<Items> {
let mut items: Items = HashMap::new();
let mut items: Items = HashMap::with_hasher(NonRandomHasherState);
for iinf in &meta.iinf {
items.insert(
iinf.item_id,
Expand Down Expand Up @@ -357,7 +357,7 @@ pub fn construct_items(meta: &MetaBox) -> AvifResult<Items> {
.ok_or(AvifError::BmffParseFailed)?;
}
}
let mut ipma_seen: HashSet<u32> = HashSet::new();
let mut ipma_seen: HashSet<u32> = HashSet::with_hasher(NonRandomHasherState);
for association in &meta.iprp.associations {
if ipma_seen.contains(&association.item_id) {
println!("item has duplictate ipma.");
Expand Down
21 changes: 13 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ mod codecs;
mod internal_utils;
mod parser;

#[cfg(feature = "use_ahash")]
type HashMap<K, V> = ahash::AHashMap<K, V>;
#[cfg(feature = "use_ahash")]
type HashSet<K> = ahash::AHashSet<K>;
#[cfg(not(feature = "use_ahash"))]
type HashMap<K, V> = std::collections::HashMap<K, V>;
#[cfg(not(feature = "use_ahash"))]
type HashSet<K> = std::collections::HashSet<K>;
// Workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=1516634.
#[derive(Default)]
pub struct NonRandomHasherState;

impl std::hash::BuildHasher for NonRandomHasherState {
type Hasher = std::collections::hash_map::DefaultHasher;
fn build_hasher(&self) -> std::collections::hash_map::DefaultHasher {
std::collections::hash_map::DefaultHasher::new()
}
}

pub type HashMap<K, V> = std::collections::HashMap<K, V, NonRandomHasherState>;
pub type HashSet<K> = std::collections::HashSet<K, NonRandomHasherState>;

#[derive(Debug, Default, PartialEq, Copy, Clone)]
pub enum PixelFormat {
Expand Down
3 changes: 2 additions & 1 deletion src/parser/mp4box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,8 @@ fn parse_meta(stream: &mut IStream) -> AvifResult<MetaBox> {
parse_hdlr(&mut sub_stream)?;
}

let mut boxes_seen = HashSet::from([String::from("hdlr")]);
let mut boxes_seen: HashSet<String> = HashSet::with_hasher(NonRandomHasherState);
boxes_seen.insert(String::from("hdlr"));
while stream.has_bytes_left() {
let header = parse_header(stream)?;
match header.box_type.as_str() {
Expand Down
15 changes: 7 additions & 8 deletions src/reformat/coeffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ fn calculate_yuv_coefficients_from_cicp(
match matrix_coefficients {
MatrixCoefficients::ChromaDerivedNcl => Some(color_primaries.y_coeffs()),
_ => {
let lookup = HashMap::from([
(MatrixCoefficients::Bt709, (0.2126f32, 0.0722)),
(MatrixCoefficients::Fcc, (0.30, 0.11)),
(MatrixCoefficients::Bt470bg, (0.299, 0.114)),
(MatrixCoefficients::Bt601, (0.299, 0.114)),
(MatrixCoefficients::Smpte240, (0.212, 0.087)),
(MatrixCoefficients::Bt2020Ncl, (0.2627, 0.0593)),
]);
let mut lookup = HashMap::with_hasher(NonRandomHasherState);
lookup.insert(MatrixCoefficients::Bt709, (0.2126f32, 0.0722));
lookup.insert(MatrixCoefficients::Fcc, (0.30, 0.11));
lookup.insert(MatrixCoefficients::Bt470bg, (0.299, 0.114));
lookup.insert(MatrixCoefficients::Bt601, (0.299, 0.114));
lookup.insert(MatrixCoefficients::Smpte240, (0.212, 0.087));
lookup.insert(MatrixCoefficients::Bt2020Ncl, (0.2627, 0.0593));
lookup
.get(&matrix_coefficients)
.map(|x| [x.0, 1.0 - x.0 - x.1, x.1])
Expand Down

0 comments on commit 6c0218b

Please sign in to comment.