diff --git a/src/main/java/org/weasis/dicom/util/ForwardUtil.java b/src/main/java/org/weasis/dicom/util/ForwardUtil.java index f61b478..f35e5ce 100644 --- a/src/main/java/org/weasis/dicom/util/ForwardUtil.java +++ b/src/main/java/org/weasis/dicom/util/ForwardUtil.java @@ -26,7 +26,6 @@ import org.dcm4che6.data.DicomObject; import org.dcm4che6.data.Tag; import org.dcm4che6.data.UID; -import org.dcm4che6.data.VR; import org.dcm4che6.img.DicomImageReader; import org.dcm4che6.img.DicomImageUtils; import org.dcm4che6.img.DicomOutputData; @@ -199,12 +198,19 @@ public static void storeOneDestination( public static synchronized StoreFromStreamSCU prepareTransfer( DicomForwardDestination destination, String cuid, String tsuid) throws IOException { - String outTsuid = tsuid.equals(UID.RLELossless) ? UID.ExplicitVRLittleEndian : tsuid; + String outTsuid = + tsuid.equals(UID.RLELossless) + || tsuid.equals(UID.ImplicitVRLittleEndian) + || tsuid.equals(UID.ExplicitVRBigEndianRetired) + ? UID.ExplicitVRLittleEndian + : tsuid; StoreFromStreamSCU streamSCU = destination.getStreamSCU(); if (streamSCU.getAssociation() == null || !streamSCU.getAssociation().isOpen()) { // Add Presentation Context for the association streamSCU.addData(cuid, outTsuid); - streamSCU.addData(cuid, UID.ExplicitVRLittleEndian); + if (!outTsuid.equals(UID.ExplicitVRLittleEndian)) { + streamSCU.addData(cuid, UID.ExplicitVRLittleEndian); + } streamSCU.open(); } else { // Handle dynamically new SOPClassUID @@ -212,7 +218,9 @@ public static synchronized StoreFromStreamSCU prepareTransfer( boolean missingTsuid = val.findFirst().isEmpty(); // Add Presentation Context for the association streamSCU.addData(cuid, outTsuid); - streamSCU.addData(cuid, UID.ExplicitVRLittleEndian); + if (!outTsuid.equals(UID.ExplicitVRLittleEndian)) { + streamSCU.addData(cuid, UID.ExplicitVRLittleEndian); + } if (missingTsuid) { streamSCU.close(true); streamSCU.open(); @@ -354,7 +362,6 @@ private static DataWriter buildDataWriter( try (DicomOutputStream writer = new DicomOutputStream(out).withEncoding(DicomEncoding.of(tsuid))) { writer.writeDataSet(data); - writer.writeHeader(Tag.ItemDelimitationItem, VR.NONE, 0); } }; } @@ -444,12 +451,12 @@ public ByteBuffer getBytes(int frame) throws IOException { if (numberOfFrame == 1) { int length = 0; for (int i = 0; i < nbFragments - 1; i++) { - DataFragment bulkData = fragments.get(i + frame + 1); + DataFragment bulkData = fragments.get(i + 1); length += bulkData.valueLength(); } ByteArrayOutputStream out = new ByteArrayOutputStream(length); for (int i = 0; i < nbFragments - 1; i++) { - DataFragment fragment = pix.getDataFragment(frame + 1); + DataFragment fragment = pix.getDataFragment(i + 1); fragment.writeTo(out); } return ByteBuffer.wrap(out.toByteArray());