public final void readFully(final byte b[], final int off, final int len) throws IOException { // this may look over-complicated, but the problem is that the InputStream.read() methods are // not guaranteed to fill up the buffer you pass to it. So we need to loop until we have filled // up the buffer or until we reach the end of the file. final int bytesRead = _stream.read(b, off, len); if (bytesRead == -1) { throw new EOFException("EOF reached"); } if (bytesRead < len) { // we didn't get all the data we wanted, so read some more readFully(b, off + bytesRead, len - bytesRead); } }
static DdsPixelFormat read(final LittleEndianDataInput in) throws IOException { final DdsPixelFormat format = new DdsPixelFormat(); format.dwSize = in.readInt(); if (format.dwSize != 32) { throw new Error("invalid pixel format size: " + format.dwSize); } format.dwFlags = in.readInt(); format.dwFourCC = in.readInt(); format.dwRGBBitCount = in.readInt(); format.dwRBitMask = in.readInt(); format.dwGBitMask = in.readInt(); format.dwBBitMask = in.readInt(); format.dwABitMask = in.readInt(); return format; } }
public final double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
public Image load(final InputStream is, final boolean flipVertically) throws IOException { final LittleEndianDataInput in = new LittleEndianDataInput(is); // Read and check magic word... final int dwMagic = in.readInt(); if (dwMagic != getInt("DDS ")) { throw new Error("Not a dds file."); } logger.finest("Reading DDS file."); // Create our data store; final DdsImageInfo info = new DdsImageInfo(); info.flipVertically = flipVertically; // Read standard dds header info.header = DdsHeader.read(in); // if applicable, read DX10 header info.headerDX10 = info.header.ddpf.dwFourCC == getInt("DX10") ? DdsHeaderDX10.read(in) : null; // Create our new image final Image image = new Image(); image.setWidth(info.header.dwWidth); image.setHeight(info.header.dwHeight); // update depth based on flags / header updateDepth(image, info); // add our format and image data. populateImage(image, info, in); // return the loaded image return image; }
DataInput di = dis; if (isLittleEndian) { di = new LittleEndianDataInput(dis);
public final short readShort() throws IOException { return (short) readUnsignedShort(); }
public Image load(final InputStream is, final boolean flipVertically) throws IOException { final LittleEndianDataInput in = new LittleEndianDataInput(is); // Read and check magic word... final int dwMagic = in.readInt(); if (dwMagic != getInt("DDS ")) { throw new Error("Not a dds file."); } logger.finest("Reading DDS file."); // Create our data store; final DdsImageInfo info = new DdsImageInfo(); info.flipVertically = flipVertically; // Read standard dds header info.header = DdsHeader.read(in); // if applicable, read DX10 header info.headerDX10 = info.header.ddpf.dwFourCC == getInt("DX10") ? DdsHeaderDX10.read(in) : null; // Create our new image final Image image = new Image(); image.setWidth(info.header.dwWidth); image.setHeight(info.header.dwHeight); // update depth based on flags / header updateDepth(image, info); // add our format and image data. populateImage(image, info, in); // return the loaded image return image; }
DataInput di = dis; if (isLittleEndian) { di = new LittleEndianDataInput(dis);
public final char readChar() throws IOException { return (char) readUnsignedShort(); }
public final void readFully(final byte b[], final int off, final int len) throws IOException { // this may look over-complicated, but the problem is that the InputStream.read() methods are // not guaranteed to fill up the buffer you pass to it. So we need to loop until we have filled // up the buffer or until we reach the end of the file. final int bytesRead = _stream.read(b, off, len); if (bytesRead == -1) { throw new EOFException("EOF reached"); } if (bytesRead < len) { // we didn't get all the data we wanted, so read some more readFully(b, off + bytesRead, len - bytesRead); } }
@Before public void setup() throws Exception { in = new MockInputStream(); array = new byte[10]; littleEndien = new LittleEndianDataInput(in); }
static DdsPixelFormat read(final LittleEndianDataInput in) throws IOException { final DdsPixelFormat format = new DdsPixelFormat(); format.dwSize = in.readInt(); if (format.dwSize != 32) { throw new Error("invalid pixel format size: " + format.dwSize); } format.dwFlags = in.readInt(); format.dwFourCC = in.readInt(); format.dwRGBBitCount = in.readInt(); format.dwRBitMask = in.readInt(); format.dwGBitMask = in.readInt(); format.dwBBitMask = in.readInt(); format.dwABitMask = in.readInt(); return format; } }
public final short readShort() throws IOException { return (short) readUnsignedShort(); }
public final double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
static final ByteBuffer readDXT(final LittleEndianDataInput in, final int totalSize, final DdsImageInfo info, final Image image) throws IOException { int mipWidth = info.header.dwWidth; int mipHeight = info.header.dwHeight; final ByteBuffer buffer = BufferUtils.createByteBuffer(totalSize); for (int mip = 0; mip < info.header.dwMipMapCount; mip++) { final byte[] data = new byte[info.mipmapByteSizes[mip]]; in.readFully(data); if (!info.flipVertically) { buffer.put(data); } else { final byte[] flipped = flipDXT(data, mipWidth, mipHeight, image.getDataFormat()); buffer.put(flipped); mipWidth = Math.max(mipWidth / 2, 1); mipHeight = Math.max(mipHeight / 2, 1); } } buffer.rewind(); return buffer; }
public final float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
public final char readChar() throws IOException { return (char) readUnsignedShort(); }
static final ByteBuffer readDXT(final LittleEndianDataInput in, final int totalSize, final DdsImageInfo info, final Image image) throws IOException { int mipWidth = info.header.dwWidth; int mipHeight = info.header.dwHeight; final ByteBuffer buffer = BufferUtils.createByteBuffer(totalSize); for (int mip = 0; mip < info.header.dwMipMapCount; mip++) { final byte[] data = new byte[info.mipmapByteSizes[mip]]; in.readFully(data); if (!info.flipVertically) { buffer.put(data); } else { final byte[] flipped = flipDXT(data, mipWidth, mipHeight, image.getDataFormat()); buffer.put(flipped); mipWidth = Math.max(mipWidth / 2, 1); mipHeight = Math.max(mipHeight / 2, 1); } } buffer.rewind(); return buffer; }
public final float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
public void run() { try { littleEndien.readFully(array); } catch (IOException e) { e.printStackTrace(); fail("ioexception"); } } });