(data: Vec<u8>, cur_width: i32, height: i32, width: i32)
| 120 | } |
| 121 | |
| 122 | pub fn get_cropped_data(data: Vec<u8>, cur_width: i32, height: i32, width: i32) -> Vec<u8> { |
| 123 | if data.len() as i32 != height * cur_width * 4 { |
| 124 | data |
| 125 | } else { |
| 126 | let mut cropped_data: Vec<u8> = vec![0; (4 * height * width).try_into().unwrap()]; |
| 127 | let mut cropped_data_index = 0; |
| 128 | |
| 129 | for (i, item) in data.iter().enumerate() { |
| 130 | let x = i as i32 % (cur_width * 4); |
| 131 | if x < (width * 4) { |
| 132 | cropped_data[cropped_data_index] = *item; |
| 133 | cropped_data_index += 1; |
| 134 | } |
| 135 | } |
| 136 | cropped_data |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | #[cfg(test)] |
| 141 | mod tests { |
no outgoing calls
no test coverage detected