public DicomInputStream(InputStream in, String tsuid) throws IOException { this(in, TransferSyntax.valueOf(tsuid)); }
public static TransferSyntax valueOf(String uid) { if (uid == null) throw new NullPointerException("uid"); TransferSyntax ts = map.get(uid); return ts != null ? ts : new TransferSyntax(uid, true, false, false, true); }
/** * This method gets the encoded image from the given object as a byte array * of data. */ protected byte[] extractImageEncoding(IIOImage iioimage, ImageWriteParam param) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); MemoryCacheImageOutputStream imageOutput = new MemoryCacheImageOutputStream( baos); writer.setOutput(imageOutput); writer.write(null, iioimage, writeParam); imageOutput.close(); baos.close(); byte[] data = baos.toByteArray(); // Write little endian raw data if( (!encapsulated) && bytes==2 && ! dos.getTransferSyntax().bigEndian() ) { for(int i=0; i<data.length; i+=2) { byte swap = data[i]; data[i] = data[i+1]; data[i+1] = swap; } } return data; }
public int readHeader() throws IOException { tagpos = pos; readFully(header, 0, 8); tag = ts.bigEndian() ? ByteUtils.bytesBE2tag(header, 0) : ByteUtils .bytesLE2tag(header, 0); if (expectFmiEnd && !TagUtils.isFileMetaInfoElement(tag)) { String tsuid = attrs.getString(Tag.TransferSyntaxUID); if (tsuid != null) { ts = TransferSyntax.valueOf(tsuid); tag = ts.bigEndian() ? ByteUtils.bytesBE2tag(header, 0) : ByteUtils.bytesLE2tag(header, 0); } else { if (TagUtils.hasVR(tag) && ts.explicitVR()) { try { vr = VR.valueOf(((header[4] & 0xff) << 8) | (header[5] & 0xff)); vallen = ts.bigEndian() ? ByteUtils.bytesBE2ushort(header, 6) : ByteUtils.bytesLE2ushort(header, 6); if (vr == VR.UN_SIEMENS) { vallen = ts.bigEndian() ? ByteUtils.bytesBE2int(header, 4) : ByteUtils .bytesLE2int(header, 4); return tag;
/** Sets up the child writer if it hasn't already been setup */ protected void setupWriter(IIOMetadata metadata) { if (writer != null) return; if (metadata == null) metadata = getDefaultStreamMetadata(null); DicomStreamMetaData dmeta = (DicomStreamMetaData) metadata; DicomObject dobj = dmeta.getDicomObject(); String tsuid = dobj.getString(Tag.TransferSyntaxUID); TransferSyntax ts = TransferSyntax.valueOf(tsuid); encapsulated = ts.encapsulated(); if (encapsulated) { writer = ImageWriterFactory.getInstance() .getWriterForTransferSyntax(tsuid); writeParam = ImageWriterFactory.getInstance().createWriteParam( tsuid, writer); } else { writer = ImageIO.getImageWritersByFormatName("RAW").next(); } }
TransferSyntax.add(new TransferSyntax("1.2.826.0.1.3680043.2.682.1.40", false,false, false, true)); TransferSyntax.add(new TransferSyntax("1.2.840.10008.1.2.4.70", true,false, false, true)); TransferSyntax.add(new TransferSyntax("1.2.840.10008.1.2.5.50", false,false, false, true));
public void writeHeader(int tag, VR vr, int len) throws IOException { if (ts.bigEndian()) { ByteUtils.tag2bytesBE(tag, header, 0); if (vr != null && ts.explicitVR()) { ByteUtils.ushort2bytesBE(vr.code(), header, 4); if (vr.explicitVRHeaderLength() == 8) { if (ts.bigEndian()) { ByteUtils.ushort2bytesBE(len, header, 6); off = 4; if (ts.bigEndian()) { ByteUtils.int2bytesBE(len, header, 4);
public final void setTransferSyntax(TransferSyntax ts) { if (ts.deflated() && !(out instanceof DeflaterOutputStream)) out = new DeflaterOutputStream(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true)); this.ts = ts; }
vlen = 8; final int alen = (ts.explicitVR() ? vr.explicitVRHeaderLength() : 8) + vlen;
info.tsuid = in.getTransferSyntax().uid(); info.fmiEndPos = in.getEndOfFileMetaInfoPosition(); } catch (IOException e) {
private void switchTransferSyntax(TransferSyntax ts) throws IOException { if (this.ts != null && this.ts.deflated()) throw new IllegalStateException( "Cannot switch back from Deflated TS"); if (ts.deflated()) { if (hasZLIBHeader()) { log.warn("Deflated DICOM Stream with ZLIB Header"); super.in = new InflaterInputStream(super.in); } else super.in = new InflaterInputStream(super.in, new Inflater(true)); } this.ts = ts; }
public final void setTransferSyntax(String tsuid) { setTransferSyntax(TransferSyntax.valueOf(tsuid)); }
private void writeGroupLength(int tag, int length) throws IOException { writeHeader(tag, VR.UL, 4); write(VR.UL.toBytes(length, ts.bigEndian()), 0, 4); }
in.setHandler(new StopTagInputHandler(Tag.StudyDate)); in.readDicomObject(dcmObj, PEEK_LEN); info.tsuid = in.getTransferSyntax().uid(); info.fmiEndPos = in.getEndOfFileMetaInfoPosition(); } catch (IOException e) {
/** * Write a DICOM dataset to the output stream. * * @param attrs * A DicomObject containing the attributes to write. * @param tsuid * A String containing the transfer syntax UID of the file. * @throws IOException */ public void writeDataset(DicomObject attrs, String tsuid) throws IOException { writeDataset(attrs, TransferSyntax.valueOf(tsuid)); }
private void transcodeValue(DicomInputStream in, VR vr) throws IOException { boolean toggleEndian = out.getTransferSyntax().bigEndian() != in.getTransferSyntax().bigEndian(); int remaining = in.valueLength(); while (remaining > 0) { int len = Math.min(remaining, buf.length); in.readFully(buf, 0, len); if (toggleEndian) vr.toggleEndian(buf, 0, len); out.write(buf, 0, len); remaining -= len; } }
public void writeTo(PDVOutputStream out, String tsuid) throws IOException { DicomOutputStream dos = new DicomOutputStream(out); dos.writeDataset(data, TransferSyntax.valueOf(tsuid)); }
if (vallen == -1 || vr == VR.SQ ) { DicomElement a = vr == VR.SQ ? attrs.putSequence(tag) : attrs .putFragments(tag, vr, ts.bigEndian()); readItems(a, vallen); } else { DicomElement a = attrs.putBytes(tag, vr, readBytes(vallen), ts .bigEndian()); if (tag == 0x00020000) { fmiEndPos = pos + a.getInt(false);
@Override public DicomObject readDataset() throws IOException { PresentationContext pc = as.getAssociateAC().getPresentationContext( pcid); String tsuid = pc.getTransferSyntax(); return readDicomObject(TransferSyntax.valueOf(tsuid)); }