Rational[] rationals = (Rational[]) value; for (Rational rational : rationals) { stream.writeInt((int) rational.numerator()); stream.writeInt((int) rational.denominator()); case TIFF.TYPE_LONG: case TIFF.TYPE_SLONG: stream.writeInt(((Number) value).intValue()); break; case TIFF.TYPE_RATIONAL: case TIFF.TYPE_SRATIONAL: Rational rational = (Rational) value; stream.writeInt((int) rational.numerator()); stream.writeInt((int) rational.denominator()); break; case TIFF.TYPE_FLOAT:
private void writeFileHeader(int infoHeaderSize, int fileSize, boolean hasMasks) throws IOException { // 14 bytes imageOutput.writeShort('M' << 8 | 'B'); imageOutput.writeInt(fileSize + (hasMasks ? 16 : 0)); // File size (only known at this time if uncompressed!) imageOutput.writeShort(0); // Reserved imageOutput.writeShort(0); // Reserved imageOutput.writeInt(DIB.BMP_FILE_HEADER_SIZE + infoHeaderSize + (hasMasks ? 16 : 0)); // Offset to image data }
private void writeBody(ByteArrayOutputStream pImageData) throws IOException { imageOutput.writeInt(IFF.CHUNK_BODY); imageOutput.writeInt(pImageData.size()); // NOTE: This is much faster than imageOutput.write(pImageData.toByteArray()) // as the data array is not duplicated OutputStream adapter = IIOUtil.createStreamAdapter(imageOutput); try { pImageData.writeTo(adapter); } finally { adapter.close(); } if (pImageData.size() % 2 == 0) { imageOutput.writeByte(0); // PAD } imageOutput.flush(); }
/** * Creates the binary header for the raster file. * * <p>The space for the header of the rasterfile is created, filling the spaces with zeros. * After the compression the values will be rewritten * * @param rows number of rows that will be written. * @throws IOException if an error occurs while trying to write the header. */ private void createEmptyHeader(int rows) throws IOException { addressesOfRows = new long[rows + 1]; // the size of a long in C? imageOS.write(4); // write the addresses of the row begins. Since we don't know how // much // they will be compressed, they will be filled after the // compression for (int i = 0; i < rows + 1; i++) { imageOS.writeInt(0); } pointerInFilePosition = imageOS.getStreamPosition(); addressesOfRows[0] = pointerInFilePosition; }
public static void writePages(ImageOutputStream imageOutput, List<TIFFPage> pages) throws IOException { TIFFWriter exif = new TIFFWriter(); long nextPagePos = imageOutput.getStreamPosition(); if (nextPagePos == 0) { exif.writeTIFFHeader(imageOutput); nextPagePos = imageOutput.getStreamPosition(); imageOutput.writeInt(0); } else { // already has pages, so remember place of EOF to replace with // IFD offset nextPagePos -= 4; } for (TIFFPage tiffPage : pages) { long ifdOffset = tiffPage.write(imageOutput, exif); long tmp = imageOutput.getStreamPosition(); imageOutput.seek(nextPagePos); imageOutput.writeInt((int) ifdOffset); imageOutput.seek(tmp); nextPagePos = tmp; imageOutput.writeInt(0); } }
private void writeValueAt(final long dataOffset, final Object value, final short type, final ImageOutputStream stream) throws IOException { stream.writeInt(assertIntegerOffset(dataOffset)); long position = stream.getStreamPosition(); stream.seek(dataOffset); writeValueInline(value, type, stream); stream.seek(position); }
theCreatedFile.writeInt((int) rowaddresses[i]);
@Override public boolean write(final Directory directory, final ImageOutputStream stream) throws IOException { Validate.notNull(directory); Validate.notNull(stream); // TODO: Should probably validate that the directory contains only valid TIFF entries... // the writer will crash on non-Integer ids and unsupported types // TODO: Implement the above validation in IFD constructor? writeTIFFHeader(stream); if (directory instanceof CompoundDirectory) { CompoundDirectory compoundDirectory = (CompoundDirectory) directory; for (int i = 0; i < compoundDirectory.directoryCount(); i++) { writeIFD(compoundDirectory.getDirectory(i), stream, false); } } else { writeIFD(directory, stream, false); } // Offset to next IFD (EOF) stream.writeInt(0); return true; }
/** * Writes a 32-bit unsigned integer. * * @param v TODO * @throws java.io.IOException TODO */ public void writeLONG(long v) throws IOException { out.writeInt((int) v); }
imageOutput.writeInt((int) ifdPointer); imageOutput.seek(nextIFDPointerOffset); imageOutput.writeInt(0); // Update next IFD pointer later imageOutput.writeInt(0); // Update current IFD pointer later imageOutput.writeInt((int) ifdPointer); imageOutput.seek(nextIFDPointerOffset); imageOutput.writeInt(0); // Next IFD pointer updated later
@Override protected void writeHistograms(final ImageOutputStream ios) throws IOException { for (int i = 0; i < 4000; i += 1000) { for (int j = 0; j < 256; j++) { ios.writeInt(i + j); } } }
private void writeBox(IIOMetadataNode node) throws IOException { int type = Box.getTypeInt((String)Box.getAttribute(node, "Type")); int length = new Integer((String)Box.getAttribute(node, "Length")).intValue(); Box box = Box.createBox(type, node); otherLength += length; stream.writeInt(length); stream.writeInt(type); byte[] data = box.getContent(); stream.write(data, 0, data.length); }
private void writeBox(IIOMetadataNode node) throws IOException { int type = Box.getTypeInt((String)Box.getAttribute(node, "Type")); int length = new Integer((String)Box.getAttribute(node, "Length")).intValue(); Box box = Box.createBox(type, node); otherLength += length; stream.writeInt(length); stream.writeInt(type); byte[] data = box.getContent(); stream.write(data, 0, data.length); }
private void writeValueAt(final long dataOffset, final Object value, final short type, final ImageOutputStream stream) throws IOException { stream.writeInt(assertIntegerOffset(dataOffset)); long position = stream.getStreamPosition(); stream.seek(dataOffset); writeValueInline(value, type, stream); stream.seek(position); }