annotate OrthancFramework/Sources/DicomParsing/DcmtkTranscoder.cpp @ 5363:3c8286e5d07b multiple-jpeg-decoders

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