Skip to content

Commit

Permalink
LinGui: Reworked dimensions tab
Browse files Browse the repository at this point in the history
Also includes libhb changes to support new dimensions tab.

New libhb function hb_rotate_geometry() helper for rotating dimensions
tab settings when rotation filter settings change.

Simplified hb_set_anamorphic_size2 and added support for updating
display size.

Added new pad filter parameters top, bottom, left, right to make
interface to pad filter fit more easily with our UI.

Added preset keys for pad filter PicturePadMode, PicturePadColor,
PicturePadTop, PicturePadBottom, PicturePadLeft, PicturePadRight.

Added preset keys PictureAllowUpscaling, PictureUseMaximumSize which are
used in the new dimensions tab.
  • Loading branch information
jstebbins committed May 2, 2021
1 parent bae2225 commit 6ae34e0
Show file tree
Hide file tree
Showing 25 changed files with 10,704 additions and 9,700 deletions.
209 changes: 148 additions & 61 deletions gtk/src/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -2206,42 +2206,6 @@ get_aspect_string(gint aspect_n, gint aspect_d)
return aspect;
}

static void
update_aspect_info(signal_user_data_t *ud)
{
}

static void
update_crop_info(signal_user_data_t *ud)
{
GtkWidget *widget;
gchar *text;
gint width, height, crop[4] = {0,};
gint title_id, titleindex;
const hb_title_t *title;

title_id = ghb_dict_get_int(ud->settings, "title");
title = ghb_lookup_title(title_id, &titleindex);
if (title != NULL)
{
crop[0] = ghb_dict_get_int(ud->settings, "PictureTopCrop");
crop[1] = ghb_dict_get_int(ud->settings, "PictureBottomCrop");
crop[2] = ghb_dict_get_int(ud->settings, "PictureLeftCrop");
crop[3] = ghb_dict_get_int(ud->settings, "PictureRightCrop");
width = title->geometry.width - crop[2] - crop[3];
height = title->geometry.height - crop[0] - crop[1];
text = g_strdup_printf ("%d x %d", width, height);
widget = GHB_WIDGET(ud->builder, "crop_dimensions2");
gtk_label_set_text(GTK_LABEL(widget), text);
g_free(text);
}
}

static void
update_scale_info(signal_user_data_t *ud)
{
}

void
ghb_update_title_info(signal_user_data_t *ud)
{
Expand Down Expand Up @@ -2282,14 +2246,19 @@ ghb_update_title_info(signal_user_data_t *ud)
widget = GHB_WIDGET(ud->builder, "source_info_label");
gtk_label_set_text(GTK_LABEL(widget), text);
free(text);
free(aspect);
free(rate);

ghb_update_display_aspect_label(ud);
text = g_strdup_printf("%d x %d", geo->width, geo->height);
ghb_ui_update(ud, "source_storage_size", ghb_string_value(text));
g_free(text);

text = g_strdup_printf("%d x %d", geo->width * geo->par.num / geo->par.den,
geo->height);
ghb_ui_update(ud, "source_display_size", ghb_string_value(text));
g_free(text);

update_crop_info(ud);
update_aspect_info(ud);
update_scale_info(ud);
ghb_ui_update(ud, "source_aspect_ratio", ghb_string_value(aspect));
free(aspect);
}

static void update_meta(GhbValue *settings, const char *name, const char *val)
Expand Down Expand Up @@ -2518,7 +2487,7 @@ ghb_update_summary_info(signal_user_data_t *ud)
sval = ghb_dict_get_string(ud->settings, "PictureSharpenFilter");
unsharp = sval != NULL && !strcasecmp(sval, "unsharp");
lapsharp = sval != NULL && !strcasecmp(sval, "lapsharp");
sval = ghb_dict_get_string(ud->settings, "PictureRotate");
sval = ghb_dict_get_string(ud->settings, "rotate");
rot = sval != NULL && !!strcasecmp(sval, "disable=1");
gray = ghb_dict_get_bool(ud->settings, "VideoGrayScale");

Expand Down Expand Up @@ -2602,16 +2571,16 @@ ghb_update_summary_info(signal_user_data_t *ud)

