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;
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations