@Override public void setId(String id) throws FormatException, IOException { log.debug("setId(" + id + ")"); super.setId(id); }
@Override public void setId(String id) throws FormatException, IOException { if (id.equals(currentId)) return; super.setId(id); if (imageLocations == null) { MetadataRetrieve r = getMetadataRetrieve(); imageLocations = new String[r.getImageCount()][]; for (int i=0; i<imageLocations.length; i++) { setSeries(i); imageLocations[i] = new String[planeCount()]; } setSeries(0); } }
@Override public void setId(String id) throws FormatException, IOException { if (id.equals(currentId)) return; super.setId(id); if (imageLocations == null) { MetadataRetrieve r = getMetadataRetrieve(); imageLocations = new String[r.getImageCount()][]; for (int i=0; i<imageLocations.length; i++) { setSeries(i); imageLocations[i] = new String[planeCount()]; } setSeries(0); } }
@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 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); }
@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); }
/** * Initializes the writer. * @param output The file where to write the compressed data. * @param compression The compression to use. * @param bigTiff Pass <code>true</code> to set the <code>bigTiff</code> flag, * <code>false</code> otherwise. * @return See above. * @throws Exception Thrown if an error occurred. */ private TiffWriter initializeWriter(String output, String compression, boolean bigTiff) throws Exception { IMetadata newMetadata = service.createOMEXMLMetadata(); MetadataConverter.convertMetadata(metadata, newMetadata); TiffWriter writer = new TiffWriter(); writer.setMetadataRetrieve(newMetadata); writer.setCompression(compression); writer.setWriteSequentially(true); writer.setInterleaved(false); writer.setBigTiff(bigTiff); writer.setId(output); return writer; }
writer.setInterleaved(true); writer.setBigTiff(bigTiff); writer.setId(output); bytesPerPixel = FormatTools.getBytesPerPixel(PIXEL_TYPE);
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; }