Exemple #1
0
  // takes the reader lock
  BufferedImage getAssociatedImage(String name) throws IOException {
    Lock rl = lock.readLock();
    rl.lock();
    try {
      checkDisposed();

      long dim[] = new long[2];
      OpenSlideJNI.openslide_get_associated_image_dimensions(osr, name, dim);
      checkError();
      if (dim[0] == -1) {
        // non-terminal error
        throw new IOException("Failure reading associated image");
      }

      BufferedImage img =
          new BufferedImage((int) dim[0], (int) dim[1], BufferedImage.TYPE_INT_ARGB_PRE);

      int data[] = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();

      OpenSlideJNI.openslide_read_associated_image(osr, name, data);
      checkError();
      return img;
    } finally {
      rl.unlock();
    }
  }
Exemple #2
0
  // takes the reader lock
  public void paintRegionARGB(int dest[], long x, long y, int level, int w, int h)
      throws IOException {
    if ((long) w * (long) h > dest.length) {
      throw new ArrayIndexOutOfBoundsException(
          "Size of data (" + dest.length + ") is less than w * h");
    }

    if (w < 0 || h < 0) {
      throw new IllegalArgumentException("w and h must be nonnegative");
    }

    Lock rl = lock.readLock();
    rl.lock();
    try {
      checkDisposed();
      OpenSlideJNI.openslide_read_region(osr, dest, x, y, level, w, h);
      checkError();
    } finally {
      rl.unlock();
    }
  }
Exemple #3
0
  public OpenSlide(File file) throws IOException {
    if (!file.exists()) {
      throw new FileNotFoundException(file.toString());
    }

    // vartika on 5 august
    filePath = file.getPath();

    osr = OpenSlideJNI.openslide_open(file.getPath());

    if (osr == 0) {
      throw new IOException(file + ": Not a file that OpenSlide can recognize");
    }
    // dispose on error, we are in the constructor
    try {
      checkError();
    } catch (IOException e) {
      dispose();
      throw e;
    }

    // store level count
    levelCount = OpenSlideJNI.openslide_get_level_count(osr);

    // store dimensions
    levelWidths = new long[levelCount];
    levelHeights = new long[levelCount];
    levelDownsamples = new double[levelCount];

    for (int i = 0; i < levelCount; i++) {
      long dim[] = new long[2];
      OpenSlideJNI.openslide_get_level_dimensions(osr, i, dim);
      levelWidths[i] = dim[0];
      levelHeights[i] = dim[1];
      levelDownsamples[i] = OpenSlideJNI.openslide_get_level_downsample(osr, i);
    }

    // properties
    HashMap<String, String> props = new HashMap<String, String>();
    for (String s : OpenSlideJNI.openslide_get_property_names(osr)) {
      props.put(s, OpenSlideJNI.openslide_get_property_value(osr, s));
    }

    properties = Collections.unmodifiableMap(props);

    // associated images
    HashMap<String, AssociatedImage> associated = new HashMap<String, AssociatedImage>();
    for (String s : OpenSlideJNI.openslide_get_associated_image_names(osr)) {
      associated.put(s, new AssociatedImage(s, this));
    }

    associatedImages = Collections.unmodifiableMap(associated);

    // store info for hash and equals
    canonicalFile = file.getCanonicalFile();
    String quickhash1 = getProperties().get(PROPERTY_NAME_QUICKHASH1);
    if (quickhash1 != null) {
      hashCodeVal = (int) Long.parseLong(quickhash1.substring(0, 8), 16);
    } else {
      hashCodeVal = canonicalFile.hashCode();
    }

    // dispose on error, we are in the constructor
    try {
      checkError();
    } catch (IOException e) {
      dispose();
      throw e;
    }
  }