misc patches done to get everything to play ball
also adds editorconfig
This commit is contained in:
11
.editorconfig
Normal file
11
.editorconfig
Normal file
@@ -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
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
|
import jpegTurbo from '@computernewb/jpeg-turbo';
|
||||||
import jpegTurbo from "@computernewb/jpeg-turbo";
|
import Piscina from 'piscina';
|
||||||
import Piscina from "piscina";
|
|
||||||
|
|
||||||
export default async (opts: any) => {
|
export default async (opts: any) => {
|
||||||
|
try {
|
||||||
let res = await jpegTurbo.compress(opts.buffer, {
|
let res = await jpegTurbo.compress(opts.buffer, {
|
||||||
format: jpegTurbo.FORMAT_RGBA,
|
format: jpegTurbo.FORMAT_RGBA,
|
||||||
width: opts.width,
|
width: opts.width,
|
||||||
@@ -13,4 +13,7 @@ export default async (opts: any) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return Piscina.move(res);
|
return Piscina.move(res);
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -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'),
|
filename: path.join(import.meta.dirname + '/JPEGEncoderWorker.js'),
|
||||||
minThreads: 4,
|
minThreads: 4,
|
||||||
maxThreads: 4
|
maxThreads: 4
|
||||||
@@ -53,7 +54,7 @@ const kJpegPool = new Piscina({
|
|||||||
async function EncodeJpeg(canvas: Buffer, displaySize: Size, rect: Rect): Promise<Buffer> {
|
async function EncodeJpeg(canvas: Buffer, displaySize: Size, rect: Rect): Promise<Buffer> {
|
||||||
let offset = (rect.y * displaySize.width + rect.x) * 4;
|
let offset = (rect.y * displaySize.width + rect.x) * 4;
|
||||||
|
|
||||||
let res = await kJpegPool.run({
|
let res = await TheJpegEncoderPool.run({
|
||||||
buffer: canvas.subarray(offset),
|
buffer: canvas.subarray(offset),
|
||||||
width: rect.width,
|
width: rect.width,
|
||||||
height: rect.height,
|
height: rect.height,
|
||||||
@@ -61,6 +62,10 @@ async function EncodeJpeg(canvas: Buffer, displaySize: Size, rect: Rect): Promis
|
|||||||
quality: kJpegQuality
|
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
|
// have to manually turn it back into a buffer because
|
||||||
// Piscina for some reason turns it into a Uint8Array
|
// Piscina for some reason turns it into a Uint8Array
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ __metadata:
|
|||||||
"@types/ws": "npm:^8.5.5"
|
"@types/ws": "npm:^8.5.5"
|
||||||
execa: "npm:^8.0.1"
|
execa: "npm:^8.0.1"
|
||||||
mnemonist: "npm:^0.39.5"
|
mnemonist: "npm:^0.39.5"
|
||||||
parcel: "npm:^2.12.0"
|
|
||||||
piscina: "npm:^4.4.0"
|
piscina: "npm:^4.4.0"
|
||||||
prettier: "npm:^3.2.5"
|
prettier: "npm:^3.2.5"
|
||||||
sharp: "npm:^0.33.3"
|
sharp: "npm:^0.33.3"
|
||||||
|
|||||||
Reference in New Issue
Block a user