Skip to content
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
7 changes: 3 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ harness = false

[dev-dependencies]
criterion = "0.3.4"
assert_cmd = "2.0.0"
assert_cmd = "2.1.1"
assert_fs = "1.0.1"
predicates = "2.0.1"
image = { version = "0.25.2", default-features = true }
Expand Down
4 changes: 2 additions & 2 deletions benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{Criterion, criterion_group, criterion_main};
use dify::diff;
use image::{io::Reader as ImageReader, RgbaImage};
use image::{RgbaImage, io::Reader as ImageReader};

fn get_image(path: &str) -> RgbaImage {
ImageReader::open(path)
Expand Down
26 changes: 15 additions & 11 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Context, Result};
use anyhow::{Context, Result, anyhow};
use colored::*;
use getopts::{Matches, Options};
use std::collections::HashSet;
Expand Down Expand Up @@ -119,11 +119,13 @@ impl Cli {
Some(value) => match &value.to_lowercase()[..] {
"left" => Ok(Some(OutputImageBase::LeftImage)),
"right" => Ok(Some(OutputImageBase::RightImage)),
unsupported => Err(anyhow!(format!(
"-c/--copy-image \"{}\" is not supported, possible values: left, right",
unsupported.magenta()
)
.red())),
unsupported => Err(anyhow!(
format!(
"-c/--copy-image \"{}\" is not supported, possible values: left, right",
unsupported.magenta()
)
.red()
)),
},
None => Ok(Some(OutputImageBase::LeftImage)),
}
Expand Down Expand Up @@ -163,11 +165,13 @@ impl Cli {
if (0.0..=1.0).contains(&n) {
Ok(Some(n))
} else {
Err(anyhow!(format!(
"the value of {} should be in range 0 to 1",
format!("-a/--alpha {s}").magenta()
)
.red()))
Err(anyhow!(
format!(
"the value of {} should be in range 0 to 1",
format!("-a/--alpha {s}").magenta()
)
.red()
))
}
}),
None => Ok(Some(0.1)),
Expand Down
16 changes: 9 additions & 7 deletions src/diff.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{antialiased, cli, yiq::Yiq};
use anyhow::{anyhow, Context, Result};
use anyhow::{Context, Result, anyhow};
use colored::*;
use image::{GenericImageView, ImageBuffer, ImageFormat, ImageReader, Pixel, Rgba, RgbaImage};
use std::collections::HashSet;
Expand Down Expand Up @@ -136,12 +136,14 @@ pub fn run(params: &RunParams) -> Result<Option<i32>> {
let right_dimensions = right_image.dimensions();

if !params.do_not_check_dimensions && left_dimensions != right_dimensions {
return Err(anyhow!(format!(
"dimensions of the left and right image are different, left: {}, right: {}",
format!("{}x{}", left_dimensions.0, left_dimensions.1).magenta(),
format!("{}x{}", right_dimensions.0, right_dimensions.1).magenta(),
)
.red()));
return Err(anyhow!(
format!(
"dimensions of the left and right image are different, left: {}, right: {}",
format!("{}x{}", left_dimensions.0, left_dimensions.1).magenta(),
format!("{}x{}", right_dimensions.0, right_dimensions.1).magenta(),
)
.red()
));
};

let threshold = MAX_YIQ_POSSIBLE_DELTA * params.threshold * params.threshold;
Expand Down
6 changes: 1 addition & 5 deletions src/yiq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ impl Yiq {
let delta_q = self.q - other.q;
let delta = 0.5053 * delta_y.powi(2) + 0.299 * delta_i.powi(2) + 0.195_7 * delta_q.powi(2);

if self.y > other.y {
-delta
} else {
delta
}
if self.y > other.y { -delta } else { delta }
}
}

Expand Down
24 changes: 12 additions & 12 deletions tests/e2e.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use assert_cmd::Command;
use assert_cmd::{Command, cargo_bin};
use assert_fs::assert::PathAssert;
use assert_fs::fixture::NamedTempFile;
use predicates::prelude::*;
Expand All @@ -8,19 +8,19 @@ use std::path;

#[test]
fn test_sanity() {
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
cmd.assert().failure();
}

#[test]
fn test_left_argument_is_missing() {
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
cmd.assert().stderr("Error: the LEFT argument is missing\n");
}

#[test]
fn test_right_argument_is_missing() {
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
let assert = cmd.arg(path::PathBuf::from("./nonexistent-left.file"));

assert
Expand All @@ -30,7 +30,7 @@ fn test_right_argument_is_missing() {

#[test]
fn test_left_does_not_exist() {
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
let left = path::PathBuf::from("./nonexistent-left.file");
let assert = cmd
.arg(&left)
Expand All @@ -52,7 +52,7 @@ Caused by:

#[test]
fn test_right_does_not_exist() {
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
let right = path::PathBuf::from("./nonexistent-right.file");
let assert = cmd
.arg(fs::canonicalize("./benches/fixtures/tiger.jpg").unwrap())
Expand All @@ -77,7 +77,7 @@ fn test_identical_image() {
let output = NamedTempFile::new("test_identical_image-diff.png")
.unwrap()
.into_persistent_if(std::env::var_os("CI").is_some());
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
let assert = cmd
.arg(fs::canonicalize("./benches/fixtures/tiger.jpg").unwrap())
.arg(fs::canonicalize("./benches/fixtures/tiger.jpg").unwrap())
Expand All @@ -92,7 +92,7 @@ fn test_identical_image() {
#[test]
fn test_different_image() {
let output = NamedTempFile::new("test_different_image-diff.png").unwrap();
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
let assert = cmd
.arg(fs::canonicalize("./benches/fixtures/tiger.jpg").unwrap())
.arg(fs::canonicalize("./benches/fixtures/tiger-2.jpg").unwrap())
Expand All @@ -113,7 +113,7 @@ fn test_output_image() {
let output = NamedTempFile::new("test_output_image-diff.png")
.unwrap()
.into_persistent_if(running_on_ci);
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
let assert = cmd
.arg(fs::canonicalize("./benches/fixtures/tiger.jpg").unwrap())
.arg(fs::canonicalize("./benches/fixtures/tiger-2.jpg").unwrap())
Expand All @@ -133,7 +133,7 @@ fn test_output_image_4k() {
let output = NamedTempFile::new("test_output_image_4k-diff.png")
.unwrap()
.into_persistent_if(std::env::var_os("CI").is_some());
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
let assert = cmd
.arg(fs::canonicalize("./benches/fixtures/water-4k.png").unwrap())
.arg(fs::canonicalize("./benches/fixtures/water-4k-2.png").unwrap())
Expand All @@ -153,7 +153,7 @@ fn test_output_image_web_page() {
let output = NamedTempFile::new("test_output_image_web_page-diff.png")
.unwrap()
.into_persistent_if(std::env::var_os("CI").is_some());
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
let assert = cmd
.arg(fs::canonicalize("./benches/fixtures/www.cypress.io.png").unwrap())
.arg(fs::canonicalize("./benches/fixtures/www.cypress.io-2.png").unwrap())
Expand All @@ -174,7 +174,7 @@ fn test_block_out_area() {
let output = NamedTempFile::new("test_block_out_area-diff.png")
.unwrap()
.into_persistent_if(running_on_ci);
let mut cmd = Command::cargo_bin("dify").unwrap();
let mut cmd = Command::new(cargo_bin!("dify"));
let assert = cmd
.arg(fs::canonicalize("./benches/fixtures/tiger.jpg").unwrap())
.arg(fs::canonicalize("./benches/fixtures/yellow.jpg").unwrap())
Expand Down