Mercurial > hg > orthanc
annotate Core/DicomParsing/DcmtkTranscoder.cpp @ 3942:5b882ad2ffd0 transcoding
"/{patients|studies|series}/.../modify": New option "KeepSource"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 18 May 2020 19:09:06 +0200 |
parents | c205f670098e |
children | aae045f802f4 |
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 { | |
3938 | 58 static bool GetBitsStored(uint16_t& bitsStored, |
59 DcmDataset& dataset) | |
3893 | 60 { |
3938 | 61 return dataset.findAndGetUint16(DCM_BitsStored, bitsStored).good(); |
3893 | 62 } |
63 | |
64 | |
65 static std::string GetSopInstanceUid(DcmDataset& dataset) | |
66 { | |
67 const char* v = NULL; | |
68 | |
69 if (dataset.findAndGetString(DCM_SOPInstanceUID, v).good() && | |
70 v != NULL) | |
71 { | |
72 return std::string(v); | |
73 } | |
74 else | |
75 { | |
76 throw OrthancException(ErrorCode_BadFileFormat, "File without SOP instance UID"); | |
77 } | |
78 } | |
79 | |
80 | |
81 static void CheckSopInstanceUid(DcmFileFormat& dicom, | |
82 const std::string& sopInstanceUid, | |
83 bool mustEqual) | |
84 { | |
85 if (dicom.getDataset() == NULL) | |
86 { | |
87 throw OrthancException(ErrorCode_InternalError); | |
88 } | |
3938 | 89 |
3893 | 90 bool ok; |
91 | |
3938 | 92 if (dicom.getDataset()->tagExists(DCM_PixelData)) |
3893 | 93 { |
3938 | 94 if (mustEqual) |
95 { | |
96 ok = (GetSopInstanceUid(*dicom.getDataset()) == sopInstanceUid); | |
97 } | |
98 else | |
99 { | |
100 ok = (GetSopInstanceUid(*dicom.getDataset()) != sopInstanceUid); | |
101 } | |
3893 | 102 } |
103 else | |
104 { | |
3938 | 105 // No pixel data: Transcoding must not change the SOP instance UID |
106 ok = (GetSopInstanceUid(*dicom.getDataset()) == sopInstanceUid); | |
3893 | 107 } |
3938 | 108 |
3893 | 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 { | |
3939
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
123 throw OrthancException( |
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
124 ErrorCode_ParameterOutOfRange, |
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
125 "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
|
126 boost::lexical_cast<std::string>(quality)); |
3893 | 127 } |
128 else | |
129 { | |
3939
c205f670098e
new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3938
diff
changeset
|
130 LOG(INFO) << "Quality for lossy transcoding using DCMTK is set to: " << quality; |
3893 | 131 lossyQuality_ = quality; |
132 } | |
133 } | |
134 | |
135 | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
136 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
|
137 DcmFileFormat& dicom, |
3893 | 138 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
139 bool allowNewSopInstanceUid) | |
140 { | |
141 if (dicom.getDataset() == NULL) | |
142 { | |
143 throw OrthancException(ErrorCode_InternalError); | |
144 } | |
145 | |
3894
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
146 hasSopInstanceUidChanged = false; |
8f7ad4989fec
transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3893
diff
changeset
|
147 |
3893 | 148 DicomTransferSyntax syntax; |
149 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, dicom)) | |
150 { | |
151 throw OrthancException(ErrorCode_BadFileFormat, | |
152 "Cannot determine the transfer syntax"); | |
153 } | |
154 | |
3938 | 155 uint16_t bitsStored; |
156 bool hasBitsStored = GetBitsStored(bitsStored, *dicom.getDataset()); | |
157 | |
3893 | 158 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
|
159 |
3893 | 160 if (allowedSyntaxes.find(syntax) != allowedSyntaxes.end()) |
161 { | |
162 // No transcoding is needed | |
163 return true; | |
164 } | |
165 | |
166 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianImplicit) != allowedSyntaxes.end() && | |
167 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianImplicit, NULL)) | |
168 { | |
169 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
170 return true; | |
171 } | |
172 | |
173 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianExplicit) != allowedSyntaxes.end() && | |
174 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianExplicit, NULL)) | |
175 { | |
176 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
177 return true; | |
178 } | |
179 | |
180 if (allowedSyntaxes.find(DicomTransferSyntax_BigEndianExplicit) != allowedSyntaxes.end() && | |
181 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_BigEndianExplicit, NULL)) | |
182 { | |
183 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
184 return true; | |
185 } | |
186 | |
187 if (allowedSyntaxes.find(DicomTransferSyntax_DeflatedLittleEndianExplicit) != allowedSyntaxes.end() && | |
188 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL)) | |
189 { | |
190 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
191 return true; | |
192 } | |
193 | |
194 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 | |
195 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess1) != allowedSyntaxes.end() && | |
196 allowNewSopInstanceUid && | |
3938 | 197 (!hasBitsStored || bitsStored == 8)) |
3893 | 198 { |
199 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
200 DJ_RPLossy parameters(lossyQuality_); | |
201 | |
202 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess1, ¶meters)) | |
203 { | |
204 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
|
205 hasSopInstanceUidChanged = true; |
3893 | 206 return true; |
207 } | |
208 } | |
209 #endif | |
210 | |
211 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 | |
212 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess2_4) != allowedSyntaxes.end() && | |
213 allowNewSopInstanceUid && | |
3938 | 214 (!hasBitsStored || bitsStored <= 12)) |
3893 | 215 { |
216 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
217 DJ_RPLossy parameters(lossyQuality_); | |
218 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess2_4, ¶meters)) | |
219 { | |
220 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
|
221 hasSopInstanceUidChanged = true; |
3893 | 222 return true; |
223 } | |
224 } | |
225 #endif | |
226 | |
227 #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
|
228 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
|
229 { |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
230 // 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
|
231 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
|
232 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
|
233 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
|
234 { |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
235 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
|
236 return true; |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
237 } |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
238 } |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
239 #endif |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
240 |
7459fcb1bdf7
transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3894
diff
changeset
|
241 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 |
3893 | 242 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess14SV1) != allowedSyntaxes.end()) |
243 { | |
244 // Check out "dcmjpeg/apps/dcmcjpeg.cc" | |
245 DJ_RPLossless parameters(6 /* opt_selection_value */, | |
246 0 /* opt_point_transform */); | |
247 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess14SV1, ¶meters)) | |
248 { | |
249 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
250 return true; | |
251 } | |
252 } | |
253 #endif | |
254 | |
255 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 | |
256 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGLSLossless) != allowedSyntaxes.end()) | |
257 { | |
258 // Check out "dcmjpls/apps/dcmcjpls.cc" | |
259 DJLSRepresentationParameter parameters(2 /* opt_nearlossless_deviation */, | |
260 OFTrue /* opt_useLosslessProcess */); | |
261 | |
262 /** | |
263 * WARNING: This call results in a segmentation fault if using | |
264 * the DCMTK package 3.6.2 from Ubuntu 18.04. | |
265 **/ | |
266 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossless, ¶meters)) | |
267 { | |
268 CheckSopInstanceUid(dicom, sourceSopInstanceUid, true); | |
269 return true; | |
270 } | |
271 } | |
272 #endif | |
273 | |
274 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 | |
275 if (allowNewSopInstanceUid && | |
276 allowedSyntaxes.find(DicomTransferSyntax_JPEGLSLossy) != allowedSyntaxes.end()) | |
277 { | |
278 // Check out "dcmjpls/apps/dcmcjpls.cc" | |
279 DJLSRepresentationParameter parameters(2 /* opt_nearlossless_deviation */, | |
280 OFFalse /* opt_useLosslessProcess */); | |
281 | |
282 /** | |
283 * WARNING: This call results in a segmentation fault if using | |
284 * the DCMTK package 3.6.2 from Ubuntu 18.04. | |
285 **/ | |
286 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossy, ¶meters)) | |
287 { | |
288 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
|
289 hasSopInstanceUidChanged = true; |
3893 | 290 return true; |
291 } | |
292 } | |
293 #endif | |
294 | |
295 return false; | |
296 } | |
297 | |
298 | |
3904
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
299 bool DcmtkTranscoder::IsSupported(DicomTransferSyntax syntax) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
300 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
301 if (syntax == DicomTransferSyntax_LittleEndianImplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
302 syntax == DicomTransferSyntax_LittleEndianExplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
303 syntax == DicomTransferSyntax_BigEndianExplicit || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
304 syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
305 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
306 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
307 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
308 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
309 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
310 if (syntax == DicomTransferSyntax_JPEGProcess1 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
311 syntax == DicomTransferSyntax_JPEGProcess2_4 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
312 syntax == DicomTransferSyntax_JPEGProcess14 || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
313 syntax == DicomTransferSyntax_JPEGProcess14SV1) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
314 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
315 return true; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
316 } |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
317 #endif |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
318 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
319 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
320 if (syntax == DicomTransferSyntax_JPEGLSLossless || |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
321 syntax == DicomTransferSyntax_JPEGLSLossy) |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
322 { |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
323 return true; |
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 #endif |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
326 |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
327 return false; |
c62f84c7eda9
fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3902
diff
changeset
|
328 } |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
329 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
330 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
331 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
332 bool DcmtkTranscoder::TranscodeParsedToBuffer( |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
333 std::string& target /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
334 bool& hasSopInstanceUidChanged /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
335 DcmFileFormat& dicom /* in, possibly modified */, |
3910 | 336 DicomTransferSyntax targetSyntax, |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
337 bool allowNewSopInstanceUid) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
338 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
339 if (dicom.getDataset() == NULL) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
340 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
341 throw OrthancException(ErrorCode_InternalError); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
342 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
343 |
3910 | 344 std::set<DicomTransferSyntax> tmp; |
345 tmp.insert(targetSyntax); | |
346 | |
347 if (InplaceTranscode(hasSopInstanceUidChanged, dicom, tmp, allowNewSopInstanceUid)) | |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
348 { |
3910 | 349 DicomTransferSyntax targetSyntax2; |
350 if (FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax2, dicom) && | |
351 targetSyntax == targetSyntax2 && | |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
352 dicom.getDataset() != NULL) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
353 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
354 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom.getDataset()); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
355 return true; |
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 else |
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 throw OrthancException(ErrorCode_InternalError); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
360 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
361 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
362 else |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
363 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
364 return false; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
365 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
366 } |
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 |
3907
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
369 IDicomTranscoder::TranscodedDicom* DcmtkTranscoder::TranscodeToParsed( |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
370 DcmFileFormat& dicom /* in, possibly modified */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
371 const void* buffer /* in, same DICOM file as "dicom" */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
372 size_t size, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
373 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
374 bool allowNewSopInstanceUid) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
375 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
376 DicomTransferSyntax sourceSyntax; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
377 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, dicom)) |
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 LOG(ERROR) << "Unsupport transfer syntax for transcoding"; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
380 return NULL; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
381 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
382 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
383 bool hasSopInstanceUidChanged; |
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 if (allowedSyntaxes.find(sourceSyntax) != allowedSyntaxes.end()) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
386 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
387 // No transcoding is needed |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
388 return TranscodedDicom::CreateFromExternal(dicom, false /* no change in UID */); |
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 else if (InplaceTranscode(hasSopInstanceUidChanged, dicom, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
391 allowedSyntaxes, allowNewSopInstanceUid)) |
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 return TranscodedDicom::CreateFromExternal(dicom, hasSopInstanceUidChanged); |
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 else |
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 // Cannot transcode |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
398 return NULL; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
399 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3904
diff
changeset
|
400 } |
3893 | 401 } |