diff --git a/backend/src/JPEGEncoder.ts b/backend/src/JPEGEncoder.ts index faf82e3..fe8a8a8 100644 --- a/backend/src/JPEGEncoder.ts +++ b/backend/src/JPEGEncoder.ts @@ -14,6 +14,7 @@ export class JPEGEncoder { width: rect.width, height: rect.height, stride: displaySize.width, + quality: gJpegQuality, buffer: canvas.subarray(offset) }); } diff --git a/jpeg-rs/index.d.ts b/jpeg-rs/index.d.ts index 875c97c..e777315 100644 --- a/jpeg-rs/index.d.ts +++ b/jpeg-rs/index.d.ts @@ -1,15 +1,15 @@ // interface JpegInputArgs { - width: number, - height: number, - stride: number, // The width of your input framebuffer OR your image width (if encoding a full image) - buffer: Buffer + width: number; + height: number; + stride: number; // The width of your input framebuffer OR your image width (if encoding a full image) + quality: number | undefined; + buffer: Buffer; // TODO: Allow different formats, or export a boxed ffi object which can store a format // (i.e: new JpegEncoder(FORMAT_xxx)). } /// Performs JPEG encoding. -export function jpegEncode(input: JpegInputArgs) : Promise; - +export function jpegEncode(input: JpegInputArgs): Promise; diff --git a/jpeg-rs/index.node b/jpeg-rs/index.node index 0edf5d7..3c53478 100755 Binary files a/jpeg-rs/index.node and b/jpeg-rs/index.node differ diff --git a/jpeg-rs/src/jpeg_js.rs b/jpeg-rs/src/jpeg_js.rs index de87f9b..fdf7a47 100644 --- a/jpeg-rs/src/jpeg_js.rs +++ b/jpeg-rs/src/jpeg_js.rs @@ -31,6 +31,11 @@ fn jpeg_encode_impl<'a>(cx: &mut FunctionContext<'a>) -> JsResult<'a, JsPromise> let width: u64 = input.get::(cx, "width")?.value(cx) as u64; let height: u64 = input.get::(cx, "height")?.value(cx) as u64; let stride: u64 = input.get::(cx, "stride")?.value(cx) as u64; + let quality : u64 = if let Ok(val) = input.get::(cx, "quality") { + val.value(cx) as u64 + } else { + 35u64 + }; let buffer: Handle = input.get(cx, "buffer")?; let (deferred, promise) = cx.promise(); @@ -65,7 +70,7 @@ fn jpeg_encode_impl<'a>(cx: &mut FunctionContext<'a>) -> JsResult<'a, JsPromise> let vec = COMPRESSOR.with(|lazy| { let mut b = lazy.borrow_mut(); - b.set_quality(35); + b.set_quality(quality as u32); b.set_subsamp(turbojpeg_sys::TJSAMP_TJSAMP_420); b.compress_buffer(&image) });