Skip to content

Commit 2aeb410

Browse files
committed
fix & run rustfmt, fix clippy warnings, fix examples, remove travis.yml & ci for wasm32 check
1 parent 70e30d8 commit 2aeb410

22 files changed

+185
-109
lines changed

.github/workflows/ci.yml

+18-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
profile: minimal
4444
toolchain: stable
4545
override: true
46-
- run: rustup component add rustfmt
46+
components: rustfmt
4747
- uses: actions-rs/cargo@v1
4848
with:
4949
command: fmt
@@ -59,8 +59,23 @@ jobs:
5959
profile: minimal
6060
toolchain: stable
6161
override: true
62-
- run: rustup component add clippy
62+
components: clippy
6363
- uses: actions-rs/cargo@v1
6464
with:
6565
command: clippy
66-
args: -- -D warnings
66+
args: --all-features -- -D warnings
67+
wasm32:
68+
name: Wasm32 check
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/checkout@v2
72+
- uses: actions-rs/toolchain@v1
73+
with:
74+
profile: minimal
75+
target: wasm32-unknown-unknown
76+
toolchain: stable
77+
override: true
78+
- uses: actions-rs/cargo@v1
79+
with:
80+
command: check
81+
args: --all-features --benches --bins --examples --tests

.gitignore

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
dist
2-
crate/bin
3-
crate/pkg
4-
crate/target
5-
crate/wasm-pack.log
6-
crate/Cargo.lock
2+
bin
3+
pkg
4+
target
5+
wasm-pack.log
6+
Cargo.lock
77
webpack_demo/node_modules
88
webpack_demo/dist
99
webpack_demo/package-lock.json
1010
react_app_demo/node_modules
1111
photon-docs/site
1212
output*.jpg
13-
output*.png
13+
output*.png

crate/.rustfmt.toml .rustfmt.toml

