diff options
-rw-r--r-- | libhb/common.c | 4 | ||||
-rw-r--r-- | libhb/common.h | 2 | ||||
-rw-r--r-- | libhb/deccc608sub.c | 64 | ||||
-rw-r--r-- | libhb/deccc608sub.h | 1 | ||||
-rw-r--r-- | libhb/decsrtsub.c | 3 | ||||
-rw-r--r-- | libhb/dectx3gsub.c | 3 | ||||
-rw-r--r-- | libhb/decutf8sub.c | 3 | ||||
-rw-r--r-- | libhb/rendersub.c | 7 |
8 files changed, 59 insertions, 28 deletions
diff --git a/libhb/common.c b/libhb/common.c index 053a4c4c2..bca6e6956 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -3765,13 +3765,11 @@ void hb_subtitle_close( hb_subtitle_t **sub ) * *********************************************************************/ int hb_subtitle_add_ssa_header(hb_subtitle_t *subtitle, const char *font, - int w, int h) + int fs, int w, int h) { // Free any pre-existing extradata free(subtitle->extradata); - int fs = h * .066; - // SRT subtitles are represented internally as SSA // Create an SSA header const char * ssa_header = diff --git a/libhb/common.h b/libhb/common.h index ac5692642..ca5f25178 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -159,7 +159,7 @@ int hb_audio_add(const hb_job_t * job, const hb_audio_config_t * audiocfg); hb_audio_config_t * hb_list_audio_config_item(hb_list_t * list, int i); int hb_subtitle_add_ssa_header(hb_subtitle_t *subtitle, const char *font, - int width, int height); + int fs, int width, int height); hb_subtitle_t *hb_subtitle_copy(const hb_subtitle_t *src); hb_list_t *hb_subtitle_list_copy(const hb_list_t *src); void hb_subtitle_close( hb_subtitle_t **sub ); diff --git a/libhb/deccc608sub.c b/libhb/deccc608sub.c index 0a63d1e9c..25ff7a15a 100644 --- a/libhb/deccc608sub.c +++ b/libhb/deccc608sub.c @@ -831,7 +831,7 @@ static int write_cc_buffer_as_ssa(struct eia608_screen *data, */ int rows = 0, columns = 0; int min_row = 15, max_row = 0; - int min_col = 31, max_col = 0; + int min_col = 41, max_col = 0; for (i = 0; i < 15; i++) { if (data->row_used[i]) @@ -857,36 +857,59 @@ static int write_cc_buffer_as_ssa(struct eia608_screen *data, wb->prev_font_color = COL_WHITE; wb->enc_buffer_used = 0; - int cropped_width, cropped_height, font_size, safe_zone; + int cropped_width, cropped_height, font_size; int cell_width, cell_height; + int safe_x, safe_y; + int min_safe_x, min_safe_y; + double aspect; - // CC grid is 16 rows by 32 colums + cropped_height = wb->height - wb->crop[0] - wb->crop[1]; + cropped_width = wb->width - wb->crop[2] - wb->crop[3]; + aspect = (double)wb->width * wb->par.num / + (wb->height * wb->par.den); + + // CC grid is 16 rows by 32 colums (for 4:3 video) // Our SSA resolution is the title resolution // Tranlate CC grid to SSA coordinates // The numbers are tweaked to keep things off the very // edges of the screen and in the "safe" zone - cropped_height = wb->height - wb->crop[0] - wb->crop[1]; - cropped_width = wb->width - wb->crop[2] - wb->crop[3]; + int screen_columns = 32; + if (aspect >= 1.6) + { + // If the display aspect is close to or greater than 16:9 + // then width of screen is 42 columns (see CEA-708) + screen_columns = 42; + } font_size = cropped_height * .066; - safe_zone = cropped_height * 0.025; - cell_height = (wb->height - 2 * safe_zone) / 16; - cell_width = (wb->width - 2 * safe_zone) / 32; + safe_x = 0.1 * wb->width; + safe_y = 0.1 * wb->height; + min_safe_x = 0.025 * cropped_width; + min_safe_y = 0.025 * cropped_height; + cell_height = (wb->height - 2 * safe_y) / 16; + cell_width = (wb->width - 2 * safe_x) / screen_columns; char *pos; int y, x, top; - y = cell_height * (min_row + 1 + rows) + safe_zone - wb->crop[0]; - x = cell_width * min_col + safe_zone - wb->crop[2]; + int col = min_col; + if (aspect >= 1.6) + { + // If the display aspect is close to or greater than 16:9 + // center the CC in about a 4:3 region + col += 5; + } + y = cell_height * (min_row + 1 + rows) + safe_y - wb->crop[0]; + x = cell_width * col + safe_x - wb->crop[2]; top = y - rows * font_size; - if (top < safe_zone) - y = (rows * font_size) + safe_zone; - if (y > cropped_height - safe_zone) - y = cropped_height - safe_zone; - if (x + columns * cell_width > cropped_width - safe_zone) - x = cropped_width - columns * cell_width - safe_zone; - if (x < safe_zone) - x = safe_zone; + if (top < min_safe_y) + y = (rows * font_size) + min_safe_y; + if (y > cropped_height - min_safe_y) + y = cropped_height - min_safe_y; + if (x + columns * cell_width > cropped_width - min_safe_x) + x = cropped_width - columns * cell_width - min_safe_x; + if (x < min_safe_x) + x = min_safe_x; pos = hb_strdup_printf("{\\a1\\pos(%d,%d)}", x, y); int line = 1; @@ -1766,6 +1789,7 @@ static int decccInit( hb_work_object_t * w, hb_job_t * job ) pv->cc608->width = job->title->geometry.width; pv->cc608->height = job->title->geometry.height; memcpy(pv->cc608->crop, job->crop, sizeof(int[4])); + pv->cc608->par = job->title->geometry.par; retval = general_608_init(pv->cc608); if( !retval ) { @@ -1783,7 +1807,9 @@ static int decccInit( hb_work_object_t * w, hb_job_t * job ) // Generate generic SSA Script Info. int height = job->title->geometry.height - job->crop[0] - job->crop[1]; int width = job->title->geometry.width - job->crop[2] - job->crop[3]; - hb_subtitle_add_ssa_header(w->subtitle, "Courier New", width, height); + int safe_height = 0.8 * height; + hb_subtitle_add_ssa_header(w->subtitle, "Courier New", + .08 * safe_height, width, height); } // When rendering subs, we need to push rollup subtitles out // asap (instead of waiting for a completed line) so that we diff --git a/libhb/deccc608sub.h b/libhb/deccc608sub.h index 129236bf1..d01209f62 100644 --- a/libhb/deccc608sub.h +++ b/libhb/deccc608sub.h @@ -101,6 +101,7 @@ struct s_write { int width; int height; int crop[4]; + hb_rational_t par; uint8_t prev_font_style; uint8_t prev_font_color; }; diff --git a/libhb/decsrtsub.c b/libhb/decsrtsub.c index 88c6def92..85e2a1ae0 100644 --- a/libhb/decsrtsub.c +++ b/libhb/decsrtsub.c @@ -699,7 +699,8 @@ static int decsrtInit( hb_work_object_t * w, hb_job_t * job ) // Generate generic SSA Script Info. int height = job->title->geometry.height - job->crop[0] - job->crop[1]; int width = job->title->geometry.width - job->crop[2] - job->crop[3]; - hb_subtitle_add_ssa_header(w->subtitle, "Arial", width, height); + hb_subtitle_add_ssa_header(w->subtitle, "Arial", .066 * height, + width, height); } return retval; } diff --git a/libhb/dectx3gsub.c b/libhb/dectx3gsub.c index cd121ac70..3aa22bf5c 100644 --- a/libhb/dectx3gsub.c +++ b/libhb/dectx3gsub.c @@ -250,7 +250,8 @@ static int dectx3gInit( hb_work_object_t * w, hb_job_t * job ) // For now we just create a generic SSA Script Info. int height = job->title->geometry.height - job->crop[0] - job->crop[1]; int width = job->title->geometry.width - job->crop[2] - job->crop[3]; - hb_subtitle_add_ssa_header(w->subtitle, "Arial", width, height); + hb_subtitle_add_ssa_header(w->subtitle, "Arial", .066 * height, + width, height); return 0; } diff --git a/libhb/decutf8sub.c b/libhb/decutf8sub.c index 29c90383d..82209241b 100644 --- a/libhb/decutf8sub.c +++ b/libhb/decutf8sub.c @@ -37,7 +37,8 @@ static int decutf8Init(hb_work_object_t *w, hb_job_t *job) // Generate generic SSA Script Info. int height = job->title->geometry.height - job->crop[0] - job->crop[1]; int width = job->title->geometry.width - job->crop[2] - job->crop[3]; - hb_subtitle_add_ssa_header(w->subtitle, "Arial", width, height); + hb_subtitle_add_ssa_header(w->subtitle, "Arial", .066 * height, + width, height); return 0; } diff --git a/libhb/rendersub.c b/libhb/rendersub.c index 006f4f156..1ea4c7648 100644 --- a/libhb/rendersub.c +++ b/libhb/rendersub.c @@ -596,8 +596,10 @@ static int cc608sub_post_init( hb_filter_object_t * filter, hb_job_t * job ) // to have the header rewritten with the correct dimensions. int height = job->title->geometry.height - job->crop[0] - job->crop[1]; int width = job->title->geometry.width - job->crop[2] - job->crop[3]; + int safe_height = 0.8 * height; // Use fixed widht font for CC - hb_subtitle_add_ssa_header(filter->subtitle, "Courier New", width, height); + hb_subtitle_add_ssa_header(filter->subtitle, "Courier New", + .08 * safe_height, width, height); return ssa_post_init(filter, job); } @@ -607,7 +609,8 @@ static int textsub_post_init( hb_filter_object_t * filter, hb_job_t * job ) // to have the header rewritten with the correct dimensions. int height = job->title->geometry.height - job->crop[0] - job->crop[1]; int width = job->title->geometry.width - job->crop[2] - job->crop[3]; - hb_subtitle_add_ssa_header(filter->subtitle, "Arial", width, height); + hb_subtitle_add_ssa_header(filter->subtitle, "Arial", .066 * height, + width, height); return ssa_post_init(filter, job); } |