[vlc-commits] window: fit window dimensions before display
Rémi Denis-Courmont
git at videolan.org
Sun Sep 2 16:26:31 CEST 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Oct 22 19:20:29 2014 +0300| [e9daaafd7cd2ac4df2c1348b009b27df03721938] | committer: Rémi Denis-Courmont
window: fit window dimensions before display
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e9daaafd7cd2ac4df2c1348b009b27df03721938
---
src/video_output/window.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 106 insertions(+)
diff --git a/src/video_output/window.c b/src/video_output/window.c
index 570393e20f..f1c6dfc286 100644
--- a/src/video_output/window.c
+++ b/src/video_output/window.c
@@ -28,6 +28,9 @@
# include "config.h"
#endif
#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <vlc_common.h>
#include <vlc_vout_window.h>
@@ -127,6 +130,102 @@ void vout_window_SetInhibition(vout_window_t *window, bool enabled)
#define DOUBLE_CLICK_TIME VLC_TICK_FROM_MS(300)
+static void vout_display_window_GetSize(vlc_object_t *obj,
+ const video_format_t *restrict source,
+ unsigned *restrict width,
+ unsigned *restrict height)
+{
+ *width = var_InheritInteger(obj, "width");
+ *height = var_InheritInteger(obj, "height");
+
+ /* If both width and height are forced, keep them as is. */
+ if (*width != (unsigned)-1 && *height != (unsigned)-1)
+ return;
+
+ /* Compute intended video resolution from source. */
+ unsigned w = source->i_visible_width;
+ unsigned h = source->i_visible_height;
+
+ assert(source->i_sar_num > 0 && source->i_sar_den > 0);
+ w = (w * source->i_sar_num) / source->i_sar_den;
+
+ char *crop = var_InheritString(obj, "crop");
+ if (crop != NULL)
+ {
+ unsigned num, den, cw, ch, top, bottom, left, right;
+
+ if (sscanf(crop, "%u:%u", &num, &den) == 2 && num > 0 && den > 0) {
+ if (w * den > h * num)
+ w = h * num / den;
+ else
+ h = w * den / num;
+ } else
+ if (sscanf(crop, "%ux%u+%*u+%u", &cw, &ch, &(unsigned){ 0 }) == 3) {
+ w = cw;
+ h = ch;
+ } else
+ if (sscanf(crop, "%u+%u+%u+%u", &left, &top, &right, &bottom) == 4
+ && right > left && bottom > top) {
+ w = right - left;
+ h = bottom - top;
+ } else
+ msg_Warn(obj, "Unknown crop format (%s)", crop);
+ free(crop);
+ }
+
+ char *aspect = crop ? NULL : var_InheritString(obj, "aspect-ratio");
+ if (aspect != NULL) {
+ unsigned num, den;
+
+ if (sscanf(aspect, "%u:%u", &num, &den) == 2 && num > 0 && den > 0)
+ w = h * num / den;
+ else
+ msg_Warn(obj, "Unknown aspect format (%s)", aspect);
+ free(aspect);
+ }
+
+ /* Adjust video size for orientation and pixel A/R. */
+ if (ORIENT_IS_SWAP(source->orientation)) {
+ unsigned x = w;
+
+ w = h;
+ h = x;
+ }
+
+ unsigned par_num, par_den;
+ if (var_InheritURational(obj, &par_num, &par_den, "monitor-par") == 0
+ && par_num > 0 && par_den > 0)
+ w = (w * par_den) / par_num;
+
+ /* If width is forced, adjust height according to the aspect ratio */
+ if (*width != (unsigned)-1) {
+ *height = (*width * h) / w;
+ return;
+ }
+
+ /* If height is forced, adjust width according to the aspect ratio */
+ if (*height != (unsigned)-1) {
+ *width = (*height * w) / h;
+ return;
+ }
+
+ /* If neither width nor height are forced, use the requested zoom. */
+ float zoom = var_InheritFloat(obj, "zoom");
+
+ if (isnan(zoom))
+ zoom = 1.f;
+ else
+ zoom = fabsf(zoom);
+
+ if (zoom < 0.1f)
+ zoom = 0.1f;
+ if (zoom > 10.f)
+ zoom = 10.f;
+
+ *width = lroundf(zoom * (float)w);
+ *height = lroundf(zoom * (float)h);
+}
+
typedef struct vout_display_window
{
vout_display_t *vd;
@@ -292,6 +391,13 @@ vout_window_t *vout_display_window_New(vout_thread_t *vout,
void vout_display_window_UpdateSize(vout_window_t *window,
const video_format_t *restrict fmt)
{
+ unsigned width, height;
+
+ vout_display_window_GetSize(VLC_OBJECT(window), fmt, &width, &height);
+ if (width > 0 && height > 0) {
+ msg_Dbg(window, "requested size: %ux%u", width, height);
+ vout_window_SetSize(window, width, height);
+ }
}
/**
More information about the vlc-commits
mailing list