/** 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); } }
out.writeShort(0); // version out.writeShort(0); // flags out.writeShort(0); // not sure what this is out.writeInt(0); // preview duration out.writeInt(0); // preview time out.writeShort(0); // version out.writeShort(15); // flags out.writeShort(0); // reserved out.writeInt(0); // unknown out.writeShort(0); // reserved out.writeShort(0); // version out.writeShort(0); // flags out.writeInt(1); // number of entries in the table out.writeShort(0); // time out.writeInt(1); // rate out.writeShort(0); // unknown out.writeShort(0); // version out.writeShort(0); // flags out.writeShort(0); // language out.writeShort(0); // quality
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(); }
out.writeShort(0); // version out.writeShort(0); // flags out.writeShort(0); // not sure what this is out.writeInt(0); // preview duration out.writeInt(0); // preview time out.writeShort(0); // version out.writeShort(15); // flags out.writeShort(0); // reserved out.writeInt(0); // unknown out.writeShort(0); // reserved out.writeShort(0); // version out.writeShort(0); // flags out.writeInt(1); // number of entries in the table out.writeShort(0); // time out.writeInt(1); // rate out.writeShort(0); // unknown out.writeShort(0); // version out.writeShort(0); // flags out.writeShort(0); // language out.writeShort(0); // quality
int q = Integer.parseInt(t.nextToken().trim()); if (getPixelType() == FormatTools.UINT16) { out.writeShort(q);
int q = Integer.parseInt(t.nextToken().trim()); if (getPixelType() == FormatTools.UINT16) { out.writeShort(q);
out.writeShort(tag); // tag if (value instanceof short[]) { short[] q = (short[]) value; out.writeShort(IFDType.BYTE.getCode()); writeIntValue(out, q.length); if (q.length <= dataLength) { out.writeShort(IFDType.ASCII.getCode()); // type writeIntValue(out, q.length + 1); if (q.length < dataLength) { out.writeShort(IFDType.SHORT.getCode()); // type writeIntValue(out, q.length); if (q.length <= dataLength / 2) { for (int i=0; i<q.length; i++) { out.writeShort(q[i]); // value(s) out.writeShort(0); // padding writeIntValue(out, offset + extraOut.length()); for (int i=0; i<q.length; i++) { extraOut.writeShort(q[i]); // values out.writeShort(type); writeIntValue(out, q.length); out.writeShort(IFDType.RATIONAL.getCode()); // type writeIntValue(out, q.length); if (bigTiff && q.length == 1) {
out.writeShort(tag); // tag if (value instanceof short[]) { short[] q = (short[]) value; out.writeShort(IFDType.BYTE.getCode()); writeIntValue(out, q.length); if (q.length <= dataLength) { out.writeShort(IFDType.ASCII.getCode()); // type writeIntValue(out, q.length + 1); if (q.length < dataLength) { out.writeShort(IFDType.SHORT.getCode()); // type writeIntValue(out, q.length); if (q.length <= dataLength / 2) { for (int i=0; i<q.length; i++) { out.writeShort(q[i]); // value(s) out.writeShort(0); // padding writeIntValue(out, offset + extraOut.length()); for (int i=0; i<q.length; i++) { extraOut.writeShort(q[i]); // values out.writeShort(type); writeIntValue(out, q.length); out.writeShort(IFDType.RATIONAL.getCode()); // type writeIntValue(out, q.length); if (bigTiff && q.length == 1) {
out.writeShort(newType); writeIntValue(out, newCount); writeIntValue(out, newOffset);
out.writeShort(newType); writeIntValue(out, newCount); writeIntValue(out, newOffset);
out.writeShort((short) 0); // left out.writeShort((short) 0); // top out.writeShort((short) 0); // right out.writeShort((short) 0); // bottom out.writeShort(1); out.writeShort((short) bitsPerPixel); out.writeInt((int) PADDING_BYTES); for (int i=0; i<PADDING_BYTES/2; i++) { out.writeShort((short) 0);
out.writeShort((short) 0); // left out.writeShort((short) 0); // top out.writeShort((short) 0); // right out.writeShort((short) 0); // bottom out.writeShort(1); out.writeShort((short) bitsPerPixel); out.writeInt((int) PADDING_BYTES); for (int i=0; i<PADDING_BYTES/2; i++) { out.writeShort((short) 0);