Added feature only_u8x4 that can be used to experiment with the crate's code.

This commit is contained in:
Kirill Kuzminykh
2023-12-05 21:55:45 +03:00
parent cd7832850d
commit 63f6b517ab
13 changed files with 1236 additions and 1098 deletions
-1
View File
@@ -2,4 +2,3 @@
.*
!/.gitignore
data/result
/glassbench_v1.db
Generated
+127 -77
View File
@@ -60,30 +60,30 @@ checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
[[package]]
name = "anstyle-parse"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140"
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
checksum = "a3a318f1f38d2418400f8209655bfd825785afd25aa30bb7ba6cc792e4596748"
dependencies = [
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.1"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
dependencies = [
"anstyle",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@@ -183,7 +183,7 @@ dependencies = [
"android-tzdata",
"iana-time-zone",
"num-traits",
"windows-targets",
"windows-targets 0.48.5",
]
[[package]]
@@ -237,9 +237,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.4.8"
version = "4.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64"
checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2"
dependencies = [
"clap_builder",
"clap_derive",
@@ -257,9 +257,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.4.8"
version = "4.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc"
checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb"
dependencies = [
"anstream",
"anstyle",
@@ -299,9 +299,9 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "core-foundation-sys"
version = "0.8.4"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "cpufeatures"
@@ -441,12 +441,12 @@ dependencies = [
[[package]]
name = "errno"
version = "0.3.7"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8"
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
dependencies = [
"libc",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@@ -469,10 +469,11 @@ dependencies = [
name = "fast_image_resize"
version = "2.7.3"
dependencies = [
"cfg-if",
"criterion",
"fast_image_resize",
"image",
"itertools 0.11.0",
"itertools 0.12.0",
"libvips",
"nix",
"num-traits",
@@ -515,12 +516,6 @@ dependencies = [
"spin",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "generic-array"
version = "0.14.7"
@@ -554,15 +549,15 @@ dependencies = [
[[package]]
name = "globset"
version = "0.4.13"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d"
checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1"
dependencies = [
"aho-corasick",
"bstr",
"fnv",
"log",
"regex",
"regex-automata",
"regex-syntax",
]
[[package]]
@@ -643,17 +638,16 @@ dependencies = [
[[package]]
name = "ignore"
version = "0.4.20"
version = "0.4.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492"
checksum = "747ad1b4ae841a78e8aba0d63adbfbeaea26b517b63705d47856b73015d27060"
dependencies = [
"crossbeam-deque",
"globset",
"lazy_static",
"log",
"memchr",
"regex",
"regex-automata",
"same-file",
"thread_local",
"walkdir",
"winapi-util",
]
@@ -685,7 +679,7 @@ checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
dependencies = [
"hermit-abi",
"rustix",
"windows-sys",
"windows-sys 0.48.0",
]
[[package]]
@@ -699,9 +693,9 @@ dependencies = [
[[package]]
name = "itertools"
version = "0.11.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0"
dependencies = [
"either",
]
@@ -723,9 +717,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.65"
version = "0.3.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8"
checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca"
dependencies = [
"wasm-bindgen",
]
@@ -766,9 +760,9 @@ dependencies = [
[[package]]
name = "linux-raw-sys"
version = "0.4.11"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829"
checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456"
[[package]]
name = "lock_api"
@@ -994,9 +988,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.69"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
dependencies = [
"unicode-ident",
]
@@ -1100,9 +1094,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "resize"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce43c0220eff4793a20c120ff89ee01499ba3c882957021dcdc12f5e4ca97c8"
checksum = "9b6a672c8cfa0b43a11c629acdbbe4e552a92566c835932cd1b2456e57232de3"
dependencies = [
"rayon",
"rgb",
@@ -1133,15 +1127,15 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.25"
version = "0.38.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e"
checksum = "9470c4bf8246c8daf25f9598dca807fb6510347b1e1cfa55749113850c79d88a"
dependencies = [
"bitflags 2.4.1",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@@ -1331,16 +1325,6 @@ dependencies = [
"syn 2.0.39",
]
[[package]]
name = "thread_local"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "tiff"
version = "0.9.0"
@@ -1460,9 +1444,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.88"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce"
checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
@@ -1470,9 +1454,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.88"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217"
checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826"
dependencies = [
"bumpalo",
"log",
@@ -1485,9 +1469,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.88"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2"
checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -1495,9 +1479,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.88"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907"
checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
dependencies = [
"proc-macro2",
"quote",
@@ -1508,9 +1492,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.88"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b"
checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
[[package]]
name = "weezl"
@@ -1555,7 +1539,7 @@ version = "0.51.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
dependencies = [
"windows-targets",
"windows-targets 0.48.5",
]
[[package]]
@@ -1564,7 +1548,16 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets 0.52.0",
]
[[package]]
@@ -1573,13 +1566,28 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
name = "windows-targets"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
dependencies = [
"windows_aarch64_gnullvm 0.52.0",
"windows_aarch64_msvc 0.52.0",
"windows_i686_gnu 0.52.0",
"windows_i686_msvc 0.52.0",
"windows_x86_64_gnu 0.52.0",
"windows_x86_64_gnullvm 0.52.0",
"windows_x86_64_msvc 0.52.0",
]
[[package]]
@@ -1588,42 +1596,84 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]]
name = "zune-inflate"
version = "0.2.54"
+4 -2
View File
@@ -20,12 +20,14 @@ exclude = ["/data"]
[dependencies]
cfg-if = "1.0.0"
num-traits = "0.2"
thiserror = "1.0"
[features]
for_test = []
only_u8x4 = [] # This can be used to experiment with the crate's code.
[dev-dependencies]
@@ -37,7 +39,7 @@ png = "0.17"
serde = { version = "1.0", features = ["serde_derive"] }
serde_json = "1"
walkdir = "2"
itertools = "0.11"
itertools = "0.12"
criterion = { version = "0.5", default-features = false, features = ["cargo_bench_support"] }
tera = "1"
testing = { path = "testing" }
@@ -110,7 +112,7 @@ opt-level = 3
[profile.release]
opt-level = 3
#incremental = true
lto = true
#lto = true
#codegen-units = 1
strip = true
+2 -2
View File
@@ -239,8 +239,8 @@ fn main() {
let src_image = fr::Image::from_vec_u8(
width,
height,
img.to_rgb8().into_raw(),
fr::PixelType::U8x3,
img.to_rgba8().into_raw(),
fr::PixelType::U8x4,
).unwrap();
resize_image_with_cropping(
src_image.view(),
+10 -19
View File
@@ -1,9 +1,7 @@
use std::num::NonZeroU32;
use fast_image_resize::pixels::*;
use fast_image_resize::Image;
use fast_image_resize::{CpuExtensions, FilterType, PixelType, ResizeAlg, Resizer};
use testing::{cpu_ext_into_str, PixelTestingExt};
use testing::{cpu_ext_into_str, nonzero, PixelTestingExt};
mod utils;
@@ -12,11 +10,7 @@ const NEW_HEIGHT: u32 = 567;
fn native_nearest_u8x4_bench(bench_group: &mut utils::BenchGroup) {
let image = U8x4::load_big_src_image();
let mut res_image = Image::new(
NonZeroU32::new(NEW_WIDTH).unwrap(),
NonZeroU32::new(NEW_HEIGHT).unwrap(),
image.pixel_type(),
);
let mut res_image = Image::new(nonzero(NEW_WIDTH), nonzero(NEW_HEIGHT), image.pixel_type());
let src_image = image.view();
let mut dst_image = res_image.view_mut();
let mut resizer = Resizer::new(ResizeAlg::Nearest);
@@ -32,11 +26,7 @@ fn native_nearest_u8x4_bench(bench_group: &mut utils::BenchGroup) {
fn native_nearest_u8_bench(bench_group: &mut utils::BenchGroup) {
let image = U8::load_big_src_image();
let mut res_image = Image::new(
NonZeroU32::new(NEW_WIDTH).unwrap(),
NonZeroU32::new(NEW_HEIGHT).unwrap(),
image.pixel_type(),
);
let mut res_image = Image::new(nonzero(NEW_WIDTH), nonzero(NEW_HEIGHT), image.pixel_type());
let src_image = image.view();
let mut dst_image = res_image.view_mut();
let mut resizer = Resizer::new(ResizeAlg::Nearest);
@@ -56,11 +46,7 @@ fn downscale_bench(
cpu_extensions: CpuExtensions,
filter_type: FilterType,
) {
let mut res_image = Image::new(
NonZeroU32::new(NEW_WIDTH).unwrap(),
NonZeroU32::new(NEW_HEIGHT).unwrap(),
image.pixel_type(),
);
let mut res_image = Image::new(nonzero(NEW_WIDTH), nonzero(NEW_HEIGHT), image.pixel_type());
let src_image = image.view();
let mut dst_image = res_image.view_mut();
let mut resizer = Resizer::new(ResizeAlg::Convolution(filter_type));
@@ -92,7 +78,7 @@ pub fn resize_bench(bench_group: &mut utils::BenchGroup) {
PixelType::U16x4,
PixelType::I32,
];
let mut cpu_extensions = vec![]; //CpuExtensions::None];
let mut cpu_extensions = vec![CpuExtensions::None];
#[cfg(target_arch = "x86_64")]
{
cpu_extensions.push(CpuExtensions::Sse4_1);
@@ -107,6 +93,10 @@ pub fn resize_bench(bench_group: &mut utils::BenchGroup) {
cpu_extensions.push(CpuExtensions::Simd128);
}
for pixel_type in pixel_types {
#[cfg(feature = "only_u8x4")]
if pixel_type != PixelType::U8x4 {
continue;
}
for &cpu_extension in cpu_extensions.iter() {
let image = match pixel_type {
PixelType::U8 => U8::load_big_src_image(),
@@ -125,6 +115,7 @@ pub fn resize_bench(bench_group: &mut utils::BenchGroup) {
}
native_nearest_u8x4_bench(bench_group);
#[cfg(not(feature = "only_u8x4"))]
native_nearest_u8_bench(bench_group);
}
+7 -3
View File
@@ -6,10 +6,14 @@ use crate::{ImageView, ImageViewMut};
mod common;
pub(crate) mod errors;
mod u16x2;
mod u16x4;
mod u8x2;
mod u8x4;
cfg_if::cfg_if! {
if #[cfg(not(feature = "only_u8x4"))] {
mod u16x2;
mod u16x4;
mod u8x2;
}
}
pub(crate) trait AlphaMulDiv
where
+14 -10
View File
@@ -9,20 +9,24 @@ use crate::{ImageView, ImageViewMut};
#[macro_use]
mod macros;
mod f32x1;
mod filters;
mod i32x1;
mod optimisations;
mod u16x1;
mod u16x2;
mod u16x3;
mod u16x4;
mod u8x1;
mod u8x2;
mod u8x3;
mod u8x4;
mod vertical_u16;
mod vertical_u8;
cfg_if::cfg_if! {
if #[cfg(not(feature = "only_u8x4"))] {
mod u8x1;
mod u8x2;
mod u8x3;
mod u16x1;
mod u16x2;
mod u16x3;
mod u16x4;
mod i32x1;
mod f32x1;
mod vertical_u16;
}
}
pub(crate) trait Convolution
where
+1 -1
View File
@@ -90,7 +90,7 @@ where
let src_rows = src_image.iter_rows(first_y_src);
for (&k, src_row) in ks.iter().zip(src_rows) {
let src_ptr = src_row.as_ptr() as *const u8;
let src_component = unsafe { *src_ptr.add(x_src as usize) };
let src_component = unsafe { *src_ptr.add(x_src) };
ss += src_component as i32 * (k as i32);
}
*dst_component = unsafe { normalizer.clip(ss) };
+36
View File
@@ -50,6 +50,7 @@ impl MulDiv {
src_image: &DynamicImageView,
dst_image: &mut DynamicImageViewMut,
) -> Result<(), MulDivImagesError> {
#[cfg(not(feature = "only_u8x4"))]
match (src_image, dst_image) {
(
DynamicImageView::U8x2(typed_src_image),
@@ -69,6 +70,14 @@ impl MulDiv {
) => multiply_alpha(typed_src_image, typed_dst_image, self.cpu_extensions),
_ => Err(MulDivImagesError::UnsupportedPixelType),
}
#[cfg(feature = "only_u8x4")]
match (src_image, dst_image) {
(
DynamicImageView::U8x4(typed_src_image),
DynamicImageViewMut::U8x4(typed_dst_image),
) => multiply_alpha(typed_src_image, typed_dst_image, self.cpu_extensions),
_ => Err(MulDivImagesError::UnsupportedPixelType),
}
}
/// Multiplies color-channels (RGB or Luma) of image by alpha-channel inplace.
@@ -76,6 +85,7 @@ impl MulDiv {
&self,
image: &mut DynamicImageViewMut,
) -> Result<(), MulDivImageError> {
#[cfg(not(feature = "only_u8x4"))]
match image {
DynamicImageViewMut::U8x2(typed_image) => {
multiply_alpha_inplace(typed_image, self.cpu_extensions);
@@ -95,6 +105,14 @@ impl MulDiv {
}
_ => Err(MulDivImageError::UnsupportedPixelType),
}
#[cfg(feature = "only_u8x4")]
match image {
DynamicImageViewMut::U8x4(typed_image) => {
multiply_alpha_inplace(typed_image, self.cpu_extensions);
Ok(())
}
_ => Err(MulDivImageError::UnsupportedPixelType),
}
}
/// Divides color-channels (RGB or Luma) of source image by alpha-channel and store
@@ -104,6 +122,7 @@ impl MulDiv {
src_image: &DynamicImageView,
dst_image: &mut DynamicImageViewMut,
) -> Result<(), MulDivImagesError> {
#[cfg(not(feature = "only_u8x4"))]
match (src_image, dst_image) {
(
DynamicImageView::U8x2(typed_src_image),
@@ -123,6 +142,14 @@ impl MulDiv {
) => divide_alpha(typed_src_image, typed_dst_image, self.cpu_extensions),
_ => Err(MulDivImagesError::UnsupportedPixelType),
}
#[cfg(feature = "only_u8x4")]
match (src_image, dst_image) {
(
DynamicImageView::U8x4(typed_src_image),
DynamicImageViewMut::U8x4(typed_dst_image),
) => divide_alpha(typed_src_image, typed_dst_image, self.cpu_extensions),
_ => Err(MulDivImagesError::UnsupportedPixelType),
}
}
/// Divides color-channels (RGB or Luma) of image by alpha-channel inplace.
@@ -130,6 +157,7 @@ impl MulDiv {
&self,
image: &mut DynamicImageViewMut,
) -> Result<(), MulDivImageError> {
#[cfg(not(feature = "only_u8x4"))]
match image {
DynamicImageViewMut::U8x2(typed_image) => {
divide_alpha_inplace(typed_image, self.cpu_extensions);
@@ -149,6 +177,14 @@ impl MulDiv {
}
_ => Err(MulDivImageError::UnsupportedPixelType),
}
#[cfg(feature = "only_u8x4")]
match image {
DynamicImageViewMut::U8x4(typed_image) => {
divide_alpha_inplace(typed_image, self.cpu_extensions);
Ok(())
}
_ => Err(MulDivImageError::UnsupportedPixelType),
}
}
}
+10
View File
@@ -126,6 +126,7 @@ impl Resizer {
src_image: &DynamicImageView,
dst_image: &mut DynamicImageViewMut,
) -> Result<(), DifferentTypesOfPixelsError> {
#[cfg(not(feature = "only_u8x4"))]
match (src_image, dst_image) {
(DynamicImageView::U8(src), DynamicImageViewMut::U8(dst)) => {
self.resize_inner(src, dst);
@@ -161,6 +162,15 @@ impl Resizer {
return Err(DifferentTypesOfPixelsError);
}
}
#[cfg(feature = "only_u8x4")]
match (src_image, dst_image) {
(DynamicImageView::U8x4(src), DynamicImageViewMut::U8x4(dst)) => {
self.resize_inner(src, dst);
}
_ => {
return Err(DifferentTypesOfPixelsError);
}
}
Ok(())
}
+515 -498
View File
File diff suppressed because it is too large Load Diff
+8 -8
View File
@@ -60,12 +60,12 @@ fn crop_view_mut() {
let src_image = fr::Image::from_vec_u8(
nonzero(64),
nonzero(32),
vec![255; 64 * 32],
fr::PixelType::U8,
vec![255; 64 * 32 * 4],
fr::PixelType::U8x4,
)
.unwrap();
// Black destination image
let mut dst_image = fr::Image::new(nonzero(64), nonzero(32), fr::PixelType::U8);
let mut dst_image = fr::Image::new(nonzero(64), nonzero(32), fr::PixelType::U8x4);
let mut cropped_dst_view = dst_image
.view_mut()
@@ -84,7 +84,7 @@ fn crop_view_mut() {
.resize(&src_image.view(), &mut cropped_dst_view)
.unwrap();
let row_size: usize = 64;
let row_size: usize = 64 * 4;
let dst_buffer = dst_image.buffer();
let black_block = vec![0u8; 10 * row_size];
@@ -92,10 +92,10 @@ fn crop_view_mut() {
assert_eq!(dst_buffer[0..10 * row_size], black_block);
// Middle rows
let mut middle_row = vec![0u8; 10];
middle_row.extend(vec![255u8; 44]);
middle_row.extend(vec![0u8; 10]);
for row in dst_buffer.chunks_exact(row_size).skip(10).take(12) {
let mut middle_row = vec![0u8; 10 * 4];
middle_row.extend(vec![255u8; 44 * 4]);
middle_row.extend(vec![0u8; 10 * 4]);
for row in dst_buffer.chunks_exact(row_size).skip(10 * 4).take(12 * 4) {
assert_eq!(row, middle_row);
}
+502 -477
View File
File diff suppressed because it is too large Load Diff