Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomParsing/DcmtkTranscoder.cpp @ 4596:2b64cc3cea99
added OrthancPluginContentType_DicomUntilPixelData
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 17 Mar 2021 15:31:26 +0100 |
parents | d9473bd5ed43 |
children | 7053502fbf97 |
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 | |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
3893 | 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" | |
4304 | 37 #include "../Logging.h" |
3893 | 38 #include "../OrthancException.h" |
39 | |
40 #include <dcmtk/dcmdata/dcdeftag.h> | |
41 #include <dcmtk/dcmjpeg/djrploss.h> // for DJ_RPLossy | |
42 #include <dcmtk/dcmjpeg/djrplol.h> // for DJ_RPLossless | |
43 #include <dcmtk/dcmjpls/djrparam.h> // for DJLSRepresentationParameter | |
44 | |
4304 | 45 #include <boost/lexical_cast.hpp> |
46 | |
3893 | 47 |
48 namespace Orthanc | |
49 { | |
4297 | 50 DcmtkTranscoder::DcmtkTranscoder() : |
51 lossyQuality_(90) | |
52 { | |
53 } | |
54 | |
55 | |
3938 | 56 static bool GetBitsStored(uint16_t& bitsStored, |
57 DcmDataset& dataset) | |
3893 | 58 { |
3938 | 59 return dataset.findAndGetUint16(DCM_BitsStored, bitsStored).good(); |
3893 | 60 } |
61 | |
62 | |
63 void DcmtkTranscoder::SetLossyQuality(unsigned int quality) | |
64 { | |
4200 | 65 if (quality == 0 || |
3893 | 66 quality > 100) |
67 { | |
3939
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
68 throw OrthancException( |
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
69 ErrorCode_ParameterOutOfRange, |
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
70 "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
|
71 boost::lexical_cast<std::string>(quality)); |
3893 | 72 } |
73 else | |
74 { | |
3939
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
75 LOG(INFO) << "Quality for lossy transcoding using DCMTK is set to: " << quality; |
3893 | 76 lossyQuality_ = quality; |
77 } | |
78 } | |
79 | |
4297 | 80 unsigned int DcmtkTranscoder::GetLossyQuality() const |
81 { | |
82 return lossyQuality_; | |
83 } | |
84 | |
85 | |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3946
diff
changeset
|
86 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
|
87 DcmFileFormat& dicom, |
3893 | 88 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
89 bool allowNewSopInstanceUid) | |
90 { | |
91 if (dicom.getDataset() == NULL) | |
92 { | |
93 throw OrthancException(ErrorCode_InternalError); | |
94 } | |
95 | |
96 DicomTransferSyntax syntax; | |
97 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, dicom)) | |
98 { | |
99 throw OrthancException(ErrorCode_BadFileFormat, | |
100 "Cannot determine the transfer syntax"); | |
101 } | |
102 | |
3938 | 103 uint16_t bitsStored; |
104 bool hasBitsStored = GetBitsStored(bitsStored, *dicom.getDataset()); | |
105 | |
3893 | 106 if (allowedSyntaxes.find(syntax) != allowedSyntaxes.end()) |
107 { | |
108 // No transcoding is needed | |
109 return true; | |
110 } | |
111 | |
112 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianImplicit) != allowedSyntaxes.end() && | |
113 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianImplicit, NULL)) | |
114 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
115 selectedSyntax = DicomTransferSyntax_LittleEndianImplicit; |
3893 | 116 return true; |
117 } | |
118 | |
119 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianExplicit) != allowedSyntaxes.end() && | |
120 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianExplicit, NULL)) | |
121 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
122 selectedSyntax = DicomTransferSyntax_LittleEndianExplicit; |
3893 | 123 return true; |
124 } | |
125 | |
126 if (allowedSyntaxes.find(DicomTransferSyntax_BigEndianExplicit) != allowedSyntaxes.end() && | |
127 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_BigEndianExplicit, NULL)) | |
128 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
129 selectedSyntax = DicomTransferSyntax_BigEndianExplicit; |
3893 | 130 return true; |
131 } | |
132 | |
133 if (allowedSyntaxes.find(DicomTransferSyntax_DeflatedLittleEndianExplicit) != allowedSyntaxes.end() && | |
134 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL)) | |
135 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
136 selectedSyntax = DicomTransferSyntax_DeflatedLittleEndianExplicit; |
3893 | 137 return true; |
138 } | |
139 | |
140 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 | |
141 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess1) != allowedSyntaxes.end() && | |
142 allowNewSopInstanceUid && | |
3938 | 143 (!hasBitsStored || bitsStored == 8)) |
3893 | 144 { |
145 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
146 DJ_RPLossy parameters(lossyQuality_); | |
147 | |
148 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess1, ¶meters)) | |
149 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
150 selectedSyntax = DicomTransferSyntax_JPEGProcess1; |
3893 | 151 return true; |
152 } | |
153 } | |
154 #endif | |
155 | |
156 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 | |
157 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess2_4) != allowedSyntaxes.end() && | |
158 allowNewSopInstanceUid && | |
3938 | 159 (!hasBitsStored || bitsStored <= 12)) |
3893 | 160 { |
161 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
162 DJ_RPLossy parameters(lossyQuality_); | |
163 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess2_4, ¶meters)) | |
164 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
165 selectedSyntax = DicomTransferSyntax_JPEGProcess2_4; |
3893 | 166 return true; |
167 } | |
168 } | |
169 #endif | |
170 | |
171 #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
|
172 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
|
173 { |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
174 // 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
|
175 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
|
176 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
|
177 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
|
178 { |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
179 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
|
180 return true; |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
181 } |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
182 } |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
183 #endif |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
184 |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
185 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 |
3893 | 186 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess14SV1) != allowedSyntaxes.end()) |
187 { | |
188 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
189 DJ_RPLossless parameters(6 /* opt_selection_value */, | |
190 0 /* opt_point_transform */); | |
191 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess14SV1, ¶meters)) | |
192 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
193 selectedSyntax = DicomTransferSyntax_JPEGProcess14SV1; |
3893 | 194 return true; |
195 } | |
196 } | |
197 #endif | |
198 | |
199 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 | |
200 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGLSLossless) != allowedSyntaxes.end()) | |
201 { | |
202 // Check out "dcmjpls/apps/dcmcjpls.cc" | |
203 DJLSRepresentationParameter parameters(2 /* opt_nearlossless_deviation */, | |
204 OFTrue /* opt_useLosslessProcess */); | |
205 | |
206 /** | |
207 * WARNING: This call results in a segmentation fault if using | |
208 * the DCMTK package 3.6.2 from Ubuntu 18.04. | |
209 **/ | |
210 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossless, ¶meters)) | |
211 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
212 selectedSyntax = DicomTransferSyntax_JPEGLSLossless; |
3893 | 213 return true; |
214 } | |
215 } | |
216 #endif | |
217 | |
218 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 | |
219 if (allowNewSopInstanceUid && | |
220 allowedSyntaxes.find(DicomTransferSyntax_JPEGLSLossy) != allowedSyntaxes.end()) | |
221 { | |
222 // Check out "dcmjpls/apps/dcmcjpls.cc" | |
223 DJLSRepresentationParameter parameters(2 /* opt_nearlossless_deviation */, | |
224 OFFalse /* opt_useLosslessProcess */); | |
225 | |
226 /** | |
227 * WARNING: This call results in a segmentation fault if using | |
228 * the DCMTK package 3.6.2 from Ubuntu 18.04. | |
229 **/ | |
230 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossy, ¶meters)) | |
231 { | |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
232 selectedSyntax = DicomTransferSyntax_JPEGLSLossy; |
3893 | 233 return true; |
234 } | |
235 } | |
236 #endif | |
237 | |
238 return false; | |
239 } | |
240 | |
3904
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
241 bool DcmtkTranscoder::IsSupported(DicomTransferSyntax syntax) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
242 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
243 if (syntax == DicomTransferSyntax_LittleEndianImplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
244 syntax == DicomTransferSyntax_LittleEndianExplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
245 syntax == DicomTransferSyntax_BigEndianExplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
246 syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit) |
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 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
249 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
250 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
251 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
252 if (syntax == DicomTransferSyntax_JPEGProcess1 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
253 syntax == DicomTransferSyntax_JPEGProcess2_4 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
254 syntax == DicomTransferSyntax_JPEGProcess14 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
255 syntax == DicomTransferSyntax_JPEGProcess14SV1) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
256 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
257 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
258 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
259 #endif |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
260 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
261 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
262 if (syntax == DicomTransferSyntax_JPEGLSLossless || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
263 syntax == DicomTransferSyntax_JPEGLSLossy) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
264 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
265 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
266 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
267 #endif |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
268 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
269 return false; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
270 } |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
271 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
272 |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
273 bool DcmtkTranscoder::Transcode(DicomImage& target, |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
274 DicomImage& source /* in, "GetParsed()" possibly modified */, |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
275 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
276 bool allowNewSopInstanceUid) |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
277 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
278 target.Clear(); |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
279 |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
280 DicomTransferSyntax sourceSyntax; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
281 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, source.GetParsed())) |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
282 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
283 LOG(ERROR) << "Unsupport transfer syntax for transcoding"; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
284 return false; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
285 } |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
286 |
3981
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
287 { |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
288 std::string s; |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
289 for (std::set<DicomTransferSyntax>::const_iterator |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
290 it = allowedSyntaxes.begin(); it != allowedSyntaxes.end(); ++it) |
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 if (!s.empty()) |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
293 { |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
294 s += ", "; |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
295 } |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
296 |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
297 s += GetTransferSyntaxUid(*it); |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
298 } |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
299 |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
300 if (s.empty()) |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
301 { |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
302 s = "<none>"; |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
303 } |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
304 |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
305 LOG(INFO) << "DCMTK transcoding from " << GetTransferSyntaxUid(sourceSyntax) |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
306 << " to one of: " << s; |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
307 } |
31252a887f0b
info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3951
diff
changeset
|
308 |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
309 #if !defined(NDEBUG) |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
310 const std::string sourceSopInstanceUid = GetSopInstanceUid(source.GetParsed()); |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
311 #endif |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
312 |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
313 DicomTransferSyntax targetSyntax; |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
314 if (allowedSyntaxes.find(sourceSyntax) != allowedSyntaxes.end()) |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
315 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
316 // No transcoding is needed |
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 target.AcquireBuffer(source); |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
319 return true; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
320 } |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3946
diff
changeset
|
321 else if (InplaceTranscode(targetSyntax, source.GetParsed(), |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
322 allowedSyntaxes, allowNewSopInstanceUid)) |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
323 { |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
324 // Sanity check |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
325 DicomTransferSyntax targetSyntax2; |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
326 if (FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax2, source.GetParsed()) && |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
327 targetSyntax == targetSyntax2 && |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
328 allowedSyntaxes.find(targetSyntax2) != allowedSyntaxes.end()) |
3944
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 target.AcquireParsed(source); |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
331 source.Clear(); |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
332 |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
333 #if !defined(NDEBUG) |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
334 // Only run the sanity check in debug mode |
3951
5fe8c6d3212e
removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3946
diff
changeset
|
335 CheckTranscoding(target, sourceSyntax, sourceSopInstanceUid, |
3946
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
336 allowedSyntaxes, allowNewSopInstanceUid); |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
337 #endif |
1f33ed7f82e6
automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3945
diff
changeset
|
338 |
3944
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
339 return true; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
340 } |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
341 else |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
342 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
343 throw OrthancException(ErrorCode_InternalError); |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
344 } |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
345 } |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
346 else |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
347 { |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
348 // Cannot transcode |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
349 return false; |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
350 } |
aae045f802f4
preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3939
diff
changeset
|
351 } |
3893 | 352 } |