]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/libdraw/readimage.c
snes: fix input botch
[plan9front.git] / sys / src / libdraw / readimage.c
index 3c80b49828ac63a8a156347d5f0e24ae81d05182..66fac96560224616414b6125a6c3a019ba1898fd 100644 (file)
@@ -19,11 +19,15 @@ readimage(Display *d, int fd, int dolock)
 
        if(readn(fd, hdr, 11) != 11)
                return nil;
-       if(memcmp(hdr, "compressed\n", 11) == 0)
-               return creadimage(d, fd, dolock);
+       if(memcmp(hdr, "compressed\n", 11) == 0){
+               if(i = creadimage(d, fd, dolock))
+                       goto Done;
+               return nil;
+       }
+               
        if(readn(fd, hdr+11, 5*12-11) != 5*12-11)
                return nil;
-       if(d)
+       if(d != nil)
                chunk = d->bufsize - 32;        /* a little room for header */
        else
                chunk = 8192;
@@ -74,7 +78,7 @@ readimage(Display *d, int fd, int dolock)
        l = bytesperline(r, chantodepth(chan));
        if(l > chunk)
                chunk = l;
-       if(d){
+       if(d != nil){
                if(dolock)
                        lockdisplay(d);
                i = allocimage(d, r, chan, 0, -1);
@@ -112,7 +116,7 @@ readimage(Display *d, int fd, int dolock)
                        for(j=0; j<chunk; j++)
                                tmp[j] ^= 0xFF;
 
-               if(d){
+               if(d != nil){
                        if(dolock)
                                lockdisplay(d);
                        if(loadimage(i, Rect(r.min.x, miny, r.max.x, miny+dy), tmp, chunk) <= 0)
@@ -123,5 +127,7 @@ readimage(Display *d, int fd, int dolock)
                miny += dy;
        }
        free(tmp);
+   Done:
+       setmalloctag(i, getcallerpc(&d));
        return i;
 }