ref: e73a9eb9e835d21bd44d2f0a26d144c49c504d07
parent: a00b6bdbfa72a1688a866edf5f825720c9874ada
author: aiju <devnull@localhost>
date: Fri Jun 10 08:14:02 EDT 2016
togif: -E flag to read animation from stdin
--- a/sys/man/1/jpg
+++ b/sys/man/1/jpg
@@ -105,6 +105,8 @@
.I msec
]
.I file ...
+|
+.B -E
]
.br
.B toppm
@@ -351,6 +353,11 @@
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
--- 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 @@
{
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 @@
dt = -1;
trans = -1;
loop = UNSET;
+ eof = 0;
ARGBEGIN{
case 'l':
s = ARGF();
@@ -54,6 +55,9 @@
if(trans > 255)
usage();
break;
+ case 'E':
+ eof++;
+ break;
default:
usage();
}ARGEND
@@ -65,7 +69,34 @@
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");