-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import conversionLoadSampleInputs from "./conversion-load-sample-inputs.js" | ||
|
||
class ConversionModel { | ||
|
||
inputVolume: Uint8Array | ||
outputFormat: string | ||
forceServerSide: boolean | ||
|
||
constructor() { | ||
this.outputFormat = "mha" | ||
this.forceServerSide = false | ||
} | ||
} | ||
|
||
|
||
class ConversionController { | ||
|
||
constructor(loadSampleInputs) { | ||
this.loadSampleInputs = loadSampleInputs | ||
|
||
this.model = new ConversionModel() | ||
const model = this.model | ||
|
||
this.webWorker = null | ||
|
||
if (loadSampleInputs) { | ||
const loadSampleInputsButton = document.querySelector("#conversionInputs [name=loadSampleInputs]") | ||
loadSampleInputsButton.setAttribute('style', 'display: block-inline;') | ||
loadSampleInputsButton.addEventListener('click', (event) => { | ||
loadSampleInputs(model) | ||
}) | ||
} | ||
|
||
// ---------------------------------------------- | ||
// Inputs | ||
const inputElement = document.querySelector('#conversionInputs input[name=input-volume-file]') | ||
inputElement.addEventListener('change', (event) => { | ||
const dataTransfer = event.dataTransfer | ||
const files = event.target.files || dataTransfer.files | ||
|
||
files[0].arrayBuffer().then((arrayBuffer) => { | ||
model.inputs.set("input", new Uint8Array(arrayBuffer)) | ||
const input = document.querySelector("#conversionInputs sl-input[name=input]") | ||
input.value = model.inputs.get("input").toString().substring(0, 50) + ' ...' | ||
}) | ||
}) | ||
|
||
// // ---------------------------------------------- | ||
// // Options | ||
// const stringifyElement = document.querySelector('#conversionInputs sl-checkbox[name=stringify]') | ||
// stringifyElement.addEventListener('sl-change', (event) => { | ||
// model.options.set("stringify", stringifyElement.checked) | ||
// }) | ||
|
||
// const compressionLevelElement = document.querySelector('#conversionInputs sl-input[name=compression-level]') | ||
// compressionLevelElement.addEventListener('sl-change', (event) => { | ||
// model.options.set("compressionLevel", parseInt(compressionLevelElement.value)) | ||
// }) | ||
|
||
// const dataUrlPrefixElement = document.querySelector('#conversionInputs sl-input[name=data-url-prefix]') | ||
// dataUrlPrefixElement.addEventListener('sl-change', (event) => { | ||
// model.options.set("dataUrlPrefix", dataUrlPrefixElement.value) | ||
// }) | ||
|
||
// ---------------------------------------------- | ||
// Outputs | ||
const outputOutputDownload = document.querySelector('#conversionOutputs sl-button[name=output-download]') | ||
outputOutputDownload.addEventListener('click', (event) => { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
if (model.outputs.has("output")) { | ||
globalThis.downloadFile(model.outputs.get("output"), "output.bin") | ||
} | ||
}) | ||
|
||
const runButton = document.querySelector('#conversionInputs sl-button[name="run"]') | ||
runButton.addEventListener('click', async (event) => { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
|
||
if(!model.inputVolume) { | ||
globalThis.notify("Required input volume not provided", "Please provide an AIM or ISQ file", "danger", "exclamation-octagon") | ||
return | ||
} | ||
|
||
|
||
try { | ||
runButton.loading = true | ||
const t0 = performance.now() | ||
|
||
const { webWorker, output } = await conversion.conversion(this.webWorker, | ||
model.inputs.get('input').slice(), | ||
Object.fromEntries(model.options.entries()) | ||
) | ||
|
||
const t1 = performance.now() | ||
globalThis.notify("conversion successfully completed", `in ${t1 - t0} milliseconds.`, "success", "rocket-fill") | ||
this.webWorker = webWorker | ||
|
||
model.outputs.set("output", output) | ||
outputOutputDownload.variant = "success" | ||
outputOutputDownload.disabled = false | ||
const outputOutput = document.querySelector('#conversionOutputs sl-textarea[name=output]') | ||
outputOutput.value = output.toString().substring(0, 200) + ' ...' | ||
} catch (error) { | ||
globalThis.notify("Error while running pipeline", error.toString(), "danger", "exclamation-octagon") | ||
throw error | ||
} finally { | ||
runButton.loading = false | ||
} | ||
}) | ||
} | ||
} | ||
|
||
const conversionController = new ConversionController(conversionLoadSampleInputs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export default function conversionLoadSampleInputs (model) { | ||
const sampleInput = new Uint8Array([222, 173, 190, 239]) | ||
context.inputs.set("input", sampleInput) | ||
const inputElement = document.querySelector("#compressStringifyInputs [name=input]") | ||
inputElement.value = sampleInput.toString() | ||
|
||
const stringify = true | ||
context.options.set("stringify", stringify) | ||
const stringifyElement = document.querySelector('#compressStringifyInputs sl-checkbox[name=stringify]') | ||
stringifyElement.checked = stringify | ||
|
||
const compressionLevel = 5 | ||
context.options.set("compressionLevel", compressionLevel) | ||
const compressionLevelElement = document.querySelector('#compressStringifyInputs sl-input[name=compression-level]') | ||
compressionLevelElement.value = compressionLevel | ||
|
||
const dataUrlPrefix = 'data:application/iwi+cbor+zstd;base64,' | ||
context.options.set("dataUrlPrefix", dataUrlPrefix) | ||
const dataUrlPrefixElement = document.querySelector('#compressStringifyInputs sl-input[name=data-url-prefix]') | ||
dataUrlPrefixElement.value = dataUrlPrefix | ||
|
||
return model | ||
} |
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import './conversion-controller.js' | ||
// import './calibration-controller.js' |
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,3 +106,8 @@ li { | |
background-color: #f9f9f9; | ||
} | ||
} | ||
|
||
.sl-toast-stack { | ||
left: 0; | ||
right: auto; | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.