- moved superqemu's "QemuDisplay" here; the VNC VM and Qemu both share it (and it has been renamed to a less goofy dumb name) - VNC VM has been heavily refactored to just use the VNC display we have (this means only one source of truth, less bugs, and it's generally just Better to share the code imho). this means that future plans to abstract this further (or implement the client in cvm-rs in general) won't cause any explosions, or require duplicate effort - vms are now in src/vm/... just better organization - superqemu doesn't manage a display anymore (or care about it, other than making sure the socket is unlinked on stop). Instead now it provides info for us to setup our own VNC client. This is also why we provide our own shim interface This currently relies on a alpha version of superqemu. Before this is merged into cvmts main I will publish a stable tag and point cvmts to that new version
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { Size, Rect } from './Utilities';
|
|
import sharp from 'sharp';
|
|
import * as cvm from '@cvmts/cvm-rs';
|
|
|
|
// A good balance. TODO: Configurable?
|
|
let gJpegQuality = 35;
|
|
|
|
const kThumbnailSize: Size = {
|
|
width: 400,
|
|
height: 300
|
|
};
|
|
|
|
// this returns appropiate Sharp options to deal with CVMTS raw framebuffers
|
|
// (which are RGBA bitmaps, essentially. We probably should abstract that out but
|
|
// that'd mean having to introduce that to rfb and oihwekjtgferklds;./tghnredsltg;erhds)
|
|
function GetRawSharpOptions(size: Size): sharp.CreateRaw {
|
|
return {
|
|
width: size.width,
|
|
height: size.height,
|
|
channels: 4
|
|
};
|
|
}
|
|
|
|
export class JPEGEncoder {
|
|
static SetQuality(quality: number) {
|
|
gJpegQuality = quality;
|
|
}
|
|
|
|
static async Encode(canvas: Buffer, displaySize: Size, rect: Rect): Promise<Buffer> {
|
|
let offset = (rect.y * displaySize.width + rect.x) * 4;
|
|
return cvm.jpegEncode({
|
|
width: rect.width,
|
|
height: rect.height,
|
|
stride: displaySize.width,
|
|
buffer: canvas.subarray(offset)
|
|
});
|
|
}
|
|
|
|
static async EncodeThumbnail(buffer: Buffer, size: Size): Promise<Buffer> {
|
|
let { data, info } = await sharp(buffer, { raw: GetRawSharpOptions(size) })
|
|
.resize(kThumbnailSize.width, kThumbnailSize.height, { fit: 'fill' })
|
|
.raw()
|
|
.toBuffer({ resolveWithObject: true });
|
|
|
|
return cvm.jpegEncode({
|
|
width: kThumbnailSize.width,
|
|
height: kThumbnailSize.height,
|
|
stride: kThumbnailSize.width,
|
|
buffer: data
|
|
});
|
|
}
|
|
}
|