Search in sources :

Example 1 with Transcoder

use of org.dcm4che3.imageio.codec.Transcoder in project dcm4chee-arc-light by dcm4che.

the class StoreServiceImpl method selectCompressionRule.

private ArchiveCompressionRule selectCompressionRule(Transcoder transcoder, StoreContext storeContext) {
    ImageDescriptor imageDescriptor = transcoder.getImageDescriptor();
    if (// not an image
    imageDescriptor == null)
        return null;
    if (// already compressed
    transcoder.getSourceTransferSyntaxType() != TransferSyntaxType.NATIVE)
        return null;
    StoreSession session = storeContext.getStoreSession();
    Optional<ArchiveCompressionRule> matchingRule = session.getArchiveAEExtension().compressionRules().filter(rule -> rule.match(session.getRemoteHostName(), session.getCallingAET(), session.getLocalHostName(), session.getCalledAET(), storeContext.getAttributes())).findFirst();
    if (matchingRule.isPresent()) {
        if (!imageDescriptor.isMultiframeWithEmbeddedOverlays()) {
            return matchingRule.get();
        }
        LOG.info("Compression of multi-frame image with embedded overlays not supported");
    }
    return null;
}
Also used : Templates(javax.xml.transform.Templates) SoftwareConfiguration(org.dcm4chee.arc.event.SoftwareConfiguration) Cache(org.dcm4chee.arc.Cache) LoggerFactory(org.slf4j.LoggerFactory) JSONWriter(org.dcm4che3.json.JSONWriter) LeadingCFindSCPQueryCache(org.dcm4chee.arc.LeadingCFindSCPQueryCache) org.dcm4chee.arc.entity(org.dcm4chee.arc.entity) ConfigurationChanges(org.dcm4che3.conf.api.ConfigurationChanges) Transcoder(org.dcm4che3.imageio.codec.Transcoder) SupplementAssigningAuthorities(org.dcm4chee.arc.mima.SupplementAssigningAuthorities) DicomConfiguration(org.dcm4che3.conf.api.DicomConfiguration) UIDUtils(org.dcm4che3.util.UIDUtils) CFindSCUAttributeCoercion(org.dcm4chee.arc.query.scu.CFindSCUAttributeCoercion) CountingInputStream(org.dcm4che3.util.CountingInputStream) MetricsService(org.dcm4chee.arc.metrics.MetricsService) org.dcm4che3.net(org.dcm4che3.net) Collectors(java.util.stream.Collectors) EJBException(javax.ejb.EJBException) HttpServletRequestInfo(org.dcm4chee.arc.keycloak.HttpServletRequestInfo) SAXException(org.xml.sax.SAXException) MergeMWLQueryParam(org.dcm4chee.arc.MergeMWLQueryParam) ApplicationScoped(javax.enterprise.context.ApplicationScoped) org.dcm4chee.arc.store(org.dcm4chee.arc.store) org.dcm4che3.io(org.dcm4che3.io) JsonGenerator(javax.json.stream.JsonGenerator) Socket(java.net.Socket) java.util(java.util) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) MergeMWLCache(org.dcm4chee.arc.MergeMWLCache) ZipInputStream(java.util.zip.ZipInputStream) TransferSyntaxType(org.dcm4che3.imageio.codec.TransferSyntaxType) org.dcm4chee.arc.storage(org.dcm4chee.arc.storage) Function(java.util.function.Function) Inject(javax.inject.Inject) CoercionFactory(org.dcm4chee.arc.coerce.CoercionFactory) HL7Application(org.dcm4che3.net.hl7.HL7Application) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) Json(javax.json.Json) org.dcm4che3.data(org.dcm4che3.data) Event(javax.enterprise.event.Event) OutputStream(java.io.OutputStream) CFindSCU(org.dcm4chee.arc.query.scu.CFindSCU) org.dcm4chee.arc.conf(org.dcm4chee.arc.conf) Logger(org.slf4j.Logger) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) ImageDescriptor(org.dcm4che3.imageio.codec.ImageDescriptor) StringUtils(org.dcm4che3.util.StringUtils) Consumer(java.util.function.Consumer) UnparsedHL7Message(org.dcm4che3.net.hl7.UnparsedHL7Message) InputStream(java.io.InputStream) ImageDescriptor(org.dcm4che3.imageio.codec.ImageDescriptor)

