Skip to content

Commit

Permalink
feat: Add support for orientation of subtitles in Rust
Browse files Browse the repository at this point in the history
by adding necessary labels needed for it
  • Loading branch information
IshanGrover2004 committed Feb 17, 2024
1 parent 8b8c38e commit 0d75727
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/rust/src/decoder/tv_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(());
}
Expand Down Expand Up @@ -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);

Expand All @@ -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())?;
Expand Down

0 comments on commit 0d75727

Please sign in to comment.