@@ -301,6 +301,7 @@ interface LineCandidate {
301301 floor : number ;
302302 window : LineWindow ;
303303 firstIndex : number ;
304+ lastIndex : number ;
304305}
305306
306307/** A run that reaches the last sample lasts to the film's end; one at sample 0 starts exactly there. */
@@ -348,7 +349,16 @@ function lineCandidates(frames: CraftFrame[], duration: number, canvas: Canvas):
348349 const floor = lineFloorSec ( words , finalLine ) ;
349350 // Clearly long enough even at the shortest the grid allows.
350351 if ( window . endIn - window . startIn >= floor ) continue ;
351- candidates . push ( { track, words, text, finalLine, floor, window, firstIndex : run [ 0 ] } ) ;
352+ candidates . push ( {
353+ track,
354+ words,
355+ text,
356+ finalLine,
357+ floor,
358+ window,
359+ firstIndex : run [ 0 ] ,
360+ lastIndex : run [ 1 ] ,
361+ } ) ;
352362 }
353363 return candidates ;
354364}
@@ -393,7 +403,7 @@ export async function detectLineUnread(
393403 const held = windowSeconds ( window ) ;
394404 if ( held >= candidate . floor - T . measureToleranceSec ) continue ;
395405 const error = Math . max ( window . startIn - window . startOut , window . endOut - window . endIn ) / 2 ;
396- findings . push ( lineUnreadFinding ( candidate , window , held , error ) ) ;
406+ findings . push ( lineUnreadFinding ( candidate , window , held , error , frames ) ) ;
397407 }
398408 return findings ;
399409}
@@ -403,6 +413,7 @@ function lineUnreadFinding(
403413 window : LineWindow ,
404414 held : number ,
405415 error : number ,
416+ frames : CraftFrame [ ] ,
406417) : CraftFinding {
407418 const { track, words, text, finalLine, floor } = candidate ;
408419 const quoted = quote ( text , 60 ) ;
@@ -429,9 +440,43 @@ function lineUnreadFinding(
429440 words,
430441 seconds : round ( held ) ,
431442 floorSeconds : round ( floor ) ,
443+ measured : measuredAround ( frames , track . key , candidate . firstIndex , candidate . lastIndex ) ,
432444 } ;
433445}
434446
447+ const MEASURED_SPAN = 3 ;
448+
449+ /** The samples at both ends of the line's run, as the sampler measured them. */
450+ function measuredAround (
451+ frames : CraftFrame [ ] ,
452+ key : number ,
453+ first : number ,
454+ last : number ,
455+ ) : NonNullable < CraftFinding [ "measured" ] > {
456+ const indices = new Set < number > ( ) ;
457+ for ( const edge of [ first , last ] ) {
458+ for ( let at = edge - MEASURED_SPAN ; at <= edge + MEASURED_SPAN ; at += 1 ) indices . add ( at ) ;
459+ }
460+ const out : NonNullable < CraftFinding [ "measured" ] > = [ ] ;
461+ for ( const index of [ ...indices ] . sort ( ( a , b ) => a - b ) ) {
462+ const frame = frames [ index ] ;
463+ if ( ! frame ) continue ;
464+ const parts = frame . parts . filter ( ( part ) => part . block === key && ! part . captions ) ;
465+ if ( parts . length === 0 ) {
466+ out . push ( { time : round ( frame . time ) , opacity : null , heightPx : null } ) ;
467+ continue ;
468+ }
469+ const top = Math . min ( ...parts . map ( ( part ) => part . rect . top ) ) ;
470+ const bottom = Math . max ( ...parts . map ( ( part ) => part . rect . top + part . rect . height ) ) ;
471+ out . push ( {
472+ time : round ( frame . time ) ,
473+ opacity : round ( Math . max ( ...parts . map ( ( part ) => part . opacity ) ) ) ,
474+ heightPx : Math . round ( bottom - top ) ,
475+ } ) ;
476+ }
477+ return out ;
478+ }
479+
435480// ---------- text_below_floor ----------
436481
437482interface SmallText {
0 commit comments