vello_cpu/filter/
offset.rs1use vello_common::filter::offset::Offset;
7use vello_common::pixmap::Pixmap;
8
9use super::FilterEffect;
10use super::shift::offset_pixels;
11use crate::filter::context::ScratchBuffer;
12
13impl FilterEffect for Offset {
14 fn execute_lowp(&self, pixmap: &mut Pixmap, _: &mut ScratchBuffer) {
15 offset_pixels(pixmap, self.dx, self.dy);
16 }
17
18 fn execute_highp(&self, pixmap: &mut Pixmap, _: &mut ScratchBuffer) {
19 offset_pixels(pixmap, self.dx, self.dy);
20 }
21}
22
23#[cfg(test)]
24mod tests {
25 use super::Offset;
26 use crate::filter::FilterEffect;
27 use crate::filter::context::ScratchBuffer;
28 use vello_common::peniko::color::PremulRgba8;
29 use vello_common::pixmap::Pixmap;
30
31 #[test]
32 fn offset_moves_pixels_and_clears_uncovered_area() {
33 let mut filter_scratch = ScratchBuffer::new();
34 let mut pixmap = Pixmap::new(4, 3);
35 pixmap.set_pixel(1, 1, PremulRgba8::from_u32(0xff_00_00_ff)); Offset::new(2.0, -1.0).execute_lowp(&mut pixmap, &mut filter_scratch);
38
39 assert_eq!(pixmap.sample(3, 0), PremulRgba8::from_u32(0xff_00_00_ff));
41 assert_eq!(pixmap.sample(1, 1), PremulRgba8::from_u32(0));
43 }
44}