public void transcodeWithTranscoder(File src, final File dest) throws IOException { try (Transcoder transcoder = new Transcoder(src)) { transcoder.setIncludeFileMetaInformation(!nofmi); transcoder.setRetainFileMetaInformation(retainfmi); transcoder.setEncodingOptions(encOpts); transcoder.setDestinationTransferSyntax(tsuid); if (tstype.isPixeldataEncapsulated()) transcoder.setCompressParams(params.toArray(new Property[0])); transcoder.transcode(new Transcoder.Handler(){ @Override public OutputStream newOutputStream(Transcoder transcoder, Attributes dataset) throws IOException { return new FileOutputStream(dest); } }); } }
private void decompressPixelData() throws IOException { int length = imageDescriptor.getLength(); int padding = length & 1; adjustDataset(); writeDataset(); dos.writeHeader(Tag.PixelData, VR.OW, length + padding); for (int i = 0; i < imageDescriptor.getFrames(); i++) { decompressFrame(i); writeFrame(); } if (padding != 0) dos.write(0); }
private void processPixelData() throws IOException { if (decompressor != null) initEncapsulatedPixelData(); VR vr; if (compressor != null) { vr = VR.OB; compressPixelData(); } else if (decompressor != null) { vr = VR.OW; decompressPixelData(); } else { vr = dis.vr(); copyPixelData(); } setPixelDataBulkData(vr); }
private void compressPixelData() throws IOException { int padding = dis.length() - imageDescriptor.getLength(); for (int i = 0; i < imageDescriptor.getFrames(); i++) { if (decompressor == null) readFrame(); else bi = decompressFrame(i); if (i == 0) { extractEmbeddedOverlays(); adjustDataset(); writeDataset(); dos.writeHeader(Tag.PixelData, VR.OB, -1); dos.writeHeader(Tag.Item, null, 0); } nullifyUnusedBits(); compressFrame(i); } dis.skipFully(padding); dos.writeHeader(Tag.SequenceDelimitationItem, null, 0); }
private void copyPixelData() throws IOException { int length = dis.length(); writeDataset(); dos.writeHeader(Tag.PixelData, dis.vr(), length); if (length == -1) { dis.readValue(dis, dataset); dos.writeHeader(Tag.SequenceDelimitationItem, null, 0); } else { if (dis.bigEndian() == dos.isBigEndian()) StreamUtils.copy(dis, dos, length, buffer()); else StreamUtils.copy(dis, dos, length, dis.vr().numEndianBytes(), buffer()); } }
public void setCompressParams(Property[] imageWriteParams) { int count = 0; for (Property property : cat(compressorParam.getImageWriteParams(), imageWriteParams)) { String name = property.getName(); if (name.equals("maxPixelValueError")) this.maxPixelValueError = ((Number) property.getValue()).intValue(); else if (name.equals("avgPixelValueBlockSize")) this.avgPixelValueBlockSize = ((Number) property.getValue()).intValue(); else { if (count++ == 0) compressParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); property.setAt(compressParam); } } if (maxPixelValueError >= 0) { ImageReaderFactory.ImageReaderParam readerParam = ImageReaderFactory.getImageReaderParam(destTransferSyntax); if (readerParam == null) throw new UnsupportedOperationException( "Unsupported Transfer Syntax: " + destTransferSyntax); this.verifier = ImageReaderFactory.getImageReader(readerParam); this.verifyParam = verifier.getDefaultReadParam(); LOG.debug("Verifier: {}", verifier.getClass().getName()); } }
private void write(SampleModel sm, byte[][] bankData) throws IOException { int h = sm.getHeight(); int w = sm.getWidth(); ComponentSampleModel csm = (ComponentSampleModel) sm; int len = w * csm.getPixelStride(); int stride = csm.getScanlineStride(); if (csm.getBandOffsets()[0] != 0) bgr2rgb(bankData[0]); for (byte[] b : bankData) for (int y = 0, off = 0; y < h; ++y, off += stride) dos.write(b, off, len); }
? new BandedSampleModel(dataType, cols, rows, samples) : new PixelInterleavedSampleModel(dataType, cols, rows, samples, cols * samples, bandOffsets(samples)); WritableRaster raster = Raster.createWritableRaster(sm, null); bi = new BufferedImage(cm, raster, false, null);
public void transcodeWithTranscoder(File src, final File dest) throws IOException { try (Transcoder transcoder = new Transcoder(src)) { transcoder.setIncludeFileMetaInformation(!nofmi); transcoder.setRetainFileMetaInformation(retainfmi); transcoder.setEncodingOptions(encOpts); transcoder.setDestinationTransferSyntax(tsuid); if (tstype.isPixeldataEncapsulated()) transcoder.setCompressParams(params.toArray(new Property[0])); transcoder.transcode(new Transcoder.Handler(){ @Override public OutputStream newOutputStream(Transcoder transcoder, Attributes dataset) throws IOException { return new FileOutputStream(dest); } }); } }