Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions crates/resvg/src/filter/composite.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// Copyright 2020 the Resvg Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use super::{ImageRef, ImageRefMut, f32_bound};
use super::{Error, ImageRef, ImageRefMut, f32_bound};
use rgb::RGBA8;
use usvg::ApproxZeroUlps;

/// Performs an arithmetic composition.
///
/// - `src1` and `src2` image pixels should have a **premultiplied alpha**.
/// - `dest` image pixels will have a **premultiplied alpha**.
///
/// # Panics
///
/// When `src1`, `src2` and `dest` have different sizes.
pub fn arithmetic(
k1: f32,
k2: f32,
Expand All @@ -21,9 +17,14 @@ pub fn arithmetic(
src1: ImageRef,
src2: ImageRef,
dest: ImageRefMut,
) {
assert!(src1.width == src2.width && src1.width == dest.width);
assert!(src1.height == src2.height && src1.height == dest.height);
) -> Result<(), Error> {
if src1.width != src2.width || src1.width != dest.width {
return Err(Error::InvalidRegion);
}

if src1.height != src2.height || src1.height != dest.height {
return Err(Error::InvalidRegion);
}

let calc = |i1, i2, max| {
let i1 = i1 as f32 / 255.0;
Expand All @@ -49,4 +50,5 @@ pub fn arithmetic(

i += 1;
}
Ok(())
}
2 changes: 1 addition & 1 deletion crates/resvg/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ fn apply_composite(
pixmap1.as_image_ref(),
pixmap2.as_image_ref(),
pixmap.as_image_ref_mut(),
);
)?;

return Ok(Image::from_image(pixmap, cs));
}
Expand Down