void readZrlePackedRLEPixels(int tw, int th, int[] palette)
			throws Exception {

		int ptr = 0;
		int end = ptr + tw * th;
		while (ptr < end) {
			int index = zrleInStream.readU8();
			int len = 1;
			if ((index & 128) != 0) {
				int b;
				do {
					b = zrleInStream.readU8();
					len += b;
				} while (b == 255);

				if (!(len <= end - ptr))
					throw new Exception("ZRLE decoder: assertion failed"
							+ " (len <= end - ptr)");
			}

			index &= 127;
			int pix = palette[index];

			if (bytesPixel == 1) {
				while (len-- > 0)
					zrleTilePixels8[ptr++] = (byte) pix;
			} else {
				while (len-- > 0)
					zrleTilePixels24[ptr++] = pix;
			}
		}
	}