annotate OrthancFramework/Resources/Graveyard/TestTranscoding.cpp @ 4299:3f85db78c441

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 05 Nov 2020 18:24:50 +0100
parents 304842a0d152
children d9473bd5ed43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4120
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
1 /**
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
4 * Department, University Hospital of Liege, Belgium
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
6 *
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
7 * This program is free software: you can redistribute it and/or
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * the License, or (at your option) any later version.
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 *
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 * This program is distributed in the hope that it will be useful, but
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
15 * Lesser General Public License for more details.
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
16 *
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * License along with this program. If not, see
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * <http://www.gnu.org/licenses/>.
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 **/
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
21
304842a0d152 adding missing license headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
22
3885
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
23 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
24 DcmFileFormat& dicom,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
25 DicomTransferSyntax syntax)
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
26 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
27 E_TransferSyntax xfer;
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
28 if (!LookupDcmtkTransferSyntax(xfer, syntax))
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
29 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
30 return false;
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
31 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
32 else if (!dicom.validateMetaInfo(xfer).good())
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
33 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
34 throw OrthancException(ErrorCode_InternalError,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
35 "Cannot setup the transfer syntax to write a DICOM instance");
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
36 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
37 else
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
38 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
39 return SaveToMemoryBufferInternal(buffer, dicom, xfer);
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
40 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
41 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
42
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
43
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
44 bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
45 DcmFileFormat& dicom)
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
46 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
47 E_TransferSyntax xfer = dicom.getDataset()->getCurrentXfer();
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
48 if (xfer == EXS_Unknown)
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
49 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
50 throw OrthancException(ErrorCode_InternalError,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
51 "Cannot write a DICOM instance with unknown transfer syntax");
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
52 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
53 else if (!dicom.validateMetaInfo(xfer).good())
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
54 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
55 throw OrthancException(ErrorCode_InternalError,
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
56 "Cannot setup the transfer syntax to write a DICOM instance");
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
57 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
58 else
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
59 {
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
60 return SaveToMemoryBufferInternal(buffer, dicom, xfer);
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
61 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
62 }
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
63
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
64
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
65
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
66
e23026566536 removed unused functions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3884
diff changeset
67
3884
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 #include <dcmtk/dcmdata/dcostrmb.h>
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 #include <dcmtk/dcmdata/dcpixel.h>
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 #include <dcmtk/dcmdata/dcpxitem.h>
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 #include "../Core/DicomParsing/Internals/DicomFrameIndex.h"
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 namespace Orthanc
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 class IParsedDicomImage : public boost::noncopyable
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 virtual ~IParsedDicomImage()
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 virtual DicomTransferSyntax GetTransferSyntax() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 virtual std::string GetSopClassUid() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 virtual std::string GetSopInstanceUid() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 virtual unsigned int GetFramesCount() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 // Can return NULL, for compressed transfer syntaxes
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 virtual ImageAccessor* GetUncompressedFrame(unsigned int frame) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 virtual void GetCompressedFrame(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 unsigned int frame) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 virtual void WriteToMemoryBuffer(std::string& target) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 class IDicomImageReader : public boost::noncopyable
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 virtual ~IDicomImageReader()
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 virtual IParsedDicomImage* Read(const void* data,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 size_t size) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 virtual IParsedDicomImage* Transcode(const void* data,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 size_t size,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 DicomTransferSyntax syntax,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 bool allowNewSopInstanceUid) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 class DcmtkImageReader : public IDicomImageReader
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 private:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 class Image : public IParsedDicomImage
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 private:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 std::unique_ptr<DcmFileFormat> dicom_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 std::unique_ptr<DicomFrameIndex> index_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 DicomTransferSyntax transferSyntax_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 std::string sopClassUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 std::string sopInstanceUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 static std::string GetStringTag(DcmDataset& dataset,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 const DcmTagKey& tag)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 const char* value = NULL;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 if (!dataset.findAndGetString(tag, value).good() ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 value == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 "Missing SOP class/instance UID in DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 return std::string(value);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 Image(DcmFileFormat* dicom,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 DicomTransferSyntax syntax) :
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 dicom_(dicom),
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 transferSyntax_(syntax)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 if (dicom == NULL ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 dicom_->getDataset() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 throw OrthancException(ErrorCode_NullPointer);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 DcmDataset& dataset = *dicom_->getDataset();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 index_.reset(new DicomFrameIndex(dataset));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 sopClassUid_ = GetStringTag(dataset, DCM_SOPClassUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 sopInstanceUid_ = GetStringTag(dataset, DCM_SOPInstanceUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 virtual DicomTransferSyntax GetTransferSyntax() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 return transferSyntax_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 virtual std::string GetSopClassUid() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 return sopClassUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 virtual std::string GetSopInstanceUid() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 return sopInstanceUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 virtual unsigned int GetFramesCount() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 return index_->GetFramesCount();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 virtual void WriteToMemoryBuffer(std::string& target) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 assert(dicom_.get() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 if (!FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, transferSyntax_))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 throw OrthancException(ErrorCode_InternalError,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 "Cannot write the DICOM instance to a memory buffer");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 virtual ImageAccessor* GetUncompressedFrame(unsigned int frame) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 assert(dicom_.get() != NULL &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 dicom_->getDataset() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 return DicomImageDecoder::Decode(*dicom_->getDataset(), frame);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 virtual void GetCompressedFrame(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 unsigned int frame) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 assert(index_.get() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 index_->GetRawFrame(target, frame);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 unsigned int lossyQuality_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 static DicomTransferSyntax DetectTransferSyntax(DcmFileFormat& dicom)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 if (dicom.getDataset() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 throw OrthancException(ErrorCode_InternalError);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 DcmDataset& dataset = *dicom.getDataset();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 E_TransferSyntax xfer = dataset.getCurrentXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 if (xfer == EXS_Unknown)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 dataset.updateOriginalXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 xfer = dataset.getCurrentXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 if (xfer == EXS_Unknown)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 "Cannot determine the transfer syntax of the DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 DicomTransferSyntax syntax;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 if (FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, xfer))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 return syntax;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 throw OrthancException(
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 "Unsupported transfer syntax: " + boost::lexical_cast<std::string>(xfer));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 static uint16_t GetBitsStored(DcmFileFormat& dicom)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 if (dicom.getDataset() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 throw OrthancException(ErrorCode_InternalError);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 uint16_t bitsStored;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 if (dicom.getDataset()->findAndGetUint16(DCM_BitsStored, bitsStored).good())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 return bitsStored;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 "Missing \"Bits Stored\" tag in DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 DcmtkImageReader() :
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 lossyQuality_(90)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 void SetLossyQuality(unsigned int quality)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 if (quality <= 0 ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 quality > 100)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 throw OrthancException(ErrorCode_ParameterOutOfRange);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 lossyQuality_ = quality;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 unsigned int GetLossyQuality() const
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 return lossyQuality_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 virtual IParsedDicomImage* Read(const void* data,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 size_t size)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(data, size));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 if (dicom.get() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 throw OrthancException(ErrorCode_BadFileFormat);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 DicomTransferSyntax transferSyntax = DetectTransferSyntax(*dicom);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 return new Image(dicom.release(), transferSyntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 virtual IParsedDicomImage* Transcode(const void* data,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 size_t size,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 DicomTransferSyntax syntax,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 bool allowNewSopInstanceUid)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(data, size));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 if (dicom.get() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 throw OrthancException(ErrorCode_BadFileFormat);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 const uint16_t bitsStored = GetBitsStored(*dicom);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 if (syntax == DetectTransferSyntax(*dicom))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 // No transcoding is needed
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 if (syntax == DicomTransferSyntax_LittleEndianImplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_LittleEndianImplicit, NULL))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 if (syntax == DicomTransferSyntax_LittleEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_LittleEndianExplicit, NULL))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 if (syntax == DicomTransferSyntax_BigEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_BigEndianExplicit, NULL))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 if (syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 #if ORTHANC_ENABLE_JPEG == 1
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 if (syntax == DicomTransferSyntax_JPEGProcess1 &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 allowNewSopInstanceUid &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 bitsStored == 8)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 DJ_RPLossy rpLossy(lossyQuality_);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 if (FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_JPEGProcess1, &rpLossy))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 #endif
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 #if ORTHANC_ENABLE_JPEG == 1
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 if (syntax == DicomTransferSyntax_JPEGProcess2_4 &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 allowNewSopInstanceUid &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 bitsStored <= 12)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 DJ_RPLossy rpLossy(lossyQuality_);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 if (FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_JPEGProcess2_4, &rpLossy))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 return new Image(dicom.release(), syntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 #endif
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 //LOG(INFO) << "Unable to transcode DICOM image using the built-in reader";
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 return NULL;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 class IDicomTranscoder1 : public boost::noncopyable
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 virtual ~IDicomTranscoder1()
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 virtual DcmFileFormat& GetDicom() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 virtual DicomTransferSyntax GetTransferSyntax() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 virtual std::string GetSopClassUid() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 virtual std::string GetSopInstanceUid() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 virtual unsigned int GetFramesCount() = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 virtual ImageAccessor* DecodeFrame(unsigned int frame) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 virtual void GetCompressedFrame(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 unsigned int frame) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 // NB: Transcoding can change the value of "GetSopInstanceUid()"
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 // and "GetTransferSyntax()" if lossy compression is applied
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 virtual bool Transcode(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 DicomTransferSyntax syntax,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 bool allowNewSopInstanceUid) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 virtual void WriteToMemoryBuffer(std::string& target) = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 class DcmtkTranscoder2 : public IDicomTranscoder1
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 private:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 std::unique_ptr<DcmFileFormat> dicom_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 std::unique_ptr<DicomFrameIndex> index_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 DicomTransferSyntax transferSyntax_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 std::string sopClassUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 std::string sopInstanceUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 uint16_t bitsStored_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 unsigned int lossyQuality_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 static std::string GetStringTag(DcmDataset& dataset,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 const DcmTagKey& tag)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 const char* value = NULL;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 if (!dataset.findAndGetString(tag, value).good() ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 value == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 "Missing SOP class/instance UID in DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 return std::string(value);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 void Setup(DcmFileFormat* dicom)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 lossyQuality_ = 90;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 dicom_.reset(dicom);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 if (dicom == NULL ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 dicom_->getDataset() == NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 throw OrthancException(ErrorCode_NullPointer);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 DcmDataset& dataset = *dicom_->getDataset();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 index_.reset(new DicomFrameIndex(dataset));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 E_TransferSyntax xfer = dataset.getCurrentXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 if (xfer == EXS_Unknown)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 dataset.updateOriginalXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 xfer = dataset.getCurrentXfer();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 if (xfer == EXS_Unknown)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 "Cannot determine the transfer syntax of the DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(transferSyntax_, xfer))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 throw OrthancException(
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 "Unsupported transfer syntax: " + boost::lexical_cast<std::string>(xfer));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 if (!dataset.findAndGetUint16(DCM_BitsStored, bitsStored_).good())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 throw OrthancException(ErrorCode_BadFileFormat,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 "Missing \"Bits Stored\" tag in DICOM instance");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 sopClassUid_ = GetStringTag(dataset, DCM_SOPClassUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 sopInstanceUid_ = GetStringTag(dataset, DCM_SOPInstanceUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 public:
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 DcmtkTranscoder2(DcmFileFormat* dicom) // Takes ownership
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 Setup(dicom);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 DcmtkTranscoder2(const void* dicom,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 size_t size)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 Setup(FromDcmtkBridge::LoadFromMemoryBuffer(dicom, size));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 void SetLossyQuality(unsigned int quality)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 if (quality <= 0 ||
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 quality > 100)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 throw OrthancException(ErrorCode_ParameterOutOfRange);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 lossyQuality_ = quality;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 unsigned int GetLossyQuality() const
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 return lossyQuality_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 unsigned int GetBitsStored() const
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 return bitsStored_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 virtual DcmFileFormat& GetDicom()
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 assert(dicom_ != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 return *dicom_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 virtual DicomTransferSyntax GetTransferSyntax() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 return transferSyntax_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 virtual std::string GetSopClassUid() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 return sopClassUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 virtual std::string GetSopInstanceUid() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 return sopInstanceUid_;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 virtual unsigned int GetFramesCount() ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 return index_->GetFramesCount();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 virtual void WriteToMemoryBuffer(std::string& target) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 if (!FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 throw OrthancException(ErrorCode_InternalError,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 "Cannot write the DICOM instance to a memory buffer");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 virtual ImageAccessor* DecodeFrame(unsigned int frame) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 assert(dicom_->getDataset() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 return DicomImageDecoder::Decode(*dicom_->getDataset(), frame);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 virtual void GetCompressedFrame(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 unsigned int frame) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 index_->GetRawFrame(target, frame);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 virtual bool Transcode(std::string& target,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 DicomTransferSyntax syntax,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 assert(dicom_ != NULL &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 dicom_->getDataset() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 if (syntax == GetTransferSyntax())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 printf("NO TRANSCODING\n");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 // No change in the transfer syntax => simply serialize the current dataset
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 WriteToMemoryBuffer(target);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 printf(">> %d\n", bitsStored_);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 if (syntax == DicomTransferSyntax_LittleEndianImplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 transferSyntax_ = DicomTransferSyntax_LittleEndianImplicit;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 if (syntax == DicomTransferSyntax_LittleEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 transferSyntax_ = DicomTransferSyntax_LittleEndianExplicit;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 if (syntax == DicomTransferSyntax_BigEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 transferSyntax_ = DicomTransferSyntax_BigEndianExplicit;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 if (syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 transferSyntax_ = DicomTransferSyntax_DeflatedLittleEndianExplicit;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 #if ORTHANC_ENABLE_JPEG == 1
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 if (syntax == DicomTransferSyntax_JPEGProcess1 &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 allowNewSopInstanceUid &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 GetBitsStored() == 8)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 DJ_RPLossy rpLossy(lossyQuality_);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 if (FromDcmtkBridge::Transcode(*dicom_, syntax, &rpLossy) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 transferSyntax_ = DicomTransferSyntax_JPEGProcess1;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 sopInstanceUid_ = GetStringTag(*dicom_->getDataset(), DCM_SOPInstanceUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 #endif
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 #if ORTHANC_ENABLE_JPEG == 1
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 if (syntax == DicomTransferSyntax_JPEGProcess2_4 &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 allowNewSopInstanceUid &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 GetBitsStored() <= 12)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 DJ_RPLossy rpLossy(lossyQuality_);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 if (FromDcmtkBridge::Transcode(*dicom_, syntax, &rpLossy) &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 transferSyntax_ = DicomTransferSyntax_JPEGProcess2_4;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 sopInstanceUid_ = GetStringTag(*dicom_->getDataset(), DCM_SOPInstanceUID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 return true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 #endif
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 return false;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 #include <boost/filesystem.hpp>
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 static void TestFile(const std::string& path)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 static unsigned int count = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 count++;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 printf("** %s\n", path.c_str());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 std::string s;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 SystemToolbox::ReadFile(s, path);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 Orthanc::DcmtkTranscoder2 transcoder(s.c_str(), s.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 /*if (transcoder.GetBitsStored() != 8) // TODO
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 return; */
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 char buf[1024];
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 sprintf(buf, "/tmp/source-%06d.dcm", count);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 printf(">> %s\n", buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 Orthanc::SystemToolbox::WriteFile(s, buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 printf("[%s] [%s] [%s] %d %d\n", GetTransferSyntaxUid(transcoder.GetTransferSyntax()),
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 transcoder.GetSopClassUid().c_str(), transcoder.GetSopInstanceUid().c_str(),
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 transcoder.GetFramesCount(), transcoder.GetTransferSyntax());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 for (size_t i = 0; i < transcoder.GetFramesCount(); i++)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 std::string f;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 transcoder.GetCompressedFrame(f, i);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 if (i == 0)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 char buf[1024];
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 sprintf(buf, "/tmp/frame-%06d.raw", count);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 printf(">> %s\n", buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 Orthanc::SystemToolbox::WriteFile(f, buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 std::string t;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 transcoder.WriteToMemoryBuffer(t);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 Orthanc::DcmtkTranscoder2 transcoder2(t.c_str(), t.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 printf(">> %d %d ; %lu bytes\n", transcoder.GetTransferSyntax(), transcoder2.GetTransferSyntax(), t.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 std::string a = transcoder.GetSopInstanceUid();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 DicomTransferSyntax b = transcoder.GetTransferSyntax();
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 DicomTransferSyntax syntax = DicomTransferSyntax_JPEGProcess2_4;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 //DicomTransferSyntax syntax = DicomTransferSyntax_LittleEndianExplicit;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 std::string t;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 bool ok = transcoder.Transcode(t, syntax, true);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 printf("Transcoding: %d\n", ok);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 if (ok)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 printf("[%s] => [%s]\n", a.c_str(), transcoder.GetSopInstanceUid().c_str());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 printf("[%s] => [%s]\n", GetTransferSyntaxUid(b),
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 GetTransferSyntaxUid(transcoder.GetTransferSyntax()));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 char buf[1024];
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 sprintf(buf, "/tmp/transcoded-%06d.dcm", count);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 printf(">> %s\n", buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 Orthanc::SystemToolbox::WriteFile(t, buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 Orthanc::DcmtkTranscoder2 transcoder2(t.c_str(), t.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 printf(" => transcoded transfer syntax %d ; %lu bytes\n", transcoder2.GetTransferSyntax(), t.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 printf("\n");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 TEST(Toto, DISABLED_Transcode)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 //OFLog::configure(OFLogger::DEBUG_LOG_LEVEL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 if (1)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 const char* const PATH = "/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes";
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 for (boost::filesystem::directory_iterator it(PATH);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 it != boost::filesystem::directory_iterator(); ++it)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 if (boost::filesystem::is_regular_file(it->status()))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 TestFile(it->path().string());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 if (0)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 TestFile("/home/jodogne/Subversion/orthanc-tests/Database/Multiframe.dcm");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 TestFile("/home/jodogne/Subversion/orthanc-tests/Database/Issue44/Monochrome1-Jpeg.dcm");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 if (0)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 TestFile("/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/1.2.840.10008.1.2.1.dcm");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 TEST(Toto, DISABLED_Transcode2)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 for (int i = 0; i <= DicomTransferSyntax_XML; i++)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 DicomTransferSyntax a = (DicomTransferSyntax) i;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 std::string path = ("/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/" +
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 std::string(GetTransferSyntaxUid(a)) + ".dcm");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 if (Orthanc::SystemToolbox::IsRegularFile(path))
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 printf("\n======= %s\n", GetTransferSyntaxUid(a));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 std::string source;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 Orthanc::SystemToolbox::ReadFile(source, path);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 DcmtkImageReader reader;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 std::unique_ptr<IParsedDicomImage> image(
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 reader.Read(source.c_str(), source.size()));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 ASSERT_TRUE(image.get() != NULL);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 ASSERT_EQ(a, image->GetTransferSyntax());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 std::string target;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 image->WriteToMemoryBuffer(target);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 for (int j = 0; j <= DicomTransferSyntax_XML; j++)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 DicomTransferSyntax b = (DicomTransferSyntax) j;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 //if (a == b) continue;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 std::unique_ptr<IParsedDicomImage> image(
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 reader.Transcode(source.c_str(), source.size(), b, true));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 if (image.get() != NULL)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 printf("[%s] -> [%s]\n", GetTransferSyntaxUid(a), GetTransferSyntaxUid(b));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 std::string target;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 image->WriteToMemoryBuffer(target);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 char buf[1024];
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 sprintf(buf, "/tmp/%s-%s.dcm", GetTransferSyntaxUid(a), GetTransferSyntaxUid(b));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 SystemToolbox::WriteFile(target, buf);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 else if (a != DicomTransferSyntax_JPEG2000 &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 a != DicomTransferSyntax_JPEG2000LosslessOnly)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 ASSERT_TRUE(b != DicomTransferSyntax_LittleEndianImplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 b != DicomTransferSyntax_LittleEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 b != DicomTransferSyntax_BigEndianExplicit &&
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 b != DicomTransferSyntax_DeflatedLittleEndianExplicit);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 #include "../Core/DicomNetworking/DicomAssociation.h"
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 #include "../Core/DicomNetworking/DicomControlUserConnection.h"
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 #include "../Core/DicomNetworking/DicomStoreUserConnection.h"
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 TEST(Toto, DISABLED_DicomAssociation)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 DicomAssociationParameters params;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 params.SetLocalApplicationEntityTitle("ORTHANC");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 params.SetRemoteApplicationEntityTitle("PACS");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 params.SetRemotePort(2001);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 #if 0
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 DicomAssociation assoc;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 assoc.ProposeGenericPresentationContext(UID_StorageCommitmentPushModelSOPClass);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 assoc.ProposeGenericPresentationContext(UID_VerificationSOPClass);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 assoc.ProposePresentationContext(UID_ComputedRadiographyImageStorage,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 DicomTransferSyntax_JPEGProcess1);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 assoc.ProposePresentationContext(UID_ComputedRadiographyImageStorage,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 DicomTransferSyntax_JPEGProcess2_4);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 assoc.ProposePresentationContext(UID_ComputedRadiographyImageStorage,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 DicomTransferSyntax_JPEG2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 assoc.Open(params);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 int presID = ASC_findAcceptedPresentationContextID(&assoc.GetDcmtkAssociation(), UID_ComputedRadiographyImageStorage);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 printf(">> %d\n", presID);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 std::map<DicomTransferSyntax, uint8_t> pc;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 printf(">> %d\n", assoc.LookupAcceptedPresentationContext(pc, UID_ComputedRadiographyImageStorage));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 for (std::map<DicomTransferSyntax, uint8_t>::const_iterator
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 it = pc.begin(); it != pc.end(); ++it)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 printf("[%s] => %d\n", GetTransferSyntaxUid(it->first), it->second);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 #else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 DicomControlUserConnection assoc(params);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 try
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 printf(">> %d\n", assoc.Echo());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 catch (OrthancException&)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 params.SetRemoteApplicationEntityTitle("PACS");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 params.SetRemotePort(2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 DicomControlUserConnection assoc(params);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 printf(">> %d\n", assoc.Echo());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 #endif
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 static void TestTranscode(DicomStoreUserConnection& scu,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 const std::string& sopClassUid,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 DicomTransferSyntax transferSyntax)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 std::set<DicomTransferSyntax> accepted;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 scu.LookupTranscoding(accepted, sopClassUid, transferSyntax);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 if (accepted.empty())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 throw OrthancException(ErrorCode_NetworkProtocol,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 "The SOP class is not supported by the remote modality");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 unsigned int count = 0;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 for (std::set<DicomTransferSyntax>::const_iterator
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 it = accepted.begin(); it != accepted.end(); ++it)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 LOG(INFO) << "available for transcoding " << (count++) << ": " << sopClassUid
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 << " / " << GetTransferSyntaxUid(*it);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 if (accepted.find(transferSyntax) != accepted.end())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 printf("**** OK, without transcoding !! [%s]\n", GetTransferSyntaxUid(transferSyntax));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 else
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 // Transcoding - only in Orthanc >= 1.7.0
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 const DicomTransferSyntax uncompressed[] = {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 DicomTransferSyntax_LittleEndianImplicit, // Default transfer syntax
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 DicomTransferSyntax_LittleEndianExplicit,
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 DicomTransferSyntax_BigEndianExplicit
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 };
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931 bool found = false;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 for (size_t i = 0; i < 3; i++)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 if (accepted.find(uncompressed[i]) != accepted.end())
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 printf("**** TRANSCODING to %s\n", GetTransferSyntaxUid(uncompressed[i]));
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 found = true;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 break;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 if (!found)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 printf("**** KO KO KO\n");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 TEST(Toto, DISABLED_Store)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 DicomAssociationParameters params;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 params.SetLocalApplicationEntityTitle("ORTHANC");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 params.SetRemoteApplicationEntityTitle("STORESCP");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 params.SetRemotePort(2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 DicomStoreUserConnection assoc(params);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 assoc.RegisterStorageClass(UID_MRImageStorage, DicomTransferSyntax_JPEGProcess1);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 assoc.RegisterStorageClass(UID_MRImageStorage, DicomTransferSyntax_JPEGProcess2_4);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 //assoc.RegisterStorageClass(UID_MRImageStorage, DicomTransferSyntax_LittleEndianExplicit);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 //assoc.SetUncompressedSyntaxesProposed(false); // Necessary for transcoding
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963 assoc.SetCommonClassesProposed(false);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 assoc.SetRetiredBigEndianProposed(true);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 TestTranscode(assoc, UID_MRImageStorage, DicomTransferSyntax_LittleEndianExplicit);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966 TestTranscode(assoc, UID_MRImageStorage, DicomTransferSyntax_JPEG2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 TestTranscode(assoc, UID_MRImageStorage, DicomTransferSyntax_JPEG2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971 TEST(Toto, DISABLED_Store2)
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 {
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 DicomAssociationParameters params;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 params.SetLocalApplicationEntityTitle("ORTHANC");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 params.SetRemoteApplicationEntityTitle("STORESCP");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 params.SetRemotePort(2000);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 DicomStoreUserConnection assoc(params);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 //assoc.SetCommonClassesProposed(false);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 assoc.SetRetiredBigEndianProposed(true);
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 std::string s;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 Orthanc::SystemToolbox::ReadFile(s, "/tmp/i/" + std::string(GetTransferSyntaxUid(DicomTransferSyntax_BigEndianExplicit)) +".dcm");
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 std::string c, i;
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 assoc.Store(c, i, s.c_str(), s.size());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987 printf("[%s] [%s]\n", c.c_str(), i.c_str());
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988 }
83061cdc7703 moving old tests to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989