]> granicus.if.org Git - handbrake/commitdiff
deccc608sub: improve CC positioning
authorjstebbins <jstebbins.hb@gmail.com>
Sun, 5 Apr 2015 23:21:09 +0000 (23:21 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Sun, 5 Apr 2015 23:21:09 +0000 (23:21 +0000)
The safe zone margin was not wide enough and the font size was a little
too small.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7063 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/common.c
libhb/common.h
libhb/deccc608sub.c
libhb/deccc608sub.h
libhb/decsrtsub.c
libhb/dectx3gsub.c
libhb/decutf8sub.c
libhb/rendersub.c

index 053a4c4c2a4f4b4e2a7e11e0a093818574db376e..bca6e695606f1617630685e753b35712feb5f5a8 100644 (file)
@@ -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 =
index ac56926422a51abe225fc9805ceb9ff8094e6e4d..ca5f2517827ed3625e5427350b872be44ef87571 100644 (file)
@@ -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 );
index 0a63d1e9ce8e0284d1caaa4ee6ffd527b47ff2e7..25ff7a15a9b1d58c89e83a89880886d8f320e85a 100644 (file)
@@ -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
index 129236bf1e2aa3932a10cfc20cb1ce8e405a4d19..d01209f62e56c5077d38d2560cb55c9eeb4e456b 100644 (file)
@@ -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;
 };
index 88c6def92cd92209712a228b9ec28a2efdc64b2c..85e2a1ae0329eb5e3cc4235ea0a16ba38a61d3f1 100644 (file)
@@ -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;
 }
index cd121ac7054ce77ec6583462838e815bd1a9f076..3aa22bf5c2048d0b12d7787984020bc155540640 100644 (file)
@@ -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;
 }
index 29c90383d1a8ebefd7f5510b868422db19398ebc..82209241b4bf4e84fa2960bb17009d9131587c8b 100644 (file)
@@ -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;
 }
index 006f4f156e1e085b056d8ea5a4a4637dbab1005f..1ea4c764804f4b18d212baa7905e69daadb70c00 100644 (file)
@@ -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);
 }