OSDN Git Service

LinGui: more anamorphic settings changes
authorjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 15 Apr 2009 21:36:55 +0000 (21:36 +0000)
committerjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 15 Apr 2009 21:36:55 +0000 (21:36 +0000)
- recalculate display dims correctly when changing titles and presets
- when presets are saved, save par

git-svn-id: svn://localhost/HandBrake/trunk@2330 b64f7644-9d1e-0410-96f1-a4d463321fa5

gtk/src/callbacks.c
gtk/src/ghb.ui
gtk/src/hb-backend.c
gtk/src/hb-backend.h
gtk/src/internal_defaults.xml
gtk/src/presets.c

index e003ffc..166b8c6 100644 (file)
@@ -1000,6 +1000,7 @@ show_title_info(signal_user_data_t *ud, ghb_title_info_t *tinfo)
        GtkWidget *widget;
        gchar *text;
 
+       ud->dont_clear_presets = TRUE;
        widget = GHB_WIDGET (ud->builder, "title_duration");
        if (tinfo->duration != 0)
        {
@@ -1061,7 +1062,7 @@ show_title_info(signal_user_data_t *ud, ghb_title_info_t *tinfo)
                ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(tinfo->crop[2]));
                ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(tinfo->crop[3]));
        }
-       ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
+       ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
        gint width, height, crop[4];
        crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
        crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
@@ -1081,6 +1082,7 @@ show_title_info(signal_user_data_t *ud, ghb_title_info_t *tinfo)
        widget = GHB_WIDGET (ud->builder, "start_chapter");
        gtk_spin_button_set_value (GTK_SPIN_BUTTON(widget), 1);
        gtk_spin_button_set_range (GTK_SPIN_BUTTON(widget), 1, tinfo->num_chapters);
+       ud->dont_clear_presets = TRUE;
 }
 
 static gboolean update_preview = FALSE;
@@ -1256,8 +1258,9 @@ scale_width_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
        g_debug("scale_width_changed_cb ()");
        ghb_widget_to_setting(ud->settings, widget);
        ghb_check_dependency(ud, widget);
+       ghb_clear_presets_selection(ud);
        if (GTK_WIDGET_SENSITIVE(widget))
-               ghb_set_scale (ud, GHB_SCALE_KEEP_WIDTH);
+               ghb_set_scale (ud, GHB_PIC_KEEP_WIDTH);
        update_preview = TRUE;
        gchar *text;
        gint width = ghb_settings_get_int(ud->settings, "scale_width");
@@ -1275,8 +1278,9 @@ scale_height_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
        g_debug("scale_height_changed_cb ()");
        ghb_widget_to_setting(ud->settings, widget);
        ghb_check_dependency(ud, widget);
+       ghb_clear_presets_selection(ud);
        if (GTK_WIDGET_SENSITIVE(widget))
-               ghb_set_scale (ud, GHB_SCALE_KEEP_HEIGHT);
+               ghb_set_scale (ud, GHB_PIC_KEEP_HEIGHT);
        update_preview = TRUE;
        gchar *text;
        gint width = ghb_settings_get_int(ud->settings, "scale_width");
@@ -1297,8 +1301,9 @@ crop_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
        g_debug("crop_changed_cb ()");
        ghb_widget_to_setting(ud->settings, widget);
        ghb_check_dependency(ud, widget);
+       ghb_clear_presets_selection(ud);
        if (GTK_WIDGET_SENSITIVE(widget))
-               ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
+               ghb_set_scale (ud, 0);
 
        crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
        crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
@@ -1335,7 +1340,20 @@ display_width_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
        ghb_clear_presets_selection(ud);
        ghb_live_reset(ud);
        if (GTK_WIDGET_SENSITIVE(widget))
