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) {
|
if (viewMode == VIEWS.ARRANGE) {
|
||||||
let snap = SPACE.screenshot();
|
let snap = SPACE.screenshot();
|
||||||
API.view.snapshot = snap.substring(snap.indexOf(",") + 1);
|
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) {
|
if (MODE === MODES.SLA && !callback) {
|
||||||
callback = preparePreview;
|
callback = preparePreview;
|
||||||
|
|
|
||||||
|
|
@ -108,19 +108,30 @@
|
||||||
|
|
||||||
// generate thumb, preview1, preview2
|
// generate thumb, preview1, preview2
|
||||||
let thumb = [];
|
let thumb = [];
|
||||||
|
let tdata = SLA.previewSmall.data;
|
||||||
for (let x=0; x<116; x++) {
|
for (let x=0; x<116; x++) {
|
||||||
for (let y=0; y<116; y++) {
|
for (let y=0; y<116; y++) {
|
||||||
let val = 1 << Math.floor(x / 7.25);
|
let p = (x * 116 + y) * 4;
|
||||||
thumb.push((val >> 8) & 0xff);
|
let r = (tdata[p + 0] >> 3) << 11;
|
||||||
thumb.push(val & 0xff);
|
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 preview1 = [];
|
||||||
|
let pdata = SLA.previewLarge.data;
|
||||||
|
console.log({pdata});
|
||||||
for (let x=0; x<290; x++) {
|
for (let x=0; x<290; x++) {
|
||||||
for (let y=0; y<290; y++) {
|
for (let y=0; y<290; y++) {
|
||||||
let val = 1 << Math.floor(x / 18.125);
|
let p = (x * 290 + y) * 4;
|
||||||
preview1.push((val >> 8) & 0xff);
|
let r = (pdata[p + 0] >> 3) << 11;
|
||||||
preview1.push(val & 0xff);
|
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;
|
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 sws = self.worker.snap.url;
|
||||||
let b64 = atob(sws.substring(sws.indexOf(',') + 1));
|
let b64 = atob(sws.substring(sws.indexOf(',') + 1));
|
||||||
let bin = Uint8Array.from(b64, c => c.charCodeAt(0));
|
let bin = Uint8Array.from(b64, c => c.charCodeAt(0));
|
||||||
let img = new png.PNG();
|
let img = new png.PNG();
|
||||||
img.parse(bin, (err, data) => {
|
img.parse(bin, (err, data) => {
|
||||||
SLA.preview = img;
|
SLA.preview = img;
|
||||||
SLA.previewSmall = samplePNG(img, 200, 125);
|
SLA.previewSmall = samplePNG(img, smallDims.x, smallDims.y);
|
||||||
SLA.previewLarge = samplePNG(img, 400, 300);
|
SLA.previewLarge = samplePNG(img, largeDims.x, largeDims.y);
|
||||||
});
|
});
|
||||||
let height = process.slaSlice || 0.05;
|
let height = process.slaSlice || 0.05;
|
||||||
|
|
||||||
|
|
@ -635,11 +649,12 @@
|
||||||
|
|
||||||
function samplePNG(png, width, height) {
|
function samplePNG(png, width, height) {
|
||||||
let th = width, tw = height,
|
let th = width, tw = height,
|
||||||
|
aspect = width / height, // was fixed at 4/3 for photon
|
||||||
ratio = png.width / png.height,
|
ratio = png.width / png.height,
|
||||||
buf = new Uint8Array(th * tw * 4),
|
buf = new Uint8Array(th * tw * 4),
|
||||||
div, xoff, yoff, dx, ex, dy, ey, bidx, pixval;
|
div, xoff, yoff, dx, ex, dy, ey, bidx, pixval;
|
||||||
|
|
||||||
if (ratio > 4/3) {
|
if (ratio >= aspect) {
|
||||||
div = png.height / tw;
|
div = png.height / tw;
|
||||||
xoff = Math.round((png.width - (th * div)) / 2);
|
xoff = Math.round((png.width - (th * div)) / 2);
|
||||||
yoff = 0;
|
yoff = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue