From bcbf7db8d9b756146d08ea9b66d72e217f82ab24 Mon Sep 17 00:00:00 2001 From: modeco80 Date: Wed, 24 Apr 2024 03:41:32 -0400 Subject: [PATCH] misc patches done to get everything to play ball also adds editorconfig --- .editorconfig | 11 +++++++++++ cvmts/src/JPEGEncoderWorker.ts | 29 ++++++++++++++++------------- cvmts/src/WSServer.ts | 11 ++++++++--- yarn.lock | 1 - 4 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0b53eb8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = tab +indent_size = 4 + +# specifically for YAML +[{yml, yaml}] +indent_style = space diff --git a/cvmts/src/JPEGEncoderWorker.ts b/cvmts/src/JPEGEncoderWorker.ts index 25bc123..c5f93cf 100644 --- a/cvmts/src/JPEGEncoderWorker.ts +++ b/cvmts/src/JPEGEncoderWorker.ts @@ -1,16 +1,19 @@ - -import jpegTurbo from "@computernewb/jpeg-turbo"; -import Piscina from "piscina"; +import jpegTurbo from '@computernewb/jpeg-turbo'; +import Piscina from 'piscina'; export default async (opts: any) => { - let res = await jpegTurbo.compress(opts.buffer, { - format: jpegTurbo.FORMAT_RGBA, - width: opts.width, - height: opts.height, - subsampling: jpegTurbo.SAMP_422, - stride: opts.stride, - quality: opts.quality - }); + try { + let res = await jpegTurbo.compress(opts.buffer, { + format: jpegTurbo.FORMAT_RGBA, + width: opts.width, + height: opts.height, + subsampling: jpegTurbo.SAMP_422, + stride: opts.stride, + quality: opts.quality + }); - return Piscina.move(res); -} \ No newline at end of file + return Piscina.move(res); + } catch { + return; + } +}; diff --git a/cvmts/src/WSServer.ts b/cvmts/src/WSServer.ts index a789dc5..51528ba 100644 --- a/cvmts/src/WSServer.ts +++ b/cvmts/src/WSServer.ts @@ -44,7 +44,8 @@ function GetRawSharpOptions(size: Size): sharp.CreateRaw { } } -const kJpegPool = new Piscina({ +// Thread pool for doing JPEG encoding for rects. +const TheJpegEncoderPool = new Piscina({ filename: path.join(import.meta.dirname + '/JPEGEncoderWorker.js'), minThreads: 4, maxThreads: 4 @@ -53,7 +54,7 @@ const kJpegPool = new Piscina({ async function EncodeJpeg(canvas: Buffer, displaySize: Size, rect: Rect): Promise { let offset = (rect.y * displaySize.width + rect.x) * 4; - let res = await kJpegPool.run({ + let res = await TheJpegEncoderPool.run({ buffer: canvas.subarray(offset), width: rect.width, height: rect.height, @@ -61,6 +62,10 @@ async function EncodeJpeg(canvas: Buffer, displaySize: Size, rect: Rect): Promis quality: kJpegQuality }); + // TODO: There's probably (definitely) a better way to fix this + if(res == undefined) + return Buffer.from([]); + // have to manually turn it back into a buffer because // Piscina for some reason turns it into a Uint8Array @@ -1006,4 +1011,4 @@ export default class WSServer { }); return {yes:yes,no:no}; } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index b8671e3..bf82089 100644 --- a/yarn.lock +++ b/yarn.lock @@ -66,7 +66,6 @@ __metadata: "@types/ws": "npm:^8.5.5" execa: "npm:^8.0.1" mnemonist: "npm:^0.39.5" - parcel: "npm:^2.12.0" piscina: "npm:^4.4.0" prettier: "npm:^3.2.5" sharp: "npm:^0.33.3"