/** * constructs a frequency table from an array of bytes * * @param source the array to construct the table from */ public static int[] constructTable(byte[] source) { int[] ret = new int[TABLESIZE]; for (int i = 0; i < source.length; i++) { ret[IntTool.ByteToInt(source[i])]++; } return ret; }
/** * Expand a rll-compressed array * * @param source the compressed array. First byte must be the rllchar. * @return a newly created array with the expanded data. */ public static byte[] expand(byte[] source) { ByteArrayOutputStream baos = new ByteArrayOutputStream(source.length); byte rllchar = source[0]; int i; for (i = 1; i < source.length - 2; i++) { if (source[i] == rllchar) { if (source[i + 1] == 1) { baos.write(rllchar); i++; } else { int k = IntTool.ByteToInt(source[i + 1]); while (k-- > 0) { baos.write(source[i + 2]); } i += 2; } } else { baos.write(source[i]); } } while (i < source.length) { baos.write(source[i++]); } return baos.toByteArray(); }