Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 3901:603a7b86fa5f transcoding
route "/instances/.../modify": New option "Transcode"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 May 2020 14:52:53 +0200 |
parents | 023b2a9f3aa1 |
children | d1273d7cc200 |
comparison
equal
deleted
inserted
replaced
3900:32e95d28efb2 | 3901:603a7b86fa5f |
---|---|
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 | 113 |
114 static void AnonymizeOrModifyInstance(DicomModification& modification, | 114 static void AnonymizeOrModifyInstance(DicomModification& modification, |
115 RestApiPostCall& call) | 115 RestApiPostCall& call, |
116 { | 116 bool transcode, |
117 DicomTransferSyntax targetSyntax) | |
118 { | |
119 ServerContext& context = OrthancRestApi::GetContext(call); | |
117 std::string id = call.GetUriComponent("id", ""); | 120 std::string id = call.GetUriComponent("id", ""); |
118 | 121 |
119 std::unique_ptr<ParsedDicomFile> modified; | 122 std::unique_ptr<ParsedDicomFile> modified; |
120 | 123 |
121 { | 124 { |
122 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), id); | 125 ServerContext::DicomCacheLocker locker(context, id); |
123 modified.reset(locker.GetDicom().Clone(true)); | 126 modified.reset(locker.GetDicom().Clone(true)); |
124 } | 127 } |
125 | 128 |
126 modification.Apply(*modified); | 129 modification.Apply(*modified); |
127 modified->Answer(call.GetOutput()); | 130 |
131 if (transcode) | |
132 { | |
133 std::string saved; | |
134 modified->SaveToMemoryBuffer(saved); | |
135 | |
136 std::string transcoded; | |
137 bool hasSopInstanceUidChanged; | |
138 std::set<DicomTransferSyntax> ts; | |
139 ts.insert(targetSyntax); | |
140 if (context.TranscodeMemoryBuffer(transcoded, hasSopInstanceUidChanged, saved, ts, true)) | |
141 { | |
142 call.GetOutput().AnswerBuffer(transcoded, MimeType_Dicom); | |
143 } | |
144 else | |
145 { | |
146 throw OrthancException(ErrorCode_InternalError, | |
147 "Cannot transcode to transfer syntax: " + | |
148 std::string(GetTransferSyntaxUid(targetSyntax))); | |
149 } | |
150 } | |
151 else | |
152 { | |
153 modified->Answer(call.GetOutput()); | |
154 } | |
128 } | 155 } |
129 | 156 |
130 | 157 |
131 static void ModifyInstance(RestApiPostCall& call) | 158 static void ModifyInstance(RestApiPostCall& call) |
132 { | 159 { |
151 else | 178 else |
152 { | 179 { |
153 modification.SetLevel(ResourceType_Instance); | 180 modification.SetLevel(ResourceType_Instance); |
154 } | 181 } |
155 | 182 |
156 AnonymizeOrModifyInstance(modification, call); | 183 if (request.isMember("Transcode")) |
184 { | |
185 std::string s = SerializationToolbox::ReadString(request, "Transcode"); | |
186 | |
187 DicomTransferSyntax syntax; | |
188 if (LookupTransferSyntax(syntax, s)) | |
189 { | |
190 AnonymizeOrModifyInstance(modification, call, true, syntax); | |
191 } | |
192 else | |
193 { | |
194 throw OrthancException(ErrorCode_ParameterOutOfRange, "Unknown transfer syntax: " + s); | |
195 } | |
196 } | |
197 else | |
198 { | |
199 AnonymizeOrModifyInstance(modification, call, false /* no transcoding */, | |
200 DicomTransferSyntax_LittleEndianImplicit /* unused */); | |
201 } | |
157 } | 202 } |
158 | 203 |
159 | 204 |
160 static void AnonymizeInstance(RestApiPostCall& call) | 205 static void AnonymizeInstance(RestApiPostCall& call) |
161 { | 206 { |
163 modification.SetAllowManualIdentifiers(true); | 208 modification.SetAllowManualIdentifiers(true); |
164 | 209 |
165 Json::Value request; | 210 Json::Value request; |
166 ParseAnonymizationRequest(request, modification, call); | 211 ParseAnonymizationRequest(request, modification, call); |
167 | 212 |
168 AnonymizeOrModifyInstance(modification, call); | 213 AnonymizeOrModifyInstance(modification, call, false /* no transcoding */, |
214 DicomTransferSyntax_LittleEndianImplicit /* unused */); | |
169 } | 215 } |
170 | 216 |
171 | 217 |
172 static void SubmitModificationJob(std::unique_ptr<DicomModification>& modification, | 218 static void SubmitModificationJob(std::unique_ptr<DicomModification>& modification, |
173 bool isAnonymization, | 219 bool isAnonymization, |