shithub: riscv

Download patch

ref: 3a83a68e0bd65e6609f067cd2d2c3acaa2364ff1
parent: 093ca3a18224e6d17413cd5e85301741ab92313e
author: cinap_lenrek <[email protected]>
date: Sat Mar 10 01:55:54 EST 2012

page: allow running external jpg(1) program for animated gifs, mothra: handle gif with page

--- a/sys/man/1/page
+++ b/sys/man/1/page
@@ -129,6 +129,16 @@
 .B Zerox
 Displays the current image in a new page window. 
 Useful for selecting important pages from large documents.
+.TP
+.B Write
+Asks for a filename and writes the current image as
+Plan 9 bitmap.
+.TP
+.B Ext
+Shows the current image using external
+.IR jpg (1)
+program in a separate window. This is mostly usefull for
+animated gifs. 
 .PD
 .PP
 Button 3 raises a menu of the
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -1020,17 +1020,6 @@
 			setcurrent(i, selection->tag);
 			break;
 		case GIF:
-			if(rfork(RFFDG|RFNOTEG|RFPROC|RFNAMEG|RFNOWAIT) == 0){
-				snprint(cmd, sizeof(cmd), "-pid %d", getpid());
-				if(newwindow(cmd) != -1){
-					close(1); open("/dev/cons", OWRITE);
-					print("reading gif...\n");
-					filter("gif", fd);
-				}
-				exits(0);
-			}
-			close(fd);
-			break;
 		case JPEG:
 		case PNG:
 		case BMP:
--- a/sys/src/cmd/page.c
+++ b/sys/src/cmd/page.c
@@ -11,6 +11,7 @@
 	char	*label;
 
 	QLock;
+	char	*ext;
 	void	*data;
 	int	(*open)(Page *);
 
@@ -60,6 +61,7 @@
 	Cprev,
 	Czerox,
 	Cwrite,
+	Cext,
 	Cdummy2,
 	Cquit,
 };
@@ -82,6 +84,7 @@
 	[Cprev]		"prev",		Kleft, Kbs, 0,
 	[Czerox]	"zerox",	'z', 0, 0,
 	[Cwrite]	"write",	'w', 0, 0,
+	[Cext]		"ext",		'x', 0, 0,
 	[Cdummy2]	"",		0, 0, 0,
 	[Cquit]		"quit",		'q', Kdel, Keof,
 };
@@ -285,8 +288,11 @@
 	}
 
 	seek(fd, 0, 0);
-	if(p->data)
-		pipeline(fd, "%s", (char*)p->data);
+	if(p->data){
+		p->ext = p->data;
+		snprint(nam, sizeof(nam), "%s -t9", p->ext);
+		pipeline(fd, "%s", nam);
+	}
 
 	/*
 	 * dont keep the file descriptor arround if it can simply
@@ -322,7 +328,7 @@
 
 	seek(p->fd, 0, 0);
 	snprint(mnt, sizeof(mnt), "/n/tapefs.%.12d%.8lux", getpid(), (ulong)p);
-	snprint(cmd, sizeof(cmd), "%s -m %s /fd/0", p->data, mnt);
+	snprint(cmd, sizeof(cmd), "%s -m %s /fd/0", (char*)p->data, mnt);
 	switch(rfork(RFPROC|RFMEM|RFFDG|RFREND)){
 	case -1:
 		close(p->fd);
@@ -485,7 +491,7 @@
 		goto Err1;
 	}
 
-	argv[0] = p->data;
+	argv[0] = (char*)p->data;
 	switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
 	case -1:
 		goto Err2;
@@ -663,11 +669,11 @@
 	"application/x-compress",	popenfilter,	"uncompress",
 	"application/x-gzip",		popenfilter,	"gunzip",
 	"application/x-bzip2",		popenfilter,	"bunzip2",
-	"image/gif",			popenimg,	"gif -t9",
-	"image/jpeg",			popenimg,	"jpg -t9",
-	"image/png",			popenimg,	"png -t9",
-	"image/ppm",			popenimg,	"ppm -t9",
-	"image/bmp",			popenimg,	"bmp -t9",
+	"image/gif",			popenimg,	"gif",
+	"image/jpeg",			popenimg,	"jpg",
+	"image/png",			popenimg,	"png",
+	"image/ppm",			popenimg,	"ppm",
+	"image/bmp",			popenimg,	"bmp",
 	"image/p9bit",			popenimg,	nil,
 	};
 
@@ -677,6 +683,7 @@
 
 	fd = p->fd;
 	p->fd = -1;
+	p->ext = nil;
 	file = p->data;
 	p->data = nil;
 	if(fd < 0){
@@ -1187,6 +1194,49 @@
 }
 
 void
+showext(Page *p)
+{
+	char buf[128], label[64], *argv[4];
+	Point ps;
+	int fd;
+
+	if(p->ext == nil)
+		return;
+	snprint(label, sizeof(label), "%s %s", p->ext, p->label);
+	if(p->image){
+		ps = subpt(p->image->r.max, p->image->r.min);
+		ps.x += 24;
+		ps.y += 24;
+	} else
+		ps = subpt(screen->r.max, screen->r.min);
+	if((fd = p->fd) < 0){
+		if(p->open != popenfile)
+			return;
+		fd = open((char*)p->data, OREAD);
+	} else {
+		fd = dup(fd, -1);
+		seek(fd, 0, 0);
+	}
+	if(rfork(RFPROC|RFMEM|RFFDG|RFNOTEG|RFNAMEG|RFNOWAIT) == 0){
+		snprint(buf, sizeof(buf), "-pid %d -dx %d -dy %d", getpid(), ps.x, ps.y);
+		if(newwindow(buf) != -1){
+			dupfds(fd, 1, 2, -1);
+			if((fd = open("/dev/label", OWRITE)) >= 0){
+				write(fd, label, strlen(label));
+				close(fd);
+			}
+			argv[0] = "rc";
+			argv[1] = "-c";
+			argv[2] = p->ext;
+			argv[3] = nil;
+			exec("/bin/rc", argv);
+		}
+		exits(0);
+	}
+	close(fd);
+}
+
+void
 eresized(int new)
 {
 	Page *p;
@@ -1305,6 +1355,12 @@
 				}
 			}
 		}
+		qunlock(current);
+		return 1;
+	case Cext:
+		if(current == nil || !canqlock(current))
+			return 1;
+		showext(current);
 		qunlock(current);
 		return 1;
 	case Cnext: