use of net.runelite.cache.io.InputStream in project runelite by runelite.
the class SpriteLoader method load.
public SpriteDefinition[] load(int id, byte[] b) {
InputStream is = new InputStream(b);
is.setOffset(is.getLength() - 2);
int spriteCount = is.readUnsignedShort();
SpriteDefinition[] sprites = new SpriteDefinition[spriteCount];
// 2 for size
// 5 for width, height, palette length
// + 8 bytes per sprite for offset x/y, width, and height
is.setOffset(is.getLength() - 7 - spriteCount * 8);
// max width and height
int width = is.readUnsignedShort();
int height = is.readUnsignedShort();
int paletteLength = is.readUnsignedByte() + 1;
for (int i = 0; i < spriteCount; ++i) {
sprites[i] = new SpriteDefinition();
sprites[i].setId(id);
sprites[i].setFrame(i);
sprites[i].setMaxWidth(width);
sprites[i].setMaxHeight(height);
}
for (int i = 0; i < spriteCount; ++i) {
sprites[i].setOffsetX(is.readUnsignedShort());
}
for (int i = 0; i < spriteCount; ++i) {
sprites[i].setOffsetY(is.readUnsignedShort());
}
for (int i = 0; i < spriteCount; ++i) {
sprites[i].setWidth(is.readUnsignedShort());
}
for (int i = 0; i < spriteCount; ++i) {
sprites[i].setHeight(is.readUnsignedShort());
}
// same as above + 3 bytes for each palette entry, except for the first one (which is transparent)
is.setOffset(is.getLength() - 7 - spriteCount * 8 - (paletteLength - 1) * 3);
int[] palette = new int[paletteLength];
for (int i = 1; i < paletteLength; ++i) {
palette[i] = is.read24BitInt();
if (palette[i] == 0) {
palette[i] = 1;
}
}
is.setOffset(0);
for (int i = 0; i < spriteCount; ++i) {
SpriteDefinition def = sprites[i];
int spriteWidth = def.getWidth();
int spriteHeight = def.getHeight();
int dimension = spriteWidth * spriteHeight;
byte[] pixelPaletteIndicies = new byte[dimension];
byte[] pixelAlphas = new byte[dimension];
def.pixelIdx = pixelPaletteIndicies;
def.palette = palette;
int flags = is.readUnsignedByte();
if ((flags & FLAG_VERTICAL) == 0) {
// read horizontally
for (int j = 0; j < dimension; ++j) {
pixelPaletteIndicies[j] = is.readByte();
}
} else {
// read vertically
for (int j = 0; j < spriteWidth; ++j) {
for (int k = 0; k < spriteHeight; ++k) {
pixelPaletteIndicies[spriteWidth * k + j] = is.readByte();
}
}
}
// read alphas
if ((flags & FLAG_ALPHA) != 0) {
if ((flags & FLAG_VERTICAL) == 0) {
// read horizontally
for (int j = 0; j < dimension; ++j) {
pixelAlphas[j] = is.readByte();
}
} else {
// read vertically
for (int j = 0; j < spriteWidth; ++j) {
for (int k = 0; k < spriteHeight; ++k) {
pixelAlphas[spriteWidth * k + j] = is.readByte();
}
}
}
} else {
// everything non-zero is opaque
for (int j = 0; j < dimension; ++j) {
int index = pixelPaletteIndicies[j];
if (index != 0)
pixelAlphas[j] = (byte) 0xFF;
}
}
int[] pixels = new int[dimension];
// build argb pixels from palette/alphas
for (int j = 0; j < dimension; ++j) {
int index = pixelPaletteIndicies[j] & 0xFF;
pixels[j] = palette[index] | (pixelAlphas[j] << 24);
}
def.setPixels(pixels);
}
return sprites;
}
use of net.runelite.cache.io.InputStream in project runelite by runelite.
the class TrackLoader method load.
public TrackDefinition load(byte[] b) {
TrackDefinition def = new TrackDefinition();
load(def, new InputStream(b));
return def;
}
use of net.runelite.cache.io.InputStream in project runelite by runelite.
the class InventoryLoader method load.
public InventoryDefinition load(int id, byte[] b) {
InventoryDefinition def = new InventoryDefinition();
def.id = id;
InputStream is = new InputStream(b);
while (true) {
int opcode = is.readUnsignedByte();
if (opcode == 0) {
break;
}
if (opcode == 2) {
def.size = is.readUnsignedShort();
}
}
return def;
}
use of net.runelite.cache.io.InputStream in project runelite by runelite.
the class ItemLoader method load.
public ItemDefinition load(int id, byte[] b) {
ItemDefinition def = new ItemDefinition(id);
InputStream is = new InputStream(b);
while (true) {
int opcode = is.readUnsignedByte();
if (opcode == 0) {
break;
}
this.decodeValues(opcode, def, is);
}
return def;
}
use of net.runelite.cache.io.InputStream in project runelite by runelite.
the class OverlayLoader method load.
public OverlayDefinition load(int id, byte[] b) {
OverlayDefinition def = new OverlayDefinition();
InputStream is = new InputStream(b);
def.setId(id);
for (; ; ) {
int opcode = is.readUnsignedByte();
if (opcode == 0) {
break;
}
if (opcode == 1) {
int color = is.read24BitInt();
def.setRgbColor(color);
} else if (opcode == 2) {
int texture = is.readUnsignedByte();
def.setTexture(texture);
} else if (opcode == 5) {
def.setHideUnderlay(false);
} else if (opcode == 7) {
int secondaryColor = is.read24BitInt();
def.setSecondaryRgbColor(secondaryColor);
}
}
def.calculateHsl();
return def;
}
Aggregations