Package loci.formats

Examples of loci.formats.FormatException


      tiffParser = new TiffParser(in);
      tiffParser.setDoCaching(false);
      tiffParser.setUse64BitOffsets(false);
      final Boolean littleEndian = tiffParser.checkHeader();
      if (littleEndian == null) {
        throw new FormatException("Invalid FlowSight file");
      }
      final boolean little = littleEndian.booleanValue();
      in.order(little);
     
      LOGGER.info("Reading IFDs");

      ifdOffsets = tiffParser.getIFDOffsets();

      if (ifdOffsets.length < 2) {
        throw new FormatException("No IFDs found");
      }
     
      LOGGER.info("Populating metadata");

      /*
       * The first IFD contains file-scope metadata
       */
      final IFD ifd0 = tiffParser.getFirstIFD();
      tiffParser.fillInIFD(ifd0);
      final int channelCount = ifd0.getIFDIntValue(CHANNEL_COUNT_TAG);
      final String channelNamesString = ifd0.getIFDStringValue(CHANNEL_NAMES_TAG);
      channelNames = channelNamesString.split("\\|");
      if (channelNames.length != channelCount) {
        throw new FormatException(String.format(
            "Channel count (%d) does not match number of channel names (%d) in string \"%s\"",
            channelCount, channelNames.length, channelNamesString));
      }
      LOGGER.debug(String.format(
          "Found %d channels: %s",
          channelCount, channelNamesString.replace('|', ',')));
      final String channelDescsString = ifd0.getIFDStringValue(CHANNEL_DESCS_TAG);
      channelDescs =  channelDescsString.split("\\|");
      if (channelDescs.length != channelCount) {
        throw new FormatException(String.format(
            "Channel count (%d) does not match number of channel descriptions (%d) in string \"%s\"",
            channelCount, channelDescs.length, channelDescsString));
      }
      /*
       * Scan the remaining IFDs
View Full Code Here


  @Override
  public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
      throws FormatException, IOException {
    if (no > getChannelCount()) {
      throw new FormatException("Only one plane per series");
    }
    final int idx = getSeries() + 1;
    final IFD ifd = tiffParser.getIFD(ifdOffsets[idx]);
    final int imageWidth = (int)(ifd.getImageWidth());
    final int imageHeight = (int)(ifd.getImageLength());
    final int wOff = x + no * imageWidth / getChannelCount();
    if ((y+h > imageHeight) || (x+w > imageWidth / getChannelCount()) ) {
      throw new FormatException("Requested tile dimensions extend beyond those of the image.");
    }
    final int compression = ifd.getIFDIntValue(IFD.COMPRESSION);
    byte [] tempBuffer; /* NB - these images are very small */
    switch(compression) {
    case GREYSCALE_COMPRESSION:
      tempBuffer = openGreyscaleBytes(ifd, imageWidth, imageHeight);
      break;
    case BITMASK_COMPRESSION:
      tempBuffer = openBitmaskBytes(ifd, imageWidth, imageHeight);
      break;
    default:
      throw new FormatException(String.format("Unknown compression code: %d", compression));
    }
    final int bytesPerSample = ifd.getIFDIntValue(IFD.BITS_PER_SAMPLE) / 8;
    for (int yy=y; yy<y+h; yy++) {
      final int srcOff = bytesPerSample * (wOff + yy * imageWidth);
      final int destOff = bytesPerSample * (yy-y) * w;
 
View Full Code Here

        in.seek(stripOffsets[i]);
        for (int j=0; j<stripByteCounts[i]; j+=2) {
          byte value = in.readByte();
          int runLength = (in.readByte() & 0xFF)+1;
          if (off + runLength > uncompressed.length) {
            throw new FormatException("Unexpected buffer overrun encountered when decompressing bitmask data");
          }
          Arrays.fill(uncompressed, off, off+runLength, value);
          off += runLength;
        }
      } catch (IOException e) {
        LOGGER.error("Caught exception while reading bitmask IFD data", e);
        throw new FormatException(String.format("Error in FlowSight file format: %s", e.getMessage()));
      }
    }
    if (off != uncompressed.length) throw new FormatException("Buffer shortfall encountered when decompressing bitmask data");
    return uncompressed;
  }
