예제 #1
0
 /*
  * Reads and returns an array of bytes from the file.
  *
  */
 public byte[] readBytes(TiffIFDEntry entry) throws IOException {
   byte[] bytes = new byte[(int) entry.count];
   ByteBuffer buff = ByteBuffer.wrap(bytes);
   this.theChannel.position(entry.asOffset());
   this.theChannel.read(buff);
   return bytes;
 }
예제 #2
0
  /*
   * Reads a ColorMap.
   *
   */
  public byte[][] readColorMap(TiffIFDEntry colorMapEntry) throws IOException {
    if (null == colorMapEntry) {
      String message = Logging.getMessage("GeotiffReader.MissingColormap");
      Logging.logger().severe(message);
      throw new IOException(message);
    }

    // NOTE: TIFF gives total number of cmap values, which is 3 times the size of cmap table...
    // CLUT is composed of shorts, but we'll read as bytes (thus, the factor of 2)...
    int numEntries = (int) colorMapEntry.count / 3;
    byte[][] tmp = new byte[3][numEntries * 2];

    this.theChannel.position(colorMapEntry.asLong());

    // Unroll the loop; the TIFF spec says "...3 is the number of the counting, and the counting
    // shall be 3..."
    // TIFF spec also says that all red values precede all green, which precede all blue.
    ByteBuffer buff = ByteBuffer.wrap(tmp[0]);
    this.theChannel.read(buff);
    buff = ByteBuffer.wrap(tmp[1]);
    this.theChannel.read(buff);
    buff = ByteBuffer.wrap(tmp[2]);
    this.theChannel.read(buff);

    // TIFF gives a ColorMap composed of unsigned shorts. Java's IndexedColorModel wants unsigned
    // bytes.
    // Something's got to give somewhere...we'll do our best.
    byte[][] cmap = new byte[3][numEntries];
    for (int i = 0; i < 3; i++) {
      buff = ByteBuffer.wrap(tmp[i]);
      buff.order(this.getByteOrder());
      for (int j = 0; j < numEntries; j++) {
        cmap[i][j] = (byte) (0x00ff & buff.getShort());
      }
    }

    return cmap;
  }