diff --git a/codecs/rotate/rotate.rs b/codecs/rotate/rotate.rs index f17bbcc2..d1b19f01 100644 --- a/codecs/rotate/rotate.rs +++ b/codecs/rotate/rotate.rs @@ -23,7 +23,7 @@ impl HardUnwrap for Option { } #[no_mangle] -fn rotate(width: usize, height: usize, _rotate: usize) { +fn rotate(width: usize, height: usize, rotate: usize) { let num_pixels = width * height; let in_b: &mut [u32]; let out_b: &mut [u32]; @@ -32,14 +32,26 @@ fn rotate(width: usize, height: usize, _rotate: usize) { out_b = from_raw_parts_mut::((num_pixels * 4 + 8) as *mut u32, num_pixels); } - let new_width = height; - let _new_height = width; - for y in 0..height { - for x in 0..width { - let new_x = (new_width - 1) - y; - let new_y = x; - *out_b.get_mut(new_y * new_width + new_x).unwrap_hard() = - *in_b.get(y * width + x).unwrap_hard(); + match rotate { + 0 => { + for i in 0..num_pixels { + *out_b.get_mut(i).unwrap_hard() = *in_b.get(i).unwrap_hard(); + } } + 90 => { + let new_width = height; + let _new_height = width; + for y in 0..height { + for x in 0..width { + let new_x = (new_width - 1) - y; + let new_y = x; + *out_b.get_mut(new_y * new_width + new_x).unwrap_hard() = + *in_b.get(y * width + x).unwrap_hard(); + } + } + } + 180 => std::process::abort(), + 270 => std::process::abort(), + _ => std::process::abort(), } } diff --git a/codecs/rotate/rotate.wasm b/codecs/rotate/rotate.wasm index 92547dc9..d7514e8e 100755 Binary files a/codecs/rotate/rotate.wasm and b/codecs/rotate/rotate.wasm differ