File renamed without changes.

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
112112
##### See More Examples
113113
[For more examples, check out the guide on how to get started with Photon natively.](https://silvia-odwyer.github.io/photon/guide/using-photon-natively/)
114114

115+
### Building WebAssembly package
116+
117+
In order to build the WebAssembly package you will need `wasm-pack`. Check https://rustwasm.github.io/wasm-pack/installer/ on how to install it. Then you can run the command:
118+
119+
120+
```bash
121+
wasm-pack build ./crate
122+
```
123+
115124
## Get Started With WebAssembly
116125
### Using a Bundler?
117126
#### Installing Photon
@@ -155,7 +164,6 @@ git clone https://github.com/silvia-odwyer/photon
155164

156165
Run the binary, which will perform an image processing function on an image:
157166
```sh
158-
cd crate
159167
cargo run --release
160168
```
161169

crate/.travis.yml

-11
This file was deleted.

crate/benches/photon_benchmark.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
2-
use photon_rs::channels::alter_red_channel;
3-
use photon_rs::conv::gaussian_blur;
1+
use criterion::{criterion_group, criterion_main, Criterion};
42
use photon_rs::native::{open_image, save_image};
53
use photon_rs::transform::{resize, SamplingFilter};
6-
use photon_rs::PhotonImage;
74
use std::time::Duration;
85

9-
fn gaussian_blur_3x3(img: &mut PhotonImage) {
10-
gaussian_blur(img, 3);
11-
}
12-
136
fn criterion_benchmark(c: &mut Criterion) {
147
c.bench_function("invert_image", |b| b.iter(|| invert_image()));
158

@@ -20,7 +13,8 @@ fn criterion_benchmark(c: &mut Criterion) {
2013

2114
fn invert_image() {
2215
// Open the image (a PhotonImage is returned)
23-
let mut img = open_image("examples/input_images/underground.jpg").expect("File should open");
16+
let mut img =
17+
open_image("examples/input_images/underground.jpg").expect("File should open");
2418

2519
// Invert the image
2620
photon_rs::channels::invert(&mut img);
@@ -32,7 +26,8 @@ fn invert_image() {
3226
}
3327

3428
fn resize_png() {
35-
let mut img = open_image("examples/input_images/underground.png").expect("File should open");
29+
let mut img =
30+
open_image("examples/input_images/underground.png").expect("File should open");
3631

3732
let resized_img = resize(&mut img, 800, 600, SamplingFilter::Lanczos3);
3833

@@ -43,7 +38,8 @@ fn resize_png() {
4338

4439
fn resize_jpg() {
4540
// Open the image (a PhotonImage is returned)
46-
let mut img = open_image("examples/input_images/underground.jpg").expect("File should open");
41+
let mut img =
42+
open_image("examples/input_images/underground.jpg").expect("File should open");
4743

4844
let resized_img = resize(&mut img, 800, 600, SamplingFilter::Lanczos3);
4945

crate/examples/README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## Examples
22
Examples for running Photon natively.
33

4-
Note: If you're here to see WebAssembly in action, this is the wrong path, turn back.
5-
To see WebAssembly in action, clone this repo and run `npm start` after `cd`ing into photon.
4+
Note: If you're here to see WebAssembly in action, this is the wrong path, turn back.
5+
To see WebAssembly in action, clone this repo and run `npm start` after `cd`ing into photon.
66
More details can be found in the main repo README.
77

88
### Running These Examples
@@ -14,8 +14,7 @@ git clone https://github.com/silvia-odwyer/photon
1414
Several examples are included, for this demo, we'll run the Rust file called `example.rs`:
1515

1616
```sh
17-
cd crate
18-
cargo run --example example --release
17+
cargo run --example example --release
1918
```
2019

2120
Make sure the `--release` flag is added.
@@ -28,5 +27,5 @@ To change the images being inputted, add your image to `input_images` and change
2827
To run the example which adds text to an image:
2928

3029
```sh
31-
cargo run --example add_text
32-
```
30+
cargo run --example add_text
31+
```

crate/examples/add_text.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
77
// Replace the variable file_name with whatever image you would like to apply filters to
88
// Ensure it is in the example_output directory, which can be found one sub-dir inside the photon dir.
99
// However the image referenced below, along with sample images, have been included in the dir.
10-
let file_name = "examples/input_images/daisies_fuji.jpg";
10+
let file_name = "crate/examples/input_images/daisies_fuji.jpg";
1111

1212
// Open the image
1313
let mut img = photon::native::open_image(file_name)?;

crate/examples/example.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
77
// Replace the variable file_name with whatever image you would like to apply filters to
88
// Ensure it is in the example_output directory, which can be found one sub-dir inside the photon dir.
99
// However the image referenced below, along with sample images, have been included in the dir.
10-
let file_name = "examples/input_images/underground.jpg";
10+
let file_name = "crate/examples/input_images/underground.jpg";
1111

1212
// Open the image
1313
let effects: [&str; 5] =
@@ -21,10 +21,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2121
photon::colour_spaces::hsl(&mut img, effect, 0.2_f32);
2222

2323
// Write the contents of this image in JPG format.
24-
photon::native::save_image(
25-
img,
26-
&format!("output_{}.jpg", effect)[..],
27-
)?;
24+
photon::native::save_image(img, &format!("output_{}.jpg", effect)[..])?;
2825

2926
let end = Instant::now();
3027
println!(

crate/examples/seam_carver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extern crate photon_rs;
33
extern crate time;
44

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

99
// // Open the image

crate/src/channels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::helpers;
99
use crate::{PhotonImage, Rgb};
1010
extern crate palette;
1111
use crate::channels::palette::Hue;
12+
use crate::iter::ImageIterator;
1213
use palette::{Lab, Lch, Pixel, Saturate, Shade, Srgb, Srgba};
1314
use wasm_bindgen::prelude::*;
14-
use crate::iter::ImageIterator;
1515

1616
/// Alter a select channel by incrementing or decrementing its value by a constant.
1717
///

crate/src/colour_spaces.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::{helpers, PhotonImage, Rgb};
66
use image::GenericImageView;
77
use palette::{Hsl, Hsv, Hue, Lch, Pixel, Saturate, Shade, Srgba};
88
extern crate wasm_bindgen;
9-
use wasm_bindgen::prelude::*;
109
use crate::iter::ImageIterator;
10+
use wasm_bindgen::prelude::*;
1111

1212
/// Apply gamma correction.
1313
// #[wasm_bindgen]

0 commit comments

Comments
 (0)