Skip to content

Commit

Permalink
fix: Set QOI to be cached
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanpingle committed Oct 19, 2023
1 parent 16c4eae commit bfa6d61
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/features/encoders/qoi/worker/qoiEncode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import qoi_enc, { QoiModule } from 'codecs/qoi/enc/qoi_enc';
import { EncodeOptions } from '../shared/meta';
import type { QoiModule } from 'codecs/qoi/enc/qoi_enc';
import type { EncodeOptions } from '../shared/meta';
import { initEmscriptenModule } from 'features/worker-utils';

let emscriptenModule: Promise<QoiModule>;

async function init() {
const qoiEncoder = await import('codecs/qoi/enc/qoi_enc.js');
return initEmscriptenModule(qoiEncoder.default);
}

export default async function encode(
data: ImageData,
options: EncodeOptions,
): Promise<ArrayBuffer> {
if (!emscriptenModule) {
emscriptenModule = initEmscriptenModule(qoi_enc);
emscriptenModule = init();
}

const module = await emscriptenModule;
Expand Down

0 comments on commit bfa6d61

Please sign in to comment.