fix daily backup
This commit is contained in:
parent
1d9fa2a310
commit
cf4265eebf
|
@ -123,17 +123,23 @@ class Palette {
|
||||||
/*
|
/*
|
||||||
* Take a buffer of indexed pixels and output it as RGB Array
|
* Take a buffer of indexed pixels and output it as RGB Array
|
||||||
* @param chunkBuffer Buffer of indexed pixels
|
* @param chunkBuffer Buffer of indexed pixels
|
||||||
|
* @param targetLength Optional integer of length of chunk
|
||||||
|
* (will be padded or cut to its size)
|
||||||
* @return RGB Buffer
|
* @return RGB Buffer
|
||||||
*/
|
*/
|
||||||
buffer2RGB(chunkBuffer) {
|
buffer2RGB(chunkBuffer, targetLength = null) {
|
||||||
const { length } = chunkBuffer;
|
let minLength = chunkBuffer.length;
|
||||||
|
let length = minLength;
|
||||||
|
if (targetLength) {
|
||||||
|
minLength = Math.min(targetLength, minLength);
|
||||||
|
length = targetLength;
|
||||||
|
}
|
||||||
const colors = new Uint8Array(length * 3);
|
const colors = new Uint8Array(length * 3);
|
||||||
let color;
|
let color;
|
||||||
let value;
|
let value;
|
||||||
const { rgb } = this;
|
const { rgb } = this;
|
||||||
|
|
||||||
let c = 0;
|
let c = 0;
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < minLength; i++) {
|
||||||
value = chunkBuffer[i];
|
value = chunkBuffer[i];
|
||||||
|
|
||||||
color = (value & 0x3F) * 3;
|
color = (value & 0x3F) * 3;
|
||||||
|
@ -141,6 +147,17 @@ class Palette {
|
||||||
colors[c++] = rgb[color++];
|
colors[c++] = rgb[color++];
|
||||||
colors[c++] = rgb[color];
|
colors[c++] = rgb[color];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (minLength < length) {
|
||||||
|
const blankR = rgb[0];
|
||||||
|
const blankG = rgb[1];
|
||||||
|
const blankB = rgb[2];
|
||||||
|
for (let i = minLength; i < length; i += 1) {
|
||||||
|
colors[c++] = blankR;
|
||||||
|
colors[c++] = blankG;
|
||||||
|
colors[c++] = blankB;
|
||||||
|
}
|
||||||
|
}
|
||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -279,13 +279,7 @@ export async function createPngBackup(
|
||||||
}
|
}
|
||||||
if (chunk && chunk.length) {
|
if (chunk && chunk.length) {
|
||||||
try {
|
try {
|
||||||
const tileBuffer = new Uint32Array(TILE_SIZE ** 2);
|
const tileBuffer = palette.buffer2RGB(chunk, TILE_SIZE ** 2);
|
||||||
const chunkLength = chunk.length;
|
|
||||||
const { abgr } = palette;
|
|
||||||
for (let i = 0; i < chunkLength; i += 1) {
|
|
||||||
tileBuffer[i] = abgr[chunk[i] & 0x3F];
|
|
||||||
}
|
|
||||||
|
|
||||||
const filename = `${xBackupDir}/${y}.png`;
|
const filename = `${xBackupDir}/${y}.png`;
|
||||||
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
|
Loading…
Reference in New Issue
Block a user