Search in sources :

Example 1 with Base64Codec

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

the class OMEXMLWriter method compress.

// -- Helper methods --
/**
 * Compress the given byte array using the current codec.
 * The compressed data is then base64-encoded.
 */
private byte[] compress(byte[] b) throws FormatException, IOException {
    MetadataRetrieve r = getMetadataRetrieve();
    String type = r.getPixelsType(series).toString();
    int pixelType = FormatTools.pixelTypeFromString(type);
    int bytes = FormatTools.getBytesPerPixel(pixelType);
    CodecOptions options = new CodecOptions();
    options.width = r.getPixelsSizeX(series).getValue().intValue();
    options.height = r.getPixelsSizeY(series).getValue().intValue();
    options.channels = 1;
    options.interleaved = false;
    options.signed = FormatTools.isSigned(pixelType);
    boolean littleEndian = false;
    if (r.getPixelsBigEndian(series) != null) {
        littleEndian = !r.getPixelsBigEndian(series).booleanValue();
    } else if (r.getPixelsBinDataCount(series) == 0) {
        littleEndian = !r.getPixelsBinDataBigEndian(series, 0).booleanValue();
    }
    options.littleEndian = littleEndian;
    options.bitsPerSample = bytes * 8;
    if (compression.equals("J2K")) {
        b = new JPEG2000Codec().compress(b, options);
    } else if (compression.equals("JPEG")) {
        b = new JPEGCodec().compress(b, options);
    } else if (compression.equals("zlib")) {
        b = new ZlibCodec().compress(b, options);
    }
    return new Base64Codec().compress(b, options);
}
Also used : ZlibCodec(loci.formats.codec.ZlibCodec) CodecOptions(loci.formats.codec.CodecOptions) JPEG2000Codec(loci.formats.codec.JPEG2000Codec) Base64Codec(loci.formats.codec.Base64Codec) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) JPEGCodec(loci.formats.codec.JPEGCodec)

Aggregations

Base64Codec (loci.formats.codec.Base64Codec)1 CodecOptions (loci.formats.codec.CodecOptions)1 JPEG2000Codec (loci.formats.codec.JPEG2000Codec)1 JPEGCodec (loci.formats.codec.JPEGCodec)1 ZlibCodec (loci.formats.codec.ZlibCodec)1 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)1