forked from visdesignlab/aardvark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from visdesignlab/112-zstd-decompression
beta-0.9
- Loading branch information
Showing
12 changed files
with
650 additions
and
238 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 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 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 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 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 @@ | ||
declare module 'numcodecs'; |
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,16 @@ | ||
// Modified from: https://github.com/hms-dbmi/viv | ||
|
||
import { Pool } from 'geotiff'; | ||
import DecodeWorker from './decoder.worker?worker'; | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/API/NavigatorConcurrentHardware/hardwareConcurrency | ||
// We need to give a different way of getting this for safari, so 4 is probably a safe bet | ||
// for parallel processing in the meantime. More can't really hurt since they'll just block | ||
// each other and not the UI thread, which is the real benefit. | ||
const defaultPoolSize = globalThis?.navigator?.hardwareConcurrency ?? 4; | ||
|
||
export default class extends Pool { | ||
constructor() { | ||
super(defaultPoolSize, () => new DecodeWorker()); | ||
} | ||
} |
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,37 @@ | ||
// Modified from https://github.com/hms-dbmi/viv | ||
|
||
import { getDecoder, addDecoder } from 'geotiff'; | ||
import ZstdDecoder from './zstd-decoder'; | ||
|
||
addDecoder(50000, () => ZstdDecoder); | ||
|
||
// @ts-expect-error - We are in a worker context | ||
const worker: ServiceWorker = self; | ||
|
||
interface WorkerData { | ||
id: number; | ||
fileDirectory: string; | ||
buffer: ArrayBuffer; | ||
} | ||
|
||
async function decodeBuffer(e: MessageEvent<WorkerData>): Promise<void> { | ||
try { | ||
const { id, fileDirectory, buffer } = e.data; | ||
const decoder = await getDecoder(fileDirectory); | ||
const decoded = await decoder.decode(fileDirectory, buffer); | ||
worker.postMessage({ decoded, id }, [decoded]); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
console.error(`Failed: ${error.message} at ${e.data.id}`); | ||
} else { | ||
console.error(`Failed: Generic Error at ${e.data.id}`); | ||
} | ||
} | ||
} | ||
|
||
worker.addEventListener('message', (event: Event) => { | ||
const messageEvent = event as MessageEvent; | ||
decodeBuffer(messageEvent).catch((error: Error) => { | ||
console.error(`Error during decompression: ${error.message}`); | ||
}); | ||
}); |
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,17 @@ | ||
import { BaseDecoder } from 'geotiff'; | ||
import { Zstd } from 'numcodecs'; | ||
|
||
export default class ZstdDecoder extends BaseDecoder { | ||
decoder: any; | ||
|
||
constructor(_: any) { | ||
super(); | ||
this.decoder = new Zstd(); | ||
} | ||
|
||
async decodeBlock(buffer: ArrayBuffer) { | ||
const bytes = new Uint8Array(buffer); | ||
const decoded = await this.decoder.decode(bytes); | ||
return decoded.buffer; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,32 +1,33 @@ | ||
import { fileURLToPath, URL } from 'node:url'; | ||
import path from 'path'; | ||
import { defineConfig, loadEnv } from 'vite' | ||
import { defineConfig, loadEnv } from 'vite'; | ||
|
||
import vue from '@vitejs/plugin-vue'; | ||
|
||
import { quasar, transformAssetUrls } from '@quasar/vite-plugin'; | ||
|
||
export default defineConfig(({ command, mode }) => { | ||
// Load env file based on `mode` in the current working directory. | ||
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix. | ||
const env = loadEnv(mode, process.cwd(), '') | ||
return { | ||
// vite config | ||
plugins: [ | ||
vue(), | ||
// Load env file based on `mode` in the current working directory. | ||
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix. | ||
const env = loadEnv(mode, process.cwd(), ''); | ||
return { | ||
// vite config | ||
plugins: [ | ||
vue(), | ||
|
||
quasar({ | ||
sassVariables: 'src/quasar-variables.sass', | ||
}), | ||
], | ||
resolve: { | ||
alias: { | ||
'@': fileURLToPath(new URL('./src', import.meta.url)), | ||
quasar({ | ||
sassVariables: 'src/quasar-variables.sass', | ||
}), | ||
], | ||
resolve: { | ||
alias: { | ||
'@': fileURLToPath(new URL('./src', import.meta.url)), | ||
}, | ||
}, | ||
}, | ||
define: { | ||
__APP_ENV__: JSON.stringify(env.APP_ENV), | ||
}, | ||
} | ||
}) | ||
|
||
define: { | ||
__APP_ENV__: JSON.stringify(env.APP_ENV), | ||
}, | ||
worker: { | ||
format: 'es', | ||
}, | ||
}; | ||
}); |
Oops, something went wrong.