diff options
-rw-r--r-- | gtk/src/callbacks.c | 14 | ||||
-rw-r--r-- | gtk/src/hb-backend.c | 136 | ||||
-rw-r--r-- | gtk/src/hb-backend.h | 1 |
3 files changed, 94 insertions, 57 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c index 862cd3c6e..469eb2b3b 100644 --- a/gtk/src/callbacks.c +++ b/gtk/src/callbacks.c @@ -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); diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c index 79e7c607d..ab8b8ef89 100644 --- a/gtk/src/hb-backend.c +++ b/gtk/src/hb-backend.c @@ -3452,11 +3452,86 @@ 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]; diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h index e21e4c476..47627c71d 100644 --- a/gtk/src/hb-backend.h +++ b/gtk/src/hb-backend.h @@ -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); |