Search in sources :

Example 1 with JPEG2000Writer

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();
}
Also used : IFormatWriter(loci.formats.IFormatWriter) JPEG2000Writer(loci.formats.out.JPEG2000Writer) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) DependencyException(loci.common.services.DependencyException) File(java.io.File) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with JPEG2000Writer

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);
}
Also used : JPEG2000Writer(loci.formats.out.JPEG2000Writer) ServiceFactory(loci.common.services.ServiceFactory) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) IFormatWriter(loci.formats.IFormatWriter) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ByteArrayHandle(loci.common.ByteArrayHandle) ImageReader(loci.formats.ImageReader) Test(org.testng.annotations.Test)

Example 3 with JPEG2000Writer

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();
    }
}
Also used : IFormatWriter(loci.formats.IFormatWriter) JPEG2000Writer(loci.formats.out.JPEG2000Writer) IMetadata(loci.formats.meta.IMetadata) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) DependencyException(loci.common.services.DependencyException) File(java.io.File) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

DependencyException (loci.common.services.DependencyException)3 ServiceException (loci.common.services.ServiceException)3 ServiceFactory (loci.common.services.ServiceFactory)3 FormatException (loci.formats.FormatException)3 IFormatWriter (loci.formats.IFormatWriter)3 IMetadata (loci.formats.meta.IMetadata)3 JPEG2000Writer (loci.formats.out.JPEG2000Writer)3 OMEXMLService (loci.formats.services.OMEXMLService)3 File (java.io.File)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 ByteArrayHandle (loci.common.ByteArrayHandle)1 ImageReader (loci.formats.ImageReader)1 Test (org.testng.annotations.Test)1