Example 2 with Transcoder

use of org.dcm4che3.imageio.codec.Transcoder in project dcm4chee-arc-light by dcm4che.

the class StoreServiceImpl method writeToStorage.

private void writeToStorage(StoreContext ctx, InputStream data) throws DicomServiceException {
    String receiveTranferSyntax = ctx.getReceiveTranferSyntax();
    ArchiveAEExtension arcAE = ctx.getStoreSession().getArchiveAEExtension();
    ArchiveDeviceExtension arcDev = arcAE.getArchiveDeviceExtension();
    try (Transcoder transcoder = receiveTranferSyntax != null ? new Transcoder(data, receiveTranferSyntax) : new Transcoder(data)) {
        ctx.setReceiveTransferSyntax(transcoder.getSourceTransferSyntax());
        transcoder.setIncludeBulkData(DicomInputStream.IncludeBulkData.URI);
        transcoder.setBulkDataDescriptor(arcAE.getBulkDataDescriptor());
        transcoder.setPixelDataBulkDataURI("");
        transcoder.setConcatenateBulkDataFiles(true);
        transcoder.setBulkDataDirectory(arcAE.getBulkDataSpoolDirectoryFile());
        transcoder.setIncludeFileMetaInformation(true);
        transcoder.setIncludeImplementationVersionName(arcDev.isStoreImplementationVersionName());
        transcoder.setDeleteBulkDataFiles(true);
        transcoder.transcode(new TranscoderHandler(ctx));
    } catch (StorageException e) {
        LOG.warn("{}: Failed to store received object:\n", ctx.getStoreSession(), e);
        throw new DicomServiceException(Status.OutOfResources, e);
    } catch (DicomStreamException e) {
        LOG.warn("{}: Failed to parse received object:\n", ctx.getStoreSession(), e);
        throw new DicomServiceException(FAILED_TO_PARSE_DICOM_STREAM, e);
    } catch (Throwable e) {
        LOG.warn("{}: Failed to store received object:\n", ctx.getStoreSession(), e);
        throw new DicomServiceException(Status.ProcessingFailure, e);
    }
}
Also used : Transcoder(org.dcm4che3.imageio.codec.Transcoder) DicomServiceException(org.dcm4che3.net.service.DicomServiceException)

Example 3 with Transcoder

use of org.dcm4che3.imageio.codec.Transcoder in project dcm4chee-arc-light by dcm4che.

the class RetrieveTaskImpl method store.

private void store(InstanceLocations inst, Association storeas, Collection<InstanceLocations> outstandingRSP) {
    CStoreRSPHandler rspHandler = new CStoreRSPHandler(inst, storeas, outstandingRSP);
    String iuid = inst.getSopInstanceUID();
    String cuid = inst.getSopClassUID();
    int priority = ctx.getPriority();
    Set<String> tsuids = storeas.getTransferSyntaxesFor(cuid);
    try {
        RetrieveService service = ctx.getRetrieveService();
        try (Transcoder transcoder = service.openTranscoder(ctx, inst, tsuids, false)) {
            String tsuid = transcoder.getDestinationTransferSyntax();
            AttributesCoercion coerce;
            List<ArchiveAttributeCoercion2> coercions = service.getArchiveAttributeCoercions(ctx, inst);
            if (coercions.isEmpty()) {
                ArchiveAttributeCoercion rule = service.getArchiveAttributeCoercion(ctx, inst);
                if (rule != null) {
                    transcoder.setNullifyPixelData(rule.isNullifyPixelData());
                }
                coerce = service.getAttributesCoercion(ctx, inst, rule);
            } else {
                transcoder.setNullifyPixelData(ArchiveAttributeCoercion2.containsScheme(coercions, ArchiveAttributeCoercion2.NULLIFY_PIXEL_DATA));
                coerce = service.getAttributesCoercion(ctx, inst, coercions);
            }
            iuid = coerce.remapUID(iuid);
            TranscoderDataWriter data = new TranscoderDataWriter(transcoder, coerce);
            outstandingRSP.add(inst);
            long startTime = System.nanoTime();
            if (ctx.getMoveOriginatorAETitle() != null) {
                storeas.cstore(cuid, iuid, priority, ctx.getMoveOriginatorAETitle(), ctx.getMoveOriginatorMessageID(), data, tsuid, rspHandler);
            } else {
                storeas.cstore(cuid, iuid, priority, data, tsuid, rspHandler);
            }
            service.getMetricsService().acceptDataRate("send-to-" + storeas.getRemoteAET(), data.getCount(), startTime);
        }
    } catch (Exception e) {
        outstandingRSP.remove(inst);
        ctx.incrementFailed();
        ctx.addFailedSOPInstanceUID(iuid);
        LOG.warn("{}: failed to send {} to {}:", rqas != null ? rqas : storeas, inst, ctx.getDestinationAETitle(), e);
    }
}
Also used : Transcoder(org.dcm4che3.imageio.codec.Transcoder) ArchiveAttributeCoercion(org.dcm4chee.arc.conf.ArchiveAttributeCoercion) IOException(java.io.IOException) RetrieveService(org.dcm4chee.arc.retrieve.RetrieveService) ArchiveAttributeCoercion2(org.dcm4chee.arc.conf.ArchiveAttributeCoercion2) AttributesCoercion(org.dcm4che3.data.AttributesCoercion)

