/** @see loci.formats.IFormatReader#openBytes(int, byte[], int, int, int, int) */ 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); int index = no; for (int i = 0; i < series; i++) { index += core[i].imageCount; } if (index >= binDataOffsets.size()) { index = binDataOffsets.size() - 1; } long offset = binDataOffsets.get(index).longValue(); String compress = compression.get(index); in.seek(offset); int depth = FormatTools.getBytesPerPixel(getPixelType()); int planeSize = getSizeX() * getSizeY() * depth; CodecOptions options = new CodecOptions(); options.width = getSizeX(); options.height = getSizeY(); options.bitsPerSample = depth * 8; options.channels = getRGBChannelCount(); options.maxBytes = planeSize; options.littleEndian = isLittleEndian(); options.interleaved = isInterleaved(); byte[] pixels = new Base64Codec().decompress(in, options); // return a blank plane if no pixel data was stored if (pixels.length == 0) { LOGGER.debug("No pixel data for plane #{}", no); return buf; } // TODO: Create a method uncompress to handle all compression methods if (compress.equals("bzip2")) { byte[] tempPixels = pixels; pixels = new byte[tempPixels.length - 2]; System.arraycopy(tempPixels, 2, pixels, 0, pixels.length); ByteArrayInputStream bais = new ByteArrayInputStream(pixels); CBZip2InputStream bzip = new CBZip2InputStream(bais); pixels = new byte[planeSize]; bzip.read(pixels, 0, pixels.length); tempPixels = null; bais.close(); bais = null; bzip = null; } else if (compress.equals("zlib")) { pixels = new ZlibCodec().decompress(pixels, options); } else if (compress.equals("J2K")) { pixels = new JPEG2000Codec().decompress(pixels, options); } else if (compress.equals("JPEG")) { pixels = new JPEGCodec().decompress(pixels, options); } for (int row = 0; row < h; row++) { int off = (row + y) * getSizeX() * depth + x * depth; System.arraycopy(pixels, off, buf, row * w * depth, w * depth); } pixels = null; return buf; }