Mercurial > hg > orthanc
annotate Core/DicomParsing/MemoryBufferTranscoder.cpp @ 3926:2910b0d30fe0 transcoding
Allow concurrent calls to the custom image decoders provided by the plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 14 May 2020 07:37:44 +0200 |
parents | 1f71c2f20e16 |
children | 7dc5e7e0045d |
rev | line source |
---|---|
3893 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
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 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeaders.h" | |
35 #include "MemoryBufferTranscoder.h" | |
36 | |
37 #include "../OrthancException.h" | |
38 #include "FromDcmtkBridge.h" | |
39 | |
40 namespace Orthanc | |
41 { | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
42 MemoryBufferTranscoder::MemoryBufferTranscoder() |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
43 { |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
44 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
45 useDcmtk_ = true; |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
46 #else |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
47 useDcmtk_ = false; |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
48 #endif |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
49 } |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
50 |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
51 |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
52 void MemoryBufferTranscoder::SetDcmtkUsed(bool used) |
3893 | 53 { |
54 #if ORTHANC_ENABLE_DCMTK_TRANSCODING != 1 | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
55 if (useDcmtk) |
3893 | 56 { |
57 throw OrthancException(ErrorCode_NotImplemented, | |
58 "Orthanc was built without support for DMCTK transcoding"); | |
59 } | |
60 #endif | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
61 |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
62 useDcmtk_ = used; |
3893 | 63 } |
64 | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
65 |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
66 bool MemoryBufferTranscoder::TranscodeParsedToBuffer( |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
67 std::string& target /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
68 DicomTransferSyntax& sourceSyntax /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
69 bool& hasSopInstanceUidChanged /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
70 DcmFileFormat& dicom /* in, possibly modified */, |
3910 | 71 DicomTransferSyntax targetSyntax, |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
72 bool allowNewSopInstanceUid) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
73 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
74 if (dicom.getDataset() == NULL) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
75 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
76 throw OrthancException(ErrorCode_InternalError); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
77 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
78 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
79 std::string source; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
80 FromDcmtkBridge::SaveToMemoryBuffer(source, *dicom.getDataset()); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
81 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
82 const void* data = source.empty() ? NULL : source.c_str(); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
83 |
3910 | 84 std::set<DicomTransferSyntax> tmp; |
85 tmp.insert(targetSyntax); | |
86 | |
87 DicomTransferSyntax targetSyntax2; | |
88 bool success = Transcode(target, sourceSyntax, targetSyntax2, hasSopInstanceUidChanged, | |
89 data, source.size(), tmp, allowNewSopInstanceUid); | |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
90 |
3910 | 91 if (success && |
92 targetSyntax != targetSyntax2) | |
93 { | |
94 throw OrthancException(ErrorCode_InternalError); | |
95 } | |
96 | |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
97 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 |
3910 | 98 if (!success && |
99 useDcmtk_ && | |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
100 dcmtk_.TranscodeParsedToBuffer( |
3910 | 101 target, sourceSyntax, hasSopInstanceUidChanged, |
102 dicom, targetSyntax, allowNewSopInstanceUid)) | |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
103 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
104 success = true; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
105 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
106 #endif |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
107 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
108 return success; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
109 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
110 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
111 |
3907
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
112 IDicomTranscoder::TranscodedDicom* MemoryBufferTranscoder::TranscodeToParsed( |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
113 DcmFileFormat& dicom /* in, possibly modified */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
114 const void* buffer /* in, same DICOM file as "dicom" */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
115 size_t size, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
116 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
117 bool allowNewSopInstanceUid) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
118 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
119 DicomTransferSyntax sourceSyntax, targetSyntax; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
120 bool hasSopInstanceUidChanged; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
121 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
122 std::string target; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
123 if (Transcode(target, sourceSyntax, targetSyntax, hasSopInstanceUidChanged, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
124 buffer, size, allowedSyntaxes, allowNewSopInstanceUid)) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
125 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
126 const void* data = target.empty() ? NULL : target.c_str(); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
127 return IDicomTranscoder::TranscodedDicom::CreateFromInternal( |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
128 FromDcmtkBridge::LoadFromMemoryBuffer(data, target.size()), hasSopInstanceUidChanged); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
129 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
130 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
131 else if (useDcmtk_) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
132 { |
3907
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
133 return dcmtk_.TranscodeToParsed(dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid); |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
134 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
135 #endif |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
136 else |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
137 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
138 return NULL; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
139 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
140 } |
3893 | 141 } |