-               ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
+               ghb_set_scale (ud, GHB_PIC_KEEP_DISPLAY_WIDTH);
+
+       gint pic_par;
+
+       pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
+       if (pic_par == 3)
+       {
+               gint par_width, par_height;
+
+               par_width = ghb_settings_get_int(ud->settings, "par_width");
+               par_height = ghb_settings_get_int(ud->settings, "par_height");
+               ghb_settings_set_int(ud->settings, "PicturePARWidth", par_width);
+               ghb_settings_set_int(ud->settings, "PicturePARHeight", par_height);
+       }
        update_preview = TRUE;
 }
 
@@ -1348,7 +1366,20 @@ display_height_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
        ghb_clear_presets_selection(ud);
        ghb_live_reset(ud);
        if (GTK_WIDGET_SENSITIVE(widget))
-               ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
+               ghb_set_scale (ud, GHB_PIC_KEEP_DISPLAY_HEIGHT);
+
+       gint pic_par;
+
+       pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
+       if (pic_par == 3)
+       {
+               gint par_width, par_height;
+
+               par_width = ghb_settings_get_int(ud->settings, "par_width");
+               par_height = ghb_settings_get_int(ud->settings, "par_height");
+               ghb_settings_set_int(ud->settings, "PicturePARWidth", par_width);
+               ghb_settings_set_int(ud->settings, "PicturePARHeight", par_height);
+       }
        update_preview = TRUE;
 }
 
@@ -1361,7 +1392,7 @@ scale_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
        ghb_clear_presets_selection(ud);
        ghb_live_reset(ud);
        if (GTK_WIDGET_SENSITIVE(widget))
-               ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
+               ghb_set_scale (ud, 0);
        update_preview = TRUE;
        
        gchar *text;
index d2620f3..29987c3 100644 (file)
@@ -4702,16 +4702,38 @@ location as the movie.</property>
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkLabel" id="pixel_aspect">
+                                  <object class="GtkLabel" id="par_width">
                                     <property name="visible">True</property>
                                     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                                    <property name="label" translatable="yes">--:--</property>
+                                    <property name="label" translatable="yes">--</property>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>
                                     <property name="position">1</property>
                                   </packing>
                                 </child>
+                                <child>
+                                  <object class="GtkLabel" id="pixel_aspect">
+                                    <property name="visible">True</property>
+                                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                                    <property name="label" translatable="yes">:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">2</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="par_height">
+                                    <property name="visible">True</property>
+                                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                                    <property name="label" translatable="yes">--</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">3</property>
+                                  </packing>
+                                </child>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
index 21635a2..5012576 100644 (file)
@@ -2577,7 +2577,7 @@ ghb_get_default_acodec()
 static void
 picture_settings_deps(signal_user_data_t *ud)
 {
-       gboolean autoscale, keep_aspect;
+       gboolean autoscale, keep_aspect, enable_keep_aspect;
        gboolean enable_scale_width, enable_scale_height;
        gboolean enable_disp_width, enable_disp_height;
        gint pic_par, disp_width, disp_height, scale_width, scale_height;
@@ -2594,6 +2594,7 @@ picture_settings_deps(signal_user_data_t *ud)
        enable_scale_height = !autoscale && (pic_par != 1);
        enable_disp_width = (pic_par == 3) && !keep_aspect;
        enable_disp_height = FALSE;
+       enable_keep_aspect = (pic_par != 1 && pic_par != 2);
 
        GtkWidget *widget;
        widget = GHB_WIDGET(ud->builder, "scale_width");
@@ -2604,6 +2605,18 @@ picture_settings_deps(signal_user_data_t *ud)
        gtk_widget_set_sensitive(widget, enable_disp_width);
        widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
        gtk_widget_set_sensitive(widget, enable_disp_height);
+       widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
+       gtk_widget_set_sensitive(widget, enable_keep_aspect);
+       widget = GHB_WIDGET(ud->builder, "autoscale");
+       gtk_widget_set_sensitive(widget, pic_par != 1);
+       if (!enable_keep_aspect)
+       {
+               ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
+       }
+       if (pic_par == 1)
+       {
+               ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
+       }
 }
 
 void
