diff --git a/jxl/src/image.rs b/jxl/src/image.rs index 4f6ff84..3e2fcb1 100644 --- a/jxl/src/image.rs +++ b/jxl/src/image.rs @@ -184,6 +184,13 @@ impl Image { Ok(img) } + #[cfg(test)] + pub fn new_constant(size: (usize, usize), val: T) -> Result> { + let mut img = Self::new(size)?; + img.data.iter_mut().for_each(|x| *x = val); + Ok(img) + } + pub fn size(&self) -> (usize, usize) { self.size } diff --git a/jxl/src/render/stages/upsample.rs b/jxl/src/render/stages/upsample.rs index 8984e74..2063fdc 100644 --- a/jxl/src/render/stages/upsample.rs +++ b/jxl/src/render/stages/upsample.rs @@ -98,6 +98,24 @@ mod test { ) } + #[test] + fn upsample2x_constant() -> Result<()> { + let ups_factors = CustomTransformData::default(); + let image_size = (238, 412); + let input_size = (image_size.0 / 2, image_size.1 / 2); + let val = 0.777f32; + let input = Image::new_constant(input_size, val)?; + let stage = Upsample2x::new(&ups_factors, 0); + let output: Vec> = + make_and_run_simple_pipeline(stage, &[input], image_size, 123)?.1; + for x in 0..image_size.0 { + for y in 0..image_size.1 { + assert!((output[0].as_rect().row(y)[x] - val).abs() <= 0.0000001); + } + } + Ok(()) + } + #[test] fn test_upsample2() -> Result<()> { let mut input = Image::new((7, 7))?;