Skip to content

Commit 56b7d38

Browse files
Merge pull request silvia-odwyer#179 from volbot/master
photon::transform additions
2 parents 43dfcf5 + e17a0f2 commit 56b7d38

File tree

4 files changed

+240
-104
lines changed

4 files changed

+240
-104
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ Contributors include (be sure to add yourself to the list if you submitted a PR)
240240
* **bboshoven** - [@bboshoven](https://github.com/bboshoven)
241241
* **benliao** - [@benliao](https://github.com/benliao)
242242
* **Fineshop Design** - [@fineshop](https://github.com/fineshop)
243+
* **volbot** - [@volbot](https://github.com/volbot)
243244
* **Future You(?)** - (See Contributing above)
244245

245246
## License

crate/examples/rotate.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
extern crate image;
2+
extern crate photon_rs;
3+
4+
use instant::Instant;
5+
6+
fn main() -> Result<(), Box<dyn std::error::Error>> {
7+
let file_name = "crate/examples/input_images/daisies_fuji.jpg";
8+
println!("file name = {}", file_name);
9+
10+
// // Open the image
11+
let img = photon_rs::native::open_image(file_name)?;
12+
let start = Instant::now();
13+
// Seam Carver
14+
let (w, h) = (img.get_width(), img.get_height());
15+
println!("original = w: {}, h: {}", w, h);
16+
let angles = vec![
17+
60.0, // 60.0 = q1:60.0
18+
135.0, // 135.0 = q2:45.0
19+
562.5, // 517.5 = q3:22.5
20+
-30.0, // -30.0 = q4:60.0
21+
];
22+
let operations = angles.len();
23+
let mut results = Vec::new();
24+
for i in 0..operations {
25+
let angle = angles[i];
26+
let result = photon_rs::transform::rotate(&img, angles[i]);
27+
println!(
28+
"after rotate({}) = w: {}, h: {}",
29+
angle,
30+
result.get_width(),
31+
result.get_height()
32+
);
33+
results.push(result);
34+
}
35+
36+
// Write all outputs in JPEG format.
37+
for i in (0..operations).rev() {
38+
photon_rs::native::save_image(
39+
results.remove(i),
40+
&format!("output_rotate_{}.jpg", i + 1),
41+
)?;
42+
}
43+
let end = Instant::now();
44+
println!(
45+
"Took {} seconds to rotate {} images.",
46+
(end - start).as_secs_f64(),
47+
operations
48+
);
49+
50+
Ok(())
51+
}

crate/examples/shear.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
extern crate image;
2+
extern crate photon_rs;
3+
4+
use instant::Instant;
5+
6+
fn main() -> Result<(), Box<dyn std::error::Error>> {
7+
let file_name = "crate/examples/input_images/daisies_fuji.jpg";
8+
println!("file name = {}", file_name);
9+
10+
// // Open the image
11+
let img = photon_rs::native::open_image(file_name)?;
12+
let start = Instant::now();
13+
// Seam Carver
14+
let (w, h) = (img.get_width(), img.get_height());
15+
println!("original = w: {}, h: {}", w, h);
16+
let shear = 1.;
17+
18+
let res1 = photon_rs::transform::shearx(&img, shear);
19+
println!(
20+
"after shearx({}) = w: {}, h: {}",
21+
shear,
22+
res1.get_width(),
23+
res1.get_height()
24+
);
25+
let res2 = photon_rs::transform::sheary(&img, shear);
26+
println!(
27+
"after sheary({}) = w: {}, h: {}",
28+
shear,
29+
res2.get_width(),
30+
res2.get_height()
31+
);
32+
33+
// Write both outputs in JPEG format.
34+
photon_rs::native::save_image(res1, "output_shearx.jpg")?;
35+
photon_rs::native::save_image(res2, "output_sheary.jpg")?;
36+
let end = Instant::now();
37+
println!(
38+
"Took {} seconds to shear 2 images.",
39+
(end - start).as_secs_f64()
40+
);
41+
42+
Ok(())
43+
}

0 commit comments

Comments
 (0)