Mercurial > hg > orthanc
comparison Plugins/Samples/GdcmDecoder/GdcmDecoderCache.cpp @ 3915:7e33516965f8 transcoding
merging sample GDCM decoder and Orthanc Web viewer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 11 May 2020 15:13:16 +0200 |
parents | 6110a4995ace |
children |
comparison
equal
deleted
inserted
replaced
3914:e14b5a7a0f75 | 3915:7e33516965f8 |
---|---|
20 | 20 |
21 | 21 |
22 #include "GdcmDecoderCache.h" | 22 #include "GdcmDecoderCache.h" |
23 | 23 |
24 #include "../../../Core/Compatibility.h" | 24 #include "../../../Core/Compatibility.h" |
25 #include "OrthancImageWrapper.h" | |
26 | 25 |
27 namespace OrthancPlugins | 26 namespace OrthancPlugins |
28 { | 27 { |
29 std::string GdcmDecoderCache::ComputeMd5(OrthancPluginContext* context, | 28 std::string GdcmDecoderCache::ComputeMd5(const void* dicom, |
30 const void* dicom, | |
31 size_t size) | 29 size_t size) |
32 { | 30 { |
33 std::string result; | 31 std::string result; |
34 | 32 |
35 char* md5 = OrthancPluginComputeMd5(context, dicom, size); | 33 char* md5 = OrthancPluginComputeMd5(OrthancPlugins::GetGlobalContext(), dicom, size); |
36 | 34 |
37 if (md5 == NULL) | 35 if (md5 == NULL) |
38 { | 36 { |
39 throw std::runtime_error("Cannot compute MD5 hash"); | 37 throw std::runtime_error("Cannot compute MD5 hash"); |
40 } | 38 } |
47 } | 45 } |
48 catch (...) | 46 catch (...) |
49 { | 47 { |
50 } | 48 } |
51 | 49 |
52 OrthancPluginFreeString(context, md5); | 50 OrthancPluginFreeString(OrthancPlugins::GetGlobalContext(), md5); |
53 | 51 |
54 if (!ok) | 52 if (!ok) |
55 { | 53 { |
56 throw std::runtime_error("Not enough memory"); | 54 throw std::runtime_error("Not enough memory"); |
57 } | 55 } |
60 return result; | 58 return result; |
61 } | 59 } |
62 } | 60 } |
63 | 61 |
64 | 62 |
65 OrthancImageWrapper* GdcmDecoderCache::Decode(OrthancPluginContext* context, | 63 OrthancImage* GdcmDecoderCache::Decode(const void* dicom, |
66 const void* dicom, | 64 const uint32_t size, |
67 const uint32_t size, | 65 uint32_t frameIndex) |
68 uint32_t frameIndex) | |
69 { | 66 { |
70 std::string md5 = ComputeMd5(context, dicom, size); | 67 std::string md5 = ComputeMd5(dicom, size); |
71 | 68 |
72 // First check whether the previously decoded image is the same | 69 // First check whether the previously decoded image is the same |
73 // as this one | 70 // as this one |
74 { | 71 { |
75 boost::mutex::scoped_lock lock(mutex_); | 72 boost::mutex::scoped_lock lock(mutex_); |
77 if (decoder_.get() != NULL && | 74 if (decoder_.get() != NULL && |
78 size_ == size && | 75 size_ == size && |
79 md5_ == md5) | 76 md5_ == md5) |
80 { | 77 { |
81 // This is the same image: Reuse the previous decoding | 78 // This is the same image: Reuse the previous decoding |
82 return new OrthancImageWrapper(context, decoder_->Decode(context, frameIndex)); | 79 return new OrthancImage(decoder_->Decode(frameIndex)); |
83 } | 80 } |
84 } | 81 } |
85 | 82 |
86 // This is not the same image | 83 // This is not the same image |
87 std::unique_ptr<GdcmImageDecoder> decoder(new GdcmImageDecoder(dicom, size)); | 84 std::unique_ptr<GdcmImageDecoder> decoder(new GdcmImageDecoder(dicom, size)); |
88 std::unique_ptr<OrthancImageWrapper> image(new OrthancImageWrapper(context, decoder->Decode(context, frameIndex))); | 85 std::unique_ptr<OrthancImage> image(new OrthancImage(decoder->Decode(frameIndex))); |
89 | 86 |
90 { | 87 { |
91 // Cache the newly created decoder for further use | 88 // Cache the newly created decoder for further use |
92 boost::mutex::scoped_lock lock(mutex_); | 89 boost::mutex::scoped_lock lock(mutex_); |
93 decoder_.reset(decoder.release()); | 90 decoder_.reset(decoder.release()); |