diff --git a/codecs/basis/asdf.html b/codecs/basis/asdf.html deleted file mode 100644 index 3a2b770b..00000000 --- a/codecs/basis/asdf.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/client/lazy-app/Compress/index.tsx b/src/client/lazy-app/Compress/index.tsx index 19e30fcb..467d167a 100644 --- a/src/client/lazy-app/Compress/index.tsx +++ b/src/client/lazy-app/Compress/index.tsx @@ -97,6 +97,9 @@ async function decodeImage( try { if (!canDecode) { + if (mimeType === 'image/basisu') { + return await workerBridge.basisDecode(signal, blob); + } if (mimeType === 'image/avif') { return await workerBridge.avifDecode(signal, blob); } diff --git a/src/client/lazy-app/util/index.ts b/src/client/lazy-app/util/index.ts index eb7d81ed..cba6656e 100644 --- a/src/client/lazy-app/util/index.ts +++ b/src/client/lazy-app/util/index.ts @@ -152,7 +152,7 @@ const magicNumberMapInput = [ [/^\x00\x00\x00 ftypavif\x00\x00\x00\x00/, 'image/avif'], [/^\xff\x0a/, 'image/jxl'], [/^\x00\x00\x00\x0cJXL \x0d\x0a\x87\x0a/, 'image/jxl'], - [/^Bs\x10/, 'image/basisu'], + [/^sB/, 'image/basisu'], ] as const; export type ImageMimeTypes = typeof magicNumberMapInput[number][1]; diff --git a/src/features/decoders/basis/worker/basisDecode.ts b/src/features/decoders/basis/worker/basisDecode.ts new file mode 100644 index 00000000..cc93a07a --- /dev/null +++ b/src/features/decoders/basis/worker/basisDecode.ts @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Google Inc. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import type { BasisModule } from 'codecs/basis/dec/basis_dec'; +import wasmUrl from 'url:codecs/basis/dec/basis_dec.wasm'; +import { initEmscriptenModule, blobToArrayBuffer } from 'features/worker-utils'; + +let emscriptenModule: Promise; + +export default async function decode(blob: Blob): Promise { + if (!emscriptenModule) { + const decoder = await import('codecs/basis/dec/basis_dec'); + emscriptenModule = initEmscriptenModule(decoder.default, wasmUrl); + } + + const [module, data] = await Promise.all([ + emscriptenModule, + blobToArrayBuffer(blob), + ]); + + const result = module.decode(data); + if (!result) throw new Error('Decoding error'); + return result; +}