private byte[] decodeRLE8(int imSize, int padding, byte values[]) {

	byte val[] = new byte[width * height];
	int count = 0, l = 0;
	int value;
	boolean flag = false;

	while (count != imSize) {

	    value = values[count++] & 0xff;

	    if (value == 0) {
		switch(values[count++] & 0xff) {

		case 0:
		    // End-of-scanline marker
		    break;

		case 1:
		    // End-of-RLE marker
		    flag = true;
		    break;

		case 2:
		    // delta or vector marker
		    int xoff = values[count++] & 0xff;
		    int yoff = values[count] & 0xff;
		    // Move to the position xoff, yoff down
		    l += xoff + yoff*width;
		    break;

		default:
		    int end = values[count-1] & 0xff;
		    for (int i=0; i<end; i++) {
			val[l++] = (byte)(values[count++] & 0xff);
		    }

		    // Whenever end pixels can fit into odd number of bytes,
		    // an extra padding byte will be present, so skip that.
		    if (!isEven(end)) {
			count++;
		    }
		}
	    } else {
		for (int i=0; i<value; i++) {
		    val[l++] = (byte)(values[count] & 0xff);
		}
		count++;
	    }

	    // If End-of-RLE data, then exit the while loop
	    if (flag) {
		break;
	    }
	}

	return val;
    }