@Override public void reopenFile() throws IOException { if (in != null) { in.close(); } in = new RandomAccessInputStream(spcId); in.order(true); }
/** Searches for the divider tag in blocks of the given size. */ public long testBlock(String filename, int blockSize) throws IOException { LOGGER.info("Searching for divider in blocks of {}...", blockSize); long start = System.currentTimeMillis(); RandomAccessInputStream in = new RandomAccessInputStream(filename); long offset = in.findString(blockSize, TAG).length(); in.close(); long end = System.currentTimeMillis(); LOGGER.info("Search result: {} -- in {} ms", offset, end - start); return offset; }
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; }
/** * @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); if (files.size() > 1) { in = new RandomAccessInputStream(files.get(no)); in.order(isLittleEndian()); } in.seek(pixelOffsets[no]); readPlane(in, x, getSizeY() - y - h, w, h, buf); int bpp = FormatTools.getBytesPerPixel(getPixelType()); byte[] rowBuf = new byte[w * bpp]; for (int row=0; row<h/2; row++) { int src = row * rowBuf.length; int dest = (h - row - 1) * rowBuf.length; System.arraycopy(buf, src, rowBuf, 0, rowBuf.length); System.arraycopy(buf, dest, buf, src, rowBuf.length); System.arraycopy(rowBuf, 0, buf, dest, rowBuf.length); } if (files.size() > 1) { in.close(); } return buf; }
@Override public void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); int[] dimensions; try (JPEGTileDecoder decoder = new JPEGTileDecoder()) { dimensions = decoder.preprocess(in); } CoreMetadata m = core.get(0); m.interleaved = true; m.littleEndian = false; m.sizeX = dimensions[0]; m.sizeY = dimensions[1]; m.sizeZ = 1; m.sizeT = 1; reopenFile(); m.sizeC = 3; m.rgb = getSizeC() > 1; m.imageCount = 1; m.pixelType = FormatTools.UINT8; m.dimensionOrder = "XYCZT"; m.metadataComplete = true; m.indexed = false; MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); }
private void parseChannelData(Location dir) throws IOException { emWave = new double[channelNames.size()]; exWave = new double[channelNames.size()]; exposure = new double[channelNames.size()]; gain = new double[channelNames.size()]; offset = new double[channelNames.size()]; for (int c=0; c<channelNames.size(); c++) { Location dyeFile = new Location(dir, channelNames.get(c) + ".dye"); IniList dye = null; try (RandomAccessInputStream stream = new RandomAccessInputStream(dyeFile.getAbsolutePath()); InputStreamReader isr = new InputStreamReader(stream, Constants.ENCODING); BufferedReader br = new BufferedReader(isr)) { dye = new IniParser().parseINI(br); } IniTable numerator = dye.getTable("Numerator"); String em = numerator.get("Emission"); em = em.substring(0, em.indexOf(' ')); emWave[c] = Double.parseDouble(em); String ex = numerator.get("Excitation"); ex = ex.substring(0, ex.lastIndexOf(" ")); if (ex.indexOf(' ') != -1) { ex = ex.substring(ex.lastIndexOf(" ") + 1); } exWave[c] = Double.parseDouble(ex); exposure[c] = Double.parseDouble(numerator.get("Exposure")); gain[c] = Double.parseDouble(numerator.get("Gain")); offset[c] = Double.parseDouble(numerator.get("Offset")); } }
/** * @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); lastPlane = no; int fileIndex = no < files[getSeries()].size() ? no : 0; int planeIndex = no < files[getSeries()].size() ? 0 : no; String filename = (String) files[getSeries()].get(fileIndex); if (new Location(filename).exists()) { if (checkSuffix(filename, TiffReader.TIFF_SUFFIXES)) { tiff.setId(filename); return tiff.openBytes(planeIndex, buf, x, y, w, h); } else { try (RandomAccessInputStream s = new RandomAccessInputStream(filename)) { s.seek(planeIndex * FormatTools.getPlaneSize(this)); readPlane(s, x, y, w, h, buf); } } } // imitate Leica's software and return a blank plane if the // appropriate TIFF file is missing return buf; }
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; }
private RandomAccessInputStream getDecompressedStream(String filename) throws FormatException, IOException { RandomAccessInputStream s = new RandomAccessInputStream(filename); if (checkSuffix(filename, "c01")) { LOGGER.info("Decompressing file"); try { s.seek(4); ZlibCodec codec = new ZlibCodec(); byte[] file = codec.decompress(s, null); return new RandomAccessInputStream(file); } finally { s.close(); } } return s; }
/** * @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); lastChannel = getZCTCoords(no)[1]; if (picFiles != null) { int file = no % picFiles.length; try (RandomAccessInputStream ras = new RandomAccessInputStream(picFiles[file])) { long offset = (no / picFiles.length) * FormatTools.getPlaneSize(this); ras.seek(offset + 76); readPlane(ras, x, y, w, h, buf); } } else { in.seek(no * FormatTools.getPlaneSize(this) + 76); readPlane(in, x, y, w, h, buf); } return buf; }
/** * @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); if (files.size() > 1) { in = new RandomAccessInputStream(files.get(no)); in.order(isLittleEndian()); } in.seek(pixelOffsets[no]); readPlane(in, x, getSizeY() - y - h, w, h, buf); int bpp = FormatTools.getBytesPerPixel(getPixelType()); byte[] rowBuf = new byte[w * bpp]; for (int row=0; row<h/2; row++) { int src = row * rowBuf.length; int dest = (h - row - 1) * rowBuf.length; System.arraycopy(buf, src, rowBuf, 0, rowBuf.length); System.arraycopy(buf, dest, buf, src, rowBuf.length); System.arraycopy(rowBuf, 0, buf, dest, rowBuf.length); } if (files.size() > 1) { in.close(); } return buf; }
@Override public void initFile(String id) throws FormatException, IOException { super.initFile(id); in = new RandomAccessInputStream(id); int[] dimensions; try (JPEGTileDecoder decoder = new JPEGTileDecoder()) { dimensions = decoder.preprocess(in); } CoreMetadata m = core.get(0); m.interleaved = true; m.littleEndian = false; m.sizeX = dimensions[0]; m.sizeY = dimensions[1]; m.sizeZ = 1; m.sizeT = 1; reopenFile(); m.sizeC = 3; m.rgb = getSizeC() > 1; m.imageCount = 1; m.pixelType = FormatTools.UINT8; m.dimensionOrder = "XYCZT"; m.metadataComplete = true; m.indexed = false; MetadataStore store = makeFilterMetadata(); MetadataTools.populatePixels(store, this); }
private void parseChannelData(Location dir) throws IOException { emWave = new double[channelNames.size()]; exWave = new double[channelNames.size()]; exposure = new double[channelNames.size()]; gain = new double[channelNames.size()]; offset = new double[channelNames.size()]; for (int c=0; c<channelNames.size(); c++) { Location dyeFile = new Location(dir, channelNames.get(c) + ".dye"); IniList dye = null; try (RandomAccessInputStream stream = new RandomAccessInputStream(dyeFile.getAbsolutePath()); InputStreamReader isr = new InputStreamReader(stream, Constants.ENCODING); BufferedReader br = new BufferedReader(isr)) { dye = new IniParser().parseINI(br); } IniTable numerator = dye.getTable("Numerator"); String em = numerator.get("Emission"); em = em.substring(0, em.indexOf(' ')); emWave[c] = Double.parseDouble(em); String ex = numerator.get("Excitation"); ex = ex.substring(0, ex.lastIndexOf(" ")); if (ex.indexOf(' ') != -1) { ex = ex.substring(ex.lastIndexOf(" ") + 1); } exWave[c] = Double.parseDouble(ex); exposure[c] = Double.parseDouble(numerator.get("Exposure")); gain[c] = Double.parseDouble(numerator.get("Gain")); offset[c] = Double.parseDouble(numerator.get("Offset")); } }
/** * @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); lastPlane = no; int fileIndex = no < files[getSeries()].size() ? no : 0; int planeIndex = no < files[getSeries()].size() ? 0 : no; String filename = (String) files[getSeries()].get(fileIndex); if (new Location(filename).exists()) { if (checkSuffix(filename, TiffReader.TIFF_SUFFIXES)) { tiff.setId(filename); return tiff.openBytes(planeIndex, buf, x, y, w, h); } else { try (RandomAccessInputStream s = new RandomAccessInputStream(filename)) { s.seek(planeIndex * FormatTools.getPlaneSize(this)); readPlane(s, x, y, w, h, buf); } } } // imitate Leica's software and return a blank plane if the // appropriate TIFF file is missing return buf; }
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; }
private RandomAccessInputStream getDecompressedStream(String filename) throws FormatException, IOException { RandomAccessInputStream s = new RandomAccessInputStream(filename); if (checkSuffix(filename, "c01")) { LOGGER.info("Decompressing file"); try { s.seek(4); ZlibCodec codec = new ZlibCodec(); byte[] file = codec.decompress(s, null); return new RandomAccessInputStream(file); } finally { s.close(); } } return s; }
@Override public boolean isThisType(byte[] block) { try { RandomAccessInputStream stream = new RandomAccessInputStream(block); boolean isThisType = isThisType(stream); stream.close(); return isThisType; } catch (IOException e) { LOGGER.debug("", e); } return false; }
@Override public void reopenFile() throws IOException { if (in != null) { in.close(); } in = new RandomAccessInputStream(spcId); in.order(true); }
/** * @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); lastChannel = getZCTCoords(no)[1]; if (picFiles != null) { int file = no % picFiles.length; try (RandomAccessInputStream ras = new RandomAccessInputStream(picFiles[file])) { long offset = (no / picFiles.length) * FormatTools.getPlaneSize(this); ras.seek(offset + 76); readPlane(ras, x, y, w, h, buf); } } else { in.seek(no * FormatTools.getPlaneSize(this) + 76); readPlane(in, x, y, w, h, buf); } return buf; }
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; }