/** * @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int) */ @Override public void saveBytes(int no, byte[] buf, IFD ifd, int x, int y, int w, int h) throws FormatException, IOException { super.saveBytes(no, buf, ifd, x, y, w, h); int index = no; while (imageLocations[series][index] != null) { if (index < imageLocations[series].length - 1) { index++; } else { break; } } imageLocations[series][index] = currentId; }
/** * @see loci.formats.IFormatWriter#saveBytes(int, byte[], int, int, int, int) */ @Override public void saveBytes(int no, byte[] buf, IFD ifd, int x, int y, int w, int h) throws FormatException, IOException { super.saveBytes(no, buf, ifd, x, y, w, h); int index = no; while (imageLocations[series][index] != null) { if (index < imageLocations[series].length - 1) { index++; } else { break; } } imageLocations[series][index] = currentId; }
/** * Saves the given image to the specified (possibly already open) file. * The IFD hashtable allows specification of TIFF parameters such as bit * depth, compression and units. */ public void saveBytes(int no, byte[] buf, IFD ifd) throws IOException, FormatException { int w = getSizeX(); int h = getSizeY(); saveBytes(no, buf, ifd, 0, 0, w, h); }
/** * Saves the given image to the specified (possibly already open) file. * The IFD hashtable allows specification of TIFF parameters such as bit * depth, compression and units. */ public void saveBytes(int no, byte[] buf, IFD ifd) throws IOException, FormatException { int w = getSizeX(); int h = getSizeY(); saveBytes(no, buf, ifd, 0, 0, w, h); }
@Override public void run() { byte[] tile = new byte[tileWidth * tileHeight * bytesPerPixel]; ByteBuffer.wrap(tile).asShortBuffer().put(0, (short) tileNumber); hashDigests.put(tileNumber, TestTools.md5(tile)); int planeNumber = FormatTools.getIndex( "XYZCT", SIZE_Z, SIZE_C, SIZE_T, SIZE_Z * SIZE_C * SIZE_T, z, c, t); IFD ifd; synchronized (ifds) { if (!ifds.containsKey(planeNumber)) { ifd = new IFD(); ifd.put(IFD.TILE_WIDTH, TILE_WIDTH); ifd.put(IFD.TILE_LENGTH, TILE_HEIGHT); ifds.put(planeNumber, ifd); } ifd = ifds.get(planeNumber); } try { writer.saveBytes(planeNumber, tile, ifd, x, y, tileWidth, tileHeight); } catch (Exception e) { LOGGER.error("Exception while writing tile", e); throw new RuntimeException(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 { IFD ifd = new IFD(); if (!sequential) { try (RandomAccessInputStream stream = new RandomAccessInputStream(currentId)) { TiffParser parser = new TiffParser(stream); long[] ifdOffsets = parser.getIFDOffsets(); if (no < ifdOffsets.length) { ifd = parser.getIFD(ifdOffsets[no]); } saveBytes(no, buf, ifd, x, y, w, h); } } else { saveBytes(no, buf, ifd, x, y, w, h); } }
/** * @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 { IFD ifd = new IFD(); if (!sequential) { try (RandomAccessInputStream stream = new RandomAccessInputStream(currentId)) { TiffParser parser = new TiffParser(stream); long[] ifdOffsets = parser.getIFDOffsets(); if (no < ifdOffsets.length) { ifd = parser.getIFD(ifdOffsets[no]); } saveBytes(no, buf, ifd, x, y, w, h); } } else { saveBytes(no, buf, ifd, x, y, w, h); } }
@Test(dataProvider = "bigTiffSuffixes") public void testSetBigTiffSuffixes(String suffix) throws IOException, FormatException { //Test that no exception is thrown when bigTiff is set automatically due to size writer.setMetadataRetrieve(metadata); ((TiffWriterMock)writer).createOutputBuffer(true); long length = 4294967296L; ((TiffWriterMock)writer).setBufferLength(length); writer.setId("test." + suffix); boolean thrown = false; try { writer.saveBytes(0, buf, ifd); } catch(FormatException e) { thrown = true; } if (suffix.contains("tif")) { assertEquals(true,thrown); } else { assertEquals(false,thrown); } }
@Test public void testSetBigTiffFileTooLarge() throws IOException, FormatException { // Test that no exception is thrown while below the big tiff limit (2147483648L) // Exception is thrown when size is out.length() + 2 * (width * height * c * bytesPerPixel) writer.setMetadataRetrieve(metadata); ((TiffWriterMock)writer).createOutputBuffer(true); long length = 4294967296L - (buf.length * 4); ((TiffWriterMock)writer).setBufferLength(length); writer.setId("test.tiff"); writer.saveBytes(0, buf, ifd); //Test format exception is thrown after the big tiff limit (2147483648L) boolean thrown = false; try { writer.saveBytes(1, buf, ifd); } catch(FormatException e) { if (e.getMessage().contains("File is too large; call setBigTiff(true)")) { thrown = true; } } assert(thrown); }
@Test public void testSetBigTiff() throws IOException, FormatException { //Test that no exception is thrown after setting big tiff writer.setMetadataRetrieve(metadata); ((TiffWriterMock)writer).createOutputBuffer(true); long length = 4294967296L - (buf.length * 2); ((TiffWriterMock)writer).setBufferLength(length); writer.setBigTiff(true); writer.setId("test.tiff"); writer.saveBytes(0, buf, ifd); }
@Test public void testSetBigTiffAutomatic() throws IOException, FormatException { //Test that no exception is thrown when bigTiff is set automatically due to size metadata.setPixelsSizeT(new PositiveInteger(1000), 0); writer.setMetadataRetrieve(metadata); ((TiffWriterMock)writer).createOutputBuffer(true); long length = 4294967296L; ((TiffWriterMock)writer).setBufferLength(length); writer.setId("test.tiff"); writer.saveBytes(0, buf, ifd); }
tile = reader.openBytes(k, x, y, w, h); tileMD5s[s][k][(i * n) + j] = TestTools.md5(tile); writer.saveBytes(k, tile, ifd, x, y, w, h);
writer.saveBytes(0, tile, ifd, x, y, w, h);
public static Plane writeImage(String file, int tileSize, boolean littleEndian, boolean interleaved, int rgbChannels, int seriesCount, int sizeT, String compression, int pixelType, boolean bigTiff) throws Exception { TiffWriter writer = new TiffWriter(); String pixelTypeString = FormatTools.getPixelTypeString(pixelType); writer.setMetadataRetrieve(createMetadata(pixelTypeString, rgbChannels, seriesCount, littleEndian, sizeT)); writer.setCompression(compression); writer.setInterleaved(interleaved); writer.setBigTiff(bigTiff); if (tileSize != 0) { writer.setTileSizeX(tileSize); writer.setTileSizeY(tileSize); } writer.setId(file); int bytes = FormatTools.getBytesPerPixel(pixelType); byte[] plane = getPlane(PLANE_WIDTH, PLANE_HEIGHT, bytes * rgbChannels); Plane originalPlane = new Plane(plane, littleEndian, !writer.isInterleaved(), rgbChannels, FormatTools.getPixelTypeString(pixelType)); for (int s=0; s<seriesCount; s++) { writer.setSeries(s); for (int t=0; t<sizeT; t++) { writer.saveBytes(t, plane); } } writer.close(); return originalPlane; }