Skip to content

Commit

Permalink
Remove delimation tag. Fix reading multi-fragment images.
Browse files Browse the repository at this point in the history
  • Loading branch information
nroduit committed Feb 5, 2021
1 parent 8c101ad commit ed5560c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/main/java/org/weasis/dicom/util/ForwardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -199,20 +198,29 @@ 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
Stream<Byte> val = streamSCU.getAssociationRq().pcidsFor(cuid, outTsuid);
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();
Expand Down Expand Up @@ -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);
}
};
}
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit ed5560c

Please sign in to comment.