@@ -2618,8 +2631,8 @@ ghb_set_scale(signal_user_data_t *ud, gint mode)
        gint crop[4], width, height, par_width, par_height;
        gint crop_width, crop_height;
        gint aspect_n, aspect_d;
-       gboolean keep_width = (mode == GHB_SCALE_KEEP_WIDTH);
-       gboolean keep_height = (mode == GHB_SCALE_KEEP_HEIGHT);
+       gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
+       gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
        gint step;
        GtkWidget *widget;
        gint mod;
@@ -2784,8 +2797,22 @@ ghb_set_scale(signal_user_data_t *ud, gint mode)
                if (job->anamorphic.mode == 3 && !keep_aspect)
                {
                        gint dar_width, dar_height;
-                       dar_width = ghb_settings_get_int(ud->settings, "PictureDisplayWidth");
-                       dar_height = ghb_settings_get_int(ud->settings, "PictureDisplayHeight");
+                       if (mode & GHB_PIC_KEEP_PAR)
+                       {
+                               par_width = ghb_settings_get_int(ud->settings, 
+                                                                                               "PicturePARWidth");
+                               par_height = ghb_settings_get_int(ud->settings, 
+                                                                                               "PicturePARHeight");
+                               dar_width = ((gdouble)width * par_width / par_height) + 0.5;
+                               dar_height = height;
+                       }
+                       else
+                       {
+                               dar_width = ghb_settings_get_int(ud->settings, 
+                                                                                               "PictureDisplayWidth");
+                               dar_height = ghb_settings_get_int(ud->settings, 
+                                                                                               "PictureDisplayHeight");
+                       }
                        job->anamorphic.dar_width = dar_width;
                        job->anamorphic.dar_height = dar_height;
                }
@@ -2805,8 +2832,6 @@ ghb_set_scale(signal_user_data_t *ud, gint mode)
                        gdouble par;
                        gint new_width, new_height;
                        
-                       g_debug("kw %s kh %s\n", keep_width ? "y":"n", keep_height ? "y":"n");
-                       g_debug("w %d h %d\n", width, height);
                        // Compute pixel aspect ration.  
                        par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
                        // Must scale so that par becomes 1:1
@@ -2854,22 +2879,30 @@ ghb_set_scale(signal_user_data_t *ud, gint mode)
        gint disp_width, dar_width, dar_height;
        gchar *str;
 
-       disp_width = par_width * width / par_height;
+       disp_width = (gdouble)(width * par_width / par_height) + 0.5;
        hb_reduce(&dar_width, &dar_height, disp_width, height);
                
+       gint iaspect = dar_width * 9 / dar_height;
        if (dar_width > 2 * dar_height)
        {
-               str = g_strdup_printf("%.2f:1", (gdouble)dar_width / dar_height);
+               str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
+       }
+       else if (iaspect <= 16 && iaspect >= 15)
+       {
+               str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
+       }
+       else if (iaspect <= 12 && iaspect >= 11)
+       {
+               str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
        }
        else
        {
-               str = g_strdup_printf("%d:%d", dar_width, dar_height);
+               str = g_strdup_printf("%d : %d", dar_width, dar_height);
        }
        ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
        g_free(str);
-       str = g_strdup_printf("%d:%d", par_width, par_height);
-       ghb_ui_update(ud, "pixel_aspect", ghb_string_value(str));
-       g_free(str);
+       ghb_ui_update(ud, "par_width", ghb_int64_value(par_width));
+       ghb_ui_update(ud, "par_height", ghb_int64_value(par_height));
        ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
        ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
        picture_settings_deps(ud);
index dcf80c7..b4f6977 100644 (file)
@@ -53,9 +53,12 @@ typedef struct
        ghb_instance_status_t queue;
 } ghb_status_t;
 