width = ghb_dict_get_int(ud->settings, "scale_width");
height = ghb_dict_get_int(ud->settings, "scale_height");
display_width = ghb_dict_get_int(ud->settings, "PictureDisplayWidth");
display_height = ghb_dict_get_int(ud->settings, "PictureDisplayHeight");
display_width = ghb_dict_get_int(ud->settings, "PictureDARWidth");
display_height = ghb_dict_get_int(ud->settings, "DisplayHeight");
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");
display_width = ghb_dict_get_int(ud->settings, "PictureDARWidth");
text = g_strdup_printf("%dx%d storage, %dx%d display\n"
"%d:%d Pixel Aspect Ratio\n"
"%s Display Aspect Ratio",
Expand All @@ -2622,6 +2591,7 @@ ghb_update_summary_info(signal_user_data_t *ud)

g_free(text);
g_free(display_aspect);

ghb_value_free(&titleDict);
}

Expand Down Expand Up @@ -2661,15 +2631,25 @@ ghb_set_title_settings(signal_user_data_t *ud, GhbValue *settings)
ghb_dict_set_string(settings, "volume", label);
g_free(label);


int angle, hflip;
hb_geometry_crop_t srcGeo;

srcGeo.geometry = title->geometry;
memcpy(srcGeo.crop, &title->crop, 4 * sizeof(int));
angle = ghb_dict_get_int(settings, "rotate");
hflip = ghb_dict_get_int(settings, "hflip");
hb_rotate_geometry(&srcGeo, &srcGeo, angle, hflip);
ghb_apply_crop(settings, &srcGeo);

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]);
srcGeo.geometry.width - crop[2] - crop[3]);

// If anamorphic or keep_aspect, the height will
// be automatically calculated
Expand All @@ -2683,10 +2663,10 @@ ghb_set_title_settings(signal_user_data_t *ud, GhbValue *settings)
pic_par == HB_ANAMORPHIC_CUSTOM)
{
ghb_dict_set_int(settings, "scale_height",
title->geometry.height - crop[0] - crop[1]);
srcGeo.geometry.height - crop[0] - crop[1]);
}

ghb_set_scale_settings(settings, GHB_PIC_KEEP_PAR|GHB_PIC_USE_MAX);
ghb_set_scale_settings(ud, settings, GHB_PIC_USE_MAX);
ghb_dict_set_int(settings, "angle_count", title->angle_count);

ghb_dict_set_string(settings, "MetaName", title->name);
Expand Down Expand Up @@ -2734,6 +2714,7 @@ ghb_set_title_settings(signal_user_data_t *ud, GhbValue *settings)
{
ghb_dict_set_string(settings, "source_label", _("No Title Found"));
ghb_dict_set_string(settings, "volume", _("New Video"));
ghb_set_scale_settings(ud, settings, GHB_PIC_USE_MAX);
}

set_destination_settings(ud, settings);
Expand Down Expand Up @@ -3378,11 +3359,9 @@ 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_PIC_KEEP_PAR);
ghb_set_scale(ud, GHB_PIC_KEEP_WIDTH);
update_preview = TRUE;
ghb_live_reset(ud);

update_scale_info(ud);
}

G_MODULE_EXPORT void
Expand All @@ -3393,12 +3372,10 @@ 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_PIC_KEEP_PAR);
ghb_set_scale(ud, GHB_PIC_KEEP_HEIGHT);

update_preview = TRUE;
ghb_live_reset(ud);

update_scale_info(ud);
}

G_MODULE_EXPORT void
Expand All @@ -3409,11 +3386,23 @@ 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, GHB_PIC_KEEP_PAR);
ghb_set_scale(ud, 0);
update_preview = TRUE;
ghb_live_reset(ud);
}

update_crop_info(ud);
G_MODULE_EXPORT void
pad_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
g_debug("pad_changed_cb ()");
ghb_widget_to_setting(ud->settings, widget);
ghb_check_dependency(ud, widget, NULL);
ghb_clear_presets_selection(ud);
ghb_live_reset(ud);
if (gtk_widget_is_sensitive(widget))
ghb_set_scale(ud, 0);

update_preview = TRUE;
}

G_MODULE_EXPORT void
Expand All @@ -3439,7 +3428,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_PIC_KEEP_PAR);
ghb_set_scale(ud, GHB_PIC_KEEP_DISPLAY_HEIGHT);

update_preview = TRUE;
}
Expand All @@ -3453,7 +3442,7 @@ par_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_PAR);
ghb_set_scale(ud, GHB_PIC_KEEP_HEIGHT);

update_preview = TRUE;
}
Expand All @@ -3467,10 +3456,108 @@ 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, GHB_PIC_KEEP_PAR);
ghb_set_scale(ud, 0);
update_preview = TRUE;
}

G_MODULE_EXPORT void
rotate_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
int angle, hflip, prev_angle, prev_hflip;

update_aspect_info(ud);
g_debug("rotate_changed_cb ()");
prev_angle = ghb_dict_get_int(ud->settings, "rotate");
prev_hflip = ghb_dict_get_int(ud->settings, "hflip");

