gif: just read and decode the first image when -9 or -c flag is specified

This commit is contained in:
cinap_lenrek 2016-10-22 00:35:17 +02:00
parent 6d97f77c2d
commit a8d00e5d56
3 changed files with 8 additions and 6 deletions

View file

@ -288,7 +288,7 @@ show(int fd, char *name)
char buf[32]; char buf[32];
err = nil; err = nil;
images = readgif(fd, CRGB); images = readgif(fd, CRGB, dflag);
if(images == nil){ if(images == nil){
fprint(2, "gif: decode %s failed: %r\n", name); fprint(2, "gif: decode %s failed: %r\n", name);
return "decode"; return "decode";

View file

@ -55,7 +55,7 @@ Rawimage** readpng(int, int);
Rawimage** Breadpng(Biobuf*, int); Rawimage** Breadpng(Biobuf*, int);
Rawimage** readtif(int, int); Rawimage** readtif(int, int);
Rawimage** Breadtif(Biobuf*, int); Rawimage** Breadtif(Biobuf*, int);
Rawimage** readgif(int, int); Rawimage** readgif(int, int, int);
Rawimage** readpixmap(int, int); Rawimage** readpixmap(int, int);
Rawimage* torgbv(Rawimage*, int); Rawimage* torgbv(Rawimage*, int);
Rawimage* totruecolor(Rawimage*, int); Rawimage* totruecolor(Rawimage*, int);

View file

@ -39,7 +39,7 @@ static char readerr[] = "ReadGIF: read error: %r";
static char extreaderr[] = "ReadGIF: can't read extension: %r"; static char extreaderr[] = "ReadGIF: can't read extension: %r";
static char memerr[] = "ReadGIF: malloc failed: %r"; static char memerr[] = "ReadGIF: malloc failed: %r";
static Rawimage** readarray(Header*); static Rawimage** readarray(Header*, int);
static Rawimage* readone(Header*); static Rawimage* readone(Header*);
static void readheader(Header*); static void readheader(Header*);
static void skipextension(Header*); static void skipextension(Header*);
@ -100,7 +100,7 @@ giferror(Header *h, char *fmt, ...)
Rawimage** Rawimage**
readgif(int fd, int colorspace) readgif(int fd, int colorspace, int justone)
{ {
Rawimage **a; Rawimage **a;
Biobuf b; Biobuf b;
@ -122,7 +122,7 @@ readgif(int fd, int colorspace)
if(setjmp(h->errlab)) if(setjmp(h->errlab))
a = nil; a = nil;
else else
a = readarray(h); a = readarray(h, justone);
giffreeall(h, 0); giffreeall(h, 0);
free(h); free(h);
return a; return a;
@ -144,7 +144,7 @@ inittbl(Header *h)
static static
Rawimage** Rawimage**
readarray(Header *h) readarray(Header *h, int justone)
{ {
Entry *tbl; Entry *tbl;
Rawimage *new, **array; Rawimage *new, **array;
@ -202,6 +202,8 @@ readarray(Header *h)
array[nimages] = nil; array[nimages] = nil;
h->array = array; h->array = array;
h->new = nil; h->new = nil;
if(justone)
goto Return;
break; break;
case 0x3B: /* Trailer */ case 0x3B: /* Trailer */