Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bokuweb committed Sep 23, 2024
1 parent 505d51d commit dfdaa40
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 53 deletions.
56 changes: 29 additions & 27 deletions crates/reg_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use thiserror::Error;
#[derive(Error, Debug)]
pub enum CompareError {
#[error("file io error, {0}")]
File(#[from] io::Error),
File(#[from] std::io::Error),
#[error("image diff error, {0}")]
ImageDiff(#[from] ImageDiffError),
#[error("unknown error")]
Expand Down Expand Up @@ -108,31 +108,32 @@ pub fn run(
.num_threads(options.concurrency.unwrap_or_else(|| 4))
.build()
.unwrap();
let result: Result<Vec<(PathBuf, DiffOutput)>, CompareError> = pool.install(|| {
targets
.par_iter()
.map(|path| {
let img1 = std::fs::read(actual_dir.join(path))?;
let img2 = std::fs::read(expected_dir.join(path))?;
let res = image_diff_rs::diff(
img1,
img2,
&DiffOption {
threshold: options.matching_threshold,
include_anti_alias: Some(!options.enable_antialias.unwrap_or_default()),
},
)?;
Ok((path.clone(), res))
})
.inspect(|r| {
if let Err(e) = r {
dbg!(&e);
}
})
.collect()
})?;

let result = result?;

let result = pool
.install(|| {
targets
.par_iter()
.map(|path| {
let img1 = std::fs::read(actual_dir.join(path))?;
let img2 = std::fs::read(expected_dir.join(path))?;
let res = image_diff_rs::diff(
img1,
img2,
&DiffOption {
threshold: options.matching_threshold,
include_anti_alias: Some(!options.enable_antialias.unwrap_or_default()),
},
)?;
Ok((path.clone(), res))
})
.inspect(|r| {
if let Err(e) = r {
dbg!(&e);
}
})
})
.collect::<Result<Vec<(PathBuf, DiffOutput)>, CompareError>>()?;

let mut differences = BTreeSet::new();
let mut passed = BTreeSet::new();
let mut failed = BTreeSet::new();
Expand All @@ -152,7 +153,7 @@ pub fn run(
differences.insert(diff_image.clone());
// TODO: make webp, png selectable
diff_image.set_extension("webp");
std::fs::write(diff_dir.join(&diff_image), item.diff_image)?;
std::fs::write(diff_dir.join(&diff_image), item.diff_image.clone())?;
}
}

Expand All @@ -174,6 +175,7 @@ pub fn run(
if let Some(html) = report.html {
std::fs::write("./report.html", html)?;
};

Ok(())
}

Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"license": "ISC",
"dependencies": {
"@tybys/wasm-util": "^0.9.0"
},
"devDependencies": {
"@types/node": "^22.5.5"
}
}
43 changes: 33 additions & 10 deletions js/pnpm-lock.yaml

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

File renamed without changes.
Binary file modified js/reg.wasm
Binary file not shown.
Binary file modified js/sample/diff/sample0.webp
Binary file not shown.
21 changes: 21 additions & 0 deletions js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "Preserve",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"allowJs": true,
"checkJs": true,
"strict": true,
"verbatimModuleSyntax": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"allowImportingTsExtensions": true,
"noImplicitOverride": true,
"noEmit": true
},
"include": ["./*.ts"]
}
29 changes: 14 additions & 15 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,20 @@ const handler = async ({ startArg, tid, memory }) => {
const { createInstanceProxy } = require('./proxy.js');
instance = createInstanceProxy(instance, memory);
wasi.start(instance);
try {
const symbols = Object.getOwnPropertySymbols(wasi);
const selectDescription = (description) => (s) => {
if (s.description) {
return s.description === description;
}
return s.toString() === `Symbol(${description})`;
};
if (Array.isArray(description)) {
return description.map((d) => symbols.filter(selectDescription(d))[0]);
}
const kStarted = symbols.filter(selectDescription('kStarted'))[0];
wasi[kStarted] = false;
} catch (_) {}
console.log(tid);
// try {
// const symbols = Object.getOwnPropertySymbols(wasi);
// const selectDescription = (description) => (s) => {
// if (s.description) {
// return s.description === description;
// }
// return s.toString() === `Symbol(${description})`;
// };
// if (Array.isArray(description)) {
// return description.map((d) => symbols.filter(selectDescription(d))[0]);
// }
// const kStarted = symbols.filter(selectDescription('kStarted'))[0];
// wasi[kStarted] = false;
// } catch (_) {}
instance.exports.wasi_thread_start(tid, startArg);
} catch (e) {
throw e;
Expand Down
2 changes: 1 addition & 1 deletion js/worker.mts → js/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ const handler = async ({ startArg, tid, memory }) => {
}
};

parentPort.addListener('message', handler);
parentPort?.addListener('message', handler);

0 comments on commit dfdaa40

Please sign in to comment.