annotate OrthancFramework/Sources/DicomParsing/DcmtkTranscoder.cpp @ 5666:aa231c18b9d2 find-refactoring

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