-#define GHB_SCALE_KEEP_NONE 0
-#define GHB_SCALE_KEEP_WIDTH 1
-#define GHB_SCALE_KEEP_HEIGHT 2
+#define GHB_PIC_KEEP_WIDTH          0x01
+#define GHB_PIC_KEEP_HEIGHT         0x02
+#define GHB_PIC_KEEP_DISPLAY_WIDTH  0x04
+#define GHB_PIC_KEEP_DISPLAY_HEIGHT 0x08
+#define GHB_PIC_KEEP_DAR            0x10
+#define GHB_PIC_KEEP_PAR            0x20
 
 typedef struct
 {
@@ -118,6 +121,7 @@ void ghb_track_status(void);
 void ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count);
 void ghb_backend_queue_scan(const gchar *path, gint titleindex);
 gboolean ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex);
+void ghb_par_init(signal_user_data_t *ud);
 void ghb_set_scale(signal_user_data_t *ud, gint mode);
 GValue* ghb_get_chapters(gint titleindex);
 void ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss);
index ad93669..3c2beaf 100644 (file)
                <true />
                <key>autoscale</key>
                <false />
+               <key>par_width</key>
+               <integer>0</integer>
+               <key>par_height</key>
+               <integer>0</integer>
                <key>vquality_type_bitrate</key>
                <false />
                <key>vquality_type_constant</key>
                <string>none</string>
                <key>PictureDetelecineCustom</key>
                <string></string>
+               <key>PicturePAR</key>
+               <integer>2</integer>
+               <key>PicturePARWidth</key>
+               <integer>853</integer>
+               <key>PicturePARHeight</key>
+               <integer>720</integer>
+               <key>PictureHeight</key>
+               <integer>0</integer>
+               <key>PictureWidth</key>
+               <integer>0</integer>
                <key>SubtitlesForced</key>
                <true />
                <key>VideoFramerate</key>
                <true />
                <key>Mp4LargeFile</key>
                <false />
-               <key>PicturePAR</key>
-               <integer>2</integer>
-               <key>PictureHeight</key>
-               <integer>0</integer>
-               <key>PictureWidth</key>
-               <integer>0</integer>
                <key>AudioList</key>
                <array>
                        <dict>
index fb4bfc2..2a07291 100644 (file)
@@ -45,6 +45,18 @@ static void store_plist(GValue *plist, const gchar *name);
 static void store_presets(void);
 static void store_prefs(void);
 
+gint
+preset_path_cmp(gint *indices1, gint len1, gint *indices2, gint len2)
+{
+       gint ii;
+       for (ii = 0; ii < len1 && ii < len2; ii++)
+       {
+               if (indices1[ii] != indices2[ii])
+                       return indices1[ii] - indices2[ii];
+       }
+       return len1 - len2;
+}
+
 // This only handle limited depth
 GtkTreePath*
 ghb_tree_path_new_from_indices(gint *indices, gint len)
@@ -2183,7 +2195,7 @@ import_xlat_preset(GValue *dict)
 {
        gboolean uses_max;
        gint uses_pic;
-       gint par;
+       gint par, par_width, par_height;
        gint vqtype;
 
        g_debug("import_xlat_preset ()");
@@ -2193,6 +2205,12 @@ import_xlat_preset(GValue *dict)
                                                preset_dict_get_value(dict, "UsesPictureSettings"));
        par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
        vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
