use of loci.formats.in.TiffReader in project bioformats by openmicroscopy.
the class TiffWriterTest method testSaveBytesTiling.
@Test(dataProvider = "tiling")
public void testSaveBytesTiling(int tileSize, boolean littleEndian, boolean interleaved, int rgbChannels, int seriesCount, int sizeT, String compression, int pixelType, boolean bigTiff) throws Exception {
if (percentageOfTilingTests == 0)
return;
File tmp = File.createTempFile("tiffWriterTest_Tiling", ".tiff");
tmp.deleteOnExit();
Plane originalPlane = WriterUtilities.writeImage(tmp, tileSize, littleEndian, interleaved, rgbChannels, seriesCount, sizeT, compression, pixelType, bigTiff);
TiffReader reader = new TiffReader();
reader.setId(tmp.getAbsolutePath());
int expectedTileSize = tileSize;
if (tileSize < TILE_GRANULARITY) {
expectedTileSize = TILE_GRANULARITY;
} else {
expectedTileSize = Math.round((float) tileSize / TILE_GRANULARITY) * TILE_GRANULARITY;
}
IFD tileIFd = reader.getIFDs().get(0);
assertEquals(tileIFd.getIFDIntValue(IFD.TILE_LENGTH), expectedTileSize);
assertEquals(tileIFd.getIFDIntValue(IFD.TILE_WIDTH), expectedTileSize);
WriterUtilities.checkImage(reader, originalPlane, interleaved, rgbChannels, seriesCount, sizeT, compression);
tmp.delete();
reader.close();
}
use of loci.formats.in.TiffReader in project bioformats by openmicroscopy.
the class OMETiffWriterLargeImageWidthTest method testImageWidthWrittenCorrectly.
@Test
public void testImageWidthWrittenCorrectly() throws Exception {
ImageWriter writer = new ImageWriter();
writer.setMetadataRetrieve(ms);
writer.setId(target.getAbsolutePath());
writer.saveBytes(0, buf, 0, 0, buf.length, 1);
writer.close();
TiffReader reader = new TiffReader();
reader.setId(target.getAbsolutePath());
assertEquals(SIZE_X, reader.getSizeX());
assertEquals(SIZE_Y, reader.getSizeY());
}
use of loci.formats.in.TiffReader in project bioformats by openmicroscopy.
the class TiffWriterTest method assertTiles.
/**
* Tests the writing of the tiles.
* @param output The output where to write the data.
* @param compression The compression to use.
* @param n The value by which to divide the width of the image.
* @param m The value by which to divide the height of the image.
* @param bigTiff Pass <code>true</code> to set the <code>bigTiff</code> flag,
* <code>false</code> otherwise.
*/
private void assertTiles(String output, String compression, int n, int m, boolean bigTiff) throws Exception {
TiffWriter writer = initializeWriter(output, compression, bigTiff);
int x, y;
byte[] tile;
long[] rowPerStrip;
int w, h;
IFD ifd;
int count;
int series = reader.getSeriesCount();
String[][][] tileMD5s = new String[series][][];
for (int s = 0; s < series; s++) {
reader.setSeries(s);
w = reader.getSizeX() / n;
h = reader.getSizeY() / m;
rowPerStrip = new long[1];
rowPerStrip[0] = h;
count = reader.getImageCount();
tileMD5s[s] = new String[count][m * n];
for (int k = 0; k < count; k++) {
ifd = new IFD();
ifd.put(IFD.TILE_WIDTH, w);
ifd.put(IFD.TILE_LENGTH, h);
ifd.put(IFD.ROWS_PER_STRIP, rowPerStrip);
for (int i = 0; i < m; i++) {
y = h * i;
for (int j = 0; j < n; j++) {
x = w * j;
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.close();
// Now going to read the output.
TiffReader outputReader = new TiffReader();
outputReader.setId(output);
// first series.
String writtenDigest;
String readDigest;
for (int s = 0; s < series; s++) {
outputReader.setSeries(s);
count = outputReader.getImageCount();
h = outputReader.getSizeY() / m;
w = outputReader.getSizeX() / n;
for (int k = 0; k < count; k++) {
for (int i = 0; i < m; i++) {
y = h * i;
for (int j = 0; j < n; j++) {
x = w * j;
tile = outputReader.openBytes(k, x, y, w, h);
writtenDigest = tileMD5s[s][k][(i * n) + j];
readDigest = TestTools.md5(tile);
if (!writtenDigest.equals(readDigest)) {
fail(String.format("Compression:%s MD5:%d;%d;%d;%d;%d; %s != %s", compression, k, x, y, w, h, writtenDigest, readDigest));
}
}
}
}
}
outputReader.close();
}
use of loci.formats.in.TiffReader in project bioformats by openmicroscopy.
the class OMETiffWriterTest method testSaveBytesTiling.
@Test(dataProvider = "tiling")
public void testSaveBytesTiling(int tileSize, boolean littleEndian, boolean interleaved, int rgbChannels, int seriesCount, int sizeT, String compression, int pixelType, boolean bigTiff) throws Exception {
if (percentageOfTilingTests == 0)
return;
File tmp = File.createTempFile("OMETiffWriterTest_Tiling", ".ome.tiff");
tmp.deleteOnExit();
Plane originalPlane = WriterUtilities.writeImage(tmp, tileSize, littleEndian, interleaved, rgbChannels, seriesCount, sizeT, compression, pixelType, bigTiff);
TiffReader reader = new TiffReader();
reader.setId(tmp.getAbsolutePath());
int expectedTileSize = tileSize;
if (tileSize < TILE_GRANULARITY) {
expectedTileSize = TILE_GRANULARITY;
} else {
expectedTileSize = Math.round((float) tileSize / TILE_GRANULARITY) * TILE_GRANULARITY;
}
IFD tileIFd = reader.getIFDs().get(0);
assertEquals(tileIFd.getIFDIntValue(IFD.TILE_LENGTH), expectedTileSize);
assertEquals(tileIFd.getIFDIntValue(IFD.TILE_WIDTH), expectedTileSize);
WriterUtilities.checkImage(reader, originalPlane, interleaved, rgbChannels, seriesCount, sizeT, compression);
tmp.delete();
reader.close();
}
use of loci.formats.in.TiffReader in project bioformats by openmicroscopy.
the class OMETiffWriterTest method testSaveBytes.
@Test(dataProvider = "nonTiling")
public void testSaveBytes(int tileSize, boolean littleEndian, boolean interleaved, int rgbChannels, int seriesCount, int sizeT, String compression, int pixelType, boolean bigTiff) throws Exception {
if (percentageOfSaveBytesTests == 0)
return;
File tmp = File.createTempFile("OMETiffWriterTest", ".ome.tiff");
tmp.deleteOnExit();
Plane originalPlane = WriterUtilities.writeImage(tmp, tileSize, littleEndian, interleaved, rgbChannels, seriesCount, sizeT, compression, pixelType, bigTiff);
TiffReader reader = new TiffReader();
reader.setId(tmp.getAbsolutePath());
WriterUtilities.checkImage(reader, originalPlane, interleaved, rgbChannels, seriesCount, sizeT, compression);
tmp.delete();
reader.close();
}
Aggregations