Mercurial > hg > orthanc
annotate Plugins/Samples/GdcmDecoder/GdcmDecoderCache.cpp @ 3038:53d583d2c775 db-changes
removing IDatabaseWrapper::LookupIdentifier()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 19 Dec 2018 18:06:46 +0100 |
parents | 878b59270859 |
children | 4e43e67f8ecf |
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 |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
5 * Copyright (C) 2017-2018 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 | |
24 #include "OrthancImageWrapper.h" | |
25 | |
26 namespace OrthancPlugins | |
27 { | |
28 std::string GdcmDecoderCache::ComputeMd5(OrthancPluginContext* context, | |
29 const void* dicom, | |
30 size_t size) | |
31 { | |
32 std::string result; | |
33 | |
34 char* md5 = OrthancPluginComputeMd5(context, dicom, size); | |
35 | |
36 if (md5 == NULL) | |
37 { | |
38 throw std::runtime_error("Cannot compute MD5 hash"); | |
39 } | |
40 | |
41 bool ok = false; | |
42 try | |
43 { | |
44 result.assign(md5); | |
45 ok = true; | |
46 } | |
47 catch (...) | |
48 { | |
49 } | |
50 | |
51 OrthancPluginFreeString(context, md5); | |
52 | |
53 if (!ok) | |
54 { | |
55 throw std::runtime_error("Not enough memory"); | |
56 } | |
57 else | |
58 { | |
59 return result; | |
60 } | |
61 } | |
62 | |
63 | |
1837 | 64 OrthancImageWrapper* GdcmDecoderCache::Decode(OrthancPluginContext* context, |
65 const void* dicom, | |
66 const uint32_t size, | |
67 uint32_t frameIndex) | |
1834 | 68 { |
69 std::string md5 = ComputeMd5(context, dicom, size); | |
70 | |
71 // First check whether the previously decoded image is the same | |
72 // as this one | |
73 { | |
74 boost::mutex::scoped_lock lock(mutex_); | |
75 | |
76 if (decoder_.get() != NULL && | |
77 size_ == size && | |
78 md5_ == md5) | |
79 { | |
80 // 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
|
81 return new OrthancImageWrapper(context, decoder_->Decode(context, frameIndex)); |
1834 | 82 } |
83 } | |
84 | |
85 // This is not the same image | |
86 std::auto_ptr<GdcmImageDecoder> decoder(new GdcmImageDecoder(dicom, size)); | |
1840
859224214616
simplification of the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1837
diff
changeset
|
87 std::auto_ptr<OrthancImageWrapper> image(new OrthancImageWrapper(context, decoder->Decode(context, frameIndex))); |
1834 | 88 |
89 { | |
90 // Cache the newly created decoder for further use | |
91 boost::mutex::scoped_lock lock(mutex_); | |
92 decoder_ = decoder; | |
93 size_ = size; | |
94 md5_ = md5; | |
95 } | |
96 | |
1837 | 97 return image.release(); |
1834 | 98 } |
99 } |