Mercurial > hg > orthanc
annotate Core/DicomParsing/DcmtkTranscoder.cpp @ 3907:1555feda39e2 transcoding
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 08 May 2020 11:24:34 +0200 |
parents | f0dd5ded8927 |
children | 6762a97deabc |
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 "DcmtkTranscoder.h" | |
36 | |
37 | |
38 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG) | |
39 # error Macro ORTHANC_ENABLE_DCMTK_JPEG must be defined | |
40 #endif | |
41 | |
42 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS) | |
43 # error Macro ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS must be defined | |
44 #endif | |
45 | |
46 | |
47 #include "FromDcmtkBridge.h" | |
48 #include "../OrthancException.h" | |
49 | |
50 #include <dcmtk/dcmdata/dcdeftag.h> | |
51 #include <dcmtk/dcmjpeg/djrploss.h> // for DJ_RPLossy | |
52 #include <dcmtk/dcmjpeg/djrplol.h> // for DJ_RPLossless | |
53 #include <dcmtk/dcmjpls/djrparam.h> // for DJLSRepresentationParameter | |
54 | |
55 | |
56 namespace Orthanc | |
57 { | |
58 static uint16_t GetBitsStored(DcmDataset& dataset) | |
59 { | |
60 uint16_t bitsStored; | |
61 if (dataset.findAndGetUint16(DCM_BitsStored, bitsStored).good()) | |
62 { | |
63 return bitsStored; | |
64 } | |
65 else | |
66 { | |
67 throw OrthancException(ErrorCode_BadFileFormat, | |
68 "Missing \"Bits Stored\" tag in DICOM instance"); | |
69 } | |
70 } | |
71 | |
72 | |
73 static std::string GetSopInstanceUid(DcmDataset& dataset) | |
74 { | |
75 const char* v = NULL; | |
76 | |
77 if (dataset.findAndGetString(DCM_SOPInstanceUID, v).good() && | |
78 v != NULL) | |
79 { | |
80 return std::string(v); | |
81 } | |
82 else | |
83 { | |
84 throw OrthancException(ErrorCode_BadFileFormat, "File without SOP instance UID"); | |
85 } | |
86 } | |
87 | |
88 | |
89 static void CheckSopInstanceUid(DcmFileFormat& dicom, | |
90 const std::string& sopInstanceUid, | |
91 bool mustEqual) | |
92 { | |
93 if (dicom.getDataset() == NULL) | |
94 { | |
95 throw OrthancException(ErrorCode_InternalError); | |
96 } | |
97 | |
98 bool ok; | |
99 | |
100 if (mustEqual) | |
101 { | |
102 ok = (GetSopInstanceUid(*dicom.getDataset()) == sopInstanceUid); | |
103 } | |
104 else | |
105 { | |
106 ok = (GetSopInstanceUid(*dicom.getDataset()) != sopInstanceUid); | |
107 } | |
108 | |
109 if (!ok) | |
110 { | |
111 throw OrthancException(ErrorCode_InternalError, | |
112 mustEqual ? "The SOP instance UID has changed unexpectedly during transcoding" : | |
113 "The SOP instance UID has not changed as expected during transcoding"); | |
114 } | |
115 } | |
116 | |
117 | |
118 void DcmtkTranscoder::SetLossyQuality(unsigned int quality) | |
119 { | |
120 if (quality <= 0 || | |
121 quality > 100) | |
122 { | |
123 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
124 } | |
125 else | |
126 { | |
127 lossyQuality_ = quality; | |
128 } | |
129 } | |
130 | |
131 | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
132 bool DcmtkTranscoder::InplaceTranscode(bool& hasSopInstanceUidChanged /* out */, |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
133 DcmFileFormat& dicom, |
3893 | 134 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
135 bool allowNewSopInstanceUid) | |
136 { | |
137 if (dicom.getDataset() == NULL) | |
138 { | |
139 throw OrthancException(ErrorCode_InternalError); | |
140 } | |
141 | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
142 hasSopInstanceUidChanged = false; |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
143 |
3893 | 144 DicomTransferSyntax syntax; |
145 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, dicom)) | |
146 { | |
147 throw OrthancException(ErrorCode_BadFileFormat, | |
148 "Cannot determine the transfer syntax"); | |
149 } | |
150 | |
151 const uint16_t bitsStored = GetBitsStored(*dicom.getDataset()); | |
152 std::string sourceSopInstanceUid = GetSopInstanceUid(*dicom.getDataset()); | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
153 |
3893 | 154 if (allowedSyntaxes.find(syntax) != allowedSyntaxes.end()) |
155 { | |
156 // No transcoding is needed | |
157 return true; | |
158 } | |
159 | |
160 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianImplicit) != allowedSyntaxes.end() && | |
161 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianImplicit, NULL)) | |
162 { | |
163 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
164 return true; | |
165 } | |
166 | |
167 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianExplicit) != allowedSyntaxes.end() && | |
168 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianExplicit, NULL)) | |
169 { | |
170 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
171 return true; | |
172 } | |
173 | |
174 if (allowedSyntaxes.find(DicomTransferSyntax_BigEndianExplicit) != allowedSyntaxes.end() && | |
175 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_BigEndianExplicit, NULL)) | |
176 { | |
177 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
178 return true; | |
179 } | |
180 | |
181 if (allowedSyntaxes.find(DicomTransferSyntax_DeflatedLittleEndianExplicit) != allowedSyntaxes.end() && | |
182 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL)) | |
183 { | |
184 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
185 return true; | |
186 } | |
187 | |
188 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 | |
189 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess1) != allowedSyntaxes.end() && | |
190 allowNewSopInstanceUid && | |
191 bitsStored == 8) | |
192 { | |
193 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
194 DJ_RPLossy parameters(lossyQuality_); | |
195 | |
196 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess1, ¶meters)) | |
197 { | |
198 CheckSopInstanceUid(dicom, sourceSopInstanceUid, false); | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
199 hasSopInstanceUidChanged = true; |
3893 | 200 return true; |
201 } | |
202 } | |
203 #endif | |
204 | |
205 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 | |
206 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess2_4) != allowedSyntaxes.end() && | |
207 allowNewSopInstanceUid && | |
208 bitsStored <= 12) | |
209 { | |
210 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
211 DJ_RPLossy parameters(lossyQuality_); | |
212 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess2_4, ¶meters)) | |
213 { | |
214 CheckSopInstanceUid(dicom, sourceSopInstanceUid, false); | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
215 hasSopInstanceUidChanged = true; |
3893 | 216 return true; |
217 } | |
218 } | |
219 #endif | |
220 | |
221 #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
|
222 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
|
223 { |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
224 // 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
|
225 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
|
226 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
|
227 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
|
228 { |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
229 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
230 return true; |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
231 } |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
232 } |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
233 #endif |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
234 |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
235 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 |
3893 | 236 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess14SV1) != allowedSyntaxes.end()) |
237 { | |
238 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
239 DJ_RPLossless parameters(6 /* opt_selection_value */, | |
240 0 /* opt_point_transform */); | |
241 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess14SV1, ¶meters)) | |
242 { | |
243 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
244 return true; | |
245 } | |
246 } | |
247 #endif | |
248 | |
249 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 | |
250 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGLSLossless) != allowedSyntaxes.end()) | |
251 { | |
252 // Check out "dcmjpls/apps/dcmcjpls.cc" | |
253 DJLSRepresentationParameter parameters(2 /* opt_nearlossless_deviation */, | |
254 OFTrue /* opt_useLosslessProcess */); | |
255 | |
256 /** | |
257 * WARNING: This call results in a segmentation fault if using | |
258 * the DCMTK package 3.6.2 from Ubuntu 18.04. | |
259 **/ | |
260 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossless, ¶meters)) | |
261 { | |
262 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
263 return true; | |
264 } | |
265 } | |
266 #endif | |
267 | |
268 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 | |
269 if (allowNewSopInstanceUid && | |
270 allowedSyntaxes.find(DicomTransferSyntax_JPEGLSLossy) != allowedSyntaxes.end()) | |
271 { | |
272 // Check out "dcmjpls/apps/dcmcjpls.cc" | |
273 DJLSRepresentationParameter parameters(2 /* opt_nearlossless_deviation */, | |
274 OFFalse /* opt_useLosslessProcess */); | |
275 | |
276 /** | |
277 * WARNING: This call results in a segmentation fault if using | |
278 * the DCMTK package 3.6.2 from Ubuntu 18.04. | |
279 **/ | |
280 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossy, ¶meters)) | |
281 { | |
282 CheckSopInstanceUid(dicom, sourceSopInstanceUid, false); | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
283 hasSopInstanceUidChanged = true; |
3893 | 284 return true; |
285 } | |
286 } | |
287 #endif | |
288 | |
289 return false; | |
290 } | |
291 | |
292 | |
293 bool DcmtkTranscoder::TranscodeToBuffer(std::string& target, | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
294 bool& hasSopInstanceUidChanged /* out */, |
3893 | 295 const void* buffer, |
296 size_t size, | |
297 const std::set<DicomTransferSyntax>& allowedSyntaxes, | |
298 bool allowNewSopInstanceUid) | |
299 { | |
3907
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
300 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size)); |
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
301 if (dicom.get() == NULL) |
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
302 { |
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
303 throw OrthancException(ErrorCode_BadFileFormat); |
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
304 } |
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
305 |
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
306 std::unique_ptr<TranscodedDicom> transcoded( |
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
307 TranscodeToParsed(*dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid)); |
3893 | 308 |
309 if (transcoded.get() == NULL) | |
310 { | |
311 return false; | |
312 } | |
313 else | |
314 { | |
3907
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
315 if (transcoded->GetDicom().getDataset() == NULL) |
3893 | 316 { |
317 throw OrthancException(ErrorCode_InternalError); | |
318 } | |
319 | |
3907
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
320 FromDcmtkBridge::SaveToMemoryBuffer(target, *transcoded->GetDicom().getDataset()); |
3893 | 321 return true; |
322 } | |
323 } | |
3904
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
324 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
325 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
326 bool DcmtkTranscoder::IsSupported(DicomTransferSyntax syntax) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
327 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
328 if (syntax == DicomTransferSyntax_LittleEndianImplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
329 syntax == DicomTransferSyntax_LittleEndianExplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
330 syntax == DicomTransferSyntax_BigEndianExplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
331 syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
332 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
333 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
334 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
335 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
336 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
337 if (syntax == DicomTransferSyntax_JPEGProcess1 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
338 syntax == DicomTransferSyntax_JPEGProcess2_4 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
339 syntax == DicomTransferSyntax_JPEGProcess14 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
340 syntax == DicomTransferSyntax_JPEGProcess14SV1) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
341 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
342 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
343 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
344 #endif |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
345 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
346 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
347 if (syntax == DicomTransferSyntax_JPEGLSLossless || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
348 syntax == DicomTransferSyntax_JPEGLSLossy) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
349 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
350 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
351 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
352 #endif |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
353 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
354 return false; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
355 } |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
356 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
357 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
358 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
359 bool DcmtkTranscoder::TranscodeParsedToBuffer( |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
360 std::string& target /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
361 DicomTransferSyntax& sourceSyntax /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
362 DicomTransferSyntax& targetSyntax /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
363 bool& hasSopInstanceUidChanged /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
364 DcmFileFormat& dicom /* in, possibly modified */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
365 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
366 bool allowNewSopInstanceUid) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
367 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
368 if (dicom.getDataset() == NULL) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
369 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
370 throw OrthancException(ErrorCode_InternalError); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
371 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
372 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
373 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, dicom)) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
374 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
375 LOG(ERROR) << "Unsupport transfer syntax for transcoding"; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
376 return false; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
377 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
378 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
379 if (InplaceTranscode(hasSopInstanceUidChanged, dicom, allowedSyntaxes, allowNewSopInstanceUid)) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
380 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
381 if (FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax, dicom) && |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
382 allowedSyntaxes.find(targetSyntax) != allowedSyntaxes.end() && |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
383 dicom.getDataset() != NULL) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
384 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
385 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom.getDataset()); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
386 return true; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
387 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
388 else |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
389 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
390 throw OrthancException(ErrorCode_InternalError); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
391 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
392 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
393 else |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
394 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
395 return false; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
396 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
397 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
398 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
399 |
3907
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
400 IDicomTranscoder::TranscodedDicom* DcmtkTranscoder::TranscodeToParsed( |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
401 DcmFileFormat& dicom /* in, possibly modified */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
402 const void* buffer /* in, same DICOM file as "dicom" */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
403 size_t size, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
404 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
405 bool allowNewSopInstanceUid) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
406 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
407 DicomTransferSyntax sourceSyntax; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
408 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, dicom)) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
409 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
410 LOG(ERROR) << "Unsupport transfer syntax for transcoding"; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
411 return NULL; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
412 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
413 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
414 bool hasSopInstanceUidChanged; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
415 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
416 if (allowedSyntaxes.find(sourceSyntax) != allowedSyntaxes.end()) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
417 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
418 // No transcoding is needed |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
419 return TranscodedDicom::CreateFromExternal(dicom, false /* no change in UID */); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
420 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
421 else if (InplaceTranscode(hasSopInstanceUidChanged, dicom, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
422 allowedSyntaxes, allowNewSopInstanceUid)) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
423 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
424 return TranscodedDicom::CreateFromExternal(dicom, hasSopInstanceUidChanged); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
425 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
426 else |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
427 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
428 // Cannot transcode |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
429 return NULL; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
430 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
431 } |
3893 | 432 } |