View Full Code Here

                value |= - (1 << shift);
              }
            }
          } catch (IOException e) {
            LOGGER.error("IOException during read of greyscale image", e);
            formatException[0] = new FormatException(
                String.format("Error in FlowSight format: %s", e.getMessage()));
            loaded = true;
            bHasNext = false;
          } catch (FormatException e) {
            LOGGER.error("Format exception during read of greyscale image", e);
View Full Code Here

    if (!isBigTiff) {
      isBigTiff = (out.length() + 2
          * (width * height * c * bytesPerPixel)) >= 4294967296L;
      if (isBigTiff) {
        throw new FormatException("File is too large; call setBigTiff(true)");
      }
    }

    // write the image
    ifd.put(new Integer(IFD.LITTLE_ENDIAN), new Boolean(littleEndian));
View Full Code Here

    super.initFile(id);
    IRandomAccess is = Location.getHandle(id, false);
    is.setOrder(ByteOrder.LITTLE_ENDIAN);
    final int cookie = is.readInt();
    if (cookie != COOKIE) {
      throw new FormatException(String.format("Expected file cookie of %d, but got %d.", COOKIE, cookie));
    }
    long fileLength = is.length();
    records = new ArrayList<IM3Record>();
    dataSets = new ArrayList<ContainerRecord>();
    spectra = new ArrayList<Spectrum>();
View Full Code Here

      lsmFilenames = parseMDB(id);
    }
    else lsmFilenames = new String[] {id};

    if (lsmFilenames == null || lsmFilenames.length == 0) {
      throw new FormatException("LSM files were not found.");
    }

    timestamps = new Vector<Double>();
    imageNames = new Vector<String>();
    xCoordinates = new Vector<Double>();
    yCoordinates = new Vector<Double>();
    zCoordinates = new Vector<Double>();
    seriesCounts = new Hashtable<String, Integer>();

    int seriesCount = 0;

    Vector<String> validFiles = new Vector<String>();
    for (String filename : lsmFilenames) {
      try {
        int extraSeries = getExtraSeries(filename);
        seriesCounts.put(filename, extraSeries);
        seriesCount += extraSeries;
        validFiles.add(filename);
      }
      catch (IOException e) {
        LOGGER.debug("Failed to parse " + filename, e);
      }
    }
    lsmFilenames = validFiles.toArray(new String[validFiles.size()]);

    core.clear();
    for (int c=0; c<seriesCount; c++) {
      CoreMetadata ms = new CoreMetadata();
        core.add(ms);
    }
    channelNames = new String[seriesCount][];
    ifdsList = new Vector<IFDList>();
    ifdsList.setSize(seriesCount);

    int realSeries = 0;
    for (int i=0; i<lsmFilenames.length; i++) {
      RandomAccessInputStream stream =
        new RandomAccessInputStream(lsmFilenames[i]);
      int count = seriesCounts.get(lsmFilenames[i]);

      TiffParser tp = new TiffParser(stream);
      Boolean littleEndian = tp.checkHeader();
      long[] ifdOffsets = tp.getIFDOffsets();
      int ifdsPerSeries = (ifdOffsets.length / 2) / count;

      int offset = 0;
      Object zeissTag = null;
      for (int s=0; s<count; s++, realSeries++) {
        CoreMetadata ms = core.get(realSeries);
        ms.littleEndian = littleEndian;

        IFDList ifds = new IFDList();
        while (ifds.size() < ifdsPerSeries) {
          tp.setDoCaching(offset == 0);
          IFD ifd = tp.getIFD(ifdOffsets[offset]);
          if (offset == 0) zeissTag = ifd.get(ZEISS_ID);
          if (offset > 0 && ifds.size() == 0) {
            ifd.putIFDValue(ZEISS_ID, zeissTag);
          }
          ifds.add(ifd);
          if (zeissTag != null) offset += 2;
          else offset++;
        }

        for (IFD ifd : ifds) {
          tp.fillInIFD(ifd);
        }

        ifdsList.set(realSeries, ifds);
      }
      stream.close();
    }

    MetadataStore store = makeFilterMetadata();

    lut = new byte[ifdsList.size()][][];

    long[] previousStripOffsets = null;

    for (int series=0; series<ifdsList.size(); series++) {
      // IFD ordering is ZPT, so reset state if we have multiple timepoints
      // this prevents offsets from being confused when the first offset in
      // the next series is legitimately smaller than the last offset in
      // the previous series
      if (series > 0 && getSizeT() > 1) {
        previousStripOffsets = null;
      }

      IFDList ifds = ifdsList.get(series);
      for (IFD ifd : ifds) {
        // check that predictor is set to 1 if anything other
        // than LZW compression is used
        if (ifd.getCompression() != TiffCompression.LZW) {
          ifd.putIFDValue(IFD.PREDICTOR, 1);
        }
      }

      // fix the offsets for > 4 GB files
      RandomAccessInputStream s =
        new RandomAccessInputStream(getLSMFileFromSeries(series));
      for (int i=0; i<ifds.size(); i++) {
        long[] stripOffsets = ifds.get(i).getStripOffsets();

        if (stripOffsets == null || (i != 0 && previousStripOffsets == null)) {
          throw new FormatException(
            "Strip offsets are missing; this is an invalid file.");
        }
        else if (i == 0 && previousStripOffsets == null) {
          previousStripOffsets = stripOffsets;
          continue;
View Full Code Here

    try {
      ServiceFactory factory = new ServiceFactory();
      mdbService = factory.getInstance(MDBService.class);
    }
    catch (DependencyException de) {
      throw new FormatException("MDB Tools Java library not found", de);
    }

    try {
      mdbService.initialize(mdbFile);
    }
View Full Code Here

TOP

Related Classes of loci.formats.FormatException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.