+/* decode RLE */
+static int decode_rle(unsigned char *in, int len, int width, int height)
+{
+ int n = width * height;
+ unsigned char *out, v, l;
+ int i, j = 0;
+
+ /* no RLE magic */
+ if (n < 4 || !!strncmp((char *)in, "RLE!", 4))
+ return 0;
+
+ i = 4;
+ if (len-i < 1)
+ return -EINVAL;
+
+ out = (unsigned char *)malloc(n);
+ if (!out)
+ return -ENOMEM;
+
+ while ((l = in[i++])) {
+ if (len-i < 1) {
+ /* short read */
+ free(out);
+ return -EIO;
+ }
+ v = in[i++];
+ memset(out+j, v, l);
+ j += l;
+ }
+
+ memcpy(in, out, n);
+ free(out);
+ return 0;
+}
+