summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraiju <devnull@localhost>2016-06-10 12:14:02 +0200
committeraiju <devnull@localhost>2016-06-10 12:14:02 +0200
commite73a9eb9e835d21bd44d2f0a26d144c49c504d07 (patch)
tree859fa45535d22a5fa496489a61a741377a3a8bc9
parenta00b6bdbfa72a1688a866edf5f825720c9874ada (diff)
downloadplan9front-e73a9eb9e835d21bd44d2f0a26d144c49c504d07.tar.xz
togif: -E flag to read animation from stdin
-rw-r--r--sys/man/1/jpg7
-rw-r--r--sys/src/cmd/jpg/togif.c37
2 files changed, 41 insertions, 3 deletions
diff --git a/sys/man/1/jpg b/sys/man/1/jpg
index 5b3b9da1a..6df712f99 100644
--- a/sys/man/1/jpg
+++ b/sys/man/1/jpg
@@ -105,6 +105,8 @@ jpg, gif, png, tif, ppm, bmp, v210, yuv, ico, tga, tojpg, togeordi, togif, toppm
.I msec
]
.I file ...
+|
+.B -E
]
.br
.B toppm
@@ -351,6 +353,11 @@ By default, the images are displayed as fast as they can be rendered.
This option specifies the time, in milliseconds, to pause while
displaying the next named
.IR file .
+.TP
+.B -E
+Specifying this option instead of a list of files will read the frames from a pipe on fd 0.
+Each frame is terminated with EOF.
+End of the animation is specified by an extra EOF.
.PP
.I Gif
translates files that contain a `transparency' index by attaching
diff --git a/sys/src/cmd/jpg/togif.c b/sys/src/cmd/jpg/togif.c
index 353368830..2a5e18627 100644
--- a/sys/src/cmd/jpg/togif.c
+++ b/sys/src/cmd/jpg/togif.c
@@ -9,7 +9,7 @@
void
usage(void)
{
- fprint(2, "usage: togif [-l loopcount] [-c 'comment'] [-d Δt (ms)] [-t transparency-index] [file ... [-d Δt] file ...]\n");
+ fprint(2, "usage: togif [-l loopcount] [-c 'comment'] [-d Δt (ms)] [-t transparency-index] [file ... [-d Δt] file ... | -E]\n");
exits("usage");
}
@@ -20,7 +20,7 @@ main(int argc, char *argv[])
{
Biobuf bout;
Memimage *i, *ni;
- int fd, j, dt, trans, loop;
+ int fd, j, dt, trans, loop, eof;
char buf[256];
char *err, *comment, *s;
@@ -28,6 +28,7 @@ main(int argc, char *argv[])
dt = -1;
trans = -1;
loop = UNSET;
+ eof = 0;
ARGBEGIN{
case 'l':
s = ARGF();
@@ -54,6 +55,9 @@ main(int argc, char *argv[])
if(trans > 255)
usage();
break;
+ case 'E':
+ eof++;
+ break;
default:
usage();
}ARGEND
@@ -65,7 +69,34 @@ main(int argc, char *argv[])
err = nil;
- if(argc == 0){
+ if(eof){
+ if(argc != 0) usage();
+ for(j = 0;;j++){
+ i = readmemimage(0);
+ if(i == nil) break;
+ ni = memonechan(i);
+ if(ni == nil)
+ sysfatal("converting image to RGBV: %r");
+ if(i != nil){
+ freememimage(i);
+ i = ni;
+ }
+ if(j == 0){
+ err = memstartgif(&bout, i, loop);
+ if(err != nil)
+ break;
+ }
+ if(comment)
+ err = memwritegif(&bout, i, comment, dt, trans);
+ else{
+ snprint(buf, sizeof buf, "Converted by Plan 9 from <stdin>");
+ err = memwritegif(&bout, i, buf, dt, trans);
+ }
+ if(err != nil) break;
+ freememimage(i);
+ comment = nil;
+ }
+ }else if(argc == 0){
i = readmemimage(0);
if(i == nil)
sysfatal("reading input: %r");