mirror of
https://github.com/Cykooz/fast_image_resize.git
synced 2026-10-07 17:01:09 +00:00
Added support for multi-thread for resizing images with ResizeAlg::Nearest algorithm (#54).
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
## [Unreleased] - ReleaseDate
|
||||
|
||||
### Added
|
||||
|
||||
- Added support for multi-thread for resizing images with `ResizeAlg::Nearest` algorithm
|
||||
([#54](https://github.com/Cykooz/fast_image_resize/issues/54)).
|
||||
|
||||
## [5.2.2] - 2025-08-29
|
||||
|
||||
### Fixed
|
||||
|
||||
Generated
+43
-129
@@ -83,7 +83,7 @@ version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
|
||||
dependencies = [
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -94,7 +94,7 @@ checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -169,9 +169,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.9.3"
|
||||
version = "2.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d"
|
||||
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
|
||||
|
||||
[[package]]
|
||||
name = "bitstream-io"
|
||||
@@ -230,10 +230,11 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.34"
|
||||
version = "1.2.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc"
|
||||
checksum = "590f9024a68a8c40351881787f1934dc11afd69090f5edb6831464694d836ea3"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"jobserver",
|
||||
"libc",
|
||||
"shlex",
|
||||
@@ -324,9 +325,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.46"
|
||||
version = "4.5.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c5e4fcf9c21d2e544ca1ee9d8552de13019a42aa7dbf32747fa7aaf1df76e57"
|
||||
checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@@ -344,9 +345,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.46"
|
||||
version = "4.5.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fecb53a0e6fcfb055f686001bc2e2592fa527efaf38dbe81a6a9563562e57d41"
|
||||
checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -356,9 +357,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.45"
|
||||
version = "4.5.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6"
|
||||
checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
@@ -410,23 +411,20 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "criterion"
|
||||
version = "0.5.1"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f"
|
||||
checksum = "e1c047a62b0cc3e145fa84415a3191f628e980b194c2755aa12300a4e6cbd928"
|
||||
dependencies = [
|
||||
"anes",
|
||||
"cast",
|
||||
"ciborium",
|
||||
"clap",
|
||||
"criterion-plot",
|
||||
"is-terminal",
|
||||
"itertools 0.10.5",
|
||||
"itertools 0.13.0",
|
||||
"num-traits",
|
||||
"once_cell",
|
||||
"oorandom",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"tinytemplate",
|
||||
"walkdir",
|
||||
@@ -434,12 +432,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "criterion-plot"
|
||||
version = "0.5.0"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1"
|
||||
checksum = "9b1bcc0dc7dfae599d84ad0b1a55f80cde8af3725da8313b528da95ef783e338"
|
||||
dependencies = [
|
||||
"cast",
|
||||
"itertools 0.10.5",
|
||||
"itertools 0.13.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -599,7 +597,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tera",
|
||||
"thiserror 1.0.69",
|
||||
"thiserror 2.0.16",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
@@ -612,6 +610,12 @@ dependencies = [
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e178e4fba8a2726903f6ba98a6d221e76f9c12c650d5dc0e6afdc50677b49650"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.2"
|
||||
@@ -684,7 +688,7 @@ version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
"bitflags 2.9.4",
|
||||
"ignore",
|
||||
"walkdir",
|
||||
]
|
||||
@@ -711,12 +715,6 @@ version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
|
||||
|
||||
[[package]]
|
||||
name = "humansize"
|
||||
version = "2.1.3"
|
||||
@@ -826,17 +824,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.1"
|
||||
@@ -845,18 +832,18 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.12.1"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
@@ -1035,7 +1022,7 @@ version = "0.30.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
"bitflags 2.9.4",
|
||||
"cfg-if",
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
@@ -1253,7 +1240,7 @@ version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97baced388464909d42d89643fe4361939af9b7ce7a31ee32a168f832a70f2a0"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
"bitflags 2.9.4",
|
||||
"crc32fast",
|
||||
"fdeflate",
|
||||
"flate2",
|
||||
@@ -1965,7 +1952,7 @@ version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22"
|
||||
dependencies = [
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2027,38 +2014,13 @@ dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.60.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
|
||||
dependencies = [
|
||||
"windows-targets 0.53.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.52.6",
|
||||
"windows_aarch64_msvc 0.52.6",
|
||||
"windows_i686_gnu 0.52.6",
|
||||
"windows_i686_gnullvm 0.52.6",
|
||||
"windows_i686_msvc 0.52.6",
|
||||
"windows_x86_64_gnu 0.52.6",
|
||||
"windows_x86_64_gnullvm 0.52.6",
|
||||
"windows_x86_64_msvc 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2068,106 +2030,58 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows_aarch64_gnullvm 0.53.0",
|
||||
"windows_aarch64_msvc 0.53.0",
|
||||
"windows_i686_gnu 0.53.0",
|
||||
"windows_i686_gnullvm 0.53.0",
|
||||
"windows_i686_msvc 0.53.0",
|
||||
"windows_x86_64_gnu 0.53.0",
|
||||
"windows_x86_64_gnullvm 0.53.0",
|
||||
"windows_x86_64_msvc 0.53.0",
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.53.0"
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ exclude = ["/data", "/.github"]
|
||||
[dependencies]
|
||||
cfg-if = "1.0"
|
||||
num-traits = "0.2.19"
|
||||
thiserror = "1.0"
|
||||
thiserror = "2.0"
|
||||
document-features = "0.2.11"
|
||||
# Optional dependencies
|
||||
image = { version = "0.25.6", optional = true, default-features = false }
|
||||
@@ -51,7 +51,7 @@ serde = { version = "1.0", features = ["serde_derive"] }
|
||||
serde_json = "1.0"
|
||||
walkdir = "2.5"
|
||||
itertools = "0.14.0"
|
||||
criterion = { version = "0.5.1", default-features = false, features = ["cargo_bench_support"] }
|
||||
criterion = { version = "0.7.0", default-features = false, features = ["cargo_bench_support"] }
|
||||
tera = "1.20"
|
||||
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ fn downscale_bench(
|
||||
utils::bench(
|
||||
bench_group,
|
||||
100,
|
||||
&format!("{:?} {:?}", image.pixel_type(), filter_type),
|
||||
&format!("{}{}", cpu_ext_into_str(cpu_extensions), prefix),
|
||||
format!("{:?} {:?}", image.pixel_type(), filter_type),
|
||||
format!("{}{}", cpu_ext_into_str(cpu_extensions), prefix),
|
||||
|bencher| bencher.iter(|| resizer.resize(image, &mut res_image, &options).unwrap()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ pub fn build_md_table(bench_results: &[BenchResult]) -> String {
|
||||
let col_index = col_indexes.get(&result.parameter).copied();
|
||||
if let (Some(row_index), Some(col_index)) = (row_index, col_index) {
|
||||
let value = result.estimate / 1000000.;
|
||||
if value >= 0.10 {
|
||||
if value >= 0.01 {
|
||||
let value_index = row_index * cols_count + col_index;
|
||||
values[value_index] = Cow::Owned(format!("{:.2}", value));
|
||||
}
|
||||
|
||||
@@ -129,6 +129,7 @@ impl<'a, T: ImageView> CroppedSrcImageView<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a reference to the wrapped image view.
|
||||
#[inline]
|
||||
pub fn image_view(&self) -> &T {
|
||||
self.image_view
|
||||
|
||||
+20
-4
@@ -575,10 +575,26 @@ fn resample_nearest<P: InnerPixel>(
|
||||
|
||||
let src_rows = src_view.iter_rows_with_step(y_in_start, y_scale, dst_height);
|
||||
let dst_rows = dst_view.iter_rows_mut(0);
|
||||
for (out_row, in_row) in dst_rows.zip(src_rows) {
|
||||
for (&x_in, out_pixel) in x_in_tab.iter().zip(out_row.iter_mut()) {
|
||||
// Safety of x_in value guaranteed by algorithm of creating of x_in_tab
|
||||
*out_pixel = unsafe { *in_row.get_unchecked(x_in) };
|
||||
|
||||
#[cfg(feature = "rayon")]
|
||||
{
|
||||
use rayon::prelude::*;
|
||||
|
||||
let mut row_refs: Vec<(&mut [P], &[P])> = dst_rows.zip(src_rows).collect();
|
||||
row_refs.par_iter_mut().for_each(|(out_row, in_row)| {
|
||||
for (&x_in, out_pixel) in x_in_tab.iter().zip(out_row.iter_mut()) {
|
||||
// Safety of x_in value guaranteed by algorithm of creating of x_in_tab
|
||||
*out_pixel = unsafe { *in_row.get_unchecked(x_in) };
|
||||
}
|
||||
});
|
||||
}
|
||||
#[cfg(not(feature = "rayon"))]
|
||||
{
|
||||
for (out_row, in_row) in dst_rows.zip(src_rows) {
|
||||
for (&x_in, out_pixel) in x_in_tab.iter().zip(out_row.iter_mut()) {
|
||||
// Safety of x_in value guaranteed by algorithm of creating of x_in_tab
|
||||
*out_pixel = unsafe { *in_row.get_unchecked(x_in) };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-18
@@ -6,6 +6,13 @@ use rayon::prelude::*;
|
||||
use crate::pixels::InnerPixel;
|
||||
use crate::{ImageView, ImageViewMut};
|
||||
|
||||
const ONE: NonZeroU32 = NonZeroU32::MIN;
|
||||
|
||||
#[inline]
|
||||
fn non_zero_or_one(num: u32) -> NonZeroU32 {
|
||||
NonZeroU32::new(num).unwrap_or(ONE)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn split_h_two_images_for_threading<'a, P: InnerPixel>(
|
||||
src_view: &'a impl ImageView<Pixel = P>,
|
||||
@@ -20,15 +27,14 @@ pub(crate) fn split_h_two_images_for_threading<'a, P: InnerPixel>(
|
||||
>,
|
||||
> {
|
||||
debug_assert!(src_view.height() - src_offset >= dst_view.height());
|
||||
|
||||
let dst_width = dst_view.width();
|
||||
let dst_height = dst_view.height();
|
||||
let max_num_parts = calculate_max_number_of_horizonal_parts(dst_width, dst_height).get();
|
||||
|
||||
let num_threads = current_num_threads() as u32;
|
||||
if num_threads > 1 && max_num_parts > 1 {
|
||||
let num_parts = NonZeroU32::new(num_threads.min(max_num_parts)).unwrap();
|
||||
let dst_height = NonZeroU32::new(dst_height).unwrap();
|
||||
let num_threads = non_zero_or_one(current_num_threads() as u32);
|
||||
let max_width = dst_width.max(src_view.width());
|
||||
let num_parts = calculate_max_number_of_horizonal_parts(max_width, dst_height).min(num_threads);
|
||||
if num_parts > ONE {
|
||||
let dst_height = NonZeroU32::new(dst_height)?;
|
||||
if let Some(src_parts) = src_view.split_by_height(src_offset, dst_height, num_parts) {
|
||||
if let Some(dst_parts) = dst_view.split_by_height_mut(0, dst_height, num_parts) {
|
||||
let src_iter = src_parts.into_par_iter();
|
||||
@@ -46,12 +52,11 @@ pub(crate) fn split_h_one_image_for_threading<P: InnerPixel>(
|
||||
) -> Option<impl ParallelIterator<Item = impl ImageViewMut<Pixel = P> + '_>> {
|
||||
let width = image_view.width();
|
||||
let height = image_view.height();
|
||||
let max_num_parts = calculate_max_number_of_horizonal_parts(width, height).get();
|
||||
|
||||
let num_threads = current_num_threads() as u32;
|
||||
if num_threads > 1 && max_num_parts > 1 {
|
||||
let num_parts = NonZeroU32::new(num_threads.min(max_num_parts)).unwrap();
|
||||
let height = NonZeroU32::new(height).unwrap();
|
||||
let num_threads = non_zero_or_one(current_num_threads() as u32);
|
||||
let num_parts = calculate_max_number_of_horizonal_parts(width, height).min(num_threads);
|
||||
if num_parts > ONE {
|
||||
let height = NonZeroU32::new(height)?;
|
||||
let img_parts = image_view.split_by_height_mut(0, height, num_parts);
|
||||
return img_parts.map(|parts| parts.into_par_iter());
|
||||
}
|
||||
@@ -75,11 +80,11 @@ pub(crate) fn split_v_two_images_for_threading<'a, P: InnerPixel>(
|
||||
|
||||
let dst_width = dst_view.width();
|
||||
let dst_height = dst_view.height();
|
||||
let max_num_parts = calculate_max_number_of_vertical_parts(dst_width, dst_height).get();
|
||||
|
||||
let num_threads = current_num_threads() as u32;
|
||||
if num_threads > 1 && max_num_parts > 1 {
|
||||
let num_parts = NonZeroU32::new(num_threads.min(max_num_parts)).unwrap();
|
||||
let num_threads = non_zero_or_one(current_num_threads() as u32);
|
||||
let max_height = dst_height.max(src_view.height());
|
||||
let num_parts = calculate_max_number_of_vertical_parts(dst_width, max_height).min(num_threads);
|
||||
if num_parts > ONE {
|
||||
let dst_width = NonZeroU32::new(dst_width).unwrap();
|
||||
if let Some(src_parts) = src_view.split_by_width(src_offset, dst_width, num_parts) {
|
||||
if let Some(dst_parts) = dst_view.split_by_width_mut(0, dst_width, num_parts) {
|
||||
@@ -92,16 +97,16 @@ pub(crate) fn split_v_two_images_for_threading<'a, P: InnerPixel>(
|
||||
None
|
||||
}
|
||||
|
||||
const PIXELS_PER_THREAD: u64 = 1_024; // It was selected as a result of simple benchmarking.
|
||||
const PIXELS_PER_THREAD: u64 = 1024; // It was selected as a result of simple benchmarking.
|
||||
|
||||
fn calculate_max_number_of_horizonal_parts(width: u32, height: u32) -> NonZeroU32 {
|
||||
let area = width as u64 * height as u64;
|
||||
let num_parts = (area / PIXELS_PER_THREAD).min(height as _) as u32;
|
||||
NonZeroU32::new(num_parts).unwrap_or(NonZeroU32::MIN)
|
||||
non_zero_or_one(num_parts)
|
||||
}
|
||||
|
||||
fn calculate_max_number_of_vertical_parts(width: u32, height: u32) -> NonZeroU32 {
|
||||
let area = width as u64 * height as u64;
|
||||
let num_parts = (area / PIXELS_PER_THREAD).min(width as _) as u32;
|
||||
NonZeroU32::new(num_parts).unwrap_or(NonZeroU32::MIN)
|
||||
non_zero_or_one(num_parts)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user