Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

photon::transform additions #179

Merged
merged 17 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ Contributors include (be sure to add yourself to the list if you submitted a PR)
* **bboshoven** - [@bboshoven](https://github.com/bboshoven)
* **benliao** - [@benliao](https://github.com/benliao)
* **Fineshop Design** - [@fineshop](https://github.com/fineshop)
* **volbot** - [@volbot](https://github.com/volbot)
* **Future You(?)** - (See Contributing above)

## License
Expand Down
51 changes: 51 additions & 0 deletions crate/examples/rotate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
extern crate image;
extern crate photon_rs;

use instant::Instant;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let file_name = "crate/examples/input_images/daisies_fuji.jpg";
println!("file name = {}", file_name);

// // Open the image
let img = photon_rs::native::open_image(file_name)?;
let start = Instant::now();
// Seam Carver
let (w, h) = (img.get_width(), img.get_height());
println!("original = w: {}, h: {}", w, h);
let angles = vec![
60.0, // 60.0 = q1:60.0
135.0, // 135.0 = q2:45.0
562.5, // 517.5 = q3:22.5
-30.0, // -30.0 = q4:60.0
];
let operations = angles.len();
let mut results = Vec::new();
for i in 0..operations {
let angle = angles[i];
let result = photon_rs::transform::rotate(&img, angles[i]);
println!(
"after rotate({}) = w: {}, h: {}",
angle,
result.get_width(),
result.get_height()
);
results.push(result);
}

// Write all outputs in JPEG format.
for i in (0..operations).rev() {
photon_rs::native::save_image(
results.remove(i),
&format!("output_rotate_{}.jpg", i + 1),
)?;
}
let end = Instant::now();
println!(
"Took {} seconds to rotate {} images.",
(end - start).as_secs_f64(),
operations
);

Ok(())
}
43 changes: 43 additions & 0 deletions crate/examples/shear.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
extern crate image;
extern crate photon_rs;

use instant::Instant;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let file_name = "crate/examples/input_images/daisies_fuji.jpg";
println!("file name = {}", file_name);

// // Open the image
let img = photon_rs::native::open_image(file_name)?;
let start = Instant::now();
// Seam Carver
let (w, h) = (img.get_width(), img.get_height());
println!("original = w: {}, h: {}", w, h);
let shear = 1.;

let res1 = photon_rs::transform::shearx(&img, shear);
println!(
"after shearx({}) = w: {}, h: {}",
shear,
res1.get_width(),
res1.get_height()
);
let res2 = photon_rs::transform::sheary(&img, shear);
println!(
"after sheary({}) = w: {}, h: {}",
shear,
res2.get_width(),
res2.get_height()
);

// Write both outputs in JPEG format.
photon_rs::native::save_image(res1, "output_shearx.jpg")?;
photon_rs::native::save_image(res2, "output_sheary.jpg")?;
let end = Instant::now();
println!(
"Took {} seconds to shear 2 images.",
(end - start).as_secs_f64()
);

Ok(())
}
Loading
Loading