Mercurial > hg > orthanc
annotate Plugins/Samples/GdcmDecoder/GdcmDecoderCache.cpp @ 3933:f67b48833a4f transcoding
new option "Throttling" to the GDCM plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 15 May 2020 12:25:36 +0200 |
parents | 7e33516965f8 |
children |
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 |
26 namespace OrthancPlugins | |
27 { | |
3915
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3768
diff
changeset
|
28 std::string GdcmDecoderCache::ComputeMd5(const void* dicom, |
1834 | 29 size_t size) |
30 { | |
31 std::string result; | |
32 | |
3915
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3768
diff
changeset
|
33 char* md5 = OrthancPluginComputeMd5(OrthancPlugins::GetGlobalContext(), dicom, size); |
1834 | 34 |
35 if (md5 == NULL) | |
36 { | |
37 throw std::runtime_error("Cannot compute MD5 hash"); | |
38 } | |
39 | |
40 bool ok = false; | |
41 try | |
42 { | |
43 result.assign(md5); | |
44 ok = true; | |
45 } | |
46 catch (...) | |
47 { | |
48 } | |
49 | |
3915
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3768
diff
changeset
|
50 OrthancPluginFreeString(OrthancPlugins::GetGlobalContext(), md5); |
1834 | 51 |
52 if (!ok) | |
53 { | |
54 throw std::runtime_error("Not enough memory"); | |
55 } | |
56 else | |
57 { | |
58 return result; | |
59 } | |
60 } | |
61 | |
62 | |
3915
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3768
diff
changeset
|
63 OrthancImage* GdcmDecoderCache::Decode(const void* dicom, |
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3768
diff
changeset
|
64 const uint32_t size, |
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3768
diff
changeset
|
65 uint32_t frameIndex) |
1834 | 66 { |
3915
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3768
diff
changeset
|
67 std::string md5 = ComputeMd5(dicom, size); |
1834 | 68 |
69 // First check whether the previously decoded image is the same | |
70 // as this one | |
71 { | |
72 boost::mutex::scoped_lock lock(mutex_); | |
73 | |
74 if (decoder_.get() != NULL && | |
75 size_ == size && | |
76 md5_ == md5) | |
77 { | |
78 // This is the same image: Reuse the previous decoding | |
3915
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3768
diff
changeset
|
79 return new OrthancImage(decoder_->Decode(frameIndex)); |
1834 | 80 } |
81 } | |
82 | |
83 // 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
|
84 std::unique_ptr<GdcmImageDecoder> decoder(new GdcmImageDecoder(dicom, size)); |
3915
7e33516965f8
merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3768
diff
changeset
|
85 std::unique_ptr<OrthancImage> image(new OrthancImage(decoder->Decode(frameIndex))); |
1834 | 86 |
87 { | |
88 // Cache the newly created decoder for further use | |
89 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
|
90 decoder_.reset(decoder.release()); |
1834 | 91 size_ = size; |
92 md5_ = md5; | |
93 } | |
94 | |
1837 | 95 return image.release(); |
1834 | 96 } |
97 } |