private String readString() throws IOException { final int length = in.readInt(); if (length > 0) { return in.readString(length); } else { return ""; } }
/** Read the header for an image stack. */ private void readStackHeader() throws IOException { int count = in.readInt(); if (count > 0xffff) { in.seek(in.getFilePointer() - 2); int len = in.readShort(); in.skipBytes(len); count = in.readInt() + 1; } skipTags(count); skipTagBlock(); }
private void parseImageTag(int seriesIndex) throws IOException { CoreMetadata ms = core.get(seriesIndex); ms.imageCount = in.readInt(); ms.sizeX = in.readInt(); ms.sizeY = in.readInt(); addSeriesMeta("Number of images", getImageCount()); addSeriesMeta("Image width", getSizeX()); addSeriesMeta("Image height", getSizeY()); addSeriesMeta("Bits per Sample", in.readInt()); addSeriesMeta("Samples per pixel", in.readInt()); String name = getString(fileLength * 2); if (name.indexOf('.') != -1) { name = name.substring(0, name.lastIndexOf(".")); } String[] tokens = name.split("_"); final StringBuilder buf = new StringBuilder(); for (int p=1; p<tokens.length; p++) { String lcase = tokens[p].toLowerCase(); if (!lcase.startsWith("ch0") && !lcase.startsWith("c0") && !lcase.startsWith("z0") && !lcase.startsWith("t0") && !lcase.startsWith("y0") && !lcase.startsWith("la0")) { if (buf.length() > 0) buf.append("_"); buf.append(tokens[p]); } } seriesNames.add(buf.toString()); }
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); m.littleEndian = true; in.order(isLittleEndian()); in.seek(44); m.sizeX = in.readInt(); m.sizeY = in.readInt(); m.pixelType = FormatTools.UINT32; m.sizeZ = 1; m.sizeC = 1; m.sizeT = 1; m.imageCount = 1; m.dimensionOrder = "XYZCT"; padding = (int) ((in.length() - FormatTools.getPlaneSize(this)) / (getSizeY() * 4)); addGlobalMeta("Padding bytes", padding); MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); }
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); in.seek(348); m.sizeX = in.readInt(); m.sizeY = in.readInt(); in.skipBytes(4); int bpp = in.readInt(); addGlobalMeta("Bytes per pixel", bpp); m.pixelType = FormatTools.pixelTypeFromBytes(bpp, false, bpp == 4); m.littleEndian = false; m.sizeZ = 1; m.sizeC = 1; m.sizeT = 1; m.imageCount = 1; m.rgb = false; m.interleaved = false; m.dimensionOrder = "XYZCT"; MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); }
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); m.littleEndian = false; findString(DIMENSIONS_STRING); in.skipBytes(DIMENSIONS_STRING.length() + 20); m.sizeX = in.readInt(); m.sizeY = in.readInt(); findString(PIXELS_STRING); pixelOffset = in.getFilePointer() + PIXELS_STRING.length() + 20; m.sizeZ = 1; m.sizeC = 1; m.sizeT = 1; m.imageCount = 1; m.dimensionOrder = "XYCZT"; m.pixelType = FormatTools.FLOAT; MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this, true); readExtraMetadata(store); readFileInfoMetadata(store); }
private void parseSeriesTag() throws IOException { addSeriesMeta("Version", in.readInt()); addSeriesMeta("Number of Series", in.readInt()); fileLength = in.readInt(); addSeriesMeta("Length of filename", fileLength); int extLen = in.readInt(); if (extLen > fileLength) { in.seek(8); core.get(0).littleEndian = !isLittleEndian(); in.order(isLittleEndian()); fileLength = in.readInt(); extLen = in.readInt(); } addSeriesMeta("Length of file extension", extLen); addSeriesMeta("Image file extension", getString(extLen)); }
private void parseLUT(int seriesIndex) throws IOException { int nChannels = in.readInt(); if (nChannels > 0) core.get(seriesIndex).indexed = true; addSeriesMeta("Number of LUT channels", nChannels); addSeriesMeta("ID of colored dimension", in.readInt()); addSeriesMeta(p + " version", in.readInt()); addSeriesMeta(p + " inverted?", in.read() == 1); addSeriesMeta(p + " description", getString(false)); in.skipBytes(8);
/** * Read the footer data for the current database file. * @throws IOException if the footer cannot be read from the file * @throws MetakitException if the footer is not valid for the Metakit format */ private void readFooter() throws IOException, MetakitException { stream.skipBytes(4); long headerLocation = stream.readInt(); stream.skipBytes(4); long tocLocation = stream.readInt(); stream.seek(tocLocation); readTOC(); }
public AttachmentEntry(RandomAccessInputStream s) throws IOException { schemaType = s.readString(2); s.skipBytes(10); // reserved filePosition = s.readLong(); filePart = s.readInt(); contentGUID = s.readString(16); contentFileType = s.readString(8); name = s.readString(80); }
long fp = s.getFilePointer(); s.seek(startFilePointer - 44); int uidLength = s.readInt(); String uid = s.readString(uidLength); s.seek(fp);
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; }
@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 void parseChannelTag() throws IOException { int nBands = in.readInt(); for (int band=0; band<nBands; band++) { String p = "Band #" + (band + 1) + " "; addSeriesMeta(p + "Lower wavelength", in.readDouble()); in.skipBytes(4); addSeriesMeta(p + "Higher wavelength", in.readDouble()); in.skipBytes(4); addSeriesMeta(p + "Gain", in.readDouble()); addSeriesMeta(p + "Offset", in.readDouble()); } }
TiffIFDEntry readTiffIFDEntry() throws IOException { int entryTag = in.readUnsignedShort(); // Parse the entry's "Type" IFDType entryType; try { entryType = IFDType.get(in.readUnsignedShort()); } catch (EnumException e) { LOGGER.error("Error reading IFD type at: {}", in.getFilePointer()); throw e; } // Parse the entry's "ValueCount" int valueCount = bigTiff ? (int) in.readLong() : in.readInt(); if (valueCount < 0) { throw new RuntimeException("Count of '" + valueCount + "' unexpected."); } int nValueBytes = valueCount * entryType.getBytesPerElement(); int threshhold = bigTiff ? 8 : 4; long offset = nValueBytes > threshhold ? getNextOffset(0) : in.getFilePointer(); return new TiffIFDEntry(entryTag, entryType, valueCount, offset); } }
/** Read the header for an image stack. */ private void readStackHeader() throws IOException { int count = in.readInt(); if (count > 0xffff) { in.seek(in.getFilePointer() - 2); int len = in.readShort(); in.skipBytes(len); count = in.readInt() + 1; } skipTags(count); skipTagBlock(); }
private void parseImageTag(int seriesIndex) throws IOException { CoreMetadata ms = core.get(seriesIndex); ms.imageCount = in.readInt(); ms.sizeX = in.readInt(); ms.sizeY = in.readInt(); addSeriesMeta("Number of images", getImageCount()); addSeriesMeta("Image width", getSizeX()); addSeriesMeta("Image height", getSizeY()); addSeriesMeta("Bits per Sample", in.readInt()); addSeriesMeta("Samples per pixel", in.readInt()); String name = getString(fileLength * 2); if (name.indexOf('.') != -1) { name = name.substring(0, name.lastIndexOf(".")); } String[] tokens = name.split("_"); final StringBuilder buf = new StringBuilder(); for (int p=1; p<tokens.length; p++) { String lcase = tokens[p].toLowerCase(); if (!lcase.startsWith("ch0") && !lcase.startsWith("c0") && !lcase.startsWith("z0") && !lcase.startsWith("t0") && !lcase.startsWith("y0") && !lcase.startsWith("la0")) { if (buf.length() > 0) buf.append("_"); buf.append(tokens[p]); } } seriesNames.add(buf.toString()); }
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); CoreMetadata m = core.get(0); m.littleEndian = true; in.order(isLittleEndian()); in.seek(44); m.sizeX = in.readInt(); m.sizeY = in.readInt(); m.pixelType = FormatTools.UINT32; m.sizeZ = 1; m.sizeC = 1; m.sizeT = 1; m.imageCount = 1; m.dimensionOrder = "XYZCT"; padding = (int) ((in.length() - FormatTools.getPlaneSize(this)) / (getSizeY() * 4)); addGlobalMeta("Padding bytes", padding); MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); }