Skip to content

Commit

Permalink
feat: Add support for orientation of subtitles in C
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 e40f895 commit 8b8c38e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
36 changes: 36 additions & 0 deletions src/lib_ccx/ccx_decoders_708_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,35 @@ void dtvcc_write_scc_header(dtvcc_tv_screen *tv, struct encoder_ctx *encoder)
write_wrapped(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
}

int count_captions_lines_scc(dtvcc_tv_screen *tv)
{
int count = 0;
for (int i = 0; i < CCX_DTVCC_SCREENGRID_ROWS; i++)
{
if (!dtvcc_is_row_empty(tv, i))
{
count++;
}
}

return count;
}

void add_needed_scc_labels(char *buf, int subtitle_count, int count)
{
switch (subtitle_count)
{
case 1:
sprintf(buf + strlen(buf), " 94e0 94e0");
break;
case 2:
sprintf(buf + strlen(buf), count == 1 ? " 9440 9440" : " 94e0 94e0");
break;
default:
sprintf(buf + strlen(buf), count == 1 ? " 13e0 13e0" : (count == 2 ? " 9440 9440" : " 94e0 94e0"));
}
}

void dtvcc_write_scc(dtvcc_writer_ctx *writer, dtvcc_service_decoder *decoder, struct encoder_ctx *encoder)
{
dtvcc_tv_screen *tv = decoder->tv;
Expand Down Expand Up @@ -444,10 +473,16 @@ void dtvcc_write_scc(dtvcc_writer_ctx *writer, dtvcc_service_decoder *decoder, s
time_show.time_in_ms += 1000 / 29.97;
}

int subtitle_count = count_captions_lines_scc(tv);
int count = 0;

for (int i = 0; i < CCX_DTVCC_SCREENGRID_ROWS; i++)
{
if (!dtvcc_is_row_empty(tv, i))
{
count++;
add_needed_scc_labels(buf, subtitle_count, count);

int first, last, bytes_written = 0;
dtvcc_get_write_interval(tv, i, &first, &last);
for (int j = first; j <= last; j++)
Expand All @@ -464,6 +499,7 @@ void dtvcc_write_scc(dtvcc_writer_ctx *writer, dtvcc_service_decoder *decoder, s
sprintf(buf + strlen(buf), " ");
}
}

// Display caption (942f 942f)
sprintf(buf + strlen(buf), "942f 942f \n\n");
write_wrapped(encoder->dtvcc_writers[tv->service_number - 1].fd, buf, strlen(buf));
Expand Down
11 changes: 6 additions & 5 deletions src/lib_ccx/ccx_decoders_708_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
void dtvcc_write_done(dtvcc_tv_screen *tv, struct encoder_ctx *encoder);

void dtvcc_writer_init(dtvcc_writer_ctx *writer,
char *base_filename,
int program_number,
int service_number,
enum ccx_output_format write_format,
struct encoder_cfg *cfg);
char *base_filename,
int program_number,
int service_number,
enum ccx_output_format write_format,
struct encoder_cfg *cfg);
void dtvcc_writer_cleanup(dtvcc_writer_ctx *writer);
void dtvcc_writer_output(dtvcc_writer_ctx *writer, dtvcc_service_decoder *decoder, struct encoder_ctx *encoder);

Expand All @@ -31,6 +31,7 @@ void dtvcc_write_sami_header(dtvcc_tv_screen *tv, struct encoder_ctx *encoder);
void dtvcc_write_sami_footer(dtvcc_tv_screen *tv, struct encoder_ctx *encoder);
void dtvcc_write_sami(dtvcc_writer_ctx *writer, dtvcc_service_decoder *decoder, struct encoder_ctx *encoder);
void dtvcc_write_scc_header(dtvcc_tv_screen *tv, struct encoder_ctx *encoder);
void add_needed_scc_labels(char *buf, int subtitle_count, int count);
void dtvcc_write_scc(dtvcc_writer_ctx *writer, dtvcc_service_decoder *decoder, struct encoder_ctx *encoder);
void dtvcc_write(dtvcc_writer_ctx *writer, dtvcc_service_decoder *decoder, struct encoder_ctx *encoder);

Expand Down

0 comments on commit 8b8c38e

Please sign in to comment.