Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 1906:d7c1cb559431
optimization for multi-frame images
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 05 Jan 2016 17:45:27 +0100 |
parents | 8b0ee8d5e6d0 |
children | 6c73df12ca51 |
comparison
equal
deleted
inserted
replaced
1905:8b1baa2315b8 | 1906:d7c1cb559431 |
---|---|
372 catch (boost::bad_lexical_cast) | 372 catch (boost::bad_lexical_cast) |
373 { | 373 { |
374 return; | 374 return; |
375 } | 375 } |
376 | 376 |
377 std::string publicId = call.GetUriComponent("id", ""); | 377 std::auto_ptr<ImageAccessor> decoded; |
378 std::string dicomContent; | |
379 context.ReadFile(dicomContent, publicId, FileContentType_Dicom); | |
380 | 378 |
381 try | 379 try |
382 { | 380 { |
381 std::string publicId = call.GetUriComponent("id", ""); | |
382 | |
383 #if ORTHANC_PLUGINS_ENABLED == 1 | 383 #if ORTHANC_PLUGINS_ENABLED == 1 |
384 IDicomImageDecoder& decoder = context.GetPlugins(); | 384 if (context.GetPlugins().HasCustomImageDecoder()) |
385 #else | 385 { |
386 DefaultDicomImageDecoder decoder; // This is Orthanc's built-in decoder | 386 // TODO create a cache of file |
387 std::string dicomContent; | |
388 context.ReadFile(dicomContent, publicId, FileContentType_Dicom); | |
389 decoded.reset(context.GetPlugins().Decode(dicomContent.c_str(), dicomContent.size(), frame)); | |
390 } | |
387 #endif | 391 #endif |
388 | 392 |
389 std::auto_ptr<ImageAccessor> decoded(decoder.Decode(dicomContent.c_str(), dicomContent.size(), frame)); | 393 if (decoded.get() == NULL) |
390 | 394 { |
391 ImageToEncode image(decoded, mode); | 395 // Use Orthanc's built-in decoder, using the cache to speed-up |
392 | 396 // things on multi-frame images |
393 HttpContentNegociation negociation; | 397 ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId); |
394 EncodePng png(image); negociation.Register("image/png", png); | 398 decoded.reset(DicomImageDecoder::Decode(locker.GetDicom(), frame)); |
395 EncodeJpeg jpeg(image, call); negociation.Register("image/jpeg", jpeg); | |
396 | |
397 if (negociation.Apply(call.GetHttpHeaders())) | |
398 { | |
399 image.Answer(call.GetOutput()); | |
400 } | 399 } |
401 } | 400 } |
402 catch (OrthancException& e) | 401 catch (OrthancException& e) |
403 { | 402 { |
404 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange) | 403 if (e.GetErrorCode() == ErrorCode_ParameterOutOfRange) |
414 root += "../"; | 413 root += "../"; |
415 } | 414 } |
416 | 415 |
417 call.GetOutput().Redirect(root + "app/images/unsupported.png"); | 416 call.GetOutput().Redirect(root + "app/images/unsupported.png"); |
418 } | 417 } |
418 } | |
419 | |
420 ImageToEncode image(decoded, mode); | |
421 | |
422 HttpContentNegociation negociation; | |
423 EncodePng png(image); negociation.Register("image/png", png); | |
424 EncodeJpeg jpeg(image, call); negociation.Register("image/jpeg", jpeg); | |
425 | |
426 if (negociation.Apply(call.GetHttpHeaders())) | |
427 { | |
428 image.Answer(call.GetOutput()); | |
419 } | 429 } |
420 } | 430 } |
421 | 431 |
422 | 432 |
423 static void GetMatlabImage(RestApiGetCall& call) | 433 static void GetMatlabImage(RestApiGetCall& call) |