Example 4 with Transcoder

use of org.dcm4che3.imageio.codec.Transcoder in project dcm4chee-arc-light by dcm4che.

the class RetrieveServiceImpl method openTranscoder.

@Override
public Transcoder openTranscoder(RetrieveContext ctx, InstanceLocations inst, Collection<String> tsuids, boolean fmi) throws IOException {
    removeUnsupportedTransferSyntax(inst, tsuids);
    LocationInputStream locationInputStream = openLocationInputStream(ctx, inst);
    Transcoder transcoder = new Transcoder(toDicomInputStream(locationInputStream));
    transcoder.setIncludeBulkData(DicomInputStream.IncludeBulkData.URI);
    ArchiveAEExtension arcAE = ctx.getArchiveAEExtension();
    transcoder.setBulkDataDescriptor(arcAE.getBulkDataDescriptor());
    transcoder.setBulkDataDirectory(arcAE.getBulkDataSpoolDirectoryFile());
    transcoder.setConcatenateBulkDataFiles(true);
    transcoder.setDestinationTransferSyntax(selectTransferSyntax(locationInputStream, tsuids));
    transcoder.setCloseOutputStream(false);
    transcoder.setIncludeFileMetaInformation(fmi);
    return transcoder;
}
Also used : Transcoder(org.dcm4che3.imageio.codec.Transcoder)

Example 5 with Transcoder

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

the class TranscoderTest method test.

private void test(String ifname, String ofname, final String outts, boolean fmi) throws IOException {
    final File ifile = new File("target/test-data/" + ifname);
    final File ofile = new File("target/test-out/" + ofname);
    Transcoder.Handler handler = new Transcoder.Handler() {

        @Override
        public OutputStream newOutputStream(Transcoder transcoder, Attributes dataset) throws IOException {
            return new FileOutputStream(ofile);
        }
    };
    try (Transcoder transcoder = new Transcoder(ifile)) {
        transcoder.setIncludeFileMetaInformation(fmi);
        transcoder.setIncludeBulkData(DicomInputStream.IncludeBulkData.URI);
        transcoder.setDestinationTransferSyntax(outts);
        transcoder.transcode(handler);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Attributes(org.dcm4che3.data.Attributes) File(java.io.File)

Aggregations

Transcoder (org.dcm4che3.imageio.codec.Transcoder)9 IOException (java.io.IOException)7 OutputStream (java.io.OutputStream)4 Attributes (org.dcm4che3.data.Attributes)4 FileOutputStream (java.io.FileOutputStream)2 AttributesCoercion (org.dcm4che3.data.AttributesCoercion)2 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)2 File (java.io.File)1 InputStream (java.io.InputStream)1 Socket (java.net.Socket)1 java.util (java.util)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ZipInputStream (java.util.zip.ZipInputStream)1 EJBException (javax.ejb.EJBException)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Event (javax.enterprise.event.Event)1 Inject (javax.inject.Inject)1 Json (javax.json.Json)1