/** * Write the given value to the given RandomAccessOutputStream. * If the 'bigTiff' flag is set, then the value will be written as an 8 byte * long; otherwise, it will be written as a 4 byte integer. */ private void writeIntValue(RandomAccessOutputStream out, long offset) throws IOException { if (bigTiff) { out.writeLong(offset); } else { out.writeInt((int) offset); } }
/** * Write the given value to the given RandomAccessOutputStream. * If the 'bigTiff' flag is set, then the value will be written as an 8 byte * long; otherwise, it will be written as a 4 byte integer. */ private void writeIntValue(RandomAccessOutputStream out, long offset) throws IOException { if (bigTiff) { out.writeLong(offset); } else { out.writeInt((int) offset); } }
public void writeIFD(IFD ifd, long nextOffset) throws FormatException, IOException { TreeSet<Integer> keys = new TreeSet<Integer>(ifd.keySet()); int keyCount = keys.size(); if (ifd.containsKey(new Integer(IFD.LITTLE_ENDIAN))) keyCount--; if (ifd.containsKey(new Integer(IFD.BIG_TIFF))) keyCount--; if (ifd.containsKey(new Integer(IFD.REUSE))) keyCount--; long fp = out.getFilePointer(); int bytesPerEntry = bigTiff ? TiffConstants.BIG_TIFF_BYTES_PER_ENTRY : TiffConstants.BYTES_PER_ENTRY; int ifdBytes = (bigTiff ? 16 : 6) + bytesPerEntry * keyCount; if (bigTiff) out.writeLong(keyCount); else out.writeShort(keyCount); ByteArrayHandle extra = new ByteArrayHandle(); RandomAccessOutputStream extraStream = new RandomAccessOutputStream(extra); for (Integer key : keys) { if (key.equals(IFD.LITTLE_ENDIAN) || key.equals(IFD.BIG_TIFF) || key.equals(IFD.REUSE)) continue; Object value = ifd.get(key); writeIFDValue(extraStream, ifdBytes + fp, key.intValue(), value); } if (bigTiff) out.seek(out.getFilePointer()); writeIntValue(out, nextOffset); out.write(extra.getBytes(), 0, (int) extra.length()); extraStream.close(); }
public void writeIFD(IFD ifd, long nextOffset) throws FormatException, IOException { TreeSet<Integer> keys = new TreeSet<Integer>(ifd.keySet()); int keyCount = keys.size(); if (ifd.containsKey(new Integer(IFD.LITTLE_ENDIAN))) keyCount--; if (ifd.containsKey(new Integer(IFD.BIG_TIFF))) keyCount--; if (ifd.containsKey(new Integer(IFD.REUSE))) keyCount--; long fp = out.getFilePointer(); int bytesPerEntry = bigTiff ? TiffConstants.BIG_TIFF_BYTES_PER_ENTRY : TiffConstants.BYTES_PER_ENTRY; int ifdBytes = (bigTiff ? 16 : 6) + bytesPerEntry * keyCount; if (bigTiff) out.writeLong(keyCount); else out.writeShort(keyCount); ByteArrayHandle extra = new ByteArrayHandle(); RandomAccessOutputStream extraStream = new RandomAccessOutputStream(extra); for (Integer key : keys) { if (key.equals(IFD.LITTLE_ENDIAN) || key.equals(IFD.BIG_TIFF) || key.equals(IFD.REUSE)) continue; Object value = ifd.get(key); writeIFDValue(extraStream, ifdBytes + fp, key.intValue(), value); } if (bigTiff) out.seek(out.getFilePointer()); writeIntValue(out, nextOffset); out.write(extra.getBytes(), 0, (int) extra.length()); extraStream.close(); }
/** Writes the TIFF file header. */ public void writeHeader() throws IOException { // write endianness indicator out.seek(0); if (isLittleEndian()) { out.writeByte(TiffConstants.LITTLE); out.writeByte(TiffConstants.LITTLE); } else { out.writeByte(TiffConstants.BIG); out.writeByte(TiffConstants.BIG); } // write magic number if (bigTiff) { out.writeShort(TiffConstants.BIG_TIFF_MAGIC_NUMBER); } else out.writeShort(TiffConstants.MAGIC_NUMBER); // write the offset to the first IFD // for vanilla TIFFs, 8 is the offset to the first IFD // for BigTIFFs, 8 is the number of bytes in an offset if (bigTiff) { out.writeShort(8); out.writeShort(0); // write the offset to the first IFD for BigTIFF files out.writeLong(16); } else { out.writeInt(8); } }
/** Writes the TIFF file header. */ public void writeHeader() throws IOException { // write endianness indicator out.seek(0); if (isLittleEndian()) { out.writeByte(TiffConstants.LITTLE); out.writeByte(TiffConstants.LITTLE); } else { out.writeByte(TiffConstants.BIG); out.writeByte(TiffConstants.BIG); } // write magic number if (bigTiff) { out.writeShort(TiffConstants.BIG_TIFF_MAGIC_NUMBER); } else out.writeShort(TiffConstants.MAGIC_NUMBER); // write the offset to the first IFD // for vanilla TIFFs, 8 is the offset to the first IFD // for BigTIFFs, 8 is the number of bytes in an offset if (bigTiff) { out.writeShort(8); out.writeShort(0); // write the offset to the first IFD for BigTIFF files out.writeLong(16); } else { out.writeInt(8); } }