annotate OrthancFramework/Sources/DicomParsing/DcmtkTranscoder.cpp @ 5485:48b8dae6dc77

upgrade to year 2024
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Jan 2024 15:10:42 +0100
parents 58b91f5f4e79
children f7adfb22e20e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5480
diff changeset
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5480
diff changeset
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * the License, or (at your option) any later version.
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * 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
16 * Lesser General Public License for more details.
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
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
18 * 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
19 * 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
20 * <http://www.gnu.org/licenses/>.
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "../PrecompiledHeaders.h"
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "DcmtkTranscoder.h"
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 # error Macro ORTHANC_ENABLE_DCMTK_JPEG must be defined
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 # error Macro ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS must be defined
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "FromDcmtkBridge.h"
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
38 #include "../Logging.h"
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "../OrthancException.h"
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
40 #include "../Toolbox.h"
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <dcmtk/dcmdata/dcdeftag.h>
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <dcmtk/dcmjpeg/djrploss.h> // for DJ_RPLossy
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #include <dcmtk/dcmjpeg/djrplol.h> // for DJ_RPLossless
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include <dcmtk/dcmjpls/djrparam.h> // for DJLSRepresentationParameter
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
47 #include <boost/lexical_cast.hpp>
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
48
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 namespace Orthanc
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
52 DcmtkTranscoder::DcmtkTranscoder() :
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
53 lossyQuality_(90)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
54 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
55 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
56
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
57
3938
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3929
diff changeset
58 static bool GetBitsStored(uint16_t& bitsStored,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3929
diff changeset
59 DcmDataset& dataset)
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
3938
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3929
diff changeset
61 return dataset.findAndGetUint16(DCM_BitsStored, bitsStored).good();
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 void DcmtkTranscoder::SetLossyQuality(unsigned int quality)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
67 if (quality == 0 ||
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 quality > 100)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
3939
c205f670098e new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3938
diff changeset
70 throw OrthancException(
c205f670098e new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3938
diff changeset
71 ErrorCode_ParameterOutOfRange,
c205f670098e new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3938
diff changeset
72 "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
73 boost::lexical_cast<std::string>(quality));
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 else
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
3939
c205f670098e new configuration options: BuiltinDecoderTranscoderOrder and IngestTranscoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3938
diff changeset
77 LOG(INFO) << "Quality for lossy transcoding using DCMTK is set to: " << quality;
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 lossyQuality_ = quality;
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
82 unsigned int DcmtkTranscoder::GetLossyQuality() const
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
83 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
84 return lossyQuality_;
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
85 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
86
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
87 bool TryTranscode(std::vector<std::string>& failureReasons, /* out */
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
88 DicomTransferSyntax& selectedSyntax, /* out*/
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
89 DcmFileFormat& dicom, /* in/out */
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
90 const std::set<DicomTransferSyntax>& allowedSyntaxes,
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
91 DicomTransferSyntax trySyntax)
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
92 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
93 if (allowedSyntaxes.find(trySyntax) != allowedSyntaxes.end())
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
94 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
95 if (FromDcmtkBridge::Transcode(dicom, trySyntax, NULL))
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
96 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
97 selectedSyntax = trySyntax;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
98 return true;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
99 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
100
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
101 failureReasons.push_back(std::string("Internal error while transcoding to ") + GetTransferSyntaxUid(trySyntax));
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
102 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
103 return false;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
104 }
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
105
3951
5fe8c6d3212e removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3946
diff changeset
106 bool DcmtkTranscoder::InplaceTranscode(DicomTransferSyntax& selectedSyntax /* out */,
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
107 std::string& failureReason /* out */,
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
108 DcmFileFormat& dicom, /* in/out */
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 const std::set<DicomTransferSyntax>& allowedSyntaxes,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 bool allowNewSopInstanceUid)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
112 std::vector<std::string> failureReasons;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
113
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 if (dicom.getDataset() == NULL)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 throw OrthancException(ErrorCode_InternalError);
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 DicomTransferSyntax syntax;
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, dicom))
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 throw OrthancException(ErrorCode_BadFileFormat,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 "Cannot determine the transfer syntax");
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
3938
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3929
diff changeset
126 uint16_t bitsStored;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3929
diff changeset
127 bool hasBitsStored = GetBitsStored(bitsStored, *dicom.getDataset());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3929
diff changeset
128
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (allowedSyntaxes.find(syntax) != allowedSyntaxes.end())
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 // No transcoding is needed
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 return true;
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
134
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
135 if (TryTranscode(failureReasons, selectedSyntax, dicom, allowedSyntaxes, DicomTransferSyntax_LittleEndianImplicit))
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
136 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
137 return true;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
138 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
139
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
140 if (TryTranscode(failureReasons, selectedSyntax, dicom, allowedSyntaxes, DicomTransferSyntax_LittleEndianExplicit))
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
142 return true;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
143 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
144
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
145 if (TryTranscode(failureReasons, selectedSyntax, dicom, allowedSyntaxes, DicomTransferSyntax_BigEndianExplicit))
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
146 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
147 return true;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
148 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
149
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
150 if (TryTranscode(failureReasons, selectedSyntax, dicom, allowedSyntaxes, DicomTransferSyntax_DeflatedLittleEndianExplicit))
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
151 {
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 return true;
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
157 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess1) != allowedSyntaxes.end())
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
159 if (!allowNewSopInstanceUid)
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
160 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
161 failureReasons.push_back(std::string("Can not transcode to ") + GetTransferSyntaxUid(DicomTransferSyntax_JPEGProcess1) + " without generating new SOPInstanceUID");
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
162 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
163 else if (hasBitsStored && bitsStored != 8)
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
164 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
165 failureReasons.push_back(std::string("Can not transcode to ") + GetTransferSyntaxUid(DicomTransferSyntax_JPEGProcess1) + " if BitsStored != 8");
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
166 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
167 else
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
169 // Check out "dcmjpeg/apps/dcmcjpeg.cc"
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
170 DJ_RPLossy parameters(lossyQuality_);
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
171
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
172 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess1, &parameters))
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
173 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
174 selectedSyntax = DicomTransferSyntax_JPEGProcess1;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
175 return true;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
176 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
177 failureReasons.push_back(std::string("Internal error while transcoding to ") + GetTransferSyntaxUid(DicomTransferSyntax_JPEGProcess1));
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
183 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess2_4) != allowedSyntaxes.end())
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
185 if (!allowNewSopInstanceUid)
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
186 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
187 failureReasons.push_back(std::string("Can not transcode to ") + GetTransferSyntaxUid(DicomTransferSyntax_JPEGProcess2_4) + " without generating new SOPInstanceUID");
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
188 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
189 else if (hasBitsStored && bitsStored > 12)
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
191 failureReasons.push_back(std::string("Can not transcode to ") + GetTransferSyntaxUid(DicomTransferSyntax_JPEGProcess2_4) + " if BitsStored != 8");
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
192 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
193 else
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
194 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
195 // Check out "dcmjpeg/apps/dcmcjpeg.cc"
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
196 DJ_RPLossy parameters(lossyQuality_);
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
197 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess2_4, &parameters))
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
198 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
199 selectedSyntax = DicomTransferSyntax_JPEGProcess2_4;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
200 return true;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
201 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
202 failureReasons.push_back(std::string("Internal error while transcoding to ") + GetTransferSyntaxUid(DicomTransferSyntax_JPEGProcess2_4));
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 #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
208 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
209 {
7459fcb1bdf7 transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3894
diff changeset
210 // 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
211 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
212 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
213 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess14, &parameters))
7459fcb1bdf7 transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3894
diff changeset
214 {
3946
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
215 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
216 return true;
7459fcb1bdf7 transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3894
diff changeset
217 }
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
218 failureReasons.push_back(std::string("Internal error while transcoding to ") + GetTransferSyntaxUid(DicomTransferSyntax_JPEGProcess14));
3902
7459fcb1bdf7 transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3894
diff changeset
219 }
7459fcb1bdf7 transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3894
diff changeset
220 #endif
7459fcb1bdf7 transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3894
diff changeset
221
7459fcb1bdf7 transcoding to 1.2.840.10008.1.2.4.57
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3894
diff changeset
222 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess14SV1) != allowedSyntaxes.end())
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 // Check out "dcmjpeg/apps/dcmcjpeg.cc"
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 DJ_RPLossless parameters(6 /* opt_selection_value */,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 0 /* opt_point_transform */);
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess14SV1, &parameters))
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 {
3946
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
230 selectedSyntax = DicomTransferSyntax_JPEGProcess14SV1;
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 return true;
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
233 failureReasons.push_back(std::string("Internal error while transcoding to ") + GetTransferSyntaxUid(DicomTransferSyntax_JPEGProcess14SV1));
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGLSLossless) != allowedSyntaxes.end())
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 // Check out "dcmjpls/apps/dcmcjpls.cc"
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 DJLSRepresentationParameter parameters(2 /* opt_nearlossless_deviation */,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 OFTrue /* opt_useLosslessProcess */);
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 /**
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 * WARNING: This call results in a segmentation fault if using
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 * the DCMTK package 3.6.2 from Ubuntu 18.04.
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 **/
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossless, &parameters))
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
3946
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
250 selectedSyntax = DicomTransferSyntax_JPEGLSLossless;
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 return true;
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 }
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
253 failureReasons.push_back(std::string("Internal error while transcoding to ") + GetTransferSyntaxUid(DicomTransferSyntax_JPEGLSLossless));
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 if (allowNewSopInstanceUid &&
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 allowedSyntaxes.find(DicomTransferSyntax_JPEGLSLossy) != allowedSyntaxes.end())
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 // Check out "dcmjpls/apps/dcmcjpls.cc"
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 DJLSRepresentationParameter parameters(2 /* opt_nearlossless_deviation */,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 OFFalse /* opt_useLosslessProcess */);
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 /**
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 * WARNING: This call results in a segmentation fault if using
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 * the DCMTK package 3.6.2 from Ubuntu 18.04.
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 **/
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossy, &parameters))
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
3946
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
271 selectedSyntax = DicomTransferSyntax_JPEGLSLossy;
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 return true;
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
274 failureReasons.push_back(std::string("Internal error while transcoding to ") + GetTransferSyntaxUid(DicomTransferSyntax_JPEGLSLossy));
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
278 Orthanc::Toolbox::JoinStrings(failureReason, failureReasons, ", ");
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 return false;
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
3904
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
282 bool DcmtkTranscoder::IsSupported(DicomTransferSyntax syntax)
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
283 {
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
284 if (syntax == DicomTransferSyntax_LittleEndianImplicit ||
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
285 syntax == DicomTransferSyntax_LittleEndianExplicit ||
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
286 syntax == DicomTransferSyntax_BigEndianExplicit ||
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
287 syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit)
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
288 {
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
289 return true;
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
290 }
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
291
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
292 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
293 if (syntax == DicomTransferSyntax_JPEGProcess1 ||
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
294 syntax == DicomTransferSyntax_JPEGProcess2_4 ||
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
295 syntax == DicomTransferSyntax_JPEGProcess14 ||
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
296 syntax == DicomTransferSyntax_JPEGProcess14SV1)
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
297 {
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
298 return true;
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
299 }
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
300 #endif
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
301
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
302 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
303 if (syntax == DicomTransferSyntax_JPEGLSLossless ||
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
304 syntax == DicomTransferSyntax_JPEGLSLossy)
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 #endif
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
309
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
310 return false;
c62f84c7eda9 fixing incorrect behavior in MemoryBufferTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3902
diff changeset
311 }
3906
f0dd5ded8927 refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3904
diff changeset
312
f0dd5ded8927 refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3904
diff changeset
313
3944
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
314 bool DcmtkTranscoder::Transcode(DicomImage& target,
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
315 DicomImage& source /* in, "GetParsed()" possibly modified */,
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
316 const std::set<DicomTransferSyntax>& allowedSyntaxes,
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
317 bool allowNewSopInstanceUid)
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
318 {
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
319 target.Clear();
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
320
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
321 DicomTransferSyntax sourceSyntax;
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
322 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, source.GetParsed()))
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
323 {
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
324 LOG(ERROR) << "Unsupport transfer syntax for transcoding";
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
325 return false;
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
326 }
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
327
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
328 std::string failureReason;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
329 std::string s;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
330 for (std::set<DicomTransferSyntax>::const_iterator
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
331 it = allowedSyntaxes.begin(); it != allowedSyntaxes.end(); ++it)
3981
31252a887f0b info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3951
diff changeset
332 {
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
333 if (!s.empty())
3981
31252a887f0b info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3951
diff changeset
334 {
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
335 s += ", ";
3981
31252a887f0b info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3951
diff changeset
336 }
31252a887f0b info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3951
diff changeset
337
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
338 s += GetTransferSyntaxUid(*it);
3981
31252a887f0b info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3951
diff changeset
339 }
31252a887f0b info log about dcmtk transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3951
diff changeset
340
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
341 if (s.empty())
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
342 {
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
343 s = "<none>";
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
344 }
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
345
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
346 LOG(INFO) << "DCMTK transcoding from " << GetTransferSyntaxUid(sourceSyntax)
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
347 << " to one of: " << s;
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
348
3946
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
349 #if !defined(NDEBUG)
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
350 const std::string sourceSopInstanceUid = GetSopInstanceUid(source.GetParsed());
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
351 #endif
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
352
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
353 DicomTransferSyntax targetSyntax;
3944
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
354 if (allowedSyntaxes.find(sourceSyntax) != allowedSyntaxes.end())
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
355 {
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
356 // No transcoding is needed
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
357 target.AcquireParsed(source);
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
358 target.AcquireBuffer(source);
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
359 return true;
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
360 }
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
361 else if (InplaceTranscode(targetSyntax, failureReason, source.GetParsed(),
3944
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
362 allowedSyntaxes, allowNewSopInstanceUid))
3946
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
363 {
3944
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
364 // Sanity check
3946
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
365 DicomTransferSyntax targetSyntax2;
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
366 if (FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax2, source.GetParsed()) &&
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
367 targetSyntax == targetSyntax2 &&
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
368 allowedSyntaxes.find(targetSyntax2) != allowedSyntaxes.end())
3944
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
369 {
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
370 target.AcquireParsed(source);
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
371 source.Clear();
3946
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
372
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
373 #if !defined(NDEBUG)
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
374 // Only run the sanity check in debug mode
3951
5fe8c6d3212e removed useless information "hasSopInstanceUidChanged"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3946
diff changeset
375 CheckTranscoding(target, sourceSyntax, sourceSopInstanceUid,
3946
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
376 allowedSyntaxes, allowNewSopInstanceUid);
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
377 #endif
1f33ed7f82e6 automatic test of transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3945
diff changeset
378
3944
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
379 return true;
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
380 }
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
381 else
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
382 {
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
383 throw OrthancException(ErrorCode_InternalError);
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
384 }
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
385 }
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
386 else
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
387 {
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
388 // Cannot transcode
5480
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
389 LOG(WARNING) << "DCMTK was unable to transcode from " << GetTransferSyntaxUid(sourceSyntax)
58b91f5f4e79 more detailed log if InPlaceTranscode fails
Alain Mazy <am@osimis.io>
parents: 5185
diff changeset
390 << " to one of: " << s << " " << failureReason;
3944
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
391 return false;
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
392 }
aae045f802f4 preparing simplified interface for IDicomTranscoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3939
diff changeset
393 }
3893
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 }