Search in sources :

Example 1 with SegmentedInputImageStream

use of org.dcm4che3.imageio.stream.SegmentedInputImageStream in project dcm4che by dcm4che.

the class DicomImageReader method iisOfFrame.

/**
 * Generate an image input stream for the given frame, -1 for all frames (video, multi-component single frame)
 * Does not necessarily support the length operation without seeking/reading to the end of the input.
 *
 * @param frameIndex
 * @return
 * @throws IOException
 */
public ImageInputStream iisOfFrame(int frameIndex) throws IOException {
    ImageInputStream iisOfFrame;
    if (epdiis != null) {
        seekFrame(frameIndex);
        iisOfFrame = epdiis;
    } else if (pixelDataFragments == null) {
        return null;
    } else {
        iisOfFrame = new SegmentedInputImageStream(iis, pixelDataFragments, frames == 1 ? -1 : frameIndex);
        ((SegmentedInputImageStream) iisOfFrame).setImageDescriptor(imageDescriptor);
    }
    return patchJpegLS != null ? new PatchJPEGLSImageInputStream(iisOfFrame, patchJpegLS) : iisOfFrame;
}
Also used : SegmentedInputImageStream(org.dcm4che3.imageio.stream.SegmentedInputImageStream) PatchJPEGLSImageInputStream(org.dcm4che3.imageio.codec.jpeg.PatchJPEGLSImageInputStream) PatchJPEGLSImageInputStream(org.dcm4che3.imageio.codec.jpeg.PatchJPEGLSImageInputStream) EncapsulatedPixelDataImageInputStream(org.dcm4che3.imageio.stream.EncapsulatedPixelDataImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream)

Example 2 with SegmentedInputImageStream

use of org.dcm4che3.imageio.stream.SegmentedInputImageStream in project dcm4che by dcm4che.

the class DicomImageReader method readPostPixeldata.

/**
 * Reads post-pixel data tags, will skip past any remaining images (which may be very slow), and
 * add any post-pixel data information to the attributes object.
 * NOTE: This read will read past image data, and may end up scanning/seeking through multiframe or video data in order to find the
 * post pixel data.  This may be slow.
 *
 * Replaces the attributes object with a new one, thus is thread safe for other uses of the object.
 */
public Attributes readPostPixeldata() throws IOException {
    if (frames == 0)
        return metadata.getAttributes();
    if (dis != null) {
        if (flushedFrames > frames) {
            return metadata.getAttributes();
        }
        dis.skipFully((frames - flushedFrames) * frameLength);
        flushedFrames = frames + 1;
        return readPostAttr(dis);
    }
    long offset;
    if (pixelData != null) {
        offset = pixelData.offset() + pixelData.longLength();
    } else {
        SegmentedInputImageStream siis = (SegmentedInputImageStream) iisOfFrame(-1);
        offset = siis.getOffsetPostPixelData();
    }
    iis.seek(offset);
    @SuppressWarnings("resource") DicomInputStream dis = new DicomInputStream(new ImageInputStreamAdapter(iis), getTransferSyntaxUID());
    return readPostAttr(dis);
}
Also used : SegmentedInputImageStream(org.dcm4che3.imageio.stream.SegmentedInputImageStream) DicomInputStream(org.dcm4che3.io.DicomInputStream) ImageInputStreamAdapter(org.dcm4che3.imageio.stream.ImageInputStreamAdapter)

Example 3 with SegmentedInputImageStream

use of org.dcm4che3.imageio.stream.SegmentedInputImageStream in project dcm4che by dcm4che.

the class Decompressor method decompressFrame.

@SuppressWarnings("resource")
protected BufferedImage decompressFrame(ImageInputStream iis, int index) throws IOException {
    SegmentedInputImageStream siis = new SegmentedInputImageStream(iis, pixeldataFragments, index);
    siis.setImageDescriptor(imageDescriptor);
    decompressor.setInput(patchJpegLS != null ? new PatchJPEGLSImageInputStream(siis, patchJpegLS) : siis);
    readParam.setDestination(bi);
    long start = System.currentTimeMillis();
    bi = decompressor.read(0, readParam);
    long end = System.currentTimeMillis();
    if (LOG.isDebugEnabled())
        LOG.debug("Decompressed frame #{} 1:{} in {} ms", new Object[] { index + 1, (float) sizeOf(bi) / siis.getStreamPosition(), end - start });
    return bi;
}
Also used : SegmentedInputImageStream(org.dcm4che3.imageio.stream.SegmentedInputImageStream) PatchJPEGLSImageInputStream(org.dcm4che3.imageio.codec.jpeg.PatchJPEGLSImageInputStream)

Example 4 with SegmentedInputImageStream

use of org.dcm4che3.imageio.stream.SegmentedInputImageStream 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)

Aggregations

SegmentedInputImageStream (org.dcm4che3.imageio.stream.SegmentedInputImageStream)3 PatchJPEGLSImageInputStream (org.dcm4che3.imageio.codec.jpeg.PatchJPEGLSImageInputStream)2 FileImageInputStream (javax.imageio.stream.FileImageInputStream)1 ImageInputStream (javax.imageio.stream.ImageInputStream)1 BulkData (org.dcm4che3.data.BulkData)1 BytesWithImageImageDescriptor (org.dcm4che3.imageio.codec.BytesWithImageImageDescriptor)1 ImageDescriptor (org.dcm4che3.imageio.codec.ImageDescriptor)1 EncapsulatedPixelDataImageInputStream (org.dcm4che3.imageio.stream.EncapsulatedPixelDataImageInputStream)1 ImageInputStreamAdapter (org.dcm4che3.imageio.stream.ImageInputStreamAdapter)1 DicomInputStream (org.dcm4che3.io.DicomInputStream)1