ghb_widget_to_setting(ud->settings, widget);
ghb_check_dependency(ud, widget, NULL);
ghb_clear_presets_selection(ud);
ghb_live_reset(ud);

hb_geometry_crop_t geo;

// First normalize current settings to 0 angle 0 hflip
geo.geometry.width = ghb_dict_get_int(ud->settings, "scale_width");
geo.geometry.height = ghb_dict_get_int(ud->settings, "scale_height");
geo.geometry.par.num =
ghb_dict_get_int(ud->settings, "PicturePARWidth");
geo.geometry.par.den =
ghb_dict_get_int(ud->settings, "PicturePARHeight");
geo.crop[0] = ghb_dict_get_int(ud->settings, "PictureTopCrop");
geo.crop[1] = ghb_dict_get_int(ud->settings, "PictureBottomCrop");
geo.crop[2] = ghb_dict_get_int(ud->settings, "PictureLeftCrop");
geo.crop[3] = ghb_dict_get_int(ud->settings, "PictureRightCrop");

geo.pad[0] = ghb_dict_get_int(ud->settings, "PicturePadTop");
geo.pad[1] = ghb_dict_get_int(ud->settings, "PicturePadBottom");
geo.pad[2] = ghb_dict_get_int(ud->settings, "PicturePadLeft");
geo.pad[3] = ghb_dict_get_int(ud->settings, "PicturePadRight");
// Normally hflip is applied, then rotation.
// To revert, must apply rotation then hflip.
hb_rotate_geometry(&geo, &geo, 360 - prev_angle, 0);
hb_rotate_geometry(&geo, &geo, 0, prev_hflip);

const hb_title_t * title;
int title_id, titleindex;

title_id = ghb_dict_get_int(ud->settings, "title");
title = ghb_lookup_title(title_id, &titleindex);
if (title != NULL)
{
// If there is a title, reset to title width/height so that
// dimension limits get properly re-applied
geo.geometry.width = title->geometry.width;
geo.geometry.height = title->geometry.height;
}

// rotate dimensions to new angle and hflip
angle = ghb_dict_get_int(ud->settings, "rotate");
hflip = ghb_dict_get_int(ud->settings, "hflip");
hb_rotate_geometry(&geo, &geo, angle, hflip);

ghb_dict_set_int(ud->settings, "scale_width",
geo.geometry.width - geo.crop[2] - geo.crop[3]);
ghb_dict_set_int(ud->settings, "scale_height",
geo.geometry.height - geo.crop[0] - geo.crop[1]);
ghb_dict_set_int(ud->settings, "PicturePARWidth", geo.geometry.par.num);
ghb_dict_set_int(ud->settings, "PicturePARHeight", geo.geometry.par.den);
ghb_dict_set_int(ud->settings, "PictureTopCrop", geo.crop[0]);
ghb_dict_set_int(ud->settings, "PictureBottomCrop", geo.crop[1]);
ghb_dict_set_int(ud->settings, "PictureLeftCrop", geo.crop[2]);
ghb_dict_set_int(ud->settings, "PictureRightCrop", geo.crop[3]);

ghb_dict_set_int(ud->settings, "PicturePadTop", geo.pad[0]);
ghb_dict_set_int(ud->settings, "PicturePadBottom", geo.pad[1]);
ghb_dict_set_int(ud->settings, "PicturePadLeft", geo.pad[2]);
ghb_dict_set_int(ud->settings, "PicturePadRight", geo.pad[3]);

ghb_set_scale(ud, 0);
update_preview = TRUE;
}

G_MODULE_EXPORT void
resolution_limit_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
g_debug("resolution_limit_changed_cb ()");
ghb_widget_to_setting(ud->settings, widget);
ghb_check_dependency(ud, widget, NULL);
ghb_clear_presets_selection(ud);
ghb_live_reset(ud);

const gchar * resolution_limit;
int width, height;

resolution_limit = ghb_dict_get_string(ud->settings, "resolution_limit");
ghb_lookup_resolution_limit_dimensions(resolution_limit, &width, &height);
if (width >= 0 && height >= 0)
{
ghb_dict_set_int(ud->settings, "PictureWidth", width);
ghb_dict_set_int(ud->settings, "PictureHeight", height);
}

ghb_set_scale(ud, GHB_PIC_KEEP_HEIGHT);

update_preview = TRUE;
}

G_MODULE_EXPORT void
Expand Down
Loading

0 comments on commit 6ae34e0

Please sign in to comment.