| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | use std::time::Instant; |
| 16 | |
| 17 | #[test] |
| 18 | fn the_session_maps_a_pgs_track_onto_the_timeline_and_draws_it() { |
| 19 | |
| 20 | let Some(film) = engine::real_library::film("hevc_4k_pgs") else { |
| 21 | return; |
| 22 | }; |
| 23 | let film = film.as_path(); |
| 24 | let opened = Instant::now(); |
| 25 | let mut session = engine::PlaybackSession::open(film).expect("the film opens"); |
| 26 | session.set_gain(0.0); |
| 27 | let rows = session |
| 28 | .import_subtitles(film) |
| 29 | .expect("the film's own subtitle tracks"); |
| 30 | eprintln!("{rows} rows in {:?}", opened.elapsed()); |
| 31 | let pick = session |
| 32 | .subtitles() |
| 33 | .iter() |
| 34 | .position(|t| t.is_bitmap()) |
| 35 | .expect("a bitmap row to pick"); |
| 36 | assert_eq!( |
| 37 | session.subtitles()[pick].refused, None, |
| 38 | "a row a click can pick" |
| 39 | ); |
| 40 | |
| 41 | let mapped = Instant::now(); |
| 42 | let cues = session.timeline_cues(pick); |
| 43 | eprintln!("{} cues mapped in {:?}", cues.len(), mapped.elapsed()); |
| 44 | assert!(!cues.is_empty(), "no cue of this track lands on the timeline"); |
| 45 | |
| 46 | |
| 47 | let warm = Instant::now(); |
| 48 | let again = session.timeline_cues(pick); |
| 49 | let warm = warm.elapsed(); |
| 50 | eprintln!("mapped again in {warm:?}"); |
| 51 | assert_eq!(again, cues, "the same map, twice"); |
| 52 | assert!(warm.as_millis() < 16, "a repaint's worth of map: {warm:?}"); |
| 53 | |
| 54 | |
| 55 | |
| 56 | for pair in cues.windows(2) { |
| 57 | assert!(pair[0].end_us > pair[0].start_us, "{:?}", pair[0]); |
| 58 | assert!(pair[1].start_us >= pair[0].start_us, "{pair:?}"); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | let drawn = Instant::now(); |
| 63 | let image = cues[0].image.as_ref().expect("a picture cue"); |
| 64 | let rgba = image.rgba().expect("the first display set decodes"); |
| 65 | let took = drawn.elapsed(); |
| 66 | eprintln!( |
| 67 | "cue 0 decoded to {}x{} in {took:?}", |
| 68 | image.width, image.height, |
| 69 | ); |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | assert!(took.as_millis() < 16, "a frame's worth of decode: {took:?}"); |
| 76 | assert_eq!(rgba.len(), (image.width * image.height * 4) as usize); |
| 77 | let opaque = rgba.chunks_exact(4).filter(|px| px[3] > 0).count(); |
| 78 | assert!(opaque > 0, "the block decoded to an empty canvas"); |
| 79 | assert!( |
| 80 | opaque < (image.width * image.height) as usize, |
| 81 | "a subtitle that covers the whole frame is not a subtitle" |
| 82 | ); |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | let lane = session.add_lane(engine::project::LaneKind::Subtitle); |
| 91 | session |
| 92 | .place_sub( |
| 93 | lane, |
| 94 | 0, |
| 95 | engine::project::SubClip { |
| 96 | start: 0, |
| 97 | frames: 60, |
| 98 | track: pick, |
| 99 | in_us: cues[0].start_us, |
| 100 | out_us: cues[0].end_us, |
| 101 | link: None, |
| 102 | }, |
| 103 | ) |
| 104 | .expect("the lane is empty, so the placement lands"); |
| 105 | assert_eq!( |
| 106 | session.planned_subtitles(engine::export::Format::Hevc, []), |
| 107 | format!( |
| 108 | "S1 {} — pictures; drawn, not written", |
| 109 | session.subtitles()[pick].label |
| 110 | ), |
| 111 | "a real PGS row on a lane says why it cannot travel" |
| 112 | ); |
| 113 | |
| 114 | |
| 115 | |
| 116 | let text = session |
| 117 | .subtitles() |
| 118 | .iter() |
| 119 | .position(|t| !t.is_bitmap() && t.refused.is_none()) |
| 120 | .expect("the film's text track"); |
| 121 | let words = session.timeline_cues(text); |
| 122 | assert!(!words.is_empty()); |
| 123 | assert!(words.iter().all(|c| c.image.is_none())); |
| 124 | } |