<!doctypehtml>
<title>JXL animation repetition count via ImageDecoder and snapshotWindow</title> <!-- Intentionally not including SimpleTest.css to control page background. -->
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/WindowSnapshot.js"></script>
<style> html, body { background: black; margin: 0; padding: 0; }
</style>
<script>
/* globals ImageDecoder */
async function testRepetitionCount(filename, repetitionCount) {
const response = await fetch(filename);
const decoder = new ImageDecoder({data: response.body, type: 'image/jxl'});
await decoder.tracks.ready;
const track = decoder.tracks.selectedTrack;
ok(track.animated, `${filename}: track must be animated`);
is(track.repetitionCount, repetitionCount,
`${filename}: repetitionCount must match`);
await decoder.completed;
const frameCount = track.frameCount;
is(frameCount, 4, `${filename}: must have exactly 4 frames`);
let loopDurationUs = 0;
for (let i = 0; i < frameCount; i++) {
const result = await decoder.decode({frameIndex: i});
loopDurationUs += result.image.duration;
result.image.close();
}
decoder.close();
const loopDurationMs = loopDurationUs / 1000;
const frameDurationMs = loopDurationMs / frameCount;
const isInfinite = repetitionCount === Infinity;
// For infinite repetitions, poll for one full cycle + buffer; for finite,
// poll until the expected total duration has elapsed.
const pollDurationMs = isInfinite
? loopDurationMs + frameDurationMs * 3
: loopDurationMs * (repetitionCount + 1) + frameDurationMs * 3;
// White background is distinct from both the black page background and all
// four animation frame colors (red/green/blue/yellow). It shows while the
// image is loading, allowing polling to start immediately without waiting
// for the load event.
const imgBgColor = 0xFFFFFF;
const img = document.createElement('img'); img.style.cssText = 'position:fixed;top:0;left:0;width:100px;height:100px;background-color:white;';
document.body.appendChild(img);
// Read the center pixel of the image via snapshotWindow (which uses
// drawWindow and captures the current animation frame, not just frame0).
const pixelX = 50;
const pixelY = 50;
let animationStartTime = null;
let lastChangeTime = null;
let lastPixelKey = 0; // 0 = black (page background before img is painted)
let frameChanges = 0;
await new Promise(requestAnimationFrame);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.