mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 00:37:19 +00:00
Switch to dssim_core
This commit is contained in:
74
codecs/visdif/Cargo.lock
generated
74
codecs/visdif/Cargo.lock
generated
@@ -1,11 +1,5 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
|
||||||
name = "adler"
|
|
||||||
version = "0.2.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@@ -40,15 +34,6 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crc32fast"
|
|
||||||
version = "1.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-deque"
|
name = "crossbeam-deque"
|
||||||
version = "0.7.3"
|
version = "0.7.3"
|
||||||
@@ -98,13 +83,13 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dssim"
|
name = "dssim-core"
|
||||||
version = "2.11.2"
|
version = "2.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "462c6cf1cb98d8f7dc5f7a5878e9f05e6be51086370f7f162e446a62ebfab0cb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getopts",
|
|
||||||
"imgref",
|
"imgref",
|
||||||
"itertools",
|
"itertools",
|
||||||
"lodepng",
|
|
||||||
"rayon",
|
"rayon",
|
||||||
"rgb",
|
"rgb",
|
||||||
]
|
]
|
||||||
@@ -115,33 +100,12 @@ version = "1.6.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f"
|
checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "flate2"
|
|
||||||
version = "1.0.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "766d0e77a2c1502169d4a93ff3b8c15a71fd946cd0126309752104e5f3c46d94"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"crc32fast",
|
|
||||||
"libc",
|
|
||||||
"miniz_oxide",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures"
|
name = "futures"
|
||||||
version = "0.1.29"
|
version = "0.1.29"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef"
|
checksum = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "getopts"
|
|
||||||
version = "0.2.21"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-width",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.1.15"
|
version = "0.1.15"
|
||||||
@@ -187,17 +151,6 @@ version = "0.2.72"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
|
checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lodepng"
|
|
||||||
version = "3.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1d6face0280146377ad4959c588399014554f2875e953fdec135655ca769e1da"
|
|
||||||
dependencies = [
|
|
||||||
"flate2",
|
|
||||||
"libc",
|
|
||||||
"rgb",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.8"
|
version = "0.4.8"
|
||||||
@@ -228,15 +181,6 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
|
checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "miniz_oxide"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4d7559a8a40d0f97e1edea3220f698f78b1c5ab67532e49f68fde3910323b722"
|
|
||||||
dependencies = [
|
|
||||||
"adler",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num_cpus"
|
name = "num_cpus"
|
||||||
version = "1.13.0"
|
version = "1.13.0"
|
||||||
@@ -335,7 +279,9 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"dssim",
|
"dssim-core",
|
||||||
|
"imgref",
|
||||||
|
"rgb",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-test",
|
"wasm-bindgen-test",
|
||||||
"wee_alloc",
|
"wee_alloc",
|
||||||
@@ -352,12 +298,6 @@ dependencies = [
|
|||||||
"unicode-xid 0.2.1",
|
"unicode-xid 0.2.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-width"
|
|
||||||
version = "0.1.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
name = "squoosh-visdiff"
|
name = "squoosh-visdiff"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Surma <surma@surma.link>"]
|
authors = ["Surma <surma@surma.link>"]
|
||||||
|
edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
@@ -14,6 +15,9 @@ default = ["console_error_panic_hook", "wee_alloc"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cfg-if = "0.1.2"
|
cfg-if = "0.1.2"
|
||||||
wasm-bindgen = "0.2.38"
|
wasm-bindgen = "0.2.38"
|
||||||
|
dssim-core = "2.11.3"
|
||||||
|
imgref = "1.7.0"
|
||||||
|
rgb = "0.8.24"
|
||||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||||
# logging them with `console.error`. This is great for development, but requires
|
# logging them with `console.error`. This is great for development, but requires
|
||||||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
||||||
@@ -27,8 +31,8 @@ console_error_panic_hook = { version = "0.1.1", optional = true }
|
|||||||
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
|
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
|
||||||
wee_alloc = { version = "0.4.2", optional = true }
|
wee_alloc = { version = "0.4.2", optional = true }
|
||||||
|
|
||||||
[dependencies.dssim]
|
#[dependencies.dssim]
|
||||||
path = "/Users/surma/src/github.com/kornelski/dssim"
|
#path = "/Users/surma/src/github.com/kornelski/dssim"
|
||||||
|
|
||||||
#dssim = "2.11.2"
|
#dssim = "2.11.2"
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
mod utils;
|
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
use dssim::ToRGBAPLU;
|
use dssim_core::{Dssim, ToRGBAPLU};
|
||||||
|
use imgref;
|
||||||
|
use rgb::FromSlice;
|
||||||
|
|
||||||
|
mod utils;
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
||||||
@@ -17,13 +19,28 @@ cfg_if! {
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn ssim(
|
pub fn ssim(data_a: Vec<u8>, data_b: Vec<u8>, width: usize, height: usize) -> f64 {
|
||||||
image_a: Vec<u8>,
|
let dssim = Dssim::new();
|
||||||
image_b: Vec<u8>
|
|
||||||
) -> f64 {
|
// FIXME: Creating new Dssim every time is wasteful. In the context
|
||||||
let a = image_a.as_slice().to_rgbaplu();
|
// of the CLI, one image is highly likely to remain static (i.e. the
|
||||||
let b = image_b.as_slice().to_rgbaplu();
|
// reference image). dssim_core has a `set_save_ssim_maps`, that should
|
||||||
|
// make subsequent comparisons a lot cheaper.
|
||||||
|
|
||||||
|
let image_a = imgref::Img::new(data_a.as_slice().as_rgba().to_rgbaplu(), width, height);
|
||||||
|
let a = match dssim.create_image(&image_a) {
|
||||||
|
Some(v) => v,
|
||||||
|
_ => return -1.0, // FIXME: Use something more idiomatic
|
||||||
|
};
|
||||||
|
|
||||||
|
let image_b = imgref::Img::new(data_b.as_slice().as_rgba().to_rgbaplu(), width, height);
|
||||||
|
let b = match dssim.create_image(&image_b) {
|
||||||
|
Some(v) => v,
|
||||||
|
_ => return -1.0, // FIXME: Use something more idiomatic
|
||||||
|
};
|
||||||
|
|
||||||
|
//let b = (image_b.as_slice().to_rgbaplu();
|
||||||
// TODO: Rearchitect entire thing to enable `set_save_ssim_maps`
|
// TODO: Rearchitect entire thing to enable `set_save_ssim_maps`
|
||||||
// accrossm multiple SSIM calculations.
|
// accrossm multiple SSIM calculations.
|
||||||
dssim::Dssim::new().compare(a, b)
|
dssim.compare(&a, &b).0.into()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user