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 Piscina from "piscina";
|
||||
import jpegTurbo from '@computernewb/jpeg-turbo';
|
||||
import Piscina from 'piscina';
|
||||
|
||||
export default async (opts: any) => {
|
||||
try {
|
||||
let res = await jpegTurbo.compress(opts.buffer, {
|
||||
format: jpegTurbo.FORMAT_RGBA,
|
||||
width: opts.width,
|
||||
@@ -13,4 +13,7 @@ export default async (opts: any) => {
|
||||
});
|
||||
|
||||
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'),
|
||||
minThreads: 4,
|
||||
maxThreads: 4
|
||||
@@ -53,7 +54,7 @@ const kJpegPool = new Piscina({
|
||||
async function EncodeJpeg(canvas: Buffer, displaySize: Size, rect: Rect): Promise<Buffer> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user