@slidevideo/cli 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -2
  3. package/addons/slidevideo/geometry.ts +334 -1
  4. package/addons/slidevideo/global-top.vue +57 -6
  5. package/addons/slidevideo/preview.ts +242 -25
  6. package/assets/fonts/OFL-LICENSES.txt +95 -0
  7. package/assets/fonts/instrument-serif-latin-2.woff2 +0 -0
  8. package/assets/fonts/instrument-serif-latin-ext-1.woff2 +0 -0
  9. package/assets/fonts/jetbrains-mono-latin-4.woff2 +0 -0
  10. package/assets/fonts/jetbrains-mono-latin-ext-3.woff2 +0 -0
  11. package/assets/fonts/plus-jakarta-sans-latin-6.woff2 +0 -0
  12. package/assets/fonts/plus-jakarta-sans-latin-ext-5.woff2 +0 -0
  13. package/dist/adapters/powerpoint-preview.d.ts +1 -1
  14. package/dist/adapters/powerpoint-preview.js +13 -2
  15. package/dist/adapters/powerpoint.js +91 -14
  16. package/dist/adapters/slidev-inspection.js +7 -2
  17. package/dist/annotation-paint.d.ts +195 -5
  18. package/dist/annotation-paint.js +1188 -2
  19. package/dist/annotations.d.ts +26 -2
  20. package/dist/annotations.js +1117 -29
  21. package/dist/captions.d.ts +6 -0
  22. package/dist/captions.js +320 -0
  23. package/dist/cli.js +40 -17
  24. package/dist/compositor.js +51 -3
  25. package/dist/contracts.d.ts +253 -14
  26. package/dist/pipeline.d.ts +6 -1
  27. package/dist/pipeline.js +66 -19
  28. package/dist/preview/contracts.d.ts +14 -0
  29. package/dist/preview/player.js +523 -33
  30. package/dist/preview/server.d.ts +1 -1
  31. package/dist/preview/server.js +124 -3
  32. package/dist/preview/view.d.ts +1 -1
  33. package/dist/preview/view.js +26 -7
  34. package/dist/run.d.ts +1 -0
  35. package/dist/run.js +20 -0
  36. package/dist/speech.d.ts +10 -1
  37. package/dist/speech.js +17 -1
  38. package/dist/stamp-fonts.d.ts +17 -0
  39. package/dist/stamp-fonts.js +202 -0
  40. package/dist/storyboard.js +60 -3
  41. package/dist/timing.d.ts +2 -0
  42. package/dist/timing.js +277 -11
  43. package/package.json +12 -1
  44. package/schemas/annotation-geometry.v1.json +111 -0
  45. package/schemas/schedule.v1.json +1672 -84
  46. package/schemas/storyboard.v1.json +3725 -85
  47. package/skills/slidevideo/SKILL.md +5 -5
  48. package/skills/slidevideo/references/decks.md +6 -4
  49. package/skills/slidevideo/references/production.md +12 -11
  50. package/skills/slidevideo/references/storyboard.md +268 -5
  51. package/tools/powerpoint/powerpoint.ps1 +155 -6
  52. package/tools/powerpoint/preview.ps1 +68 -1
@@ -2,10 +2,12 @@ import { spawn } from 'node:child_process';
2
2
  import { mkdtemp, rm, writeFile } from 'node:fs/promises';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
5
+ import { createCanvas } from '@napi-rs/canvas';
6
+ import { ensureStampFonts, measureStampText } from './stamp-fonts.js';
5
7
  import { balancedSum, execute, executionSignal, ffmpegFilterScriptFlags, hashFile, saveJson } from './media.js';
6
8
  import { executable } from './executables.js';
7
9
  import { ProductionError, requireCondition } from './errors.js';
8
- import { effectPrimitives, findTargetGeometry, highlightPaint, underlineFragmentPrimitives, underlineFragmentsVisible, underlinePaint, underlineWipeFractions, } from './annotation-paint.js';
10
+ import { activeViewTransform, effectPrimitives, evaluateLaserPosition, evaluateViewTransform, findTargetGeometry, forwardTransformRect, highlightPaint, inverseTransformPoint, laserDirtyBounds, laserDotSample, laserFadeFraction, laserPaint, laserVisible, paintLaser, paintStamp, pointInExpandedAperture, spotlightApertureBounds, spotlightAperturesVisible, spotlightFadeFraction, spotlightMaskSample, spotlightPaint, stampDirtyBounds, stampPaint, stampVisible, underlineFragmentPrimitives, underlineFragmentsVisible, underlinePaint, underlineWipeFractions, zoomPaint, zoomProgress, zoomTransformVisible, } from './annotation-paint.js';
9
11
  function toRgbPrimitive(paint) {
10
12
  return {
11
13
  ...paint,
@@ -97,12 +99,95 @@ function hasMeasurableRects(rects, video) {
97
99
  return right - left >= 2 && bottom - top >= 2;
98
100
  });
99
101
  }
