示例#1
0
  /* @see BaseTiffReader#initStandardMetadata() */
  protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();

    ifds = tiffParser.getIFDs();

    core.clear();
    for (int i = 0; i < ifds.size(); i++) {
      CoreMetadata ms = new CoreMetadata();
      core.add(ms);
      ms.imageCount = 1;
      IFD ifd = ifds.get(i);
      ifd.remove(PIXELS_TAG);
      tiffParser.fillInIFD(ifd);

      PhotoInterp photo = ifd.getPhotometricInterpretation();
      int samples = ifd.getSamplesPerPixel();
      ms.rgb = samples > 1 || photo == PhotoInterp.RGB || photo == PhotoInterp.CFA_ARRAY;
      if (photo == PhotoInterp.CFA_ARRAY) samples = 3;

      ms.sizeX = (int) ifd.getImageWidth();
      ms.sizeY = (int) ifd.getImageLength();
      ms.sizeZ = 1;
      ms.sizeC = isRGB() ? samples : 1;
      ms.sizeT = 1;
      ms.pixelType = ifd.getPixelType();
      ms.indexed = photo == PhotoInterp.RGB_PALETTE;
      ms.dimensionOrder = "XYCZT";
      ms.interleaved = false;
    }

    IFD firstIFD = ifds.get(0);

    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
      String xml = firstIFD.getIFDTextValue(XML_TAG).trim();
      xml = xml.substring(xml.indexOf("<"));
      XMLTools.parseXML(xml, new ImaconHandler());
    }

    String[] creationInfo = firstIFD.getIFDTextValue(CREATOR_TAG).split("\n");

    if (creationInfo.length > 4) {
      experimenterName = creationInfo[4].trim();
    }
    if (creationInfo.length > 6) {
      imageName = creationInfo[6].trim();
    }
    if (creationInfo.length > 8) {
      creationDate = creationInfo[8].trim();
    }
    if (creationInfo.length > 10) {
      creationDate += " " + creationInfo[10].trim();
    }
  }
  /* @see loci.formats.FormatReader#initFile(String) */
  protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);

    if (!checkSuffix(id, "vsi")) {
      Location current = new Location(id).getAbsoluteFile();
      Location parent = current.getParentFile();
      parent = parent.getParentFile();
      Location grandparent = parent.getParentFile();
      String vsi = parent.getName();
      vsi = vsi.substring(1, vsi.length() - 1) + ".vsi";

      Location vsiFile = new Location(grandparent, vsi);
      if (!vsiFile.exists()) {
        throw new FormatException("Could not find .vsi file.");
      } else {
        id = vsiFile.getAbsolutePath();
      }
    }

    parser = new TiffParser(id);
    ifds = parser.getIFDs();

    RandomAccessInputStream vsi = new RandomAccessInputStream(id);
    vsi.order(parser.getStream().isLittleEndian());
    vsi.seek(8);
    readTags(vsi);
    vsi.seek(parser.getStream().getFilePointer());

    vsi.skipBytes(273);

    ArrayList<String> files = new ArrayList<String>();
    Location file = new Location(id).getAbsoluteFile();

    Location dir = file.getParentFile();

    String name = file.getName();
    name = name.substring(0, name.lastIndexOf("."));

    Location pixelsDir = new Location(dir, "_" + name + "_");
    String[] stackDirs = pixelsDir.list(true);
    if (stackDirs != null) {
      for (String f : stackDirs) {
        Location stackDir = new Location(pixelsDir, f);
        String[] pixelsFiles = stackDir.list(true);
        if (pixelsFiles != null) {
          for (String pixelsFile : pixelsFiles) {
            if (checkSuffix(pixelsFile, "ets")) {
              files.add(new Location(stackDir, pixelsFile).getAbsolutePath());
            }
          }
        }
      }
    }
    files.add(file.getAbsolutePath());
    usedFiles = files.toArray(new String[files.size()]);

    core = new CoreMetadata[files.size() - 1 + ifds.size()];

    tileOffsets = new Long[files.size() - 1][];
    rows = new int[files.size() - 1];
    cols = new int[files.size() - 1];
    nDimensions = new int[core.length];

    IFDList exifs = parser.getExifIFDs();

    compressionType = new int[core.length];
    tileX = new int[core.length];
    tileY = new int[core.length];
    tileMap = new HashMap[core.length];

    for (int s = 0; s < core.length; s++) {
      core[s] = new CoreMetadata();
    }

    for (int s = 0; s < core.length; s++) {
      tileMap[s] = new HashMap<TileCoordinate, Integer>();

      if (s == 0 && !hasFlattenedResolutions()) {
        core[s].resolutionCount = ifds.size() + (files.size() == 1 ? 0 : 1);
      }

      if (s < files.size() - 1) {
        setSeries(s);
        parseETSFile(files.get(s), s);

        core[s].littleEndian = compressionType[s] == RAW;
        core[s].interleaved = core[s].rgb;

        if (s == 0 && exifs.size() > 0) {
          IFD exif = exifs.get(0);

          int newX = exif.getIFDIntValue(IFD.PIXEL_X_DIMENSION);
          int newY = exif.getIFDIntValue(IFD.PIXEL_Y_DIMENSION);

          if (getSizeX() > newX || getSizeY() > newY) {
            core[s].sizeX = newX;
            core[s].sizeY = newY;
          }
        }

        setSeries(0);
      } else {
        IFD ifd = ifds.get(s - files.size() + 1);
        PhotoInterp p = ifd.getPhotometricInterpretation();
        int samples = ifd.getSamplesPerPixel();
        core[s].rgb = samples > 1 || p == PhotoInterp.RGB;
        core[s].sizeX = (int) ifd.getImageWidth();
        core[s].sizeY = (int) ifd.getImageLength();
        core[s].sizeZ = 1;
        core[s].sizeT = 1;
        core[s].sizeC = core[s].rgb ? samples : 1;
        core[s].littleEndian = ifd.isLittleEndian();
        core[s].indexed =
            p == PhotoInterp.RGB_PALETTE
                && (get8BitLookupTable() != null || get16BitLookupTable() != null);
        core[s].imageCount = 1;
        core[s].pixelType = ifd.getPixelType();
        core[s].interleaved = false;
        core[s].falseColor = false;
        core[s].thumbnail = s != 0;
      }
      core[s].metadataComplete = true;
      core[s].dimensionOrder = "XYCZT";
    }
    vsi.close();

    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
  }
  /* @see loci.formats.in.BaseTiffReader#initStandardMetadata() */
  protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();

    ifds = tiffParser.getIFDs();
    for (IFD ifd : ifds) {
      tiffParser.fillInIFD(ifd);
    }

    String comment = ifds.get(0).getComment();
    String[] values = comment.split(";");
    for (String v : values) {
      int eq = v.indexOf("=");
      if (eq < 0) continue;
      String key = v.substring(0, eq).trim();
      String value = v.substring(eq + 1).trim();
      addGlobalMeta(key, value);

      if (key.equals("OverlapsXY")) {
        String[] overlapValues = value.split(" ");
        overlaps = new int[ifds.size() * 2];
        for (int i = 0; i < overlapValues.length; i++) {
          overlaps[i] = Integer.parseInt(overlapValues[i]);
        }
      }
    }

    core = new CoreMetadata[ifds.size()];

    for (int i = 0; i < core.length; i++) {
      setSeries(i);
      core[i] = new CoreMetadata();

      if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {}
    }
    setSeries(0);

    // repopulate core metadata

    for (int s = 0; s < core.length; s++) {
      IFD ifd = ifds.get(s);
      PhotoInterp p = ifd.getPhotometricInterpretation();
      int samples = ifd.getSamplesPerPixel();
      core[s].rgb = samples > 1 || p == PhotoInterp.RGB;

      long numTileRows = ifd.getTilesPerColumn() - 1;
      long numTileCols = ifd.getTilesPerRow() - 1;

      int overlapX = overlaps[s * 2];
      int overlapY = overlaps[s * 2 + 1];

      core[s].sizeX = (int) (ifd.getImageWidth() - (numTileCols * overlapX));
      core[s].sizeY = (int) (ifd.getImageLength() - (numTileRows * overlapY));
      core[s].sizeZ = 1;
      core[s].sizeT = 1;
      core[s].sizeC = core[s].rgb ? samples : 1;
      core[s].littleEndian = ifd.isLittleEndian();
      core[s].indexed =
          p == PhotoInterp.RGB_PALETTE
              && (get8BitLookupTable() != null || get16BitLookupTable() != null);
      core[s].imageCount = 1;
      core[s].pixelType = ifd.getPixelType();
      core[s].metadataComplete = true;
      core[s].interleaved = false;
      core[s].falseColor = false;
      core[s].dimensionOrder = "XYCZT";
      core[s].thumbnail = s > 0;
    }

    // look for all of the other associated metadata files

    files = new ArrayList<String>();

    Location baseFile = new Location(currentId).getAbsoluteFile();
    Location parent = baseFile.getParentFile();
    String name = baseFile.getName();
    if (name.indexOf(".") >= 0) {
      name = name.substring(0, name.indexOf(".") + 1);
    }

    roiFile = new Location(parent, name + "ROI").getAbsolutePath();
    roiDrawFile = new Location(parent, name + "ROI-draw").getAbsolutePath();

    String[] list = parent.list(true);
    for (String f : list) {
      if (!f.equals(baseFile.getName())) {
        files.add(new Location(parent, f).getAbsolutePath());
      }
    }
  }