use of loci.formats.out.JPEG2000Writer in project bioformats by openmicroscopy.
the class LosslessJPEG2000Test method setUp.
@BeforeMethod
public void setUp() throws Exception {
File temp8 = File.createTempFile("test", ".jp2");
File temp16 = File.createTempFile("test", ".jp2");
temp8.deleteOnExit();
temp16.deleteOnExit();
Location.mapId(FILE_8, temp8.getAbsolutePath());
Location.mapId(FILE_16, temp16.getAbsolutePath());
IMetadata metadata8;
try {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
metadata8 = 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(metadata8, 0, "foo", false, "XYCZT", "uint8", 1, 1, 1, 1, 1, 1);
IFormatWriter writer8 = new JPEG2000Writer();
writer8.setMetadataRetrieve(metadata8);
writer8.setId(FILE_8);
writer8.saveBytes(0, PIXELS_8);
writer8.close();
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_16);
writer16.saveBytes(0, PIXELS_16);
writer16.close();
}
use of loci.formats.out.JPEG2000Writer 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.out.JPEG2000Writer 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();
}
}
Aggregations