From d8226c9de50c95aae509070d97adc88a2f2b8325 Mon Sep 17 00:00:00 2001 From: jakubs <jakubs> Date: Fri, 3 May 2013 14:23:35 +0000 Subject: [PATCH] SP-606 CCS-34 improve performance of reading c01 files SVN: 28993 --- .../bioformats/BioFormatsImageUtils.java | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/image_readers/source/java/ch/systemsx/cisd/imagereaders/bioformats/BioFormatsImageUtils.java b/image_readers/source/java/ch/systemsx/cisd/imagereaders/bioformats/BioFormatsImageUtils.java index ce3817be9da..9b81a4f2ca2 100644 --- a/image_readers/source/java/ch/systemsx/cisd/imagereaders/bioformats/BioFormatsImageUtils.java +++ b/image_readers/source/java/ch/systemsx/cisd/imagereaders/bioformats/BioFormatsImageUtils.java @@ -32,11 +32,16 @@ import java.util.UUID; import loci.common.IRandomAccess; import loci.common.Location; +import loci.common.RandomAccessInputStream; import loci.formats.FormatException; +import loci.formats.FormatHandler; import loci.formats.IFormatHandler; import loci.formats.IFormatReader; import loci.formats.ImageReader; +import loci.formats.MetadataTools; +import loci.formats.codec.ZlibCodec; import loci.formats.gui.BufferedImageReader; +import loci.formats.in.CellomicsReader; import loci.formats.in.DefaultMetadataOptions; import loci.formats.in.MetadataLevel; import loci.formats.in.MetadataOptions; @@ -55,6 +60,12 @@ final class BioFormatsImageUtils private static final IFormatReader[] READERS = new ImageReader().getReaders(); + static + { + MetadataTools.setDefaultDateEnabled(false); + CellomicsReader.setNoHiddenFiles(true); + } + /** * Tries to create a suitable reader for the file specified with <var>fileName</var>. This is a * factory method which returns for each invocation a new instance of a suitable reader. May @@ -201,7 +212,7 @@ final class BioFormatsImageUtils throws IOExceptionUnchecked, IllegalArgumentException { String handleId = generateHandleId(reader, imageID); - + // Add to static map. Location.mapFile(handleId, handle); try @@ -286,7 +297,7 @@ final class BioFormatsImageUtils { // Add to static map. String handleId = generateHandleId(reader, imageID); - + Location.mapFile(handleId, handle); try { @@ -326,6 +337,11 @@ final class BioFormatsImageUtils Location.mapFile(handleId, handle); try { + if (reader instanceof CellomicsReader) + { + return CellomicsReaderUtil.readSize(handleId); + } + // This does the actual parsing. reader.setId(handleId); reader.setSeries(imageID.getSeriesIndex()); @@ -346,6 +362,42 @@ final class BioFormatsImageUtils } } + public static class CellomicsReaderUtil + { + public static Dimension readSize(String id) throws FormatException, IOException + { + RandomAccessInputStream in = getDecompressedStream(id); + + in.order(true); + in.skipBytes(4); + + int x = in.readInt(); + int y = in.readInt(); + + in.close(); + + return new Dimension(x, y); + + } + + private static RandomAccessInputStream getDecompressedStream(String filename) + throws FormatException, IOException + { + RandomAccessInputStream s = new RandomAccessInputStream(filename); + if (FormatHandler.checkSuffix(filename, "c01")) + { + + s.seek(4); + ZlibCodec codec = new ZlibCodec(); + byte[] file = codec.decompress(s, null); + s.close(); + + return new RandomAccessInputStream(file); + } + return s; + } + } + static Integer readImageColorDepth(IFormatReader reader, IRandomAccess handle, ImageID imageID) throws IOExceptionUnchecked, IllegalArgumentException { -- GitLab