annotate Core/DicomParsing/MemoryBufferTranscoder.cpp @ 3893:7a5fa8f307e9 transcoding

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 06 May 2020 12:48:28 +0200
parents
children 8f7ad4989fec
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
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../PrecompiledHeaders.h"
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "MemoryBufferTranscoder.h"
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 "../OrthancException.h"
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "FromDcmtkBridge.h"
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 MemoryBufferTranscoder::MemoryBufferTranscoder(bool tryDcmtk) :
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 tryDcmtk_(tryDcmtk)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #if ORTHANC_ENABLE_DCMTK_TRANSCODING != 1
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 if (tryDcmtk)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 throw OrthancException(ErrorCode_NotImplemented,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 "Orthanc was built without support for DMCTK transcoding");
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 bool MemoryBufferTranscoder::TranscodeToBuffer(std::string& target,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 const void* buffer,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 size_t size,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 const std::set<DicomTransferSyntax>& allowedSyntaxes,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 bool allowNewSopInstanceUid)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 if (tryDcmtk_)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 return dcmtk_.TranscodeToBuffer(target, buffer, size, allowedSyntaxes, allowNewSopInstanceUid);
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 else
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 return Transcode(target, buffer, size, allowedSyntaxes, allowNewSopInstanceUid);
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 DcmFileFormat* MemoryBufferTranscoder::TranscodeToParsed(const void* buffer,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 size_t size,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 const std::set<DicomTransferSyntax>& allowedSyntaxes,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 bool allowNewSopInstanceUid)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 if (tryDcmtk_)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 return dcmtk_.TranscodeToParsed(buffer, size, allowedSyntaxes, allowNewSopInstanceUid);
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 else
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 std::string transcoded;
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 if (Transcode(transcoded, buffer, size, allowedSyntaxes, allowNewSopInstanceUid))
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 return FromDcmtkBridge::LoadFromMemoryBuffer(
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 transcoded.empty() ? NULL : transcoded.c_str(), transcoded.size());
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 else
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 return NULL;
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
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
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 bool MemoryBufferTranscoder::InplaceTranscode(DcmFileFormat& dicom,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 const std::set<DicomTransferSyntax>& allowedSyntaxes,
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 bool allowNewSopInstanceUid)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 if (tryDcmtk_)
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 return dcmtk_.InplaceTranscode(dicom, allowedSyntaxes, allowNewSopInstanceUid);
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 else
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 #endif
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 // "HasInplaceTranscode()" should have been called
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 throw OrthancException(ErrorCode_BadSequenceOfCalls);
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
7a5fa8f307e9 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }