chore: add timers

This commit is contained in:
Arnošt Pleskot 2023-06-16 23:42:45 +02:00
parent d5ac76d4ea
commit 671ed94d74
No known key found for this signature in database
2 changed files with 12 additions and 3 deletions

View File

@ -267,22 +267,29 @@ export const canvasToBlob = async (
tileDataArray[tileY][tileX] = imageData; tileDataArray[tileY][tileX] = imageData;
} }
console.time("tiling");
// Iterate over the tiles and process each one // Iterate over the tiles and process each one
for (let tileY = 0; tileY < canvasHeight / tileHeight; tileY++) { for (let tileY = 0; tileY < canvasHeight / tileHeight; tileY++) {
for (let tileX = 0; tileX < canvasWidth / tileWidth; tileX++) { for (let tileX = 0; tileX < canvasWidth / tileWidth; tileX++) {
processTile(tileX, tileY); processTile(tileX, tileY);
} }
} }
console.timeEnd("tiling");
console.time("create png");
// Create a new PNG image with the final dimensions // Create a new PNG image with the final dimensions
const finalImage = new PNG({ width: canvasWidth, height: canvasHeight }); const finalImage = new PNG({ width: canvasWidth, height: canvasHeight });
console.timeEnd("create png");
console.time("concat tiles");
// Merge the tiles into the final image // Merge the tiles into the final image
for (let tileY = 0; tileY < canvasHeight / tileHeight; tileY++) { for (let tileY = 0; tileY < canvasHeight / tileHeight; tileY++) {
for (let tileX = 0; tileX < canvasWidth / tileWidth; tileX++) { for (let tileX = 0; tileX < canvasWidth / tileWidth; tileX++) {
const imageData = tileDataArray[tileY][tileX]; const imageData = tileDataArray[tileY][tileX];
const destX = tileX * tileWidth; const destX = tileX * tileWidth;
const destY = tileY * tileHeight; const destY = tileY * tileHeight;
// Copy the pixels from the tile to the final image
for (let y = 0; y < tileHeight; y++) { for (let y = 0; y < tileHeight; y++) {
for (let x = 0; x < tileWidth; x++) { for (let x = 0; x < tileWidth; x++) {
const index = (y * tileWidth + x) * 4; const index = (y * tileWidth + x) * 4;
@ -295,8 +302,11 @@ export const canvasToBlob = async (
} }
} }
} }
console.timeEnd("concat tiles");
console.time("create buffer");
const buffer = PNG.sync.write(finalImage); const buffer = PNG.sync.write(finalImage);
console.timeEnd("create buffer");
return new Blob([buffer], { type: "image/png" }); return new Blob([buffer], { type: "image/png" });
}; };

View File

@ -74,11 +74,10 @@ export const exportCanvas = async (
tempCanvas.style.display = "none"; tempCanvas.style.display = "none";
document.body.appendChild(tempCanvas); document.body.appendChild(tempCanvas);
console.log("tempCanvas", tempCanvas.width, tempCanvas.height);
if (type === "png") { if (type === "png") {
console.time("export png");
let blob = await canvasToBlob(tempCanvas); let blob = await canvasToBlob(tempCanvas);
console.log("final blob size", blob.size); console.timeEnd("export png");
tempCanvas.remove(); tempCanvas.remove();
if (appState.exportEmbedScene) { if (appState.exportEmbedScene) {
blob = await ( blob = await (