From 0d75727280a5c65f7483cd708a640a98e8f9c7b1 Mon Sep 17 00:00:00 2001 From: IshanGrover2004 Date: Sat, 17 Feb 2024 20:51:14 +0530 Subject: [PATCH] feat: Add support for orientation of subtitles in Rust by adding necessary labels needed for it --- src/rust/src/decoder/tv_screen.rs | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/rust/src/decoder/tv_screen.rs b/src/rust/src/decoder/tv_screen.rs index c10ee4f95..1646bdbf2 100644 --- a/src/rust/src/decoder/tv_screen.rs +++ b/src/rust/src/decoder/tv_screen.rs @@ -360,6 +360,13 @@ impl dtvcc_tv_screen { Ok(()) } + fn count_captions_lines_scc(&self) -> usize { + (0..CCX_DTVCC_SCREENGRID_ROWS) + .into_iter() + .filter(|&row_index| !self.is_row_empty(row_index as usize)) + .count() + } + /// Write captions in SCC format pub fn write_scc(&self, writer: &mut Writer) -> Result<(), String> { fn adjust_odd_parity(value: u8) -> u8 { @@ -375,6 +382,27 @@ impl dtvcc_tv_screen { value } } + fn add_needed_scc_labels(buf: &mut String, subtitle_count: usize, count: usize) { + match subtitle_count { + 1 => buf.push_str(" 94e0 94e0"), + 2 => { + if count == 1 { + buf.push_str(" 9440 9440"); + } else { + buf.push_str(" 94e0 94e0") + } + } + _ => { + if count == 1 { + buf.push_str(" 13e0 13e0"); + } else if count == 2 { + buf.push_str(" 9440 9440"); + } else { + buf.push_str(" 94e0 94e0") + } + } + } + } if self.is_screen_empty(writer) { return Ok(()); } @@ -424,8 +452,14 @@ impl dtvcc_tv_screen { } } + let subtitle_count = self.count_captions_lines_scc(); + let mut count = 0; + for row_index in 0..CCX_DTVCC_SCREENGRID_ROWS as usize { if !self.is_row_empty(row_index) { + count += 1; + add_needed_scc_labels(&mut buf, subtitle_count, count); + let (first, last) = self.get_write_interval(row_index); debug!("First: {}, Last: {}", first, last); @@ -446,6 +480,7 @@ impl dtvcc_tv_screen { } } } + // Display caption (942f 942f) buf.push_str("942f 942f \n\n"); writer.write_to_file(buf.as_bytes())?;