Mercurial > hg > orthanc
annotate Plugins/Samples/GdcmDecoder/GdcmDecoderCache.cpp @ 3858:3ab2d48c8f69 c-get
integration mainline->c-get
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 21 Apr 2020 16:37:25 +0200 |
parents | 6110a4995ace |
children | 7e33516965f8 |
rev | line source |
---|---|
1834 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1834 | 4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
1834 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "GdcmDecoderCache.h" | |
23 | |
3768
6110a4995ace
replacing std::auto_ptr by std::unique_ptr in GDCM sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
24 #include "../../../Core/Compatibility.h" |
1834 | 25 #include "OrthancImageWrapper.h" |
26 | |
27 namespace OrthancPlugins | |
28 { | |
29 std::string GdcmDecoderCache::ComputeMd5(OrthancPluginContext* context, | |
30 const void* dicom, | |
31 size_t size) | |
32 { | |
33 std::string result; | |
34 | |
35 char* md5 = OrthancPluginComputeMd5(context, dicom, size); | |
36 | |
37 if (md5 == NULL) | |
38 { | |
39 throw std::runtime_error("Cannot compute MD5 hash"); | |
40 } | |
41 | |
42 bool ok = false; | |
43 try | |
44 { | |
45 result.assign(md5); | |
46 ok = true; | |
47 } | |
48 catch (...) | |
49 { | |
50 } | |
51 | |
52 OrthancPluginFreeString(context, md5); | |
53 | |
54 if (!ok) | |
55 { | |
56 throw std::runtime_error("Not enough memory"); | |
57 } | |
58 else | |
59 { | |
60 return result; | |
61 } | |
62 } | |
63 | |
64 | |
1837 | 65 OrthancImageWrapper* GdcmDecoderCache::Decode(OrthancPluginContext* context, |
66 const void* dicom, | |
67 const uint32_t size, | |
68 uint32_t frameIndex) | |
1834 | 69 { |
70 std::string md5 = ComputeMd5(context, dicom, size); | |
71 | |
72 // First check whether the previously decoded image is the same | |
73 // as this one | |
74 { | |
75 boost::mutex::scoped_lock lock(mutex_); | |
76 | |
77 if (decoder_.get() != NULL && | |
78 size_ == size && | |
79 md5_ == md5) | |
80 { | |
81 // This is the same image: Reuse the previous decoding | |
1840
859224214616
simplification of the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1837
diff
changeset
|
82 return new OrthancImageWrapper(context, decoder_->Decode(context, frameIndex)); |
1834 | 83 } |
84 } | |
85 | |
86 // This is not the same image | |
3768
6110a4995ace
replacing std::auto_ptr by std::unique_ptr in GDCM sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
87 std::unique_ptr<GdcmImageDecoder> decoder(new GdcmImageDecoder(dicom, size)); |
6110a4995ace
replacing std::auto_ptr by std::unique_ptr in GDCM sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
88 std::unique_ptr<OrthancImageWrapper> image(new OrthancImageWrapper(context, decoder->Decode(context, frameIndex))); |
1834 | 89 |
90 { | |
91 // Cache the newly created decoder for further use | |
92 boost::mutex::scoped_lock lock(mutex_); | |
3768
6110a4995ace
replacing std::auto_ptr by std::unique_ptr in GDCM sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
93 decoder_.reset(decoder.release()); |
1834 | 94 size_ = size; |
95 md5_ = md5; | |
96 } | |
97 | |
1837 | 98 return image.release(); |
1834 | 99 } |
100 } |