From e5d57ed6049e7727ce05b9894a92cb1ca2db7453 Mon Sep 17 00:00:00 2001 From: var4yn <2016slavyakinnikita@gmail.com> Date: Sat, 26 Jul 2025 07:27:51 +0800 Subject: [PATCH 1/6] fix: correct text alpha blending --- src/drawing/text.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/drawing/text.rs b/src/drawing/text.rs index 13319afb..0bcf212c 100644 --- a/src/drawing/text.rs +++ b/src/drawing/text.rs @@ -88,6 +88,11 @@ pub fn draw_text_mut( let image_width = canvas.width() as i32; let image_height = canvas.height() as i32; + let has_alpha = match C::Pixel::COLOR_MODEL { + "RGBA" | "YA" => true, + _ => false, + }; + layout_glyphs(scale, font, text, |g, bb| { let x_shift = x + bb.min.x.round() as i32; let y_shift = y + bb.min.y.round() as i32; @@ -98,10 +103,19 @@ pub fn draw_text_mut( if (0..image_width).contains(&image_x) && (0..image_height).contains(&image_y) { let image_x = image_x as u32; let image_y = image_y as u32; - let pixel = canvas.get_pixel(image_x, image_y); + let mut pixel = canvas.get_pixel(image_x, image_y); let gv = gv.clamp(0.0, 1.0); - let weighted_color = weighted_sum(pixel, color, 1.0 - gv, gv); - canvas.draw_pixel(image_x, image_y, weighted_color); + + if has_alpha { + let mut color = color; + color.apply_with_alpha(|f| f, |g| Clamp::clamp(g.into() * gv)); + + pixel.blend(&color); + } else { + pixel = weighted_sum(pixel, color, 1.0 - gv, gv); + } + + canvas.draw_pixel(image_x, image_y, pixel); } }) }); From 5f660c9d705f8eebb208828c57fcbaa02a432545 Mon Sep 17 00:00:00 2001 From: var4yn <2016slavyakinnikita@gmail.com> Date: Sat, 26 Jul 2025 14:48:49 +0800 Subject: [PATCH 2/6] fix conflict with `half@2.6.0`: upgrade rust to 1.81.0 --- .github/workflows/check.yml | 2 +- Cargo.toml | 10 +++++----- src/drawing/text.rs | 5 +---- src/template_matching.rs | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c8523e17..8c2766e6 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -98,7 +98,7 @@ jobs: # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability strategy: matrix: - msrv: ["1.80.1"] # Don't forget to update the `rust-version` in Cargo.toml as well + msrv: ["1.81.0"] # Don't forget to update the `rust-version` in Cargo.toml as well name: ubuntu / ${{ matrix.msrv }} steps: - uses: actions/checkout@v4 diff --git a/Cargo.toml b/Cargo.toml index 3520d054..0b40ce1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "imageproc" -version = "0.26.0" +version = "0.26.1" authors = ["theotherphil"] # note: when changed, also update `msrv` in `.github/workflows/check.yml` -rust-version = "1.80.1" +rust-version = "1.81.0" edition = "2021" license = "MIT" description = "Image processing operations" @@ -13,14 +13,13 @@ homepage = "https://github.com/image-rs/imageproc" exclude = [".github/*", "examples/*", "tests/*"] [features] -default = ["rayon", "image/default"] +default = ["rayon"] display-window = ["sdl2"] -rayon = ["dep:rayon", "image/rayon"] +rayon = ["dep:rayon"] [dependencies] ab_glyph = { version = "0.2.23", default-features = false, features = ["std"] } approx = { version = "0.5", default-features = false } -image = { version = "0.25.0", default-features = false } itertools = { version = "0.13.0", default-features = false, features = [ "use_std", ] } @@ -37,6 +36,7 @@ sdl2 = { version = "0.36", optional = true, default-features = false, features = ] } katexit = { version = "0.1.4", optional = true, default-features = false } rustdct = "0.7.1" +image = "0.25.6" [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2", default-features = false, features = ["js"] } diff --git a/src/drawing/text.rs b/src/drawing/text.rs index 0bcf212c..28eddf04 100644 --- a/src/drawing/text.rs +++ b/src/drawing/text.rs @@ -88,10 +88,7 @@ pub fn draw_text_mut( let image_width = canvas.width() as i32; let image_height = canvas.height() as i32; - let has_alpha = match C::Pixel::COLOR_MODEL { - "RGBA" | "YA" => true, - _ => false, - }; + let has_alpha = matches!(C::Pixel::COLOR_MODEL, "RGBA" | "YA"); layout_glyphs(scale, font, text, |g, bb| { let x_shift = x + bb.min.x.round() as i32; diff --git a/src/template_matching.rs b/src/template_matching.rs index e51a2fb6..a9476289 100644 --- a/src/template_matching.rs +++ b/src/template_matching.rs @@ -392,7 +392,7 @@ mod methods { } fn square_sum(input: &GrayImage) -> f32 { - input.iter().map(|&x| (x as f32 * x as f32)).sum() + input.iter().map(|&x| x as f32 * x as f32).sum() } fn mult_square_sum(a: &GrayImage, b: &GrayImage) -> f32 { a.iter() From 9a3b79a7741691e248c44719457046404ba33400 Mon Sep 17 00:00:00 2001 From: var4yn <2016slavyakinnikita@gmail.com> Date: Sat, 26 Jul 2025 15:17:26 +0800 Subject: [PATCH 3/6] downgrade `image` to v0.25.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0b40ce1e..fca02ba7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ rayon = ["dep:rayon"] [dependencies] ab_glyph = { version = "0.2.23", default-features = false, features = ["std"] } approx = { version = "0.5", default-features = false } +image = { version = "0.25.0", default-features = false } itertools = { version = "0.13.0", default-features = false, features = [ "use_std", ] } @@ -36,7 +37,6 @@ sdl2 = { version = "0.36", optional = true, default-features = false, features = ] } katexit = { version = "0.1.4", optional = true, default-features = false } rustdct = "0.7.1" -image = "0.25.6" [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2", default-features = false, features = ["js"] } From a5751669ade3b3d4606660f73da71a4aae97b692 Mon Sep 17 00:00:00 2001 From: var4yn <2016slavyakinnikita@gmail.com> Date: Sat, 26 Jul 2025 15:42:13 +0800 Subject: [PATCH 4/6] fix fetures in .toml --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fca02ba7..81fa796c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,9 @@ homepage = "https://github.com/image-rs/imageproc" exclude = [".github/*", "examples/*", "tests/*"] [features] -default = ["rayon"] +default = ["rayon", "image/default"] display-window = ["sdl2"] -rayon = ["dep:rayon"] +rayon = ["dep:rayon", "image/rayon"] [dependencies] ab_glyph = { version = "0.2.23", default-features = false, features = ["std"] } From 11a74dd66d311a9998a4b9e08874a60b31235406 Mon Sep 17 00:00:00 2001 From: var4yn <2016slavyakinnikita@gmail.com> Date: Sat, 26 Jul 2025 16:38:58 +0800 Subject: [PATCH 5/6] upgrade `image` to 0.25.6, ignore miri test in `contrast.rs` --- Cargo.toml | 2 +- src/contrast.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 81fa796c..d58759b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ rayon = ["dep:rayon", "image/rayon"] [dependencies] ab_glyph = { version = "0.2.23", default-features = false, features = ["std"] } approx = { version = "0.5", default-features = false } -image = { version = "0.25.0", default-features = false } +image = { version = "0.25.6", default-features = false } itertools = { version = "0.13.0", default-features = false, features = [ "use_std", ] } diff --git a/src/contrast.rs b/src/contrast.rs index c9024f1b..ac67c97d 100644 --- a/src/contrast.rs +++ b/src/contrast.rs @@ -462,6 +462,7 @@ fn histogram_lut(source_histc: &[u32; 256], target_histc: &[u32; 256]) -> [usize lut } +#[cfg(not(miri))] #[cfg(test)] mod tests { use super::*; From 7498e4d728e377a5a83a10cea46270f3f58e5089 Mon Sep 17 00:00:00 2001 From: var4yn <2016slavyakinnikita@gmail.com> Date: Sat, 26 Jul 2025 17:16:22 +0800 Subject: [PATCH 6/6] upgrade `rayon` to 1.10.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d58759b2..2d31208e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ rand = { version = "0.8.5", default-features = false, features = [ "std_rng", ] } rand_distr = { version = "0.4.3", default-features = false } -rayon = { version = "1.8.0", optional = true, default-features = false } +rayon = { version = "1.10.0", optional = true, default-features = false } sdl2 = { version = "0.36", optional = true, default-features = false, features = [ "bundled", ] }