while ((nextCommand = in.readBits(chunk)) != EOD)
while ((nextCommand = in.readBits(chunk)) != EOD)
while ((nextCommand = in.readBits(chunk)) != EOD)
private byte[] getNextChunk() throws IOException { if (leftoverData != null) { byte[] res = Arrays.copyOf(leftoverData, leftoverData.length); this.leftoverData = null; return res; } try { thisWord = this.bitStream.readBits(codeLengthBits); if (thisWord == CLEAR_TABLE_MARKER) { this.codeLengthBits = 9; initLZWTable(); this.previousWord = -1; return getNextChunk(); } else if (thisWord == EOD) { return null; } else { byte[] res = getChunkFromLZWTable(); this.codeLengthBits = calculateCodeLength(); previousWord = thisWord; return res; } } catch (EOFException e) { LOGGER.log(Level.FINE, "Unexpected end of LZW data."); return null; } }
/** * Decodes a one bit image to a 4-bit image, well, converts * * @param data data buffer, contains the compressed data, and target for the * decompressed data * @param entry the font entry * @throws IOException */ private void decodeOneBit(byte[] data, final Bf4Entry entry) throws IOException { byte[] values = new byte[data.length]; System.arraycopy(data, 0, values, 0, data.length); MemoryCacheImageInputStream iis = new MemoryCacheImageInputStream(new ByteArrayInputStream(values)); iis.setByteOrder(ByteOrder.LITTLE_ENDIAN); FourBitWriter writer = new FourBitWriter(data); for (int y = 0; y < entry.getHeight(); y++) { for (int x = 0; x < entry.getWidth(); x++) { int bit = (int) iis.readBits(1); if (bit == 1) { writer.write(255); } else { writer.write(0); } } } }
for (int y = 0; y < entry.getHeight(); y++) { for (int x = 0; x < entry.getWidth(); x++) { writer.write((int) iis.readBits(4));