Search in sources :

Example 1 with JPEG2000CodecOptions

use of loci.formats.codec.JPEG2000CodecOptions in project bioformats by openmicroscopy.

the class TiffCompressionCompressTest method testJPEG_2000_ResetNumberDecompositionLevel.

@Test(enabled = true)
public void testJPEG_2000_ResetNumberDecompositionLevel() throws FormatException, IOException {
    TiffCompression compression = TiffCompression.JPEG_2000;
    JPEG2000CodecOptions opt = JPEG2000CodecOptions.getDefaultOptions();
    int v = 16;
    opt.numDecompositionLevels = v;
    CodecOptions options = compression.getCompressionCodecOptions(ifd, opt);
    assertTrue(options instanceof JPEG2000CodecOptions);
    JPEG2000CodecOptions j2k = (JPEG2000CodecOptions) options;
    assertEquals(j2k.numDecompositionLevels, opt.numDecompositionLevels);
    compression = TiffCompression.JPEG_2000_LOSSY;
    options = compression.getCompressionCodecOptions(ifd, opt);
    assertTrue(options instanceof JPEG2000CodecOptions);
    j2k = (JPEG2000CodecOptions) options;
    assertEquals(j2k.numDecompositionLevels, opt.numDecompositionLevels);
    compression = TiffCompression.ALT_JPEG2000;
    options = compression.getCompressionCodecOptions(ifd, opt);
    j2k = (JPEG2000CodecOptions) options;
    assertEquals(j2k.numDecompositionLevels, opt.numDecompositionLevels);
}
Also used : CodecOptions(loci.formats.codec.CodecOptions) JPEG2000CodecOptions(loci.formats.codec.JPEG2000CodecOptions) TiffCompression(loci.formats.tiff.TiffCompression) JPEG2000CodecOptions(loci.formats.codec.JPEG2000CodecOptions) Test(org.testng.annotations.Test)

Example 2 with JPEG2000CodecOptions

use of loci.formats.codec.JPEG2000CodecOptions in project bioformats by openmicroscopy.

the class TiffCompressionCompressTest method testJPEG_2000_ResetBlockSize.

@Test(enabled = true)
public void testJPEG_2000_ResetBlockSize() throws FormatException, IOException {
    TiffCompression compression = TiffCompression.JPEG_2000;
    JPEG2000CodecOptions opt = JPEG2000CodecOptions.getDefaultOptions();
    int v = 16;
    opt.codeBlockSize = new int[] { v, v };
    CodecOptions options = compression.getCompressionCodecOptions(ifd, opt);
    assertTrue(options instanceof JPEG2000CodecOptions);
    JPEG2000CodecOptions j2k = (JPEG2000CodecOptions) options;
    assertEquals(j2k.codeBlockSize.length, opt.codeBlockSize.length);
    for (int i = 0; i < j2k.codeBlockSize.length; i++) {
        assertEquals(j2k.codeBlockSize[i], opt.codeBlockSize[i]);
    }
    compression = TiffCompression.JPEG_2000_LOSSY;
    options = compression.getCompressionCodecOptions(ifd, opt);
    assertTrue(options instanceof JPEG2000CodecOptions);
    j2k = (JPEG2000CodecOptions) options;
    assertEquals(j2k.codeBlockSize.length, opt.codeBlockSize.length);
    for (int i = 0; i < j2k.codeBlockSize.length; i++) {
        assertEquals(j2k.codeBlockSize[i], opt.codeBlockSize[i]);
    }
    compression = TiffCompression.ALT_JPEG2000;
    options = compression.getCompressionCodecOptions(ifd, opt);
    j2k = (JPEG2000CodecOptions) options;
    assertEquals(j2k.codeBlockSize.length, opt.codeBlockSize.length);
    for (int i = 0; i < j2k.codeBlockSize.length; i++) {
        assertEquals(j2k.codeBlockSize[i], opt.codeBlockSize[i]);
    }
}
Also used : CodecOptions(loci.formats.codec.CodecOptions) JPEG2000CodecOptions(loci.formats.codec.JPEG2000CodecOptions) TiffCompression(loci.formats.tiff.TiffCompression) JPEG2000CodecOptions(loci.formats.codec.JPEG2000CodecOptions) Test(org.testng.annotations.Test)

