]> granicus.if.org Git - handbrake/commitdiff
LinGui: fix initial cropping (the right way)
authorJohn Stebbins <jstebbins.hb@gmail.com>
Fri, 16 Jun 2017 20:29:56 +0000 (13:29 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Fri, 16 Jun 2017 20:29:56 +0000 (13:29 -0700)
gtk/src/callbacks.c
gtk/src/hb-backend.c
gtk/src/hb-backend.h

index 862cd3c6e70c001ba51895b5b0579e4f71feb6da..469eb2b3bb729b3cf70a6493a27fa25d203f45db 100644 (file)
@@ -1885,7 +1885,16 @@ set_title_settings(signal_user_data_t *ud, GhbValue *settings)
             ghb_dict_set(settings, "volume_label", ghb_value_dup(
                     ghb_dict_get_value(ud->globals, "volume_label")));
         }
-        ghb_dict_set_int(settings, "scale_width", title->geometry.width);
+
+        int crop[4];
+
+        ghb_apply_crop(settings, title);
+        crop[0] = ghb_dict_get_int(settings, "PictureTopCrop");
+        crop[1] = ghb_dict_get_int(settings, "PictureBottomCrop");
+        crop[2] = ghb_dict_get_int(settings, "PictureLeftCrop");
+        crop[3] = ghb_dict_get_int(settings, "PictureRightCrop");
+        ghb_dict_set_int(settings, "scale_width",
+                 title->geometry.width - crop[2] - crop[3]);
 
         // If anamorphic or keep_aspect, the hight will
         // be automatically calculated
@@ -1898,7 +1907,8 @@ set_title_settings(signal_user_data_t *ud, GhbValue *settings)
             pic_par == HB_ANAMORPHIC_AUTO ||
             pic_par == HB_ANAMORPHIC_CUSTOM)
         {
-            ghb_dict_set_int(settings, "scale_height", title->geometry.height);
+            ghb_dict_set_int(settings, "scale_height",
+                title->geometry.height - crop[0] - crop[1]);
         }
 
         ghb_set_scale_settings(settings, GHB_PIC_KEEP_PAR|GHB_PIC_USE_MAX);
index 79e7c607d141d2b96b2d424a24a19769602047ed..ab8b8ef89d576a7b50538c7cf50365c81c977ee8 100644 (file)
@@ -3451,12 +3451,87 @@ ghb_limit_rational( gint *num, gint *den, gint limit )
     }
 }
 
+void
+ghb_apply_crop(GhbValue *settings, const hb_title_t * title)
+{
+    gboolean autocrop, loosecrop;
+    gint crop[4] = {0,};
+
+    autocrop = ghb_dict_get_bool(settings, "PictureAutoCrop");
+    // "PictureLooseCrop" is a flag that says we prefer to crop extra to
+    // satisfy alignment constraints rather than scaling to satisfy them.
+    loosecrop = ghb_dict_get_bool(settings, "PictureLooseCrop");
+
+    if (autocrop)
+    {
+        crop[0] = title->crop[0];
+        crop[1] = title->crop[1];
+        crop[2] = title->crop[2];
+        crop[3] = title->crop[3];
+    }
+    else
+    {
+        crop[0] = ghb_dict_get_int(settings, "PictureTopCrop");
+        crop[1] = ghb_dict_get_int(settings, "PictureBottomCrop");
+        crop[2] = ghb_dict_get_int(settings, "PictureLeftCrop");
+        crop[3] = ghb_dict_get_int(settings, "PictureRightCrop");
+    }
+    if (loosecrop)
+    {
+        gint need1, need2;
+        gint crop_width, crop_height, width, height;
+        gint mod;
+
+        mod = ghb_settings_combo_int(settings, "PictureModulus");
+        if (mod <= 0)
+            mod = 16;
+
+        // Adjust the cropping to accomplish the desired width and height
+        crop_width = title->geometry.width - crop[2] - crop[3];
+        crop_height = title->geometry.height - crop[0] - crop[1];
+        width = MOD_DOWN(crop_width, mod);
+        height = MOD_DOWN(crop_height, mod);
+
+        need1 = EVEN((crop_height - height) / 2);
+        need2 = crop_height - height - need1;
+        crop[0] += need1;
+        crop[1] += need2;
+        need1 = EVEN((crop_width - width) / 2);
+        need2 = crop_width - width - need1;
+        crop[2] += need1;
+        crop[3] += need2;
+    }
+    // Prevent crop from creating too small an image
+    if (title->geometry.height - crop[0] -crop[1] < 16)
+    {
+        crop[0] = title->geometry.height - crop[1] - 16;
+        if (crop[0] < 0)
+        {
+            crop[1] += crop[0];
+            crop[0] = 0;
+        }
+    }
+    if (title->geometry.width - crop[2] - crop[3] < 16)
+    {
+        crop[2] = title->geometry.width - crop[3] - 16;
+        if (crop[2] < 0)
+        {
+            crop[3] += crop[2];
+            crop[2] = 0;
+        }
+    }
+    ghb_dict_set_int(settings, "PictureTopCrop", crop[0]);
+    ghb_dict_set_int(settings, "PictureBottomCrop", crop[1]);
+    ghb_dict_set_int(settings, "PictureLeftCrop", crop[2]);
+    ghb_dict_set_int(settings, "PictureRightCrop", crop[3]);
+}
+
 void
 ghb_set_scale_settings(GhbValue *settings, gint mode)
 {
     gboolean keep_aspect;
     gint pic_par;
-    gboolean autocrop, autoscale, loosecrop;
+    gboolean autoscale;
     gint crop[4] = {0,};
     gint width, height;
     gint crop_width, crop_height;
@@ -3499,11 +3574,7 @@ ghb_set_scale_settings(GhbValue *settings, gint mode)
     if (mod <= 0)
         mod = 16;
     keep_aspect = ghb_dict_get_bool(settings, "PictureKeepRatio");
-    autocrop = ghb_dict_get_bool(settings, "PictureAutoCrop");
     autoscale = ghb_dict_get_bool(settings, "autoscale");
-    // "PictureLooseCrop" is a flag that says we prefer to crop extra to
-    // satisfy alignment constraints rather than scaling to satisfy them.
-    loosecrop = ghb_dict_get_bool(settings, "PictureLooseCrop");
     // Align dimensions to either 16 or 2 pixels
     // The scaler crashes if the dimensions are not divisible by 2
     // x264 also will not accept dims that are not multiple of 2
@@ -3513,56 +3584,11 @@ ghb_set_scale_settings(GhbValue *settings, gint mode)
         keep_height = FALSE;
     }
 
