* Wie viele Bildpunkte der Szene wirklich leuchten. * * Der Weg fuehrt ueber ein Bild und nicht ueber die Zeichenflaeche: eine * WebGL-Flaeche ohne `preserveDrawingBuffer` gibt ihre Bildpunkte nicht heraus, * und sie dafuer umzukonfigurieren hiesse, das Produkt fuer die Messung zu * aendern. Pl
(page)
| 2509 | * Verbindung und kein zweiter Prozess. |
| 2510 | */ |
| 2511 | async function litPixels(page) { |
| 2512 | const scene = page.locator('[data-testid="atlas-galaxy-scene"]'); |
| 2513 | const box = await scene.boundingBox(); |
| 2514 | if (box === null) { |
| 2515 | return 0; |
| 2516 | } |
| 2517 | const shot = await page.screenshot({ |
| 2518 | clip: { |
| 2519 | x: Math.round(box.x), y: Math.round(box.y), |
| 2520 | width: Math.max(8, Math.round(box.width)), height: Math.max(8, Math.round(box.height)), |
| 2521 | }, |
| 2522 | }); |
| 2523 | return page.evaluate(async (data) => { |
| 2524 | const image = new Image(); |
| 2525 | image.src = `data:image/png;base64,${data}`; |
| 2526 | await image.decode(); |
| 2527 | const canvas = document.createElement('canvas'); |
| 2528 | canvas.width = image.width; |
| 2529 | canvas.height = image.height; |
| 2530 | const context = canvas.getContext('2d'); |
| 2531 | context.drawImage(image, 0, 0); |
| 2532 | const pixels = context.getImageData(0, 0, canvas.width, canvas.height).data; |
| 2533 | let lit = 0; |
| 2534 | for (let i = 0; i < pixels.length; i += 4) { |
| 2535 | if ((pixels[i] + pixels[i + 1] + pixels[i + 2]) / 3 > 26) { |
| 2536 | lit += 1; |
| 2537 | } |
| 2538 | } |
| 2539 | return lit; |
| 2540 | }, shot.toString('base64')); |
| 2541 | } |
| 2542 | |
| 2543 | // ------------------------------------------------------------- Die Etappen --- |
| 2544 |