MCPcopy Create free account
hub / github.com/GraphiteEditor/Graphite / orientation_iter

Method orientation_iter

libraries/rawkit/src/postprocessing/transform.rs:4–42  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

2
3impl Image<u16> {
4 pub fn orientation_iter(&self) -> (usize, usize, impl Iterator<Item = Pixel> + use<'_>) {
5 let (final_width, final_height) = if self.orientation.will_swap_coordinates() {
6 (self.height, self.width)
7 } else {
8 (self.width, self.height)
9 };
10
11 let index_0_0 = inverse_orientation_index(self.orientation, 0, 0, self.width, self.height);
12 let index_0_1 = inverse_orientation_index(self.orientation, 0, 1, self.width, self.height);
13 let index_1_0 = inverse_orientation_index(self.orientation, 1, 0, self.width, self.height);
14
15 let column_step = (index_0_1.0 - index_0_0.0, index_0_1.1 - index_0_0.1);
16 let row_step = (index_1_0.0 - index_0_0.0, index_1_0.1 - index_0_0.1);
17 let mut index = index_0_0;
18
19 let channels = self.channels as usize;
20
21 (
22 final_width,
23 final_height,
24 (0..final_height).flat_map(move |row| {
25 let temp = (0..final_width).map(move |column| {
26 let initial_index = (self.width as i64 * index.0 + index.1) as usize;
27 let pixel = &self.data[channels * initial_index..channels * (initial_index + 1)];
28 index = (index.0 + column_step.0, index.1 + column_step.1);
29
30 Pixel {
31 values: pixel.try_into().unwrap(),
32 row,
33 column,
34 }
35 });
36
37 index = (index.0 + row_step.0, index.1 + row_step.1);
38
39 temp
40 }),
41 )
42 }
43}
44
45pub fn inverse_orientation_index(orientation: OrientationValue, mut row: usize, mut column: usize, width: usize, height: usize) -> (i64, i64) {

Callers 1

transform_and_applyMethod · 0.80

Calls 2

will_swap_coordinatesMethod · 0.80

Tested by

no test coverage detected