mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-06 00:08:19 +07:00
Begin work on transitioning DCC to use new io API
This commit is contained in:
@ -1,14 +1,5 @@
|
|||||||
package com.riiablo.codec;
|
package com.riiablo.codec;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
@ -17,12 +8,26 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|||||||
import com.badlogic.gdx.graphics.glutils.PixmapTextureData;
|
import com.badlogic.gdx.graphics.glutils.PixmapTextureData;
|
||||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
import com.badlogic.gdx.utils.StreamUtils;
|
import com.badlogic.gdx.utils.StreamUtils;
|
||||||
|
|
||||||
import com.riiablo.codec.util.BBox;
|
import com.riiablo.codec.util.BBox;
|
||||||
import com.riiablo.codec.util.BitStream;
|
import com.riiablo.codec.util.BitStream;
|
||||||
import com.riiablo.graphics.PaletteIndexedPixmap;
|
import com.riiablo.graphics.PaletteIndexedPixmap;
|
||||||
|
import com.riiablo.io.BitUtils;
|
||||||
|
import com.riiablo.io.ByteInput;
|
||||||
import com.riiablo.util.BufferUtils;
|
import com.riiablo.util.BufferUtils;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
public class DCC extends com.riiablo.codec.DC {
|
public class DCC extends com.riiablo.codec.DC {
|
||||||
private static final String TAG = "DCC";
|
private static final String TAG = "DCC";
|
||||||
private static final boolean DEBUG = !true;
|
private static final boolean DEBUG = !true;
|
||||||
@ -288,6 +293,46 @@ public class DCC extends com.riiablo.codec.DC {
|
|||||||
return new Animation.Layer(this, blendMode);
|
return new Animation.Layer(this, blendMode);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
public static DCC loadFromArray(byte[] bytes) {
|
||||||
|
return loadFromBuffer(Unpooled.wrappedBuffer(bytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DCC loadFromBuffer(ByteBuf buffer) {
|
||||||
|
ByteInput in = ByteInput.wrap(buffer);
|
||||||
|
final int fileSize = in.bytesRemaining();
|
||||||
|
|
||||||
|
Header header = Header.obtain(in);
|
||||||
|
if (DEBUG) Gdx.app.debug(TAG, header.toString());
|
||||||
|
|
||||||
|
final int numDirections = header.directions;
|
||||||
|
final int numFrames = header.framesPerDir;
|
||||||
|
|
||||||
|
int[] dirOffsets = new int[numDirections + 1];
|
||||||
|
BitUtils.readSafe32u(in, dirOffsets, 0, numDirections);
|
||||||
|
dirOffsets[numDirections] = fileSize;
|
||||||
|
if (DEBUG) Gdx.app.debug(TAG, "direction offsets = " + Arrays.toString(dirOffsets));
|
||||||
|
|
||||||
|
BBox box = new BBox();
|
||||||
|
box.xMin = box.yMin = Integer.MAX_VALUE;
|
||||||
|
box.xMax = box.yMax = Integer.MIN_VALUE;
|
||||||
|
|
||||||
|
Direction[] directions = new Direction[numDirections];
|
||||||
|
Frame[][] frames = new Frame[numDirections][numFrames];
|
||||||
|
int start = dirOffsets[0], end;
|
||||||
|
for (int d = 0; d < numDirections; d++) {
|
||||||
|
end = dirOffsets[d + 1];
|
||||||
|
// final Direction dir = directions[d] = Direction.obtain(in, end - start, frames[d]);
|
||||||
|
|
||||||
|
// assert dir.equalCellBitStream.bitsRemaining() == 0;
|
||||||
|
// assert dir.pixelMaskBitStream.bitsRemaining() == 0;
|
||||||
|
// assert dir.encodingTypeBitStream.bitsRemaining() == 0;
|
||||||
|
// assert dir.rawPixelCodesBitStream.bitsRemaining() == 0;
|
||||||
|
// assert dir.pixelCodeAndDisplacementBitStream.bytesRemaining() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
public static DCC loadFromFile(FileHandle handle) {
|
public static DCC loadFromFile(FileHandle handle) {
|
||||||
return loadFromStream(handle.read());
|
return loadFromStream(handle.read());
|
||||||
}
|
}
|
||||||
@ -693,6 +738,10 @@ public class DCC extends com.riiablo.codec.DC {
|
|||||||
return new Header().read(in);
|
return new Header().read(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Header obtain(ByteInput in) {
|
||||||
|
return new Header().read(in);
|
||||||
|
}
|
||||||
|
|
||||||
Header read(InputStream in) throws IOException {
|
Header read(InputStream in) throws IOException {
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(IOUtils.readFully(in, SIZE)).order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuffer buffer = ByteBuffer.wrap(IOUtils.readFully(in, SIZE)).order(ByteOrder.LITTLE_ENDIAN);
|
||||||
signature = BufferUtils.readUnsignedByte(buffer);
|
signature = BufferUtils.readUnsignedByte(buffer);
|
||||||
@ -705,6 +754,18 @@ public class DCC extends com.riiablo.codec.DC {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Header read(ByteInput in) {
|
||||||
|
in = in.readSlice(SIZE);
|
||||||
|
signature = in.read8();
|
||||||
|
version = in.readSafe8u();
|
||||||
|
directions = in.readSafe8u();
|
||||||
|
framesPerDir = in.readSafe32u();
|
||||||
|
tag = in.readSafe32u();
|
||||||
|
finalDC6Size = in.readSafe32u();
|
||||||
|
assert in.bytesRemaining() == 0 : "in.bytesRemaining(" + in.bytesRemaining() + ") > " + 0;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this)
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package com.riiablo.io;
|
package com.riiablo.io;
|
||||||
|
|
||||||
|
import com.riiablo.util.DebugUtils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.riiablo.util.DebugUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps a {@link ByteBuf} to support reading sequences of bytes and supporting
|
* Wraps a {@link ByteBuf} to support reading sequences of bytes and supporting
|
||||||
@ -230,6 +232,13 @@ public class ByteInput {
|
|||||||
return new ByteInput(slice, mark);
|
return new ByteInput(slice, mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteInput readUnalignedSlice(long numBytes) {
|
||||||
|
if (aligned()) return readSlice(numBytes);
|
||||||
|
assert numBytes <= Integer.MAX_VALUE : "ByteBuf only supports int length";
|
||||||
|
final ByteBuf slice = buffer.slice(mark, (int) numBytes);
|
||||||
|
throw null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a byte array containing a duplicated region of the byte stream.
|
* Returns a byte array containing a duplicated region of the byte stream.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user