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);
}
Aggregations