MCPcopy Index your code
hub / github.com/ColmapView/Colmapview.github.io / getScreenshotStats

Function getScreenshotStats

e2e/webgpu-psnr-app.spec.ts:728–770  ·  view source on GitHub ↗
(page: Page, png: Buffer)

Source from the content-addressed store, hash-verified

726}
727
728async function getScreenshotStats(page: Page, png: Buffer): Promise<ScreenshotStats> {
729 return page.evaluate(async (base64) => {
730 const image = new Image();
731 const loaded = new Promise<void>((resolve, reject) => {
732 image.onload = () => resolve();
733 image.onerror = () => reject(new Error('Failed to decode screenshot'));
734 });
735 image.src = `data:image/png;base64,${base64}`;
736 await loaded;
737
738 const canvas = document.createElement('canvas');
739 canvas.width = image.naturalWidth;
740 canvas.height = image.naturalHeight;
741 const context = canvas.getContext('2d');
742 if (!context) throw new Error('Failed to create screenshot stats canvas context');
743 context.drawImage(image, 0, 0);
744 const pixels = context.getImageData(0, 0, canvas.width, canvas.height).data;
745 let visiblePixelCount = 0;
746 let nonBlackPixelCount = 0;
747 let lumaSum = 0;
748 for (let index = 0; index < pixels.length; index += 4) {
749 const alpha = pixels[index + 3];
750 if (alpha === 0) continue;
751 visiblePixelCount += 1;
752 const red = pixels[index];
753 const green = pixels[index + 1];
754 const blue = pixels[index + 2];
755 const luma = 0.2126 * red + 0.7152 * green + 0.0722 * blue;
756 lumaSum += luma;
757 if (red + green + blue > 8) {
758 nonBlackPixelCount += 1;
759 }
760 }
761
762 return {
763 width: canvas.width,
764 height: canvas.height,
765 visiblePixelCount,
766 nonBlackPixelCount,
767 meanLuma: visiblePixelCount > 0 ? lumaSum / visiblePixelCount : 0,
768 };
769 }, png.toString('base64'));
770}
771
772async function captureNonBlankSceneCenterSamplesUntilWebGpu(
773 page: Page,

Calls 3

drawImageMethod · 0.80
resolveFunction · 0.50
getContextMethod · 0.45

Tested by

no test coverage detected