Hi!

Another thing that bothered me about video(1) from Xenocara is that it does not
maintain frame aspect ratio.  The diff below adds panning to maintain aspect
ratio after resize.

Comments?  OKs?

--
Dmitrij D. Czarkoff

Index: video.c
===================================================================
RCS file: /var/cvs/xenocara/app/video/video.c,v
retrieving revision 1.21
diff -u -p -r1.21 video.c
--- video.c     21 Oct 2016 09:48:48 -0000      1.21
+++ video.c     25 Oct 2016 12:34:01 -0000
@@ -72,6 +72,11 @@ struct xdsp {
        int              saved_y;
        int              saved_w;
        int              saved_h;
+       int              resized;
+       int              box_x;
+       int              box_y;
+       int              box_w;
+       int              box_h;
        int              max_width;
        int              max_height;
        int              screen_id;
@@ -163,6 +168,7 @@ struct video {
        int              net_wm;
        int              width;
        int              height;
+       double           aspect;
        int              bpf;
        int              fps;
        int              nofps;
@@ -590,6 +596,20 @@ resize_window(struct video *vid, int ful
                x->saved_y = new_y;
        }
 
+       x->resized = 1;
+
+       if ((double)x->width > (double)x->height * vid->aspect) {
+               x->box_h = x->height;
+               x->box_y = 0;
+               x->box_w = (int)(x->height * vid->aspect);
+               x->box_x = (x->width - x->box_w) / 2;
+       } else {
+               x->box_w = x->width;
+               x->box_x = 0;
+               x->box_h = (int)(x->width / vid->aspect);
+               x->box_y = (x->height - x->box_h) / 2;
+       }
+
        XSync(x->dpy, False);
        XSync(x->dpy, True);
 }
@@ -1252,6 +1272,7 @@ choose_size(struct video *vid)
                        vid->fps = d->rates[i][cur];
                }
        }
+       vid->aspect = (double)vid->width / (double)vid->height;
 
        return 1;
 }
@@ -1715,9 +1736,13 @@ stream(struct video *vid)
                }
                if (vid->mode & M_OUT_XV) {
                        x->xv_image->data = src;
+                       if (x->resized) {
+                               x->resized = 0;
+                               XClearWindow(x->dpy, x->window);
+                       }
                        ret = XvPutImage(x->dpy, x->port, x->window, x->gc,
                            x->xv_image, 0, 0, vid->width, vid->height,
-                           0, 0, x->width, x->height);
+                           x->box_x, x->box_y, x->box_w, x->box_h);
                        if (ret != Success) {
                                warn("XvPutImage");
                                return 0;

Reply via email to