comparison OrthancServer/ServerContext.cpp @ 3930:b99acc213937 transcoding

transcoder plugins and GDCM transcoding are working
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 14 May 2020 19:20:40 +0200
parents 4cdc875510d1
children e6606d3ec892
comparison
equal deleted inserted replaced
3929:7dc5e7e0045d 3930:b99acc213937
530 { 530 {
531 std::set<DicomTransferSyntax> syntaxes; 531 std::set<DicomTransferSyntax> syntaxes;
532 syntaxes.insert(option); 532 syntaxes.insert(option);
533 533
534 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded( 534 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded(
535 GetTranscoder().TranscodeToParsed(dicom.GetParsedDicomFile().GetDcmtkObject(), 535 TranscodeToParsed(dicom.GetParsedDicomFile().GetDcmtkObject(),
536 dicom.GetBufferData(), dicom.GetBufferSize(), 536 dicom.GetBufferData(), dicom.GetBufferSize(),
537 syntaxes, true /* allow new SOP instance UID */)); 537 syntaxes, true /* allow new SOP instance UID */));
538 538
539 if (transcoded.get() == NULL) 539 if (transcoded.get() == NULL)
540 { 540 {
541 // Cannot transcode => store the original file 541 // Cannot transcode => store the original file
542 return StoreAfterTranscoding(resultPublicId, dicom, mode); 542 return StoreAfterTranscoding(resultPublicId, dicom, mode);
543 } 543 }
1170 1170
1171 return NULL; 1171 return NULL;
1172 } 1172 }
1173 1173
1174 1174
1175 IDicomTranscoder& ServerContext::GetTranscoder()
1176 {
1177 IDicomTranscoder* transcoder = dcmtkTranscoder_.get();
1178
1179 #if ORTHANC_ENABLE_PLUGINS == 1
1180 if (HasPlugins())
1181 {
1182 transcoder = &GetPlugins();
1183 }
1184 #endif
1185
1186 if (transcoder == NULL)
1187 {
1188 throw OrthancException(ErrorCode_InternalError);
1189 }
1190 else
1191 {
1192 return *transcoder;
1193 }
1194 }
1195
1196
1197 ImageAccessor* ServerContext::DecodeDicomFrame(const std::string& publicId, 1175 ImageAccessor* ServerContext::DecodeDicomFrame(const std::string& publicId,
1198 unsigned int frameIndex) 1176 unsigned int frameIndex)
1199 { 1177 {
1200 // TODO => Reorder given the global parameter 1178 // TODO => Reorder given the global parameter
1201 1179
1214 return decoded.release(); 1192 return decoded.release();
1215 } 1193 }
1216 else 1194 else
1217 { 1195 {
1218 LOG(INFO) << "The installed image decoding plugins cannot handle an image, " 1196 LOG(INFO) << "The installed image decoding plugins cannot handle an image, "
1219 << "fallback to the built-in decoder"; 1197 << "fallback to the built-in DCMTK decoder";
1220 } 1198 }
1221 } 1199 }
1222 #endif 1200 #endif
1223 1201
1224 { 1202 {
1246 return decoded.release(); 1224 return decoded.release();
1247 } 1225 }
1248 else 1226 else
1249 { 1227 {
1250 LOG(INFO) << "The installed image decoding plugins cannot handle an image, " 1228 LOG(INFO) << "The installed image decoding plugins cannot handle an image, "
1251 << "fallback to the built-in decoder"; 1229 << "fallback to the built-in DCMTK decoder";
1252 } 1230 }
1253 } 1231 }
1254 #endif 1232 #endif
1255 1233
1256 return DicomImageDecoder::Decode(dicom.GetParsedDicomFile(), frameIndex); 1234 return DicomImageDecoder::Decode(dicom.GetParsedDicomFile(), frameIndex);
1273 connection.Store(sopClassUid, sopInstanceUid, data, dicom.size(), 1251 connection.Store(sopClassUid, sopInstanceUid, data, dicom.size(),
1274 hasMoveOriginator, moveOriginatorAet, moveOriginatorId); 1252 hasMoveOriginator, moveOriginatorAet, moveOriginatorId);
1275 } 1253 }
1276 else 1254 else
1277 { 1255 {
1278 connection.Transcode(sopClassUid, sopInstanceUid, GetTranscoder(), data, dicom.size(), 1256 connection.Transcode(sopClassUid, sopInstanceUid, *this, data, dicom.size(),
1279 hasMoveOriginator, moveOriginatorAet, moveOriginatorId); 1257 hasMoveOriginator, moveOriginatorAet, moveOriginatorId);
1280 } 1258 }
1281 } 1259 }
1260
1261
1262 bool ServerContext::TranscodeParsedToBuffer(std::string& target /* out */,
1263 bool& hasSopInstanceUidChanged /* out */,
1264 DcmFileFormat& dicom /* in, possibly modified */,
1265 DicomTransferSyntax targetSyntax,
1266 bool allowNewSopInstanceUid)
1267 {
1268 #if ORTHANC_ENABLE_PLUGINS == 1
1269 if (HasPlugins())
1270 {
1271 if (GetPlugins().TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom,
1272 targetSyntax, allowNewSopInstanceUid))
1273 {
1274 return true;
1275 }
1276 else
1277 {
1278 LOG(INFO) << "The installed transcoding plugins cannot handle an image, "
1279 << "fallback to the built-in DCMTK transcoder";
1280 }
1281 }
1282 #endif
1283
1284 return dcmtkTranscoder_->TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom,
1285 targetSyntax, allowNewSopInstanceUid);
1286 }
1287
1288
1289 IDicomTranscoder::TranscodedDicom*
1290 ServerContext::TranscodeToParsed(DcmFileFormat& dicom,
1291 const void* buffer,
1292 size_t size,
1293 const std::set<DicomTransferSyntax>& allowedSyntaxes,
1294 bool allowNewSopInstanceUid)
1295 {
1296 #if ORTHANC_ENABLE_PLUGINS == 1
1297 if (HasPlugins())
1298 {
1299 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded(
1300 GetPlugins().TranscodeToParsed(dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid));
1301
1302 if (transcoded.get() != NULL)
1303 {
1304 return transcoded.release();
1305 }
1306 else
1307 {
1308 LOG(INFO) << "The installed transcoding plugins cannot handle an image, "
1309 << "fallback to the built-in DCMTK transcoder";
1310 }
1311 }
1312 #endif
1313
1314 return dcmtkTranscoder_->TranscodeToParsed(
1315 dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid);
1316 }
1282 } 1317 }