-    if (autocrop)
-    {
-        crop[0] = title->crop[0];
-        crop[1] = title->crop[1];
-        crop[2] = title->crop[2];
-        crop[3] = title->crop[3];
-        ghb_dict_set_int(settings, "PictureTopCrop", crop[0]);
-        ghb_dict_set_int(settings, "PictureBottomCrop", crop[1]);
-        ghb_dict_set_int(settings, "PictureLeftCrop", crop[2]);
-        ghb_dict_set_int(settings, "PictureRightCrop", crop[3]);
-    }
-    else
-    {
-        crop[0] = ghb_dict_get_int(settings, "PictureTopCrop");
-        crop[1] = ghb_dict_get_int(settings, "PictureBottomCrop");
-        crop[2] = ghb_dict_get_int(settings, "PictureLeftCrop");
-        crop[3] = ghb_dict_get_int(settings, "PictureRightCrop");
-        // Prevent manual crop from creating too small an image
-        if (title->geometry.height - crop[0] < crop[1] + 16)
-        {
-            crop[0] = title->geometry.height - crop[1] - 16;
-        }
-        if (title->geometry.width - crop[2] < crop[3] + 16)
-        {
-            crop[2] = title->geometry.width - crop[3] - 16;
-        }
-    }
-    if (loosecrop)
-    {
-        gint need1, need2;
-
-        // Adjust the cropping to accomplish the desired width and height
-        crop_width = title->geometry.width - crop[2] - crop[3];
-        crop_height = title->geometry.height - crop[0] - crop[1];
-        width = MOD_DOWN(crop_width, mod);
-        height = MOD_DOWN(crop_height, mod);
-
-        need1 = EVEN((crop_height - height) / 2);
-        need2 = crop_height - height - need1;
-        crop[0] += need1;
-        crop[1] += need2;
-        need1 = EVEN((crop_width - width) / 2);
-        need2 = crop_width - width - need1;
-        crop[2] += need1;
-        crop[3] += need2;
-        ghb_dict_set_int(settings, "PictureTopCrop", crop[0]);
-        ghb_dict_set_int(settings, "PictureBottomCrop", crop[1]);
-        ghb_dict_set_int(settings, "PictureLeftCrop", crop[2]);
-        ghb_dict_set_int(settings, "PictureRightCrop", crop[3]);
-    }
+    ghb_apply_crop(settings, title);
+    crop[0] = ghb_dict_get_int(settings, "PictureTopCrop");
+    crop[1] = ghb_dict_get_int(settings, "PictureBottomCrop");
+    crop[2] = ghb_dict_get_int(settings, "PictureLeftCrop");
+    crop[3] = ghb_dict_get_int(settings, "PictureRightCrop");
     uiGeo.crop[0] = crop[0];
     uiGeo.crop[1] = crop[1];
     uiGeo.crop[2] = crop[2];
index e21e4c47689abced5a6e61facb1bfd27d57b61ea..47627c71daf8d17a2ef64dafbd8662e6c7f76db6 100644 (file)
@@ -121,6 +121,7 @@ void ghb_backend_scan_stop();
 void ghb_backend_queue_scan(const gchar *path, gint titleindex);
 hb_list_t * ghb_get_title_list();
 void ghb_par_init(signal_user_data_t *ud);
+void ghb_apply_crop(GhbValue *settings, const hb_title_t * title);
 void ghb_set_scale(signal_user_data_t *ud, gint mode);
 void ghb_set_scale_settings(GhbValue *settings, gint mode);
 void ghb_picture_settings_deps(signal_user_data_t *ud);