mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-20 03:18:06 +08:00
Rename Raw-rs to Rawkit (#2088)
* Rename within files * Rename in CI * Rename the folder and file names * Rename raw_rs to rawkit * Add example to README * Add initial documentation * Small API changes and extra documentation * Bump versions and stuff * Readme improvements * Merge proc-macro crates into one * Add README to rawkit-proc-macros * Remove keywords and categories * Add licenses to rawkit-proc-macros --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
70
libraries/rawkit/src/postprocessing/transform.rs
Normal file
70
libraries/rawkit/src/postprocessing/transform.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
use crate::{Image, Pixel, Transform};
|
||||
|
||||
impl Image<u16> {
|
||||
pub fn transform_iter(&self) -> (usize, usize, impl Iterator<Item = Pixel> + use<'_>) {
|
||||
let (final_width, final_height) = if self.transform.will_swap_coordinates() {
|
||||
(self.height, self.width)
|
||||
} else {
|
||||
(self.width, self.height)
|
||||
};
|
||||
|
||||
let index_0_0 = inverse_transform_index(self.transform, 0, 0, self.width, self.height);
|
||||
let index_0_1 = inverse_transform_index(self.transform, 0, 1, self.width, self.height);
|
||||
let index_1_0 = inverse_transform_index(self.transform, 1, 0, self.width, self.height);
|
||||
|
||||
let column_step = (index_0_1.0 - index_0_0.0, index_0_1.1 - index_0_0.1);
|
||||
let row_step = (index_1_0.0 - index_0_0.0, index_1_0.1 - index_0_0.1);
|
||||
let mut index = index_0_0;
|
||||
|
||||
let channels = self.channels as usize;
|
||||
|
||||
(
|
||||
final_width,
|
||||
final_height,
|
||||
(0..final_height).flat_map(move |row| {
|
||||
let temp = (0..final_width).map(move |column| {
|
||||
let initial_index = (self.width as i64 * index.0 + index.1) as usize;
|
||||
let pixel = &self.data[channels * initial_index..channels * (initial_index + 1)];
|
||||
index = (index.0 + column_step.0, index.1 + column_step.1);
|
||||
|
||||
Pixel {
|
||||
values: pixel.try_into().unwrap(),
|
||||
row,
|
||||
column,
|
||||
}
|
||||
});
|
||||
|
||||
index = (index.0 + row_step.0, index.1 + row_step.1);
|
||||
|
||||
temp
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inverse_transform_index(transform: Transform, mut row: usize, mut column: usize, width: usize, height: usize) -> (i64, i64) {
|
||||
let value = match transform {
|
||||
Transform::Horizontal => 0,
|
||||
Transform::MirrorHorizontal => 1,
|
||||
Transform::Rotate180 => 3,
|
||||
Transform::MirrorVertical => 2,
|
||||
Transform::MirrorHorizontalRotate270 => 4,
|
||||
Transform::Rotate90 => 6,
|
||||
Transform::MirrorHorizontalRotate90 => 7,
|
||||
Transform::Rotate270 => 5,
|
||||
};
|
||||
|
||||
if value & 4 != 0 {
|
||||
std::mem::swap(&mut row, &mut column)
|
||||
}
|
||||
|
||||
if value & 2 != 0 {
|
||||
row = height - 1 - row;
|
||||
}
|
||||
|
||||
if value & 1 != 0 {
|
||||
column = width - 1 - column;
|
||||
}
|
||||
|
||||
(row as i64, column as i64)
|
||||
}
|
||||
Reference in New Issue
Block a user