public void overwriteLastIFDOffset(RandomAccessInputStream raf) throws FormatException, IOException { if (raf == null) throw new FormatException("Output cannot be null"); TiffParser parser = new TiffParser(raf); long[] offsets = parser.getIFDOffsets(); out.seek(raf.getFilePointer() - (bigTiff ? 8 : 4)); writeIntValue(out, 0); }
public void overwriteLastIFDOffset(RandomAccessInputStream raf) throws FormatException, IOException { if (raf == null) throw new FormatException("Output cannot be null"); TiffParser parser = new TiffParser(raf); long[] offsets = parser.getIFDOffsets(); out.seek(raf.getFilePointer() - (bigTiff ? 8 : 4)); writeIntValue(out, 0); }
public void overwriteIFDOffset(RandomAccessInputStream raf, long offset, long nextPointer) throws FormatException, IOException { if (raf == null) { throw new FormatException("Input stream cannot be null"); } int bytesPerEntry = bigTiff ? TiffConstants.BIG_TIFF_BYTES_PER_ENTRY : TiffConstants.BYTES_PER_ENTRY; raf.seek(offset); long entries = bigTiff ? raf.readLong() : raf.readUnsignedShort(); long overwriteOffset = offset + bytesPerEntry * entries + (bigTiff ? 8 : 2); out.seek(overwriteOffset); writeIntValue(out, nextPointer); }
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 overwriteIFDOffset(RandomAccessInputStream raf, long offset, long nextPointer) throws FormatException, IOException { if (raf == null) { throw new FormatException("Input stream cannot be null"); } int bytesPerEntry = bigTiff ? TiffConstants.BIG_TIFF_BYTES_PER_ENTRY : TiffConstants.BYTES_PER_ENTRY; raf.seek(offset); long entries = bigTiff ? raf.readLong() : raf.readUnsignedShort(); long overwriteOffset = offset + bytesPerEntry * entries + (bigTiff ? 8 : 2); out.seek(overwriteOffset); writeIntValue(out, nextPointer); }
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(); }
@Test public void testOverwriteComment() throws FormatException, IOException { out.seek(0); tiffSaver.writeHeader(); tiffSaver.writeIFD(ifd, 0); tiffSaver.overwriteComment(in, "new comment"); assertTrue("new comment".equals(tiffParser.getComment())); }
/** * Seek to the given (x, y) coordinate of the image that starts at * the given offset. */ protected void seekToPlaneOffset(long baseOffset, int x, int y) throws IOException { out.seek(baseOffset); MetadataRetrieve r = getMetadataRetrieve(); int samples = getSamplesPerPixel(); int pixelType = FormatTools.pixelTypeFromString(r.getPixelsType(series).toString()); int bpp = FormatTools.getBytesPerPixel(pixelType); if (interleaved) bpp *= samples; try { int sizeX = getSizeX(); out.skipBytes(bpp * (y * sizeX + x)); } catch (FormatException e) { throw new IOException(e); } }
/** * Seek to the given (x, y) coordinate of the image that starts at * the given offset. */ protected void seekToPlaneOffset(long baseOffset, int x, int y) throws IOException { out.seek(baseOffset); MetadataRetrieve r = getMetadataRetrieve(); int samples = getSamplesPerPixel(); int pixelType = FormatTools.pixelTypeFromString(r.getPixelsType(series).toString()); int bpp = FormatTools.getBytesPerPixel(pixelType); if (interleaved) bpp *= samples; try { int sizeX = getSizeX(); out.skipBytes(bpp * (y * sizeX + x)); } catch (FormatException e) { throw new IOException(e); } }
/** * @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int) */ @Override public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { checkParams(no, buf, x, y, w, h); if (!isFullPlane(x, y, w, h)) { throw new FormatException( "APNGWriter does not yet support saving image tiles."); } MetadataRetrieve meta = getMetadataRetrieve(); int width = meta.getPixelsSizeX(series).getValue().intValue(); int height = meta.getPixelsSizeY(series).getValue().intValue(); out.seek(footerPointer); if (!initialized[series][no]) { writeFCTL(width, height); if (numFrames == 0) writePLTE(); initialized[series][no] = true; } writePixels(numFrames == 0 ? "IDAT" : "fdAT", buf, x, y, w, h); numFrames++; writeFooter(); }
/** * @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int) */ @Override public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { checkParams(no, buf, x, y, w, h); if (!isFullPlane(x, y, w, h)) { throw new FormatException( "APNGWriter does not yet support saving image tiles."); } MetadataRetrieve meta = getMetadataRetrieve(); int width = meta.getPixelsSizeX(series).getValue().intValue(); int height = meta.getPixelsSizeY(series).getValue().intValue(); out.seek(footerPointer); if (!initialized[series][no]) { writeFCTL(width, height); if (numFrames == 0) writePLTE(); initialized[series][no] = true; } writePixels(numFrames == 0 ? "IDAT" : "fdAT", buf, x, y, w, h); numFrames++; writeFooter(); }
out.seek(BYTE_COUNT_OFFSET);
private void writeFooter() throws IOException { footerPointer = out.getFilePointer(); // write IEND chunk out.writeInt(0); out.writeBytes("IEND"); out.writeInt(crc("IEND".getBytes(Constants.ENCODING))); // update frame count out.seek(numFramesPointer); out.writeInt(numFrames); out.skipBytes(4); byte[] b = new byte[12]; b[0] = 'a'; b[1] = 'c'; b[2] = 'T'; b[3] = 'L'; DataTools.unpackBytes(numFrames, b, 4, 4, false); DataTools.unpackBytes(0, b, 8, 4, false); out.writeInt(crc(b)); }
out.seek(BYTE_COUNT_OFFSET);
private void writeFooter() throws IOException { footerPointer = out.getFilePointer(); // write IEND chunk out.writeInt(0); out.writeBytes("IEND"); out.writeInt(crc("IEND".getBytes(Constants.ENCODING))); // update frame count out.seek(numFramesPointer); out.writeInt(numFrames); out.skipBytes(4); byte[] b = new byte[12]; b[0] = 'a'; b[1] = 'c'; b[2] = 'T'; b[3] = 'L'; DataTools.unpackBytes(numFrames, b, 4, 4, false); DataTools.unpackBytes(0, b, 8, 4, false); out.writeInt(crc(b)); }
@Test public void testOverwriteIFDValue() throws FormatException, IOException { out.seek(0); tiffSaver.setBigTiff(false); tiffSaver.writeHeader(); tiffSaver.writeIFD(ifd, 0); tiffSaver.overwriteIFDValue(in, 0, IFD.IMAGE_WIDTH, 1024); assertEquals(1024, tiffParser.getFirstIFD().getImageWidth()); }
/** 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); } }
Object array = DataTools.makeDataArray(buf, bpp, fp, little); out.seek(out.length()); if (array instanceof byte[]) { writePlane(varName, (byte[]) array, w, h);
Object array = DataTools.makeDataArray(buf, bpp, fp, little); out.seek(out.length()); if (array instanceof byte[]) { writePlane(varName, (byte[]) array, w, h);