Example 3 with JPEG2000CodecOptions

use of loci.formats.codec.JPEG2000CodecOptions in project bioformats by openmicroscopy.

the class MinimalTiffReader method setResolutionLevel.

/**
 * Sets the resolution level when we have JPEG 2000 compressed data.
 * @param ifd The active IFD that is being used in our current
 * <code>openBytes()</code> calling context. It will be the sub-resolution
 * IFD if <code>currentSeries > 0</code>.
 */
protected void setResolutionLevel(IFD ifd) {
    if (tiffParser == null) {
        initTiffParser();
    }
    if (j2kCodecOptions == null) {
        j2kCodecOptions = new JPEG2000CodecOptions();
    }
    j2kCodecOptions.resolution = Math.abs(getCoreIndex() - resolutionLevels);
    LOGGER.debug("Using JPEG 2000 resolution level {}", j2kCodecOptions.resolution);
    tiffParser.setCodecOptions(j2kCodecOptions);
}
Also used : JPEG2000CodecOptions(loci.formats.codec.JPEG2000CodecOptions)

Example 4 with JPEG2000CodecOptions

use of loci.formats.codec.JPEG2000CodecOptions in project bioformats by openmicroscopy.

the class JPEG2000Reader method openBytes.

/**
 * @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int)
 */
@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
    if (lastSeries == getCoreIndex() && lastSeriesPlane != null) {
        RandomAccessInputStream s = new RandomAccessInputStream(lastSeriesPlane);
        readPlane(s, x, y, w, h, buf);
        s.close();
        return buf;
    }
    JPEG2000CodecOptions options = JPEG2000CodecOptions.getDefaultOptions();
    options.interleaved = isInterleaved();
    options.littleEndian = isLittleEndian();
    if (resolutionLevels != null) {
        options.resolution = Math.abs(getCoreIndex() - resolutionLevels);
    } else if (core.size() > 1) {
        options.resolution = getCoreIndex();
    }
    in.seek(pixelsOffset);
    lastSeriesPlane = new JPEG2000Codec().decompress(in, options);
    RandomAccessInputStream s = new RandomAccessInputStream(lastSeriesPlane);
    readPlane(s, x, y, w, h, buf);
    s.close();
    lastSeries = getCoreIndex();
    return buf;
}
Also used : JPEG2000Codec(loci.formats.codec.JPEG2000Codec) JPEG2000CodecOptions(loci.formats.codec.JPEG2000CodecOptions) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 5 with JPEG2000CodecOptions

use of loci.formats.codec.JPEG2000CodecOptions in project bioformats by openmicroscopy.

the class TiffCompressionCompressTest method testJPEG_2000_ResetQuality.

@Test(enabled = true)
public void testJPEG_2000_ResetQuality() throws FormatException, IOException {
    TiffCompression compression = TiffCompression.JPEG_2000;
    JPEG2000CodecOptions opt = JPEG2000CodecOptions.getDefaultOptions();
    opt.quality = 1.0f;
    CodecOptions options = compression.getCompressionCodecOptions(ifd, opt);
    assertEquals(options.quality, opt.quality);
    compression = TiffCompression.JPEG_2000_LOSSY;
    options = compression.getCompressionCodecOptions(ifd, opt);
    assertEquals(options.quality, opt.quality);
    compression = TiffCompression.ALT_JPEG2000;
    options = compression.getCompressionCodecOptions(ifd, opt);
    assertEquals(options.quality, opt.quality);
}
Also used : CodecOptions(loci.formats.codec.CodecOptions) JPEG2000CodecOptions(loci.formats.codec.JPEG2000CodecOptions) TiffCompression(loci.formats.tiff.TiffCompression) JPEG2000CodecOptions(loci.formats.codec.JPEG2000CodecOptions) Test(org.testng.annotations.Test)

Aggregations

JPEG2000CodecOptions (loci.formats.codec.JPEG2000CodecOptions)7 CodecOptions (loci.formats.codec.CodecOptions)3 JPEG2000Codec (loci.formats.codec.JPEG2000Codec)3 TiffCompression (loci.formats.tiff.TiffCompression)3 Test (org.testng.annotations.Test)3 RandomAccessInputStream (loci.common.RandomAccessInputStream)2 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)1