shithub: treason

Download patch

ref: 60f4589f28583b6d83dde28c70be3b16092d2858
parent: 98ff0d3b979916a86e675557021c485ee07ba04b
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Sep 16 15:33:30 EDT 2020

crop frames

--- a/decoder_av1.c
+++ b/decoder_av1.c
@@ -79,6 +79,7 @@
 		}else if((f = malloc(sizeof(*f) + pic.p.w*pic.p.h*3)) != nil){
 			f->w = pic.p.w;
 			f->h = pic.p.h;
+			memset(&f->crop, 0, sizeof(f->crop));
 			yuv420_rgb24(f->w, f->h, pic.data[0], pic.data[1], pic.data[2], pic.stride[0], pic.stride[1], f->rgb, f->w*3);
 			f->dt = (pic.m.timestamp - lasttimestamp) * d->timebase * 1000000000ULL;
 			lasttimestamp = pic.m.timestamp;
--- a/decoder_h264.c
+++ b/decoder_h264.c
@@ -25,12 +25,13 @@
 	Aux *a;
 	int res, off;
 	u32int used, nerr, isidr, picid;
-	u32int realh, w, h, crop, left, top;
+	u32int realw, realh, w, h, crop, left, top;
 	u8int *pic;
 
 	d = x;
 	a = d->aux;
 	lasttimestamp = 0;
+	realw = 0;
 	realh = 0;
 	for(res = 0; res >= 0 && (res = Sread(d->s, &sf)) == 0 && sf.sz > 0;){
 		off = 0;
@@ -48,6 +49,10 @@
 			}else if((f = malloc(sizeof(*f) + w*h*3)) != nil){
 				f->w = w;
 				f->h = realh;
+				f->crop.left = left;
+				f->crop.top = top;
+				f->crop.right = realw;
+				f->crop.bottom = realh;
 				yuv420_rgb24(w, h, pic, pic+w*h, pic+w*h*5/4, w, w/2, f->rgb, w*3);
 				f->dt = (sf.timestamp - lasttimestamp) * d->timebase * 1000000000ULL;
 				lasttimestamp = sf.timestamp;
@@ -65,6 +70,7 @@
 				w = h264bsdPicWidth(&a->c) * 16;
 				h = h264bsdPicHeight(&a->c) * 16;
 			}
+			realw = w;
 			realh = h;
 			if(w & 15)
 				w += 16 - (w & 15);
--- a/decoder_vpx.c
+++ b/decoder_vpx.c
@@ -47,7 +47,12 @@
 			if((f = malloc(sizeof(*f) + im->w*im->h*3)) != nil){
 				f->w = im->w;
 				f->h = im->h;
+				f->crop.left = 0;
+				f->crop.top = 0;
+				f->crop.right = im->d_w;
+				f->crop.bottom = im->d_h;
 				yuv420_rgb24(im->w, im->h, im->planes[0], im->planes[1], im->planes[2], im->stride[0], im->stride[1], f->rgb, f->w*3);
+				vpx_img_free(im);
 				f->dt = (sf.timestamp - lasttimestamp) * d->timebase * 1000000000ULL;
 				lasttimestamp = sf.timestamp;
 
--- a/frame.h
+++ b/frame.h
@@ -1,7 +1,10 @@
 typedef struct Frame Frame;
 
 struct Frame {
-	int w, h;
 	uvlong dt;
+	int w, h;
+	struct {
+		int left, top, right, bottom;
+	}crop;
 	u8int rgb[1];
 };
--- a/main.c
+++ b/main.c
@@ -48,7 +48,7 @@
 {
 	uvlong x, end, left;
 	static uvlong delay;
-	Rectangle r;
+	Rectangle r, clip;
 
 	lockdisplay(display);
 
@@ -78,9 +78,14 @@
 			sleep(1);
 	}
 
+	clip = Rect(f->crop.left, f->crop.top, f->crop.right, f->crop.bottom);
+	if(badrect(clip))
+		clip = curim->r;
+	replclipr(curim, 0, clip);
+
 	x = nanosec();
-	if(Dx(r) < Dx(screen->r) && Dy(r) < Dy(screen->r))
-		r = rectsubpt(screen->r, divpt(Pt(Dx(r)-Dx(screen->r), Dy(r)-Dy(screen->r)), 2));
+	if(Dx(clip) < Dx(screen->r) && Dy(clip) < Dy(screen->r))
+		r = rectsubpt(screen->r, divpt(Pt(Dx(clip)-Dx(screen->r), Dy(clip)-Dy(screen->r)), 2));
 	else
 		r = screen->r;
 	draw(screen, r, curim, nil, ZP);