# HG changeset patch # User Sebastien Jodogne # Date 1566548806 -7200 # Node ID 9222c93c0b5b519e6b8a03a092660744f7d68ce8 # Parent 8ea13bf99ff56bc4899155067e94485b7d0cb923 new file WadoRsRetrieveRendered.cpp diff -r 8ea13bf99ff5 -r 9222c93c0b5b CMakeLists.txt --- a/CMakeLists.txt Thu Aug 22 18:50:32 2019 +0200 +++ b/CMakeLists.txt Fri Aug 23 10:26:46 2019 +0200 @@ -159,6 +159,7 @@ ${CMAKE_SOURCE_DIR}/Plugin/StowRs.cpp ${CMAKE_SOURCE_DIR}/Plugin/WadoRs.cpp ${CMAKE_SOURCE_DIR}/Plugin/WadoRsRetrieveFrames.cpp + ${CMAKE_SOURCE_DIR}/Plugin/WadoRsRetrieveRendered.cpp ${CMAKE_SOURCE_DIR}/Plugin/WadoUri.cpp ${AUTOGENERATED_SOURCES} ) diff -r 8ea13bf99ff5 -r 9222c93c0b5b Plugin/Plugin.cpp --- a/Plugin/Plugin.cpp Thu Aug 22 18:50:32 2019 +0200 +++ b/Plugin/Plugin.cpp Fri Aug 23 10:26:46 2019 +0200 @@ -388,94 +388,6 @@ -static void AnswerFrameRendered(OrthancPluginRestOutput* output, - int frame, - const OrthancPluginHttpRequest* request) -{ - OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); - - if (request->method != OrthancPluginHttpMethod_Get) - { - OrthancPluginSendMethodNotAllowed(context, output, "GET"); - } - else - { - std::string instanceId; - if (LocateInstance(output, instanceId, request)) - { - Orthanc::MimeType mime = Orthanc::MimeType_Jpeg; // This is the default in DICOMweb - - for (uint32_t i = 0; i < request->headersCount; i++) - { - if (boost::iequals(request->headersKeys[i], "Accept") && - !boost::iequals(request->headersValues[i], "*/*")) - { - try - { - // TODO - Support conversion to GIF - - mime = Orthanc::StringToMimeType(request->headersValues[i]); - if (mime != Orthanc::MimeType_Png && - mime != Orthanc::MimeType_Jpeg) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); - } - } - catch (Orthanc::OrthancException&) - { - LOG(ERROR) << "Unsupported MIME type in WADO-RS rendered frame: " << request->headersValues[i]; - throw; - } - } - } - - std::map headers; - headers["Accept"] = Orthanc::EnumerationToString(mime); - - // NB: In DICOMweb, the "frame" parameter is in the range [1..N], whereas - // Orthanc uses range [0..N-1], hence the "-1" below - OrthancPlugins::MemoryBuffer buffer; - if (buffer.RestApiGet("/instances/" + instanceId + "/frames/" + - boost::lexical_cast(frame - 1) + "/preview", headers, false)) - { - OrthancPluginAnswerBuffer(context, output, buffer.GetData(), - buffer.GetSize(), Orthanc::EnumerationToString(mime)); - } - else - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, - "Inexistent frame index in this image: " + boost::lexical_cast(frame)); - } - } - else - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem, "Inexistent instance"); - } - } -} - - -void RetrieveInstanceRendered(OrthancPluginRestOutput* output, - const char* url, - const OrthancPluginHttpRequest* request) -{ - AnswerFrameRendered(output, 1 /* first frame */, request); -} - - -void RetrieveFrameRendered(OrthancPluginRestOutput* output, - const char* url, - const OrthancPluginHttpRequest* request) -{ - assert(request->groupsCount == 4); - const char* frame = request->groups[3]; - - AnswerFrameRendered(output, boost::lexical_cast(frame), request); -} - - - - static bool DisplayPerformanceWarning(OrthancPluginContext* context) { diff -r 8ea13bf99ff5 -r 9222c93c0b5b Plugin/WadoRs.h --- a/Plugin/WadoRs.h Thu Aug 22 18:50:32 2019 +0200 +++ b/Plugin/WadoRs.h Fri Aug 23 10:26:46 2019 +0200 @@ -59,3 +59,11 @@ void RetrieveFrames(OrthancPluginRestOutput* output, const char* url, const OrthancPluginHttpRequest* request); + +void RetrieveInstanceRendered(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request); + +void RetrieveFrameRendered(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request); diff -r 8ea13bf99ff5 -r 9222c93c0b5b Plugin/WadoRsRetrieveRendered.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugin/WadoRsRetrieveRendered.cpp Fri Aug 23 10:26:46 2019 +0200 @@ -0,0 +1,110 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2019 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + **/ + +#include "WadoRs.h" + +#include + +#include + +static void AnswerFrameRendered(OrthancPluginRestOutput* output, + int frame, + const OrthancPluginHttpRequest* request) +{ + OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); + + if (request->method != OrthancPluginHttpMethod_Get) + { + OrthancPluginSendMethodNotAllowed(context, output, "GET"); + } + else + { + std::string instanceId; + if (LocateInstance(output, instanceId, request)) + { + Orthanc::MimeType mime = Orthanc::MimeType_Jpeg; // This is the default in DICOMweb + + for (uint32_t i = 0; i < request->headersCount; i++) + { + if (boost::iequals(request->headersKeys[i], "Accept") && + !boost::iequals(request->headersValues[i], "*/*")) + { + try + { + // TODO - Support conversion to GIF + + mime = Orthanc::StringToMimeType(request->headersValues[i]); + if (mime != Orthanc::MimeType_Png && + mime != Orthanc::MimeType_Jpeg) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + } + catch (Orthanc::OrthancException&) + { + LOG(ERROR) << "Unsupported MIME type in WADO-RS rendered frame: " << request->headersValues[i]; + throw; + } + } + } + + std::map headers; + headers["Accept"] = Orthanc::EnumerationToString(mime); + + // NB: In DICOMweb, the "frame" parameter is in the range [1..N], whereas + // Orthanc uses range [0..N-1], hence the "-1" below + OrthancPlugins::MemoryBuffer buffer; + if (buffer.RestApiGet("/instances/" + instanceId + "/frames/" + + boost::lexical_cast(frame - 1) + "/preview", headers, false)) + { + OrthancPluginAnswerBuffer(context, output, buffer.GetData(), + buffer.GetSize(), Orthanc::EnumerationToString(mime)); + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, + "Inexistent frame index in this image: " + boost::lexical_cast(frame)); + } + } + else + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem, "Inexistent instance"); + } + } +} + + +void RetrieveInstanceRendered(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) +{ + AnswerFrameRendered(output, 1 /* first frame */, request); +} + + +void RetrieveFrameRendered(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) +{ + assert(request->groupsCount == 4); + const char* frame = request->groups[3]; + + AnswerFrameRendered(output, boost::lexical_cast(frame), request); +}