use of loci.formats.IFormatWriter in project bioformats by openmicroscopy.
the class SixteenBitLosslessJPEG2000Test method testLosslessPixels.
@Test
public void testLosslessPixels() throws Exception {
int failureCount = 0;
for (int v = Short.MIN_VALUE; v < Short.MAX_VALUE; v += increment) {
int index = v + Short.MAX_VALUE + 1;
byte[] pixels = DataTools.shortToBytes((short) v, false);
String file = index + ".jp2";
ByteArrayHandle tmpFile = new ByteArrayHandle(1);
Location.mapFile(file, tmpFile);
IMetadata metadata16;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
metadata16 = service.createOMEXMLMetadata();
} catch (DependencyException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
} catch (ServiceException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
}
MetadataTools.populateMetadata(metadata16, 0, "foo", false, "XYCZT", "uint16", 1, 1, 1, 1, 1, 1);
IFormatWriter writer16 = new JPEG2000Writer();
writer16.setMetadataRetrieve(metadata16);
writer16.setId(file);
writer16.saveBytes(0, pixels);
writer16.close();
byte[] buf = tmpFile.getBytes();
byte[] realData = new byte[(int) tmpFile.length()];
System.arraycopy(buf, 0, realData, 0, realData.length);
tmpFile.close();
tmpFile = new ByteArrayHandle(realData);
Location.mapFile(file, tmpFile);
ImageReader reader = new ImageReader();
reader.setId(file);
byte[] plane = reader.openBytes(0);
for (int q = 0; q < plane.length; q++) {
if (plane[q] != pixels[q]) {
LOGGER.debug("FAILED on {}", DataTools.bytesToShort(pixels, false));
failureCount++;
break;
}
}
reader.close();
tmpFile.close();
Location.mapFile(file, null);
}
assertEquals(failureCount, 0);
}
use of loci.formats.IFormatWriter in project bioformats by openmicroscopy.
the class EightBitLosslessJPEG2000Test method setUp.
@BeforeMethod
public void setUp() throws Exception {
for (byte v = Byte.MIN_VALUE; v < Byte.MAX_VALUE; v++) {
int index = v + Byte.MAX_VALUE + 1;
pixels[index][0] = v;
String file = index + ".jp2";
File tempFile = File.createTempFile("test", ".jp2");
tempFile.deleteOnExit();
Location.mapId(file, tempFile.getAbsolutePath());
files.add(file);
IMetadata metadata;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
metadata = service.createOMEXMLMetadata();
} catch (DependencyException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
} catch (ServiceException exc) {
throw new FormatException("Could not create OME-XML store.", exc);
}
MetadataTools.populateMetadata(metadata, 0, "foo", false, "XYCZT", "uint8", 1, 1, 1, 1, 1, 1);
IFormatWriter writer = new JPEG2000Writer();
writer.setMetadataRetrieve(metadata);
writer.setId(file);
writer.saveBytes(0, pixels[index]);
writer.close();
}
}
use of loci.formats.IFormatWriter in project bioformats by openmicroscopy.
the class FormatWriterTest method getWriterList.
// -- Data provider --
@DataProvider(name = "getWriterList")
public Object[][] getWriterList() {
IFormatWriter[] writers = new ImageWriter().getWriters();
List tmp = new ArrayList();
for (int i = 0; i < writers.length; i++) {
String[] compressionTypes = writers[i].getCompressionTypes();
if (compressionTypes == null) {
try {
IFormatWriter w = (IFormatWriter) writers[i].getClass().newInstance();
tmp.add(w);
} catch (InstantiationException ie) {
} catch (IllegalAccessException iae) {
}
continue;
}
for (int q = 0; q < compressionTypes.length; q++) {
try {
IFormatWriter w = (IFormatWriter) writers[i].getClass().newInstance();
if (DataTools.containsValue(w.getPixelTypes(compressionTypes[q]), reader.getPixelType())) {
w.setCompression(compressionTypes[q]);
tmp.add(w);
}
} catch (FormatException fe) {
} catch (InstantiationException ie) {
} catch (IllegalAccessException iae) {
}
}
}
IFormatWriter[][] writersToUse = new IFormatWriter[tmp.size()][1];
for (int i = 0; i < tmp.size(); i++) {
writersToUse[i][0] = (IFormatWriter) tmp.get(i);
}
return writersToUse;
}
Aggregations