From 671ed94d74755096a64bf85e12bc37017bc481e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arno=C5=A1t=20Pleskot?= Date: Fri, 16 Jun 2023 23:42:45 +0200 Subject: [PATCH] chore: add timers --- src/data/blob.ts | 10 ++++++++++ src/data/index.ts | 5 ++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/data/blob.ts b/src/data/blob.ts index 47e587ec6..1da33575b 100644 --- a/src/data/blob.ts +++ b/src/data/blob.ts @@ -267,22 +267,29 @@ export const canvasToBlob = async ( tileDataArray[tileY][tileX] = imageData; } + console.time("tiling"); // Iterate over the tiles and process each one for (let tileY = 0; tileY < canvasHeight / tileHeight; tileY++) { for (let tileX = 0; tileX < canvasWidth / tileWidth; tileX++) { processTile(tileX, tileY); } } + console.timeEnd("tiling"); + console.time("create png"); // Create a new PNG image with the final dimensions const finalImage = new PNG({ width: canvasWidth, height: canvasHeight }); + console.timeEnd("create png"); + console.time("concat tiles"); // Merge the tiles into the final image for (let tileY = 0; tileY < canvasHeight / tileHeight; tileY++) { for (let tileX = 0; tileX < canvasWidth / tileWidth; tileX++) { const imageData = tileDataArray[tileY][tileX]; const destX = tileX * tileWidth; const destY = tileY * tileHeight; + + // Copy the pixels from the tile to the final image for (let y = 0; y < tileHeight; y++) { for (let x = 0; x < tileWidth; x++) { 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); + console.timeEnd("create buffer"); return new Blob([buffer], { type: "image/png" }); }; diff --git a/src/data/index.ts b/src/data/index.ts index 2061388fb..a2de70f88 100644 --- a/src/data/index.ts +++ b/src/data/index.ts @@ -74,11 +74,10 @@ export const exportCanvas = async ( tempCanvas.style.display = "none"; document.body.appendChild(tempCanvas); - console.log("tempCanvas", tempCanvas.width, tempCanvas.height); - if (type === "png") { + console.time("export png"); let blob = await canvasToBlob(tempCanvas); - console.log("final blob size", blob.size); + console.timeEnd("export png"); tempCanvas.remove(); if (appState.exportEmbedScene) { blob = await (