Esempio n. 1
0
  @Override
  public Raster readRaster(int frameIndex, ImageReadParam param) throws IOException {
    readMetadata();
    checkIndex(frameIndex);

    if (decompressor != null) {
      decompressor.setInput(iisOfFrame(frameIndex));

      if (LOG.isDebugEnabled()) LOG.debug("Start decompressing frame #" + (frameIndex + 1));
      Raster wr =
          pmi.decompress() == pmi && decompressor.canReadRaster()
              ? decompressor.readRaster(0, decompressParam(param))
              : decompressor.read(0, decompressParam(param)).getRaster();
      if (LOG.isDebugEnabled()) LOG.debug("Finished decompressing frame #" + (frameIndex + 1));
      return wr;
    }
    iis.seek(pixeldata.offset + frameIndex * frameLength);
    WritableRaster wr = Raster.createWritableRaster(createSampleModel(dataType, banded), null);
    DataBuffer buf = wr.getDataBuffer();
    if (buf instanceof DataBufferByte) {
      byte[][] data = ((DataBufferByte) buf).getBankData();
      for (byte[] bs : data) iis.readFully(bs);
      if (pixeldata.bigEndian && pixeldataVR.vr == VR.OW) ByteUtils.swapShorts(data);
    } else {
      short[] data = ((DataBufferUShort) buf).getData();
      iis.readFully(data, 0, data.length);
    }
    return wr;
  }