1pub fn flip_vertical(memory: &[u8], size: [u32; 2], channels: u8) -> Vec<u8> {
5 let (width, height, channels) = (size[0] as usize, size[1] as usize,
6 channels as usize);
7 let mut res = vec![0; width * height];
8 let stride = width * channels;
9 for y in 0..height {
10 for x in 0..width {
11 for c in 0..channels {
12 res[(c + x * channels + (height - 1 - y) * stride) as usize] =
13 memory[(c + x * channels + y * stride) as usize];
14 }
15 }
16 }
17 res
18}
19
20pub fn alpha_to_rgba8(memory: &[u8], size: [u32; 2]) -> Vec<u8> {
22 let (width, height) = (size[0] as usize, size[1] as usize);
23 let capacity = width * height * 4;
24 let stride = width;
25 let mut res = Vec::with_capacity(capacity);
26 for y in 0..height {
27 for x in 0..width {
28 res.push(255);
29 res.push(255);
30 res.push(255);
31 res.push(memory[x + y * stride]);
32 }
33 }
34 res
35}