@Override public void reopenFile() throws IOException { if (in != null) { in.close(); } in = new RandomAccessInputStream(spcId); in.order(true); }
@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 4; if (!FormatTools.validStream(stream, blockLen, false)) return false; stream.order(true); int checkLittleEndian = stream.readInt(); stream.seek(stream.getFilePointer() - 4); stream.order(false); int checkBigEndian = stream.readInt(); return checkLittleEndian == MAGIC || checkBigEndian == MAGIC; }
private byte[] readPixelBlock(RandomAccessInputStream s, long offset) throws IOException { s.order(true); s.seek(offset); int checkLength = s.readInt(); int check = s.readInt(); if (check != 3) { s.seek(offset); return null; } s.skipBytes(8); // currently unknown int uidLength = s.readInt(); String uid = s.readString(uidLength); LOGGER.debug("reading pixel block with uid = {}", uid); if (checkLength != uidLength + 12) { s.seek(offset); return null; } int pixelBytes = s.readInt(); s.skipBytes(4); // currently unknown byte[] pixels = new byte[pixelBytes]; s.readFully(pixels); return pixels; }
private RandomAccessInputStream getCZTag(IFD ifd) throws FormatException, IOException { // get TIF_CZ_LSMINFO structure short[] s = ifd.getIFDShortArray(ZEISS_ID); if (s == null) { LOGGER.warn("Invalid Zeiss LSM file. Tag {} not found.", ZEISS_ID); TiffReader reader = new TiffReader(); reader.setId(getLSMFileFromSeries(getSeries())); core.set(getSeries(), reader.getCoreMetadataList().get(0)); reader.close(); return null; } byte[] cz = new byte[s.length]; for (int i=0; i<s.length; i++) { cz[i] = (byte) s[i]; } RandomAccessInputStream ras = new RandomAccessInputStream(cz); ras.order(isLittleEndian()); return ras; }
long fp = in.getFilePointer(); boolean littleEndian = in.isLittleEndian(); in.order(false); long pointer = in.getFilePointer(); if (length > 0xff00 || code < 0xff00) { in.seek(pointer - 3); continue; in.skipBytes(1); int height = in.readShort() & 0xffff; int width = in.readShort() & 0xffff; in.seek(pointer + length - 2); in.seek(fp); in.order(littleEndian);
/** * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ @Override public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); long planeSize = (long) FormatTools.getPlaneSize(this); int index = getCoreIndex(); RandomAccessInputStream dat = new RandomAccessInputStream(datFile); try { dat.order(isLittleEndian()); dat.seek(dataPointers.get(index) + no * planeSize); readPlane(dat, x, y, w, h, buf); } finally { dat.close(); } return buf; }
@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 12; if (!FormatTools.validStream(stream, blockLen, false)) return false; String s = stream.readString(4); boolean little = s.equals("iiii"); boolean big = s.equals("mmmm"); if (!big && !little) return false; stream.order(little); int size = stream.readInt(); if (size != 4) return false; // first block size should be 4 int version = stream.readInt(); return version >= 0x100e; }
private byte[] readPixelBlock(RandomAccessInputStream s, long offset) throws IOException { s.order(true); s.seek(offset); int checkLength = s.readInt(); int check = s.readInt(); if (check != 3) { s.seek(offset); return null; } s.skipBytes(8); // currently unknown int uidLength = s.readInt(); String uid = s.readString(uidLength); LOGGER.debug("reading pixel block with uid = {}", uid); if (checkLength != uidLength + 12) { s.seek(offset); return null; } int pixelBytes = s.readInt(); s.skipBytes(4); // currently unknown byte[] pixels = new byte[pixelBytes]; s.readFully(pixels); return pixels; }
private RandomAccessInputStream getCZTag(IFD ifd) throws FormatException, IOException { // get TIF_CZ_LSMINFO structure short[] s = ifd.getIFDShortArray(ZEISS_ID); if (s == null) { LOGGER.warn("Invalid Zeiss LSM file. Tag {} not found.", ZEISS_ID); TiffReader reader = new TiffReader(); reader.setId(getLSMFileFromSeries(getSeries())); core.set(getSeries(), reader.getCoreMetadataList().get(0)); reader.close(); return null; } byte[] cz = new byte[s.length]; for (int i=0; i<s.length; i++) { cz[i] = (byte) s[i]; } RandomAccessInputStream ras = new RandomAccessInputStream(cz); ras.order(isLittleEndian()); return ras; }
@Override public void reopenFile() throws IOException { if (in != null) { in.close(); } in = new RandomAccessInputStream(spcId); in.order(true); }
@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 4; if (!FormatTools.validStream(stream, blockLen, false)) return false; stream.order(true); int checkLittleEndian = stream.readInt(); stream.seek(stream.getFilePointer() - 4); stream.order(false); int checkBigEndian = stream.readInt(); return checkLittleEndian == MAGIC || checkBigEndian == MAGIC; }
/** * @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */ @Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 104; if (!FormatTools.validStream(stream, blockLen, true)) return false; int size = (int) stream.readFloat() * 4; if (size == 0) { stream.seek(0); stream.order(false); size = (int) stream.readFloat() * 4; } stream.skipBytes(4); size *= (int) stream.readFloat(); stream.seek(44); int nsam = (int) stream.readFloat(); size *= nsam; int headerSize = nsam * (int) stream.readFloat() * 4; stream.skipBytes(48); int slices = (int) stream.readFloat(); if (slices > 0) { size *= slices; } return size + headerSize == stream.length() || size == stream.length(); }
/** * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ @Override public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); long planeSize = (long) FormatTools.getPlaneSize(this); int index = getCoreIndex(); RandomAccessInputStream dat = new RandomAccessInputStream(datFile); try { dat.order(isLittleEndian()); dat.seek(dataPointers.get(index) + no * planeSize); readPlane(dat, x, y, w, h, buf); } finally { dat.close(); } return buf; }
@Override public boolean isThisType(RandomAccessInputStream stream) throws IOException { final int blockLen = 12; if (!FormatTools.validStream(stream, blockLen, false)) return false; String s = stream.readString(4); boolean little = s.equals("iiii"); boolean big = s.equals("mmmm"); if (!big && !little) return false; stream.order(little); int size = stream.readInt(); if (size != 4) return false; // first block size should be 4 int version = stream.readInt(); return version >= 0x100e; }
private int getExtraSeries(String file) throws FormatException, IOException { if (in != null) in.close(); in = new RandomAccessInputStream(file, 16); boolean littleEndian = in.read() == TiffConstants.LITTLE; in.order(littleEndian); tiffParser = new TiffParser(in); IFD ifd = tiffParser.getFirstIFD(); RandomAccessInputStream ras = getCZTag(ifd); if (ras == null) return 1; ras.order(littleEndian); ras.seek(264); dimensionP = ras.readInt(); dimensionM = ras.readInt(); ras.close(); int nSeries = dimensionM * dimensionP; return nSeries <= 0 ? 1 : nSeries; }
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); m.littleEndian = false; in.order(isLittleEndian()); m.sizeX = in.readShort(); m.sizeY = in.readShort(); m.sizeZ = in.readShort(); long fileLength = in.length() - HEADER_SIZE; int nBytes = (int) (fileLength / (getSizeX() * getSizeY() * getSizeZ())); m.pixelType = FormatTools.pixelTypeFromBytes(nBytes, false, false); m.sizeC = 1; m.sizeT = 1; m.rgb = false; m.dimensionOrder = "XYZCT"; m.imageCount = getSizeZ() * getSizeC() * getSizeT(); MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); }
private RandomAccessInputStream getStream(int row) throws IOException { Object o = sampleTable[row][14]; String fileLink = o == null ? "0" : o.toString().trim(); RandomAccessInputStream data = null; if (fileLink.equals("0")) { data = new RandomAccessInputStream((byte[]) sampleTable[row][13]); } else { fileLink = new Location(dir, fileLink + ".dat").getAbsolutePath(); data = new RandomAccessInputStream(fileLink); } data.order(true); return data; }
private int getFileVersion(RandomAccessInputStream stream) throws IOException { stream.seek(0); stream.order(LITTLE_ENDIAN); try { final String magicString = stream.readString(FILE_MAGIC_STRING.length()); final short magicNumber = stream.readShort(); final int version = stream.readInt(); if (magicString.equals(FILE_MAGIC_STRING) && magicNumber == MAGIC_NUMBER) { return version; } } catch(IOException exception) { } return - 1; }