+       par_width = ghb_value_int(preset_dict_get_value(dict, "PicturePARWidth"));
+       par_height = ghb_value_int(preset_dict_get_value(dict, "PicturePARHeight"));
+       ghb_dict_insert(dict, g_strdup("par_width"), 
+                                       ghb_int_value_new(par_width));
+       ghb_dict_insert(dict, g_strdup("par_height"), 
+                                       ghb_int_value_new(par_height));
 
        if (uses_max || uses_pic == 2)
        {
@@ -2337,6 +2355,7 @@ static void
 export_xlat_preset(GValue *dict)
 {
        gboolean autoscale, target, br, constant;
+       gint par_width, par_height;
 
        g_debug("export_xlat_prest ()");
        autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
@@ -2346,6 +2365,10 @@ export_xlat_preset(GValue *dict)
                                preset_dict_get_value(dict, "vquality_type_bitrate"));
        constant = ghb_value_boolean(
                                preset_dict_get_value(dict, "vquality_type_constant"));
+       par_width = ghb_value_int(
+                               preset_dict_get_value(dict, "par_width"));
+       par_height = ghb_value_int(
+                               preset_dict_get_value(dict, "par_height"));
 
        if (autoscale)
                ghb_dict_insert(dict, g_strdup("UsesPictureSettings"), 
@@ -2370,11 +2393,17 @@ export_xlat_preset(GValue *dict)
                ghb_dict_insert(dict, g_strdup("VideoQualityType"), 
                                                ghb_int_value_new(2));
        }
+       ghb_dict_insert(dict, g_strdup("PicturePARWidth"), 
+                                               ghb_int_value_new(par_width));
+       ghb_dict_insert(dict, g_strdup("PicturePARHeight"), 
+                                               ghb_int_value_new(par_height));
        ghb_dict_remove(dict, "UsesMaxPictureSettings");
        ghb_dict_remove(dict, "autoscale");
        ghb_dict_remove(dict, "vquality_type_target");
        ghb_dict_remove(dict, "vquality_type_bitrate");
        ghb_dict_remove(dict, "vquality_type_constant");
+       ghb_dict_remove(dict, "par_width");
+       ghb_dict_remove(dict, "par_height");
        export_value_xlat(dict);
 }
 
@@ -2532,6 +2561,7 @@ settings_save(signal_user_data_t *ud, const GValue *path)
        GValue *value;
        gboolean autoscale;
        gint *indices, len, count;
+       gint *def_indices, def_len;
        const gchar *name;
        gboolean replace = FALSE;
 
@@ -2622,7 +2652,16 @@ settings_save(signal_user_data_t *ud, const GValue *path)
        }
        ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(name));
        if (replace)
+       {
+               def_indices = presets_find_default(presetsPlist, &def_len);
+               if (def_indices != NULL && 
+                       preset_path_cmp(indices, len, def_indices, def_len) != 0)
+               {
+                       ghb_dict_insert(dict, g_strdup("Default"), 
+                                                       ghb_boolean_value_new(FALSE));
+               }
                presets_list_update_item(ud, indices, len);
+       }
        else
        {
                ghb_dict_insert(dict, g_strdup("Default"), 
@@ -3221,10 +3260,21 @@ presets_row_expanded_cb(
 {
        gint *indices, len;
        gboolean expanded, folder;
+       GValue *dict;
 
        expanded = gtk_tree_view_row_expanded(treeview, path);
        indices = gtk_tree_path_get_indices(path);
        len = gtk_tree_path_get_depth(path);
+       dict = presets_get_dict(presetsPlist, indices, len);
+       if (preset_folder_is_open(dict))
+       {
+               if (expanded)
+                       return;
+       }
+       else if (!expanded)
+       {
+               return;
+       }
        folder = ghb_presets_get_folder(presetsPlist, indices, len);
        if (folder)
        {
@@ -3235,7 +3285,6 @@ presets_row_expanded_cb(
        if (!expanded)
        {
                GValue *presets = NULL;
-               GValue *dict;
                gint *more_indices, count, ii;
 
                more_indices = g_malloc((len+1)*sizeof(gint));
@@ -3342,12 +3391,12 @@ presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_
                        titleindex = ghb_settings_combo_int(ud->settings, "title");
                        ghb_set_pref_audio(titleindex, ud);
                        ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
-                       ud->dont_clear_presets = FALSE;
                        if (ghb_get_title_info (&tinfo, titleindex))
                        {
                                preset_update_title_deps(ud, &tinfo);
                        }
-                       ghb_set_scale (ud, GHB_SCALE_KEEP_NONE);
+                       ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
+                       ud->dont_clear_presets = FALSE;
 
                        gdouble vqmin, vqmax, step, page;
                        gint digits;