Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomParsing/DcmtkTranscoder.cpp @ 4200:7112a8af0b63
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 16 Sep 2020 20:53:31 +0200 |
parents | bf7b9edf6b81 |
children | 785a2713323e |
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 | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
3893 | 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 | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
3893 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
3893 | 20 **/ |
21 | |
22 | |
23 #include "../PrecompiledHeaders.h" | |
24 #include "DcmtkTranscoder.h" | |
25 | |
26 | |
27 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG) | |
28 # error Macro ORTHANC_ENABLE_DCMTK_JPEG must be defined | |
29 #endif | |
30 | |
31 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS) | |
32 # error Macro ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS must be defined | |
33 #endif | |
34 | |
35 | |
36 #include "FromDcmtkBridge.h" | |
37 #include "../OrthancException.h" | |
38 | |
39 #include <dcmtk/dcmdata/dcdeftag.h> | |
40 #include <dcmtk/dcmjpeg/djrploss.h> // for DJ_RPLossy | |
41 #include <dcmtk/dcmjpeg/djrplol.h> // for DJ_RPLossless | |
42 #include <dcmtk/dcmjpls/djrparam.h> // for DJLSRepresentationParameter | |
43 | |
44 | |
45 namespace Orthanc | |
46 { | |
3938 | 47 static bool GetBitsStored(uint16_t& bitsStored, |
48 DcmDataset& dataset) | |
3893 | 49 { |
3938 | 50 return dataset.findAndGetUint16(DCM_BitsStored, bitsStored).good(); |
3893 | 51 } |
52 | |
53 | |
54 void DcmtkTranscoder::SetLossyQuality(unsigned int quality) | |
55 { | |
4200 | 56 if (quality == 0 || |
3893 | 57 quality > 100) |
58 { | |
3939
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
59 throw OrthancException( |
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
60 ErrorCode_ParameterOutOfRange, |
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
61 "The quality for lossy transcoding must be an integer between 1 and 100, received: " + |
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
62 boost::lexical_cast<std::string>(quality)); |
3893 | 63 } |
64 else | |
65 { | |
3939
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
66 LOG(INFO) << "Quality for lossy transcoding using DCMTK is set to: " << quality; |
3893 | 67 lossyQuality_ = quality; |
68 } | |
69 } | |
70 | |
71 | |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3946
diff
changeset
|
72 bool DcmtkTranscoder::InplaceTranscode(DicomTransferSyntax& selectedSyntax /* out */, |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
73 DcmFileFormat& dicom, |
3893 | 74 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
75 bool allowNewSopInstanceUid) | |
76 { | |
77 if (dicom.getDataset() == NULL) | |
78 { | |
79 throw OrthancException(ErrorCode_InternalError); | |
80 } | |
81 | |
82 DicomTransferSyntax syntax; | |
83 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, dicom)) | |
84 { | |
85 throw OrthancException(ErrorCode_BadFileFormat, | |
86 "Cannot determine the transfer syntax"); | |
87 } | |
88 | |
3938 | 89 uint16_t bitsStored; |
90 bool hasBitsStored = GetBitsStored(bitsStored, *dicom.getDataset()); | |
91 | |
3893 | 92 if (allowedSyntaxes.find(syntax) != allowedSyntaxes.end()) |
93 { | |
94 // No transcoding is needed | |
95 return true; | |
96 } | |
97 | |
98 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianImplicit) != allowedSyntaxes.end() && | |
99 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianImplicit, NULL)) | |
100 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
101 selectedSyntax = DicomTransferSyntax_LittleEndianImplicit; |
3893 | 102 return true; |
103 } | |
104 | |
105 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianExplicit) != allowedSyntaxes.end() && | |
106 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianExplicit, NULL)) | |
107 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
108 selectedSyntax = DicomTransferSyntax_LittleEndianExplicit; |
3893 | 109 return true; |
110 } | |
111 | |
112 if (allowedSyntaxes.find(DicomTransferSyntax_BigEndianExplicit) != allowedSyntaxes.end() && | |
113 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_BigEndianExplicit, NULL)) | |
114 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
115 selectedSyntax = DicomTransferSyntax_BigEndianExplicit; |
3893 | 116 return true; |
117 } | |
118 | |
119 if (allowedSyntaxes.find(DicomTransferSyntax_DeflatedLittleEndianExplicit) != allowedSyntaxes.end() && | |
120 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL)) | |
121 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
122 selectedSyntax = DicomTransferSyntax_DeflatedLittleEndianExplicit; |
3893 | 123 return true; |
124 } | |
125 | |
126 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 | |
127 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess1) != allowedSyntaxes.end() && | |
128 allowNewSopInstanceUid && | |
3938 | 129 (!hasBitsStored || bitsStored == 8)) |
3893 | 130 { |
131 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
132 DJ_RPLossy parameters(lossyQuality_); | |
133 | |
134 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess1, ¶meters)) | |
135 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
136 selectedSyntax = DicomTransferSyntax_JPEGProcess1; |
3893 | 137 return true; |
138 } | |
139 } | |
140 #endif | |
141 | |
142 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 | |
143 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess2_4) != allowedSyntaxes.end() && | |
144 allowNewSopInstanceUid && | |
3938 | 145 (!hasBitsStored || bitsStored <= 12)) |
3893 | 146 { |
147 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
148 DJ_RPLossy parameters(lossyQuality_); | |
149 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess2_4, ¶meters)) | |
150 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
151 selectedSyntax = DicomTransferSyntax_JPEGProcess2_4; |
3893 | 152 return true; |
153 } | |
154 } | |
155 #endif | |
156 | |
157 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 | |
3902
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
158 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess14) != allowedSyntaxes.end()) |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
159 { |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
160 // Check out "dcmjpeg/apps/dcmcjpeg.cc" |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
161 DJ_RPLossless parameters(6 /* opt_selection_value */, |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
162 0 /* opt_point_transform */); |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
163 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess14, ¶meters)) |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
164 { |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
165 selectedSyntax = DicomTransferSyntax_JPEGProcess14; |
3902
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
166 return true; |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
167 } |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
168 } |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
169 #endif |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
170 |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
171 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 |
3893 | 172 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess14SV1) != allowedSyntaxes.end()) |
173 { | |
174 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
175 DJ_RPLossless parameters(6 /* opt_selection_value */, | |
176 0 /* opt_point_transform */); | |
177 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess14SV1, ¶meters)) | |
178 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
179 selectedSyntax = DicomTransferSyntax_JPEGProcess14SV1; |
3893 | 180 return true; |
181 } | |
182 } | |
183 #endif | |
184 | |
185 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 | |
186 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGLSLossless) != allowedSyntaxes.end()) | |
187 { | |
188 // Check out "dcmjpls/apps/dcmcjpls.cc" | |
189 DJLSRepresentationParameter parameters(2 /* opt_nearlossless_deviation */, | |
190 OFTrue /* opt_useLosslessProcess */); | |
191 | |
192 /** | |
193 * WARNING: This call results in a segmentation fault if using | |
194 * the DCMTK package 3.6.2 from Ubuntu 18.04. | |
195 **/ | |
196 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossless, ¶meters)) | |
197 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
198 selectedSyntax = DicomTransferSyntax_JPEGLSLossless; |
3893 | 199 return true; |
200 } | |
201 } | |
202 #endif | |
203 | |
204 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 | |
205 if (allowNewSopInstanceUid && | |
206 allowedSyntaxes.find(DicomTransferSyntax_JPEGLSLossy) != allowedSyntaxes.end()) | |
207 { | |
208 // Check out "dcmjpls/apps/dcmcjpls.cc" | |
209 DJLSRepresentationParameter parameters(2 /* opt_nearlossless_deviation */, | |
210 OFFalse /* opt_useLosslessProcess */); | |
211 | |
212 /** | |
213 * WARNING: This call results in a segmentation fault if using | |
214 * the DCMTK package 3.6.2 from Ubuntu 18.04. | |
215 **/ | |
216 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossy, ¶meters)) | |
217 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
218 selectedSyntax = DicomTransferSyntax_JPEGLSLossy; |
3893 | 219 return true; |
220 } | |
221 } | |
222 #endif | |
223 | |
224 return false; | |
225 } | |
226 | |
227 | |
3904
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
228 bool DcmtkTranscoder::IsSupported(DicomTransferSyntax syntax) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
229 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
230 if (syntax == DicomTransferSyntax_LittleEndianImplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
231 syntax == DicomTransferSyntax_LittleEndianExplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
232 syntax == DicomTransferSyntax_BigEndianExplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
233 syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
234 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
235 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
236 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
237 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
238 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
239 if (syntax == DicomTransferSyntax_JPEGProcess1 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
240 syntax == DicomTransferSyntax_JPEGProcess2_4 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
241 syntax == DicomTransferSyntax_JPEGProcess14 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
242 syntax == DicomTransferSyntax_JPEGProcess14SV1) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
243 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
244 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
245 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
246 #endif |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
247 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
248 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
249 if (syntax == DicomTransferSyntax_JPEGLSLossless || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
250 syntax == DicomTransferSyntax_JPEGLSLossy) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
251 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
252 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
253 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
254 #endif |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
255 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
256 return false; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
257 } |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
258 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
259 |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
260 bool DcmtkTranscoder::Transcode(DicomImage& target, |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
261 DicomImage& source /* in, "GetParsed()" possibly modified */, |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
262 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
263 bool allowNewSopInstanceUid) |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
264 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
265 target.Clear(); |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
266 |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
267 DicomTransferSyntax sourceSyntax; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
268 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, source.GetParsed())) |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
269 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
270 LOG(ERROR) << "Unsupport transfer syntax for transcoding"; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
271 return false; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
272 } |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
273 |
3981
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
274 { |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
275 std::string s; |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
276 for (std::set<DicomTransferSyntax>::const_iterator |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
277 it = allowedSyntaxes.begin(); it != allowedSyntaxes.end(); ++it) |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
278 { |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
279 if (!s.empty()) |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
280 { |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
281 s += ", "; |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
282 } |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
283 |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
284 s += GetTransferSyntaxUid(*it); |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
285 } |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
286 |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
287 if (s.empty()) |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
288 { |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
289 s = "<none>"; |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
290 } |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
291 |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
292 LOG(INFO) << "DCMTK transcoding from " << GetTransferSyntaxUid(sourceSyntax) |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
293 << " to one of: " << s; |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
294 } |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
295 |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
296 #if !defined(NDEBUG) |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
297 const std::string sourceSopInstanceUid = GetSopInstanceUid(source.GetParsed()); |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
298 #endif |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
299 |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
300 DicomTransferSyntax targetSyntax; |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
301 if (allowedSyntaxes.find(sourceSyntax) != allowedSyntaxes.end()) |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
302 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
303 // No transcoding is needed |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
304 target.AcquireParsed(source); |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
305 target.AcquireBuffer(source); |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
306 return true; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
307 } |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3946
diff
changeset
|
308 else if (InplaceTranscode(targetSyntax, source.GetParsed(), |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
309 allowedSyntaxes, allowNewSopInstanceUid)) |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
310 { |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
311 // Sanity check |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
312 DicomTransferSyntax targetSyntax2; |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
313 if (FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax2, source.GetParsed()) && |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
314 targetSyntax == targetSyntax2 && |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
315 allowedSyntaxes.find(targetSyntax2) != allowedSyntaxes.end()) |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
316 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
317 target.AcquireParsed(source); |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
318 source.Clear(); |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
319 |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
320 #if !defined(NDEBUG) |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
321 // Only run the sanity check in debug mode |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3946
diff
changeset
|
322 CheckTranscoding(target, sourceSyntax, sourceSopInstanceUid, |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
323 allowedSyntaxes, allowNewSopInstanceUid); |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
324 #endif |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
325 |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
326 return true; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
327 } |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
328 else |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
329 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
330 throw OrthancException(ErrorCode_InternalError); |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
331 } |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
332 } |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
333 else |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
334 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
335 // Cannot transcode |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
336 return false; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
337 } |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
338 } |
3893 | 339 } |