Search in sources :

Example 1 with CacheException

use of loci.formats.cache.CacheException in project bioformats by openmicroscopy.

the class BFVirtualStack method getProcessor.

// -- VirtualStack API methods --
@Override
public synchronized ImageProcessor getProcessor(int n) {
    reader.setSeries(series);
    // check cache first
    if (currentSlice >= 0 && currentProcessor != null) {
        List<MethodEntry> currentStack = currentProcessor.getMethodStack();
        if (currentStack.size() > 1) {
            methodStacks.get(currentSlice).addAll(currentStack);
        }
    }
    int sliceIndex = planeIndexes == null ? n - 1 : planeIndexes[n - 1];
    int[] pos = reader.getZCTCoords(sliceIndex);
    if (merge)
        pos = new ChannelMerger(reader).getZCTCoords(sliceIndex);
    int[] cachePos = FormatTools.rasterToPosition(len, sliceIndex);
    ImageProcessor ip = null;
    try {
        ip = (ImageProcessor) cache.getObject(cachePos);
        cache.setCurrentPos(cachePos);
    } catch (CacheException exc) {
        exc.printStackTrace();
    }
    // cache missed
    try {
        if (ip == null) {
            ip = reader.openProcessors(reader.getIndex(pos[0], pos[1], pos[2]))[0];
        }
    } catch (FormatException exc) {
        exc.printStackTrace();
    } catch (IOException exc) {
        exc.printStackTrace();
    }
    if (colorize) {
        // apply color table, if necessary
        byte[] lut = new byte[256];
        byte[] blank = new byte[256];
        for (int i = 0; i < lut.length; i++) {
            lut[i] = (byte) i;
            blank[i] = (byte) 0;
        }
        IndexColorModel model = null;
        if (pos[1] < 3) {
            model = new IndexColorModel(8, 256, pos[1] == 0 ? lut : blank, pos[1] == 1 ? lut : blank, pos[1] == 2 ? lut : blank);
        } else
            model = new IndexColorModel(8, 256, lut, lut, lut);
        if (ip != null)
            ip.setColorModel(model);
    } else if (merge) {
        currentSlice = n - 1;
        ImageProcessor[] otherChannels = new ImageProcessor[reader.getSizeC() - 1];
        for (int i = 0; i < otherChannels.length; i++) {
            int channel = i >= pos[1] ? i + 1 : i;
            try {
                cachePos[0] = channel;
                otherChannels[i] = (ImageProcessor) cache.getObject(cachePos);
            } catch (CacheException exc) {
                exc.printStackTrace();
            }
            if (otherChannels[i] == null) {
                try {
                    int index = reader.getIndex(pos[0], channel, pos[2]);
                    otherChannels[i] = reader.openProcessors(index)[0];
                } catch (FormatException exc) {
                    exc.printStackTrace();
                } catch (IOException exc) {
                    exc.printStackTrace();
                }
            }
        }
        currentProcessor = new RecordedImageProcessor(ip, pos[1], otherChannels);
        currentProcessor.setDoRecording(record);
        if (calibrationTable == null) {
            calibrationTable = currentProcessor.getChild().getCalibrationTable();
        } else {
            currentProcessor.setCalibrationTable(calibrationTable);
        }
        return currentProcessor.getChild();
    }
    if (ip != null) {
        currentSlice = n - 1;
        currentProcessor = new RecordedImageProcessor(ip);
        currentProcessor.setDoRecording(record);
        if (calibrationTable == null) {
            calibrationTable = currentProcessor.getChild().getCalibrationTable();
        } else {
            currentProcessor.setCalibrationTable(calibrationTable);
        }
        return currentProcessor.getChild();
    }
    return null;
}
Also used : ImageProcessor(ij.process.ImageProcessor) CacheException(loci.formats.cache.CacheException) ChannelMerger(loci.formats.ChannelMerger) MethodEntry(loci.plugins.util.RecordedImageProcessor.MethodEntry) IOException(java.io.IOException) FormatException(loci.formats.FormatException) IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

ImageProcessor (ij.process.ImageProcessor)1 IndexColorModel (java.awt.image.IndexColorModel)1 IOException (java.io.IOException)1 ChannelMerger (loci.formats.ChannelMerger)1 FormatException (loci.formats.FormatException)1 CacheException (loci.formats.cache.CacheException)1 MethodEntry (loci.plugins.util.RecordedImageProcessor.MethodEntry)1