comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 1781:5ad4e4d92ecb

AcceptMediaDispatcher bootstrap
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Nov 2015 17:46:32 +0100
parents 613df4362575
children 2dbf25006f88
comparison
equal deleted inserted replaced
1780:94990da8710e 1781:5ad4e4d92ecb
257 call.GetOutput().AnswerJson(result); 257 call.GetOutput().AnswerJson(result);
258 } 258 }
259 } 259 }
260 260
261 261
262 static void AnswerImage(RestApiGetCall& call,
263 ParsedDicomFile& dicom,
264 unsigned int frame,
265 ImageExtractionMode mode)
266 {
267 typedef std::vector<std::string> MediaRanges;
268
269 // Get the HTTP "Accept" header, if any
270 std::string accept = call.GetHttpHeader("accept", "*/*");
271
272 MediaRanges mediaRanges;
273 Toolbox::TokenizeString(mediaRanges, accept, ',');
274
275 for (MediaRanges::const_reverse_iterator it = mediaRanges.rbegin();
276 it != mediaRanges.rend(); ++it)
277 {
278 }
279
280 throw OrthancException(ErrorCode_NotAcceptable);
281
282 std::string image;
283 dicom.ExtractPngImage(image, frame, mode);
284 call.GetOutput().AnswerBuffer(image, "image/png");
285 }
286
287
262 template <enum ImageExtractionMode mode> 288 template <enum ImageExtractionMode mode>
263 static void GetImage(RestApiGetCall& call) 289 static void GetImage(RestApiGetCall& call)
264 { 290 {
265 ServerContext& context = OrthancRestApi::GetContext(call); 291 ServerContext& context = OrthancRestApi::GetContext(call);
266 292
275 { 301 {
276 return; 302 return;
277 } 303 }
278 304
279 std::string publicId = call.GetUriComponent("id", ""); 305 std::string publicId = call.GetUriComponent("id", "");
280 std::string dicomContent, png; 306 std::string dicomContent;
281 context.ReadFile(dicomContent, publicId, FileContentType_Dicom); 307 context.ReadFile(dicomContent, publicId, FileContentType_Dicom);
282 308
283 ParsedDicomFile dicom(dicomContent); 309 ParsedDicomFile dicom(dicomContent);
284 310
285 try 311 try
286 { 312 {
287 dicom.ExtractPngImage(png, frame, mode); 313 AnswerImage(call, dicom, frame, mode);
288 call.GetOutput().AnswerBuffer(png, "image/png");
289 } 314 }
290 catch (OrthancException& e) 315 catch (OrthancException& e)
291 { 316 {
292 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange) 317 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange)
293 { 318 {