Skip to content

Commit 0f77e9e

Browse files
authored
Make external dependencies optional (#736)
* Made ab_glyph an optional dependency * Made rustdct an optional dependency
1 parent 4a45a7e commit 0f77e9e

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ homepage = "https://github.com/image-rs/imageproc"
1212
exclude = [".github/*", "examples/*", "tests/*"]
1313

1414
[features]
15-
default = ["rayon", "image/default"]
15+
default = ["rayon", "image/default", "text", "fft"]
1616
display-window = ["sdl2"]
1717
rayon = ["dep:rayon", "image/rayon"]
1818

19+
# Option: enable phash
20+
fft = ["dep:rustdct"]
21+
22+
# Option: enable drawing::text
23+
text = ["dep:ab_glyph"]
24+
1925
[dependencies]
20-
ab_glyph = { version = "0.2.23", default-features = false, features = ["std"] }
26+
ab_glyph = { version = "0.2.23", default-features = false, features = ["std"], optional = true}
2127
approx = { version = "0.5", default-features = false }
2228
image = { version = "0.25.0", default-features = false }
2329
itertools = { version = "0.14.0", default-features = false, features = [
@@ -36,7 +42,7 @@ sdl2 = { version = "0.38.0", optional = true, default-features = false, features
3642
"bundled",
3743
] }
3844
katexit = { version = "0.1.4", optional = true, default-features = false }
39-
rustdct = "0.7.1"
45+
rustdct = { version = "0.7.1", optional = true }
4046

4147
[target.'cfg(target_arch = "wasm32")'.dependencies]
4248
getrandom = { version = "0.3.0", default-features = false, features = ["wasm_js"] }

src/drawing/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ pub use self::rect::{
3232
draw_filled_rect, draw_filled_rect_mut, draw_hollow_rect, draw_hollow_rect_mut,
3333
};
3434

35+
#[cfg(feature = "text")]
3536
mod text;
37+
38+
#[cfg(feature = "text")]
3639
pub use self::text::{draw_text, draw_text_mut, text_size};
3740

3841
mod fill;

src/image_hash/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
//! [Perceptual hashing]: https://en.wikipedia.org/wiki/Perceptual_hashing
44
55
mod average_hash;
6+
67
mod bits;
8+
#[cfg(feature = "fft")]
79
mod phash;
10+
#[cfg(feature = "fft")]
811
mod signals;
912

13+
#[cfg(feature = "fft")]
14+
pub use phash::{phash, PHash};
15+
1016
use bits::Bits64;
1117

1218
pub use average_hash::{average_hash, AverageHash};
13-
pub use phash::{phash, PHash};

src/image_hash/signals.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ fn dct1d(
6868
debug_assert_eq!(img_buf.len(), width * height);
6969
Image::from_vec(img.width(), img.height(), img_buf).unwrap()
7070
}
71-
7271
fn transpose_inplace(img: &mut Image<Luma<f32>>) {
7372
assert_eq!(
7473
img.width(),
@@ -92,7 +91,6 @@ fn transpose_inplace(img: &mut Image<Luma<f32>>) {
9291
}
9392
}
9493
}
95-
9694
fn transpose(img: &Image<Luma<f32>>) -> Image<Luma<f32>> {
9795
let nwidth = img.height();
9896
let nheight = img.width();

tests/regression.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ fn test_bilateral_filter() {
978978
}
979979

980980
#[test]
981+
#[cfg(feature = "text")]
981982
fn test_draw_text() {
982983
let font_bytes = include_bytes!("data/fonts/DejaVuSans.ttf");
983984
let font = ab_glyph::FontRef::try_from_slice(font_bytes).unwrap();

0 commit comments

Comments
 (0)