From fadb53f075e63a49de7c4d4c58ff07bfbfe6f478 Mon Sep 17 00:00:00 2001 From: Surma Date: Fri, 15 Feb 2019 19:25:32 +0100 Subject: [PATCH] Readd rotation cases --- codecs/rotate/rotate.rs | 30 +++++++++++++++++++++--------- codecs/rotate/rotate.wasm | Bin 353 -> 462 bytes 2 files changed, 21 insertions(+), 9 deletions(-) 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 92547dc9390d27ade493b2173edabf851701bb92..d7514e8e5e89a47fedca3eee56b49c0ca385168f 100755 GIT binary patch literal 462 zcmY+AO-{ow5QXQ*Nz){5x`oxaD^@I7*NYY*!5Pw^MnV>)RhtbGk|PelX*d8kU`J4GQ`_w7$L7#7=5@Vpx~6Vl)=cSs+cjOQoFlP1zX@#=6nLJor_N`=8JhnsA^!vS z7F3ULYe~?@FiRFz?do-@9;l48i@{}LB+)*&vCmxY!4;CYQq{5!lx$%^n~CJkNa-pW zJL0*p6fy}9HWjnb!cq-;8uldSir|Joj5nG~D#4%^Nk+kuOgx6!M6x>zMWIt5C^45b zxLnF1Q7L2prg6j$PAiEzOHwcCTlgGDvkoy7$U_1xLT4%sR1NV5KjZj>t8|F}#O3L8 RK4^JaOyB#y2Ph0^`2`*^NC*G` delta 247 zcmW+wIc~#15Su-0tvuS*K7pgkFL13bT)4sM?PbJ4Z726-jIn*$7EC=kA-s|^*YADbi8zwMKVn@ZoB#j-