Search in sources :

Example 11 with BulkData

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);
}
Also used : Fragments(org.dcm4che3.data.Fragments) BulkData(org.dcm4che3.data.BulkData) IncludeBulkData(org.dcm4che3.io.DicomInputStream.IncludeBulkData)

Example 12 with BulkData

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;
}
Also used : Attributes(org.dcm4che3.data.Attributes) BulkData(org.dcm4che3.data.BulkData) DicomOutputStream(org.dcm4che3.io.DicomOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 13 with BulkData

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);
    }
}
Also used : Attributes(org.dcm4che3.data.Attributes) Fragments(org.dcm4che3.data.Fragments) Value(org.dcm4che3.data.Value) BulkData(org.dcm4che3.data.BulkData) Sequence(org.dcm4che3.data.Sequence)

Example 14 with BulkData

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;
}
Also used : BytesWithImageImageDescriptor(org.dcm4che3.imageio.codec.BytesWithImageImageDescriptor) ImageDescriptor(org.dcm4che3.imageio.codec.ImageDescriptor) BulkData(org.dcm4che3.data.BulkData)

Example 15 with BulkData

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;
        }
    }
}
Also used : BulkData(org.dcm4che3.data.BulkData) IncludeBulkData(org.dcm4che3.io.DicomInputStream.IncludeBulkData)

Aggregations

BulkData (org.dcm4che3.data.BulkData)17 Attributes (org.dcm4che3.data.Attributes)10 Fragments (org.dcm4che3.data.Fragments)9 IncludeBulkData (org.dcm4che3.io.DicomInputStream.IncludeBulkData)5 Sequence (org.dcm4che3.data.Sequence)3 VR (org.dcm4che3.data.VR)3 DicomInputStream (org.dcm4che3.io.DicomInputStream)3 File (java.io.File)2 IOException (java.io.IOException)2 Value (org.dcm4che3.data.Value)2 ImageDescriptor (org.dcm4che3.imageio.codec.ImageDescriptor)2 Test (org.junit.Test)2 Color (java.awt.Color)1 Shape (java.awt.Shape)1 StringWriter (java.io.StringWriter)1 BigInteger (java.math.BigInteger)1 SeekableByteChannel (java.nio.channels.SeekableByteChannel)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1