public void writeTIFFHeader(final ImageOutputStream stream) throws IOException { // Header ByteOrder byteOrder = stream.getByteOrder(); stream.writeShort(byteOrder == ByteOrder.BIG_ENDIAN ? TIFF.BYTE_ORDER_MARK_BIG_ENDIAN : TIFF.BYTE_ORDER_MARK_LITTLE_ENDIAN); stream.writeShort(42); }
case TIFF.TYPE_SHORT: case TIFF.TYPE_SSHORT: stream.writeShort(((Number) value).intValue()); break; case TIFF.TYPE_LONG:
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 writeValue(final ImageOutputStream stream, final Object value) throws IOException { if (value instanceof String) { byte[] data = ((String) value).getBytes(StandardCharsets.UTF_8); stream.writeShort(data.length); stream.write(data); } else if (value instanceof byte[]) { byte[] data = (byte[]) value; stream.writeShort(data.length); stream.write(data); } else if (value instanceof Integer) { // TODO: Need to know types from tag stream.writeShort(2); stream.writeShort((Integer) value); } } }
private void writeSOF0(ImageOutputStream outputStream, int bands, int width, int height, int subsampling) throws IOException { outputStream.writeShort(JPEG.SOF0); // TODO: Use correct process for data outputStream.writeShort(2 + 6 + 3 * bands); // SOF0 len outputStream.writeByte(8); // bits TODO: Consult raster/transfer type or BitsPerSample for 12/16 bits support outputStream.writeShort(height); // height outputStream.writeShort(width); // width outputStream.writeByte(bands); // Number of components for (int comp = 0; comp < bands; comp++) { outputStream.writeByte(comp); // Component id outputStream.writeByte(comp == 0 ? subsampling : 0x11); // h/v subsampling outputStream.writeByte(comp); // Q table selector TODO: Consider merging if tables are equal, correct selection if only 1 or 2 valid tables are contained } }
private void writeICOHeader() throws IOException { if (imageOutput.getStreamPosition() != 0) { throw new IllegalStateException("Stream already written to"); } imageOutput.writeShort(0); imageOutput.writeShort(DIB.TYPE_ICO); imageOutput.flushBefore(imageOutput.getStreamPosition()); }
imageOutput.writeShort(0); imageOutput.writeShort(0); imageOutput.writeShort(0); imageOutput.writeShort(pImage.getHeight()); imageOutput.writeShort(pImage.getWidth()); imageOutput.writeShort(PICT.OP_VERSION); imageOutput.writeShort(PICT.OP_VERSION_2); imageOutput.writeShort(PICT.OP_HEADER_OP); imageOutput.writeShort(PICT.MAC_DEFAULT_DPI); imageOutput.writeShort(0); imageOutput.writeShort(PICT.MAC_DEFAULT_DPI); imageOutput.writeShort(0); imageOutput.writeShort(0); imageOutput.writeShort(0); imageOutput.writeShort(pImage.getHeight()); imageOutput.writeShort(pImage.getWidth()); imageOutput.writeShort(PICT.OP_DEF_HILITE); imageOutput.writeShort(PICT.OP_CLIP_RGN); imageOutput.writeShort(10); imageOutput.writeShort(0); imageOutput.writeShort(0); imageOutput.writeShort(pImage.getHeight());
private void writeSOS(ImageOutputStream outputStream, int bands) throws IOException { outputStream.writeShort(JPEG.SOS); outputStream.writeShort(6 + 2 * bands); // SOS length outputStream.writeByte(bands); // Num comp for (int component = 0; component < bands; component++) { outputStream.writeByte(component); // Comp id outputStream.writeByte(component == 0 ? component : 0x10 + (component & 0xf)); // dc/ac selector TODO: correct selection if only 1 or 2 valid tables are contained } outputStream.writeByte(0); // Spectral selection start outputStream.writeByte(0); // Spectral selection end outputStream.writeByte(0); // Approx high & low }
private void writePICTTrailer() throws IOException { // Write out end opcode. Be sure to be word-aligned. long length = imageOutput.length(); if (length == -1) { throw new IIOException("Cannot write trailer without knowing length"); } if ((length & 1) > 0) { imageOutput.writeByte(0); } imageOutput.writeShort(PICT.OP_END_OF_PICTURE); }
@Override public void prepareWriteSequence(final IIOMetadata streamMetadata) throws IOException { assertOutput(); if (sequenceIndex >= 0) { throw new IllegalStateException("writeSequence already started"); } writeICOHeader(); // Count: Needs to be updated for each new image imageOutput.writeShort(0); sequenceIndex = 0; // TODO: Allow passing the initial size of the directory in the stream metadata? // - as this is much more efficient than growing... // How do we update the "image directory" containing "image entries", // and which must be written *before* the image data? // - Allocate a block of N * 16 bytes // - If image count % N > N, we need to move the first image backwards in the file and allocate another N items... imageOutput.write(new byte[INITIAL_ENTRY_COUNT * ENTRY_SIZE]); // Allocate room for 8 entries for now }
@Override public void writeHeader(final IIOImage image, final ImageWriterSpi provider) throws IOException { // Write PAM magic imageOutput.writeShort(PNM.PAM); imageOutput.write('\n'); // Comments writeComments(image.getMetadata(), provider); // Write width/height and number of channels imageOutput.write(String.format("WIDTH %s\nHEIGHT %s\n", getWidth(image), getHeight(image)).getBytes(UTF8)); imageOutput.write(String.format("DEPTH %s\n", getNumBands(image)).getBytes(UTF8)); // TODO: maxSample (8 or16 bit) imageOutput.write(String.format("MAXVAL %s\n", getMaxVal(image)).getBytes(UTF8)); // TODO: Determine tuple type based on input color model and image data TupleType tupleType = getNumBands(image) > 3 ? TupleType.RGB_ALPHA : TupleType.RGB; imageOutput.write(String.format("TUPLTYPE %s\nENDHDR\n", tupleType).getBytes(UTF8)); } }
@Override public void writeHeader(final IIOImage image, final ImageWriterSpi provider) throws IOException { // Write P4/P5/P6 magic (Support only RAW formats for now; if we are to support PLAIN formats, pass parameter) // TODO: Determine PBM, PBM or PPM based on input color model and image data? short type = PNM.PPM; imageOutput.writeShort(type); imageOutput.write('\n'); // Comments writeComments(image.getMetadata(), provider); // Dimensions (width/height) imageOutput.write(String.format("%s %s\n", getWidth(image), getHeight(image)).getBytes(HeaderWriter.UTF8)); // MaxSample if (type != PNM.PBM) { imageOutput.write(String.format("%s\n", getMaxVal(image)).getBytes(HeaderWriter.UTF8)); } } }
imageOutput.writeShort(bytes.size());
imageOutput.writeShort(bytes.size());
@Override public boolean write(final Directory directory, final ImageOutputStream stream) throws IOException { notNull(directory, "directory"); notNull(stream, "stream"); // TODO: Make sure we always write application record version (2.00) // TODO: Write encoding UTF8? for (Entry entry : directory) { int tag = (Integer) entry.getIdentifier(); Object value = entry.getValue(); if (IPTC.Tags.isArray((short) tag)) { Object[] values = (Object[]) value; for (Object v : values) { stream.write(0x1c); stream.writeShort(tag); writeValue(stream, v); } } else { stream.write(0x1c); stream.writeShort(tag); writeValue(stream, value); } } return false; }
imageOutput.writeShort(sequenceIndex + 1);
outputStream.writeShort(JPEG.SOI); writeSOF0(outputStream, bands, c, r, subsampling); writeData(stream, outputStream, offsets[i], byteCounts[i]); outputStream.writeShort(JPEG.EOI); outputStream.writeShort(JPEG.SOI); writeSOF0(outputStream, bands, c, r, subsampling); writeSOS(outputStream, bands); writeData(stream, outputStream, offsets[i], byteCounts[i]); outputStream.writeShort(JPEG.EOI);
stream.writeShort(ordered.size()); stream.writeShort((Integer) entry.getIdentifier()); stream.writeShort(getType(entry));
private void writePICTTrailer() throws IOException { // Write out end opcode. Be sure to be word-aligned. long length = imageOutput.length(); if (length == -1) { throw new IIOException("Cannot write trailer without knowing length"); } if ((length & 1) > 0) { imageOutput.writeByte(0); } imageOutput.writeShort(PICT.OP_END_OF_PICTURE); }
private void writeRecordData(final ImageOutputStream ios) throws IOException { BaseRecordTest.writeRecordData(ios); ios.writeInt(1234); // prefixDataLineNumber // B4 ios.writeInt(2345); // ccdUnitNumber // B4 ios.writeInt(3456); // scanStartTimeMillisAtDay // B4 ios.writeShort(4567); // scanStartTimeMicros // B2 ios.writeInt(5678); // numLeftDummyPixels // B4 ios.writeInt(6789); // numRightDummyPixels // B4 CeosTestHelper.writeBlanks(ios, BaseRecordTest.RECORD_LENGTH - 34); }