comparison OrthancServer/ServerContext.cpp @ 3906:f0dd5ded8927 transcoding

refactoring using IDicomTranscoder::TranscodedDicom
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 08 May 2020 11:16:16 +0200
parents c62f84c7eda9
children 1f71c2f20e16
comparison
equal deleted inserted replaced
3905:061f3d031b5d 3906:f0dd5ded8927
1153 } 1153 }
1154 } 1154 }
1155 } 1155 }
1156 1156
1157 1157
1158 bool ServerContext::Transcode(std::string& target, 1158 bool ServerContext::Transcode(std::string& target /* out */,
1159 bool& hasSopInstanceUidChanged, 1159 DicomTransferSyntax& sourceSyntax /* out */,
1160 DicomTransferSyntax& targetSyntax /* out */,
1161 bool& hasSopInstanceUidChanged /* out */,
1160 ParsedDicomFile& dicom, // Possibly modified 1162 ParsedDicomFile& dicom, // Possibly modified
1161 const std::set<DicomTransferSyntax>& allowedSyntaxes, 1163 const std::set<DicomTransferSyntax>& allowedSyntaxes,
1162 bool allowNewSopInstanceUid) 1164 bool allowNewSopInstanceUid)
1163 { 1165 {
1164 DicomTransferSyntax inputSyntax;
1165 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(inputSyntax, dicom.GetDcmtkObject()))
1166 {
1167 throw OrthancException(ErrorCode_BadFileFormat,
1168 "Cannot determine the source transfer syntax during transcoding");
1169 }
1170
1171 IDicomTranscoder* transcoder = dcmtkTranscoder_.get(); 1166 IDicomTranscoder* transcoder = dcmtkTranscoder_.get();
1172 1167
1173 #if ORTHANC_ENABLE_PLUGINS == 1 1168 #if ORTHANC_ENABLE_PLUGINS == 1
1174 if (HasPlugins()) 1169 if (HasPlugins())
1175 { 1170 {
1179 1174
1180 if (transcoder == NULL) 1175 if (transcoder == NULL)
1181 { 1176 {
1182 throw OrthancException(ErrorCode_InternalError); 1177 throw OrthancException(ErrorCode_InternalError);
1183 } 1178 }
1184 else if (transcoder->HasInplaceTranscode(inputSyntax, allowedSyntaxes)) 1179
1185 { 1180 return transcoder->TranscodeParsedToBuffer(
1186 if (transcoder->InplaceTranscode(hasSopInstanceUidChanged, dicom.GetDcmtkObject(), 1181 target, sourceSyntax, targetSyntax, hasSopInstanceUidChanged,
1187 allowedSyntaxes, allowNewSopInstanceUid)) 1182 dicom.GetDcmtkObject(), allowedSyntaxes, allowNewSopInstanceUid);
1188 {
1189 // In-place transcoding is supported and has succeeded
1190 dicom.SaveToMemoryBuffer(target);
1191 return true;
1192 }
1193 else
1194 {
1195 return false;
1196 }
1197 }
1198 else
1199 {
1200 std::string source;
1201 dicom.SaveToMemoryBuffer(source);
1202
1203 const char* data = source.empty() ? NULL : source.c_str();
1204
1205 return transcoder->TranscodeToBuffer(
1206 target, hasSopInstanceUidChanged, data, source.size(), allowedSyntaxes, allowNewSopInstanceUid);
1207 }
1208 } 1183 }
1209 } 1184 }