generate cxdlp preview/thumb
This commit is contained in:
parent
abcb2a9fac
commit
4837ac83df
3 changed files with 36 additions and 10 deletions
|
|
@ -993,7 +993,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
|||
if (viewMode == VIEWS.ARRANGE) {
|
||||
let snap = SPACE.screenshot();
|
||||
API.view.snapshot = snap.substring(snap.indexOf(",") + 1);
|
||||
KIRI.work.snap(SPACE.screenshot2());
|
||||
KIRI.work.snap(SPACE.screenshot2({width: 640}));
|
||||
}
|
||||
if (MODE === MODES.SLA && !callback) {
|
||||
callback = preparePreview;
|
||||
|
|
|
|||
|
|
@ -108,19 +108,30 @@
|
|||
|
||||
// generate thumb, preview1, preview2
|
||||
let thumb = [];
|
||||
let tdata = SLA.previewSmall.data;
|
||||
for (let x=0; x<116; x++) {
|
||||
for (let y=0; y<116; y++) {
|
||||
let val = 1 << Math.floor(x / 7.25);
|
||||
thumb.push((val >> 8) & 0xff);
|
||||
thumb.push(val & 0xff);
|
||||
let p = (x * 116 + y) * 4;
|
||||
let r = (tdata[p + 0] >> 3) << 11;
|
||||
let g = (tdata[p + 1] >> 2) << 5;
|
||||
let b = (tdata[p + 2] >> 3);
|
||||
let v = (r | g | b) & 0xffff;
|
||||
thumb.push((v >> 8) & 0xff);
|
||||
thumb.push(v & 0xff);
|
||||
}
|
||||
}
|
||||
let preview1 = [];
|
||||
let pdata = SLA.previewLarge.data;
|
||||
console.log({pdata});
|
||||
for (let x=0; x<290; x++) {
|
||||
for (let y=0; y<290; y++) {
|
||||
let val = 1 << Math.floor(x / 18.125);
|
||||
preview1.push((val >> 8) & 0xff);
|
||||
preview1.push(val & 0xff);
|
||||
let p = (x * 290 + y) * 4;
|
||||
let r = (pdata[p + 0] >> 3) << 11;
|
||||
let g = (pdata[p + 1] >> 2) << 5;
|
||||
let b = (pdata[p + 2] >> 3);
|
||||
let v = (r | g | b) & 0xffff;
|
||||
preview1.push((v >> 8) & 0xff);
|
||||
preview1.push(v & 0xff);
|
||||
}
|
||||
}
|
||||
let preview2 = preview1;
|
||||
|
|
|
|||
|
|
@ -50,14 +50,28 @@
|
|||
});
|
||||
}
|
||||
|
||||
let smallDims = { x: 200, y: 125 };
|
||||
let largeDims = { x: 400, y: 300 };
|
||||
|
||||
switch (device.deviceName) {
|
||||
case 'Anycubic.Photon':
|
||||
case 'Anycubic.Photon.S':
|
||||
// defaults above
|
||||
break;
|
||||
case 'Creality.Halot.Sky':
|
||||
smallDims = { x: 116, y: 116 };
|
||||
largeDims = { x: 290, y: 290 };
|
||||
break;
|
||||
}
|
||||
|
||||
let sws = self.worker.snap.url;
|
||||
let b64 = atob(sws.substring(sws.indexOf(',') + 1));
|
||||
let bin = Uint8Array.from(b64, c => c.charCodeAt(0));
|
||||
let img = new png.PNG();
|
||||
img.parse(bin, (err, data) => {
|
||||
SLA.preview = img;
|
||||
SLA.previewSmall = samplePNG(img, 200, 125);
|
||||
SLA.previewLarge = samplePNG(img, 400, 300);
|
||||
SLA.previewSmall = samplePNG(img, smallDims.x, smallDims.y);
|
||||
SLA.previewLarge = samplePNG(img, largeDims.x, largeDims.y);
|
||||
});
|
||||
let height = process.slaSlice || 0.05;
|
||||
|
||||
|
|
@ -635,11 +649,12 @@
|
|||
|
||||
function samplePNG(png, width, height) {
|
||||
let th = width, tw = height,
|
||||
aspect = width / height, // was fixed at 4/3 for photon
|
||||
ratio = png.width / png.height,
|
||||
buf = new Uint8Array(th * tw * 4),
|
||||
div, xoff, yoff, dx, ex, dy, ey, bidx, pixval;
|
||||
|
||||
if (ratio > 4/3) {
|
||||
if (ratio >= aspect) {
|
||||
div = png.height / tw;
|
||||
xoff = Math.round((png.width - (th * div)) / 2);
|
||||
yoff = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue