Skip to content

Commit

Permalink
Merge pull request HandBrake#19 from jstebbins/ana-custom
Browse files Browse the repository at this point in the history
Fix bizarre custom anamorphic behavior
  • Loading branch information
jstebbins committed Oct 26, 2015
2 parents af4bd04 + c8425c9 commit 79df3e5
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 78 deletions.
14 changes: 7 additions & 7 deletions gtk/src/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,7 @@ set_title_settings(signal_user_data_t *ud, GhbValue *settings)
if (!(keep_aspect || pic_par) || pic_par == 3)
{
ghb_dict_set_int(settings, "scale_height",
title->geometry.width - title->crop[0] - title->crop[1]);
title->geometry.height - title->crop[0] - title->crop[1]);
}

ghb_set_scale_settings(settings, GHB_PIC_KEEP_PAR|GHB_PIC_USE_MAX);
Expand Down Expand Up @@ -2501,7 +2501,7 @@ scale_width_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
ghb_check_dependency(ud, widget, NULL);
ghb_clear_presets_selection(ud);
if (gtk_widget_is_sensitive(widget))
ghb_set_scale(ud, GHB_PIC_KEEP_WIDTH);
ghb_set_scale(ud, GHB_PIC_KEEP_WIDTH|GHB_PIC_KEEP_PAR);
update_preview = TRUE;
ghb_live_reset(ud);

Expand All @@ -2516,7 +2516,7 @@ scale_height_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
ghb_check_dependency(ud, widget, NULL);
ghb_clear_presets_selection(ud);
if (gtk_widget_is_sensitive(widget))
ghb_set_scale(ud, GHB_PIC_KEEP_HEIGHT);
ghb_set_scale(ud, GHB_PIC_KEEP_HEIGHT|GHB_PIC_KEEP_PAR);

update_preview = TRUE;
ghb_live_reset(ud);
Expand All @@ -2532,7 +2532,7 @@ crop_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
ghb_check_dependency(ud, widget, NULL);
ghb_clear_presets_selection(ud);
if (gtk_widget_is_sensitive(widget))
ghb_set_scale(ud, 0);
ghb_set_scale(ud, GHB_PIC_KEEP_PAR);
update_preview = TRUE;
ghb_live_reset(ud);

Expand Down Expand Up @@ -2562,7 +2562,7 @@ display_height_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
ghb_clear_presets_selection(ud);
ghb_live_reset(ud);
if (gtk_widget_is_sensitive(widget))
ghb_set_scale(ud, GHB_PIC_KEEP_DISPLAY_HEIGHT);
ghb_set_scale(ud, GHB_PIC_KEEP_DISPLAY_HEIGHT|GHB_PIC_KEEP_PAR);

update_preview = TRUE;
}
Expand Down Expand Up @@ -2590,7 +2590,7 @@ scale_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
ghb_clear_presets_selection(ud);
ghb_live_reset(ud);
if (gtk_widget_is_sensitive(widget))
ghb_set_scale(ud, 0);
ghb_set_scale(ud, GHB_PIC_KEEP_PAR);
update_preview = TRUE;

update_aspect_info(ud);
Expand All @@ -2604,7 +2604,7 @@ show_crop_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
ghb_check_dependency(ud, widget, NULL);
ghb_live_reset(ud);
if (gtk_widget_is_sensitive(widget))
ghb_set_scale(ud, 0);
ghb_set_scale(ud, GHB_PIC_KEEP_PAR);
ghb_pref_save(ud->prefs, "preview_show_crop");
update_preview = TRUE;
}
Expand Down
51 changes: 32 additions & 19 deletions gtk/src/hb-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -3746,6 +3746,8 @@ ghb_set_scale_settings(GhbValue *settings, gint mode)
uiGeo.geometry.par.num =
ghb_dict_get_int(settings, "PictureDisplayWidth");
uiGeo.geometry.par.den = width;
hb_reduce(&uiGeo.geometry.par.num, &uiGeo.geometry.par.den,
uiGeo.geometry.par.num, uiGeo.geometry.par.den);
}
}
else
Expand Down Expand Up @@ -3881,9 +3883,10 @@ get_preview_geometry(signal_user_data_t *ud, const hb_title_t *title,
srcGeo->par = title->geometry.par;

uiGeo->mode = ghb_settings_combo_int(ud->settings, "PicturePAR");
uiGeo->keep = ghb_dict_get_bool(ud->settings, "PictureKeepRatio") ||
uiGeo->mode == HB_ANAMORPHIC_STRICT ||
uiGeo->mode == HB_ANAMORPHIC_LOOSE;
uiGeo->keep = (ghb_dict_get_bool(ud->settings, "PictureKeepRatio") ||
uiGeo->mode == HB_ANAMORPHIC_STRICT ||
uiGeo->mode == HB_ANAMORPHIC_LOOSE) ?
HB_KEEP_DISPLAY_ASPECT : 0;
uiGeo->itu_par = 0;
uiGeo->modulus = ghb_settings_combo_int(ud->settings, "PictureModulus");
uiGeo->crop[0] = ghb_dict_get_int(ud->settings, "PictureTopCrop");
Expand Down Expand Up @@ -4557,36 +4560,46 @@ ghb_get_preview_image(
src_line += image->plane[0].stride;
dst += stride;
}
gint w = ghb_dict_get_int(ud->settings, "scale_width");
gint h = ghb_dict_get_int(ud->settings, "scale_height");
ghb_par_scale(ud, &w, &h, resultGeo.par.num, resultGeo.par.den);

*out_width = ghb_dict_get_int(ud->settings, "scale_width");
*out_height = ghb_dict_get_int(ud->settings, "scale_height");
ghb_par_scale(ud, out_width, out_height,
resultGeo.par.num, resultGeo.par.den);

gint c0, c1, c2, c3;
c0 = ghb_dict_get_int(ud->settings, "PictureTopCrop");
c1 = ghb_dict_get_int(ud->settings, "PictureBottomCrop");
c2 = ghb_dict_get_int(ud->settings, "PictureLeftCrop");
c3 = ghb_dict_get_int(ud->settings, "PictureRightCrop");

gdouble xscale = (gdouble)w / (gdouble)(title->geometry.width - c2 - c3);
gdouble yscale = (gdouble)h / (gdouble)(title->geometry.height - c0 - c1);

*out_width = w;
*out_height = h;
gdouble xscale, yscale;
if (ghb_dict_get_bool(ud->prefs, "preview_show_crop"))
{
xscale = (gdouble)image->width / title->geometry.width;
yscale = (gdouble)image->height / title->geometry.height;
}
else
{
xscale = (gdouble)image->width / (title->geometry.width - c2 - c3);
yscale = (gdouble)image->height / (title->geometry.height - c0 - c1);
}

int previewWidth = image->width;
int previewHeight = image->height;

// If the preview is too large to fit the screen, reduce it's size.
if (ghb_dict_get_bool(ud->prefs, "reduce_hd_preview"))
{
GdkScreen *ss;
gint s_w, s_h;
gint factor = 80;

if (ghb_dict_get_bool(ud->prefs, "preview_fullscreen"))
{
factor = 100;
}

GdkScreen *ss;
gint s_w, s_h;

ss = gdk_screen_get_default();
s_w = gdk_screen_get_width(ss);
s_h = gdk_screen_get_height(ss);
Expand All @@ -4610,28 +4623,28 @@ ghb_get_preview_image(
}
xscale *= (gdouble)previewWidth / orig_w;
yscale *= (gdouble)previewHeight / orig_h;
w *= (gdouble)previewWidth / orig_w;
h *= (gdouble)previewHeight / orig_h;
scaled_preview = gdk_pixbuf_scale_simple(preview,
previewWidth, previewHeight, GDK_INTERP_HYPER);
g_object_unref(preview);
preview = scaled_preview;
}
}

if (ghb_dict_get_bool(ud->prefs, "preview_show_crop"))
{
c0 *= yscale;
c1 *= yscale;
c2 *= xscale;
c3 *= xscale;

// Top
hash_pixbuf(preview, c2, 0, w, c0, 32, 0);
hash_pixbuf(preview, 0, 0, previewWidth, c0, 32, 0);
// Bottom
hash_pixbuf(preview, c2, previewHeight-c1, w, c1, 32, 0);
hash_pixbuf(preview, 0, previewHeight-c1, previewWidth, c1, 32, 0);
// Left
hash_pixbuf(preview, 0, c0, c2, h, 32, 1);
hash_pixbuf(preview, 0, 0, c2, previewHeight, 32, 1);
// Right
hash_pixbuf(preview, previewWidth-c3, c0, c3, h, 32, 1);
hash_pixbuf(preview, previewWidth-c3, 0, c3, previewHeight, 32, 1);
}
hb_image_close(&image);
return preview;
Expand Down
5 changes: 5 additions & 0 deletions libhb/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@

#define HB_DVD_READ_BUFFER_SIZE 2048

#define HB_MIN_WIDTH 32
#define HB_MIN_HEIGHT 32
#define HB_MAX_WIDTH 20480
#define HB_MAX_HEIGHT 20480

typedef struct hb_handle_s hb_handle_t;
typedef struct hb_hwd_s hb_hwd_t;
typedef struct hb_list_s hb_list_t;
Expand Down
Loading

0 comments on commit 79df3e5

Please sign in to comment.