Search in sources :

Example 1 with XPEGParser

use of org.dcm4che3.imageio.codec.XPEGParser in project dcm4che by dcm4che.

the class Jpg2Dcm method convert.

private void convert(Path srcFilePath, Path destFilePath) throws Exception {
    ContentType fileType = ContentType.probe(srcFilePath);
    Attributes fileMetadata = SAXReader.parse(StreamUtils.openFileOrURL(fileType.getSampleMetadataFile(photo)));
    fileMetadata.addAll(staticMetadata);
    supplementMissingValue(fileMetadata, Tag.SOPClassUID, fileType.getSOPClassUID(photo));
    try (SeekableByteChannel channel = Files.newByteChannel(srcFilePath);
        DicomOutputStream dos = new DicomOutputStream(destFilePath.toFile())) {
        XPEGParser parser = fileType.newParser(channel);
        parser.getAttributes(fileMetadata);
        dos.writeDataset(fileMetadata.createFileMetaInformation(parser.getTransferSyntaxUID()), fileMetadata);
        dos.writeHeader(Tag.PixelData, VR.OB, -1);
        dos.writeHeader(Tag.Item, null, 0);
        if (noAPPn && parser.getPositionAfterAPPSegments() > 0) {
            copyPixelData(channel, parser.getPositionAfterAPPSegments(), dos, (byte) 0xFF, (byte) JPEG.SOI);
        } else {
            copyPixelData(channel, parser.getCodeStreamPosition(), dos);
        }
        dos.writeHeader(Tag.SequenceDelimitationItem, null, 0);
    }
    System.out.println(MessageFormat.format(rb.getString("converted"), srcFilePath, destFilePath));
}
Also used : SeekableByteChannel(java.nio.channels.SeekableByteChannel) XPEGParser(org.dcm4che3.imageio.codec.XPEGParser) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) DicomOutputStream(org.dcm4che3.io.DicomOutputStream)

Example 2 with XPEGParser

use of org.dcm4che3.imageio.codec.XPEGParser in project dcm4che by dcm4che.

the class StowRS method pixelMetadata.

private void pixelMetadata(String contentLoc, StowRSBulkdata stowRSBulkdata, Attributes metadata) {
    File bulkdataFile = stowRSBulkdata.getBulkdataFile();
    if (pixelHeader || tsuid || noApp) {
        CompressedPixelData compressedPixelData = CompressedPixelData.valueOf();
        try (FileInputStream fis = new FileInputStream(bulkdataFile)) {
            compressedPixelData.parse(fis.getChannel());
            XPEGParser parser = compressedPixelData.getParser();
            if (pixelHeader)
                parser.getAttributes(metadata);
            stowRSBulkdata.setParser(parser);
        } catch (IOException e) {
            LOG.info("Exception caught getting pixel data from file {}: {}", bulkdataFile, e.getMessage());
        }
    }
    contentLocBulkdata.put(contentLoc, stowRSBulkdata);
}
Also used : XPEGParser(org.dcm4che3.imageio.codec.XPEGParser)

Example 3 with XPEGParser

use of org.dcm4che3.imageio.codec.XPEGParser in project dcm4che by dcm4che.

the class StowRS method writeFile.

private void writeFile(String contentLocation, OutputStream out, StowChunk stowChunk) throws Exception {
    String bulkdataContentType1 = bulkdataFileContentType.getMediaType();
    StowRSBulkdata stowRSBulkdata = contentLocBulkdata.get(contentLocation);
    XPEGParser parser = stowRSBulkdata.getParser();
    if (bulkdataFileContentType.getBulkdataTypeTag() == Tag.PixelData && tsuid)
        bulkdataContentType1 = bulkdataContentType1 + "; transfer-syntax=" + parser.getTransferSyntaxUID();
    LOG.info("> Bulkdata Content Type: " + bulkdataContentType1);
    writePartHeaders(out, bulkdataContentType1, contentLocation);
    int offset = 0;
    int length = (int) stowRSBulkdata.getFileLength();
    long positionAfterAPPSegments = parser != null ? parser.getPositionAfterAPPSegments() : -1L;
    if (noApp && positionAfterAPPSegments != -1L) {
        offset = (int) positionAfterAPPSegments;
        out.write(-1);
        out.write((byte) JPEG.SOI);
    }
    length -= offset;
    out.write(Files.readAllBytes(stowRSBulkdata.getBulkdataFilePath()), offset, length);
    stowChunk.setAttributes(stowRSBulkdata.bulkdataFile.length());
}
Also used : XPEGParser(org.dcm4che3.imageio.codec.XPEGParser)

Aggregations

XPEGParser (org.dcm4che3.imageio.codec.XPEGParser)3 SeekableByteChannel (java.nio.channels.SeekableByteChannel)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 DicomOutputStream (org.dcm4che3.io.DicomOutputStream)1