100
- function measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, targetAppIndex, targetOppositePrimitives, sampleRects) {
102
+ function sampleBilinearChannel(frame, width, height, fx, fy, channel) {
103
+ const cx = Math.max(0, Math.min(width - 1, fx));
104
+ const cy = Math.max(0, Math.min(height - 1, fy));
105
+ const x0 = Math.floor(cx);
106
+ const y0 = Math.floor(cy);
107
+ const x1 = Math.min(width - 1, x0 + 1);
108
+ const y1 = Math.min(height - 1, y0 + 1);
109
+ const tx = cx - x0;
110
+ const ty = cy - y0;
111
+ const c00 = frame[(y0 * width + x0) * 3 + channel];
112
+ const c10 = frame[(y0 * width + x1) * 3 + channel];
113
+ const c01 = frame[(y1 * width + x0) * 3 + channel];
114
+ const c11 = frame[(y1 * width + x1) * 3 + channel];
115
+ return (c00 * (1 - tx) + c10 * tx) * (1 - ty) + (c01 * (1 - tx) + c11 * tx) * ty;
116
+ }
117
+ function measureZoomRegion(finalFrame, baseFrame, video, covered, appPrimitives, activeSpotlights, outputTimeMs, slideBounds, expectedView, oppositeView) {
118
+ const left = Math.max(0, Math.ceil(slideBounds.x));
119
+ const right = Math.min(video.width, Math.floor(slideBounds.x + slideBounds.width));
120
+ const top = Math.max(0, Math.ceil(slideBounds.y));
121
+ const bottom = Math.min(video.height, Math.floor(slideBounds.y + slideBounds.height));
122
+ const w = right - left;
123
+ const h = bottom - top;
124
+ if (w < 16 || h < 16) {
125
+ return { count: 0, expected_error: null, opposite_error: null, contrast: null, passed: false };
126
+ }
127
+ const x0 = left + 4;
128
+ const x1 = right - 4;
129
+ const y0 = top + 4;
130
+ const y1 = bottom - 4;
131
+ const stepX = Math.max(1, Math.floor((x1 - x0) / 96));
132
+ const stepY = Math.max(1, Math.floor((y1 - y0) / 54));
133
+ let expectedError = 0;
134
+ let oppositeError = 0;
135
+ let contrast = 0;
136
+ let count = 0;
137
+ const predict = (view, px, py, x, y) => {
138
+ const pt = view ? inverseTransformPoint(view, px, py) : { x: px, y: py };
139
+ const mask = activeSpotlights.length > 0 ? spotlightMaskSample(activeSpotlights, outputTimeMs, pt.x, pt.y) : undefined;
140
+ const rgb = [0, 0, 0];
141
+ for (const channel of [0, 1, 2]) {
142
+ let value = view
143
+ ? sampleBilinearChannel(baseFrame, video.width, video.height, pt.x - 0.5, pt.y - 0.5, channel)
144
+ : baseFrame[(y * video.width + x) * 3 + channel];
145
+ if (mask && mask.alpha > 0) {
146
+ value = value * (1 - mask.alpha) + mask.rgb[channel] * mask.alpha;
147
+ }
148
+ for (const list of appPrimitives) {
149
+ for (const primitive of list) {
150
+ if (inside(primitive.rectangle, pt.x, pt.y))
151
+ value = blendChannel(value, primitive, channel);
152
+ }
153
+ }
154
+ rgb[channel] = value;
155
+ }
156
+ return rgb;
157
+ };
158
+ for (let y = y0; y < y1; y += stepY) {
159
+ for (let x = x0; x < x1; x += stepX) {
160
+ const px = x + 0.5;
161
+ const py = y + 0.5;
162
+ if (covered.some(bounds => inside(bounds, px, py)))
163
+ continue;
164
+ const expRgb = predict(expectedView, px, py, x, y);
165
+ const oppRgb = predict(oppositeView, px, py, x, y);
166
+ const offset = (y * video.width + x) * 3;
167
+ for (const channel of [0, 1, 2]) {
168
+ expectedError += Math.abs(finalFrame[offset + channel] - expRgb[channel]);
169
+ oppositeError += Math.abs(finalFrame[offset + channel] - oppRgb[channel]);
170
+ contrast += Math.abs(expRgb[channel] - oppRgb[channel]);
171
+ count++;
172
+ }
173
+ }
174
+ }
175
+ const passed = count > 0 && contrast / count >= 4 && expectedError / count <= 14 && expectedError < oppositeError * 0.7;
176
+ return {
177
+ count,
178
+ expected_error: count ? expectedError / count : null,
179
+ opposite_error: count ? oppositeError / count : null,
180
+ contrast: count ? contrast / count : null,
181
+ passed,
182
+ };
183
+ }
184
+ function measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, targetAppIndex, targetOppositePrimitives, sampleRects, spotlightOpts, view) {
101
185
  let expectedError = 0;
102
186
  let oppositeError = 0;
103
187
  let contrast = 0;
104
188
  let count = 0;
105
- for (const rect of sampleRects) {
189
+ const outputRects = view ? sampleRects.map(rect => forwardTransformRect(view, rect)) : sampleRects;
190
+ for (const rect of outputRects) {
106
191
  const left = Math.max(0, Math.ceil(rect.x));
107
192
  const right = Math.min(video.width, Math.floor(rect.x + rect.width));
108
193
  const top = Math.max(0, Math.ceil(rect.y));
@@ -125,18 +210,35 @@ function measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, tar
125
210
  const py = y + 0.5;
126
211
  if (covered.some(bounds => inside(bounds, px, py)))
127
212
  continue;
213
+ const pt = view ? inverseTransformPoint(view, px, py) : { x: px, y: py };
214
+ if (spotlightOpts?.acceptPixel && !spotlightOpts.acceptPixel(pt.x, pt.y))
215
+ continue;
216
+ const expMask = spotlightOpts && spotlightOpts.expected.length > 0
217
+ ? spotlightMaskSample(spotlightOpts.expected, spotlightOpts.timeMs, pt.x, pt.y)
218
+ : undefined;
219
+ const oppMask = spotlightOpts && spotlightOpts.opposite.length > 0
220
+ ? spotlightMaskSample(spotlightOpts.opposite, spotlightOpts.oppositeTimeMs ?? spotlightOpts.timeMs, pt.x, pt.y)
221
+ : undefined;
128
222
  const offset = (y * video.width + x) * 3;
129
223
  for (const channel of [0, 1, 2]) {
130
- let expected = baseFrame[offset + channel];
224
+ let expected = view
225
+ ? sampleBilinearChannel(baseFrame, video.width, video.height, pt.x - 0.5, pt.y - 0.5, channel)
226
+ : baseFrame[offset + channel];
131
227
  let opposite = expected;
228
+ if (expMask && expMask.alpha > 0) {
229
+ expected = expected * (1 - expMask.alpha) + expMask.rgb[channel] * expMask.alpha;
230
+ }
231
+ if (oppMask && oppMask.alpha > 0) {
232
+ opposite = opposite * (1 - oppMask.alpha) + oppMask.rgb[channel] * oppMask.alpha;
233
+ }
132
234
  for (let appIndex = 0; appIndex < appPrimitives.length; appIndex++) {
133
235
  for (const primitive of appPrimitives[appIndex]) {
134
- if (inside(primitive.rectangle, px, py))
236
+ if (inside(primitive.rectangle, pt.x, pt.y))
135
237
  expected = blendChannel(expected, primitive, channel);
136
238
  }
137
239
  const oppositeList = appIndex === targetAppIndex ? targetOppositePrimitives : appPrimitives[appIndex];
138
240
  for (const primitive of oppositeList) {
139
- if (inside(primitive.rectangle, px, py))
241
+ if (inside(primitive.rectangle, pt.x, pt.y))
140
242
  opposite = blendChannel(opposite, primitive, channel);
141
243
  }
142
244
  }
@@ -148,7 +250,8 @@ function measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, tar
148
250
  }
149
251
  }
150
252
  }
151
- const passed = count > 0 && contrast / count >= 4 && expectedError / count <= 12 && expectedError < oppositeError * 0.7;
253
+ const maxError = view ? 14 : 12;
254
+ const passed = count > 0 && contrast / count >= 4 && expectedError / count <= maxError && expectedError < oppositeError * 0.7;
152
255
  return {
153
256
  count,
154
257
  expected_error: count ? expectedError / count : null,
@@ -159,9 +262,8 @@ function measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, tar
159
262
  }
160
263
  export function annotationApplications(video, schedule, visual, audioOrigin) {
161
264
  const observations = visual.annotation_geometry ?? [];
162
- return schedule.annotations.map((annotation) => {
163
- const context = { annotation: annotation.id, target: annotation.target };
164
- const geometry = findTargetGeometry(observations, annotation, annotation.target);
265
+ const validateGeometry = (annotation, target, context) => {
266
+ const geometry = findTargetGeometry(observations, annotation, target);
165
267
  requireCondition(geometry, 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: missing or ambiguous capture geometry`, 5, context);
166
268
  const { content, fragments, viewport } = geometry;
167
269
  const finite = [
@@ -191,17 +293,36 @@ export function annotationApplications(video, schedule, visual, audioOrigin) {
191
293
  content.height > 0 &&
192
294
  content.x + content.width <= viewport.width + 0.01 &&
193
295
  content.y + content.height <= viewport.height + 0.01 &&
194
- fragments.length >= 1 &&
296
+ (target.type === 'slide' ? fragments.length === 0 : fragments.length >= 1) &&
195
297
  fragments.every(bounds => bounds.x >= -0.00001 && bounds.y >= -0.00001 && bounds.width > 0 && bounds.height > 0 && bounds.x + bounds.width <= 1.00001 && bounds.y + bounds.height <= 1.00001), 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: invalid viewport, slide-content rectangle or target bounds`, 5, context);
196
- const target = annotation.target;
197
298
  if (target.type === 'region') {
198
299
  requireCondition(fragments.length === 1 && ['x', 'y', 'width', 'height'].every(key => Math.abs(fragments[0][key] - target[key]) < 0.00001), 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: region geometry differs from authored coordinates`, 5, context);
199
300
  }
301
+ return geometry;
302
+ };
303
+ return schedule.annotations.map((annotation) => {
304
+ const context = { annotation: annotation.id, target: annotation.target };
200
305
  const start_ms = annotation.start_ms + audioOrigin;
201
306
  const end_ms = annotation.end_ms + audioOrigin;
202
307
  const first_frame = Math.ceil(start_ms * video.fps / 1000 - 1e-9);
203
308
  const end_frame = Math.ceil(end_ms * video.fps / 1000 - 1e-9);
204
309
  requireCondition(first_frame < end_frame, 'ANNOTATION_FRAME_RANGE', `Annotation ${annotation.id}: interval contains no output frame at ${video.fps} fps`, 2, context);
310
+ if (annotation.effect === 'laser') {
311
+ const slideGeometry = validateGeometry(annotation, { type: 'slide' }, context);
312
+ const painted = laserPaint({ target: annotation.target, appearance: annotation.appearance, motion: annotation.motion, start_ms, end_ms }, slideGeometry, target => validateGeometry(annotation, target, { annotation: annotation.id, target }).fragments);
313
+ requireCondition(laserVisible(painted), 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: laser path has no visible pointer inside the slide-content rectangle`, 5, context);
314
+ return { ...painted, id: annotation.id, first_frame, end_frame, geometry: slideGeometry };
315
+ }
316
+ if (annotation.effect === 'stamp') {
317
+ ensureStampFonts();
318
+ const target = annotation.target.type === 'point' ? { type: 'slide' } : annotation.target;
319
+ const geometry = validateGeometry(annotation, target, context);
320
+ const painted = stampPaint({ ...annotation, start_ms, end_ms }, geometry, measureStampText);
321
+ requireCondition(!painted.overflow_error, 'STAMP_OVERFLOW', `Annotation ${annotation.id}: ${painted.overflow_error}`, 2, context);
322
+ requireCondition(stampVisible(painted), 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: stamp is clipped outside the slide-content rectangle`, 5, context);
323
+ return { ...painted, id: annotation.id, first_frame, end_frame, geometry };
324
+ }
325
+ const geometry = validateGeometry(annotation, annotation.target, context);
205
326
  switch (annotation.effect) {
206
327
  case 'highlight': {
207
328
  const painted = highlightPaint({ appearance: annotation.appearance, start_ms, end_ms }, geometry);
@@ -212,6 +333,16 @@ export function annotationApplications(video, schedule, visual, audioOrigin) {
212
333
  requireCondition(underlineFragmentsVisible(painted), 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: underline is clipped outside the slide-content rectangle`, 5, context);
213
334
  return { ...painted, id: annotation.id, first_frame, end_frame, geometry };
214
335
  }
336
+ case 'spotlight': {
337
+ const painted = spotlightPaint({ appearance: annotation.appearance, motion: annotation.motion, start_ms, end_ms }, geometry);
338
+ requireCondition(spotlightAperturesVisible(painted), 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: spotlight aperture is clipped outside the slide-content rectangle`, 5, context);
339
+ return { ...painted, id: annotation.id, first_frame, end_frame, geometry };
340
+ }
341
+ case 'zoom': {
342
+ const painted = zoomPaint({ appearance: annotation.appearance, motion: annotation.motion, start_ms, end_ms }, geometry);
343
+ requireCondition(zoomTransformVisible(painted), 'ANNOTATION_GEOMETRY', `Annotation ${annotation.id}: zoom target and padding leave no magnification room inside the slide-content rectangle`, 5, context);
344
+ return { ...painted, id: annotation.id, first_frame, end_frame, geometry };
345
+ }
215
346
  }
216
347
  });
217
348
  }
@@ -264,12 +395,16 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
264
395
  }
265
396
  for (const index of [boundaryFrame - 1, boundaryFrame].filter(frame => frame >= 0)) {
266
397
  const expectedActive = index >= item.first_frame && index < item.end_frame;
267
- const order = enqueue(index, (finalFrame, baseFrame, covered, appPrimitives, timestampMs) => {
398
+ const order = enqueue(index, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
268
399
  const current = appPrimitives[appIndex];
269
400
  const oppositeList = expectedActive
270
401
  ? current.filter(entry => entry.rectangle !== paint.rectangle)
271
402
  : [...current, targetRgb];
272
- const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, oppositeList, [paint.rectangle]);
403
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, oppositeList, [paint.rectangle], {
404
+ expected: activeSpotlights,
405
+ opposite: activeSpotlights,
406
+ timeMs: outputTimeMs,
407
+ }, activeView);
273
408
  orderedChecks.push({
274
409
  order,
275
410
  entry: {
@@ -324,9 +459,13 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
324
459
  coverage.push(`${item.id}:${part}:start,end`);
325
460
  if (item.first_frame - 1 >= 0) {
326
461
  const clearStartIndex = item.first_frame - 1;
327
- const order = enqueue(clearStartIndex, (finalFrame, baseFrame, covered, appPrimitives, timestampMs) => {
462
+ const order = enqueue(clearStartIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
328
463
  const oppositeList = [...appPrimitives[appIndex], ...settledPaints];
329
- const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, oppositeList, settledRects);
464
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, oppositeList, settledRects, {
465
+ expected: activeSpotlights,
466
+ opposite: activeSpotlights,
467
+ timeMs: outputTimeMs,
468
+ }, activeView);
330
469
  orderedChecks.push({
331
470
  order,
332
471
  entry: {
@@ -348,9 +487,13 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
348
487
  {
349
488
  const activeIndex = activeStartFrame;
350
489
  const activeRects = effectPrimitives([singleFragmentEffect], activeIndex * 1000 / video.fps).map(entry => entry.rectangle);
351
- const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, timestampMs) => {
490
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
352
491
  const oppositeList = appPrimitives[appIndex].filter(entry => !(entry.rectangle.y === fragment.rectangle.y && entry.rectangle.x >= fragment.rectangle.x && entry.rectangle.x + entry.rectangle.width <= fragment.rectangle.x + fragment.rectangle.width));
353
- const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, oppositeList, activeRects);
492
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, oppositeList, activeRects, {
493
+ expected: activeSpotlights,
494
+ opposite: activeSpotlights,
495
+ timeMs: outputTimeMs,
496
+ }, activeView);
354
497
  orderedChecks.push({
355
498
  order,
356
499
  entry: {
@@ -377,9 +520,13 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
377
520
  {
378
521
  const activeIndex = activeEndFrame;
379
522
  const activeRects = effectPrimitives([singleFragmentEffect], activeIndex * 1000 / video.fps).map(entry => entry.rectangle);
380
- const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, timestampMs) => {
523
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
381
524
  const oppositeList = appPrimitives[appIndex].filter(entry => !(entry.rectangle.y === fragment.rectangle.y && entry.rectangle.x >= fragment.rectangle.x && entry.rectangle.x + entry.rectangle.width <= fragment.rectangle.x + fragment.rectangle.width));
382
- const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, oppositeList, activeRects);
525
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, oppositeList, activeRects, {
526
+ expected: activeSpotlights,
527
+ opposite: activeSpotlights,
528
+ timeMs: outputTimeMs,
529
+ }, activeView);
383
530
  orderedChecks.push({
384
531
  order,
385
532
  entry: {
@@ -400,9 +547,13 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
400
547
  }
401
548
  {
402
549
  const clearEndIndex = item.end_frame;
403
- const order = enqueue(clearEndIndex, (finalFrame, baseFrame, covered, appPrimitives, timestampMs) => {
550
+ const order = enqueue(clearEndIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
404
551
  const oppositeList = [...appPrimitives[appIndex], ...settledPaints];
405
- const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, oppositeList, settledRects);
552
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, oppositeList, settledRects, {
553
+ expected: activeSpotlights,
554
+ opposite: activeSpotlights,
555
+ timeMs: outputTimeMs,
556
+ }, activeView);
406
557
  orderedChecks.push({
407
558
  order,
408
559
  entry: {
@@ -478,9 +629,10 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
478
629
  else {
479
630
  coverage.push(`${item.id}:wipe_in:frame_${midIn.frame}`);
480
631
  const { frame: wipeFrame, activeRects, clearRects } = midIn;
481
- const order = enqueue(wipeFrame, (finalFrame, baseFrame, covered, appPrimitives, timestampMs) => {
482
- const activeMetrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, [], activeRects);
483
- const clearMetrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, fullUnderlinePaints, clearRects);
632
+ const order = enqueue(wipeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
633
+ const spotOpts = { expected: activeSpotlights, opposite: activeSpotlights, timeMs: outputTimeMs };
634
+ const activeMetrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, [], activeRects, spotOpts, activeView);
635
+ const clearMetrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, fullUnderlinePaints, clearRects, spotOpts, activeView);
484
636
  const passed = activeMetrics.passed && clearMetrics.passed;
485
637
  orderedChecks.push({
486
638
  order,
@@ -531,9 +683,10 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
531
683
  else {
532
684
  coverage.push(`${item.id}:wipe_out:frame_${midOut.frame}`);
533
685
  const { frame: wipeFrame, activeRects, clearRects } = midOut;
534
- const order = enqueue(wipeFrame, (finalFrame, baseFrame, covered, appPrimitives, timestampMs) => {
535
- const activeMetrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, [], activeRects);
536
- const clearMetrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, fullUnderlinePaints, clearRects);
686
+ const order = enqueue(wipeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
687
+ const spotOpts = { expected: activeSpotlights, opposite: activeSpotlights, timeMs: outputTimeMs };
688
+ const activeMetrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, [], activeRects, spotOpts, activeView);
689
+ const clearMetrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, fullUnderlinePaints, clearRects, spotOpts, activeView);
537
690
  const passed = activeMetrics.passed && clearMetrics.passed;
538
691
  orderedChecks.push({
539
692
  order,
@@ -560,6 +713,927 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
560
713
  }
561
714
  break;
562
715
  }
716
+ case 'spotlight': {
717
+ const lastAvailable = Math.min(item.end_frame, totalFrames) - 1;
718
+ const settledFirst = item.in_ms > 0 ? Math.ceil((item.start_ms + item.in_ms) * video.fps / 1000 - 1e-9) : item.first_frame;
719
+ const settledLast = item.out_ms > 0 ? Math.floor((item.end_ms - item.out_ms) * video.fps / 1000 + 1e-9) - 1 : item.end_frame - 1;
720
+ let activeStartFrame = settledFirst;
721
+ let activeEndFrame = Math.min(settledLast, lastAvailable);
722
+ if (activeStartFrame > activeEndFrame) {
723
+ let bestFrame = item.first_frame;
724
+ let bestFade = -1;
725
+ for (let frame = item.first_frame; frame <= lastAvailable; frame++) {
726
+ const fade = spotlightFadeFraction(item, frame * 1000 / video.fps);
727
+ if (fade > bestFade) {
728
+ bestFade = fade;
729
+ bestFrame = frame;
730
+ }
731
+ }
732
+ activeStartFrame = bestFrame;
733
+ activeEndFrame = bestFrame;
734
+ }
735
+ const alwaysSettledItem = {
736
+ ...item,
737
+ start_ms: -Infinity,
738
+ end_ms: Infinity,
739
+ in_ms: 0,
740
+ out_ms: 0,
741
+ };
742
+ const exteriorAccept = (spots) => (px, py) => !spots.some(s => s.apertures.some(ap => pointInExpandedAperture(ap, s.softness_px + 2, px, py)));
743
+ const otherMaxDimAt = (spots, timeMs) => {
744
+ let m = 0;
745
+ for (const s of spots) {
746
+ if (s.id === item.id)
747
+ continue;
748
+ const d = s.opacity * spotlightFadeFraction(s, timeMs);
749
+ if (d > m)
750
+ m = d;
751
+ }
752
+ return m;
753
+ };
754
+ const clipToSlide = (rect) => {
755
+ const sb = item.slide_bounds;
756
+ const x = Math.max(sb.x, rect.x);
757
+ const y = Math.max(sb.y, rect.y);
758
+ const right = Math.min(sb.x + sb.width, rect.x + rect.width);
759
+ const bottom = Math.min(sb.y + sb.height, rect.y + rect.height);
760
+ return { x, y, width: Math.max(0, right - x), height: Math.max(0, bottom - y) };
761
+ };
762
+ const allApertureRects = item.apertures.map(ap => clipToSlide(spotlightApertureBounds(ap)));
763
+ const insideItemCore = (px, py) => item.apertures.some(ap => pointInExpandedAperture(ap, -2, px, py));
764
+ requiredActiveParts.push({ id: item.id, part: 'dim' });
765
+ coverage.push(`${item.id}:dim:start,end`);
766
+ if (item.first_frame - 1 >= 0) {
767
+ const clearStartIndex = item.first_frame - 1;
768
+ const order = enqueue(clearStartIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
769
+ const oppositeSpots = [...activeSpotlights, alwaysSettledItem];
770
+ const otherDim = otherMaxDimAt(activeSpotlights, outputTimeMs);
771
+ const useApertureDiff = otherDim >= item.opacity * 0.85;
772
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, appPrimitives[appIndex], useApertureDiff ? allApertureRects : [item.slide_bounds], {
773
+ expected: activeSpotlights,
774
+ opposite: oppositeSpots,
775
+ timeMs: outputTimeMs,
776
+ acceptPixel: useApertureDiff ? insideItemCore : exteriorAccept(oppositeSpots),
777
+ }, activeView);
778
+ orderedChecks.push({
779
+ order,
780
+ entry: {
781
+ annotation: item.id,
782
+ part: 'dim',
783
+ boundary: 'start',
784
+ frame_index: clearStartIndex,
785
+ encoded_ms: timestampMs,
786
+ expected_active: false,
787
+ expected_error: metrics.expected_error,
788
+ opposite_error: metrics.opposite_error,
789
+ contrast: metrics.contrast,
790
+ passed: metrics.passed,
791
+ },
792
+ gap: metrics.passed ? undefined : `${item.id}:dim:start: frame ${clearStartIndex} does not distinguish the expected spotlight state from its opposite`,
793
+ });
794
+ });
795
+ }
796
+ {
797
+ const activeIndex = activeStartFrame;
798
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
799
+ const withoutItem = activeSpotlights.filter(s => s.id !== item.id);
800
+ const otherDim = otherMaxDimAt(activeSpotlights, outputTimeMs);
801
+ const currentDim = item.opacity * spotlightFadeFraction(item, outputTimeMs);
802
+ const useApertureDiff = otherDim >= currentDim * 0.85 && otherDim > 0;
803
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, appPrimitives[appIndex], useApertureDiff ? allApertureRects : [item.slide_bounds], {
804
+ expected: activeSpotlights,
805
+ opposite: withoutItem,
806
+ timeMs: outputTimeMs,
807
+ acceptPixel: useApertureDiff ? insideItemCore : exteriorAccept(activeSpotlights),
808
+ }, activeView);
809
+ orderedChecks.push({
810
+ order,
811
+ entry: {
812
+ annotation: item.id,
813
+ part: 'dim',
814
+ boundary: 'start',
815
+ frame_index: activeIndex,
816
+ encoded_ms: timestampMs,
817
+ expected_active: true,
818
+ expected_error: metrics.expected_error,
819
+ opposite_error: metrics.opposite_error,
820
+ contrast: metrics.contrast,
821
+ passed: metrics.passed,
822
+ },
823
+ gap: metrics.passed ? undefined : `${item.id}:dim:start: frame ${activeIndex} does not distinguish the expected spotlight state from its opposite`,
824
+ });
825
+ });
826
+ }
827
+ checkBoundaryTimestamp(item.id, 'start', item.first_frame, item.start_ms);
828
+ if (item.end_frame >= totalFrames) {
829
+ gaps.push(`${item.id}:end: no encoded frame exists after this boundary`);
830
+ }
831
+ else {
832
+ {
833
+ const activeIndex = activeEndFrame;
834
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
835
+ const withoutItem = activeSpotlights.filter(s => s.id !== item.id);
836
+ const otherDim = otherMaxDimAt(activeSpotlights, outputTimeMs);
837
+ const currentDim = item.opacity * spotlightFadeFraction(item, outputTimeMs);
838
+ const useApertureDiff = otherDim >= currentDim * 0.85 && otherDim > 0;
839
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, appPrimitives[appIndex], useApertureDiff ? allApertureRects : [item.slide_bounds], {
840
+ expected: activeSpotlights,
841
+ opposite: withoutItem,
842
+ timeMs: outputTimeMs,
843
+ acceptPixel: useApertureDiff ? insideItemCore : exteriorAccept(activeSpotlights),
844
+ }, activeView);
845
+ orderedChecks.push({
846
+ order,
847
+ entry: {
848
+ annotation: item.id,
849
+ part: 'dim',
850
+ boundary: 'end',
851
+ frame_index: activeIndex,
852
+ encoded_ms: timestampMs,
853
+ expected_active: true,
854
+ expected_error: metrics.expected_error,
855
+ opposite_error: metrics.opposite_error,
856
+ contrast: metrics.contrast,
857
+ passed: metrics.passed,
858
+ },
859
+ gap: metrics.passed ? undefined : `${item.id}:dim:end: frame ${activeIndex} does not distinguish the expected spotlight state from its opposite`,
860
+ });
861
+ });
862
+ }
863
+ {
864
+ const clearEndIndex = item.end_frame;
865
+ const order = enqueue(clearEndIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
866
+ const oppositeSpots = [...activeSpotlights, alwaysSettledItem];
867
+ const otherDim = otherMaxDimAt(activeSpotlights, outputTimeMs);
868
+ const useApertureDiff = otherDim >= item.opacity * 0.85;
869
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, appPrimitives[appIndex], useApertureDiff ? allApertureRects : [item.slide_bounds], {
870
+ expected: activeSpotlights,
871
+ opposite: oppositeSpots,
872
+ timeMs: outputTimeMs,
873
+ acceptPixel: useApertureDiff ? insideItemCore : exteriorAccept(oppositeSpots),
874
+ }, activeView);
875
+ orderedChecks.push({
876
+ order,
877
+ entry: {
878
+ annotation: item.id,
879
+ part: 'dim',
880
+ boundary: 'end',
881
+ frame_index: clearEndIndex,
882
+ encoded_ms: timestampMs,
883
+ expected_active: false,
884
+ expected_error: metrics.expected_error,
885
+ opposite_error: metrics.opposite_error,
886
+ contrast: metrics.contrast,
887
+ passed: metrics.passed,
888
+ },
889
+ gap: metrics.passed ? undefined : `${item.id}:dim:end: frame ${clearEndIndex} does not distinguish the expected spotlight state from its opposite`,
890
+ });
891
+ });
892
+ }
893
+ checkBoundaryTimestamp(item.id, 'end', item.end_frame, item.end_ms);
894
+ }
895
+ for (const [apIndex, aperture] of item.apertures.entries()) {
896
+ const suffix = item.apertures.length === 1 ? '' : `:${apIndex}`;
897
+ const part = `aperture${suffix}`;
898
+ requiredActiveParts.push({ id: item.id, part });
899
+ const rect = clipToSlide(spotlightApertureBounds(aperture));
900
+ const insideSingle = (px, py) => pointInExpandedAperture(aperture, -2, px, py);
901
+ const unpunchedFrom = (spots) => spots.map(s => s.id === item.id
902
+ ? { ...s, apertures: s.apertures.filter((_, idx) => idx !== apIndex) }
903
+ : s);
904
+ coverage.push(`${item.id}:${part}:active`);
905
+ {
906
+ const activeIndex = activeStartFrame;
907
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
908
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, appPrimitives[appIndex], [rect], {
909
+ expected: activeSpotlights,
910
+ opposite: unpunchedFrom(activeSpotlights),
911
+ timeMs: outputTimeMs,
912
+ acceptPixel: insideSingle,
913
+ }, activeView);
914
+ orderedChecks.push({
915
+ order,
916
+ entry: {
917
+ annotation: item.id,
918
+ part,
919
+ boundary: 'start',
920
+ frame_index: activeIndex,
921
+ encoded_ms: timestampMs,
922
+ expected_active: true,
923
+ expected_error: metrics.expected_error,
924
+ opposite_error: metrics.opposite_error,
925
+ contrast: metrics.contrast,
926
+ passed: metrics.passed,
927
+ },
928
+ gap: metrics.passed ? undefined : `${item.id}:${part}:start: frame ${activeIndex} does not preserve bright interior inside spotlight aperture`,
929
+ });
930
+ });
931
+ }
932
+ if (item.end_frame < totalFrames && activeEndFrame !== activeStartFrame) {
933
+ const activeIndex = activeEndFrame;
934
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
935
+ const metrics = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, appPrimitives[appIndex], [rect], {
936
+ expected: activeSpotlights,
937
+ opposite: unpunchedFrom(activeSpotlights),
938
+ timeMs: outputTimeMs,
939
+ acceptPixel: insideSingle,
940
+ }, activeView);
941
+ orderedChecks.push({
942
+ order,
943
+ entry: {
944
+ annotation: item.id,
945
+ part,
946
+ boundary: 'end',
947
+ frame_index: activeIndex,
948
+ encoded_ms: timestampMs,
949
+ expected_active: true,
950
+ expected_error: metrics.expected_error,
951
+ opposite_error: metrics.opposite_error,
952
+ contrast: metrics.contrast,
953
+ passed: metrics.passed,
954
+ },
955
+ gap: metrics.passed ? undefined : `${item.id}:${part}:end: frame ${activeIndex} does not preserve bright interior inside spotlight aperture`,
956
+ });
957
+ });
958
+ }
959
+ }
960
+ const scheduleFadeCheck = (kind, durationMs) => {
961
+ let midFrame;
962
+ let bestDist = Infinity;
963
+ for (let frame = item.first_frame; frame <= lastAvailable; frame++) {
964
+ const timeMs = frame * 1000 / video.fps;
965
+ if (kind === 'fade_in' && timeMs >= item.start_ms + durationMs)
966
+ break;
967
+ if (kind === 'fade_out' && timeMs <= item.end_ms - durationMs)
968
+ continue;
969
+ const fade = spotlightFadeFraction(item, timeMs);
970
+ if (fade >= 0.15 && fade <= 0.85) {
971
+ const dist = Math.abs(fade - 0.5);
972
+ if (dist < bestDist) {
973
+ bestDist = dist;
974
+ midFrame = frame;
975
+ }
976
+ }
977
+ }
978
+ if (midFrame === undefined) {
979
+ coverage.push(`${item.id}:${kind}:unobservable_at_${video.fps}fps`);
980
+ gaps.push(`${item.id}:dim:${kind}: ${kind} (${durationMs} ms) has no observable partial frame at ${video.fps} fps`);
981
+ return;
982
+ }
983
+ coverage.push(`${item.id}:${kind}:frame_${midFrame}`);
984
+ const fadeFrame = midFrame;
985
+ const order = enqueue(fadeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
986
+ const withoutItem = activeSpotlights.filter(s => s.id !== item.id);
987
+ const settledSpots = activeSpotlights.map(s => s.id === item.id ? alwaysSettledItem : s);
988
+ const otherDim = otherMaxDimAt(activeSpotlights, outputTimeMs);
989
+ const useApertureDiff = otherDim >= item.opacity * 0.85;
990
+ const sampleRects = useApertureDiff ? allApertureRects : [item.slide_bounds];
991
+ const accept = useApertureDiff ? insideItemCore : exteriorAccept(settledSpots);
992
+ const vsInactive = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, appPrimitives[appIndex], sampleRects, {
993
+ expected: activeSpotlights,
994
+ opposite: withoutItem,
995
+ timeMs: outputTimeMs,
996
+ acceptPixel: accept,
997
+ }, activeView);
998
+ const vsSettled = measureRegion(finalFrame, baseFrame, video, covered, appPrimitives, appIndex, appPrimitives[appIndex], sampleRects, {
999
+ expected: activeSpotlights,
1000
+ opposite: settledSpots,
1001
+ timeMs: outputTimeMs,
1002
+ acceptPixel: accept,
1003
+ }, activeView);
1004
+ const passed = vsInactive.passed && vsSettled.passed;
1005
+ orderedChecks.push({
1006
+ order,
1007
+ entry: {
1008
+ annotation: item.id,
1009
+ part: 'dim',
1010
+ boundary: kind,
1011
+ frame_index: fadeFrame,
1012
+ encoded_ms: timestampMs,
1013
+ expected_active: 'partial',
1014
+ expected_error: vsInactive.expected_error,
1015
+ inactive_opposite_error: vsInactive.opposite_error,
1016
+ settled_opposite_error: vsSettled.opposite_error,
1017
+ contrast: vsInactive.contrast !== null && vsSettled.contrast !== null
1018
+ ? Math.min(vsInactive.contrast, vsSettled.contrast)
1019
+ : null,
1020
+ passed,
1021
+ },
1022
+ gap: passed ? undefined : `${item.id}:dim:${kind}: frame ${fadeFrame} does not prove partial spotlight ${kind.replace('_', '-')} progression`,
1023
+ });
1024
+ });
1025
+ };
1026
+ if (item.in_ms > 0)
1027
+ scheduleFadeCheck('fade_in', item.in_ms);
1028
+ if (item.out_ms > 0)
1029
+ scheduleFadeCheck('fade_out', item.out_ms);
1030
+ break;
1031
+ }
1032
+ case 'zoom': {
1033
+ const lastAvailable = Math.min(item.end_frame, totalFrames) - 1;
1034
+ const settledFirst = item.in_ms > 0 ? Math.ceil((item.start_ms + item.in_ms) * video.fps / 1000 - 1e-9) : item.first_frame;
1035
+ const settledLast = item.out_ms > 0 ? Math.floor((item.end_ms - item.out_ms) * video.fps / 1000 + 1e-9) - 1 : item.end_frame - 1;
1036
+ let activeStartFrame = settledFirst;
1037
+ let activeEndFrame = Math.min(settledLast, lastAvailable);
1038
+ if (activeStartFrame > activeEndFrame) {
1039
+ let bestFrame = item.first_frame;
1040
+ let bestProgress = -1;
1041
+ for (let frame = item.first_frame; frame <= lastAvailable; frame++) {
1042
+ const p = zoomProgress(item, frame * 1000 / video.fps);
1043
+ if (p > bestProgress) {
1044
+ bestProgress = p;
1045
+ bestFrame = frame;
1046
+ }
1047
+ }
1048
+ activeStartFrame = bestFrame;
1049
+ activeEndFrame = bestFrame;
1050
+ }
1051
+ const settledView = evaluateViewTransform({ ...item, start_ms: -Infinity, end_ms: Infinity, in_ms: 0, out_ms: 0 }, 0);
1052
+ requiredActiveParts.push({ id: item.id, part: 'view' });
1053
+ coverage.push(`${item.id}:view:start,end`);
1054
+ if (item.first_frame - 1 >= 0) {
1055
+ const clearStartIndex = item.first_frame - 1;
1056
+ const order = enqueue(clearStartIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
1057
+ const metrics = measureZoomRegion(finalFrame, baseFrame, video, covered, appPrimitives, activeSpotlights, outputTimeMs, item.slide_bounds, activeView, settledView);
1058
+ orderedChecks.push({
1059
+ order,
1060
+ entry: {
1061
+ annotation: item.id,
1062
+ part: 'view',
1063
+ boundary: 'start',
1064
+ frame_index: clearStartIndex,
1065
+ encoded_ms: timestampMs,
1066
+ expected_active: false,
1067
+ expected_error: metrics.expected_error,
1068
+ opposite_error: metrics.opposite_error,
1069
+ contrast: metrics.contrast,
1070
+ passed: metrics.passed,
1071
+ },
1072
+ gap: metrics.passed ? undefined : `${item.id}:view:start: frame ${clearStartIndex} does not distinguish unzoomed view from zoomed state`,
1073
+ });
1074
+ });
1075
+ }
1076
+ {
1077
+ const activeIndex = activeStartFrame;
1078
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
1079
+ const metrics = measureZoomRegion(finalFrame, baseFrame, video, covered, appPrimitives, activeSpotlights, outputTimeMs, item.slide_bounds, activeView, undefined);
1080
+ orderedChecks.push({
1081
+ order,
1082
+ entry: {
1083
+ annotation: item.id,
1084
+ part: 'view',
1085
+ boundary: 'start',
1086
+ frame_index: activeIndex,
1087
+ encoded_ms: timestampMs,
1088
+ expected_active: true,
1089
+ expected_error: metrics.expected_error,
1090
+ opposite_error: metrics.opposite_error,
1091
+ contrast: metrics.contrast,
1092
+ passed: metrics.passed,
1093
+ },
1094
+ gap: metrics.passed ? undefined : `${item.id}:view:start: frame ${activeIndex} does not distinguish zoomed view from unzoomed state`,
1095
+ });
1096
+ });
1097
+ }
1098
+ checkBoundaryTimestamp(item.id, 'start', item.first_frame, item.start_ms);
1099
+ if (item.end_frame >= totalFrames) {
1100
+ gaps.push(`${item.id}:end: no encoded frame exists after this boundary`);
1101
+ }
1102
+ else {
1103
+ {
1104
+ const activeIndex = activeEndFrame;
1105
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
1106
+ const metrics = measureZoomRegion(finalFrame, baseFrame, video, covered, appPrimitives, activeSpotlights, outputTimeMs, item.slide_bounds, activeView, undefined);
1107
+ orderedChecks.push({
1108
+ order,
1109
+ entry: {
1110
+ annotation: item.id,
1111
+ part: 'view',
1112
+ boundary: 'end',
1113
+ frame_index: activeIndex,
1114
+ encoded_ms: timestampMs,
1115
+ expected_active: true,
1116
+ expected_error: metrics.expected_error,
1117
+ opposite_error: metrics.opposite_error,
1118
+ contrast: metrics.contrast,
1119
+ passed: metrics.passed,
1120
+ },
1121
+ gap: metrics.passed ? undefined : `${item.id}:view:end: frame ${activeIndex} does not distinguish zoomed view from unzoomed state`,
1122
+ });
1123
+ });
1124
+ }
1125
+ {
1126
+ const clearEndIndex = item.end_frame;
1127
+ const order = enqueue(clearEndIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
1128
+ const metrics = measureZoomRegion(finalFrame, baseFrame, video, covered, appPrimitives, activeSpotlights, outputTimeMs, item.slide_bounds, activeView, settledView);
1129
+ orderedChecks.push({
1130
+ order,
1131
+ entry: {
1132
+ annotation: item.id,
1133
+ part: 'view',
1134
+ boundary: 'end',
1135
+ frame_index: clearEndIndex,
1136
+ encoded_ms: timestampMs,
1137
+ expected_active: false,
1138
+ expected_error: metrics.expected_error,
1139
+ opposite_error: metrics.opposite_error,
1140
+ contrast: metrics.contrast,
1141
+ passed: metrics.passed,
1142
+ },
1143
+ gap: metrics.passed ? undefined : `${item.id}:view:end: frame ${clearEndIndex} does not distinguish returned unzoomed view from zoomed state`,
1144
+ });
1145
+ });
1146
+ }
1147
+ checkBoundaryTimestamp(item.id, 'end', item.end_frame, item.end_ms);
1148
+ }
1149
+ const scheduleEaseCheck = (kind, durationMs) => {
1150
+ let midFrame;
1151
+ let bestDist = Infinity;
1152
+ for (let frame = item.first_frame; frame <= lastAvailable; frame++) {
1153
+ const timeMs = frame * 1000 / video.fps;
1154
+ if (kind === 'ease_in' && timeMs >= item.start_ms + durationMs)
1155
+ break;
1156
+ if (kind === 'ease_out' && timeMs <= item.end_ms - durationMs)
1157
+ continue;
1158
+ const p = zoomProgress(item, timeMs);
1159
+ if (p >= 0.15 && p <= 0.85) {
1160
+ const dist = Math.abs(p - 0.5);
1161
+ if (dist < bestDist) {
1162
+ bestDist = dist;
1163
+ midFrame = frame;
1164
+ }
1165
+ }
1166
+ }
1167
+ if (midFrame === undefined) {
1168
+ coverage.push(`${item.id}:${kind}:unobservable_at_${video.fps}fps`);
1169
+ gaps.push(`${item.id}:view:${kind}: ${kind} (${durationMs} ms) has no observable partial frame at ${video.fps} fps`);
1170
+ return;
1171
+ }
1172
+ coverage.push(`${item.id}:${kind}:frame_${midFrame}`);
1173
+ const easeFrame = midFrame;
1174
+ const order = enqueue(easeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs) => {
1175
+ const vsUnzoomed = measureZoomRegion(finalFrame, baseFrame, video, covered, appPrimitives, activeSpotlights, outputTimeMs, item.slide_bounds, activeView, undefined);
1176
+ const vsSettled = measureZoomRegion(finalFrame, baseFrame, video, covered, appPrimitives, activeSpotlights, outputTimeMs, item.slide_bounds, activeView, settledView);
1177
+ const passed = vsUnzoomed.passed && vsSettled.passed;
1178
+ orderedChecks.push({
1179
+ order,
1180
+ entry: {
1181
+ annotation: item.id,
1182
+ part: 'view',
1183
+ boundary: kind,
1184
+ frame_index: easeFrame,
1185
+ encoded_ms: timestampMs,
1186
+ expected_active: 'partial',
1187
+ expected_error: vsUnzoomed.expected_error,
1188
+ unzoomed_opposite_error: vsUnzoomed.opposite_error,
1189
+ settled_opposite_error: vsSettled.opposite_error,
1190
+ contrast: vsUnzoomed.contrast !== null && vsSettled.contrast !== null
1191
+ ? Math.min(vsUnzoomed.contrast, vsSettled.contrast)
1192
+ : null,
1193
+ passed,
1194
+ },
1195
+ gap: passed ? undefined : `${item.id}:view:${kind}: frame ${easeFrame} does not prove partial zoom ${kind.replace('_', '-')} progression`,
1196
+ });
1197
+ });
1198
+ };
1199
+ if (item.in_ms > 0)
1200
+ scheduleEaseCheck('ease_in', item.in_ms);
1201
+ if (item.out_ms > 0)
1202
+ scheduleEaseCheck('ease_out', item.out_ms);
1203
+ break;
1204
+ }
1205
+ case 'laser': {
1206
+ const lastAvailable = Math.min(item.end_frame, totalFrames) - 1;
1207
+ const settledFirst = item.in_ms > 0 ? Math.ceil((item.start_ms + item.in_ms) * video.fps / 1000 - 1e-9) : item.first_frame;
1208
+ const settledLast = item.out_ms > 0 ? Math.floor((item.end_ms - item.out_ms) * video.fps / 1000 + 1e-9) - 1 : item.end_frame - 1;
1209
+ let activeStartFrame = settledFirst;
1210
+ let activeEndFrame = Math.min(settledLast, lastAvailable);
1211
+ if (activeStartFrame > activeEndFrame) {
1212
+ let bestFrame = item.first_frame;
1213
+ let bestFade = -1;
1214
+ for (let frame = item.first_frame; frame <= lastAvailable; frame++) {
1215
+ const fade = laserFadeFraction(item, frame * 1000 / video.fps);
1216
+ if (fade > bestFade) {
1217
+ bestFade = fade;
1218
+ bestFrame = frame;
1219
+ }
1220
+ }
1221
+ activeStartFrame = bestFrame;
1222
+ activeEndFrame = bestFrame;
1223
+ }
1224
+ const settledLaser = {
1225
+ ...item,
1226
+ in_ms: 0,
1227
+ out_ms: 0,
1228
+ };
1229
+ const measureLaserDisk = (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, sampleTimeMs, expectedActive, activeLasers, activeStamps) => {
1230
+ const laserForSample = expectedActive ? item : settledLaser;
1231
+ const pos = evaluateLaserPosition(laserForSample, sampleTimeMs);
1232
+ const r = Math.max(1, item.radius_px - (item.radius_px >= 5 ? 1.5 : 0.5));
1233
+ const slideRect = { x: pos.x - r, y: pos.y - r, width: r * 2, height: r * 2 };
1234
+ const outRect = activeView ? forwardTransformRect(activeView, slideRect) : slideRect;
1235
+ const left = Math.max(0, Math.ceil(outRect.x));
1236
+ const right = Math.min(video.width, Math.floor(outRect.x + outRect.width));
1237
+ const top = Math.max(0, Math.ceil(outRect.y));
1238
+ const bottom = Math.min(video.height, Math.floor(outRect.y + outRect.height));
1239
+ const rw = right - left;
1240
+ const rh = bottom - top;
1241
+ let stampRgba;
1242
+ if (activeStamps.length > 0 && rw > 0 && rh > 0) {
1243
+ ensureStampFonts();
1244
+ const stampCanvas = createCanvas(rw, rh);
1245
+ const sctx = stampCanvas.getContext('2d');
1246
+ sctx.translate(-left, -top);
1247
+ if (activeView) {
1248
+ const { content: c, source: s, scale } = activeView;
1249
+ sctx.beginPath();
1250
+ sctx.rect(c.x, c.y, c.width, c.height);
1251
+ sctx.clip();
1252
+ sctx.translate(c.x, c.y);
1253
+ sctx.scale(scale, scale);
1254
+ sctx.translate(-s.x, -s.y);
1255
+ }
1256
+ for (const entry of activeStamps)
1257
+ paintStamp(sctx, entry.effect, outputTimeMs);
1258
+ stampRgba = sctx.getImageData(0, 0, rw, rh).data;
1259
+ }
1260
+ const otherLasers = activeLasers
1261
+ .filter(entry => entry.effect.id !== item.id)
1262
+ .map(entry => ({ ...entry, dirty: laserDirtyBounds(entry.effect, outputTimeMs) }));
1263
+ let expectedError = 0;
1264
+ let oppositeError = 0;
1265
+ let contrast = 0;
1266
+ let count = 0;
1267
+ for (let y = top; y < bottom; y++) {
1268
+ for (let x = left; x < right; x++) {
1269
+ const px = x + 0.5;
1270
+ const py = y + 0.5;
1271
+ if (covered.some(bounds => inside(bounds, px, py)))
1272
+ continue;
1273
+ const pt = activeView ? inverseTransformPoint(activeView, px, py) : { x: px, y: py };
1274
+ if (Math.hypot(pt.x - pos.x, pt.y - pos.y) > r)
1275
+ continue;
1276
+ const dot = laserDotSample(laserForSample, sampleTimeMs, pt.x, pt.y);
1277
+ if (dot.alpha <= 1e-6)
1278
+ continue;
1279
+ let perturbedByOtherHalo = false;
1280
+ const belowDots = [];
1281
+ const aboveDots = [];
1282
+ for (const other of otherLasers) {
1283
+ const otherDot = laserDotSample(other.effect, outputTimeMs, pt.x, pt.y);
1284
+ if (otherDot.alpha > 1e-6) {
1285
+ if (other.index < appIndex)
1286
+ belowDots.push(otherDot);
1287
+ else
1288
+ aboveDots.push(otherDot);
1289
+ }
1290
+ else if (other.dirty && inside(other.dirty, pt.x, pt.y)) {
1291
+ perturbedByOtherHalo = true;
1292
+ break;
1293
+ }
1294
+ }
1295
+ if (perturbedByOtherHalo)
1296
+ continue;
1297
+ const mask = activeSpotlights.length > 0 ? spotlightMaskSample(activeSpotlights, outputTimeMs, pt.x, pt.y) : undefined;
1298
+ const offset = (y * video.width + x) * 3;
1299
+ const sOffset = stampRgba ? ((y - top) * rw + (x - left)) * 4 : -1;
1300
+ const sAlpha = sOffset >= 0 ? stampRgba[sOffset + 3] / 255 : 0;
1301
+ for (const channel of [0, 1, 2]) {
1302
+ let bg = activeView
1303
+ ? sampleBilinearChannel(baseFrame, video.width, video.height, pt.x - 0.5, pt.y - 0.5, channel)
1304
+ : baseFrame[offset + channel];
1305
+ if (mask && mask.alpha > 0)
1306
+ bg = bg * (1 - mask.alpha) + mask.rgb[channel] * mask.alpha;
1307
+ for (const list of appPrimitives) {
1308
+ for (const primitive of list) {
1309
+ if (inside(primitive.rectangle, pt.x, pt.y))
1310
+ bg = blendChannel(bg, primitive, channel);
1311
+ }
1312
+ }
1313
+ if (sAlpha > 0)
1314
+ bg = bg * (1 - sAlpha) + stampRgba[sOffset + channel] * sAlpha;
1315
+ for (const otherDot of belowDots) {
1316
+ bg = bg * (1 - otherDot.alpha) + otherDot.rgb[channel] * otherDot.alpha;
1317
+ }
1318
+ let withLaser = bg * (1 - dot.alpha) + dot.rgb[channel] * dot.alpha;
1319
+ let withoutLaser = bg;
1320
+ for (const otherDot of aboveDots) {
1321
+ withLaser = withLaser * (1 - otherDot.alpha) + otherDot.rgb[channel] * otherDot.alpha;
1322
+ withoutLaser = withoutLaser * (1 - otherDot.alpha) + otherDot.rgb[channel] * otherDot.alpha;
1323
+ }
1324
+ const expected = expectedActive ? withLaser : withoutLaser;
1325
+ const opposite = expectedActive ? withoutLaser : withLaser;
1326
+ expectedError += Math.abs(finalFrame[offset + channel] - expected);
1327
+ oppositeError += Math.abs(finalFrame[offset + channel] - opposite);
1328
+ contrast += Math.abs(expected - opposite);
1329
+ count++;
1330
+ }
1331
+ }
1332
+ }
1333
+ const passed = count > 0 && contrast / count >= 6 && expectedError / count <= 22 && expectedError < oppositeError * 0.65;
1334
+ return {
1335
+ count,
1336
+ expected_error: count ? expectedError / count : null,
1337
+ opposite_error: count ? oppositeError / count : null,
1338
+ contrast: count ? contrast / count : null,
1339
+ passed,
1340
+ };
1341
+ };
1342
+ requiredActiveParts.push({ id: item.id, part: 'pointer' });
1343
+ coverage.push(`${item.id}:pointer:start,end`);
1344
+ if (item.first_frame - 1 >= 0) {
1345
+ const clearStartIndex = item.first_frame - 1;
1346
+ const startSampleMs = activeStartFrame * 1000 / video.fps;
1347
+ const order = enqueue(clearStartIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1348
+ const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, startSampleMs, false, activeLasers, activeStamps);
1349
+ orderedChecks.push({
1350
+ order,
1351
+ entry: {
1352
+ annotation: item.id,
1353
+ part: 'pointer',
1354
+ boundary: 'start',
1355
+ frame_index: clearStartIndex,
1356
+ encoded_ms: timestampMs,
1357
+ expected_active: false,
1358
+ expected_error: metrics.expected_error,
1359
+ opposite_error: metrics.opposite_error,
1360
+ contrast: metrics.contrast,
1361
+ passed: metrics.passed,
1362
+ },
1363
+ gap: metrics.passed ? undefined : `${item.id}:pointer:start: frame ${clearStartIndex} does not confirm laser is absent before start`,
1364
+ });
1365
+ });
1366
+ }
1367
+ {
1368
+ const activeIndex = activeStartFrame;
1369
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1370
+ const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps);
1371
+ orderedChecks.push({
1372
+ order,
1373
+ entry: {
1374
+ annotation: item.id,
1375
+ part: 'pointer',
1376
+ boundary: 'start',
1377
+ frame_index: activeIndex,
1378
+ encoded_ms: timestampMs,
1379
+ expected_active: true,
1380
+ expected_error: metrics.expected_error,
1381
+ opposite_error: metrics.opposite_error,
1382
+ contrast: metrics.contrast,
1383
+ passed: metrics.passed,
1384
+ },
1385
+ gap: metrics.passed ? undefined : `${item.id}:pointer:start: frame ${activeIndex} does not confirm laser pointer is visible`,
1386
+ });
1387
+ });
1388
+ }
1389
+ checkBoundaryTimestamp(item.id, 'start', item.first_frame, item.start_ms);
1390
+ if (item.end_frame >= totalFrames) {
1391
+ gaps.push(`${item.id}:end: no encoded frame exists after this boundary`);
1392
+ }
1393
+ else {
1394
+ {
1395
+ const activeIndex = activeEndFrame;
1396
+ const order = enqueue(activeIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1397
+ const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps);
1398
+ orderedChecks.push({
1399
+ order,
1400
+ entry: {
1401
+ annotation: item.id,
1402
+ part: 'pointer',
1403
+ boundary: 'end',
1404
+ frame_index: activeIndex,
1405
+ encoded_ms: timestampMs,
1406
+ expected_active: true,
1407
+ expected_error: metrics.expected_error,
1408
+ opposite_error: metrics.opposite_error,
1409
+ contrast: metrics.contrast,
1410
+ passed: metrics.passed,
1411
+ },
1412
+ gap: metrics.passed ? undefined : `${item.id}:pointer:end: frame ${activeIndex} does not confirm laser pointer is visible before end`,
1413
+ });
1414
+ });
1415
+ }
1416
+ {
1417
+ const clearEndIndex = item.end_frame;
1418
+ const endSampleMs = activeEndFrame * 1000 / video.fps;
1419
+ const order = enqueue(clearEndIndex, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1420
+ const metrics = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, endSampleMs, false, activeLasers, activeStamps);
1421
+ orderedChecks.push({
1422
+ order,
1423
+ entry: {
1424
+ annotation: item.id,
1425
+ part: 'pointer',
1426
+ boundary: 'end',
1427
+ frame_index: clearEndIndex,
1428
+ encoded_ms: timestampMs,
1429
+ expected_active: false,
1430
+ expected_error: metrics.expected_error,
1431
+ opposite_error: metrics.opposite_error,
1432
+ contrast: metrics.contrast,
1433
+ passed: metrics.passed,
1434
+ },
1435
+ gap: metrics.passed ? undefined : `${item.id}:pointer:end: frame ${clearEndIndex} does not confirm laser pointer cleared after end`,
1436
+ });
1437
+ });
1438
+ }
1439
+ checkBoundaryTimestamp(item.id, 'end', item.end_frame, item.end_ms);
1440
+ }
1441
+ if (item.total_length >= item.radius_px * 2 + 8 && activeEndFrame > activeStartFrame) {
1442
+ const startPos = evaluateLaserPosition(item, activeStartFrame * 1000 / video.fps);
1443
+ const midFrame = Math.floor((activeStartFrame + activeEndFrame) / 2);
1444
+ const midTimeMs = midFrame * 1000 / video.fps;
1445
+ const midPos = evaluateLaserPosition(item, midTimeMs);
1446
+ if (Math.hypot(midPos.x - startPos.x, midPos.y - startPos.y) >= item.radius_px * 2 + 6) {
1447
+ coverage.push(`${item.id}:movement:frame_${midFrame}`);
1448
+ const startTimeMs = activeStartFrame * 1000 / video.fps;
1449
+ const checkStartCleared = midTimeMs - startTimeMs > item.trail_ms + 1000 / video.fps;
1450
+ const order = enqueue(midFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1451
+ const atMid = measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps);
1452
+ const atStart = checkStartCleared
1453
+ ? measureLaserDisk(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, startTimeMs, false, activeLasers, activeStamps)
1454
+ : { passed: true, expected_error: null, opposite_error: null, contrast: null };
1455
+ const passed = atMid.passed && atStart.passed;
1456
+ orderedChecks.push({
1457
+ order,
1458
+ entry: {
1459
+ annotation: item.id,
1460
+ part: 'pointer',
1461
+ boundary: 'movement',
1462
+ frame_index: midFrame,
1463
+ encoded_ms: timestampMs,
1464
+ expected_active: true,
1465
+ expected_error: atMid.expected_error,
1466
+ opposite_error: atMid.opposite_error,
1467
+ start_cleared_error: atStart.expected_error,
1468
+ contrast: atMid.contrast,
1469
+ passed,
1470
+ },
1471
+ gap: passed ? undefined : `${item.id}:pointer:movement: frame ${midFrame} does not confirm laser movement along path`,
1472
+ });
1473
+ });
1474
+ }
1475
+ }
1476
+ break;
1477
+ }
1478
+ case 'stamp': {
1479
+ ensureStampFonts();
1480
+ requiredActiveParts.push({ id: item.id, part: 'stamp' });
1481
+ const settleFrame = item.motion_type !== 'none' && item.in_ms > 0
1482
+ ? Math.min(item.end_frame - 1, Math.ceil((item.start_ms + item.in_ms) * video.fps / 1000 - 1e-9))
1483
+ : item.first_frame;
1484
+ const activeFrame = Math.max(item.first_frame, Math.min(item.end_frame - 1, settleFrame));
1485
+ const measureStampPresence = (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, sampleTimeMs, expectedActive, activeLasers, activeStamps) => {
1486
+ const bounds = stampDirtyBounds(item, sampleTimeMs);
1487
+ if (!bounds)
1488
+ return { passed: !expectedActive, expected_error: null, opposite_error: null, contrast: null };
1489
+ const outputBounds = activeView ? forwardTransformRect(activeView, bounds) : bounds;
1490
+ const x0 = Math.max(0, Math.floor(outputBounds.x));
1491
+ const y0 = Math.max(0, Math.floor(outputBounds.y));
1492
+ const x1 = Math.min(video.width, Math.ceil(outputBounds.x + outputBounds.width));
1493
+ const y1 = Math.min(video.height, Math.ceil(outputBounds.y + outputBounds.height));
1494
+ const rw = x1 - x0;
1495
+ const rh = y1 - y0;
1496
+ if (rw < 2 || rh < 2)
1497
+ return { passed: false, expected_error: null, opposite_error: null, contrast: null };
1498
+ const renderTopLayer = (includeSelf, onlySelf = false) => {
1499
+ const canvas = createCanvas(rw, rh);
1500
+ const ctx = canvas.getContext('2d');
1501
+ ctx.translate(-x0, -y0);
1502
+ if (activeView) {
1503
+ const { content: c, source: s, scale } = activeView;
1504
+ ctx.beginPath();
1505
+ ctx.rect(c.x, c.y, c.width, c.height);
1506
+ ctx.clip();
1507
+ ctx.translate(c.x, c.y);
1508
+ ctx.scale(scale, scale);
1509
+ ctx.translate(-s.x, -s.y);
1510
+ }
1511
+ if (onlySelf) {
1512
+ paintStamp(ctx, item, sampleTimeMs);
1513
+ }
1514
+ else {
1515
+ let paintedSelf = false;
1516
+ for (const entry of activeStamps) {
1517
+ if (entry.index === appIndex) {
1518
+ if (includeSelf) {
1519
+ paintStamp(ctx, item, sampleTimeMs);
1520
+ paintedSelf = true;
1521
+ }
1522
+ continue;
1523
+ }
1524
+ if (includeSelf && !paintedSelf && entry.index > appIndex) {
1525
+ paintStamp(ctx, item, sampleTimeMs);
1526
+ paintedSelf = true;
1527
+ }
1528
+ paintStamp(ctx, entry.effect, outputTimeMs);
1529
+ }
1530
+ if (includeSelf && !paintedSelf)
1531
+ paintStamp(ctx, item, sampleTimeMs);
1532
+ for (const entry of activeLasers) {
1533
+ paintLaser(ctx, entry.effect, outputTimeMs);
1534
+ }
1535
+ }
1536
+ return ctx.getImageData(0, 0, rw, rh).data;
1537
+ };
1538
+ const hasOtherTop = activeLasers.length > 0 || activeStamps.some(entry => entry.index !== appIndex);
1539
+ const selfRgba = renderTopLayer(true, true);
1540
+ const withRgba = hasOtherTop ? renderTopLayer(true) : selfRgba;
1541
+ const withoutRgba = hasOtherTop ? renderTopLayer(false) : undefined;
1542
+ const stepX = Math.max(1, Math.floor(rw / 64));
1543
+ const stepY = Math.max(1, Math.floor(rh / 48));
1544
+ let expectedError = 0;
1545
+ let oppositeError = 0;
1546
+ let contrast = 0;
1547
+ let count = 0;
1548
+ for (let ly = 0; ly < rh; ly += stepY) {
1549
+ for (let lx = 0; lx < rw; lx += stepX) {
1550
+ const pOffset = (ly * rw + lx) * 4;
1551
+ const selfAlpha = selfRgba[pOffset + 3] / 255;
1552
+ if (selfAlpha < 0.25)
1553
+ continue;
1554
+ const x = x0 + lx;
1555
+ const y = y0 + ly;
1556
+ const px = x + 0.5;
1557
+ const py = y + 0.5;
1558
+ if (covered.some(rect => inside(rect, px, py)))
1559
+ continue;
1560
+ const pt = activeView ? inverseTransformPoint(activeView, px, py) : { x: px, y: py };
1561
+ const mask = activeSpotlights.length > 0 ? spotlightMaskSample(activeSpotlights, outputTimeMs, pt.x, pt.y) : undefined;
1562
+ const offset = (y * video.width + x) * 3;
1563
+ const withAlpha = withRgba[pOffset + 3] / 255;
1564
+ const withoutAlpha = withoutRgba ? withoutRgba[pOffset + 3] / 255 : 0;
1565
+ for (const channel of [0, 1, 2]) {
1566
+ let under = activeView
1567
+ ? sampleBilinearChannel(baseFrame, video.width, video.height, pt.x - 0.5, pt.y - 0.5, channel)
1568
+ : baseFrame[offset + channel];
1569
+ if (mask && mask.alpha > 0)
1570
+ under = under * (1 - mask.alpha) + mask.rgb[channel] * mask.alpha;
1571
+ for (const list of appPrimitives) {
1572
+ for (const primitive of list) {
1573
+ if (inside(primitive.rectangle, pt.x, pt.y))
1574
+ under = blendChannel(under, primitive, channel);
1575
+ }
1576
+ }
1577
+ const overWith = under * (1 - withAlpha) + withRgba[pOffset + channel] * withAlpha;
1578
+ const overWithout = withoutRgba ? under * (1 - withoutAlpha) + withoutRgba[pOffset + channel] * withoutAlpha : under;
1579
+ const expected = expectedActive ? overWith : overWithout;
1580
+ const opposite = expectedActive ? overWithout : overWith;
1581
+ expectedError += Math.abs(finalFrame[offset + channel] - expected);
1582
+ oppositeError += Math.abs(finalFrame[offset + channel] - opposite);
1583
+ contrast += Math.abs(expected - opposite);
1584
+ count++;
1585
+ }
1586
+ }
1587
+ }
1588
+ const maxError = activeView ? 18 : 16;
1589
+ const passed = count > 0 && contrast / count >= 6 && expectedError / count <= maxError && expectedError < oppositeError * 0.72;
1590
+ return {
1591
+ passed,
1592
+ expected_error: count ? expectedError / count : null,
1593
+ opposite_error: count ? oppositeError / count : null,
1594
+ contrast: count ? contrast / count : null,
1595
+ };
1596
+ };
1597
+ if (item.first_frame > 0) {
1598
+ const beforeFrame = item.first_frame - 1;
1599
+ const activeSampleTime = activeFrame * 1000 / video.fps;
1600
+ coverage.push(`${item.id}:before_start:frame_${beforeFrame}`);
1601
+ const order = enqueue(beforeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1602
+ const metrics = measureStampPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, activeSampleTime, false, activeLasers, activeStamps);
1603
+ orderedChecks.push({
1604
+ order,
1605
+ entry: { annotation: item.id, part: 'stamp', boundary: 'before_start', frame_index: beforeFrame, encoded_ms: timestampMs, expected_active: false, ...metrics },
1606
+ gap: metrics.passed ? undefined : `${item.id}:stamp:before_start: frame ${beforeFrame} does not confirm stamp absent before start`,
1607
+ });
1608
+ });
1609
+ }
1610
+ if (activeFrame < totalFrames) {
1611
+ coverage.push(`${item.id}:start:frame_${activeFrame}`);
1612
+ const order = enqueue(activeFrame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1613
+ const metrics = measureStampPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, outputTimeMs, true, activeLasers, activeStamps);
1614
+ orderedChecks.push({
1615
+ order,
1616
+ entry: { annotation: item.id, part: 'stamp', boundary: 'start', frame_index: activeFrame, encoded_ms: timestampMs, expected_active: true, ...metrics },
1617
+ gap: metrics.passed ? undefined : `${item.id}:stamp:start: frame ${activeFrame} does not confirm stamp appearance`,
1618
+ });
1619
+ });
1620
+ checkBoundaryTimestamp(item.id, 'start', item.first_frame, item.start_ms);
1621
+ }
1622
+ if (item.end_frame < totalFrames) {
1623
+ const activeSampleTime = activeFrame * 1000 / video.fps;
1624
+ coverage.push(`${item.id}:end:frame_${item.end_frame}`);
1625
+ const order = enqueue(item.end_frame, (finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, timestampMs, activeLasers, activeStamps) => {
1626
+ const metrics = measureStampPresence(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTimeMs, activeSampleTime, false, activeLasers, activeStamps);
1627
+ orderedChecks.push({
1628
+ order,
1629
+ entry: { annotation: item.id, part: 'stamp', boundary: 'end', frame_index: item.end_frame, encoded_ms: timestampMs, expected_active: false, ...metrics },
1630
+ gap: metrics.passed ? undefined : `${item.id}:stamp:end: frame ${item.end_frame} does not confirm stamp cleared after end`,
1631
+ });
1632
+ });
1633
+ checkBoundaryTimestamp(item.id, 'end', item.end_frame, item.end_ms);
1634
+ }
1635
+ break;
1636
+ }
563
1637
  }
564
1638
  }
565
1639
  const indices = [...tasksByFrame.keys()].sort((a, b) => a - b);
@@ -596,11 +1670,25 @@ export async function verifyAnnotations(file, base, baseFilter, applications, vi
596
1670
  const outputTime = index * 1000 / video.fps;
597
1671
  const timestampMs = Number(metadata.frames[index].best_effort_timestamp_time) * 1000;
598
1672
  const covered = overlayBounds(index);
1673
+ const activeApps = applications.filter(app => index >= app.first_frame && index < app.end_frame);
1674
+ const activeSpotlights = activeApps.filter((app) => app.effect === 'spotlight');
1675
+ const activeLasers = [];
1676
+ const activeStamps = [];
1677
+ for (let idx = 0; idx < applications.length; idx++) {
1678
+ const app = applications[idx];
1679
+ if (index >= app.first_frame && index < app.end_frame) {
1680
+ if (app.effect === 'laser')
1681
+ activeLasers.push({ index: idx, effect: app });
1682
+ else if (app.effect === 'stamp')
1683
+ activeStamps.push({ index: idx, effect: app });
1684
+ }
1685
+ }
1686
+ const activeView = activeViewTransform(activeApps, outputTime);
599
1687
  const appPrimitives = applications.map(app => index >= app.first_frame && index < app.end_frame
600
1688
  ? effectPrimitives([app], outputTime).map(toRgbPrimitive)
601
1689
  : []);
602
1690
  for (const task of tasksByFrame.get(index) ?? []) {
603
- task.run(finalFrame, baseFrame, covered, appPrimitives, timestampMs);
1691
+ task.run(finalFrame, baseFrame, covered, appPrimitives, activeSpotlights, activeView, outputTime, timestampMs, activeLasers, activeStamps);
604
1692
  }
605
1693
  }
606
1694
  const [finalEnded, baseEnded] = await Promise.all([