# HG changeset patch # User Sebastien Jodogne # Date 1459847222 -7200 # Node ID 533ff46e944b26eacf9f4a731ac3d1ab3c71eaa1 # Parent d90f737f2dded39355bedda905019787dd6a7862 return a single raw frame from DICOM videos diff -r d90f737f2dde -r 533ff46e944b Core/Endianness.h --- a/Core/Endianness.h Tue Apr 05 10:30:17 2016 +0200 +++ b/Core/Endianness.h Tue Apr 05 11:07:02 2016 +0200 @@ -45,7 +45,7 @@ /******************************************************************** ** WINDOWS ARCHITECTURES ** - ** On Windows, "host" will always be little-endian ("le"). + ** On Windows x86, "host" will always be little-endian ("le"). ********************************************************************/ #if defined(_WIN32) diff -r d90f737f2dde -r 533ff46e944b OrthancServer/Internals/DicomFrameIndex.cpp --- a/OrthancServer/Internals/DicomFrameIndex.cpp Tue Apr 05 10:30:17 2016 +0200 +++ b/OrthancServer/Internals/DicomFrameIndex.cpp Tue Apr 05 11:07:02 2016 +0200 @@ -37,6 +37,7 @@ #include "../../Core/DicomFormat/DicomImageInformation.h" #include "../FromDcmtkBridge.h" #include "../OrthancInitialization.h" +#include "../../Core/Endianness.h" #include "DicomImageDecoder.h" #include @@ -45,16 +46,6 @@ #include #include -#if defined(_WIN32) // Windows machines are always little-endian -# define le32toh(x) x -#elif defined(__APPLE__) -# include -# define le32toh(x) OSSwapLittleToHostInt32(x) -#else -# include -#endif - - namespace Orthanc { class DicomFrameIndex::FragmentIndex : public DicomFrameIndex::IIndex @@ -328,9 +319,38 @@ + bool DicomFrameIndex::IsVideo(const DcmDataset& dataset) + { + if (dataset.getOriginalXfer() == EXS_MPEG2MainProfileAtMainLevel || + dataset.getOriginalXfer() == EXS_MPEG2MainProfileAtHighLevel) + { + return true; + } + +#if DCMTK_VERSION_NUMBER > 360 + // New transfer syntaxes introduced in the DICOM standard after DCMTK 3.6.0 + if (dataset.getOriginalXfer() == EXS_MPEG4HighProfileLevel4 || + dataset.getOriginalXfer() == EXS_MPEG4BDcompatibleHighProfileLevel4 || + dataset.getOriginalXfer() == EXS_MPEG4HighProfileLevel4_2_For2DVideo || + dataset.getOriginalXfer() == EXS_MPEG4HighProfileLevel4_2_For3DVideo || + dataset.getOriginalXfer() == EXS_MPEG4StereoHighProfileLevel4_2) + { + return true; + } +#endif + + return false; + } + unsigned int DicomFrameIndex::GetFramesCount(DcmDataset& dataset) { + // Assume 1 frame for video transfer syntaxes + if (IsVideo(dataset)) + { + return 1; + } + const char* tmp = NULL; if (!dataset.findAndGetString(DCM_NumberOfFrames, tmp).good() || tmp == NULL) diff -r d90f737f2dde -r 533ff46e944b OrthancServer/Internals/DicomFrameIndex.h --- a/OrthancServer/Internals/DicomFrameIndex.h Tue Apr 05 10:30:17 2016 +0200 +++ b/OrthancServer/Internals/DicomFrameIndex.h Tue Apr 05 11:07:02 2016 +0200 @@ -72,6 +72,8 @@ void GetRawFrame(std::string& frame, unsigned int index) const; + static bool IsVideo(const DcmDataset& dataset); + static unsigned int GetFramesCount(DcmDataset& dataset); }; } diff -r d90f737f2dde -r 533ff46e944b OrthancServer/OrthancRestApi/OrthancRestResources.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue Apr 05 10:30:17 2016 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp Tue Apr 05 11:07:02 2016 +0200 @@ -236,28 +236,22 @@ static void ListFrames(RestApiGetCall& call) { - Json::Value instance; - if (OrthancRestApi::GetIndex(call).LookupResource(instance, call.GetUriComponent("id", ""), ResourceType_Instance)) - { - unsigned int numberOfFrames = 1; + std::string publicId = call.GetUriComponent("id", ""); - try - { - Json::Value tmp = instance["MainDicomTags"]["NumberOfFrames"]; - numberOfFrames = boost::lexical_cast(tmp.asString()); - } - catch (...) - { - } - - Json::Value result = Json::arrayValue; - for (unsigned int i = 0; i < numberOfFrames; i++) - { - result.append(i); - } - - call.GetOutput().AnswerJson(result); + unsigned int numberOfFrames; + + { + ServerContext::DicomCacheLocker locker(OrthancRestApi::GetContext(call), publicId); + numberOfFrames = locker.GetDicom().GetFramesCount(); } + + Json::Value result = Json::arrayValue; + for (unsigned int i = 0; i < numberOfFrames; i++) + { + result.append(i); + } + + call.GetOutput().AnswerJson(result); } diff -r d90f737f2dde -r 533ff46e944b OrthancServer/ParsedDicomFile.cpp --- a/OrthancServer/ParsedDicomFile.cpp Tue Apr 05 10:30:17 2016 +0200 +++ b/OrthancServer/ParsedDicomFile.cpp Tue Apr 05 11:07:02 2016 +0200 @@ -1261,4 +1261,10 @@ { pimpl_->frameIndex_.reset(NULL); } + + + unsigned int ParsedDicomFile::GetFramesCount() const + { + return DicomFrameIndex::GetFramesCount(*pimpl_->file_->getDataset()); + } } diff -r d90f737f2dde -r 533ff46e944b OrthancServer/ParsedDicomFile.h --- a/OrthancServer/ParsedDicomFile.h Tue Apr 05 10:30:17 2016 +0200 +++ b/OrthancServer/ParsedDicomFile.h Tue Apr 05 11:07:02 2016 +0200 @@ -149,6 +149,8 @@ std::string& mime, // OUT unsigned int frameId); // IN + unsigned int GetFramesCount() const; + static ParsedDicomFile* CreateFromJson(const Json::Value& value, DicomFromJsonFlags flags); };