use of org.dcm4che3.data.BulkData in project dcm4che by dcm4che.
the class DicomImageReader method initPixelDataIIS.
/**
* Initializes the pixel data reading from an image input stream
*/
private void initPixelDataIIS(DicomInputStream dis) throws IOException {
if (pixelDataLength == 0)
return;
if (pixelDataLength > 0) {
pixelData = new BulkData("pixeldata://", dis.getPosition(), dis.length(), dis.bigEndian());
metadata.getAttributes().setValue(Tag.PixelData, pixelDataVR, pixelData);
return;
}
dis.readItemHeader();
byte[] b = new byte[dis.length()];
dis.readFully(b);
long start = dis.getPosition();
pixelDataFragments = new Fragments(pixelDataVR, dis.bigEndian(), frames);
pixelDataFragments.add(b);
generateOffsetLengths(pixelDataFragments, frames, b, start);
}
use of org.dcm4che3.data.BulkData in project Weasis by nroduit.
the class RawImageIO method getDicomFile.
public File getDicomFile() {
Attributes dcm = getDicomObject();
File file = imageCV.getFile();
BulkData bdl = new BulkData(file.toURI().toString(), FileRawImage.HEADER_LENGTH, (int) file.length() - FileRawImage.HEADER_LENGTH, false);
dcm.setValue(Tag.PixelData, VR.OW, bdl);
File tmpFile = new File(DicomMediaIO.DICOM_EXPORT_DIR, dcm.getString(Tag.SOPInstanceUID));
try (DicomOutputStream out = new DicomOutputStream(tmpFile)) {
out.writeDataset(dcm.createFileMetaInformation(UID.ImplicitVRLittleEndian), dcm);
} catch (IOException e) {
LOGGER.error("Cannot write dicom file", e);
return null;
}
return tmpFile;
}
use of org.dcm4che3.data.BulkData in project dcm4che by dcm4che.
the class SAXWriter method writeAttribute.
private void writeAttribute(Value value, boolean bigEndian) throws SAXException {
if (value.isEmpty())
return;
if (value instanceof Sequence) {
Sequence seq = (Sequence) value;
int number = 0;
for (Attributes item : seq) {
startElement("Item", "number", ++number);
writeItem(item);
endElement("Item");
}
} else if (value instanceof Fragments) {
Fragments frags = (Fragments) value;
int number = 0;
for (Object frag : frags) {
++number;
if (frag instanceof Value && ((Value) frag).isEmpty())
continue;
startElement("DataFragment", "number", number);
if (frag instanceof BulkData)
writeBulkData((BulkData) frag);
else {
byte[] b = (byte[]) frag;
if (bigEndian)
frags.vr().toggleEndian(b, true);
writeInlineBinary(b);
}
endElement("DataFragment");
}
} else if (value instanceof BulkData) {
writeBulkData((BulkData) value);
}
}
use of org.dcm4che3.data.BulkData in project dcm4che by dcm4che.
the class StreamSegment method getSegments.
private static long[][] getSegments(SegmentedInputImageStream iis) throws IOException {
Integer curSegment = iis.getCurSegment();
if (curSegment != null && curSegment >= 0) {
ImageDescriptor desc = iis.getImageDescriptor();
List<Object> fragments = iis.getFragments();
Integer lastSegment = iis.getLastSegment();
if (!desc.isMultiframe() && lastSegment < fragments.size()) {
lastSegment = fragments.size();
}
long[] segPositions = new long[lastSegment - curSegment];
long[] segLength = new long[segPositions.length];
long beforePos = 0;
for (int i = curSegment; i < lastSegment; i++) {
synchronized (fragments) {
if (i < fragments.size()) {
Object fragment = fragments.get(i);
int k = i - curSegment;
if (fragment instanceof BulkData) {
BulkData bulk = (BulkData) fragment;
segPositions[k] = bulk.offset();
segLength[k] = bulk.length();
} else {
byte[] byteFrag = (byte[]) fragment;
segPositions[k] = beforePos;
segLength[k] = byteFrag.length;
}
beforePos += segLength[k] & 0xFFFFFFFFl;
}
}
}
return new long[][] { segPositions, segLength };
}
return null;
}
use of org.dcm4che3.data.BulkData in project dcm4che by dcm4che.
the class DicomImageReader method generateOffsetLengths.
/**
* Creates an offset/length table based on the frame positions
*/
public static void generateOffsetLengths(Fragments pixelData, int frames, byte[] basicOffsetTable, long start) {
long lastOffset = 0;
BulkData lastFrag = null;
for (int frame = 0; frame < frames; frame++) {
long offset = frame > 0 ? 1 : 0;
int offsetStart = frame * 4;
if (basicOffsetTable.length >= offsetStart + 4) {
offset = ByteUtils.bytesToIntLE(basicOffsetTable, offsetStart);
if (offset != 1) {
// Handle > 4 gb total image size by assuming incrementing modulo 4gb
offset = offset | (lastOffset & 0xFFFFFF00000000l);
if (offset < lastOffset)
offset += 0x100000000l;
lastOffset = offset;
LOG.trace("Found offset {} for frame {}", offset, frame);
}
}
long position = -1;
if (offset != 1) {
position = start + offset + 8;
}
BulkData frag = new BulkData("compressedPixelData://", position, -1, false);
if (lastFrag != null && position != -1) {
lastFrag.setLength(position - 8 - lastFrag.offset());
}
lastFrag = frag;
pixelData.add(frag);
if (offset == 0 && frame > 0) {
start = -1;
}
}
}
Aggregations