]> granicus.if.org Git - handbrake/commitdiff
LinGui: fix rounding error in display aspect
authorJohn Stebbins <jstebbins.hb@gmail.com>
Fri, 16 Mar 2018 18:06:04 +0000 (12:06 -0600)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Fri, 16 Mar 2018 18:06:04 +0000 (12:06 -0600)
This is only a cosmetic display problem.  The values used during
encoding are correct.

gtk/src/callbacks.c
gtk/src/hb-backend.c
gtk/src/hb-backend.h

index 0bdb9c08b618be06055ae998e608a9af6783a17f..b399090ab00bd0745c9fed1250bdb5b42687254a 100644 (file)
@@ -2674,7 +2674,8 @@ ghb_update_summary_info(signal_user_data_t *ud)
     gtk_label_set_text(GTK_LABEL(widget), text);
     g_free(text);
 
-    int    width, height, display_width, display_height, par_width, par_height;
+    double display_width;
+    int    width, height, display_height, par_width, par_height;
     char * display_aspect;
 
     width          = ghb_dict_get_int(ud->settings, "scale_width");
@@ -2684,12 +2685,15 @@ ghb_update_summary_info(signal_user_data_t *ud)
     par_width      = ghb_dict_get_int(ud->settings, "PicturePARWidth");
     par_height     = ghb_dict_get_int(ud->settings, "PicturePARHeight");
 
+    display_width = (double)width * par_width / par_height;
     display_aspect = ghb_get_display_aspect_string(display_width,
                                                    display_height);
+
+    display_width  = ghb_dict_get_int(ud->settings, "PictureDisplayWidth");
     text = g_strdup_printf("%dx%d storage, %dx%d display\n"
                            "%d:%d Pixel Aspect Ratio\n"
                             "%s Display Aspect Ratio",
-                           width, height, display_width, display_height,
+                           width, height, (int)display_width, display_height,
                            par_width, par_height, display_aspect);
     widget = GHB_WIDGET(ud->builder, "dimensions_summary");
     gtk_label_set_text(GTK_LABEL(widget), text);
index a3f5aa58a5f8f3f90cab8feff25afa9281095cd2..3d947c8c149625b4c63d42ba48126e90f013f64c 100644 (file)
@@ -3792,27 +3792,27 @@ ghb_set_scale_settings(GhbValue *settings, gint mode)
 }
 
 char *
-ghb_get_display_aspect_string(int disp_width, int disp_height)
+ghb_get_display_aspect_string(double disp_width, double disp_height)
 {
-    gint dar_width, dar_height;
     gchar *str;
 
-    hb_reduce(&dar_width, &dar_height, disp_width, disp_height);
-    gint iaspect = dar_width * 9 / dar_height;
-    if (dar_width > 2 * dar_height)
+    gint iaspect = disp_width * 9 / disp_height;
+    if (disp_width > 2 * disp_height)
     {
-        str = g_strdup_printf("%.2f:1", (gdouble)dar_width / dar_height);
+        str = g_strdup_printf("%.2f:1", disp_width / disp_height);
     }
     else if (iaspect <= 16 && iaspect >= 15)
     {
-        str = g_strdup_printf("%.4g:9", (gdouble)dar_width * 9 / dar_height);
+        str = g_strdup_printf("%.4g:9", disp_width * 9 / disp_height);
     }
     else if (iaspect <= 12 && iaspect >= 11)
     {
-        str = g_strdup_printf("%.4g:3", (gdouble)dar_width * 3 / dar_height);
+        str = g_strdup_printf("%.4g:3", disp_width * 3 / disp_height);
     }
     else
     {
+        gint dar_width, dar_height;
+        hb_reduce(&dar_width, &dar_height, disp_width, disp_height);
         str = g_strdup_printf("%d:%d", dar_width, dar_height);
     }
     return str;
@@ -3821,12 +3821,17 @@ ghb_get_display_aspect_string(int disp_width, int disp_height)
 void
 ghb_update_display_aspect_label(signal_user_data_t *ud)
 {
-    gint disp_width, disp_height;
+    gint width, disp_height;
+    gint par_num, par_den;
+    double disp_width;
     gchar *str;
 
-    disp_width  = ghb_dict_get_int(ud->settings, "PictureDisplayWidth");
-    disp_height = ghb_dict_get_int(ud->settings, "PictureDisplayHeight");
-    str         = ghb_get_display_aspect_string(disp_width, disp_height);
+    width  = ghb_dict_get_int(ud->settings, "scale_width");
+    disp_height = ghb_dict_get_int(ud->settings, "scale_height");
+    par_num = ghb_dict_get_int(ud->settings, "PicturePARWidth");
+    par_den = ghb_dict_get_int(ud->settings, "PicturePARHeight");
+    disp_width = (double)width * par_num / par_den;
+    str        = ghb_get_display_aspect_string(disp_width, disp_height);
     ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
     g_free(str);
 }
index 9cc157a51334607cfd59bddf458ce8e17dd2c4ef..481aafbb22f4a77dd6fede03e60f87bd7e8815fd 100644 (file)
@@ -225,7 +225,7 @@ const hb_rate_t* ghb_settings_audio_bitrate(
 const char* ghb_audio_bitrate_get_short_name(int rate);
 hb_audio_config_t* ghb_get_audio_info(const hb_title_t *title, gint track);
 hb_subtitle_t* ghb_get_subtitle_info(const hb_title_t *title, gint track);
-char * ghb_get_display_aspect_string(int disp_width, int disp_height);
+char * ghb_get_display_aspect_string(double disp_width, double disp_height);
 
 hb_handle_t* ghb_scan_handle(void);
 hb_handle_t* ghb_queue_handle(void);