private void compress() throws IOException {
if (cache != null)
return;
if (ex != null)
throw ex;
try {
BufferedImage bi = Compressor.this.readFrame(frameIndex);
Compressor.this.extractEmbeddedOverlays(frameIndex, bi);
if (bitsStored < bitsAllocated)
Compressor.this.nullifyUnusedBits(bitsStored, bi);
cache = new FlushlessMemoryCacheImageOutputStream(cacheout, imageDescriptor);
compressor.setOutput(patchJPEGLS != null
? new PatchJPEGLSImageOutputStream(cache, patchJPEGLS)
: cache);
long start = System.currentTimeMillis();
compressor.write(null, new IIOImage(bi, null, null), compressParam);
long end = System.currentTimeMillis();
streamLength = (int) cache.getStreamPosition();
if (LOG.isDebugEnabled())
LOG.debug("Compressed frame #{} {}:1 in {} ms",
new Object[] {frameIndex + 1,
(float) sizeOf(bi) / streamLength,
end - start });
Compressor.this.verify(cache, frameIndex);
} catch (IOException ex) {
cache = null;
Compressor.this.ex = ex;
throw ex;
}
}