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
|
||||
* @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
|
||||
*/
|
||||
buffer2RGB(chunkBuffer) {
|
||||
const { length } = chunkBuffer;
|
||||
buffer2RGB(chunkBuffer, targetLength = null) {
|
||||
let minLength = chunkBuffer.length;
|
||||
let length = minLength;
|
||||
if (targetLength) {
|
||||
minLength = Math.min(targetLength, minLength);
|
||||
length = targetLength;
|
||||
}
|
||||
const colors = new Uint8Array(length * 3);
|
||||
let color;
|
||||
let value;
|
||||
const { rgb } = this;
|
||||
|
||||
let c = 0;
|
||||
for (let i = 0; i < length; i++) {
|
||||
for (let i = 0; i < minLength; i++) {
|
||||
value = chunkBuffer[i];
|
||||
|
||||
color = (value & 0x3F) * 3;
|
||||
|
@ -141,6 +147,17 @@ class Palette {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -279,13 +279,7 @@ export async function createPngBackup(
|
|||
}
|
||||
if (chunk && chunk.length) {
|
||||
try {
|
||||
const tileBuffer = new Uint32Array(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 tileBuffer = palette.buffer2RGB(chunk, TILE_SIZE ** 2);
|
||||
const filename = `${xBackupDir}/${y}.png`;
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
|
|
Loading…
Reference in New Issue
Block a user