public void close() { if (iis != null) try { iis.close(); } catch (IOException ignore) {} dispose(); }
private void verify(MemoryCacheImageOutputStream cache, int index) throws IOException { if (verifier == null) return; cache.seek(0); verifier.setInput(cache); verifyParam.setDestination(bi2); long start = System.currentTimeMillis(); bi2 = verifier.read(0, verifyParam); int maxDiff = maxDiff(bi.getRaster(), bi2.getRaster()); long end = System.currentTimeMillis(); if (LOG.isDebugEnabled()) LOG.debug("Verified compressed frame #{} in {} ms - max pixel value error: {}", new Object[] { index + 1, end - start, maxDiff }); if (maxDiff > maxPixelValueError) throw new CompressionVerificationException(maxDiff); }
private void nullifyUnusedBits(int bitsStored, BufferedImage bi) { DataBuffer db = bi.getRaster().getDataBuffer(); switch (db.getDataType()) { case DataBuffer.TYPE_USHORT: nullifyUnusedBits(bitsStored, ((DataBufferUShort) db).getData()); break; case DataBuffer.TYPE_SHORT: nullifyUnusedBits(bitsStored, ((DataBufferShort) db).getData()); break; } }
tsuid = adjustTransferSyntax(tsuid, dataset.getInt(Tag.BitsStored, 8)); compressor = new Compressor(dataset, dis.getTransferSyntax()); compressor.compress(tsuid, params.toArray(new Property[0])); } else if (pixeldata instanceof Fragments) Decompressor.decompress(dataset, dis.getTransferSyntax());
for (int x = 0; x < maxX; x += blockSize) { if (maxDiff < (diff = Math.abs( sum(csm.getSamples( x, y, blockSize, blockSize, b, samples, db)) - sum(csm2.getSamples( x, y, blockSize, blockSize, b, samples, db2))))) maxDiff = diff; return maxDiff(csm, ((DataBufferByte) db).getBankData(), csm2, ((DataBufferByte) db2).getBankData()); case DataBuffer.TYPE_USHORT: return maxDiff(csm, ((DataBufferUShort) db).getData(), csm2, ((DataBufferUShort) db2).getData()); case DataBuffer.TYPE_SHORT: return maxDiff(csm, ((DataBufferShort) db).getData(), csm2, ((DataBufferShort) db2).getData()); default:
public BufferedImage readFrame(int frameIndex) throws IOException { if (iis == null) iis = new FileImageInputStream(file); if (decompressor != null) return decompressFrame(iis, frameIndex); iis.setByteOrder(pixeldata.bigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); iis.seek(pixeldata.offset() + frameLength * frameIndex); DataBuffer db = bi.getRaster().getDataBuffer(); switch (db.getDataType()) { case DataBuffer.TYPE_BYTE: byte[][] data = ((DataBufferByte) db).getBankData(); for (byte[] bs : data) iis.readFully(bs); if (pixeldata.bigEndian() && pixeldataVR.vr == VR.OW) ByteUtils.swapShorts(data); break; case DataBuffer.TYPE_USHORT: readFully(((DataBufferUShort) db).getData()); break; case DataBuffer.TYPE_SHORT: readFully(((DataBufferShort) db).getData()); break; default: throw new UnsupportedOperationException( "Unsupported Datatype: " + db.getDataType()); } return bi; }
for (Property property : cat(param.getImageWriteParams(), params)) { String name = property.getName(); if (name.equals("maxPixelValueError")) bi = createBufferedImage( Math.min(bitsStored, tstype.getMaxBitsStored()), super.tstype == TransferSyntaxType.RLE || banded,
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; } }
tsuid = adjustTransferSyntax(tsuid, dataset.getInt(Tag.BitsStored, 8)); compressor = new Compressor(dataset, dis.getTransferSyntax()); compressor.compress(tsuid, params.toArray(new Property[0])); } else if (pixeldata instanceof Fragments) Decompressor.decompress(dataset, dis.getTransferSyntax());