mirror of
https://github.com/Cykooz/fast_image_resize.git
synced 2026-10-08 01:11:09 +00:00
- Added checking images size for equal to zero in MulDiv
This commit is contained in:
Generated
+47
-40
@@ -46,47 +46,48 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299"
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.13"
|
||||
version = "0.6.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
|
||||
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.6"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
|
||||
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
|
||||
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
|
||||
checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.2"
|
||||
version = "3.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
|
||||
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys",
|
||||
@@ -231,9 +232,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.95"
|
||||
version = "1.0.96"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b"
|
||||
checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
"libc",
|
||||
@@ -381,9 +382,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
@@ -596,9 +597,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.28"
|
||||
version = "1.0.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e"
|
||||
checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
@@ -680,9 +681,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.3"
|
||||
version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
@@ -821,6 +822,12 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
@@ -883,9 +890,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.153"
|
||||
version = "0.2.154"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||
checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
|
||||
|
||||
[[package]]
|
||||
name = "libfuzzer-sys"
|
||||
@@ -922,9 +929,9 @@ checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.11"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
|
||||
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"scopeguard",
|
||||
@@ -1088,9 +1095,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
|
||||
|
||||
[[package]]
|
||||
name = "parse-zoneinfo"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41"
|
||||
checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24"
|
||||
dependencies = [
|
||||
"regex",
|
||||
]
|
||||
@@ -1109,9 +1116,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||
|
||||
[[package]]
|
||||
name = "pest"
|
||||
version = "2.7.9"
|
||||
version = "2.7.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "311fb059dee1a7b802f036316d790138c613a4e8b180c822e3925a662e9f0c95"
|
||||
checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"thiserror",
|
||||
@@ -1120,9 +1127,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pest_derive"
|
||||
version = "2.7.9"
|
||||
version = "2.7.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f73541b156d32197eecda1a4014d7f868fd2bcb3c550d5386087cfba442bf69c"
|
||||
checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_generator",
|
||||
@@ -1130,9 +1137,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pest_generator"
|
||||
version = "2.7.9"
|
||||
version = "2.7.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c35eeed0a3fab112f75165fdc026b3913f4183133f19b49be773ac9ea966e8bd"
|
||||
checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_meta",
|
||||
@@ -1143,9 +1150,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pest_meta"
|
||||
version = "2.7.9"
|
||||
version = "2.7.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2adbf29bb9776f28caece835398781ab24435585fe0d4dc1374a61db5accedca"
|
||||
checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"pest",
|
||||
@@ -1452,18 +1459,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.198"
|
||||
version = "1.0.200"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
|
||||
checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.198"
|
||||
version = "1.0.200"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
|
||||
checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -1874,9 +1881,9 @@ checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.7"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "134306a13c5647ad6453e8deaec55d3a44d6021970129e6188735e74bf546697"
|
||||
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
@@ -1965,9 +1972,9 @@ checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.6.6"
|
||||
version = "0.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352"
|
||||
checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
+2
-2
@@ -101,8 +101,8 @@ impl<'a, T: ImageView> CroppedSrcImageView<'a, T> {
|
||||
}
|
||||
|
||||
pub fn cropped(image_view: &'a T, crop_box: CropBox) -> Result<Self, CropBoxError> {
|
||||
if crop_box.width <= 0. || crop_box.height <= 0. {
|
||||
return Err(CropBoxError::WidthOrHeightLessOrEqualToZero);
|
||||
if crop_box.width < 0. || crop_box.height < 0. {
|
||||
return Err(CropBoxError::WidthOrHeightLessThanZero);
|
||||
}
|
||||
|
||||
let img_width = image_view.width() as _;
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ pub enum CropBoxError {
|
||||
PositionIsOutOfImageBoundaries,
|
||||
#[error("Size of the crop box is out of the image boundaries")]
|
||||
SizeIsOutOfImageBoundaries,
|
||||
#[error("Width or height of the crop box is less or equal to zero")]
|
||||
WidthOrHeightLessOrEqualToZero,
|
||||
#[error("Width or height of the crop box is less than zero")]
|
||||
WidthOrHeightLessThanZero,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
||||
+21
-7
@@ -12,7 +12,6 @@ use crate::{ImageError, ImageView, MulDivImagesError, PixelTrait, PixelType};
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::num::NonZeroU32;
|
||||
/// use fast_image_resize::pixels::PixelType;
|
||||
/// use fast_image_resize::images::Image;
|
||||
/// use fast_image_resize::MulDiv;
|
||||
@@ -22,7 +21,7 @@ use crate::{ImageError, ImageView, MulDivImagesError, PixelTrait, PixelType};
|
||||
/// let src_image = Image::new(width, height, PixelType::U8x4);
|
||||
/// let mut dst_image = Image::new(width, height, PixelType::U8x4);
|
||||
///
|
||||
/// let mul_div = MulDiv::default();
|
||||
/// let mul_div = MulDiv::new();
|
||||
/// mul_div.multiply_alpha(&src_image, &mut dst_image).unwrap();
|
||||
/// ```
|
||||
#[derive(Default, Debug, Clone)]
|
||||
@@ -31,6 +30,10 @@ pub struct MulDiv {
|
||||
}
|
||||
|
||||
impl MulDiv {
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn cpu_extensions(&self) -> CpuExtensions {
|
||||
self.cpu_extensions
|
||||
}
|
||||
@@ -97,8 +100,9 @@ impl MulDiv {
|
||||
if src_view.width() != dst_view.width() || src_view.height() != dst_view.height() {
|
||||
return Err(MulDivImagesError::SizeIsDifferent);
|
||||
}
|
||||
|
||||
P::multiply_alpha(src_view, dst_view, self.cpu_extensions)?;
|
||||
if src_view.width() > 0 && src_view.height() > 0 {
|
||||
P::multiply_alpha(src_view, dst_view, self.cpu_extensions)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -140,7 +144,11 @@ impl MulDiv {
|
||||
&self,
|
||||
img_view: &mut impl ImageViewMut<Pixel = P>,
|
||||
) -> Result<(), ImageError> {
|
||||
P::multiply_alpha_inplace(img_view, self.cpu_extensions)
|
||||
if img_view.width() > 0 && img_view.height() > 0 {
|
||||
P::multiply_alpha_inplace(img_view, self.cpu_extensions)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Divides color-channels (RGB or Luma) of source image by alpha-channel and store
|
||||
@@ -198,7 +206,9 @@ impl MulDiv {
|
||||
if src_view.width() != dst_view.width() || src_view.height() != dst_view.height() {
|
||||
return Err(MulDivImagesError::SizeIsDifferent);
|
||||
}
|
||||
P::divide_alpha(src_view, dst_view, self.cpu_extensions)?;
|
||||
if src_view.width() > 0 && src_view.height() > 0 {
|
||||
P::divide_alpha(src_view, dst_view, self.cpu_extensions)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -240,7 +250,11 @@ impl MulDiv {
|
||||
&self,
|
||||
img_view: &mut impl ImageViewMut<Pixel = P>,
|
||||
) -> Result<(), ImageError> {
|
||||
P::divide_alpha_inplace(img_view, self.cpu_extensions)
|
||||
if img_view.width() > 0 && img_view.height() > 0 {
|
||||
P::divide_alpha_inplace(img_view, self.cpu_extensions)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_supported(&self, pixel_type: PixelType) -> bool {
|
||||
|
||||
+11
-1
@@ -214,10 +214,20 @@ impl Resizer {
|
||||
};
|
||||
let cropped_src_view = CroppedSrcImageView::cropped(src_view, crop_box)?;
|
||||
|
||||
if crop_box.width == 0.
|
||||
|| crop_box.height == 0.
|
||||
|| dst_view.width() == 0
|
||||
|| dst_view.height() == 0
|
||||
{
|
||||
// Do nothing if any size of source or destination image is equal to zero.
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if copy_image(&cropped_src_view, dst_view).is_ok() {
|
||||
// If `copy_image()` returns `Ok` it means that
|
||||
// the size of the destination image is equal to
|
||||
// the size of the cropped source image.
|
||||
// the size of the cropped source image and
|
||||
// the copy operation has success.
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
@@ -880,12 +880,12 @@ mod u8x4 {
|
||||
))
|
||||
);
|
||||
}
|
||||
for (width, height) in [(0., 1.), (1., 0.), (-1., 1.), (1., -1.)] {
|
||||
for (width, height) in [(-1., 1.), (1., -1.)] {
|
||||
options = options.crop(0., 0., width, height);
|
||||
assert_eq!(
|
||||
resizer.resize(&src_image, &mut dst_image, &options),
|
||||
Err(ResizeError::SrcCroppingError(
|
||||
CropBoxError::WidthOrHeightLessOrEqualToZero
|
||||
CropBoxError::WidthOrHeightLessThanZero
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user