shithub: riscv

Download patch

ref: a44a1dbd19c2a9b05b497e32853e57ca88495397
parent: a6f7507661ad7decb3a0a62994bea2ba276ff81d
author: cinap_lenrek <[email protected]>
date: Wed Mar 11 08:59:19 EDT 2015

gif: fix color table clipping (for cb5.gif)

--- a/sys/src/cmd/jpg/readgif.c
+++ b/sys/src/cmd/jpg/readgif.c
@@ -376,7 +376,7 @@
 uchar*
 decode(Header *h, Rawimage *i, Entry *tbl)
 {
-	int c, doclip, incode, codesize, CTM, EOD, pici, datai, stacki, nbits, sreg, fc, code, piclen;
+	int c, incode, codesize, CTM, EOD, pici, datai, stacki, nbits, sreg, fc, code, piclen;
 	int csize, nentry, maxentry, first, ocode, ndata, nb;
 	uchar clip, *p, *pic;
 	uchar stack[4096], data[256];
@@ -386,10 +386,6 @@
 	codesize = h->buf[0];
 	if(codesize>8 || 0>codesize)
 		giferror(h, "ReadGIF: can't handle codesize %d", codesize);
-	doclip = 0;
-	if(i->cmap!=nil && i->cmaplen!=3*(1<<codesize)
-	  && (codesize!=2 || i->cmaplen!=3*2))			/* peculiar GIF bitmap files... */
-		doclip = 1;
 
 	CTM =1<<codesize;
 	EOD = CTM+1;
@@ -490,10 +486,10 @@
 	}
 
 Return:
-	if(doclip){
-		clip = i->cmaplen/3;
+	if(i->cmap!=nil && i->cmaplen!=3*256){
+		clip = (i->cmaplen/3)-1;
 		for(p = pic; p < pic+piclen; p++)
-			if(*p >= clip)
+			if(*p > clip)
 				*p = clip;
 	}
 	h->pic = nil;