Skip to content

Commit

Permalink
Improved memory efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronge-2020 committed Feb 27, 2024
1 parent 39ea4b8 commit 4427750
Showing 1 changed file with 43 additions and 50 deletions.
93 changes: 43 additions & 50 deletions main2.js
Original file line number Diff line number Diff line change
Expand Up @@ -1212,61 +1212,54 @@ async function downloadAllCores(cores) {
progressBar.style.width = "0%";
progressText.innerText = "Starting download...";

await Promise.all(
cores.map(async (core, index) => {
const fullResTileParams = {
tileX: core.x - core.currentRadius,
tileY: core.y - core.currentRadius,
tileWidth: core.currentRadius * 2,
tileHeight: core.currentRadius * 2,
tileSize: core.currentRadius * 2,
};

try {
const fullSizeImageResp = await getRegionFromWSI(
svsImageURL,
fullResTileParams
);
const blob = await fullSizeImageResp.blob();
// Log the size of each blob
console.log(`Blob ${index + 1} size: ${blob.size} bytes`);

zip.file(`core_${core.row}_${core.col}.png`, blob);
for (let index = 0; index < cores.length; index++) {
const core = cores[index];
const fullResTileParams = {
tileX: core.x - core.currentRadius,
tileY: core.y - core.currentRadius,
tileWidth: core.currentRadius * 2,
tileHeight: core.currentRadius * 2,
tileSize: core.currentRadius * 2,
};

// Update progress
const progress = ((index + 1) / cores.length) * 100;
progressBar.style.width = `${progress}%`;
progressText.innerText = `Exporting... ${progress.toFixed(2)}%`;
} catch (error) {
console.error("Error fetching or adding an image to the zip:", error);
}
})
);
try {
const fullSizeImageResp = await getRegionFromWSI(svsImageURL, fullResTileParams);
const blob = await fullSizeImageResp.blob();
console.log(`Blob ${index + 1} size: ${blob.size} bytes`);
zip.file(`core_${core.row}_${core.col}.png`, blob);

// Update progress
const progress = ((index + 1) / cores.length) * 100;
progressBar.style.width = `${progress}%`;
progressText.innerText = `Exporting... ${progress.toFixed(2)}%`;
} catch (error) {
console.error("Error fetching or adding an image to the zip:", error);
}
}

// Generate the zip file

zip
.generateAsync({
type: "blob",
compression: "DEFLATE",
compressionOptions: { level: 9 }, // Highest compression
})
.then(function (content) {
// Use a temporary link to download the zip file
const downloadLink = document.createElement("a");
downloadLink.href = URL.createObjectURL(content);
downloadLink.download = "cores.zip";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);

// Hide progress overlay and reset progress bar
overlay.style.display = "none";
progressBar.style.width = "0%";
progressText.innerText = "Initializing...";
});
zip.generateAsync({
type: "blob",
compression: "DEFLATE",
compressionOptions: { level: 6 }, // Highest compression
}).then(function (content) {
// Use a temporary link to download the zip file
const downloadLink = document.createElement("a");
downloadLink.href = URL.createObjectURL(content);
downloadLink.download = "cores.zip";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);

// Hide progress overlay and reset progress bar
overlay.style.display = "none";
progressBar.style.width = "0%";
progressText.innerText = "Initializing...";
});
}



// Main function that runs the application
const run = async () => {
bindEventListeners();
Expand Down

0 comments on commit 4427750

Please sign in to comment.